コード例 #1
0
        public BranchContext BuildIf(Node nextShapeNode, BranchContext thisBranchContext)
        {
            var newBranchContext = BuildSimpleNode(nextShapeNode, thisBranchContext);
            var ifShape          = newBranchContext.LastBranchShape;
            var ifShapePos       = newBranchContext.BranchPos;
            var yesTextPoint     = new Point(ifShapePos.X - 0.7, ifShapePos.Y + 0.2);
            var noTextPoint      = new Point(ifShapePos.X + 0.7, ifShapePos.Y + 0.2);

            VisioManipulator.DropSmallTextField("Да", yesTextPoint);
            VisioManipulator.DropSmallTextField("Нет", noTextPoint);

            var branchHeight      = BuilderUtils.CalcThreeHeight(nextShapeNode);
            var invisibleBlockPos = new Point(ifShapePos.X, ifShapePos.Y - branchHeight);
            var invisibleBlock    = VisioManipulator.DropInvisibleShape(invisibleBlockPos);

            var ifBranchContainsIf = IsBranchContainsIf(nextShapeNode.PrimaryChildNodes);
            var ifBranchOffset     = new Point(-1.2, 0);

            if (ifBranchContainsIf)
            {
                ifBranchOffset.Offset(-1.5, 0);
            }

            var ifBranchContext = new BranchContext(null, ifShape, ifShape,
                                                    NodesBranchRelation.IF_BRANCH, ifBranchOffset);

            ifBranchContext = BuildSubTreeNodes(nextShapeNode.PrimaryChildNodes, ifBranchContext);
            VisioManipulator.ConnectShapes(invisibleBlock, ifBranchContext.ShapeToContinueThree);

            var elseBranchContainsIf = IsBranchContainsIf(nextShapeNode.SecondaryChildNodes);
            var elseBranchOffset     = new Point(1.2, 0);

            if (elseBranchContainsIf)
            {
                elseBranchOffset.Offset(1.5, 0);
            }

            var elseBranchContext = new BranchContext(null, ifShape, ifShape,
                                                      NodesBranchRelation.ELSE_BRANCH, elseBranchOffset);

            elseBranchContext = BuildSubTreeNodes(nextShapeNode.SecondaryChildNodes, elseBranchContext);
            VisioManipulator.ConnectShapes(invisibleBlock, elseBranchContext.ShapeToContinueThree);

            newBranchContext = new BranchContext(thisBranchContext.BranchParent, invisibleBlock, invisibleBlock);
            ConnectToParent(thisBranchContext);
            return(newBranchContext);
        }
コード例 #2
0
        private BranchContext BuildTree(Node node, BranchContext thisBranchContext)
        {
            var prevShape        = thisBranchContext.ShapeToContinueThree;
            var newShapePos      = MoveToNextShapePos(thisBranchContext.LastBranchShape, node, thisBranchContext.BranchPos);
            var lastDroppedShape = VisioManipulator.DropShape(node, newShapePos);
            var newBranchContext = new BranchContext(lastDroppedShape, lastDroppedShape, lastDroppedShape);

            VisioManipulator.ConnectShapes(lastDroppedShape, prevShape, thisBranchContext.BranchRelation);
            if (!node.IsSimpleNode)
            {
                var nodeType = node.NodeType;
                if (nodeType == NodeType.DO_WHILE)
                {
                    var branchHeight = BuilderUtils.CalcThreeHeight(node);
                    var yesTextPoint = new Point(newShapePos.X - 0.7, newShapePos.Y - branchHeight + 0.2);
                    var noTextPoint  = new Point(newShapePos.X + 0.3, newShapePos.Y - branchHeight - 0.4);
                    VisioManipulator.DropSmallTextField("Да", yesTextPoint);
                    VisioManipulator.DropSmallTextField("Нет", noTextPoint);
                    newBranchContext = BuildSubTree(node.ChildNodes, newBranchContext);
                    newShapePos      = MoveToNextShapePos(newBranchContext.LastBranchShape);
                    var lastDoWhileShape = VisioManipulator.DropSimpleShape(node.NodeText, newShapePos, ShapeForm.DO_WHILE);
                    VisioManipulator.ConnectShapes(lastDoWhileShape, newBranchContext.ShapeToContinueThree);
                    newBranchContext = new BranchContext(lastDroppedShape, lastDoWhileShape, lastDoWhileShape);
                }
                else if (nodeType == NodeType.WHILE)
                {
                    var yesTextPoint = new Point(newShapePos.X + 0.28, newShapePos.Y - 0.7);
                    var noTextPoint  = new Point(newShapePos.X + 0.7, newShapePos.Y + 0.2);
                    VisioManipulator.DropSmallTextField("Да", yesTextPoint);
                    VisioManipulator.DropSmallTextField("Нет", noTextPoint);
                    var invisibleShapePos = new Point(newShapePos.X, newShapePos.Y + 0.5);
                    var invisibleBlock    = VisioManipulator.DropInvisibleShape(invisibleShapePos);
                    newBranchContext.BranchParent   = invisibleBlock;
                    newBranchContext.BranchRelation = NodesBranchRelation.SAME_BRANCH;
                    var tmpContext = BuildSubTree(node.ChildNodes, newBranchContext);
                    newBranchContext.LastBranchShape = tmpContext.LastBranchShape;
                }
                else if (nodeType == NodeType.IF || nodeType == NodeType.ELSE_IF)
                {
                    var yesTextPoint = new Point(newShapePos.X - 0.7, newShapePos.Y + 0.2);
                    var noTextPoint  = new Point(newShapePos.X + 0.7, newShapePos.Y + 0.2);
                    VisioManipulator.DropSmallTextField("Да", yesTextPoint);
                    VisioManipulator.DropSmallTextField("Нет", noTextPoint);

                    var branchHeight      = BuilderUtils.CalcThreeHeight(node);
                    var invisibleBlockPos = new Point(newShapePos.X, newShapePos.Y - branchHeight);
                    var invisibleBlock    = VisioManipulator.DropInvisibleShape(invisibleBlockPos);

                    var ifBranchContainsIf = IsBranchContainsIf(node.ChildNodes);
                    var ifBranchPos        = new Point(newShapePos.X - 1.2, newShapePos.Y);
                    if (ifBranchContainsIf)
                    {
                        ifBranchPos.Offset(-1.5, 0);
                    }
                    var tmpContext = newBranchContext;
                    tmpContext.BranchRelation = NodesBranchRelation.IF_BRANCH;
                    tmpContext.BranchPos      = ifBranchPos;
                    tmpContext = BuildSubTree(node.ChildNodes, tmpContext);
                    VisioManipulator.ConnectShapes(invisibleBlock, tmpContext.ShapeToContinueThree);

                    newBranchContext.BranchParent = null;
                    var elseBranchContainsIf = IsBranchContainsIf(node.ChildElseNodes);
                    var elseBranchPos        = new Point(newShapePos.X + 1.2, newShapePos.Y);
                    if (elseBranchContainsIf)
                    {
                        elseBranchPos.Offset(1.5, 0);
                    }
                    tmpContext                = newBranchContext;
                    tmpContext.BranchPos      = elseBranchPos;
                    tmpContext.BranchRelation = NodesBranchRelation.ELSE_BRANCH;
                    tmpContext                = BuildSubTree(node.ChildElseNodes, tmpContext);
                    VisioManipulator.ConnectShapes(invisibleBlock, tmpContext.ShapeToContinueThree);

                    newBranchContext = new BranchContext(thisBranchContext.BranchParent, invisibleBlock, invisibleBlock);
                }
                else
                {
                    var tmpContext = BuildSubTree(node.ChildNodes, newBranchContext);
                    newBranchContext.LastBranchShape = tmpContext.LastBranchShape;
                }

                if (newBranchContext.BranchParent != null)
                {
                    VisioManipulator.ConnectShapes(newBranchContext.LastBranchShape, newBranchContext.BranchParent, NodesBranchRelation.PARENT);
                }
            }
            return(newBranchContext);
        }