33
33
* Class used to write a diagram contents into an HDF5 file
34
* @author Vincent COUVERT
37
35
public final class BlockWriter {
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"};
43
* Window properties (scs_m.props.wpar).
45
* This property has no impact among simulation
47
private static final double[][] WPAR = {{600, 450, 0, 0, 600, 450}};
40
* Constructor (MUST NOT BE USED !!!)
50
* This class is a static singleton thus constructor must not be used.
42
private BlockWriter() {
52
private BlockWriter() { }
47
* Main writing function
55
* Write a diagram to any file.
48
57
* @param hdf5File file to create
49
58
* @param diagram diagram to save
50
59
* @return true if file created successfully
52
61
public static boolean writeDiagramToFile(String hdf5File, XcosDiagram diagram) {
54
boolean isSuccess = true; // TODO error management
63
boolean isSuccess = true;
56
65
int fileId = H5Write.createFile(hdf5File);
61
70
H5Write.writeInDataSet(fileId, "scs_m", data);
62
71
} catch (HDF5Exception e) {
63
72
e.printStackTrace();
65
75
H5Write.closeFile(fileId);
81
* Convert a diagram to a ScilabType.
83
* @param diagram the diagram to be converted
84
* @return the scilab formatted datas
70
86
public static ScilabMList convertDiagramToMList(XcosDiagram diagram) {
71
String[] diagramFields = {"diagram", "props", "objs", "version"};
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));
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
126
137
private static ScilabTList getDiagramOptions() {
127
String[] optionsFields = {"scsopt", "3D", "Background", "Link", "ID", "Cmap"};
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);
170
if (currentObject instanceof BasicBlock && !(currentObject instanceof TextBlock) ) {
179
if (currentObject instanceof BasicBlock && !(currentObject instanceof TextBlock)) {
171
180
blockList.add((BasicBlock) currentObject);
173
182
// Look inside a Block to see if there is no "AutoLink"
174
183
// Jgraphx will store this link as block's child
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));