public void ConnectShapes(ShapeWrapper shapeFrom, ShapeWrapper shapeTo, NodesBranchRelation nodesBranchRelation, ShapeConnectionType connectionType) { var connectorMaster = GetConnectionMasterFromConnectionType(connectionType, nodesBranchRelation); ConnectShapes(shapeFrom, shapeTo, connectorMaster, connectionType); }
protected Master GetConnectionMasterFromConnectionType(ShapeConnectionType connectionType, NodesBranchRelation nodesBranchRelation) { if (nodesBranchRelation == NodesBranchRelation.SAME_BRANCH || nodesBranchRelation == NodesBranchRelation.ELSE_BRANCH || nodesBranchRelation == NodesBranchRelation.IF_BRANCH) { return(Line); } else if (nodesBranchRelation == NodesBranchRelation.PARENT) { switch (connectionType) { case ShapeConnectionType.FROM_RIGHT_TO_LEFT: case ShapeConnectionType.FROM_BOT_TO_LEFT: case ShapeConnectionType.FROM_LEFT_TO_LEFT: return(Arrow); default: return(Line); } } switch (connectionType) { case ShapeConnectionType.FROM_TOP_TO_BOT: case ShapeConnectionType.FROM_TOP_TO_RIGHT: return(Line); case ShapeConnectionType.FROM_RIGHT_TO_LEFT: return(Arrow); default: return(Line); } }
public void ConnectShapes(ShapeWrapper shapeFrom, ShapeWrapper shapeTo, ConnectionMaserType connectionMaserType, ShapeConnectionType connectionType) { var connectorMaster = GetConnectionMasterFromConnectionMasterType(connectionMaserType); ConnectShapes(shapeFrom, shapeTo, connectorMaster, connectionType); }
/// <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); }
/// <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); }
public void ConnectShapes(ShapeWrapper shapeFrom, ShapeWrapper shapeTo, Master connectorMaster, ShapeConnectionType connectionType) { if (shapeFrom.ShapeForm != ShapeForm.INIT_SHAPE && shapeTo.ShapeForm != ShapeForm.INIT_SHAPE) { BuilderUtils.GetCellsAlignsFromConnectionType(out var connectionFromType, out var connectionToType, connectionType); ConnectWithDynamicGlueAndConnector(shapeFrom, shapeTo, connectorMaster, connectionFromType, connectionToType); } }
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); }
/// <summary> /// Define connection type between two shapes (none of the shapes is parent shape) /// </summary> /// <param name="firstShape">up shape</param> /// <param name="secShape">down shape</param> /// <returns>connection type</returns> public static ShapeConnectionType defineConnectionType(ShapeWrapper firstShape, ShapeWrapper secShape, bool isSameBranch) { bool firstShapeIsCommon = firstShape.isCommonShape(); bool secShapeIsCommon = secShape.isCommonShape(); ShapeConnectionType shapeConnectionType = ShapeConnectionType.FROM_TOP_TO_RIGHT; if (!firstShapeIsCommon && secShapeIsCommon) { if (isSameBranch) { shapeConnectionType = ShapeConnectionType.FROM_TOP_TO_BOT; } else { shapeConnectionType = ShapeConnectionType.FROM_TOP_TO_RIGHT; } } else if (firstShapeIsCommon && !secShapeIsCommon) { shapeConnectionType = ShapeConnectionType.FROM_TOP_TO_BOT; } else if (!firstShapeIsCommon && !secShapeIsCommon) { if (isSameBranch) { shapeConnectionType = ShapeConnectionType.FROM_TOP_TO_BOT; } else { shapeConnectionType = ShapeConnectionType.FROM_TOP_TO_RIGHT; } } else if (firstShapeIsCommon && secShapeIsCommon) { shapeConnectionType = ShapeConnectionType.FROM_TOP_TO_BOT; } return(shapeConnectionType); }
/// <summary> /// Define connection type between two shapes (first shape is parent shape) /// </summary> /// <param name="chainParentShape">parent shape</param> /// <param name="lastBranchShape">child shape</param> /// <returns>connection type</returns> public static ShapeConnectionType defineConnectionTypeWithBranchParent(ShapeWrapper chainParentShape, ShapeWrapper lastBranchShape) { bool lastBranchShapeIsCommon = lastBranchShape.isCommonShape(); ShapeConnectionType shapeConnectionType = ShapeConnectionType.FROM_TOP_TO_RIGHT; if (chainParentShape.shapeType == ShapeForm.FOR && lastBranchShapeIsCommon) { shapeConnectionType = ShapeConnectionType.FROM_BOT_TO_LEFT; } else if (chainParentShape.shapeType == ShapeForm.FOR && !lastBranchShapeIsCommon) { shapeConnectionType = ShapeConnectionType.FROM_RIGHT_TO_LEFT; } else if (chainParentShape.shapeType == ShapeForm.WHILE && lastBranchShapeIsCommon) { shapeConnectionType = ShapeConnectionType.FROM_BOT_TO_CENTER; } else if (chainParentShape.shapeType == ShapeForm.WHILE && !lastBranchShapeIsCommon) { shapeConnectionType = ShapeConnectionType.FROM_LEFT_TO_CENTER; } return(shapeConnectionType); }
/// <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); }
/// <summary> /// Out return cells align from given connection type /// </summary> /// <param name="connectionFromType">Out cell aligment for connection from shape</param> /// <param name="connectionToType">Out cell aligment for connection to shape</param> /// <param name="connectionType">type of shape connection</param> public static void GetCellsAlignsFromConnectionType(out VisCellIndices connectionFromType, out VisCellIndices connectionToType, ShapeConnectionType connectionType) { connectionToType = VisCellIndices.visAlignBottom; connectionFromType = VisCellIndices.visAlignTop; switch (connectionType) { case ShapeConnectionType.FROM_TOP_TO_BOT: connectionFromType = VisCellIndices.visAlignTop; connectionToType = VisCellIndices.visAlignBottom; break; case ShapeConnectionType.FROM_TOP_TO_RIGHT: connectionFromType = VisCellIndices.visAlignTop; connectionToType = VisCellIndices.visAlignRight; break; case ShapeConnectionType.FROM_RIGHT_TO_LEFT: connectionFromType = VisCellIndices.visAlignRight; connectionToType = VisCellIndices.visAlignLeft; break; case ShapeConnectionType.FROM_TOP_TO_LEFT: connectionFromType = VisCellIndices.visAlignTop; connectionToType = VisCellIndices.visAlignLeft; break; case ShapeConnectionType.FROM_LEFT_TO_LEFT: connectionFromType = VisCellIndices.visAlignLeft; connectionToType = VisCellIndices.visAlignLeft; break; case ShapeConnectionType.FROM_BOT_TO_LEFT: connectionFromType = VisCellIndices.visAlignBottom; connectionToType = VisCellIndices.visAlignLeft; break; default: connectionToType = VisCellIndices.visAlignBottom; connectionFromType = VisCellIndices.visAlignTop; break; } }
/// <summary> /// Connect two shapes /// </summary> /// <param name="shapeFrom">first shape to connect</param> /// <param name="shapeTo">sec shape to connect</param> /// <param name="connectorMaster">shape wich connect shapes</param> /// <param name="connectionType">shape connection type</param> public void connectShapes(Shape shapeFrom, Shape shapeTo, ShapeForm shapeForm, ShapeConnectionType connectionType, double x = 4.25, double y = 10) { Master connectorMaster = getShapeMasterByShapeType(shapeForm); VisCellIndices conectionToType = VisCellIndices.visAlignTop; VisCellIndices conectionFromType = VisCellIndices.visAlignBottom; BuilderUtills.getCellsAlignsFromConnectionType(out conectionToType, out conectionFromType, connectionType); ConnectWithDynamicGlueAndConnector(shapeFrom, shapeTo, connectorMaster, conectionToType, conectionFromType, x, y); }