1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2012 - DIGITEO - Antoine ELIAS
3 // Copyright (C) 2012 - DIGITEO - Vincent COUVERT
5 // Copyright (C) 2012 - 2016 - Scilab Enterprises
7 // This file is hereby licensed under the terms of the GNU GPL v2.0,
8 // pursuant to article 5.3.4 of the CeCILL v.2.1.
9 // This file was originally licensed under the terms of the CeCILL v2.1,
10 // and continues to be available under such terms.
11 // For more information, see the COPYING file which you should have received
12 // along with this program.
14 function varargout = %_sodload(%__varnameList__)
16 function varValue = %__convertVariable__(varValue, varName)
17 if typeof(varValue) == "ScilabMatrixHandle" then
18 //convert tlist to handle
19 varValue = createMatrixHandle(varValue);
20 elseif typeof(varValue) == "ScilabMacro" then
21 //convert tlist to macro
22 varValue = createMacro(varValue, varName);
23 elseif isList(varValue) then
25 varValue = parseList(varValue);
29 function result = isList(var)
33 if or(type(var) == [15, 16, 17]) then
40 function varValue = parseList(varValue)
42 if or(typeof(varValue)==["ce","st"]) then
43 if typeof(varValue)=="st" then
44 fieldNames = fieldnames(varValue);
46 fieldNames = varValue;
49 for kField = 1:size(fieldNames,"*")
51 if typeof(varValue)=="st" then
52 fieldValue = varValue(fieldNames(kField));
54 fieldValue = varValue{kField};
57 if typeof(fieldValue) == "ScilabMatrixHandle" then
58 fieldValue = createMatrixHandle(fieldValue);
59 elseif typeof(fieldValue) == "ScilabMacro" then
60 //convert tlist to macro
61 fieldValue = createMacro(fieldValue, "function");
62 elseif isList(fieldValue) then
63 fieldValue = parseList(fieldValue);
66 if typeof(varValue)=="st" then
67 s = size(varValue, "*");
69 if typeof(fieldValue) <> "list" then //houston !
73 varValue(iDim)(fieldNames(kField)) = fieldValue(iDim);
76 varValue(fieldNames(kField)) = fieldValue;
79 varValue{kField} = fieldValue;
84 elseif typeof(varValue)=="list" then
85 for i = definedfields(varValue)
86 if typeof(varValue(i)) == "ScilabMatrixHandle" then
87 varValue(i) = createMatrixHandle(varValue(i));
88 elseif typeof(varValue(i)) == "ScilabMacro" then
89 //convert tlist to macro
90 varValue(i) = createMacro(varValue(i), "function");
91 elseif isList(varValue(i)) then
92 varValue(i) = parseList(varValue(i));
94 varValue(i) = varValue(i);
98 fieldNb = size(getfield(1, varValue), "*");
99 for kField = 2:fieldNb // Do not inspect first field (field names)
100 fieldValue = getfield(kField, varValue);
101 if typeof(fieldValue) == "ScilabMatrixHandle" then
102 fieldValue = createMatrixHandle(fieldValue);
103 elseif typeof(fieldValue) == "ScilabMacro" then
104 //convert tlist to macro
105 fieldValue = createMacro(fieldValue, "function");
106 elseif isList(fieldValue) then
107 fieldValue = parseList(fieldValue);
109 varValue = setfield(kField, fieldValue, varValue);
114 function h = createMatrixHandle(matrixHandle)
116 if typeof(matrixHandle) <> "ScilabMatrixHandle" then
120 for i = prod(matrixHandle.dims):-1:1
122 newItem = createSingleHandle(matrixHandle.values(i));
123 if newItem == [] then
128 if or(fieldnames(matrixHandle.values(i))=="user_data") then // TODO Remove after graphic branch merge
129 if isList(matrixHandle.values(i).user_data) then
130 set(h($), "user_data", parseList(matrixHandle.values(i).user_data));
131 elseif typeof(matrixHandle.values(i).user_data) == "ScilabMatrixHandle" then
132 set(h($), "user_data", createMatrixHandle(matrixHandle.values(i).user_data));
138 function h = createSingleHandle(item)
141 h = createFigure(item);
143 h = createAxes(item);
145 h = createPolyline(item);
147 h = createPlot3d(item);
149 h = createFac3d(item);
151 h = createCompound(item);
153 h = createRectangle(item);
157 h = createChamp(item);
159 h = createSegs(item);
161 h = createGrayplot(item);
163 h = createMatplot(item);
167 h = createLegend(item);
169 h = createText(item);
171 h = createAxis(item);
173 h = createuimenu(item);
175 h = createuicontextmenu(item);
177 h = createuicontrol(item);
179 h = createDatatip(item);
181 h = createLight(item);
183 error("handle of type " + item.type + " unhandled");
191 function h = createFigure(figureProperties)
192 fields = fieldnames(figureProperties);
195 if or(fields=="resize") then
196 if figureProperties.menubar<>"figure" ..
197 | figureProperties.toolbar<>"figure" ..
198 | figureProperties.dockable<>"on" ..
199 | figureProperties.default_axes<>"on" then
200 // File created by Scilab 5.5.0 or more
201 h = figure("menubar", figureProperties.menubar, ...
202 "toolbar", figureProperties.toolbar, ...
203 "dockable", figureProperties.dockable, ...
204 "default_axes", figureProperties.default_axes, ...
207 fields(fields=="menubar") = [];
208 fields(fields=="toolbar") = [];
209 fields(fields=="dockable") = [];
210 fields(fields=="default_axes") = [];
211 fields(fields=="visible") = [];
213 [lnums, fnames] = where();
214 ind = grep(fnames, "xload");
215 xload_mode = (ind ~= []);
216 if xload_mode then // See bug #3975
224 if isempty(winsid()) then
225 h = figure("visible", "off");
233 // Following propeties will be set after all other ones
234 isVisible = figureProperties.visible;
235 fields(fields=="visible") = [];
236 resizefcn = figureProperties.resizefcn;
237 fields(fields=="resizefcn") = [];
238 event_handler = figureProperties.event_handler;
239 fields(fields=="event_handler") = [];
242 fields(fields=="figure_id") = [];
244 h.figure_position=figureProperties.figure_position;
245 fields(fields=="figure_position") = [];
246 // set auto_resize first otherwise viewport modification may not have any effect.
247 h.auto_resize = figureProperties.auto_resize;
248 fields(fields=="auto_resize") = [];
249 h.figure_size = figureProperties.figure_size;
250 fields(fields=="figure_size") = [];
251 // set axes_size last because it's more important than figure_size
252 h.axes_size = figureProperties.axes_size;
253 fields(fields=="axes_size") = [];
255 for i = 1:size(fields, "*")
256 if fields(i) == "children" then
257 c = figureProperties(fields(i));
259 createSingleHandle(c.values(s));
261 xsetech(wrect=[0 0 .1 .1])
262 createSingleHandle(c.values(i));
265 if fields(i)<>"pixmap" then // See bug #13310
266 set(h, fields(i), figureProperties(fields(i)));
271 h.resizefcn = resizefcn;
272 h.event_handler = event_handler;
273 h.visible = isVisible;
279 function h = createLabel(labelProperties, h)
280 fields = fieldnames(labelProperties);
282 for i = 1:size(fields, "*")
283 set(h, fields(i), labelProperties(fields(i)));
290 function h = createTicks(ticksProperties)
291 h = tlist(["ticks","locations","labels"], [], []);
292 fields = fieldnames(ticksProperties);
293 for i = 1:size(fields, "*")
294 h(fields(i)) = ticksProperties(fields(i));
301 function h = createAxes(axesProperties)
302 // Hack to determine whether %h_load has been called by the %h_copy macro
303 // in which case a new Axes object is created
305 [lnums, fnames] = where();
306 ind = grep(fnames, "%h_copy");
307 if ~isempty(ind) then
312 fields = fieldnames(axesProperties);
315 // Get log_flags to be sure to set them after data_bounds
316 log_flags = axesProperties.log_flags;
317 fields(fields=="log_flags") = [];
319 // Get mark_mode to be sure to set it after mark_style
320 mark_mode = axesProperties.mark_mode;
321 fields(fields=="mark_mode") = [];
323 // Get auto_ticks to be sure to set it after ticks labels
324 auto_ticks = axesProperties.auto_ticks;
325 fields(fields=="auto_ticks") = [];
327 if isfield(axesProperties, "auto_margins") then
328 auto_margins = axesProperties.auto_margins;
329 fields(fields=="auto_margins") = [];
333 for i = 1:size(fields, "*")
334 if or(fields(i) == ["title","x_label","y_label","z_label"]) then
335 createLabel(axesProperties(fields(i)), h(fields(i)));
336 elseif or(fields(i) == ["x_ticks", "y_ticks", "z_ticks"]) then
337 set(h, fields(i), createTicks(axesProperties(fields(i))));
338 elseif fields(i) == "children" then
339 createMatrixHandle(axesProperties(fields(i)));
340 elseif fields(i) == "clip_state" then
341 if axesProperties.clip_state=="on" then
342 set(h,"clip_box",axesProperties.clip_box);
344 set(h,"clip_state", axesProperties.clip_state);
345 elseif fields(i) == "clip_box" then
346 // managed with 'clip_state'
347 elseif fields(i) == "data_bounds" then
348 set(h, "data_bounds", axesProperties.data_bounds);
349 set(h, "log_flags", log_flags);
350 elseif fields(i) == "mark_style" then
351 set(h, "mark_style", axesProperties.mark_style);
352 set(h, "mark_mode", mark_mode);
354 set(h, fields(i), axesProperties(fields(i)));;
358 set(h, "auto_ticks", auto_ticks);
360 set(h, "auto_margins", auto_margins);
365 if ~isempty(%LEG) then
366 // Get handles from paths
367 links=getlinksfrompath(h, %LEG.paths)
368 if ~isempty(links) then
369 L = captions(links, %LEG.text)
370 L.visible = %LEG.visible
371 L.font_style = %LEG.font_style
372 L.font_size = %LEG.font_size
373 L.font_color = %LEG.font_color
374 L.fractional_font = %LEG.fractional_font
376 L.legend_location = %LEG.legend_location
377 L.position = %LEG.position
378 L.line_mode = %LEG.line_mode
379 L.thickness = %LEG.thickness
380 L.foreground = %LEG.foreground
381 L.fill_mode = %LEG.fill_mode
382 L.background = %LEG.background
383 if %LEG.clip_state=="on" then
384 L.clip_box = %LEG.clip_box
386 L.clip_state = %LEG.clip_state
387 L.user_data = %LEG.user_data
389 warning(msprintf(_("%s: Legend does not fit with the current context. Skipped\n"), "load"));
399 function h = createPolyline(polylineProperties)
400 fields = fieldnames(polylineProperties);
403 xpoly(polylineProperties.data(:,1), polylineProperties.data(:,2))
407 if polylineProperties.clip_state=="on" then
408 set(h, "clip_box", polylineProperties.clip_box)
410 set(h, "clip_state", polylineProperties.clip_state);
411 fields(fields=="clip_box") = [];
412 fields(fields=="clip_state") = [];
414 if polylineProperties.interp_color_mode=="on" & ~isempty(polylineProperties.interp_color_vector) then
415 set(h, "interp_color_vector", polylineProperties.interp_color_vector);
416 set(h, "interp_color_mode", polylineProperties.interp_color_mode);
418 if ~isempty(polylineProperties.interp_color_vector) then
419 h.interp_color_vector = polylineProperties.interp_color_vector;
421 h.interp_color_mode = polylineProperties.interp_color_mode;
423 fields(fields=="interp_color_vector") = [];
424 fields(fields=="interp_color_mode") = [];
426 // Get mark_mode to be sure to set it after mark_style
427 mark_mode = polylineProperties.mark_mode;
428 fields(fields=="mark_mode") = [];
433 for i = 1:size(fields, "*")
434 if fields(i) == "mark_style" then
435 set(h, "mark_style", polylineProperties.mark_style);
436 set(h, "mark_mode", mark_mode);
437 elseif fields(i) == "children" then
438 createMatrixHandle(polylineProperties(fields(i)));
439 elseif fields(i) == "datatips" then
440 createMatrixHandle(polylineProperties(fields(i)));
442 h(fields(i)) = polylineProperties(fields(i));
446 clearglobal %POLYLINE
453 function h = createPlot3d(plot3dProperties)
454 h = createSurface(plot3dProperties);
460 function h = createFac3d(fac3dProperties)
461 h = createSurface(fac3dProperties);
467 function h = createSurface(surfaceProperties)
468 fields = fieldnames(surfaceProperties);
470 // plot3d modify the axes properties
475 rotation_angles = a.rotation_angles;
476 axes_visible = a.axes_visible;
479 x_label_visible = a.x_label.visible;
480 y_label_visible = a.y_label.visible;
481 z_label_visible = a.z_label.visible;
482 x_label_text = a.x_label.text;
483 y_label_text = a.y_label.text;
484 z_label_text = a.z_label.text;
485 axes_isoview = a.isoview;
487 if (or(surfaceProperties.color_flag==[2 5]) & ~or(fields=="cdata_mapping")) | ..
488 ((surfaceProperties.color_flag>=2) & or(fields=="cdata_mapping")) then
489 plot3d1(surfaceProperties.data.x, surfaceProperties.data.y, list(surfaceProperties.data.z, surfaceProperties.data.color))
491 plot3d(surfaceProperties.data.x,surfaceProperties.data.y,surfaceProperties.data.z)
493 fields(fields=="data") = [];
495 // Restore this properties after plot3d.
496 a.rotation_angles = rotation_angles;
497 a.axes_visible = axes_visible;
500 a.x_label.visible = x_label_visible;
501 a.y_label.visible = y_label_visible;
502 a.z_label.visible = z_label_visible;
503 a.x_label.text = x_label_text;
504 a.y_label.text = y_label_text;
505 a.z_label.text = z_label_text;
506 a.isoview = axes_isoview;
508 // Get mark_mode to be sure to set it after mark_style
509 mark_mode = surfaceProperties.mark_mode;
510 fields(fields=="mark_mode") = [];
514 if or(fields=="cdata_mapping") then // Fac3d specific
515 if surfaceProperties.color_flag >= 2 then
516 set(h, "cdata_mapping", surfaceProperties.cdata_mapping);
518 fields(fields=="cdata_mapping") = [];
521 if surfaceProperties.clip_state == "on" then
522 set(h,"clip_box", surfaceProperties.clip_box);
524 set(h,"clip_state",surfaceProperties.clip_state);
525 fields(fields=="clip_box") = [];
526 fields(fields=="clip_state") = [];
528 for i = 1:size(fields, "*")
529 if fields(i) == "mark_style" then
530 set(h, "mark_style", surfaceProperties.mark_style);
531 set(h, "mark_mode", mark_mode);
533 h(fields(i)) = surfaceProperties(fields(i));
541 function h = createCompound(compoundProperties)
542 fields = fieldnames(compoundProperties);
545 h = glue(createMatrixHandle(compoundProperties.children));
546 fields(fields=="children") = [];
548 for i = 1:size(fields, "*")
549 set(h, fields(i), compoundProperties(fields(i)));
556 function h = createRectangle(rectangleProperties)
557 fields = fieldnames(rectangleProperties);
560 xrect(0,1,1,1); // create the rectangle with dummy values
563 if rectangleProperties.clip_state == "on" then
564 set(h,"clip_box", rectangleProperties.clip_box);
566 set(h,"clip_state",rectangleProperties.clip_state);
567 fields(fields=="clip_box") = [];
568 fields(fields=="clip_state") = [];
570 // Get mark_mode to be sure to set it after mark_style
571 mark_mode = rectangleProperties.mark_mode;
572 fields(fields=="mark_mode") = [];
574 for i = 1:size(fields, "*")
575 if fields(i) == "mark_style" then
576 set(h, "mark_style", rectangleProperties.mark_style);
577 set(h, "mark_mode", mark_mode);
579 h(fields(i)) = rectangleProperties(fields(i));
587 function h = createArc(arcProperties)
588 fields = fieldnames(arcProperties);
591 xarc(0,1,1,1,0,360); // create the arc with dummy values
594 if arcProperties.clip_state == "on" then
595 set(h,"clip_box", arcProperties.clip_box);
597 set(h,"clip_state",arcProperties.clip_state);
598 fields(fields=="clip_box") = [];
599 fields(fields=="clip_state") = [];
601 for i = 1:size(fields, "*")
602 set(h, fields(i), arcProperties(fields(i)));
609 function h = createChamp(champProperties)
610 fields = fieldnames(champProperties);
613 champ(champProperties.data.x, champProperties.data.y, champProperties.data.fx, champProperties.data.fy);
614 fields(fields=="data") = [];
618 if champProperties.clip_state == "on" then
619 set(h,"clip_box", champProperties.clip_box);
621 set(h,"clip_state",champProperties.clip_state);
622 fields(fields=="clip_box") = [];
623 fields(fields=="clip_state") = [];
625 for i = 1:size(fields, "*")
626 set(h, fields(i), champProperties(fields(i)));
633 function h = createSegs(segsProperties)
634 fields = fieldnames(segsProperties);
637 xsegs(segsProperties.data(:,1), segsProperties.data(:,2))
641 if segsProperties.clip_state == "on" then
642 set(h,"clip_box", segsProperties.clip_box);
644 set(h,"clip_state",segsProperties.clip_state);
645 fields(fields=="clip_box") = [];
646 fields(fields=="clip_state") = [];
648 // Get mark_mode to be sure to set it after mark_style
649 mark_mode = segsProperties.mark_mode;
650 fields(fields=="mark_mode") = [];
652 for i = 1:size(fields, "*")
653 if fields(i) == "mark_style" then
654 set(h, "mark_style", segsProperties.mark_style);
655 set(h, "mark_mode", mark_mode);
657 h(fields(i)) = segsProperties(fields(i));
665 function h = createGrayplot(grayplotProperties)
666 fields = fieldnames(grayplotProperties);
669 grayplot(grayplotProperties.data.x, grayplotProperties.data.y, grayplotProperties.data.z);
670 fields(fields=="data") = [];
674 if grayplotProperties.clip_state=="on" then
675 set(h, "clip_box", grayplotProperties.clip_box)
677 set(h, "clip_state", grayplotProperties.clip_state);
678 fields(fields=="clip_box") = [];
679 fields(fields=="clip_state") = [];
681 for i = 1:size(fields, "*")
682 set(h, fields(i), grayplotProperties(fields(i)));
689 function h = createMatplot(matplotProperties)
690 fields = fieldnames(matplotProperties);
693 Matplot(matplotProperties.data);
694 fields(fields=="data") = [];
698 if matplotProperties.clip_state=="on" then
699 set(h, "clip_box", matplotProperties.clip_box)
701 set(h, "clip_state", matplotProperties.clip_state);
702 fields(fields=="clip_box") = [];
703 fields(fields=="clip_state") = [];
705 for i = 1:size(fields, "*")
706 set(h, fields(i), matplotProperties(fields(i)));
713 function h = createFec(fecProperties)
714 fields = fieldnames(fecProperties);
717 fec(fecProperties.data(:,1), fecProperties.data(:,2), fecProperties.triangles, fecProperties.data(:,3));
718 fields(fields=="data") = [];
719 fields(fields=="triangles") = [];
723 if fecProperties.clip_state=="on" then
724 set(h, "clip_box", fecProperties.clip_box)
726 set(h, "clip_state", fecProperties.clip_state);
727 fields(fields=="clip_box") = [];
728 fields(fields=="clip_state") = [];
730 for i = 1:size(fields, "*")
731 set(h, fields(i), fecProperties(fields(i)));
738 function h = createLegend(legendProperties)
740 %LEG = legendProperties;
747 function h = createText(textProperties)
748 fields = fieldnames(textProperties);
751 if textProperties.text_box_mode == "off" then
752 xstring(textProperties.data(1), textProperties.data(2), textProperties.text)
754 xstringb(textProperties.data(1), textProperties.data(2), textProperties.text, textProperties.text_box(1), textProperties.text_box(2))
759 if textProperties.clip_state=="on" then
760 set(h, "clip_box", textProperties.clip_box)
762 set(h, "clip_state", textProperties.clip_state);
763 fields(fields=="clip_box") = [];
764 fields(fields=="clip_state") = [];
766 for i = 1:size(fields, "*")
767 set(h, fields(i), textProperties(fields(i)));
774 function h = createDatatip(datatipProperties)
776 fields = fieldnames(datatipProperties)';
779 tip_data = datatipProperties("data");
780 h = datatipCreate(%POLYLINE, tip_data);
785 v = datatipProperties(f)
786 if f == "z_component" // up to 5.5.2: http://bugzilla.scilab.org/16374
788 [f, v] = ("display_components", "xyz")
800 function h = createAxis(axisProperties)
801 fields = fieldnames(axisProperties);
804 if axisProperties.tics_direction == "bottom" then
806 elseif axisProperties.tics_direction == "top" then
808 elseif axisProperties.tics_direction == "left" then
810 elseif axisProperties.tics_direction == "right" then
812 elseif size(axisProperties.xtics_coord, "*") > 1 then
817 fields(fields=="tics_direction") = [];
819 drawaxis(x=axisProperties.xtics_coord,y=axisProperties.ytics_coord,dir=axisdir);
820 fields(fields=="xtics_coord") = [];
821 fields(fields=="ytics_coord") = [];
825 if axisProperties.clip_state=="on" then
826 set(h, "clip_box", axisProperties.clip_box)
828 set(h, "clip_state", axisProperties.clip_state);
829 fields(fields=="clip_box") = [];
830 fields(fields=="clip_state") = [];
832 for i = 1:size(fields, "*")
833 set(h, fields(i), axisProperties(fields(i)));
840 function h = createuimenu(uimenuProperties)
841 fields = fieldnames(uimenuProperties);
846 for i = 1:size(fields, "*")
847 if fields(i) == "children" then
848 children = createMatrixHandle(uimenuProperties(fields(i)));
849 for k=1:size(children, "*")
850 set(children(k), "parent", h);
853 set(h, fields(i), uimenuProperties(fields(i)));
861 function h = createuicontextmenu(uicontextmenuProperties)
862 fields = fieldnames(uicontextmenuProperties);
867 for i = 1:size(fields, "*")
868 if fields(i) == "children" then
869 children = createMatrixHandle(uicontextmenuProperties(fields(i)));
870 for k=1:size(children, "*")
871 set(children(k), "parent", h);
874 set(h, fields(i), uicontextmenuProperties(fields(i)));
882 function h = createuicontrol(uicontrolProperties)
883 fields = fieldnames(uicontrolProperties);
886 if or(fields=="scrollable") then
887 // Properties added in Scilab 5.5.0
888 // - scrollable must be set at creation (for frames)
889 // - constraints & margins must be set before parent
890 h = uicontrol("style", uicontrolProperties.style, ...
891 "scrollable", uicontrolProperties.scrollable, ...
892 "constraints", uicontrolProperties.constraints, ...
893 "margins", uicontrolProperties.margins);
894 fields(fields=="scrollable") = [];
895 fields(fields=="constraints") = [];
896 fields(fields=="margins") = [];
897 h.layout_options = uicontrolProperties.layout_options;
898 fields(fields=="layout_options") = [];
899 h.layout = uicontrolProperties.layout;
900 fields(fields=="layout") = [];
902 h = uicontrol("style", uicontrolProperties.style);
904 fields(fields=="style") = [];
906 for i = 1:size(fields, "*")
907 if fields(i) == "children" then
908 children = createMatrixHandle(uicontrolProperties(fields(i)));
909 for k=1:size(children, "*")
910 set(children(k), "parent", h);
913 set(h, fields(i), uicontrolProperties(fields(i)));
921 function h = createLight(lightProperties)
922 fields = fieldnames(lightProperties);
926 fields(fields=="children") = [];
928 for i = 1:size(fields, "*")
929 set(h, fields(i), lightProperties(fields(i)));
933 // Utility function for legends, copy/paste from %h_load
934 function links=getlinksfrompath(ax,paths)
935 // ax is a handle on an axes entity
936 // paths a list or row vector which gives the set of paths relative to
942 p(1)=p(1)-1// the caption does not exist yet
943 for kp=1:size(p,"*"),
944 if or(e.type==["Axes","Compound"])&p(kp)<=size(e.children,"*") then
961 function macro = createMacro(macroStr, macroName)
962 macroSt = macroStr(3);
963 header = strsubst(macroSt(1), "function ", "");
964 body = macroSt(2:$-1);
969 execstr("macro = " + macroName);
973 for i = 1:size(%__varnameList__, "*")
974 varargout(i) = %__convertVariable__(evstr(%__varnameList__(i)), %__varnameList__(i));
975 //printf("add %s: type %s become %s\n", %__varnameList__(i), typeof(evstr(%__varnameList__(i))), typeof(varargout(i)));