Beispiel #1
0
        /// <summary>
        /// Recursively dump the tree of TypeTreeNode data to the console.
        /// </summary>
        /// <param name="root">Root of the tree to dump (recursive).</param>
        /// <param name="indent">Indent string - - gets extended each recursion.</param>
        private static void ConsoleOutTree(TypeTreeNode root, string indent)
        {
            if (root == null)
            {
                return;
            }

            Console.WriteLine(string.Format("{0}{1}", indent, root.ToString()));

            foreach (TypeTreeNode c in root.Children.Values.OrderBy(t => t.RawType.Namespace).ThenBy(t => t.RawType.Name))
            {
                ConsoleOutTree(c, indent + "  ");
            }
        }
Beispiel #2
0
        /// <summary>
        /// This is the root of the recursive descent to display the tree on the Visio doc.
        /// The function uses PlaceOneShape() to start the recursive display.
        /// </summary>
        /// <param name="colorMap">Color map to use to render.</param>
        /// <param name="root">Root node to render.</param>
        private static void BuildAndDisplayWithVisio(
            Dictionary <string, string> colorMap,
            TypeTreeNode root)
        {
            Visio.Application app             = null;
            Visio.Document    contentDocument = null;

            try
            {
                app = new Visio.Application();
                app.Settings.EnableAutoConnect = false;
                ////app.Window.WindowState = (int)Visio.VisWindowStates.visWSRestored;
                app.Window.WindowState = (int)Visio.VisWindowStates.visWSMinimized;

                contentDocument = app.Documents.AddEx(
                    string.Empty,
                    Visio.VisMeasurementSystem.visMSUS,
                    (int)Visio.VisOpenSaveArgs.visAddDocked,
                    (int)0);

                contentDocument.PaperSize      = Visio.VisPaperSizes.visPaperSizeE;
                contentDocument.PrintLandscape = true;

                /*
                 * Visio.Document stencilDocument = contentDocument.Application.Documents.OpenEx(
                 *  "Basic_U.vss",
                 *  (short)Visio.VisOpenSaveArgs.visOpenDocked);
                 * Visio.Master shape = stencilDocument.Masters["Rectangle"];
                 */

                Visio.Master shape = contentDocument.Application.Documents.OpenEx(
                    "Basic_U.vss",
                    (short)Visio.VisOpenSaveArgs.visOpenDocked).Masters["Rectangle"];

                Visio.Page targetPage = contentDocument.Pages[1];
                targetPage.Name = "MFx Class Hirearchy";

                BuildHeadersAndFooters(colorMap, contentDocument);

                /*
                 * Program.selectionTree = app.ActiveWindow.Selection;
                 * Program.selectionTree.DeselectAll();
                 */

                double movingYBase = 4.0;
                foreach (TypeTreeNode t in
                         root.Children.Values.OrderBy(t => t.RawType.Namespace).ThenBy(t => t.RawType.Name))
                {
                    movingYBase = PlaceOneShape(
                        colorMap,
                        targetPage,
                        t,
                        shape,
                        null,
                        2.0,
                        movingYBase);
                }

                // now turn the selection into a group, and run the layout code
                // to make the tree look "right"
                ////Program.selectionTree.Group();

                // resize, set the placement, and connector routing styles
                Visio.Cell layoutCell;

                layoutCell = targetPage.PageSheet.get_CellsSRC(
                    (short)Visio.VisSectionIndices.visSectionObject,
                    (short)Visio.VisRowIndices.visRowPageLayout,
                    (short)Visio.VisCellIndices.visPLOResizePage);

                layoutCell.FormulaU = "FALSE";  // don't add more pages to contain the tree, let the user edit

                layoutCell = targetPage.PageSheet.get_CellsSRC(
                    (short)Visio.VisSectionIndices.visSectionObject,
                    (short)Visio.VisRowIndices.visRowPageLayout,
                    (short)Visio.VisCellIndices.visPLOPlaceStyle);

                layoutCell.set_Result(
                    Visio.VisUnitCodes.visPageUnits,
                    (double)Visio.VisCellVals.visPLOPlaceCompactDownRight);

                layoutCell = targetPage.PageSheet.get_CellsSRC(
                    (short)Visio.VisSectionIndices.visSectionObject,
                    (short)Visio.VisRowIndices.visRowPageLayout,
                    (short)Visio.VisCellIndices.visPLORouteStyle);

                layoutCell.set_Result(
                    Visio.VisUnitCodes.visPageUnits,
                    (double)Visio.VisCellVals.visLORouteOrgChartNS);

                targetPage.Layout();
                ////Program.selectionTree.Layout();

                Program.selectionTree.Group();

                Console.WriteLine("Print and save Visio doc if you want, then enter to quit (Visio will close).");
                Console.ReadLine();
            }
            finally
            {
                if (contentDocument != null)
                {
                    contentDocument.Saved = true;   // not really, but we can lie so the close/quit works.
                    contentDocument.Close();
                }

                if (app != null)
                {
                    app.Quit();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// This function uses the node information to place a copy of the templateShape
        /// on the targetPage, in the right color, at the specified location.
        /// The new shape is linked to the parent.  The Children of the node are then
        /// (recursively) placed on the page, linked to this new node.
        /// </summary>
        /// <param name="colorMap">Namespace color map to used for rendering.</param>
        /// <param name="targetPage">Visio page to place the objects.</param>
        /// <param name="node">Node object to place.</param>
        /// <param name="templateShape">Which shape to use to display.</param>
        /// <param name="parentShape">Parent visio node to attach child to.</param>
        /// <param name="baseLocationX">XLocation to start displaying subtree.</param>
        /// <param name="baseLocationY">YLocation to start displaying subtree.</param>
        /// <returns>Returns the next available Y coordinate to display an object.</returns>
        private static double PlaceOneShape(
            Dictionary <string, string> colorMap,
            Visio.Page targetPage,
            TypeTreeNode node,
            Visio.Master templateShape,
            Visio.Shape parentShape,
            double baseLocationX,
            double baseLocationY)
        {
            double movingYBase = baseLocationY;

            Visio.Shape newlyPlacedShape = targetPage.Drop(templateShape, baseLocationX, baseLocationY);

            // add the new object to the selection group for later "group" operation
            Program.selectionTree.Select(newlyPlacedShape, (short)Visio.VisSelectArgs.visSelect);

            if (parentShape != null)
            {
                Visio.Document stencilDocument = targetPage.Application.Documents.OpenEx(
                    "Blocks.vss",
                    (short)Visio.VisOpenSaveArgs.visOpenDocked);
                Visio.Master connectorMaster = stencilDocument.Masters["Dynamic connector"];
                Visio.Shape  connectorShape  = targetPage.Drop(connectorMaster, 1.0, 1.0);
                Program.selectionTree.Select(connectorShape, (short)Visio.VisSelectArgs.visSelect);
                ConnectShapes(parentShape, newlyPlacedShape, connectorShape);
            }

            // set the templateShape height, width, text, and color
            newlyPlacedShape.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXFormIn,
                (short)Visio.VisCellIndices.visXFormHeight).ResultIU = Program.BoxY;

            newlyPlacedShape.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXFormIn,
                (short)Visio.VisCellIndices.visXFormWidth).ResultIU = Program.BoxX;

            string shortNamespace = String.Empty;

            if (!String.IsNullOrEmpty(node.RawType.Namespace))
            {
                string[] namespaceTokens = node.RawType.Namespace.Split(new char[] { '.' });
                shortNamespace = namespaceTokens[namespaceTokens.Length - 1];
            }

            newlyPlacedShape.Text = string.Format("{0} ({1})", node.Name, shortNamespace);

            // if there is an entry in the color map, use it.
            if (!String.IsNullOrEmpty(node.RawType.Namespace) && colorMap.ContainsKey(node.RawType.Namespace))
            {
                newlyPlacedShape.get_CellsSRC(
                    (short)Visio.VisSectionIndices.visSectionObject,
                    (short)Visio.VisRowIndices.visRowFill,
                    (short)Visio.VisCellIndices.visFillForegnd).FormulaU =
                    colorMap[node.RawType.Namespace];
            }

            movingYBase += Program.BoxPitchY;

            foreach (TypeTreeNode t in node.Children.Values.OrderBy(t => t.RawType.Namespace).ThenBy(t => t.RawType.Name))
            {
                movingYBase = PlaceOneShape(
                    colorMap,
                    targetPage,
                    t,
                    templateShape,
                    newlyPlacedShape,
                    baseLocationX + Program.BoxPitchX,              // x adds Depth
                    movingYBase);
            }

            return(movingYBase);
        }