Beispiel #1
0
        /// <summary>
        /// Event handler called after a Document has been created.
        /// </summary>
        /// <param name="doc">The created Document.</param>
        private void app_DocumentCreated(Visio.Document doc)
        {
            // If the Document created is a drawing file, setup the initial set
            // of Pages. Create different Pages for each System (Object, ER, Flow).
            // Only done if this is a new Drawing file.
            if (doc.Type == Visio.VisDocumentTypes.visTypeDrawing)
            {
                Visio.Pages pages = doc.Pages;

                // Adds a different page for each remaining Subsystem.
                pages.Add().Name = CaseTypes.RELATION_PAGE;
                pages.Add().Name = CaseTypes.FLOW_PAGE;
                pages.Add().Name = CaseTypes.OBJECT_DIAGRAM_PAGE;
                pages.Add().Name = CaseTypes.DATA_MODEL_DIAGRAM_PAGE;
                pages.Add().Name = CaseTypes.ARCHITECTURE_PAGE;
                pages.Add().Name = CaseTypes.STATE_TABLE_PAGE;

                // By default, Visio opens with one page
                // Rename first page to be for the Object Editor
                // Pages Collection index starts at 1.
                Visio.Page firstPage = pages[1];
                firstPage.Name        = CaseTypes.OBJECT_PAGE;
                app.ActiveWindow.Page = firstPage.Name;

                // Opens the Object Stencil & have it docked to the Stencil Window
                app.Documents.OpenEx(CaseTypes.stencilPath() + CaseTypes.OBJECT_STENCIL,
                                     (short)Visio.VisOpenSaveArgs.visOpenDocked);

                // Event handlers that loads the appropriate stencil for a particular
                // page and unloads all other stencils when the Active Page changes.
                app.BeforeWindowPageTurn += app_BeforeWindowPageTurn;
                app.WindowTurnedToPage   += app_WindowTurnedToPage;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Event handler called after a different page is activated. Loads the
        /// appropriate stencil for this page.
        /// </summary>
        /// <param name="Window"></param>
        private void app_WindowTurnedToPage(Visio.Window Window)
        {
            string activePage  = app.ActivePage.Name;
            string stencilPath = CaseTypes.stencilPath();

            // Not all pages has an associated stencil
            bool stencilExists = true;

            switch (activePage)
            {
            case CaseTypes.OBJECT_PAGE:
                stencilPath += CaseTypes.OBJECT_STENCIL;
                break;

            case CaseTypes.RELATION_PAGE:
                stencilPath += CaseTypes.RELATION_STENCIL;

                HashSet <string> currentPageShapes = new HashSet <string>();
                foreach (Visio.Shape s in app.ActivePage.Shapes)
                {
                    currentPageShapes.Add(s.NameU);
                }

                foreach (Visio.Page p in Window.Document.Pages)
                {
                    if (p.Name == CaseTypes.OBJECT_PAGE)
                    {
                        foreach (var item in Utilities.getAllShapesOnPage(p))
                        {
                            if (!currentPageShapes.Contains(item.NameU))
                            {
                                item.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
                                app.ActivePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
                            }
                        }
                        break;
                    }
                }
                break;

            case CaseTypes.FLOW_PAGE:
                stencilPath += CaseTypes.FLOW_STENCIL;
                break;

            default:
                stencilExists = false;
                break;
            }

            if (stencilExists)
            {
                app.Documents.OpenEx(stencilPath,
                                     (short)Visio.VisOpenSaveArgs.visOpenDocked);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Retrieves a stencil document if it's open, else open it according to
        /// the openArgument.
        /// </summary>
        /// <param name="documents">Documents collection to look for Stencil.</param>
        /// <param name="stencilName">Name of the stencil.</param>
        /// <param name="openArg">How to open the stencil.</param>
        /// <returns></returns>
        public static Visio.Document getStencil(Visio.Documents documents, string stencilName,
                                                Visio.VisOpenSaveArgs openArg)
        {
            // if stencil is already open, return reference to it
            Visio.Document stencil = null;
            try
            {
                stencil = documents[stencilName];
            }
            catch
            {
                // Stencil isn't open, so open it
                string stencilPath = CaseTypes.stencilPath() + CaseTypes.OOSD_GENERAL_STENCIL;
                stencil = documents.OpenEx(stencilPath, (short)openArg);
            }

            return(stencil);
        }
Beispiel #4
0
 /// <summary>
 /// On click of Open Stencil button, open and display the Object Stencil
 /// in the stencil dock in Visio.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void openObjStencilBtn_Click(object sender, RibbonControlEventArgs e)
 {
     app.Documents.OpenEx(CaseTypes.stencilPath() + CaseTypes.OBJECT_STENCIL,
                          (short)Visio.VisOpenSaveArgs.visOpenDocked);
 }