diff options
Diffstat (limited to 'modules/io/macros')
23 files changed, 2557 insertions, 0 deletions
diff --git a/modules/io/macros/%_save.bin b/modules/io/macros/%_save.bin Binary files differnew file mode 100755 index 000000000..9e9638f39 --- /dev/null +++ b/modules/io/macros/%_save.bin diff --git a/modules/io/macros/%_save.sci b/modules/io/macros/%_save.sci new file mode 100755 index 000000000..5aac5faf8 --- /dev/null +++ b/modules/io/macros/%_save.sci @@ -0,0 +1,1047 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - DIGITEO - Antoine ELIAS +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +//2012/08/06 transform macros to string to save it + +//called by save function, transform handle in tlist and save result +function [] = %_save(%__filename__, varargin) + + function result = isList(var) + + //15 : list + //16 : tlist + //17 : mlist + if or(type(var) == [15, 16, 17]) then + result = %t; + else + result = %f; + end + endfunction + + function result = isMacro(var) + //11 : sci_u_function + if or(type(var) == [11]) then + result = %t; + else + result = %f; + end + endfunction + + function result = isCompiledMacro(var) + //11 : sci_c_function + if or(type(var) == [13]) then + result = %t; + else + result = %f; + end + endfunction + + function result = inspectList(l) + if typeof(l)=="list" then + result = list(); + for %__i__ = definedfields(l) + if typeof(l(%__i__)) == "handle" then + if ~is_handle_valid(l(%__i__)) then + oldMode = warning("query"); + warning("on"); + warning(msprintf(gettext("%s: handle no more valid ignored.\n"), "save")); + warning(oldMode); + result(%__i__) = []; + else + result(%__i__) = extractMatrixHandle(l(%__i__)); + end + elseif isMacro(l(%__i__)) | isCompiledMacro(l(%__i__)) then + //build an arbitrary name to the macro + result(%__i__) = extractMacro(l(%__i__), "function"); + elseif isList(l(%__i__)) then + result(%__i__) = inspectList(l(%__i__)); + elseif type(l(%__i__)) == 14 then //library, must not be save + result(%__i__) = []; + else + result(%__i__) = l(%__i__); + end + end + else + fieldNb = size(getfield(1, l), "*"); + for kField = 2:fieldNb // Do not inspect first field (field names) + fieldValue = getfield(kField, l); + if typeof(fieldValue) == "handle" then + fieldValue = extractMatrixHandle(fieldValue); + elseif isMacro(fieldValue) | isCompiledMacro(fieldValue) then + //build an arbitrary name to the macro + fieldValue = extractMacro(fieldValue, "function"); + elseif isList(fieldValue) then + fieldValue = inspectList(fieldValue); + end + setfield(kField, fieldValue, l); + end + result = l; + end + endfunction + + function matrixHandle = extractMatrixHandle(h) + + if typeof(h) <> "handle" then + matrixHandle = []; + return; + end + + matrixHandle = tlist(["ScilabMatrixHandle", "dims", "values"]); + matrixHandle.dims = size(h); + matrixHandle.values = list(); + for %__i__ = 1:size(h, "*") + matrixHandle.values($+1) = extractSingleHandle(h(%__i__)); + if or(fieldnames(matrixHandle.values($))=="user_data") then + if isList(matrixHandle.values($).user_data) then + matrixHandle.values($).user_data = inspectList(matrixHandle.values($).user_data) + elseif typeof(matrixHandle.values($).user_data) == "handle" then + matrixHandle.values($).user_data = extractMatrixHandle(matrixHandle.values($).user_data) + end + end + end + endfunction + + + function item = extractSingleHandle(h) + + select h.type + case "Figure" + item = extractFigure(h); + case "Axes" + item = extractAxes(h); + case "Polyline" + item = extractPolyline(h); + case "Plot3d" + item = extractPlot3d(h); + case "Fac3d" + item = extractFac3d(h); + case "Compound" + item = extractCompound(h); + case "Rectangle" + item = extractRectangle(h); + case "Arc" + item = extractArc(h); + case "Champ" + item = extractChamp(h); + case "Segs" + item = extractSegs(h); + case "Grayplot" + item = extractGrayplot(h); + case "Matplot" + item = extractMatplot(h); + case "Fec" + item = extractFec(h); + case "Legend" + item = extractLegend(h); + case "Text" + item = extractText(h); + case "Axis" + item = extractAxis(h); + case "uimenu" + item = extractuimenu(h); + case "uicontextmenu" + item = extractuicontextmenu(h); + case "uicontrol" + item = extractuicontrol(h); + case "Datatip" + item = extractDatatip(h); + case "Light" + item = extractLight(h); + else + error("handle of type " + h.type + " unhandled"); + item = []; + end + endfunction + + // + // FIGURE + // + function returnedFigure = extractFigure(h) + returnedFigure = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "figure_position", ... + "figure_size", ... + "axes_size", ... + "viewport", ... + "info_message", ... + "tag", ... + "auto_resize", ... + "figure_name", ... + "figure_id", ... + "color_map", ... + "pixel_drawing_mode", ... + "anti_aliasing", ... + "immediate_drawing", ... + "background", ... + "rotation_style", ... + "event_handler", ... + "event_handler_enable", ... + "resizefcn", ... + "closerequestfcn", ... + "resize", ... + "toolbar", ... + "toolbar_visible", ... + "menubar", ... + "menubar_visible", ... + "infobar_visible", ... + "dockable", ... + "layout", ... + "layout_options", ... + "default_axes", ... + "icon", ... + "children", ... + "user_data"]); + + fields = fieldnames(returnedFigure); + + for %__i__ = 1:size(fields, "*") + if fields(%__i__) == "children" then + returnedFigure(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))); + else + returnedFigure(fields(%__i__)) = h(fields(%__i__)); + end + end + endfunction + + // + // LABEL + // + function returnedLabel = extractLabel(h) + returnedLabel = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "text", ... + "font_foreground", ... + "foreground", ... + "background", ... + "fill_mode", ... + "font_style", ... + "font_size", ... + "fractional_font", ... + "font_angle", ... + "auto_rotation", ... + "position", ... + "auto_position"]); + + fields = fieldnames(returnedLabel); + + for %__i__ = 1:size(fields, "*") + returnedLabel(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // TICKS + // + function returnedTicks = extractTicks(ticks) + returnedTicks = tlist([ + "Ticks", ... + "locations", ... + "labels"]); + + fields = fieldnames(returnedTicks); + + for %__i__ = 1:size(fields, "*") + returnedTicks(fields(%__i__)) = ticks(fields(%__i__)); + end + endfunction + + // + // AXES + // + function returnedAxes = extractAxes(h) + returnedAxes = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "axes_visible", ... + "axes_reverse", ... + "grid", ... + "grid_position", ... + "grid_thickness", ... + "grid_style", ... + "x_location", ... + "y_location", ... + "view", ... + "title", ... + "x_label", ... + "y_label", ... + "z_label", ... + "auto_ticks", ... + "x_ticks", ... + "y_ticks", ... + "z_ticks", ... + "ticks_format", ... + "ticks_st", ... + "box", ... + "filled", ... + "sub_tics", ... + "font_style", ... + "font_size", ... + "font_color", ... + "fractional_font", ... + "isoview", ... + "cube_scaling", ... + "rotation_angles", ... + "log_flags", ... + "tight_limits", ... + "data_bounds", ... + "zoom_box", ... + "margins", ... + "auto_margins", ... + "axes_bounds", ... + "auto_clear", ... + "auto_scale", ... + "hidden_axis_color", ... + "arc_drawing_method", ... + "hiddencolor", ... + "line_mode", ... + "line_style", ... + "thickness", ... + "mark_mode", ... + "mark_style", ... + "mark_size", ... + "mark_size_unit", ... + "mark_foreground", ... + "mark_background", ... + "foreground", ... + "background", ... + "clip_state", ... + "clip_box", ... + "children", ... + "user_data"]); + + fields = fieldnames(returnedAxes); + + for %__i__ = 1:size(fields, "*") + if or(fields(%__i__) == ["title","x_label","y_label","z_label"]) then + returnedAxes(fields(%__i__)) = extractLabel(h(fields(%__i__))); + elseif or(fields(%__i__) == ["x_ticks", "y_ticks", "z_ticks"]) then + returnedAxes(fields(%__i__)) = extractTicks(h(fields(%__i__))); + elseif fields(%__i__) == "children" then + returnedAxes(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))); + else + returnedAxes(fields(%__i__)) = h(fields(%__i__)); + end + end + endfunction + + // + // POLYLINE + // + function returnedPolyline = extractPolyline(h) + returnedPolyline = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "datatips", ... + "display_function", ... + "display_function_data", ... + "data", ... + "closed", ... + "line_mode", ... + "fill_mode", ... + "line_style", ... + "thickness", ... + "arrow_size_factor", ... + "polyline_style", ... + "interp_color_vector", ... + "interp_color_mode", ... + "mark_mode", ... + "mark_style", ... + "mark_size", ... + "mark_size_unit", ... + "foreground", ... + "background", ... + "mark_foreground", ... + "mark_background", ... + "mark_offset", ... + "mark_stride", ... + "x_shift", ... + "y_shift", ... + "z_shift", ... + "bar_width", ... + "clip_state", ... + "clip_box", ... + "user_data"]); + + fields = fieldnames(returnedPolyline); + + for %__i__ = 1:size(fields, "*") + if or(fields(%__i__) == ["children", "datatips"]) then + returnedPolyline(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))); + else + returnedPolyline(fields(%__i__)) = h(fields(%__i__)); + end + end + endfunction + + // + // PLOT3D + // + function returnedPlot3d = extractPlot3d(h) + returnedPlot3d = extractSurface(h); + endfunction + + // + // FAC3D + // + function returnedFac3d = extractFac3d(h) + returnedFac3d = extractSurface(h); + endfunction + + // + // SURFACE + // + function returnedSurface = extractSurface(h) + returnedSurface = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "surface_mode", ... + "foreground", ... + "thickness", ... + "mark_mode", ... + "mark_style", ... + "mark_size", ... + "mark_size_unit", ... + "mark_foreground", ... + "mark_background", ... + "color_mode", ... + "color_flag", ... + "data", ... + "color_flag", ... + "ambient_color", ... + "diffuse_color", ... + "specular_color", ... + "use_color_material", ... + "material_shininess", ... + "hiddencolor", ... + "clip_state", ... + "clip_box", ... + "user_data", ... + "cdata_mapping"]); + + fields = fieldnames(returnedSurface); + + for %__i__ = 1:size(fields, "*") + if fields(%__i__)=="cdata_mapping" then + if h.type=="Fac3d" then + returnedSurface(fields(%__i__)) = h(fields(%__i__)); + end + else + returnedSurface(fields(%__i__)) = h(fields(%__i__)); + end + end + endfunction + + // + // COMPOUND + // + function returnedCompound = extractCompound(h) + returnedCompound = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "children", ... + "user_data"]); + + fields = fieldnames(returnedCompound); + + for %__i__ = 1:size(fields, "*") + if fields(%__i__) == "children" then + returnedCompound(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))); + else + returnedCompound(fields(%__i__)) = h(fields(%__i__)); + end + end + endfunction + + // + // RECTANGLE + // + function returnedRectangle = extractRectangle(h) + returnedRectangle = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "thickness", ... + "mark_mode", ... + "mark_style", ... + "mark_size", ... + "mark_size_unit", ... + "mark_foreground", ... + "mark_background", ... + "line_mode", ... + "line_style", ... + "fill_mode", ... + "foreground", ... + "background", ... + "data", ... + "clip_state", ... + "clip_box", ... + "user_data"]); + + fields = fieldnames(returnedRectangle); + + for %__i__ = 1:size(fields, "*") + returnedRectangle(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // ARC + // + function returnedArc = extractArc(h) + returnedArc = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "thickness", ... + "line_style", ... + "line_mode", ... + "fill_mode", ... + "foreground", ... + "background", ... + "data", ... + "arc_drawing_method", ... + "clip_state", ... + "clip_box", ... + "user_data"]); + + fields = fieldnames(returnedArc); + + for %__i__ = 1:size(fields, "*") + returnedArc(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // CHAMP + // + function returnedChamp = extractChamp(h) + returnedChamp = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "data", ... + "line_style", ... + "thickness", ... + "colored", ... + "arrow_size", ... + "clip_state", ... + "clip_box", ... + "user_data"]); + + fields = fieldnames(returnedChamp); + + for %__i__ = 1:size(fields, "*") + returnedChamp(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // SEG + // + function returnedSeg = extractSegs(h) + returnedSeg = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "data", ... + "line_mode", ... + "line_style", ... + "thickness", ... + "segs_color", ... + "mark_mode", ... + "mark_style", ... + "mark_size", ... + "mark_size_unit", ... + "mark_foreground", ... + "mark_background", ... + "clip_state", ... + "clip_box", ... + "user_data"]); + + fields = fieldnames(returnedSeg); + + for %__i__ = 1:size(fields, "*") + returnedSeg(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // GRAYPLOT + // + function returnedGrayplot = extractGrayplot(h) + returnedGrayplot = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "data", ... + "data_mapping", ... + "clip_state", ... + "clip_box", ... + "user_data"]); + + fields = fieldnames(returnedGrayplot); + + for %__i__ = 1:size(fields, "*") + returnedGrayplot(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // MATPLOT + // + function returnedMatplot = extractMatplot(h) + returnedMatplot = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "data", ... + "rect", ... + "image_type", ... + "clip_state", ... + "clip_box", ... + "user_data"]); + + fields = fieldnames(returnedMatplot); + + for %__i__ = 1:size(fields, "*") + returnedMatplot(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // FEC + // + function returnedFec = extractFec(h) + returnedFec = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "data", ... + "triangles", ... + "z_bounds", ... + "color_range", ... + "outside_colors", ... + "line_mode", ... + "foreground", ... + "clip_state", ... + "clip_box", ... + "user_data"]); + + fields = fieldnames(returnedFec); + + for %__i__ = 1:size(fields, "*") + returnedFec(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // LEGEND + // + function returnedLegend = extractLegend(h) + returnedLegend = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "text", ... + "font_style", ... + "font_size", ... + "font_color", ... + "fractional_font", ... + "links", ... + "legend_location", ... + "position", ... + "line_width", ... + "line_mode", ... + "thickness", ... + "foreground", ... + "fill_mode", ... + "background", ... + "marks_count", ... + "clip_state", ... + "clip_box", ... + "user_data", .. + "paths"]); + + fields = fieldnames(returnedLegend); + + for %__i__ = 1:size(fields, "*") + if fields(%__i__) == "links" then + returnedLegend(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))); + elseif fields(%__i__) == "paths" then + p = list(); + for kl=1:size(h.links,"*"); + p($+1) = get_entity_path(h.links(kl)); + end + returnedLegend(fields(%__i__)) = p; + else + returnedLegend(fields(%__i__)) = h(fields(%__i__)); + end + end + endfunction + + // + // TEXT + // + function returnedText = extractText(h) + returnedText = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "text", ... + "data", ... + "text_box", ... + "text_box_mode", ... + "foreground", ... + "font_style", ... + "font_size", ... + "font_angle", ... + "box", ... + "line_mode", ... + "fill_mode", ... + "font_foreground", ... + "background", ... + "alignment", ... + "fractional_font", ... + "clip_state", ... + "clip_box", ... + "user_data"]); + + fields = fieldnames(returnedText); + + for %__i__ = 1:size(fields, "*") + returnedText(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // DATATIP + // + function returnedDatatip = extractDatatip(h) + returnedDatatip = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "data", ... + "box_mode", ... + "label_mode", ... + "orientation", ... + "z_component", ... + "auto_orientation", ... + "interp_mode", ... + "display_function", ... + "font_foreground", ... + "foreground", ... + "background", ... + "mark_mode", ... + "mark_style", ... + "mark_size_unit", ... + "mark_size", ... + "mark_foreground", ... + "mark_background", ... + "user_data", ... + ]); + + fields = fieldnames(returnedDatatip); + + for %__i__ = 1:size(fields, "*") + returnedDatatip(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // AXIS + // + function returnedAxis = extractAxis(h) + returnedAxis = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "tics_direction", ... + "xtics_coord", ... + "ytics_coord", ... + "tics_color", ... + "tics_segment", ... + "tics_style", ... + "sub_tics", ... + "tics_labels", ... + "labels_font_size", ... + "labels_font_color", ... + "fractional_font", ... + "clip_state", ... + "clip_box", ... + "user_data"]); + + fields = fieldnames(returnedAxis); + + for %__i__ = 1:size(fields, "*") + returnedAxis(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // + // uimenu + // + function returneduimenu = extractuimenu(h) + returneduimenu = tlist([ + "ScilabSingleHandle", ... + "type", ... + "enable", ... + "foregroundcolor", ... + "label", ... + "visible", ... + "callback", ... + "callback_type", ... + "tag", ... + "checked", ... + "children", ... + "icon", ... + "user_data"]); + + fields = fieldnames(returneduimenu); + + for %__i__ = 1:size(fields, "*") + if fields(%__i__) == "children" then + returneduimenu(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))); + else + returneduimenu(fields(%__i__)) = h(fields(%__i__)); + end + end + endfunction + + // + // UICONTEXTMENU + // + function returneduicontextmenu = extractuicontextmenu(h) + returneduicontextmenu = tlist([ + "ScilabSingleHandle", ... + "type", ... + "children"]); + + fields = fieldnames(returneduicontextmenu); + + for %__i__ = 1:size(fields, "*") + if fields(%__i__) == "children" then + returneduicontextmenu(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))); + else + returneduicontextmenu(fields(%__i__)) = h(fields(%__i__)); + end + end + endfunction + + // + // uicontrol + // + function returneduicontrol = extractuicontrol(h) + returneduicontrol = tlist([ + "ScilabSingleHandle", ... + "type", ... + "style", ... + "backgroundcolor", ... + "enable", ... + "fontangle", ... + "fontname", ... + "fontsize", ... + "fontunits", ... + "fontweight", ... + "foregroundcolor", ... + "horizontalalignment", ... + "listboxtop", ... + "max", ... + "min", ... + "position", ... + "relief", ... + "sliderstep", ... + "string", ... + "tooltipstring", ... + "units", ... + "value", ... + "verticalalignment", ... + "visible", ... + "callback", ... + "callback_type", ... + "layout", ... + "layout_options", ... + "constraints", ... + "border", ... + "margins", ... + "groupname", ... + "scrollable", ... + "icon", ... + "user_data", ... + "tag", ... + "children"]); + + fields = fieldnames(returneduicontrol); + + for %__i__ = 1:size(fields, "*") + if fields(%__i__) == "children" then + returneduicontrol(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))); + else + returneduicontrol(fields(%__i__)) = h(fields(%__i__)); + end + end + endfunction + + // + // LIGHT + // + function returnedLight = extractLight(h) + returnedLight = tlist([ + "ScilabSingleHandle", ... + "type", ... + "visible", ... + "light_type", ... + "position", ... + "direction", ... + "ambient_color", ... + "diffuse_color", ... + "specular_color"]); + + fields = fieldnames(returnedLight); + + for %__i__ = 1:size(fields, "*") + returnedLight(fields(%__i__)) = h(fields(%__i__)); + end + endfunction + + // Utility function for legends, copy/paste from %h_load + function p=get_entity_path(e) + // given a handle e on an entity this function returns its path relative + // to its parent axes. + // the path is a vector of child index. + p=[]; + parent=e.parent; + + while %t + pos=find(parent.children==e,1) + if pos==[] then + error(msprintf(_("%s : Invalid entity %s\n"),"save","Legend")) + end + p=[pos p] + if parent.type=="Axes" then + break + end + e=parent + parent=e.parent; + end + endfunction + + function macro = extractMacro(macroPtr, macroName) + macroSt = fun2string(macroPtr, macroName); + oldMode = warning("query"); + warning("off"); + macro = tlist("ScilabMacro", isCompiledMacro(macroPtr), macroSt); + warning(oldMode); + endfunction + + //main + + //save environment + if size(varargin) == 0 then + %__excludeList__ = [ + "%_save" + "isList" + "isMacro" + "isCompiledMacro" + "inspectList" + "extractMatrixHandle" + "extractSingleHandle" + "extractFigure" + "extractLabel" + "extractTicks" + "extractAxes" + "extractPolyline" + "extractPlot3d" + "extractFac3d" + "extractSurface" + "extractCompound" + "extractRectangle" + "extractArc" + "extractChamp" + "extractSegs" + "extractGrayplot" + "extractMatplot" + "extractFec" + "extractLegend" + "extractText" + "extractAxis" + "extractuimenu" + "extractuicontextmenu" + "extractuicontrol" + "get_entity_path" + "extractMacro" + "%__excludeList__" + "%__filename__" + "varargin" + "%__varList__"]; + + //get all user variables + %__varList__ = who_user(%f); + //remove exclude variables/functions + %__grepResult__ = grep(%__varList__, %__excludeList__); + %__varList__(%__grepResult__) = []; + for %__i__ = 1:size(%__varList__, "*") + //store them as input arguments + varargin(%__i__) = %__varList__(%__i__); + end + end + + oldMode = warning("query"); + warning("off"); + + if size(varargin) == 0 then + end + + for %__i__ = size(varargin):-1:1 + + if varargin(%__i__) == "-append" then + continue; + end + + %__temp__ = evstr(varargin(%__i__)); + + if isList(%__temp__) then + //list container + value = inspectList(%__temp__); + //update + execstr(varargin(%__i__) + " = value"); + elseif typeof(%__temp__) == "handle" then + if ~is_handle_valid(%__temp__) then // Invalid handle ignored + warning(oldMode); + warning(msprintf(gettext("%s: handle no more valid ignored.\n"), "save")); + warning("off"); + varargin(%__i__) = null(); + else //convert handle to tlist + value = extractMatrixHandle(%__temp__); + //update + execstr(varargin(%__i__) + " = value"); + end + elseif isMacro(%__temp__) | isCompiledMacro(%__temp__) then + //convert macro to tlist + value = extractMacro(%__temp__, varargin(%__i__)); + //update + execstr(varargin(%__i__) + " = value"); + elseif type(%__temp__) == 14 then //library, must not be save + varargin(%__i__) = null(); + end + end + warning(oldMode); + + //if size(varargin) == 0, create an empty file + result = export_to_hdf5(%__filename__, varargin(:)); + +endfunction diff --git a/modules/io/macros/%_sodload.bin b/modules/io/macros/%_sodload.bin Binary files differnew file mode 100755 index 000000000..6532e106c --- /dev/null +++ b/modules/io/macros/%_sodload.bin diff --git a/modules/io/macros/%_sodload.sci b/modules/io/macros/%_sodload.sci new file mode 100755 index 000000000..308c44dd7 --- /dev/null +++ b/modules/io/macros/%_sodload.sci @@ -0,0 +1,992 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - DIGITEO - Antoine ELIAS +// Copyright (C) 2012 - DIGITEO - Vincent COUVERT +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +function %_sodload(%__filename__, varargin) + + function v = getScilabFileVersion(%__filename__) + verStr = h5readattr(%__filename__, "/", "SCILAB_scilab_version") + [a,b,c,d] = regexp(verStr, "/scilab-.*(\d)\.(\d)\.(\d)/"); + if size(d, "*") == 3 then + v = evstr(d(1)) * 100 + evstr(d(2)) * 10 + evstr(d(3)); + else + error("unable to find file version: %s", %__filename__); + end + endfunction + + function [varValues] = %__convertVariable__(varValues, varNames) + for i = 1:size(varValues) + if typeof(varValues(i)) == "ScilabMatrixHandle" then + //convert tlist to handle + varValues(i) = createMatrixHandle(varValues(i)); + elseif typeof(varValues(i)) == "ScilabMacro" then + //convert tlist to macro + varValues(i) = createMacro(varValues(i), varNames(i)); + elseif isList(varValues(i)) then + //list container + varValues(i) = parseList(varValues(i)); + end + end + endfunction + + function result = isList(var) + //15 : list + //16 : tlist + //17 : mlist + if or(type(var) == [15, 16, 17]) then + result = %t; + else + result = %f; + end + endfunction + + function varValue = parseList(varValue) + if typeof(varValue)=="list" then + for i = definedfields(varValue) + if typeof(varValue(i)) == "ScilabMatrixHandle" then + varValue(i) = createMatrixHandle(varValue(i)); + elseif typeof(varValue(i)) == "ScilabMacro" then + //convert tlist to macro + varValue(i) = createMacro(varValue(i), "function"); + elseif isList(varValue(i)) then + varValue(i) = parseList(varValue(i)); + else + varValue(i) = varValue(i); + end + end + else + fieldNb = size(getfield(1, varValue), "*"); + for kField = 2:fieldNb // Do not inspect first field (field names) + fieldValue = getfield(kField, varValue); + if typeof(fieldValue) == "ScilabMatrixHandle" then + fieldValue = createMatrixHandle(fieldValue); + elseif typeof(fieldValue) == "ScilabMacro" then + //convert tlist to macro + fieldValue = createMacro(fieldValue, "function"); + elseif isList(fieldValue) then + fieldValue = parseList(fieldValue); + end + setfield(kField, fieldValue, varValue); + end + end + endfunction + + function h = createMatrixHandle(matrixHandle) + h = []; + if typeof(matrixHandle) <> "ScilabMatrixHandle" then + return; + end + + for i = prod(matrixHandle.dims):-1:1 + + newItem = createSingleHandle(matrixHandle.values(i)); + if newItem == [] then + continue; + end + + h($+1) = newItem; + if or(fieldnames(matrixHandle.values(i))=="user_data") then // TODO Remove after graphic branch merge + if isList(matrixHandle.values(i).user_data) then + set(h($), "user_data", parseList(matrixHandle.values(i).user_data)); + elseif typeof(matrixHandle.values(i).user_data) == "ScilabMatrixHandle" then + set(h($), "user_data", createMatrixHandle(matrixHandle.values(i).user_data)); + end + end + end + endfunction + + function h = createSingleHandle(item) + select item.type + case "Figure" + h = createFigure(item); + case "Axes" + h = createAxes(item); + case "Polyline" + h = createPolyline(item); + case "Plot3d" + h = createPlot3d(item); + case "Fac3d" + h = createFac3d(item); + case "Compound" + h = createCompound(item); + case "Rectangle" + h = createRectangle(item); + case "Arc" + h = createArc(item); + case "Champ" + h = createChamp(item); + case "Segs" + h = createSegs(item); + case "Grayplot" + h = createGrayplot(item); + case "Matplot" + h = createMatplot(item); + case "Fec" + h = createFec(item); + case "Legend" + h = createLegend(item); + case "Text" + h = createText(item); + case "Axis" + h = createAxis(item); + case "uimenu" + h = createuimenu(item); + case "uicontextmenu" + h = createuicontextmenu(item); + case "uicontrol" + h = createuicontrol(item); + case "Datatip" + h = createDatatip(item); + case "Light" + h = createLight(item); + else + error("handle of type " + item.type + " unhandled"); + h = []; + end + endfunction + + // + // FIGURE + // + function h = createFigure(figureProperties) + fields = fieldnames(figureProperties); + fields(1) = []; + + if or(fields=="resize") then + if figureProperties.menubar<>"figure" .. + | figureProperties.toolbar<>"figure" .. + | figureProperties.dockable<>"on" .. + | figureProperties.default_axes<>"on" then + // File created by Scilab 5.5.0 or more + h = figure("menubar", figureProperties.menubar, ... + "toolbar", figureProperties.toolbar, ... + "dockable", figureProperties.dockable, ... + "default_axes", figureProperties.default_axes, ... + "visible", "off"); + h.background = -2; + fields(fields=="menubar") = []; + fields(fields=="toolbar") = []; + fields(fields=="dockable") = []; + fields(fields=="default_axes") = []; + fields(fields=="visible") = []; + else + [lnums, fnames] = where(); + ind = grep(fnames, "xload"); + xload_mode = (ind ~= []); + if xload_mode then // See bug #3975 + h = gcf(); + else + h = scf(); + end + h.visible = "off"; + end + else + if isempty(winsid()) then + h = figure("visible", "off"); + h.background = -2; + else + h = gcf(); + h.visible = "off"; + end + end + + // Following propeties will be set after all other ones + isVisible = figureProperties.visible; + fields(fields=="visible") = []; + resizefcn = figureProperties.resizefcn; + fields(fields=="resizefcn") = []; + event_handler = figureProperties.event_handler; + fields(fields=="event_handler") = []; + + // Ignore figure_id + fields(fields=="figure_id") = []; + + h.figure_position=figureProperties.figure_position; + fields(fields=="figure_position") = []; + // set auto_resize first otherwise viewport modification may not have any effect. + h.auto_resize = figureProperties.auto_resize; + fields(fields=="auto_resize") = []; + h.figure_size = figureProperties.figure_size; + fields(fields=="figure_size") = []; + // set axes_size last because it's more important than figure_size + h.axes_size = figureProperties.axes_size; + fields(fields=="axes_size") = []; + + for i = 1:size(fields, "*") + if fields(i) == "children" then + c = figureProperties(fields(i)); + s = prod(c.dims); + createSingleHandle(c.values(s)); + for i = s-1:-1:1 + xsetech(wrect=[0 0 .1 .1]) + createSingleHandle(c.values(i)); + end + else + if fields(i)<>"pixmap" then // See bug #13310 + set(h, fields(i), figureProperties(fields(i))); + end + end + end + + h.resizefcn = resizefcn; + h.event_handler = event_handler; + h.visible = isVisible; + endfunction + + // + // LABEL + // + function h = createLabel(labelProperties, h) + fields = fieldnames(labelProperties); + fields(1) = []; + for i = 1:size(fields, "*") + set(h, fields(i), labelProperties(fields(i))); + end + endfunction + + // + // TICKS + // + function h = createTicks(ticksProperties) + h = tlist(["ticks","locations","labels"], [], []); + fields = fieldnames(ticksProperties); + for i = 1:size(fields, "*") + h(fields(i)) = ticksProperties(fields(i)); + end + endfunction + + // + // AXES + // + function h = createAxes(axesProperties) + // Hack to determine whether %h_load has been called by the %h_copy macro + // in which case a new Axes object is created + + [lnums, fnames] = where(); + ind = grep(fnames, "%h_copy"); + if ~isempty(ind) then + newaxes(); + end; + + h = gca(); + fields = fieldnames(axesProperties); + fields(1) = []; + + // Get log_flags to be sure to set them after data_bounds + log_flags = axesProperties.log_flags; + fields(fields=="log_flags") = []; + + // Get mark_mode to be sure to set it after mark_style + mark_mode = axesProperties.mark_mode; + fields(fields=="mark_mode") = []; + + // Get auto_ticks to be sure to set it after ticks labels + auto_ticks = axesProperties.auto_ticks; + fields(fields=="auto_ticks") = []; + automargins = %f; + if isfield(axesProperties, "auto_margins") then + auto_margins = axesProperties.auto_margins; + fields(fields=="auto_margins") = []; + automargins = %t; + end + + for i = 1:size(fields, "*") + if or(fields(i) == ["title","x_label","y_label","z_label"]) then + createLabel(axesProperties(fields(i)), h(fields(i))); + elseif or(fields(i) == ["x_ticks", "y_ticks", "z_ticks"]) then + set(h, fields(i), createTicks(axesProperties(fields(i)))); + elseif fields(i) == "children" then + createMatrixHandle(axesProperties(fields(i))); + elseif fields(i) == "clip_state" then + if axesProperties.clip_state=="on" then + set(h,"clip_box",axesProperties.clip_box); + end + set(h,"clip_state", axesProperties.clip_state); + elseif fields(i) == "clip_box" then + // managed with 'clip_state' + elseif fields(i) == "data_bounds" then + set(h, "data_bounds", axesProperties.data_bounds); + set(h, "log_flags", log_flags); + elseif fields(i) == "mark_style" then + set(h, "mark_style", axesProperties.mark_style); + set(h, "mark_mode", mark_mode); + else + set(h, fields(i), axesProperties(fields(i)));; + end + end + + set(h, "auto_ticks", auto_ticks); + if automargins then + set(h, "auto_margins", auto_margins); + end + + // Legend management + global %LEG + if ~isempty(%LEG) then + // Get handles from paths + links=getlinksfrompath(h, %LEG.paths) + if ~isempty(links) then + L = captions(links, %LEG.text) + L.visible = %LEG.visible + L.font_style = %LEG.font_style + L.font_size = %LEG.font_size + L.font_color = %LEG.font_color + L.fractional_font = %LEG.fractional_font + L.mark_mode = "off"; + L.legend_location = %LEG.legend_location + L.position = %LEG.position + L.line_mode = %LEG.line_mode + L.thickness = %LEG.thickness + L.foreground = %LEG.foreground + L.fill_mode = %LEG.fill_mode + L.background = %LEG.background + if %LEG.clip_state=="on" then + L.clip_box = %LEG.clip_box + end + L.clip_state = %LEG.clip_state + L.user_data = %LEG.user_data + else + warning(msprintf(_("%s: Legend does not fit with the current context. Skipped\n"), "load")); + end + end + clearglobal %LEG + + endfunction + + // + // POLYLINE + // + function h = createPolyline(polylineProperties) + fields = fieldnames(polylineProperties); + fields(1) = []; + + xpoly(polylineProperties.data(:,1), polylineProperties.data(:,2)) + + h = gce(); + + if polylineProperties.clip_state=="on" then + set(h, "clip_box", polylineProperties.clip_box) + end + set(h, "clip_state", polylineProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + if polylineProperties.interp_color_mode=="on" & ~isempty(polylineProperties.interp_color_vector) then + set(h, "interp_color_vector", polylineProperties.interp_color_vector); + set(h, "interp_color_mode", polylineProperties.interp_color_mode); + else + if ~isempty(polylineProperties.interp_color_vector) then + h.interp_color_vector = polylineProperties.interp_color_vector; + end + h.interp_color_mode = polylineProperties.interp_color_mode; + end + fields(fields=="interp_color_vector") = []; + fields(fields=="interp_color_mode") = []; + + // Get mark_mode to be sure to set it after mark_style + mark_mode = polylineProperties.mark_mode; + fields(fields=="mark_mode") = []; + + global %POLYLINE + %POLYLINE = h + + for i = 1:size(fields, "*") + if fields(i) == "mark_style" then + set(h, "mark_style", polylineProperties.mark_style); + set(h, "mark_mode", mark_mode); + elseif fields(i) == "children" then + createMatrixHandle(polylineProperties(fields(i))); + elseif fields(i) == "datatips" then + createMatrixHandle(polylineProperties(fields(i))); + else + h(fields(i)) = polylineProperties(fields(i)); + end + end + + clearglobal %POLYLINE + + endfunction + + // + // PLOT3D + // + function h = createPlot3d(plot3dProperties) + h = createSurface(plot3dProperties); + endfunction + + // + // FAC3D + // + function h = createFac3d(fac3dProperties) + h = createSurface(fac3dProperties); + endfunction + + // + // SURFACE + // + function h = createSurface(surfaceProperties) + fields = fieldnames(surfaceProperties); + fields(1) = []; + // plot3d modify the axes properties + // - Save it + // - Draw plot3d + // - Restore it + a=gca(); + rotation_angles = a.rotation_angles; + axes_visible = a.axes_visible; + box = a.box; + margins = a.margins; + x_label_visible = a.x_label.visible; + y_label_visible = a.y_label.visible; + z_label_visible = a.z_label.visible; + x_label_text = a.x_label.text; + y_label_text = a.y_label.text; + z_label_text = a.z_label.text; + axes_isoview = a.isoview; + + if (or(surfaceProperties.color_flag==[2 5]) & ~or(fields=="cdata_mapping")) | .. + ((surfaceProperties.color_flag>=2) & or(fields=="cdata_mapping")) then + plot3d1(surfaceProperties.data.x, surfaceProperties.data.y, list(surfaceProperties.data.z, surfaceProperties.data.color)) + else + plot3d(surfaceProperties.data.x,surfaceProperties.data.y,surfaceProperties.data.z) + end + fields(fields=="data") = []; + + // Restore this properties after plot3d. + a.rotation_angles = rotation_angles; + a.axes_visible = axes_visible; + a.box = box; + a.margins = margins; + a.x_label.visible = x_label_visible; + a.y_label.visible = y_label_visible; + a.z_label.visible = z_label_visible; + a.x_label.text = x_label_text; + a.y_label.text = y_label_text; + a.z_label.text = z_label_text; + a.isoview = axes_isoview; + + // Get mark_mode to be sure to set it after mark_style + mark_mode = surfaceProperties.mark_mode; + fields(fields=="mark_mode") = []; + + h=gce(); + + if or(fields=="cdata_mapping") then // Fac3d specific + if surfaceProperties.color_flag >= 2 then + set(h, "cdata_mapping", surfaceProperties.cdata_mapping); + end + fields(fields=="cdata_mapping") = []; + end + + if surfaceProperties.clip_state == "on" then + set(h,"clip_box", surfaceProperties.clip_box); + end + set(h,"clip_state",surfaceProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + for i = 1:size(fields, "*") + if fields(i) == "mark_style" then + set(h, "mark_style", surfaceProperties.mark_style); + set(h, "mark_mode", mark_mode); + else + h(fields(i)) = surfaceProperties(fields(i)); + end + end + endfunction + + // + // COMPOUND + // + function h = createCompound(compoundProperties) + fields = fieldnames(compoundProperties); + fields(1) = []; + + h = glue(createMatrixHandle(compoundProperties.children)); + fields(fields=="children") = []; + + for i = 1:size(fields, "*") + set(h, fields(i), compoundProperties(fields(i))); + end + endfunction + + // + // RECTANGLE + // + function h = createRectangle(rectangleProperties) + fields = fieldnames(rectangleProperties); + fields(1) = []; + + xrect(0,1,1,1); // create the rectangle with dummy values + h = gce(); + + if rectangleProperties.clip_state == "on" then + set(h,"clip_box", rectangleProperties.clip_box); + end + set(h,"clip_state",rectangleProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + // Get mark_mode to be sure to set it after mark_style + mark_mode = rectangleProperties.mark_mode; + fields(fields=="mark_mode") = []; + + for i = 1:size(fields, "*") + if fields(i) == "mark_style" then + set(h, "mark_style", rectangleProperties.mark_style); + set(h, "mark_mode", mark_mode); + else + h(fields(i)) = rectangleProperties(fields(i)); + end + end + endfunction + + // + // ARC + // + function h = createArc(arcProperties) + fields = fieldnames(arcProperties); + fields(1) = []; + + xarc(0,1,1,1,0,360); // create the arc with dummy values + h = gce(); + + if arcProperties.clip_state == "on" then + set(h,"clip_box", arcProperties.clip_box); + end + set(h,"clip_state",arcProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + for i = 1:size(fields, "*") + set(h, fields(i), arcProperties(fields(i))); + end + endfunction + + // + // CHAMP + // + function h = createChamp(champProperties) + fields = fieldnames(champProperties); + fields(1) = []; + + champ(champProperties.data.x, champProperties.data.y, champProperties.data.fx, champProperties.data.fy); + fields(fields=="data") = []; + + h=gce(); + + if champProperties.clip_state == "on" then + set(h,"clip_box", champProperties.clip_box); + end + set(h,"clip_state",champProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + for i = 1:size(fields, "*") + set(h, fields(i), champProperties(fields(i))); + end + endfunction + + // + // SEG + // + function h = createSegs(segsProperties) + fields = fieldnames(segsProperties); + fields(1) = []; + + xsegs(segsProperties.data(:,1), segsProperties.data(:,2)) + + h=gce() + + if segsProperties.clip_state == "on" then + set(h,"clip_box", segsProperties.clip_box); + end + set(h,"clip_state",segsProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + // Get mark_mode to be sure to set it after mark_style + mark_mode = segsProperties.mark_mode; + fields(fields=="mark_mode") = []; + + for i = 1:size(fields, "*") + if fields(i) == "mark_style" then + set(h, "mark_style", segsProperties.mark_style); + set(h, "mark_mode", mark_mode); + else + h(fields(i)) = segsProperties(fields(i)); + end + end + endfunction + + // + // GRAYPLOT + // + function h = createGrayplot(grayplotProperties) + fields = fieldnames(grayplotProperties); + fields(1) = []; + + grayplot(grayplotProperties.data.x, grayplotProperties.data.y, grayplotProperties.data.z); + fields(fields=="data") = []; + + h = gce(); + + if grayplotProperties.clip_state=="on" then + set(h, "clip_box", grayplotProperties.clip_box) + end + set(h, "clip_state", grayplotProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + for i = 1:size(fields, "*") + set(h, fields(i), grayplotProperties(fields(i))); + end + endfunction + + // + // MATPLOT + // + function h = createMatplot(matplotProperties) + fields = fieldnames(matplotProperties); + fields(1) = []; + + Matplot(matplotProperties.data); + fields(fields=="data") = []; + + h = gce(); + + if matplotProperties.clip_state=="on" then + set(h, "clip_box", matplotProperties.clip_box) + end + set(h, "clip_state", matplotProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + for i = 1:size(fields, "*") + set(h, fields(i), matplotProperties(fields(i))); + end + endfunction + + // + // FEC + // + function h = createFec(fecProperties) + fields = fieldnames(fecProperties); + fields(1) = []; + + fec(fecProperties.data(:,1), fecProperties.data(:,2), fecProperties.triangles, fecProperties.data(:,3)); + fields(fields=="data") = []; + fields(fields=="triangles") = []; + + h = unglue(gce()); + + if fecProperties.clip_state=="on" then + set(h, "clip_box", fecProperties.clip_box) + end + set(h, "clip_state", fecProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + for i = 1:size(fields, "*") + set(h, fields(i), fecProperties(fields(i))); + end + endfunction + + // + // LEGEND + // + function h = createLegend(legendProperties) + global %LEG + %LEG = legendProperties; + h = []; + endfunction + + // + // TEXT + // + function h = createText(textProperties) + fields = fieldnames(textProperties); + fields(1) = []; + + if textProperties.text_box_mode == "off" then + xstring(textProperties.data(1), textProperties.data(2), textProperties.text) + else + xstringb(textProperties.data(1), textProperties.data(2), textProperties.text, textProperties.text_box(1), textProperties.text_box(2)) + end + + h = gce(); + + if textProperties.clip_state=="on" then + set(h, "clip_box", textProperties.clip_box) + end + set(h, "clip_state", textProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + for i = 1:size(fields, "*") + set(h, fields(i), textProperties(fields(i))); + end + endfunction + + // + // DATATIP + // + function h = createDatatip(datatipProperties) + + fields = fieldnames(datatipProperties); + fields(1) = []; + + tip_data = datatipProperties("data"); + h = datatipCreate(%POLYLINE, tip_data); + + for i = 1:size(fields, "*") + if fields(i) == "data" then + continue; + end + + set(h, fields(i), datatipProperties(fields(i))); + end + endfunction + + // + // AXIS + // + function h = createAxis(axisProperties) + fields = fieldnames(axisProperties); + fields(1) = []; + + if axisProperties.tics_direction == "bottom" then + axisdir="d"; + elseif axisProperties.tics_direction == "top" then + axisdir="u"; + elseif axisProperties.tics_direction == "left" then + axisdir="l"; + elseif axisProperties.tics_direction == "right" then + axisdir="r"; + elseif size(axisProperties.xtics_coord, "*") > 1 then + axisdir="u"; + else + axisdir="l"; + end + fields(fields=="tics_direction") = []; + + drawaxis(x=axisProperties.xtics_coord,y=axisProperties.ytics_coord,dir=axisdir); + fields(fields=="xtics_coord") = []; + fields(fields=="ytics_coord") = []; + + h=gce() + + if axisProperties.clip_state=="on" then + set(h, "clip_box", axisProperties.clip_box) + end + set(h, "clip_state", axisProperties.clip_state); + fields(fields=="clip_box") = []; + fields(fields=="clip_state") = []; + + for i = 1:size(fields, "*") + set(h, fields(i), axisProperties(fields(i))); + end + endfunction + + // + // uimenu + // + function h = createuimenu(uimenuProperties) + fields = fieldnames(uimenuProperties); + fields(1) = []; + + h = uimenu(); + + for i = 1:size(fields, "*") + if fields(i) == "children" then + children = createMatrixHandle(uimenuProperties(fields(i))); + for k=1:size(children, "*") + set(children(k), "parent", h); + end + else + set(h, fields(i), uimenuProperties(fields(i))); + end + end + endfunction + + // + // UICONTEXTMENU + // + function h = createuicontextmenu(uicontextmenuProperties) + fields = fieldnames(uicontextmenuProperties); + fields(1) = []; + + h = uicontextmenu(); + + for i = 1:size(fields, "*") + if fields(i) == "children" then + children = createMatrixHandle(uicontextmenuProperties(fields(i))); + for k=1:size(children, "*") + set(children(k), "parent", h); + end + else + set(h, fields(i), uicontextmenuProperties(fields(i))); + end + end + endfunction + + // + // uicontrol + // + function h = createuicontrol(uicontrolProperties) + fields = fieldnames(uicontrolProperties); + fields(1) = []; + + if or(fields=="scrollable") then + // Properties added in Scilab 5.5.0 + // - scrollable must be set at creation (for frames) + // - contraints & margins must be set before parent + h = uicontrol("style", uicontrolProperties.style, ... + "scrollable", uicontrolProperties.scrollable, ... + "constraints", uicontrolProperties.constraints, ... + "margins", uicontrolProperties.margins); + fields(fields=="scrollable") = []; + fields(fields=="constraints") = []; + fields(fields=="margins") = []; + h.layout_options = uicontrolProperties.layout_options; + fields(fields=="layout_options") = []; + h.layout = uicontrolProperties.layout; + fields(fields=="layout") = []; + else + h = uicontrol("style", uicontrolProperties.style); + end + fields(fields=="style") = []; + + for i = 1:size(fields, "*") + if fields(i) == "children" then + children = createMatrixHandle(uicontrolProperties(fields(i))); + for k=1:size(children, "*") + set(children(k), "parent", h); + end + else + set(h, fields(i), uicontrolProperties(fields(i))); + end + end + endfunction + + // + // LIGHT + // + function h = createLight(lightProperties) + fields = fieldnames(lightProperties); + fields(1) = []; + + h = light(); + fields(fields=="children") = []; + + for i = 1:size(fields, "*") + set(h, fields(i), lightProperties(fields(i))); + end + endfunction + + // Utility function for legends, copy/paste from %h_load + function links=getlinksfrompath(ax,paths) + // ax is a handle on an axes entity + // paths a list or row vector which gives the set of paths relative to + // the axes + links=[]; + ok=%t; + for p=paths + e=ax; + p(1)=p(1)-1// the caption does not exists yet + for kp=1:size(p,"*"), + if or(e.type==["Axes","Compound"])&p(kp)<=size(e.children,"*") then + e=e.children(p(kp)), + else + ok=%f + break + end + end + if ~ok then + break + end + links=[links,e] + end + if ~ok then + links=[]; + end + endfunction + + function macro = createMacro(macroStr, macroName) + + macroSt = macroStr(3); + if macroStr(2) == %t then + flag = "c"; + else + flag = "n"; + end + header = strsubst(macroSt(1), "function ", ""); + body = macroSt(2:$-1); + if body == [] then + body = ""; + end + deff(header, body, flag); + execstr("macro = " + macroName); + endfunction + + [%__lhs__, %__rhs__] = argn(); + %__resumeList__ = list(); + %__resumeVarlist__ = []; + if %__rhs__ < 1 then + error(999, msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "load", 1)); + end + + if %__rhs__ >= 1 then + if typeof(%__filename__) <> "string" | size(%__filename__, "*") <> 1 then + error(999, msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "load", 1)); + end + end + + if isfile(%__filename__) & is_hdf5_file(%__filename__) then + %__loadFunction__ = import_from_hdf5; + //fileVersion = getScilabFileVersion(%__filename__); // Not needed for the moment + else + %__loadFunction__ = %_load; + end + + //multiple output variables to prevent listinfile prints + [%__variableList__, %__varB__, %__varC__, %__varD__] = listvarinfile(%__filename__); + // + if size(varargin) <> 0 then + for i = 1:size(varargin) + %__variableName__ = varargin(i); + if typeof(%__variableName__) <> "string" | size(%__variableName__, "*") <> 1 then + error(999, msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "load", i)); + end + + if or(%__variableList__ == %__variableName__) then + %__loadFunction__(%__filename__, %__variableName__); + %__resumeList__($+1) = evstr(%__variableName__); + %__resumeVarlist__($+1) = %__variableName__; + clear(%__variableName__); + else + error(999, msprintf(gettext("%s: variable ''%s'' does not exist in ''%s''.\n"), "load", %__variableName__, %__filename__)); + end + end + else + for i = 1:size(%__variableList__, "*") + %__variableName__ = %__variableList__(i); + %__loadFunction__(%__filename__, %__variableName__); + %__resumeList__($+1) = evstr(%__variableName__); + %__resumeVarlist__($+1) = %__variableName__; + clear(%__variableName__); + end + end + + if isfile(%__filename__) & is_hdf5_file(%__filename__) then + %__resumeList__ = %__convertVariable__(%__resumeList__, %__resumeVarlist__); + end + + execstr("[" + strcat(%__resumeVarlist__, ",") + "] = resume(%__resumeList__(:))"); +endfunction diff --git a/modules/io/macros/buildmacros.bat b/modules/io/macros/buildmacros.bat new file mode 100755 index 000000000..5df334e1e --- /dev/null +++ b/modules/io/macros/buildmacros.bat @@ -0,0 +1,11 @@ +rem Scilab ( http://mwww.scilab.org/ ) - This file is part of Scilab +rem Copyright (C) INRIA +rem +rem This file must be used under the terms of the CeCILL. +rem This source file is licensed as described in the file COPYING, which +rem you should have received as part of this distribution. The terms +rem are also available at +rem http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + + +@..\..\..\bin\scilex -nwni -ns -e exec('buildmacros.sce');quit;
\ No newline at end of file diff --git a/modules/io/macros/buildmacros.sce b/modules/io/macros/buildmacros.sce new file mode 100755 index 000000000..485166d0a --- /dev/null +++ b/modules/io/macros/buildmacros.sce @@ -0,0 +1,15 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2006-2008 - INRIA - Allan CORNET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +if (isdef("genlib") == %f) then + exec(SCI+"/modules/functions/scripts/buildmacros/loadgenlib.sce"); +end +//------------------------------------ +genlib("iolib","SCI/modules/io/macros",%f,%t); +//------------------------------------ diff --git a/modules/io/macros/cleanmacros.bat b/modules/io/macros/cleanmacros.bat new file mode 100755 index 000000000..768190a8b --- /dev/null +++ b/modules/io/macros/cleanmacros.bat @@ -0,0 +1,13 @@ +rem Scilab ( http://mwww.scilab.org/ ) - This file is part of Scilab +rem Copyright (C) INRIA +rem +rem This file must be used under the terms of the CeCILL. +rem This source file is licensed as described in the file COPYING, which +rem you should have received as part of this distribution. The terms +rem are also available at +rem http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + + +@del *.bin 2>NUL +@del lib 2>NUL +@del names 2>NUL
\ No newline at end of file diff --git a/modules/io/macros/getscilabkeywords.bin b/modules/io/macros/getscilabkeywords.bin Binary files differnew file mode 100755 index 000000000..e8108f8e9 --- /dev/null +++ b/modules/io/macros/getscilabkeywords.bin diff --git a/modules/io/macros/getscilabkeywords.sci b/modules/io/macros/getscilabkeywords.sci new file mode 100755 index 000000000..f37b81cfb --- /dev/null +++ b/modules/io/macros/getscilabkeywords.sci @@ -0,0 +1,41 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2005 - INRIA - Allan CORNET +// Copyright (C) 2009 - DIGITEO - Allan CORNET +// Based on E.Segre dynamickeywords.sce +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + +function list_keywords = getscilabkeywords() + + scilab_primitives = []; + scilab_commands = []; + predef_variables = []; + scilab_functions = []; + scicos_functions = []; + + [scilab_primitives, scilab_commands] = what(); + + // predefined variables + names = who("get"); + predef_variables = names(($-predef())+1:$); + + //library functions + libvar = librarieslist(); + + for i = 1:size(libvar,1) + scilab_functions = [scilab_functions; libraryinfo(libvar(i))]; + end + + //scicos basic functions: read the lib + if with_module("xcos") then + // TO DO: changes lib names with reorganization + scicos_functions = [libraryinfo("scicos_utilslib"); libraryinfo("scicos_autolib")]; + end + + list_keywords = list(scilab_primitives, scilab_commands, predef_variables, scilab_functions, scicos_functions); + +endfunction diff --git a/modules/io/macros/halt.bin b/modules/io/macros/halt.bin Binary files differnew file mode 100755 index 000000000..91f633bb6 --- /dev/null +++ b/modules/io/macros/halt.bin diff --git a/modules/io/macros/halt.sci b/modules/io/macros/halt.sci new file mode 100755 index 000000000..6d3fc2add --- /dev/null +++ b/modules/io/macros/halt.sci @@ -0,0 +1,39 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) XXXX-2008 - INRIA +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + + +function []=halt(varargin) + + //halt() stops execution until something is entered in the keyboard. + + [lhs,rhs] = argn(0); + + msg = "halt"; + + if (rhs > 0) then + + if rhs > 1 then + error(msprintf(gettext("%s: Wrong number of input argument.\n"),"halt")); + end + + if type(varargin(1)) <> 10 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"halt",1)); + end + + if size(varargin(1),"*") <> 1 then + error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"halt",1)); + end + + msg = string(varargin(1)); + end + + mprintf(msg); + mscanf("%c"); + +endfunction diff --git a/modules/io/macros/input.bin b/modules/io/macros/input.bin Binary files differnew file mode 100755 index 000000000..08f7d7e29 --- /dev/null +++ b/modules/io/macros/input.bin diff --git a/modules/io/macros/input.sci b/modules/io/macros/input.sci new file mode 100755 index 000000000..dd5ad0b0f --- /dev/null +++ b/modules/io/macros/input.sci @@ -0,0 +1,82 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) XXXX-2008 - INRIA +// Copyright (C) 2009-2010 - DIGITEO - Allan CORNET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + + +function [x] = input(msg, flag) + + [lhs,rhs] = argn(0); + + if rhs <> 1 & rhs <> 2 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "input", 1, 2)); + end + + if type(msg) <> 10 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"input",1)); + end + + if size(msg, "*") <> 1 then + error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"input",1)); + end + + // a tricky way to get all ascii codes sequences + fmt = "%[" + ascii(32) + "-" + ascii(254) + "]"; + + currentprompt = prompt(); + + if argn(2) == 2 then + if type(flag) <> 10 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"input",2)); + end + + if size(flag, "*") <> 1 then + error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"input",2)); + end + + if (flag <> "s" & flag <> "string") then + error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' value expected.\n"),"input",2,"string")); + end + + prompt(msg); + x = mscanf(fmt); + + currentpromptAfter = prompt(); + // bug 5513 + // we had change prompt during exec of input + // we recall input + if (currentpromptAfter <> currentprompt) then + x = input(msg, flag); + end + + else + while %t + prompt(msg); + x = mscanf(fmt); + + currentpromptAfter = prompt(); + // bug 5513 + // we had change prompt during exec of input + // we recall input + if (currentpromptAfter <> currentprompt) then + x = string(input(msg)); + end + + if (length(x) == 0) | (x == " ") then + x = "[]"; + end + ierr = execstr("x=" + x,"errcatch"); + if ierr == 0 then + break; + end + mprintf(strcat(lasterror(),"\n")); + end + + end + prompt(currentprompt); +endfunction diff --git a/modules/io/macros/lib b/modules/io/macros/lib Binary files differnew file mode 100755 index 000000000..b5ef2fa80 --- /dev/null +++ b/modules/io/macros/lib diff --git a/modules/io/macros/names b/modules/io/macros/names new file mode 100755 index 000000000..23e9230b2 --- /dev/null +++ b/modules/io/macros/names @@ -0,0 +1,9 @@ +%_save +%_sodload +getscilabkeywords +halt +input +unix_g +unix_s +unix_w +unix_x diff --git a/modules/io/macros/unix_g.bin b/modules/io/macros/unix_g.bin Binary files differnew file mode 100755 index 000000000..fcfa5b0fe --- /dev/null +++ b/modules/io/macros/unix_g.bin diff --git a/modules/io/macros/unix_g.sci b/modules/io/macros/unix_g.sci new file mode 100755 index 000000000..d00e5c276 --- /dev/null +++ b/modules/io/macros/unix_g.sci @@ -0,0 +1,115 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) XXXX-2008 - INRIA +// Copyright (C) XXXX-2008 - INRIA - Allan CORNET + +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + + +function varargout = unix_g(cmd) + //unix_g - shell command execution + //%Syntax + //rep=unix_g(cmd) + //%Parameters + // cmd - a character string + // rep - a column vector of character strings + //%Description + // cmd instruction (sh syntax) is passed to shell, the standard output + // is redirected to scilab variable rep. + //%Examples + // unix_g("ls") + //%See also + // host unix_x unix_s + //! + + [lhs,rhs] = argn(0); + + if rhs <> 1 then + error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"unix_g",1)); + end + + if type(cmd) <> 10 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"unix_g",1)); + end + + if size(cmd,"*") <> 1 then + error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"unix_g",1)); + end + + if lhs > 3 then + error(msprintf(gettext("%s: Wrong number of output argument(s).\n"),"unix_g")); + end + + // initialize variables + stderr = emptystr(); + stat = 1; + rep = emptystr(); + + if getos() == "Windows" then + [rep,stat] = dos(cmd); + if (stat == %t) then + stat = 0; + else + if lhs == 3 then + stderr = rep; + else + for i=1:size(rep,"*") do write(%io(2)," "+rep(i));end + end + + stat = 1; + rep = emptystr(); + end + else + tmp = TMPDIR+"/unix.out"; + cmd1 = "("+cmd+")>"+ tmp +" 2>"+TMPDIR+"/unix.err;"; + stat = host(cmd1); + + select stat + + case 0 then + rep = mgetl(tmp); + if (size(rep,"*")==0) | (length(rep)==0) then + rep = []; + end; + + case 1 then + rep = mgetl(tmp); + + case -1 then + // host failed + if lhs == 3 then + stderr = msprintf(gettext("%s: The system interpreter does not answer..."),"unix_g"); + else + disp(msprintf(gettext("%s: The system interpreter does not answer..."),"unix_g")); + end + rep = emptystr(); + else + msg = mgetl(TMPDIR+"/unix.err"); + if lhs == 3 then + stderr = msg; + else + disp(msg(1)); + end + rep = emptystr(); + end + + mdelete(tmp); + end + + // output arguments + + varargout(1) = rep; + + if lhs >= 2 then + varargout(2) = stat; + end + + if lhs >= 3 then + varargout(3) = stderr; + end + +endfunction diff --git a/modules/io/macros/unix_s.bin b/modules/io/macros/unix_s.bin Binary files differnew file mode 100755 index 000000000..7d442b4db --- /dev/null +++ b/modules/io/macros/unix_s.bin diff --git a/modules/io/macros/unix_s.sci b/modules/io/macros/unix_s.sci new file mode 100755 index 000000000..23321fa72 --- /dev/null +++ b/modules/io/macros/unix_s.sci @@ -0,0 +1,59 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) XXXX-2008 - INRIA +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + + +function unix_s(cmd) + //unix_s - silent shell command execution + //%Syntax + // unix_s(cmd) + //%Parameters + // cmd - a character string + //%Description + // cmd instruction (sh syntax) is passed to shell, the standard output + // is redirected to /dev/null + //%Examples + // unix_s("\rm -f foo") + //%See also + // host unix_g unix_x + //! + + [lhs,rhs] = argn(0); + + if rhs <> 1 then + error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"unix_s",1)); + end + + if type(cmd) <> 10 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"unix_s",1)); + end + + if size(cmd,"*") <> 1 then + error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"unix_s",1)); + end + + if getos() == "Windows" then + [rep,stat]=dos(cmd); + if (~stat) then + for i=1:size(rep,"*") do write(%io(2)," "+rep(i));end + error(msprintf(gettext("%s: error during ""%s"" execution"),"unix_s",cmd)); + end + else + cmd1="("+cmd+")>/dev/null 2>"+TMPDIR+"/unix.err;"; + stat=host(cmd1); + select stat + case 0 then + case -1 then // host failed + error(msprintf(gettext("%s: The system interpreter does not answer..."),"unix_s")) + else //sh failed + msg=read(TMPDIR+"/unix.err",-1,1,"(a)"); + for i=1:size(msg,"*") do write(%io(2)," "+msg(i));end + error(msprintf(gettext("%s: error during ""%s"" execution"),"unix_s",cmd)); + end + end +endfunction diff --git a/modules/io/macros/unix_w.bin b/modules/io/macros/unix_w.bin Binary files differnew file mode 100755 index 000000000..6d81d94a0 --- /dev/null +++ b/modules/io/macros/unix_w.bin diff --git a/modules/io/macros/unix_w.sci b/modules/io/macros/unix_w.sci new file mode 100755 index 000000000..60116a4d8 --- /dev/null +++ b/modules/io/macros/unix_w.sci @@ -0,0 +1,66 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) XXXX-2008 - INRIA +// Copyright (C) XXXX-2008 - INRIA - Allan CORNET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + + +function unix_w(cmd) + //unix_w - shell command execution results redirected in main scilab window + //%Syntax + // unix_w(cmd) + //%Parameters + // cmd - a character string + //%Description + // cmd instruction (sh syntax) is passed to shell, the standard output + // is redirected to main scilab window + //%Examples + // unix_w("ls") + //%See also + // host unix_x unix_s unix_g + //! + + [lhs,rhs] = argn(0); + + if rhs <> 1 then + error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"unix_w",1)); + end + + if type(cmd) <> 10 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"unix_w",1)); + end + + if size(cmd,"*") <> 1 then + error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"unix_w",1)); + end + + if getos() == "Windows" then + [rep,stat]=dos(cmd,"-echo"); + if (~stat) then + error(msprintf(gettext("%s: error during ""%s"" execution"),"unix_w",cmd)); + end + else + tmp=TMPDIR+"/unix.out"; + cmd1="("+cmd+")>"+ tmp +" 2>"+TMPDIR+"/unix.err;"; + stat=host(cmd1); + + select stat + case 0 then + write(%io(2),read(tmp,-1,1,"(a)")); + case -1 then // host failed + error(msprintf(gettext("%s: The system interpreter does not answer..."),"unix_w")); + else + msg=read(TMPDIR+"/unix.err",-1,1,"(a)"); + if (size(msg,"*") == 0) then // If the program does not return anything + msg="" + end + errmsg = msprintf(gettext("%s: The command failed with the error code ""%s"" and the following message:\n"),"unix_w",string(stat)); + error(msprintf("%s\n"+strcat(msg, "\n"), errmsg)); + end + deletefile(tmp); + end +endfunction diff --git a/modules/io/macros/unix_x.bin b/modules/io/macros/unix_x.bin Binary files differnew file mode 100755 index 000000000..1d82eb694 --- /dev/null +++ b/modules/io/macros/unix_x.bin diff --git a/modules/io/macros/unix_x.sci b/modules/io/macros/unix_x.sci new file mode 100755 index 000000000..db494a590 --- /dev/null +++ b/modules/io/macros/unix_x.sci @@ -0,0 +1,68 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) XXXX-2008 - INRIA +// Copyright (C) XXXX-2008 - INRIA - Allan CORNET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + + +function unix_x(cmd) + //unix_x - shell command execution, results redirected in a window + //%Syntax + // unix_x(cmd) + //%Parameters + // cmd - a character string + //%Description + // cmd instruction is passed to shell, the standard output is redirected + // to a window + //%Examples + // unix_x("ls") + //%See also + // host unix_g unix_s + //! + + [lhs,rhs] = argn(0); + + if rhs <> 1 then + error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"unix_x",1)); + end + + if type(cmd) <> 10 then + error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"unix_x",1)); + end + + if size(cmd,"*") <> 1 then + error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"unix_x",1)); + end + + if getos() == "Windows" then + [rep,stat]=dos(cmd); + if (stat) then + messagebox(rep); + else + for i=1:size(rep,"*") do write(%io(2)," "+rep(i));end + error(msprintf(gettext("%s: error during ""%s"" execution"),"unix_x",cmd)); + end + else + tmp=TMPDIR+"/unix.out"; + cmd1="("+cmd+")>"+ tmp +" 2>"+TMPDIR+"/unix.err;"; + stat=host(cmd1); + select stat + case 0 then + rep=mgetl(tmp) + if (size(rep,"*")==0) | (length(rep)==0) then + rep=[] + end + messagebox(rep); + case -1 then // host failed + error(msprintf(gettext("%s: The system interpreter does not answer..."),"unix_x")); + else //sh failed + msg=read(TMPDIR+"/unix.err",-1,1,"(a)") + error("unix_x: "+msg(1)) + end + end + +endfunction |