1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2011 - DIGITEO - Clément DAVID <clement.david@scilab.org>
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
13 function tbx_build_blocks(module, names, macros_path)
14 // Build a default block instance
17 // tbx_build_blocks(module, names)
20 // module: toolbox base directory
21 // names: list of block names (sci file name without extension)
24 error(msprintf(gettext("%s: Wrong number of input arguments: At least %d expected.\n"),"tbx_build_blocks",2));
27 error(msprintf(gettext("%s: Wrong number of input arguments: At most %d expected.\n"),"tbx_build_blocks",3));
31 // checking module argument
32 if type(module) <> 10 then
33 error(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"),"tbx_build_blocks",1));
35 if size(module,"*") <> 1 then
36 error(msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"),"tbx_build_blocks",1));
38 if ~isdir(module) then
39 error(msprintf(gettext("%s: The directory ''%s'' doesn''t exist or is not read accessible.\n"),"tbx_build_blocks",module));
42 // checking names argument
43 if type(names) <> 10 then
44 error(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"),"tbx_build_blocks",2));
47 // checking optional macros_path argument
48 if ~exists("macros_path", "l") then
49 macros_path = module + "/macros/";
51 if type(macros_path) <> 10 then
52 error(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"),"tbx_build_blocks",3));
54 if size(macros_path,"*") <> 1 then
55 error(msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"),"tbx_build_blocks",3));
57 if ~isdir(macros_path) then
58 error(msprintf(gettext("%s: The directory ''%s'' doesn''t exist or is not read accessible.\n"),"tbx_build_blocks",macros_path));
61 mprintf(gettext("Building blocks...\n"));
63 // load Xcos libraries when not already loaded.
64 if ~exists("Sourceslib") then loadXcosLibs(); end
67 if ~isdir(module + "/images") then
68 createdir(module + "/images");
70 if ~isdir(module + "/images/h5") then
71 createdir(module + "/images/h5");
73 if ~isdir(module + "/images/gif") then
74 createdir(module + "/images/gif");
76 if ~isdir(module + "/images/svg") then
77 createdir(module + "/images/svg");
81 sciFiles = pathconvert(macros_path + "/") + names + ".sci";
82 h5Files = pathconvert(module + "/images/h5/") + names + ".sod";
83 gif_tlbx = pathconvert(module + "/images/gif");
84 svg_tlbx = pathconvert(module + "/images/svg");
85 for i=1:size(names, "*")
86 // load the interface function
87 exec(sciFiles(i), -1);
89 // export the instance
90 execstr(msprintf("scs_m = %s (''define'');", names(i)));
92 save(h5Files(i), "scs_m");
94 error(msprintf(gettext("%s: Unable to export %s to %s.\n"),"tbx_build_blocks",names(i), h5Files(i)));
99 // export a schema file if it doesn't exist
100 files = svg_tlbx + "/" + names(i) + [".svg" ".png" ".jpg" ".gif"];
101 files = files(isfile(files));
103 filename = svg_tlbx + "/" + names(i) + ".svg";
104 if ~generateBlockImage(blk, svg_tlbx, names(i), "svg", %f) then
105 error(msprintf(gettext("%s: Unable to export %s to %s .\n"),"tbx_build_blocks",names(i), filename));
109 // export an image file if it doesn't exist
110 files = gif_tlbx + "/" + names(i) + [".png" ".jpg" ".gif"];
111 files = files(isfile(files));
113 filename = gif_tlbx + "/" + names(i) + ".gif";
114 xcosPalGenerateIcon(blk, filename);