diff --git a/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java b/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java index ee95620..596d133 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java @@ -77,62 +77,56 @@ String node = stream.next(); while (node.equals(GEOMETRY_NODE)) { + // Node type String nodeType = stream.next(); if (!Objects.equals(nodeType, RESOURCE_NODE) && !Objects.equals(nodeType, FORMULA_CHANNEL_NODE) && !Objects.equals(nodeType, CHANNEL_NODE) && !Objects.equals(nodeType, IO_CHANNEL_NODE)) { throw new ExpectedNode(stream.getLine()); } - String name = stream.next(); - if (!Objects.equals(stream.next(), COLON)) { - throw new ExpectedAssignment(stream.getLine()); + // Resource path or Channel name + StringBuilder nodeIdentifier = new StringBuilder(); + String param; + while ((param = stream.next()) != null) { + if (Objects.equals(param, COLON)) { // Separator + break; + } + nodeIdentifier.append(param); } - // get x position +// // Separator +// if (!Objects.equals(stream.next(), COLON)) { +// throw new ExpectedAssignment(stream.getLine()); +// } + + // Get x position int x = Integer.parseInt(stream.next()); + // Separator if (!Objects.equals(stream.next(), COMMA)) { throw new ExpectedAssignment(stream.getLine()); } - // get y position + // Get y position int y = Integer.parseInt(stream.next()); + // Separator if (!Objects.equals(stream.next(), COMMA)) { throw new ExpectedAssignment(stream.getLine()); } - // get width + // Get width int width = Integer.parseInt(stream.next()); + // Separator if (!Objects.equals(stream.next(), COMMA)) { throw new ExpectedAssignment(stream.getLine()); } - // get height + // Get height int height = Integer.parseInt(stream.next()); // Find the current target cell and update its geometry - Object root = graph.getDefaultParent(); - mxIGraphModel graphModel = graph.getModel(); - for (int i = 0; i < graph.getModel().getChildCount(root); i++) { - Object cell = graph.getModel().getChildAt(root, i); - if (!graph.getModel().isVertex(cell)) { - continue; - } - mxGeometry geometry = (mxGeometry) ((mxCell) cell).getGeometry().clone(); - mxGraphView view = graph.getView(); - mxCellState state = view.getState(cell); - - if (!name.equals(state.getLabel())) { - continue; - } - - geometry.setX(x); - geometry.setY(y); - geometry.setWidth(width); - geometry.setHeight(height); - graphModel.setGeometry(cell, geometry); - } + buildGeometry(graph, (mxCell) graph.getDefaultParent(), nodeIdentifier, x, y, width, height); node = stream.next(); } @@ -141,4 +135,39 @@ throw new ExpectedRightBracket(stream.getLine()); } } + + private void buildGeometry(mxGraph graph, mxCell parent, StringBuilder nodeIdentifier, int x, int y, int width, int height) { + mxIGraphModel graphModel = graph.getModel(); + for (int i = 0; i < graphModel.getChildCount(parent); i++) { + mxCell cell = (mxCell) graphModel.getChildAt(parent, i); + if (!graphModel.isVertex(cell)) { + continue; + } + mxGeometry geometry = (mxGeometry) cell.getGeometry().clone(); + mxGraphView view = graph.getView(); + mxCellState state = view.getState(cell); + + StringBuilder identifier = new StringBuilder(state.getLabel()); + + if (nodeIdentifier.compareTo(identifier) == 0) { + System.out.println(nodeIdentifier + " : " + x + " " + y + " " + width + " " + height); + if (parent.getGeometry() != null) { // parent is root node + int diffX = x - (int) parent.getGeometry().getX(); + int diffY = y - (int) parent.getGeometry().getY(); + geometry.setX(diffX); + geometry.setY(diffY); + } else { + geometry.setX(x); + geometry.setY(y); + } + geometry.setWidth(width); + geometry.setHeight(height); + graphModel.setGeometry(cell, geometry); + break; + } + + // Recursive + buildGeometry(graph, cell, nodeIdentifier, x, y, width, height); + } + } }