/// <summary> /// Place "yes" and "no" text fields before build node AST branch started with "if" /// </summary> /// <param name="node">"if" node</param> /// <param name="currentNodeShape">placed "if" shape</param> /// <param name="x">new branch x</param> /// <param name="y">new branch y</param> /// <returns>last shape in branch (in this case - invisible block connecting if and else branches)</returns> private ShapeWrapper startIfElseBranch(Node node, ShapeWrapper currentNodeShape, double x, double y) { visioManipulator.addSmallTextField("Да", x - 0.7, y + 1.2); visioManipulator.addSmallTextField("Нет", x + 0.7, y + 1.2); ShapeWrapper lastBranchShape = buildIfElseTreeBranch(node.childIfNodes, currentNodeShape, ShapeConnectionType.FROM_LEFT_TO_TOP, x - 1.2, y); double statementHeight = BuilderUtills.calcStatementHeight(node); ShapeWrapper invisibleBlock = visioManipulator.dropShape(ShapeForm.INVISIBLE_BLOCK, "", x, y - statementHeight); visioManipulator.connectLastShapeToInvisibleBlock(invisibleBlock, lastBranchShape, coreX, coreY); if (node.childElseNodes.Count != 0) { //actions in if branch changes coreY (y - y of first if and else branches operators) coreY = y; lastBranchShape = buildIfElseTreeBranch(node.childElseNodes, currentNodeShape, ShapeConnectionType.FROM_RIGHT_TO_TOP, x + 1.2, y); visioManipulator.connectLastShapeToInvisibleBlock(invisibleBlock, lastBranchShape, coreX, coreY); } else { visioManipulator.connectShapes(invisibleBlock.shape, currentNodeShape.shape, ShapeForm.LINE, ShapeConnectionType.FROM_RIGHT_TO_CENTER, coreX, coreY); } coreY = y - statementHeight - 0.5; return(invisibleBlock); }
/// <summary> /// Iterate node chiled nodes to build new branch or place branch shape /// </summary> /// <param name="node">node to build</param> /// <param name="chainParentShape">branch parent shape (to connect branch last shape to it)</param> /// <param name="x">branch x</param> /// <param name="y">branch y</param> /// <returns>last branch shape</returns> private ShapeWrapper buildTreeBranch(Node node, ShapeWrapper chainParentShape, double x, double y) { ShapeWrapper lastBranchShape = null; if (node.childNodes.Count == 0) { lastBranchShape = buildTree(node, x, y); continueNodeBranch(lastBranchShape); y--; } foreach (Node currentNode in node.childNodes) { 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--; } // if parent shape exists - connect last branch shape to it if (chainParentShape != null) { ShapeConnectionType shapeConnectionType = BuilderUtills.defineConnectionTypeWithBranchParent(chainParentShape, lastBranchShape); visioManipulator.connectShapes(chainParentShape.shape, lastBranchShape.shape, ShapeForm.ARROW_LEFT, shapeConnectionType, coreX, coreY); } refrashCoreY(y); return(lastBranchShape); }
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> /// Iterate node chiled nodes (in case if statement) to build new branch or place branch shape /// </summary> /// <param name="chainParentShape">branch parent shape (to connect branch last shape to it)</param> /// <param name="ifElseConnectionType">connection type for first if or else branch shape</param> /// <param name="x">branch x</param> /// <param name="y">branch y</param> /// <returns>last branch shape</returns> private ShapeWrapper buildIfElseTreeBranch(List <Node> nodes, ShapeWrapper chainParentShape, ShapeConnectionType ifElseConnectionType, double x, double y) { Node currentNode = null; ShapeWrapper lastBranchShape = null; for (int i = 0; i < nodes.Count; i++) { currentNode = nodes[i]; if (i == 0) { if (currentNode.shapeForm == ShapeForm.IF) { if (ifElseConnectionType == ShapeConnectionType.FROM_LEFT_TO_TOP) { x -= 1.2; } else { x += 1.2; startX = x; } lastBranchShape = visioManipulator.dropShape(currentNode, x, y); visioManipulator.connectShapes(lastBranchShape.shape, chainParentShape.shape, ShapeForm.LINE, ifElseConnectionType, coreX, coreY); y--; lastBranchShape = startIfElseBranch(currentNode, lastBranchShape, x, y); } else if (currentNode.shapeForm == ShapeForm.DO) { //place invisible block to connect 'if' and first block of branch lastBranchShape = visioManipulator.dropShape(ShapeForm.INVISIBLE_BLOCK, "", x, y); visioManipulator.connectShapes(lastBranchShape.shape, chainParentShape.shape, ShapeForm.LINE, ifElseConnectionType, coreX, coreY); //IMPORTANT change global shape bacause current shape already connected manualy continueNodeBranch(lastBranchShape); lastBranchShape = buildTree(currentNode, x, y); } else { //IMPORTANT reset global shape baccause current shape already connected manualy endNodeBranch(); lastBranchShape = buildTree(currentNode, x, y); visioManipulator.connectShapes(lastBranchShape.shape, chainParentShape.shape, ShapeForm.LINE, ifElseConnectionType, coreX, coreY); } if (lastBranchShape.isCommonShape()) { //IMPORTANT call for connect next shape with FROM_TOP_TO_BOT continueNodeBranch(lastBranchShape); } else { //IMPORTANT call because lastBranchShape isn't common shape so it can not be connected FROM_TOP_TO_BOT shiftNodeBranch(lastBranchShape); } coreY -= 0.2; } else if (currentNode.isSimpleNode()) { if (lastBranchShape.isCommonShape()) { //IMPOTRANT connect shape in one branch if last shape is common continueNodeBranch(lastBranchShape); } lastBranchShape = buildTree(currentNode, x, y); continueNodeBranch(lastBranchShape); } else { lastBranchShape = buildTree(currentNode, x, y); shiftNodeBranch(lastBranchShape); y -= BuilderUtills.calcStatementHeight(currentNode); } y--; refrashCoreY(y); } return(lastBranchShape); }