public string BuildDiagram(List <Method> allMethods, bool closeAfterBuild, string diagramFilepath)
        {
            try
            {
                VisioManipulator.OpenDocument();
            }
            catch
            {
                VisioManipulator.AbortOpenDocument();
                throw;
            }

            var currentPos = new Point(StartX, StartY);

            foreach (var method in allMethods)
            {
                if (method.MethodType == MethodType.COMMON)
                {
                    VisioManipulator.DropTextField(method.MethodSignature, currentPos);
                    currentPos.Offset(0, -0.4);
                }

                var initShape   = VisioManipulator.DropSimpleShape("", new Point(currentPos.X, currentPos.Y - 0.25), ShapeForm.INIT_SHAPE);
                var treeContext = new BranchContext(null, initShape, initShape);
                foreach (var node in method.MethodNodes)
                {
                    treeContext = BuildTree(node, treeContext);
                    treeContext = new BranchContext(null, treeContext.LastBranchShape, treeContext.ShapeToContinueThree,
                                                    NodesBranchRelation.OTHER_BRANCH);
                }
                MoveCordsToNextMethod(currentPos);
            }

            string diagramFilename;

            if (closeAfterBuild)
            {
                diagramFilename = VisioManipulator.CloseDiagramDocument(diagramFilepath);
            }
            else
            {
                diagramFilename = VisioManipulator.SaveDiagramDocument(diagramFilepath);
            }

            return(diagramFilename);
        }
Esempio n. 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);
        }