Math2mat
|
00001 00018 package m2m.frontend.dynamicview; 00019 00020 import java.util.Iterator; 00021 import java.util.LinkedList; 00022 import java.util.Vector; 00023 00024 import m2m.backend.project.M2MProject; 00025 import m2m.backend.structure.*; 00026 import m2m.frontend.dynamicview.figure.*; 00027 import m2m.frontend.dynamicview.model.*; 00028 00029 import org.eclipse.draw2d.geometry.Point; 00030 import org.eclipse.draw2d.geometry.Rectangle; 00031 00032 00033 00034 public class Model 00035 { 00036 private Schema schema; 00037 00041 public static final int SPACE = 50; 00045 public static final int SPACE_INTERN_BLOC = 40; 00046 00047 00053 public Model(StructTreatment treatment, M2MProject m2mProject) 00054 { 00055 /* Create the instance of Schema */ 00056 schema = new Schema(); 00057 schema.setName("Prototype Polynome"); 00058 schema.setLayout(new Rectangle(0, 0, 1000, 1000)); 00059 schema.setproject(m2mProject); 00060 00061 // Creation of the main function 00062 createFunction((Function) treatment.getTop(), schema); 00063 00064 // Set the max depth of the schema 00065 schema.setMaxDepth(schema.getAllNodes()); 00066 } 00067 00068 00074 private void createFunction(Function function, Node graphicParent) 00075 { 00076 /* Use to locate input and output nodes of the GraphicFunction */ 00077 int positionX = SPACE; 00078 int positionY = 0; 00079 00080 // Levels of intern nodes of the GraphicFunction 00081 Vector<Vector<Element>> elementLevel = new Vector<Vector<Element>>(); 00082 00083 // Levels of intern GraphicIf conditions of the GraphicFunction 00084 Vector<Vector<Element>> conditions = new Vector<Vector<Element>>(); 00085 00086 /* Go through the inputs of the function */ 00087 for (Element element : function.getInput()) 00088 { 00089 positionY += SPACE; 00090 PointConnection pc = new PointConnection(); 00091 pc.setName(element.getName()); 00092 pc.setElement(element); 00093 pc.setLayout(new Rectangle(positionX, positionY, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00094 graphicParent.addChild(pc); 00095 } 00096 00097 /* Go through the outputs of the function */ 00098 for (Element element : function.getOutput()) 00099 { 00100 PointConnection pc = new PointConnection(); 00101 pc.setName(element.getName()); 00102 pc.setElement(element); 00103 graphicParent.addChild(pc); 00104 } 00105 00106 /* Creation of the GraphicFunction */ 00107 GraphicFunction graphicFunction = new GraphicFunction(); 00108 graphicFunction.setName(function.getName()); 00109 graphicFunction.setElement(function); 00110 graphicParent.addChild(graphicFunction); 00111 00112 /* Set the location of the GraphicFunction */ 00113 Node firstInputNode = getGraphicalNodeInParent(function.getInput().firstElement(), graphicParent); 00114 if(firstInputNode != null) 00115 graphicFunction.getLayout().setLocation(firstInputNode.getLayout().x + firstInputNode.getLayout().width + SPACE, firstInputNode.getLayout().y); 00116 else 00117 graphicFunction.getLayout().setLocation(SPACE, SPACE); 00118 00119 /* Go through the body of the function */ 00120 for (Element element : function.getBody()) 00121 { 00122 if(element instanceof Assignment) 00123 createAssignment((Assignment) element, graphicFunction, elementLevel); 00124 else if(element instanceof IfThenElse) 00125 conditions.add(createIfThenElse((IfThenElse) element, graphicFunction, elementLevel)); 00126 else if(element instanceof Multiplexer) 00127 createMultiplexer((Multiplexer) element, graphicFunction, elementLevel, conditions); 00128 else if(element instanceof Operation) 00129 createOperation((Operation) element, graphicFunction, elementLevel); 00130 else if(element instanceof LoopFor) 00131 createLoopFor((LoopFor) element, graphicFunction, elementLevel); 00132 else if(element instanceof LoopWhile) 00133 createLoopWhile((LoopWhile) element, graphicFunction, elementLevel); 00134 } 00135 00136 /* Set node locations of different levels of the GraphicFunction */ 00137 for (Vector<Element> level : elementLevel) 00138 locateNodesLevel(level, graphicFunction); 00139 00140 /* Set the size of the GraphicFunction */ 00141 graphicFunction.setFullSize(graphicFunction.getLayout().width, graphicFunction.getLayout().height); 00142 graphicFunction.setReductSize(80, 15); 00143 00144 /* Set output node locations of the GraphicFunction */ 00145 positionX = graphicFunction.getLayout().x + graphicFunction.getLayout().width + SPACE; 00146 positionY = graphicFunction.getLayout().y + SPACE; 00147 for (Element element : function.getOutput()) 00148 { 00149 Node node = getGraphicalNodeInParent(element, graphicParent); 00150 node.setLayout(new Rectangle(positionX, positionY, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00151 positionY += SPACE; 00152 graphicFunction.addOutputPointConnection((PointConnection) node); 00153 } 00154 } 00155 00156 00163 private void createLoopFor(LoopFor loopFor, Node graphicParent, Vector<Vector<Element>> elementLevel) 00164 { 00165 // Levels of intern nodes of the GraphicFor 00166 Vector<Vector<Element>> elementLevelFor = new Vector<Vector<Element>>(); 00167 00168 // Levels of intern GraphicIf and GraphicLoopIterator conditions of the GraphicFor 00169 Vector<Vector<Element>> conditions = new Vector<Vector<Element>>(); 00170 00171 /* Creation of the GraphicFor */ 00172 GraphicLoop graphicFor = new GraphicLoop(); 00173 graphicFor.setName(loopFor.getName()); 00174 graphicFor.setElement(loopFor); 00175 graphicParent.addChild(graphicFor); 00176 graphicFor.getLayout().setLocation(0, 0); 00177 00178 /* Go through the inputs of the loopFor */ 00179 Node nodeIn; 00180 int levelMax = 0; 00181 for (Element element : loopFor.getInput()) 00182 { 00183 nodeIn = getGraphicalNodeInParent(element, graphicParent); 00184 if(nodeIn instanceof GraphicLoopIterator) 00185 nodeIn = ((GraphicLoopIterator) nodeIn).getOutputPointConnection(); 00186 00187 if(nodeIn != null) 00188 { 00189 /* Create a copy of an input PointConnection */ 00190 levelMax = Math.max(levelMax, nodeIn.getLevel()+1); 00191 PointConnection pc = new PointConnection(); 00192 pc.setName(element.getName()); 00193 pc.setElement(element); 00194 pc.setLayout(new Rectangle (0, Math.max(SPACE_INTERN_BLOC, (nodeIn.getLayout().y - graphicParent.getLayout().y)/10), PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00195 pc.setLevel(0); 00196 if(pc.getLevel() > elementLevelFor.size()-1) 00197 elementLevelFor.add(new Vector<Element>()); 00198 elementLevelFor.elementAt(pc.getLevel()).add(element); 00199 graphicFor.addChild(pc); 00200 new Connection(nodeIn, pc); 00201 } 00202 } 00203 00204 /* Set the level of the GraphicLoop */ 00205 graphicFor.setLevel(levelMax); 00206 if(graphicFor.getLevel() > elementLevel.size()-1) 00207 elementLevel.add(new Vector<Element>()); 00208 elementLevel.elementAt(graphicFor.getLevel()).add(loopFor); 00209 00210 /* Go through the outputs of the function */ 00211 for (Element element : loopFor.getOutput()) 00212 { 00213 if(getGraphicalNodeInParent(element, graphicParent) == null) 00214 { 00215 PointConnection pc = new PointConnection(); 00216 pc.setName(element.getName()); 00217 pc.setElement(element); 00218 graphicParent.addChild(pc); 00219 } 00220 getGraphicalNodeInParent(element, graphicParent).setLevel(graphicFor.getLevel()); 00221 } 00222 00223 /* Creation and initialisation of the GraphicLoopIterator */ 00224 GraphicLoopIterator iter = new GraphicLoopIterator(); 00225 iter.setEndCondition(loopFor.getEnd().getType().equals("const") ? String.valueOf(((SimpleVariable)loopFor.getEnd()).getVal()) : loopFor.getEnd().getName()); 00226 iter.setIncrementation(loopFor.getIncr().getType().equals("const") ? String.valueOf(((SimpleVariable)loopFor.getIncr()).getVal()) : loopFor.getIncr().getName()); 00227 iter.setStartInitialisation(loopFor.getStart().getType().equals("const") ? String.valueOf(((SimpleVariable)loopFor.getStart()).getVal()) : loopFor.getStart().getName()); 00228 iter.setIterOperation(loopFor.getIterOperation()); 00229 if(!loopFor.getEnd().getType().equals("const")) 00230 iter.addConditionNodes(getGraphicalNodeInParent(loopFor.getEnd(), graphicFor)); 00231 if(!loopFor.getIncr().getType().equals("const")) 00232 iter.addConditionNodes(getGraphicalNodeInParent(loopFor.getIncr(), graphicFor)); 00233 if(!loopFor.getStart().getType().equals("const")) 00234 iter.addConditionNodes(getGraphicalNodeInParent(loopFor.getStart(), graphicFor)); 00235 iter.setName(loopFor.getInternalVars().get(0).getName()); 00236 iter.setLayout(new Rectangle(0, 0, LoopIteratorFigure.WIDTH, LoopIteratorFigure.HEIGHT)); 00237 graphicFor.addChild(iter); 00238 00239 /* Set the level of the GraphicLoopIterator */ 00240 iter.setLevel(1); 00241 iter.setElement(loopFor.getInternalVars().get(0)); 00242 if(elementLevelFor.isEmpty()) 00243 elementLevelFor.add(new Vector<Element>()); 00244 if(iter.getLevel() > elementLevelFor.size()-1) 00245 elementLevelFor.add(new Vector<Element>()); 00246 elementLevelFor.elementAt(iter.getLevel()).add(iter.getElement()); 00247 00248 /* Creation of the output point of the GraphicLoopIterator */ 00249 PointConnection pc = new PointConnection(); 00250 pc.setName(loopFor.getInternalVars().get(0).getName()); 00251 pc.setElement(loopFor.getInternalVars().get(0)); 00252 pc.setLayout(new Rectangle (0, 0, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00253 graphicFor.addChild(pc); 00254 pc.setLevel(iter.getLevel()); 00255 iter.setOutputPointConnexion(pc); 00256 new Connection(iter.getOutPoint(), pc); 00257 00258 /* Go through the body of the loopFor */ 00259 for (Element element : loopFor.getBody()) 00260 { 00261 if(element instanceof Assignment) 00262 createAssignment((Assignment) element, graphicFor, elementLevelFor); 00263 else if(element instanceof IfThenElse && element.getName().contains("loopfor")) 00264 createIfThenElseFor((IfThenElse) element, graphicFor, elementLevelFor); 00265 else if(element instanceof IfThenElse) 00266 conditions.add(createIfThenElse((IfThenElse) element, graphicFor, elementLevelFor)); 00267 else if(element instanceof Multiplexer) 00268 createMultiplexer((Multiplexer) element, graphicFor, elementLevelFor, conditions); 00269 else if(element instanceof Operation) 00270 createOperation((Operation) element, graphicFor, elementLevelFor); 00271 else if(element instanceof LoopFor) 00272 createLoopFor((LoopFor) element, graphicFor, elementLevelFor); 00273 else if(element instanceof LoopWhile) 00274 createLoopWhile((LoopWhile) element, graphicFor, elementLevelFor); 00275 } 00276 00277 /* Set node locations of different levels of the GraphicLoop */ 00278 for (Vector<Element> level : elementLevelFor) 00279 locateNodesLevel(level, graphicFor); 00280 00281 /* Set the size of the GraphicLoop */ 00282 graphicFor.setFullSize(graphicFor.getLayout().width, graphicFor.getLayout().height); 00283 graphicFor.setReductSize(80, 15); 00284 } 00285 00286 00293 private void createLoopWhile(LoopWhile loopWhile, Node graphicParent, Vector<Vector<Element>> elementLevel) 00294 { 00295 // Levels of intern nodes of the GraphicFor 00296 Vector<Vector<Element>> elementLevelWhile = new Vector<Vector<Element>>(); 00297 00298 // Levels of intern GraphicIf and GraphicLoopIterator conditions of the GraphicFor 00299 Vector<Vector<Element>> conditions = new Vector<Vector<Element>>(); 00300 00301 /* Creation of the GraphicFor */ 00302 GraphicLoop graphicWhile = new GraphicLoop(); 00303 graphicWhile.setName(loopWhile.getName()); 00304 graphicWhile.setElement(loopWhile); 00305 graphicParent.addChild(graphicWhile); 00306 graphicWhile.getLayout().setLocation(0, 0); 00307 00308 /* Go through the inputs of the lopWhile */ 00309 Node nodeIn; 00310 int levelMax = 0; 00311 for (Element element : loopWhile.getInput()) 00312 { 00313 nodeIn = getGraphicalNodeInParent(element, graphicParent); 00314 if(nodeIn instanceof GraphicLoopIterator) 00315 nodeIn = ((GraphicLoopIterator) nodeIn).getOutputPointConnection(); 00316 00317 if(nodeIn != null) 00318 { 00319 /* Create a copy of an input PointConnection */ 00320 levelMax = Math.max(levelMax, nodeIn.getLevel()+1); 00321 PointConnection pc = new PointConnection(); 00322 pc.setName(element.getName()); 00323 pc.setElement(element); 00324 pc.setLayout(new Rectangle (0, Math.max(SPACE_INTERN_BLOC, (nodeIn.getLayout().y - graphicParent.getLayout().y)/10), PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00325 pc.setLevel(0); 00326 if(pc.getLevel() > elementLevelWhile.size()-1) 00327 elementLevelWhile.add(new Vector<Element>()); 00328 elementLevelWhile.elementAt(pc.getLevel()).add(element); 00329 graphicWhile.addChild(pc); 00330 new Connection(nodeIn, pc); 00331 } 00332 } 00333 00334 /* Set the level of the GraphicLoop */ 00335 graphicWhile.setLevel(levelMax); 00336 if(graphicWhile.getLevel() > elementLevel.size()-1) 00337 elementLevel.add(new Vector<Element>()); 00338 elementLevel.elementAt(graphicWhile.getLevel()).add(loopWhile); 00339 00340 /* Go through outputs of the function */ 00341 for (Element element : loopWhile.getOutput()) 00342 { 00343 if(getGraphicalNodeInParent(element, graphicParent) == null) 00344 { 00345 PointConnection pc = new PointConnection(); 00346 pc.setName(element.getName()); 00347 pc.setElement(element); 00348 graphicParent.addChild(pc); 00349 } 00350 getGraphicalNodeInParent(element, graphicParent).setLevel(graphicWhile.getLevel()); 00351 } 00352 00353 /* Go through the body of the loopFor */ 00354 for (Element element : loopWhile.getBody()) 00355 { 00356 if(element instanceof Assignment) 00357 createAssignment((Assignment) element, graphicWhile, elementLevelWhile); 00358 else if(element instanceof IfThenElse && element.getName().contains("loopwhile")) 00359 createIfThenElseWhile((IfThenElse) element, graphicWhile, elementLevelWhile); 00360 else if(element instanceof IfThenElse) 00361 conditions.add(createIfThenElse((IfThenElse) element, graphicWhile, elementLevelWhile)); 00362 else if(element instanceof Multiplexer) 00363 createMultiplexer((Multiplexer) element, graphicWhile, elementLevelWhile, conditions); 00364 else if(element instanceof Operation) 00365 createOperation((Operation) element, graphicWhile, elementLevelWhile); 00366 else if(element instanceof LoopFor) 00367 createLoopFor((LoopFor) element, graphicWhile, elementLevelWhile); 00368 else if(element instanceof LoopWhile) 00369 createLoopWhile((LoopWhile) element, graphicWhile, elementLevelWhile); 00370 } 00371 00372 /* Set condition nodes of GraphicIf */ 00373 for (Node node : graphicWhile.getChildrenArray()) 00374 if(node instanceof GraphicIf && node.getName().contains("loopwhile")) 00375 { 00376 Node condNode; 00377 for(Element e: loopWhile.getCond()) { 00378 for(Element e1: ((Operation)e).getInput()) { 00379 condNode = getGraphicalNodeInParent(e1, graphicWhile); 00380 if(condNode != null) 00381 ((GraphicIf)node).addConditionNodes(condNode); 00382 else 00383 { 00384 condNode = getGraphicalNode(e1); 00385 if(condNode != null) 00386 ((GraphicIf)node).addConditionNodes(condNode); 00387 } 00388 } 00389 } 00390 } 00391 00392 /* Set node locations of different levels of the GraphicFor */ 00393 for (Vector<Element> level : elementLevelWhile) 00394 locateNodesLevel(level, graphicWhile); 00395 00396 /* Set the size of the GraphicFor */ 00397 graphicWhile.setFullSize(graphicWhile.getLayout().width, graphicWhile.getLayout().height); 00398 graphicWhile.setReductSize(80, 15); 00399 } 00400 00401 00408 private void createAssignment(Assignment assignment, Node graphicParent, Vector<Vector<Element>> elementLevel) 00409 { 00410 /* Get the input and ouput elements of the assignment */ 00411 Element elementIn = assignment.getInputAt(0); 00412 Element elementOut = assignment.getOutputAt(0); 00413 00414 /* Get the input and ouput nodes of the assignment */ 00415 Node nodeIn = getGraphicalNode(elementIn); 00416 if(nodeIn instanceof GraphicLoopIterator) 00417 nodeIn = ((GraphicLoopIterator) nodeIn).getOutputPointConnection(); 00418 Node nodeOut = getGraphicalNode(elementOut); 00419 00420 if(nodeOut == null) 00421 { 00422 /* Creation of the output point of the assignment */ 00423 PointConnection pc = new PointConnection(); 00424 pc.setName(elementOut.getName()); 00425 pc.setElement(elementOut); 00426 graphicParent.addChild(pc); 00427 00428 /* Case of an assignment between a constant and a variable */ 00429 if(nodeIn == null) 00430 { 00431 pc.setLevel(0); 00432 pc.setIsConstant(true); 00433 pc.setName(String.valueOf(((SimpleVariable)elementIn).getVal())); 00434 pc.setLayout(new Rectangle (0, 0, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00435 } 00436 else 00437 { 00438 nodeIn = getGraphicalNodeInParent(elementIn, graphicParent); 00439 /* Case of an assignment between two intern PointConnection */ 00440 if(nodeIn != null) 00441 { 00442 pc.setLevel(nodeIn.getLevel()+1); 00443 if(pc.getLevel() > elementLevel.size()-1) 00444 elementLevel.add(new Vector<Element>()); 00445 pc.setLayout(new Rectangle (0, 0, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00446 } 00447 /* Case of an assignment between an intern and an extern PointConnection */ 00448 else 00449 { 00450 nodeIn = getGraphicalNodeInParent(elementIn, graphicParent.getParent()); 00451 pc.setLevel(0); 00452 if(pc.getLevel() > elementLevel.size()-1) 00453 elementLevel.add(new Vector<Element>()); 00454 pc.setLayout(new Rectangle (0, Math.max(SPACE_INTERN_BLOC, (nodeIn.getLayout().y - graphicParent.getLayout().y)/10), PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00455 } 00456 new Connection(nodeIn, pc); 00457 elementLevel.elementAt(pc.getLevel()).add(assignment); 00458 } 00459 } 00460 /* Case of an assignment between a constant and a variable */ 00461 else 00462 new Connection(nodeIn, nodeOut); 00463 } 00464 00465 00473 private Vector<Element> createIfThenElse(IfThenElse ifThenElse, Node graphicParent, Vector<Vector<Element>> elementLevel) 00474 { 00475 // Levels of intern GraphicIf conditions of the GraphicIf 00476 Vector<Vector<Element>> conditions = new Vector<Vector<Element>>(); 00477 00478 /* Go through the body true of the IfThenElse */ 00479 for(Element element : ifThenElse.getBodyTrue()) 00480 { 00481 if(element instanceof Assignment) 00482 createAssignment((Assignment) element, graphicParent, elementLevel); 00483 else if(element instanceof IfThenElse) 00484 conditions.add(createIfThenElse((IfThenElse) element, graphicParent, elementLevel)); 00485 else if(element instanceof Multiplexer) 00486 createMultiplexer((Multiplexer) element, graphicParent, elementLevel, conditions); 00487 else if(element instanceof Operation) 00488 createOperation((Operation) element, graphicParent, elementLevel); 00489 else if(element instanceof LoopFor) 00490 createLoopFor((LoopFor) element, graphicParent, elementLevel); 00491 else if(element instanceof LoopWhile) 00492 createLoopWhile((LoopWhile) element, graphicParent, elementLevel); 00493 } 00494 00495 /* Go through the body false of the IfThenElse */ 00496 for(Element element : ifThenElse.getBodyFalse()) 00497 { 00498 if(element instanceof m2m.backend.structure.Assignment) 00499 createAssignment((Assignment) element, graphicParent, elementLevel); 00500 else if(element instanceof IfThenElse) 00501 conditions.add(createIfThenElse((IfThenElse) element, graphicParent, elementLevel)); 00502 else if(element instanceof Multiplexer) 00503 createMultiplexer((Multiplexer) element, graphicParent, elementLevel, conditions); 00504 else if(element instanceof Operation) 00505 createOperation((Operation) element, graphicParent, elementLevel); 00506 else if(element instanceof LoopFor) 00507 createLoopFor((LoopFor) element, graphicParent, elementLevel); 00508 } 00509 00510 // Return the condition of the IfThenElse 00511 return ifThenElse.getCond(); 00512 } 00513 00514 00521 private void createIfThenElseFor(IfThenElse ifThenElse, Node graphicParent, Vector<Vector<Element>> elementLevel) 00522 { 00523 /* Get the condition of the IfThenElse */ 00524 Vector<Element> condition = new Vector<Element>(); 00525 Operation cond = new Equal(); 00526 cond.addOutput(((Operation)ifThenElse.getCond().firstElement()).getOutputAt(0)); 00527 cond.addInput(((LoopFor)graphicParent.getElement()).getInternalVars().firstElement()); 00528 cond.addInput(((LoopFor)graphicParent.getElement()).getStart()); 00529 condition.add(cond); 00530 00531 /* Creation of the GraphicIf */ 00532 GraphicIf graphicIf = new GraphicIf(); 00533 graphicIf.setName(ifThenElse.getName()); 00534 graphicIf.setLayout(new Rectangle(0, 0, IfFigure.WIDTH, IfFigure.HEIGHT)); 00535 graphicIf.setElement(ifThenElse); 00536 graphicIf.setCondition(getConditionString(condition)); 00537 graphicParent.addChild(graphicIf); 00538 00539 // Set condition nodes of GraphicIf 00540 graphicIf.addConditionNodes(getGraphicalNodeInParent(((Operation)condition.firstElement()).getInput().firstElement(), graphicParent)); 00541 Node condNode = getGraphicalNode(((Operation)condition.firstElement()).getInputAt(1)); 00542 if(condNode != null) 00543 graphicIf.addConditionNodes(condNode); 00544 00545 /* Get input nodes of the IfThenElse */ 00546 Node nodeIn1 = getGraphicalNodeInParent(((Assignment)ifThenElse.getBodyTrue().firstElement()).getInputAt(0), graphicParent); 00547 Node nodeIn2 = getGraphicalNodeInParent(((Assignment)ifThenElse.getBodyFalse().firstElement()).getInputAt(0), graphicParent); 00548 if(nodeIn1 instanceof GraphicLoopIterator) 00549 nodeIn1 = ((GraphicLoopIterator) nodeIn1).getOutputPointConnection(); 00550 if(nodeIn2 instanceof GraphicLoopIterator) 00551 nodeIn2 = ((GraphicLoopIterator) nodeIn2).getOutputPointConnection(); 00552 00553 if (nodeIn2 == null) 00554 { 00555 /* Create the second input */ 00556 Element elementIn = ((Assignment)ifThenElse.getBodyFalse().firstElement()).getInputAt(0); 00557 PointConnection pc = new PointConnection(); 00558 pc.setName(elementIn.getName()); 00559 pc.setLevel(nodeIn1.getLevel()); 00560 pc.setLayout(new Rectangle (0, 0, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00561 pc.setElement(elementIn); 00562 graphicParent.addChild(pc); 00563 nodeIn2 = pc; 00564 } 00565 00566 /* Set the level of the GraphicIf */ 00567 graphicIf.setLevel(Math.max(nodeIn1.getLevel(), nodeIn2.getLevel())+1); 00568 if(graphicIf.getLevel() > elementLevel.size()-1) 00569 elementLevel.add(new Vector<Element>()); 00570 elementLevel.elementAt(graphicIf.getLevel()).add(ifThenElse); 00571 00572 /* Creation of the output point of GraphicIf */ 00573 Element elementOut = ((Assignment)ifThenElse.getBodyTrue().firstElement()).getOutputAt(0); 00574 PointConnection pc = new PointConnection(); 00575 pc.setName(elementOut.getName()); 00576 pc.setLevel(graphicIf.getLevel()); 00577 pc.setElement(elementOut); 00578 pc.setLayout(new Rectangle (0, 0, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00579 graphicParent.addChild(pc); 00580 graphicIf.setOutputPointConnexion(pc); 00581 00582 new Connection(nodeIn1, graphicIf.getTruePoint()); 00583 new Connection(nodeIn2, graphicIf.getFalsePoint()); 00584 new Connection(graphicIf.getOutPoint(), pc); 00585 } 00586 00593 private void createIfThenElseWhile(IfThenElse ifThenElse, Node graphicParent, Vector<Vector<Element>> elementLevel) 00594 { 00595 // Get the condition of the IfThenElse 00596 Vector<Element> condition = ifThenElse.getCond(); 00597 00598 /* Creation of the GraphicIf */ 00599 GraphicIf graphicIf = new GraphicIf(); 00600 graphicIf.setName(ifThenElse.getName()); 00601 graphicIf.setLayout(new Rectangle(0, 0, IfFigure.WIDTH, IfFigure.HEIGHT)); 00602 graphicIf.setElement(ifThenElse); 00603 graphicIf.setCondition(getConditionString(condition)); 00604 graphicParent.addChild(graphicIf); 00605 00606 /* Get input nodes of the IfThenElse */ 00607 Node nodeIn1 = getGraphicalNodeInParent(((Assignment)ifThenElse.getBodyTrue().firstElement()).getInputAt(0), graphicParent); 00608 Node nodeIn2 = getGraphicalNodeInParent(((Assignment)ifThenElse.getBodyFalse().firstElement()).getInputAt(0), graphicParent); 00609 if(nodeIn1 instanceof GraphicLoopIterator) 00610 nodeIn1 = ((GraphicLoopIterator) nodeIn1).getOutputPointConnection(); 00611 if(nodeIn2 instanceof GraphicLoopIterator) 00612 nodeIn2 = ((GraphicLoopIterator) nodeIn2).getOutputPointConnection(); 00613 00614 if (nodeIn2 == null) 00615 { 00616 /* Create the second input */ 00617 Element elementIn = ((Assignment)ifThenElse.getBodyFalse().firstElement()).getInputAt(0); 00618 PointConnection pc = new PointConnection(); 00619 pc.setName(elementIn.getName()); 00620 pc.setLevel(nodeIn1.getLevel()); 00621 pc.setLayout(new Rectangle (0, 0, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00622 pc.setElement(elementIn); 00623 graphicParent.addChild(pc); 00624 nodeIn2 = pc; 00625 } 00626 00627 /* Set the level of the GraphicIf */ 00628 graphicIf.setLevel(Math.max(nodeIn1.getLevel(), nodeIn2.getLevel())+1); 00629 if(graphicIf.getLevel() > elementLevel.size()-1) 00630 elementLevel.add(new Vector<Element>()); 00631 elementLevel.elementAt(graphicIf.getLevel()).add(ifThenElse); 00632 00633 /* Creation of the output point of GraphicIf */ 00634 Element elementOut = ((Assignment)ifThenElse.getBodyTrue().firstElement()).getOutputAt(0); 00635 PointConnection pc = new PointConnection(); 00636 pc.setName(elementOut.getName()); 00637 pc.setLevel(graphicIf.getLevel()); 00638 pc.setElement(elementOut); 00639 pc.setLayout(new Rectangle (0, 0, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00640 graphicParent.addChild(pc); 00641 graphicIf.setOutputPointConnexion(pc); 00642 00643 00644 new Connection(nodeIn1, graphicIf.getTruePoint()); 00645 new Connection(nodeIn2, graphicIf.getFalsePoint()); 00646 new Connection(graphicIf.getOutPoint(), pc); 00647 } 00648 00649 00657 private void createMultiplexer(Multiplexer mux, Node graphicParent, Vector<Vector<Element>> elementLevel, Vector<Vector<Element>> conditions) 00658 { 00659 /* Get the condition of the Multiplexer */ 00660 Vector<Element> condition = new Vector<Element>(); 00661 String variableConditionName = mux.getSel().getName(); 00662 for(Vector<Element> cond : conditions) 00663 if(((Operation)cond.lastElement()).getOutputAt(0).getName().equalsIgnoreCase(variableConditionName)) 00664 condition.addAll(cond); 00665 00666 /* Creation of the GraphicIf */ 00667 GraphicIf ifThenElse = new GraphicIf(); 00668 ifThenElse.setName(mux.getName()); 00669 ifThenElse.setLayout(new Rectangle(0, 0, IfFigure.WIDTH, IfFigure.HEIGHT)); 00670 ifThenElse.setElement(mux); 00671 ifThenElse.setCondition(getConditionString(condition)); 00672 graphicParent.addChild(ifThenElse); 00673 00674 /* Set condition nodes of the GraphicIf */ 00675 Vector<Element> inputCondition = new Vector<Element>(); 00676 Vector<Element> outputCondition = new Vector<Element>(); 00677 for(Element element : condition) 00678 { 00679 for(Element input : ((Operation)element).getInput()) 00680 if(!inputCondition.contains(input) && !((Variable)input).getType().equals("const")) 00681 inputCondition.add(input); 00682 outputCondition.addAll(((Operation)element).getOutput()); 00683 } 00684 inputCondition.removeAll(outputCondition); 00685 for(Element element : inputCondition) 00686 ifThenElse.addConditionNodes(getGraphicalNodeInParent(element, graphicParent)); 00687 00688 /* Get input nodes of the multiplexer */ 00689 Node nodeIn1 = getGraphicalNodeInParent(mux.getInputAt(0), graphicParent); 00690 Node nodeIn2 = getGraphicalNodeInParent(mux.getInputAt(1), graphicParent); 00691 if(nodeIn1 instanceof GraphicLoopIterator) 00692 nodeIn1 = ((GraphicLoopIterator) nodeIn1).getOutputPointConnection(); 00693 if(nodeIn2 instanceof GraphicLoopIterator) 00694 nodeIn2 = ((GraphicLoopIterator) nodeIn2).getOutputPointConnection(); 00695 00696 /* Set the level of the GraphicIf */ 00697 ifThenElse.setLevel(Math.max(nodeIn1.getLevel(), nodeIn2.getLevel())+1); 00698 if(ifThenElse.getLevel() > elementLevel.size()-1) 00699 elementLevel.add(new Vector<Element>()); 00700 elementLevel.elementAt(ifThenElse.getLevel()).add(mux); 00701 00702 /* Creation of the output point of the GraphicIf */ 00703 Element elementOut = mux.getOutputAt(0); 00704 PointConnection pc = new PointConnection(); 00705 if(getGraphicalNodeInParent(elementOut, graphicParent) != null) 00706 pc = (PointConnection)getGraphicalNodeInParent(elementOut, graphicParent); 00707 else 00708 { 00709 pc.setName(elementOut.getName()); 00710 pc.setElement(elementOut); 00711 pc.setLayout(new Rectangle (0, 0, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00712 graphicParent.addChild(pc); 00713 } 00714 ifThenElse.setOutputPointConnexion(pc); 00715 pc.setLevel(ifThenElse.getLevel()); 00716 00717 new Connection(nodeIn1, ifThenElse.getTruePoint()); 00718 new Connection(nodeIn2, ifThenElse.getFalsePoint()); 00719 new Connection(ifThenElse.getOutPoint(), pc); 00720 } 00721 00722 00729 private void createOperation(Operation operation, Node graphicParent, Vector<Vector<Element>> elementLevel) 00730 { 00731 Node node; 00732 int maxLevel = 0; 00733 Vector<Node> inputs = new Vector<Node>(); 00734 00735 /* Get nodes input of the operation */ 00736 for(Element e : operation.getInput()) { 00737 node = getGraphicalNodeInParent(e, graphicParent); 00738 if(node instanceof GraphicLoopIterator) 00739 node = ((GraphicLoopIterator) node).getOutputPointConnection(); 00740 inputs.add(node); 00741 } 00742 00743 for(int i = 0; i < inputs.size(); i++) { 00744 node = inputs.get(i); 00745 if(node == null) { 00746 /* Create the first constant input */ 00747 PointConnection pc = new PointConnection(); 00748 pc.setName(String.valueOf(((SimpleVariable)operation.getInputAt(i)).getVal())); 00749 if(i == 0 && inputs.size() > 1) 00750 pc.setLevel(inputs.get(1) == null ? 0 : inputs.get(1).getLevel()); 00751 else if(i == 1) 00752 pc.setLevel(inputs.get(0) == null ? 0 : inputs.get(0).getLevel()); 00753 pc.setLayout(new Rectangle (0, 0, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00754 pc.setElement(operation.getInputAt(i)); 00755 graphicParent.addChild(pc); 00756 pc.setIsConstant(true); 00757 inputs.set(i, pc); 00758 } 00759 } 00760 00761 /* Creation of the GraphicOperation */ 00762 GraphicOperation o = new GraphicOperation(); 00763 o.setName(operation.getName()); 00764 o.setElement(operation); 00765 o.setOperatorName(operation.getOpSymbol()); 00766 graphicParent.addChild(o); 00767 00768 /* Set the level of the GraphicOperation */ 00769 for(Node in : inputs) 00770 maxLevel = maxLevel < in.getLevel() ? in.getLevel() : maxLevel; 00771 o.setLevel(maxLevel+1); 00772 if(o.getLevel() > elementLevel.size()-1) 00773 elementLevel.add(new Vector<Element>()); 00774 elementLevel.elementAt(o.getLevel()).add(operation); 00775 o.setLayout(new Rectangle (0, 0, OperationFigure.WIDTH, OperationFigure.HEIGHT)); 00776 00777 /* Creation of the output point of the GraphicOperation */ 00778 Element elementOut = operation.getOutput().elementAt(0); 00779 PointConnection pc = new PointConnection(); 00780 if(getGraphicalNodeInParent(elementOut, graphicParent) != null) 00781 pc = (PointConnection)getGraphicalNodeInParent(elementOut, graphicParent); 00782 else { 00783 pc.setName(elementOut.getName()); 00784 pc.setElement(elementOut); 00785 pc.setLayout(new Rectangle (0, 0, PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT)); 00786 graphicParent.addChild(pc); 00787 } 00788 o.setOutputPointConnexion(pc); 00789 pc.setLevel(o.getLevel()); 00790 00791 for(Node in : inputs) 00792 new Connection(in, o); 00793 new Connection(o, pc); 00794 } 00795 00796 00802 private void locateNodesLevel(Vector<Element> level, GraphicFunction graphicFunction) 00803 { 00804 Vector<Node> nodes = new Vector<Node>(); 00805 Point bestLocation = new Point(); 00806 Node nodeOut = null; 00807 Node nodeIn = null; 00808 00809 /* Create the node vector */ 00810 for (Element element : level) 00811 { 00812 if(element instanceof Assignment) 00813 nodes.add(getGraphicalNodeInParent(((Assignment)element).getOutputAt(0), graphicFunction)); 00814 else 00815 nodes.add(getGraphicalNodeInParent(element, graphicFunction)); 00816 } 00817 00818 /* Get and set the best location for all nodes of the level */ 00819 for (Node node: nodes) 00820 { 00821 if(!(node instanceof PointConnection && ((PointConnection)node).getIsConstant()) && node.getLevel() != 0) 00822 { 00823 int index = nodes.indexOf(node); 00824 bestLocation = getBestLocation(level.elementAt(index), graphicFunction); 00825 00826 if(node instanceof PointConnection) 00827 node.getLayout().setLocation(graphicFunction.getLayout().width, Math.max(SPACE_INTERN_BLOC, bestLocation.y-PointConnectionFigure.WIDTH/2)); 00828 else if(node instanceof GraphicOperation) 00829 node.getLayout().setLocation(graphicFunction.getLayout().width, Math.max(SPACE_INTERN_BLOC, bestLocation.y-OperationFigure.WIDTH/2)); 00830 else if(node instanceof GraphicIf) 00831 node.getLayout().setLocation(graphicFunction.getLayout().width, Math.max(SPACE_INTERN_BLOC, bestLocation.y-IfFigure.WIDTH/2)); 00832 else if(node instanceof GraphicLoop) 00833 node.getLayout().setLocation(graphicFunction.getLayout().width, Math.max(SPACE_INTERN_BLOC, bestLocation.y-node.getLayout().height/2)); 00834 else if(node instanceof GraphicLoopIterator) 00835 node.getLayout().setLocation(graphicFunction.getLayout().width, Math.max(SPACE_INTERN_BLOC, bestLocation.y-node.getLayout().height/2)); 00836 } 00837 } 00838 00839 // Suppression of all superpositions 00840 elasticLayout(nodes); 00841 00842 /* Update the size of the parent node and locate output and constant node */ 00843 for (Node node: nodes) 00844 { 00845 if(node instanceof PointConnection) 00846 { 00847 /* Update the size of the parent node */ 00848 graphicFunction.getLayout().setSize(Math.max(graphicFunction.getLayout().width, node.getLayout().x + node.getLayout().width + SPACE_INTERN_BLOC), 00849 Math.max(graphicFunction.getLayout().height, node.getLayout().y + node.getLayout().height + SPACE_INTERN_BLOC)); 00850 } 00851 else if(node instanceof GraphicOperation) 00852 { 00853 locateConstantInput(node.getElement(), graphicFunction); 00854 00855 /* Locate output of the GraphicOperation */ 00856 nodeOut = ((GraphicOperation)node).getOutputPointConnection(); 00857 nodeOut.getLayout().x = node.getLayout().x + node.getLayout().width + 10; 00858 nodeOut.getLayout().y = (2*node.getLayout().y + node.getLayout().height)/2 - PointConnectionFigure.HEIGHT/2; 00859 00860 /* Update the size of the parent node */ 00861 graphicFunction.getLayout().setSize(Math.max(graphicFunction.getLayout().width, nodeOut.getLayout().x + nodeOut.getLayout().width + SPACE_INTERN_BLOC), 00862 Math.max(graphicFunction.getLayout().height, nodeOut.getLayout().y + nodeOut.getLayout().height + SPACE_INTERN_BLOC)); 00863 } 00864 else if(node instanceof GraphicIf) 00865 { 00866 locateConstantInput(node.getElement(), graphicFunction); 00867 00868 /* Locate output of the GraphicIf */ 00869 nodeOut = ((GraphicIf)node).getOutputPointConnection(); 00870 nodeOut.getLayout().x = node.getLayout().x + node.getLayout().width + 10; 00871 nodeOut.getLayout().y = (2*node.getLayout().y + node.getLayout().height)/2 - PointConnectionFigure.HEIGHT/2; 00872 00873 /* Update the size of the parent node */ 00874 graphicFunction.getLayout().setSize(Math.max(graphicFunction.getLayout().width, nodeOut.getLayout().x + nodeOut.getLayout().width + SPACE_INTERN_BLOC), 00875 Math.max(graphicFunction.getLayout().height, nodeOut.getLayout().y + nodeOut.getLayout().height + SPACE_INTERN_BLOC)); 00876 } 00877 else if(node instanceof GraphicLoop) 00878 { 00879 Vector<Node> outputNodes = new Vector<Node>(); 00880 00881 // Update the size of the parent node 00882 graphicFunction.getLayout().setSize(Math.max(graphicFunction.getLayout().width, node.getLayout().x + node.getLayout().width + SPACE_INTERN_BLOC), 00883 Math.max(graphicFunction.getLayout().height, node.getLayout().y + node.getLayout().height + SPACE_INTERN_BLOC)); 00884 00885 /* Locate all outputs of the GraphicFor */ 00886 for (Element element : ((Function)node.getElement()).getOutput()) 00887 { 00888 nodeOut = getGraphicalNodeInParent(element, graphicFunction); 00889 nodeOut.getLayout().x = node.getLayout().x + node.getLayout().width + 15; 00890 nodeOut.getLayout().y = node.getLayout().y + getGraphicalNodeInParent(element, node).getLayout().y; 00891 nodeOut.getLayout().setSize(PointConnectionFigure.WIDTH, PointConnectionFigure.HEIGHT); 00892 ((GraphicLoop)node).addOutputPointConnection((PointConnection) nodeOut); 00893 outputNodes.add(nodeOut); 00894 new Connection(getGraphicalNodeInParent(element, node), getGraphicalNodeInParent(element, graphicFunction)); 00895 00896 /* Update the size of the parent node */ 00897 graphicFunction.getLayout().setSize(Math.max(graphicFunction.getLayout().width, nodeOut.getLayout().x + nodeOut.getLayout().width + SPACE_INTERN_BLOC), 00898 Math.max(graphicFunction.getLayout().height, node.getLayout().y + node.getLayout().height + SPACE_INTERN_BLOC)); 00899 } 00900 00901 elasticLayout(outputNodes); 00902 00903 /* Locate all constant input node */ 00904 for(Element element : ((Function)node.getElement()).getInput()) 00905 { 00906 nodeIn = getGraphicalNodeInParent(element, graphicFunction); 00907 if(((Variable)nodeIn.getElement()).getType().equals("const")) 00908 { 00909 nodeIn.getLayout().x = node.getLayout().x - 30; 00910 nodeIn.getLayout().y = node.getLayout().y + getGraphicalNodeInParent(element, node).getLayout().y+1; 00911 } 00912 } 00913 } 00914 else if(node instanceof GraphicLoopIterator) 00915 { 00916 /* Locate output of the GraphicIf */ 00917 nodeOut = ((GraphicLoopIterator)node).getOutputPointConnection(); 00918 nodeOut.getLayout().x = node.getLayout().x + node.getLayout().width + 10; 00919 nodeOut.getLayout().y = (2*node.getLayout().y + node.getLayout().height)/2 - PointConnectionFigure.HEIGHT/2 + 2; 00920 00921 /* Update the size of the parent node */ 00922 graphicFunction.getLayout().setSize(Math.max(graphicFunction.getLayout().width, nodeOut.getLayout().x + nodeOut.getLayout().width + SPACE_INTERN_BLOC), 00923 Math.max(graphicFunction.getLayout().height, nodeOut.getLayout().y + nodeOut.getLayout().height + SPACE_INTERN_BLOC)); 00924 } 00925 } 00926 } 00927 00928 00935 private Point getBestLocation(Element element, GraphicFunction graphicFunction) 00936 { 00937 Node nodeIn1; 00938 Node nodeIn2; 00939 Point point = new Point(); 00940 Node parentNode = getGraphicalNodeInParent(element, graphicFunction); 00941 00942 /* Get the best location of node represented by Assignment element */ 00943 if(element instanceof Operation && ((Operation)element).getInput().size() == 1) 00944 { 00945 /* Get the input of the Assignment element */ 00946 nodeIn1 = getGraphicalNodeInParent(((Operation)element).getInputAt(0), graphicFunction); 00947 point.setLocation(0, (nodeIn1.getLayout().y + nodeIn1.getLayout().height/2)); 00948 } 00949 00950 /* Get the best location of node represented by Operation element */ 00951 else if(element instanceof Operation) 00952 { 00953 /* Get the inputs of the Operation element */ 00954 nodeIn1 = getGraphicalNodeInParent(((Operation)element).getInputAt(0), graphicFunction); 00955 nodeIn2 = getGraphicalNodeInParent(((Operation)element).getInputAt(1), graphicFunction); 00956 if(nodeIn1 instanceof GraphicLoopIterator) 00957 nodeIn1 = ((GraphicLoopIterator) nodeIn1).getOutputPointConnection(); 00958 if(nodeIn2 instanceof GraphicLoopIterator) 00959 nodeIn2 = ((GraphicLoopIterator) nodeIn2).getOutputPointConnection(); 00960 00961 /* Check if there is an constant input */ 00962 if(!((PointConnection)nodeIn1).getIsConstant() && !((PointConnection)nodeIn2).getIsConstant()) 00963 point.setLocation(0, (nodeIn1.getLayout().y + nodeIn2.getLayout().y + nodeIn2.getLayout().height)/2); 00964 else if(((PointConnection)nodeIn1).getIsConstant() && ((PointConnection)nodeIn2).getIsConstant()) 00965 point.setLocation(0, SPACE_INTERN_BLOC + getGraphicalNodeInParent(element, graphicFunction).getLayout().height/2); 00966 else if(((PointConnection)nodeIn1).getIsConstant()) 00967 point.setLocation(0, nodeIn2.getLayout().y + nodeIn2.getLayout().height/2); 00968 else if(((PointConnection)nodeIn2).getIsConstant()) 00969 point.setLocation(0, nodeIn1.getLayout().y + nodeIn1.getLayout().height/2); 00970 } 00971 00972 /* Get the best location of node represented by IfThenElse element */ 00973 else if(element instanceof IfThenElse) 00974 { 00975 /* Get the inputs of the IfThenElse element */ 00976 nodeIn1 = getGraphicalNodeInParent(((Assignment)((IfThenElse)element).getBodyTrue().firstElement()).getInputAt(0), graphicFunction); 00977 nodeIn2 = getGraphicalNodeInParent(((Assignment)((IfThenElse)element).getBodyFalse().firstElement()).getInputAt(0), graphicFunction); 00978 if(nodeIn1 instanceof GraphicLoopIterator) 00979 nodeIn1 = ((GraphicLoopIterator) nodeIn1).getOutputPointConnection(); 00980 if(nodeIn2 instanceof GraphicLoopIterator) 00981 nodeIn2 = ((GraphicLoopIterator) nodeIn2).getOutputPointConnection(); 00982 00983 /* Check if there is an constant input */ 00984 if(nodeIn1.getLevel() > parentNode.getLevel()) 00985 point.setLocation(0, nodeIn2.getLayout().y + nodeIn2.getLayout().height/2); 00986 else if (nodeIn2.getLevel() > parentNode.getLevel()) 00987 point.setLocation(0, nodeIn1.getLayout().y + nodeIn1.getLayout().height/2); 00988 } 00989 00990 /* Get the best location of node represented by LoopFor element */ 00991 else if(element instanceof Function) 00992 { 00993 /* Get the first and last input of the LoopFor element */ 00994 Node firstInputNode = getGraphicalNodeInParent(((Function) element).getInput().lastElement(), graphicFunction); 00995 Node lastInputNode = getGraphicalNodeInParent(((Function) element).getInput().lastElement(), graphicFunction); 00996 00997 point.setLocation(0, (firstInputNode.getLayout().y+lastInputNode.getLayout().y)/2); 00998 } 00999 01000 else 01001 point.setLocation(0, SPACE_INTERN_BLOC); 01002 01003 return point; 01004 } 01005 01006 01012 private void locateConstantInput(Element element, Node graphicParent) 01013 { 01014 if(!(element instanceof Assignment) && !(element instanceof Function)) 01015 { 01016 01017 int value; 01018 Vector<Node> inputs = new Vector<Node>(); 01019 Rectangle layoutParent = getGraphicalNodeInParent(element, graphicParent).getLayout(); 01020 01021 /* Get nodes input of the operation */ 01022 for(Element e : ((Operation)element).getInput()) { 01023 Node node = getGraphicalNodeInParent(e, graphicParent); 01024 if(node instanceof GraphicLoopIterator) 01025 node = ((GraphicLoopIterator) node).getOutputPointConnection(); 01026 inputs.add(node); 01027 } 01028 01029 /* Locate constant nodes represented by Multiplexer element */ 01030 if(element instanceof Multiplexer) { 01031 for(int i = 0; i < inputs.size(); i++){ 01032 Node node = inputs.get(i); 01033 if(((PointConnection)node).getIsConstant()) 01034 node.getLayout().setLocation(layoutParent.x-20, layoutParent.y+5+i*19); 01035 } 01036 } 01037 /* Locate constant nodes represented by Operation element */ 01038 else if(element instanceof Operation) 01039 { 01040 if(inputs.size() == 2) 01041 { 01042 Node nodeIn1 = inputs.elementAt(0); 01043 Node nodeIn2 = inputs.elementAt(1); 01044 /* Locate the first and second node of the Multiplexer element */ 01045 if(((PointConnection)nodeIn1).getIsConstant() && ((PointConnection)nodeIn2).getIsConstant()) 01046 { 01047 nodeIn1.getLayout().setLocation(layoutParent.x-20, layoutParent.y-5); 01048 nodeIn2.getLayout().setLocation(layoutParent.x-20, layoutParent.y+15); 01049 } 01050 /* Locate the first node of the Multiplexer element */ 01051 else if(((PointConnection)nodeIn1).getIsConstant()) 01052 { 01053 value = (nodeIn2.getLayout().y > layoutParent.y) ? -5 : +15; 01054 nodeIn1.getLayout().setLocation(layoutParent.x-20, layoutParent.y+value); 01055 } 01056 /* Locate the second node of the Multiplexer element */ 01057 else if(((PointConnection)nodeIn2).getIsConstant()) 01058 { 01059 value = (nodeIn1.getLayout().y > layoutParent.y) ? -5 : +15; 01060 nodeIn2.getLayout().setLocation(layoutParent.x-20, layoutParent.y+value); 01061 } 01062 } 01063 else if(inputs.size() == 1) 01064 { 01065 if(((PointConnection)inputs.elementAt(0)).getIsConstant()) 01066 inputs.elementAt(0).getLayout().setLocation(layoutParent.x-20, layoutParent.y+4); 01067 } 01068 } 01069 } 01070 } 01071 01076 private void elasticLayout(Vector<Node> nodes) 01077 { 01078 Node tempNode; 01079 01080 /* Order the node list with the bigger horizontal position */ 01081 for(int i = 0; i < nodes.size(); i++) 01082 for(int j = i; j < nodes.size(); j++) 01083 if(nodes.elementAt(i).getLayout().y < nodes.elementAt(j).getLayout().y) 01084 { 01085 tempNode = nodes.elementAt(i); 01086 nodes.setElementAt(nodes.elementAt(j), i); 01087 nodes.setElementAt(tempNode, j); 01088 } 01089 01090 /* Delete superpositions in the level */ 01091 for(Node node : nodes) 01092 { 01093 if (nodes.indexOf(node) != nodes.size()-1) 01094 deleteSuperpositionUp(nodes, node, nodes.elementAt(nodes.indexOf(node)+1)); 01095 01096 if (nodes.indexOf(node) != 0) 01097 deleteSuperpositionDown(nodes, node, nodes.elementAt(nodes.indexOf(node)-1)); 01098 } 01099 } 01100 01101 01108 private void deleteSuperpositionDown(Vector<Node> nodes, Node node, Node nextNode) 01109 { 01110 int dSuperposition; 01111 Node tempNode; 01112 01113 /* If the current node is the last node, all superositions are deleted */ 01114 if(nextNode == null) 01115 return; 01116 01117 // Get the distance of superposition 01118 dSuperposition = distanceSuperposedDown(node, nextNode); 01119 01120 /* Check if there is a superposition */ 01121 if(dSuperposition != 0) 01122 { 01123 // Delete the superposition 01124 nextNode.getLayout().y += dSuperposition; 01125 01126 /* Get the next node */ 01127 if(nodes.indexOf(nextNode) == 0) 01128 tempNode = null; 01129 else 01130 tempNode = nodes.elementAt(nodes.indexOf(nextNode)-1); 01131 01132 deleteSuperpositionDown(nodes, nextNode, tempNode); 01133 } 01134 } 01135 01136 01144 private boolean deleteSuperpositionUp(Vector<Node> nodes, Node node, Node nextNode) 01145 { 01146 int dSuperposition; 01147 Node tempNode; 01148 01149 /* If the current node is the last node, check the succes of deleted superpositions */ 01150 if(nextNode == null) 01151 return node.getLayout().y >= SPACE_INTERN_BLOC; 01152 01153 // Get the distance of superposition 01154 dSuperposition = distanceSuperposedUp(node, nextNode); 01155 01156 /* Check if there is a superposition */ 01157 if(dSuperposition != 0) 01158 { 01159 // Delete the superposition 01160 nextNode.getLayout().y -= dSuperposition; 01161 01162 /* Get the next node */ 01163 if(nodes.indexOf(nextNode) == nodes.size()-1) 01164 tempNode = null; 01165 else 01166 tempNode = nodes.elementAt(nodes.indexOf(nextNode)+1); 01167 01168 if(!deleteSuperpositionUp(nodes, nextNode, tempNode)) 01169 { 01170 // Set the original location 01171 nextNode.getLayout().y += dSuperposition; 01172 01173 return false; 01174 } 01175 } 01176 01177 return true; 01178 } 01179 01180 01187 private int distanceSuperposedUp(Node nodeTest, Node node) 01188 { 01189 Rectangle nodeLayout = node.getLayout(); 01190 Rectangle nodeLayoutTest = nodeTest.getLayout(); 01191 01192 if(nodeLayoutTest.y < nodeLayout.y+nodeLayout.height+SPACE_INTERN_BLOC) 01193 return nodeLayout.y + nodeLayout.height - nodeLayoutTest.y + SPACE_INTERN_BLOC; 01194 else 01195 return 0; 01196 } 01197 01198 01205 private int distanceSuperposedDown(Node nodeTest, Node node) 01206 { 01207 Rectangle nodeLayout = node.getLayout(); 01208 Rectangle nodeLayoutTest = nodeTest.getLayout(); 01209 01210 if(nodeLayoutTest.y+nodeLayoutTest.height > nodeLayout.y-SPACE_INTERN_BLOC) 01211 return nodeLayoutTest.y+nodeLayoutTest.height - nodeLayout.y+SPACE_INTERN_BLOC; 01212 else 01213 return 0; 01214 } 01215 01216 01222 private String getConditionString(Vector<Element> condition) 01223 { 01224 /* Construct a vector of strings containing all parts of the condition */ 01225 Vector<Vector<String>> conditionsNames = new Vector<Vector<String>>(); 01226 for(Element operation : condition) 01227 { 01228 Vector<String> names = new Vector<String>(); 01229 for(Element element : ((Operation)operation).getInput()) 01230 { 01231 if(!(((Variable)element).getType().equals("const"))) 01232 names.add(element.getName()); 01233 else 01234 names.add(String.valueOf(((SimpleVariable)element).getVal())); 01235 } 01236 01237 names.add(((Operation)operation).getOpSymbol()); 01238 names.add(((Operation)operation).getOutputAt(0).getName()); 01239 conditionsNames.add(names); 01240 } 01241 01242 /* Replace all temporary signal of the condition */ 01243 for(Vector<String> names1 : conditionsNames) 01244 { 01245 for(Vector<String> names2 : conditionsNames) 01246 { 01247 if(names2.lastElement().equalsIgnoreCase(names1.elementAt(0))) 01248 if(names2.size() != 3) 01249 names1.setElementAt(names2.elementAt(0) + " " + names2.elementAt(2) + " " +names2.elementAt(1), 0); 01250 else 01251 names1.setElementAt(names2.elementAt(1) + names2.elementAt(0), 0); 01252 01253 if(names1.size() != 3 && names2.lastElement().equalsIgnoreCase(names1.elementAt(1))) 01254 names1.setElementAt(names2.elementAt(0) + " " + names2.elementAt(2) + " " +names2.elementAt(1), 1); 01255 } 01256 } 01257 01258 /* Construct and return the finally string */ 01259 if(conditionsNames.lastElement().size() != 3) 01260 return conditionsNames.lastElement().elementAt(0) + " " + conditionsNames.lastElement().elementAt(2) + " " + conditionsNames.lastElement().elementAt(1); 01261 else 01262 return conditionsNames.lastElement().elementAt(1) + conditionsNames.lastElement().elementAt(0); 01263 01264 } 01265 01266 01273 private Node getGraphicalNodeInParent(Element element, Node parent) 01274 { 01275 for(Node node : parent.getChildrenArray()) 01276 if(element == node.getElement()) 01277 return node; 01278 01279 return null; 01280 } 01281 01282 01288 private Node getGraphicalNode(Element element) 01289 { 01290 /* Use to go through all nodes */ 01291 LinkedList<Node> nodeList = new LinkedList<Node>(); 01292 nodeList.addAll(schema.getChildrenArray()); 01293 Iterator<Node> iterNode = nodeList.iterator(); 01294 Node node; 01295 01296 while (iterNode.hasNext()) 01297 { 01298 node = iterNode.next(); 01299 01300 /* Return the node if elements are equals */ 01301 if(element == node.getElement()) 01302 return node; 01303 01304 if(node.getChildrenArray().size() != 0) 01305 nodeList.addAll(node.getChildrenArray()); 01306 01307 nodeList.remove(nodeList.indexOf(node)); 01308 iterNode = nodeList.iterator(); 01309 } 01310 01311 return null; 01312 } 01313 01314 01319 public Schema getSchema() 01320 { 01321 return schema; 01322 } 01323 01324 01329 public void setSchema(Schema schema) 01330 { 01331 this.schema = schema; 01332 } 01333 }