/// <summary> /// Place last method shape (end) /// </summary> private void placeEndShape(List <Node> mainBranch) { ShapeWrapper endShape = visioManipulator.dropShape(ShapeForm.BEGIN, "Конец", coreX, coreY); ShapeConnectionType shapeConnection = BuilderUtills.defineConnectionType(globalLastDropedShape, endShape, globalIsSameBranch); visioManipulator.connectShapes(globalLastDropedShape.shape, endShape.shape, ShapeForm.LINE, shapeConnection, coreX, coreY); }
private ShapeWrapper buildDoWhileBranch(Node node, ShapeWrapper chainParentShape, double x, double y) { Node currentNode = null; ShapeWrapper lastBranchShape = null; for (int i = 0; i < node.childNodes.Count; i++) { currentNode = node.childNodes[i]; if (i == node.childNodes.Count - 1) { y -= 0.2; visioManipulator.addSmallTextField("Да", x - 0.7, y + 0.2); visioManipulator.addSmallTextField("Нет", x + 0.7, y + 0.2); //drop last do while shape (while) lastBranchShape = visioManipulator.dropShape(currentNode, x, y); // connect last shape with perv shape ShapeConnectionType shapeConnectionType = BuilderUtills.defineConnectionType(globalLastDropedShape, lastBranchShape, globalIsSameBranch); visioManipulator.connectShapes(globalLastDropedShape.shape, lastBranchShape.shape, ShapeForm.LINE, shapeConnectionType, coreX, coreY); // connsect last shape with do-while branch parent visioManipulator.connectShapes(chainParentShape.shape, lastBranchShape.shape, ShapeForm.ARROW_LEFT, ShapeConnectionType.FROM_LEFT_TO_CENTER, coreX, coreY); continueNodeBranch(lastBranchShape); } else { if (currentNode.isSimpleNode()) { lastBranchShape = buildTree(currentNode, x, y); continueNodeBranch(lastBranchShape); } else { lastBranchShape = buildTree(currentNode, x, y); shiftNodeBranch(lastBranchShape); y -= BuilderUtills.calcStatementHeight(currentNode); y -= 0.5; } } y--; } refrashCoreY(y); return(lastBranchShape); }
/// <summary> /// Recursive method connect place new shapes from node and connect them if node have childe nodes - build them /// </summary> /// <param name="node">node to create shape</param> /// <param name="x">new shape x</param> /// <param name="y">new shape y</param> /// <returns>last places shape in nodes AST branch</returns> private ShapeWrapper buildTree(Node node, double x, double y) { //because first shape in 'do-while' is little invisible block if (node.shapeForm == ShapeForm.DO) { y += 0.4; } ShapeWrapper currentNodeShape = visioManipulator.dropShape(node, x, y); y--; if (globalLastDropedShape != null) { ShapeConnectionType shapeConnectionType = BuilderUtills.defineConnectionType(globalLastDropedShape, currentNodeShape, globalIsSameBranch); visioManipulator.connectShapes(globalLastDropedShape.shape, currentNodeShape.shape, ShapeForm.LINE, shapeConnectionType, coreX, coreY); } ShapeWrapper lastBranchShape = currentNodeShape; if (node.shapeForm == ShapeForm.IF) { lastBranchShape = startIfElseBranch(node, currentNodeShape, x, y); coreY -= 0.2; } else if (node.shapeForm == ShapeForm.WHILE) { y -= 0.2; lastBranchShape = currentNodeShape; continueNodeBranch(lastBranchShape); startWhileBranch(node, currentNodeShape, x, y); coreY -= 0.2; } else if (node.shapeForm == ShapeForm.FOR) { lastBranchShape = currentNodeShape; continueNodeBranch(lastBranchShape); buildTreeBranch(node, currentNodeShape, x, y); coreY -= 0.2; } else if (node.shapeForm == ShapeForm.DO) { y += 0.2; lastBranchShape = buildDoWhileBranch(node, currentNodeShape, x, y); coreY -= 0.2; } refrashCoreY(y); endNodeBranch(); return(lastBranchShape); }