protected BranchContext DropNextShape(Node node, BranchContext thisBranchContext)
        {
            var newShapePos = GetNextShapePos(thisBranchContext, node);

            if (thisBranchContext.BranchOffset != default)
            {
                newShapePos.Offset(thisBranchContext.BranchOffset.X, thisBranchContext.BranchOffset.Y);
                thisBranchContext.ResetOffset();
            }

            var lastDroppedShape = VisioManipulator.DropShape(node, newShapePos);

            thisBranchContext.SetLastShape(lastDroppedShape);
            return(thisBranchContext);
        }
예제 #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);
        }