~ubuntu-branches/ubuntu/precise/scilab/precise

« back to all changes in this revision

Viewing changes to modules/xcos/src/java/org/scilab/modules/xcos/io/BlockWriter.java

  • Committer: Bazaar Package Importer
  • Author(s): Sylvestre Ledru
  • Date: 2010-04-16 15:57:24 UTC
  • mfrom: (1.1.9 upstream) (4.4.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100416155724-lx1sdku0oidl0ffn
Tags: 5.2.2-1
* New upstream release
* better-feedback-on-lib-error.diff, full_support.diff, renesas-sh.diff,
  s390javadetection.diff, sparc64.diff, test_run_permission.diff,
  z_cpudetection.diff removed (applied upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
/**
33
33
 * Class used to write a diagram contents into an HDF5 file
34
 
 * @author Vincent COUVERT
35
 
 *
36
34
 */
37
35
public final class BlockWriter {
38
 
 
 
36
        /** Diagram MList header (scs_m) */
 
37
        private static final String[] DIAGRAM_FIELDS = {"diagram", "props", "objs", "version"};
 
38
        /** Diagram properties MList header (scs_m.props) */
 
39
        private static final String[] PROPS_FIELDS = {"params", "wpar", "title", "tol", "tf", "context", "void1", "options", "void2", "void3", "doc"};
 
40
        /** Diagram options MList header (scs_m.props.options) */
 
41
        private static final String[] OPTS_FIELDS = {"scsopt", "3D", "Background", "Link", "ID", "Cmap"};
 
42
        /**
 
43
         * Window properties (scs_m.props.wpar).
 
44
         * 
 
45
         * This property has no impact among simulation
 
46
         */
 
47
        private static final double[][] WPAR = {{600, 450, 0, 0, 600, 450}};
 
48
        
39
49
    /**
40
 
     * Constructor (MUST NOT BE USED !!!)
 
50
     * This class is a static singleton thus constructor must not be used.
41
51
     */
42
 
    private BlockWriter() {
43
 
 
44
 
    }
 
52
    private BlockWriter() { }
45
53
 
46
54
    /**
47
 
     * Main writing function
 
55
     * Write a diagram to any file.
 
56
     * 
48
57
     * @param hdf5File file to create
49
58
     * @param diagram diagram to save
50
59
     * @return true if file created successfully
51
60
     */
52
61
    public static boolean writeDiagramToFile(String hdf5File, XcosDiagram diagram)      {
53
62
 
54
 
        boolean isSuccess = true; // TODO error management
 
63
        boolean isSuccess = true;
55
64
 
56
65
        int fileId = H5Write.createFile(hdf5File);
57
66
        
61
70
            H5Write.writeInDataSet(fileId, "scs_m", data);
62
71
        } catch (HDF5Exception e) {
63
72
            e.printStackTrace();
 
73
            isSuccess = false;
64
74
        }
65
75
        H5Write.closeFile(fileId);
66
76
 
67
77
        return isSuccess;
68
78
    }
69
79
 
 
80
    /**
 
81
     * Convert a diagram to a ScilabType.
 
82
     * 
 
83
     * @param diagram the diagram to be converted
 
84
     * @return the scilab formatted datas
 
85
     */
70
86
    public static ScilabMList convertDiagramToMList(XcosDiagram diagram) {
71
 
        String[] diagramFields = {"diagram", "props", "objs", "version"};
72
 
 
73
 
        ScilabMList data = new ScilabMList(diagramFields);
 
87
        ScilabMList data = new ScilabMList(DIAGRAM_FIELDS);
74
88
        data.add(getDiagramProps(diagram));
75
89
        data.add(getDiagramObjs(diagram));
76
90
        data.add(getDiagramVersion(diagram));
85
99
     * @return a TList
86
100
     */
87
101
    private static ScilabTList getDiagramProps(XcosDiagram diagram) {
88
 
        String[] propsFields = {"params", "wpar", "title", "tol", "tf", "context", "void1", "options", "void2", "void3", "doc"};
89
 
        ScilabTList data = new ScilabTList(propsFields);
90
 
        // This propertie has no impact among simulation
91
 
        double[][] wpar = {{600,450,0,0,600,450}};
92
 
        data.add(new ScilabDouble(wpar)); // wpar
 
102
        ScilabTList data = new ScilabTList(PROPS_FIELDS);
 
103
        data.add(new ScilabDouble(WPAR)); // wpar
93
104
        data.add(new ScilabString(diagram.getTitle())); // title
94
105
        data.add(new ScilabDouble(createTol(diagram))); // tol
95
106
        data.add(new ScilabDouble(diagram.getFinalIntegrationTime())); // tf
124
135
     * @return the TList
125
136
     */
126
137
    private static ScilabTList getDiagramOptions() {
127
 
        String[] optionsFields = {"scsopt", "3D", "Background", "Link", "ID", "Cmap"};
128
 
 
129
 
        ScilabTList data = new ScilabTList(optionsFields);
 
138
        ScilabTList data = new ScilabTList(OPTS_FIELDS);
130
139
        ScilabList threeDimension = new ScilabList();
131
140
        threeDimension.add(new ScilabBoolean(true));
132
141
        threeDimension.add(new ScilabDouble(33));
167
176
                Object currentObject = diagram.getModel().getChildAt(diagram.getDefaultParent(), i);
168
177
                
169
178
                
170
 
                if (currentObject instanceof BasicBlock && !(currentObject instanceof TextBlock) ) {
 
179
                if (currentObject instanceof BasicBlock && !(currentObject instanceof TextBlock)) {
171
180
                        blockList.add((BasicBlock) currentObject);
172
181
                        //
173
182
                        // Look inside a Block to see if there is no "AutoLink"
174
183
                        // Jgraphx will store this link as block's child  
175
184
                        //
176
 
                        for(int j = 0 ; j < ((BasicBlock) currentObject).getChildCount() ; ++j) {
 
185
                        for (int j = 0; j < ((BasicBlock) currentObject).getChildCount(); ++j) {
177
186
                                if (((BasicBlock) currentObject).getChildAt(j) instanceof BasicLink) {
178
187
                                        linkList.add((BasicLink) ((BasicBlock) currentObject).getChildAt(j));
179
188
                                }