summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/BasicBlockInfo.java354
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockPositioning.java263
2 files changed, 617 insertions, 0 deletions
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/BasicBlockInfo.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/BasicBlockInfo.java
new file mode 100644
index 0000000..a06bc1d
--- /dev/null
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/BasicBlockInfo.java
@@ -0,0 +1,354 @@
1package org.scilab.modules.xcos.io;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.scilab.modules.hdf5.scilabTypes.ScilabBoolean;
7import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
8import org.scilab.modules.hdf5.scilabTypes.ScilabList;
9import org.scilab.modules.hdf5.scilabTypes.ScilabMList;
10import org.scilab.modules.hdf5.scilabTypes.ScilabString;
11import org.scilab.modules.hdf5.scilabTypes.ScilabType;
12import org.scilab.modules.xcos.block.BasicBlock;
13import org.scilab.modules.xcos.port.BasicPort;
14import org.scilab.modules.xcos.port.command.CommandPort;
15import org.scilab.modules.xcos.port.control.ControlPort;
16import org.scilab.modules.xcos.port.input.ExplicitInputPort;
17import org.scilab.modules.xcos.port.input.ImplicitInputPort;
18import org.scilab.modules.xcos.port.input.InputPort;
19import org.scilab.modules.xcos.port.output.ExplicitOutputPort;
20import org.scilab.modules.xcos.port.output.ImplicitOutputPort;
21import org.scilab.modules.xcos.port.output.OutputPort;
22
23public final class BasicBlockInfo {
24
25 private BasicBlockInfo() {
26
27 }
28
29 public static ScilabDouble getAllLinkId(List ports) {
30 if (ports.isEmpty()) {
31 return new ScilabDouble();
32 }
33
34 double[][] data = new double[ports.size()][1];
35 for (int i = 0 ; i < ports.size() ; ++i) {
36 data[i][0] = ((BasicPort) ports.get(i)).getConnectedLinkId();
37 }
38
39 return new ScilabDouble(data);
40 }
41
42 public static ScilabDouble getAllPortsDataLines(List ports) {
43 if (ports.isEmpty()) {
44 return new ScilabDouble();
45 }
46 double[][] data = new double[ports.size()][1];
47 for (int i = 0 ; i < ports.size() ; ++i) {
48 data[i][0] = ((BasicPort) ports.get(i)).getDataLines();
49 }
50
51 return new ScilabDouble(data);
52 }
53
54 public static ScilabDouble getAllPortsDataColumns(List ports) {
55 boolean allZeros = true;
56 if (ports.isEmpty()) {
57 return new ScilabDouble();
58 }
59
60 double[][] data = new double[ports.size()][1];
61 for (int i = 0 ; i < ports.size() ; ++i) {
62 data[i][0] = ((BasicPort) ports.get(i)).getDataColumns();
63 if(data[i][0] != 0) {
64 allZeros = false;
65 }
66 }
67
68 if(allZeros) {
69 return new ScilabDouble();
70 }
71
72 return new ScilabDouble(data);
73 }
74
75 public static ScilabType getAllPortsDataType(List ports) {
76 if (ports.isEmpty()) {
77 return new ScilabDouble();
78 }
79 double[][] data = new double[ports.size()][1];
80 for (int i = 0 ; i < ports.size() ; ++i) {
81 data[i][0] = ((BasicPort) ports.get(i)).getDataType().getAsDouble();
82 }
83
84 return new ScilabDouble(data);
85 }
86
87 public static ScilabType getAllPortsType(List ports) {
88 if (ports.isEmpty()) {
89 return new ScilabDouble();
90 }
91 String[][] data = new String[ports.size()][1];
92 for (int i = 0 ; i < ports.size() ; ++i) {
93 data[i][0] = ((BasicPort) ports.get(i)).getType().getAsString();
94 }
95
96 return new ScilabString(data);
97 }
98
99 public static ScilabMList createScilabGraphicsProperties(BasicBlock block) {
100 String[] graphicsFields = {"graphics", "orig", "sz", "flip", "theta", "exprs", "pin", "pout", "pein", "peout", "gr_i",
101 "id", "in_implicit", "out_implicit"};
102 ScilabMList graphics = new ScilabMList(graphicsFields);
103
104 double[][] orig = {{block.getGeometry().getX(), - block.getGeometry().getY()}};
105 graphics.add(new ScilabDouble(orig)); // orig
106
107 double[][] sz = {{block.getGeometry().getWidth(), block.getGeometry().getHeight()}};
108 graphics.add(new ScilabDouble(sz)); // sz
109
110 // graphics.add(new ScilabBoolean(!flip)); // flip
111 graphics.add(new ScilabBoolean(true)); // flip
112
113 // mxCellState state = getParentDiagram().getView().getState(this);
114 // String currentBlockDirection = mxUtils.getString(state.getStyle(), mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST);
115 //
116 // double theta = 0;
117 // if(currentBlockDirection.compareTo(mxConstants.DIRECTION_EAST) == 0){
118 // if(flip){
119 // theta = 180;
120 // }else{
121 // theta = 0;
122 // }
123 // }else if(currentBlockDirection.compareTo(mxConstants.DIRECTION_NORTH) == 0){
124 // if(flip){
125 // theta = 270;
126 // }else{
127 // theta = 90;
128 // }
129 // }else if(currentBlockDirection.compareTo(mxConstants.DIRECTION_WEST) == 0){
130 // if(flip){
131 // theta = 0;
132 // }else{
133 // theta = 180;
134 // }
135 // }else if(currentBlockDirection.compareTo(mxConstants.DIRECTION_SOUTH) == 0){
136 // if(flip){
137 // theta = 90;
138 // }else{
139 // theta = 270;
140 // }
141 // }
142 // graphics.add(new ScilabDouble(theta)); // theta
143
144 graphics.add(new ScilabDouble(0)); // theta
145
146 graphics.add(block.getExprs()); // exprs
147
148 graphics.add(getAllLinkId(getAllInputPorts(block))); // pin
149
150 graphics.add(getAllLinkId(getAllOutputPorts(block))); // pout
151
152 graphics.add(getAllLinkId(getAllControlPorts(block))); // pein
153
154 graphics.add(getAllLinkId(getAllCommandPorts(block))); // peout
155
156 ScilabList gr_i = new ScilabList();
157 ScilabString graphicsInstructions = new ScilabString("xstringb(orig(1),orig(2),\"" + block.getInterfaceFunctionName() + "\",sz(1),sz(2));");
158 gr_i.add(graphicsInstructions);
159 gr_i.add(new ScilabDouble(8));
160 graphics.add(gr_i); // gr_i
161
162 graphics.add(new ScilabString("")); // id
163
164 graphics.add(getAllPortsType(getAllInputPorts(block))); // in_implicit
165
166 graphics.add(getAllPortsType(getAllOutputPorts(block))); // out_implicit
167
168 return graphics;
169 }
170
171
172 public static ScilabMList createScilabModelProperties(BasicBlock block) {
173 String[] modelFields = {"model", "sim", "in", "in2", "intyp", "out", "out2", "outtyp", "evtin", "evtout",
174 "state", "dstate", "odstate", "rpar", "ipar", "opar", "blocktype", "firing", "dep_ut", "label",
175 "nzcross", "nmode", "equations"};
176 ScilabMList model = new ScilabMList(modelFields);
177
178 model.add(block.getSimulationFunctionNameAndType()); // sim
179
180 model.add(getAllPortsDataLines(getAllInputPorts(block))); // in
181
182 model.add(getAllPortsDataColumns(getAllInputPorts(block))); // in2
183
184 model.add(getAllPortsDataType(getAllInputPorts(block))); // intyp
185
186 model.add(getAllPortsDataLines(getAllOutputPorts(block))); // out
187
188 model.add(getAllPortsDataColumns(getAllOutputPorts(block))); // out2
189
190 model.add(getAllPortsDataType(getAllOutputPorts(block))); // outtyp
191
192 model.add(getAllPortsDataLines(getAllControlPorts(block))); // evtin
193
194 model.add(getAllPortsDataLines(getAllCommandPorts(block))); // evtout
195
196 model.add(block.getState()); // state
197
198 model.add(block.getDState()); // dstate
199
200 model.add(block.getODState()); // odstate
201
202 model.add(block.getRealParameters()); // rpar
203
204 model.add(block.getIntegerParameters()); // ipar
205
206 model.add(block.getObjectsParameters()); // opar
207
208 model.add(new ScilabString(block.getBlockType())); // blocktype
209
210 model.add(block.getAllCommandPortsInitialStates()); // firing
211
212 boolean[][] dep_ut = {{block.dependsOnU() , block.dependsOnT()}};
213 model.add(new ScilabBoolean(dep_ut)); // dep_ut
214
215 model.add(new ScilabString("")); // label
216
217 model.add(block.getNbZerosCrossing()); // nzcross
218
219 model.add(block.getNmode()); // nmode
220
221 if (block.getEquations() == null) {
222 model.add(new ScilabList()); // equations
223 }
224 else {
225 model.add(block.getEquations()); // equations
226 }
227
228 return model;
229 }
230
231 public static ScilabString createScilabGuiProperties(BasicBlock block) {
232 return new ScilabString(block.getInterfaceFunctionName());
233 }
234
235 public static ScilabList createScilabDocProperties(BasicBlock block) {
236 ScilabList result = new ScilabList();
237 // Store UID in doc so that Scilab will now it without being disturbed.
238 result.add(new ScilabString(block.getId()));
239
240 return result;
241 }
242
243 public static ScilabMList getAsScilabObj(BasicBlock block) {
244 String[] objFields = {"Block", "graphics", "model", "gui", "doc"};
245 ScilabMList obj = new ScilabMList(objFields);
246
247 obj.add(BasicBlockInfo.createScilabGraphicsProperties(block));
248 obj.add(BasicBlockInfo.createScilabModelProperties(block));
249 obj.add(BasicBlockInfo.createScilabGuiProperties(block));
250 obj.add(BasicBlockInfo.createScilabDocProperties(block));
251
252 return obj;
253 }
254
255 public static List<InputPort> getAllInputPorts(BasicBlock block) {
256 List<InputPort> data = new ArrayList<InputPort>();
257 int childrenCount = block.getChildCount();
258
259 for (int i = 0 ; i < childrenCount ; ++i) {
260 if(block.getChildAt(i) instanceof InputPort) {
261 data.add((InputPort) block.getChildAt(i));
262 }
263 }
264
265 return data;
266 }
267
268 public static List<ExplicitInputPort> getAllExplicitInputPorts(BasicBlock block) {
269 List<ExplicitInputPort> data = new ArrayList<ExplicitInputPort>();
270 int childrenCount = block.getChildCount();
271
272 for (int i = 0 ; i < childrenCount ; ++i) {
273 if(block.getChildAt(i) instanceof ExplicitInputPort) {
274 data.add((ExplicitInputPort) block.getChildAt(i));
275 }
276 }
277 return data;
278 }
279
280 public static List<ImplicitInputPort> getAllImplicitInputPorts(BasicBlock block) {
281 List<ImplicitInputPort> data = new ArrayList<ImplicitInputPort>();
282 int childrenCount = block.getChildCount();
283
284 for (int i = 0 ; i < childrenCount ; ++i) {
285 if(block.getChildAt(i) instanceof ImplicitInputPort) {
286 data.add((ImplicitInputPort) block.getChildAt(i));
287 }
288 }
289 return data;
290 }
291
292 public static List<OutputPort> getAllOutputPorts(BasicBlock block) {
293 List<OutputPort> data = new ArrayList<OutputPort>();
294 int childrenCount = block.getChildCount();
295
296 for (int i = 0 ; i < childrenCount ; ++i) {
297 if(block.getChildAt(i) instanceof OutputPort) {
298 data.add((OutputPort) block.getChildAt(i));
299 }
300 }
301
302 return data;
303 }
304
305 public static List<ExplicitOutputPort> getAllExplicitOutputPorts(BasicBlock block) {
306 List<ExplicitOutputPort> data = new ArrayList<ExplicitOutputPort>();
307 int childrenCount = block.getChildCount();
308
309 for (int i = 0 ; i < childrenCount ; ++i) {
310 if(block.getChildAt(i) instanceof ExplicitOutputPort) {
311 data.add((ExplicitOutputPort) block.getChildAt(i));
312 }
313 }
314 return data;
315 }
316
317 public static List<ImplicitOutputPort> getAllImplicitOutputPorts(BasicBlock block) {
318 List<ImplicitOutputPort> data = new ArrayList<ImplicitOutputPort>();
319 int childrenCount = block.getChildCount();
320
321 for (int i = 0 ; i < childrenCount ; ++i) {
322 if(block.getChildAt(i) instanceof ImplicitOutputPort) {
323 data.add((ImplicitOutputPort) block.getChildAt(i));
324 }
325 }
326 return data;
327 }
328
329 public static List<CommandPort> getAllCommandPorts(BasicBlock block) {
330 List<CommandPort> data = new ArrayList<CommandPort>();
331 int childrenCount = block.getChildCount();
332
333 for (int i = 0 ; i < childrenCount ; ++i) {
334 if(block.getChildAt(i) instanceof CommandPort) {
335 data.add((CommandPort) block.getChildAt(i));
336 }
337 }
338
339 return data;
340 }
341
342 public static List<ControlPort> getAllControlPorts(BasicBlock block) {
343 List<ControlPort> data = new ArrayList<ControlPort>();
344 int childrenCount = block.getChildCount();
345
346 for (int i = 0 ; i < childrenCount ; ++i) {
347 if(block.getChildAt(i) instanceof ControlPort) {
348 data.add((ControlPort) block.getChildAt(i));
349 }
350 }
351
352 return data;
353 }
354}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockPositioning.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockPositioning.java
new file mode 100644
index 0000000..c8452b7
--- /dev/null
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockPositioning.java
@@ -0,0 +1,263 @@
1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009 - DIGITEO - Antoine ELIAS
4 *
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
13package org.scilab.modules.xcos.utils;
14
15import java.util.List;
16
17import org.scilab.modules.xcos.block.BasicBlock;
18import org.scilab.modules.xcos.io.BasicBlockInfo;
19import org.scilab.modules.xcos.port.BasicPort;
20
21import com.mxgraph.model.mxGeometry;
22import com.mxgraph.util.mxConstants;
23import com.mxgraph.util.mxUtils;
24import com.mxgraph.view.mxCellState;
25
26public final class BlockPositioning {
27
28 /**
29 * Constructor
30 */
31
32 private BlockPositioning() {
33
34 }
35 /**
36 * Dispatch ports on Block's _WEST_ side.
37 * @param ports
38 */
39 public static void updateWestPortsPosition(BasicBlock block, List ports) {
40 mxGeometry blockGeom = block.getGeometry();
41 if(blockGeom == null){
42 return;
43 }
44 for (int i = 0 ; i < ports.size() ; ++i) {
45 mxGeometry portGeom = ((BasicPort) ports.get(i)).getGeometry();
46 portGeom.setX(- portGeom.getWidth());
47 portGeom.setY((i + 1.0) * (blockGeom.getHeight() / (ports.size() + 1.0))
48 - (portGeom.getHeight() / 2.0));
49 }
50 }
51
52 /**
53 * Dispatch ports on Block's _NORTH_ side.
54 * @param ports
55 */
56 public static void updateNorthPortsPosition(BasicBlock block, List ports) {
57 mxGeometry blockGeom = block.getGeometry();
58 if(blockGeom == null){
59 return;
60 }
61 for (int i = 0 ; i < ports.size() ; ++i) {
62 mxGeometry portGeom = ((BasicPort) ports.get(i)).getGeometry();
63 portGeom.setX((i + 1.0) * (blockGeom.getWidth() / (ports.size() + 1.0))
64 - (portGeom.getWidth() / 2.0));
65 portGeom.setY(- portGeom.getHeight());
66 }
67 }
68
69 /**
70 * Dispatch ports on Block's _EAST_ side.
71 * @param ports
72 */
73 public static void updateEastPortsPosition(BasicBlock block, List ports) {
74 mxGeometry blockGeom = block.getGeometry();
75 if(blockGeom == null){
76 return;
77 }
78 for (int i = 0 ; i < ports.size() ; ++i) {
79 mxGeometry portGeom = ((BasicPort) ports.get(i)).getGeometry();
80 portGeom.setX(blockGeom.getWidth());
81 portGeom.setY((i + 1.0) * (blockGeom.getHeight() / (ports.size() + 1.0))
82 - (portGeom.getHeight() / 2.0));
83 }
84 }
85
86 /**
87 * Dispatch ports on Block's _SOUTH_ side.
88 * @param ports
89 */
90 public static void updateSouthPortsPosition(BasicBlock block, List ports) {
91 mxGeometry blockGeom = block.getGeometry();
92 if(blockGeom == null){
93 return;
94 }
95 for (int i = 0 ; i < ports.size() ; ++i) {
96 mxGeometry portGeom = ((BasicPort) ports.get(i)).getGeometry();
97 portGeom.setX((i + 1.0) * (blockGeom.getWidth() / (ports.size() + 1.0))
98 - (portGeom.getWidth() / 2.0));
99 portGeom.setY(blockGeom.getHeight());
100 }
101 }
102
103 public static void updatePortsPosition(BasicBlock block, String blockDirection) {
104 // Block -> EAST
105 // East <=> Out / North <=> Control / West <=> In / South <=> Command
106 if (blockDirection.compareTo(mxConstants.DIRECTION_EAST) == 0) {
107 if(block.getFlip()){
108 updateEastPortsPosition(block, BasicBlockInfo.getAllOutputPorts(block));
109 updateSouthPortsPosition(block, BasicBlockInfo.getAllControlPorts(block));
110 updateWestPortsPosition(block, BasicBlockInfo.getAllInputPorts(block));
111 updateNorthPortsPosition(block, BasicBlockInfo.getAllCommandPorts(block));
112 }else{
113 updateEastPortsPosition(block, BasicBlockInfo.getAllOutputPorts(block));
114 updateNorthPortsPosition(block, BasicBlockInfo.getAllControlPorts(block));
115 updateWestPortsPosition(block, BasicBlockInfo.getAllInputPorts(block));
116 updateSouthPortsPosition(block, BasicBlockInfo.getAllCommandPorts(block));
117 }
118 }
119 // Block -> NORTH
120 // East <=> Command / North <=> Out / West <=> Control / South <=> In
121 if (blockDirection.compareTo(mxConstants.DIRECTION_NORTH) == 0) {
122 if(block.getFlip()){
123 updateWestPortsPosition(block, BasicBlockInfo.getAllCommandPorts(block));
124 updateNorthPortsPosition(block, BasicBlockInfo.getAllOutputPorts(block));
125 updateEastPortsPosition(block, BasicBlockInfo.getAllControlPorts(block));
126 updateSouthPortsPosition(block, BasicBlockInfo.getAllInputPorts(block));
127 }else{
128 updateEastPortsPosition(block, BasicBlockInfo.getAllCommandPorts(block));
129 updateNorthPortsPosition(block, BasicBlockInfo.getAllOutputPorts(block));
130 updateWestPortsPosition(block, BasicBlockInfo.getAllControlPorts(block));
131 updateSouthPortsPosition(block, BasicBlockInfo.getAllInputPorts(block));
132 }
133 }
134 // Block -> WEST
135 // East <=> In / North <=> Command / West <=> Out / South <=> Control
136 if (blockDirection.compareTo(mxConstants.DIRECTION_WEST) == 0) {
137 if(block.getFlip()){
138 updateEastPortsPosition(block, BasicBlockInfo.getAllInputPorts(block));
139 updateSouthPortsPosition(block, BasicBlockInfo.getAllCommandPorts(block));
140 updateWestPortsPosition(block, BasicBlockInfo.getAllOutputPorts(block));
141 updateNorthPortsPosition(block, BasicBlockInfo.getAllControlPorts(block));
142 }else{
143 updateEastPortsPosition(block, BasicBlockInfo.getAllInputPorts(block));
144 updateNorthPortsPosition(block, BasicBlockInfo.getAllCommandPorts(block));
145 updateWestPortsPosition(block, BasicBlockInfo.getAllOutputPorts(block));
146 updateSouthPortsPosition(block, BasicBlockInfo.getAllControlPorts(block));
147 }
148 }
149 // Block -> SOUTH
150 // East <=> Control / North <=> In / West <=> Command / South <=> Out
151 if (blockDirection.compareTo(mxConstants.DIRECTION_SOUTH) == 0) {
152 if(block.getFlip()){
153 updateWestPortsPosition(block, BasicBlockInfo.getAllControlPorts(block));
154 updateNorthPortsPosition(block, BasicBlockInfo.getAllInputPorts(block));
155 updateEastPortsPosition(block, BasicBlockInfo.getAllCommandPorts(block));
156 updateSouthPortsPosition(block, BasicBlockInfo.getAllOutputPorts(block));
157 }else{
158 updateEastPortsPosition(block, BasicBlockInfo.getAllControlPorts(block));
159 updateNorthPortsPosition(block, BasicBlockInfo.getAllInputPorts(block));
160 updateWestPortsPosition(block, BasicBlockInfo.getAllCommandPorts(block));
161 updateSouthPortsPosition(block, BasicBlockInfo.getAllOutputPorts(block));
162 }
163 }
164 }
165
166 public static String getNextAntiClockwiseDirection(String currentBlockDirection) {
167 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_EAST) == 0) { return mxConstants.DIRECTION_NORTH; }
168 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_NORTH) == 0) { return mxConstants.DIRECTION_WEST; }
169 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_WEST) == 0) { return mxConstants.DIRECTION_SOUTH; }
170 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_SOUTH) == 0) { return mxConstants.DIRECTION_EAST; }
171 return null;
172 }
173
174 public static String getNextClockwiseDirection(String currentBlockDirection) {
175 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_EAST) == 0) { return mxConstants.DIRECTION_SOUTH; }
176 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_NORTH) == 0) { return mxConstants.DIRECTION_EAST; }
177 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_WEST) == 0) { return mxConstants.DIRECTION_NORTH; }
178 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_SOUTH) == 0) { return mxConstants.DIRECTION_WEST; }
179 return null;
180 }
181
182 public static String getNextFlipDirection(String currentBlockDirection) {
183 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_EAST) == 0) { return mxConstants.DIRECTION_WEST; }
184 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_NORTH) == 0) { return mxConstants.DIRECTION_SOUTH; }
185 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_WEST) == 0) { return mxConstants.DIRECTION_EAST; }
186 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_SOUTH) == 0) { return mxConstants.DIRECTION_NORTH; }
187 return null;
188 }
189
190 public static String getEventPortsDirection(BasicBlock block, String currentBlockDirection) {
191 if(block.getFlip()){
192 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_EAST) == 0) { return mxConstants.DIRECTION_NORTH; }
193 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_NORTH) == 0) { return mxConstants.DIRECTION_WEST; }
194 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_WEST) == 0) { return mxConstants.DIRECTION_SOUTH; }
195 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_SOUTH) == 0) { return mxConstants.DIRECTION_EAST; }
196 return null;
197 }else{
198 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_EAST) == 0) { return mxConstants.DIRECTION_SOUTH; }
199 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_NORTH) == 0) { return mxConstants.DIRECTION_EAST; }
200 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_WEST) == 0) { return mxConstants.DIRECTION_NORTH; }
201 if (currentBlockDirection.compareTo(mxConstants.DIRECTION_SOUTH) == 0) { return mxConstants.DIRECTION_WEST; }
202 return null;
203 }
204 }
205
206 public static String getDataPortsDirection(String currentBlockDirection) {
207 return currentBlockDirection;
208 }
209
210 public static void rotatePorts(BasicBlock block, List ports , String portOrientation){
211 for(int i = 0 ; i < ports.size() ; ++i) {
212 mxUtils.setCellStyles(block.getParentDiagram().getModel(), new Object[] {ports.get(i)}, mxConstants.STYLE_DIRECTION, portOrientation);
213 }
214 }
215
216 public static void updateBlockDirection(BasicBlock block, String newBlockDirection) {
217 mxUtils.setCellStyles(block.getParentDiagram().getModel(), new Object[] {block}, mxConstants.STYLE_DIRECTION, newBlockDirection);
218
219 rotatePorts(block, BasicBlockInfo.getAllInputPorts(block), getDataPortsDirection(newBlockDirection));
220 rotatePorts(block, BasicBlockInfo.getAllOutputPorts(block), getDataPortsDirection(newBlockDirection));
221 rotatePorts(block, BasicBlockInfo.getAllCommandPorts(block), getEventPortsDirection(block, newBlockDirection));
222 rotatePorts(block, BasicBlockInfo.getAllControlPorts(block), getEventPortsDirection(block, newBlockDirection));
223 }
224
225 public static void updateBlockView(BasicBlock block) {
226
227 if (block != null
228 && block.getParentDiagram() != null
229 && block.getParentDiagram().getView() != null
230 && block.getParentDiagram().getView().getState(block) != null) {
231 mxCellState state = block.getParentDiagram().getView().getState(block);
232 String currentBlockDirection = mxUtils.getString(state.getStyle(), mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST);
233 //currentBlockDirection = mxConstants.DIRECTION_EAST;
234 BlockPositioning.updatePortsPosition(block, currentBlockDirection);
235 rotatePorts(block, BasicBlockInfo.getAllInputPorts(block), getDataPortsDirection(currentBlockDirection));
236 rotatePorts(block, BasicBlockInfo.getAllOutputPorts(block), getDataPortsDirection(currentBlockDirection));
237 rotatePorts(block, BasicBlockInfo.getAllCommandPorts(block), getEventPortsDirection(block, currentBlockDirection));
238 rotatePorts(block, BasicBlockInfo.getAllControlPorts(block), getEventPortsDirection(block, currentBlockDirection));
239 }
240 }
241
242 public static void toggleFlip(BasicBlock block) {
243
244 block.setFlip(!block.getFlip());
245
246 mxCellState state = block.getParentDiagram().getView().getState(block);
247 String currentBlockDirection = mxUtils.getString(state.getStyle(), mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST);
248
249 updatePortsPosition(block, getNextFlipDirection(currentBlockDirection));
250 updateBlockDirection(block, getNextFlipDirection(currentBlockDirection));
251 }
252
253
254 public static void toggleAntiClockwiseRotation(BasicBlock block) {
255 mxCellState state = block.getParentDiagram().getView().getState(block);
256 String currentBlockDirection = mxUtils.getString(state.getStyle(), mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST);
257
258 updatePortsPosition(block, getNextAntiClockwiseDirection(currentBlockDirection));
259 updateBlockDirection(block, getNextAntiClockwiseDirection(currentBlockDirection));
260 }
261
262
263}