public void RebuildTree(IVDocument d) //Completely rebuild the model
        {
            Log.Debug("entered rebuild tree");
            try
            {
                Log.Debug("State before reset: ViewChildren: " + View.Children.Count + ", Model.Alternatives:" + Model.Alternatives.Count + ", Model.Documents:" + Model.Documents.Count + ", Model.Forces:" + Model.Forces.Count + ", Model.Stakeholders:" + Model.Stakeholders.Count);
                View.Children.Clear();
                Model.Alternatives.Clear();
                Model.Documents.Clear();
                Model.Forces.Clear();
                Model.Stakeholders.Clear();
                Model.PlanningItems.Clear();

                foreach (Page page in d.Pages)
                {
                    foreach (Shape shape in page.Shapes)
                    {
                        View.AddToTree(shape, false);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex);
#if DEBUG
                throw;
#endif
            }
        }
예제 #2
0
        /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         * ~
         * ~ Private methods
         * ~
         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

        /// <summary>
        /// Validate all of the pages in the designated document.
        /// </summary>
        /// <param name="document">Visio document.</param>
        private ModelCommandResult ValidateAll(IVDocument document)
        {
            #region Validations

            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            #endregion

            ModelCommandResult result = new ModelCommandResult();

            int pageCount = document.Pages.Count;

            for (int i = 1; i <= pageCount; i++)
            {
                Page          page = document.Pages[i];
                PageEventArgs ev   = new PageEventArgs(i, pageCount, page.Name);

                OnPageStart(ev);

                ModelCommandPageResult pageResult = Work(page, true);
                result.Add(pageResult);

                OnPageEnd(ev);
            }

            return(result);
        }
예제 #3
0
 /// <summary>
 /// extra glueing settings are necessary for the shapes
 /// </summary>
 /// <param name="doc"></param>
 protected override void VisioApplication_DocumentCreatedOrLoadedEvent(IVDocument doc)
 {
     //set glue to geometry to true, to allow connectors to connect the instance shapes
     if (!doc.GlueSettings.HasFlag(NetOffice.VisioApi.Enums.VisGlueSettings.visGlueToGeometry))
     {
         doc.GlueSettings = doc.GlueSettings | NetOffice.VisioApi.Enums.VisGlueSettings.visGlueToGeometry;
     }
 }
 public static void Execute(IVDocument document)
 {
     Log.Debug($"Document {document.Name} based on {document.Template} created. ");
     if (document.Template.Contains(Information.TemplateName))
     {
         Log.Debug($"Initialize with an empty model and show setup wizard.");
         Globals.RationallyAddIn.Model     = new RationallyModel();
         Globals.RationallyAddIn.View.Page = Globals.RationallyAddIn.Application.ActivePage;
         ShowSetupWizard();
     }
 }
예제 #5
0
        public void EntitytoPage()
        {
            List <IVShape> shapes = new List <IVShape>();

            foreach (IVShape shape in this._application.ActivePage.Shapes)
            {
                if (shape.Name.Contains("Context Entity (CE)"))
                {
                    bool exists = false;
                    foreach (var s in shapes)
                    {
                        if (s.Text == shape.Text)
                        {
                            exists = true; System.Windows.Forms.MessageBox.Show(shape.Text +
                                                                                " already exists.");
                        }
                    }
                    if (exists == false)
                    {
                        shapes.Add(shape);
                    }
                }
            }
            if (shapes.Count >= 1)
            {
                foreach (var shape in shapes)
                {
                    IVPage page = this._application.ActiveDocument.Pages.Add();
                    page.Name = shape.Text;
                    IVDocument stencil      = this._application.Documents.OpenEx("SMT_BeC.vssx", 4);
                    IVMaster   masterentity = new IVMaster();
                    foreach (var m in stencil.Masters)
                    {
                        if (m.Name == "Context Entity/ Function")
                        {
                            masterentity = m;
                        }
                    }
                    IVShape shapeh = page.Drop(masterentity, 10.3 / 2.54, 20.5 / 2.54);
                    shapeh.Text = shape.Text;
                    shapeh.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
                    IVHyperlink hl = shape.Hyperlinks.Add();
                    hl.SubAddress = page.Name;
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("No Context Entity found.");
            };
        }
예제 #6
0
        private void CreateLvp(string system, IVDocument doc)
        {
            foreach (Page page in doc.Pages)
            {
                page.Name = "LVP_" + system;

                IVShape header;
                IVShape boundary = page.DrawRectangle(0, 12, 9, 1); boundary.CellsSRC(1, 3, 1).FormulaU = "THEMEGUARD(RGB(0,0,0))";

                header = page.DrawRectangle(1, 1, 8, 1.5); header.Text = "Logical Viewpoint: " + system; header.SetCenter(4, (28 / 2.54));
                header.CellsSRC(1, 11, 4).Formula = "0"; header.LineStyle = "none"; header.CellsSRC(3, 0, 7).FormulaU = "24 pt";
                header.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            }
        }
        private static void DelegateCreateDocumentEvent(IVDocument d)
        {
            if (d.Template.Contains(Information.TemplateName))
            {
                try
                {
                    Log.Debug("rationally template detected");
                    DocumentCreatedEventHandler.Execute(d);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, ex);
#if DEBUG
                    throw;
#endif
                }
            }
        }
        private void Application_DocumentOpenendEvent(IVDocument d)
        {
            Log.Debug($"DocumentOpenEvent for Document  {d.Name} detected.");
            if (Application.ActiveDocument.Template.Contains(Information.TemplateName) && showRationallyUpdatePopup)
            {
                Log.Debug("Rationally template and update required detected.");
                try
                {
                    UpdateAvailable upd = new UpdateAvailable(AddInLocalVersion, addInOnlineVersion);
                    upd.Show();
                    showRationallyUpdatePopup = false;
                    Log.Debug("Shown update popup successfully.");
                }
                catch (Exception ex)
                {
                    Log.Error(ex, ex);
#if DEBUG
                    throw;
#endif
                }
            }
        }
예제 #9
0
        private async void Application_DocumentLoadedOrCreated(IVDocument pDoc)
        {
            await startupTask;

            if (!initialized)
            {
                //set ribbon behaviour
                if (IsSPESproject)
                {
                    //set document referencer
                    documentReferencer = new SPES_DocumentReferencer();
                    documentReferencer.LoadConfigFromFile(documentReferencerFile);

                    //set SPES specifics
                    this.ModelTargetDropDown.Enabled  = false;
                    this.CreateNewSPESProject.Visible = false;

                    //load module based on definition
                    var type = documentReferencer.GetTypeFromFile(application.ActiveDocument.Name);
                    if (type != null)
                    {
                        ModelTargetDropDown.SelectedItem = ModelTargetDropDown.Items.First(k => k.Label == modelverifiers.First(t => t.ToString() == type.ToString()).ModelName);
                    }
                    else
                    {
                        ModelTargetDropDown.SelectedItem = ModelTargetDropDown.Items.Where(t => t.Label == "none").First();
                    }
                }
                else
                {
                    //set normal behaviour
                    this.ModelTargetDropDown.Enabled  = true;
                    this.CreateNewSPESProject.Visible = true;
                }

                ModelTargetDropDown_SelectionChanged(null, null);
                initialized = true;
            }
        }
예제 #10
0
        public void CreateSubsystems(SPES_DocumentReferencer pReferencer)
        {
            //bestimme Namen des übergeordneten Systems anhand des Seitennamens

            IVPage active     = this._application.ActivePage;
            string systemname = active.Name.Substring(4);

            //TODO: check if file is LVP_Overview datei (Logical Viewpoint) / Logical Design
            if (this._application.ActiveDocument.Name != $"{systemname}_LVP.vsdx")
            {
                throw new Exception("Active Document is not the LVP overview file.");
            }

            IVSelection    selects = this._application.ActiveWindow.Selection;
            List <IVShape> shapes  = new List <IVShape>();

            foreach (var shape in selects.SelectionForDragCopy)
            {
                if (shape.Shapes != null)
                {
                    bool firstshape = true;
                    int  count      = 0;
                    foreach (var subshape in shape.Shapes)
                    {
                        count++;
                        if (count % 2 == 1)
                        {
                            if (firstshape == true)
                            {
                                shapes.Add(subshape);
                            }
                            firstshape = false;
                        }
                    }
                }
                else
                {
                    shapes.Add(shape);
                }
            }
            //System.Windows.Forms.MessageBox.Show("Create Documents?");
            //getPage "Systemübersicht"--> dazu Document holen mit passender Page
            //speichere aktuelle Applikation ab und suche Applikation mit der Page "Systemübersicht"
            IVDocument  systemdoc      = null;
            IVPage      systemoverview = null;
            Application subapplic      = this._application;
            IntPtr      subapplickey   = new IntPtr(0);
            IntPtr      applickey      = new IntPtr(0);
            Application applic         = null;;
            bool        found          = false;

            foreach (var window in OpenWindowGetter.GetOpenWindows())
            {
                if (found == false)
                {
                    if (window.Value.Contains("Visio Professional") || window.Value.Contains("Microsoft Visio"))
                    {
                        OpenWindowGetter.SetForegroundWindow(window.Key);
                        applic = NetOffice.VisioApi.Application.GetActiveInstance();
                        if (subapplic == applic)
                        {
                            subapplickey = window.Key;
                        }
                        ;
                        foreach (var doc in applic.Documents)
                        {
                            foreach (var page in doc.Pages)
                            {
                                if (page.Name == "System Overview")
                                {
                                    systemdoc      = doc;
                                    systemoverview = page;
                                    applickey      = window.Key;
                                    found          = true;
                                }
                            }
                        }
                    }
                }
            }

            if (found == false)
            {
                var file = new System.IO.DirectoryInfo(
                    new System.IO.FileInfo(_application.ActiveDocument.FullName).Directory.FullName)
                           .GetFiles().First(t => t.Name.Contains("_Overview.vsdx"));
                _application.Documents.Open(file.FullName);

                foreach (var window in OpenWindowGetter.GetOpenWindows())
                {
                    if (found == false)
                    {
                        if (window.Value.Contains("Visio Professional") || window.Value.Contains("Microsoft Visio"))
                        {
                            OpenWindowGetter.SetForegroundWindow(window.Key);
                            applic = NetOffice.VisioApi.Application.GetActiveInstance();
                            if (subapplic == applic)
                            {
                                subapplickey = window.Key;
                            }
                            ;
                            foreach (var doc in applic.Documents)
                            {
                                foreach (var page in doc.Pages)
                                {
                                    if (page.Name == "System Overview")
                                    {
                                        systemdoc      = doc;
                                        systemoverview = page;
                                        applickey      = window.Key;
                                        found          = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //erstelle für jede ausgewählte Shape/Subsystem auf dem Zeichenblatt "Systemübersicht" ein Rechteck und verbinde dieses mit dem höher gelegenen System
            int     counter  = 0;
            int     sum      = shapes.Count;
            IVShape preshape = null;

            foreach (var shape in systemoverview.Shapes)
            {
                if (shape.Text == systemname)
                {
                    preshape = shape;
                }
            }
            double xvalue = (Convert.ToDouble(preshape.CellsSRC(1, 1, 0).FormulaU.Substring(0, preshape.CellsSRC(1, 1, 0).FormulaU.IndexOf(' ')))) / 10;
            double yvalue = (Convert.ToDouble(preshape.CellsSRC(1, 1, 1).FormulaU.Substring(0, preshape.CellsSRC(1, 1, 1).FormulaU.IndexOf(' ')))) / 10;

            foreach (var shape in shapes)
            {
                IVShape subsystem = systemoverview.DrawRectangle(1, 1, 3, 1.5);
                subsystem.Text = shape.Text;
                subsystem.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
                subsystem.SetCenter(BerechneXPosition(xvalue, sum, counter) / 2.54, (yvalue - 3.0) / 2.54);
                counter++;
                //verbinde zu übergeordnetem System
                preshape.AutoConnect(subsystem, 0);
                //erstelle neues Zeichenblatt und erstelle Hyperlink
                IVPage shapePage = systemdoc.Pages.Add();
                shapePage.Name = shape.Text;
                IVHyperlink hl = subsystem.Hyperlinks.Add();
                hl.SubAddress = shapePage.Name; //geht nur wenn, Page in selber Dokumentebene ist.

                //rufe Methode auf, die für die gespeicherten Pages, die benötigten Dokumente erstellt und einbindet
                CreateSubSystemElements(shapePage, applickey, pReferencer);
            }
            //setze Verbinder als gerade/straight
            foreach (var connects in systemoverview.Shapes)
            {
                if (connects.Name.Contains("Dynamic connector") || connects.Name.Contains("Dynamischer Verbinder"))
                {
                    connects.CellsSRC(1, 23, 10).Formula = "16";
                }
            }

            //systemoverview.CreateSelection(VisSelectionTypes.visSelTypeAll).Align(VisHorizontalAlignTypes.visHorzAlignLeft, VisVerticalAlignTypes.visVertAlignMiddle) ;
            OpenWindowGetter.SetForegroundWindow(subapplickey);
        }
예제 #11
0
        private void CreateRvp(string systemname, IVDocument doc)
        {
            //TODO neu erstellte Diagramme mit Shapesheet oeffnen
            IVPage      page = new IVPage();
            IVShape     header, kontext, neutral, bezogen;
            IVShape     wissenskontext, funktKontext, struktKontext;
            IVShape     goals, useMap, szenario;
            IVShape     struktPerspektive, funktPerspektive, verhaltensPerspektive;
            IVHyperlink wkhl, skhl, fkhl, ghl, uchl, mschl, sphl, fphl, vphl;
            IVShape     statusWk, statusfK, statussK, statusG, statusUcm, statusSz, statussP, statusfP, statusVp;

            foreach (Page p in doc.Pages)
            {
                page = p;
            }

            page.Name = "RVP_" + systemname;
            IVShape boundary = page.DrawRectangle(0, 12, 9, 1); boundary.CellsSRC(1, 3, 1).FormulaU = "THEMEGUARD(RGB(0,0,0))";

            header = page.DrawRectangle(1, 1, 8, 1.5); header.Text = "Requirements Viewpoint: " + systemname; header.SetCenter(4, (28 / 2.54));
            header.CellsSRC(1, 11, 4).Formula = "0"; header.LineStyle = "none"; header.CellsSRC(3, 0, 7).FormulaU = "24 pt";
            header.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            //Kontextmodelle
            kontext = page.DrawRectangle(1, 1, 3, 1.5); kontext.Text = "Context Models"; kontext.SetCenter((3 / 2.54), (25 / 2.54));
            kontext.CellsSRC(1, 11, 4).Formula = "0"; kontext.LineStyle = "none"; kontext.CellsSRC(3, 0, 7).FormulaU = "18 pt";
            kontext.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            wissenskontext = page.DrawRectangle(2.5, 2.5, 4.2, 4.2); wissenskontext.Text = "Context of Knowledge";
            wissenskontext.SetCenter((3 / 2.54), (22 / 2.54)); wissenskontext.CellsSRC(1, 11, 4).Formula = "0";
            wissenskontext.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            statusWk = page.DrawOval(1, 1, 1.16, 1.16); statusWk.SetCenter(3 / 2.54, 20.5 / 2.54); statusWk.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,0,0))";

            struktKontext = page.DrawRectangle(2.5, 2.5, 4.2, 4.2); struktKontext.Text = "Structural operational Context";
            struktKontext.SetCenter((8 / 2.54), (22 / 2.54)); struktKontext.CellsSRC(1, 11, 4).Formula = "0";
            struktKontext.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            statussK     = page.DrawOval(1, 1, 1.16, 1.16); statussK.SetCenter(8 / 2.54, 20.5 / 2.54); statussK.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,0,0))";
            funktKontext = page.DrawRectangle(2.5, 2.5, 4.2, 4.2); funktKontext.Text = "Functional operational Context";
            funktKontext.SetCenter((13 / 2.54), (22 / 2.54)); funktKontext.CellsSRC(1, 11, 4).Formula = "0";
            funktKontext.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            statusfK = page.DrawOval(1, 1, 1.16, 1.16); statusfK.SetCenter(13 / 2.54, 20.5 / 2.54); statusfK.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,0,0))";

            //Loesungsneutrale Modelle
            neutral = page.DrawRectangle(1, 1, 4, 1.5); neutral.Text = "Solution-unaware Models"; neutral.SetCenter((4 / 2.54), (18 / 2.54));
            neutral.CellsSRC(1, 11, 4).Formula = "0"; neutral.LineStyle = "none"; neutral.CellsSRC(3, 0, 7).FormulaU = "18 pt";
            neutral.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            goals = page.DrawRectangle(2.5, 2.5, 4.2, 4.2); goals.Text = "Goals";
            goals.SetCenter((3 / 2.54), (15 / 2.54)); goals.CellsSRC(1, 11, 4).Formula = "0";
            goals.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            statusG = page.DrawOval(1, 1, 1.16, 1.16); statusG.SetCenter(3 / 2.54, 13.5 / 2.54); statusG.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,0,0))";
            useMap  = page.DrawRectangle(2.5, 2.5, 4.2, 4.2); useMap.Text = "Use-Case Maps";
            useMap.SetCenter((8 / 2.54), (15 / 2.54)); useMap.CellsSRC(1, 11, 4).Formula = "0";
            useMap.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            statusUcm = page.DrawOval(1, 1, 1.16, 1.16); statusUcm.SetCenter(8 / 2.54, 13.5 / 2.54); statusUcm.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,0,0))";
            szenario  = page.DrawRectangle(2.5, 2.5, 4.2, 4.2); szenario.Text = "Scenarios";
            szenario.SetCenter((13 / 2.54), (15 / 2.54)); szenario.CellsSRC(1, 11, 4).Formula = "0";
            szenario.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            statusSz = page.DrawOval(1, 1, 1.16, 1.16); statusSz.SetCenter(13 / 2.54, 13.5 / 2.54); statusSz.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,0,0))";

            //Loesungsbezogene Modelle
            bezogen = page.DrawRectangle(1, 1, 4, 1.5); bezogen.Text = "Solution-oriented Models"; bezogen.SetCenter((4 / 2.54), (11 / 2.54));
            bezogen.CellsSRC(1, 11, 4).Formula = "0"; bezogen.LineStyle = "none"; bezogen.CellsSRC(3, 0, 7).FormulaU = "18 pt";
            bezogen.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            struktPerspektive = page.DrawRectangle(2.5, 2.5, 4.2, 4.2); struktPerspektive.Text = "Structural Perspective";
            struktPerspektive.SetCenter((3 / 2.54), (8 / 2.54)); struktPerspektive.CellsSRC(1, 11, 4).Formula = "0";
            struktPerspektive.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            statussP         = page.DrawOval(1, 1, 1.16, 1.16); statussP.SetCenter(3 / 2.54, 6.5 / 2.54); statussP.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,0,0))";
            funktPerspektive = page.DrawRectangle(2.5, 2.5, 4.2, 4.2); funktPerspektive.Text = "Function Perspective";
            funktPerspektive.SetCenter((8 / 2.54), (8 / 2.54)); funktPerspektive.CellsSRC(1, 11, 4).Formula = "0";
            funktPerspektive.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            statusfP = page.DrawOval(1, 1, 1.16, 1.16); statusfP.SetCenter(8 / 2.54, 6.5 / 2.54); statusfP.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,0,0))";
            verhaltensPerspektive = page.DrawRectangle(2.5, 2.5, 4.2, 4.2); verhaltensPerspektive.Text = "Behavioral Perspective";
            verhaltensPerspektive.SetCenter((13 / 2.54), (8 / 2.54)); verhaltensPerspektive.CellsSRC(1, 11, 4).Formula = "0";
            verhaltensPerspektive.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,255,255))";
            statusVp = page.DrawOval(1, 1, 1.16, 1.16); statusVp.SetCenter(13 / 2.54, 6.5 / 2.54); statusVp.CellsSRC(1, 3, 0).FormulaU = "THEMEGUARD(RGB(255,0,0))";

            //Weise erstellte Objekte zu
            wkhl         = wissenskontext.AddHyperlink();
            wkhl.Address = (System.IO.Path.Combine(this._application.ActiveDocument.Path, systemname + "_RVP_CoK.vsdx"));
            skhl         = struktKontext.AddHyperlink();
            skhl.Address = (System.IO.Path.Combine(this._application.ActiveDocument.Path, systemname + "_RVP_soC.vsdx"));
            fkhl         = funktKontext.AddHyperlink();
            fkhl.Address = (System.IO.Path.Combine(this._application.ActiveDocument.Path, systemname + "_RVP_foC.vsdx"));

            ghl           = goals.AddHyperlink();
            ghl.Address   = (System.IO.Path.Combine(this._application.ActiveDocument.Path, systemname + "_RVP_Goals.vsdx"));
            uchl          = useMap.AddHyperlink();
            uchl.Address  = (System.IO.Path.Combine(this._application.ActiveDocument.Path, systemname + "_RVP_UCM.vsdx"));
            mschl         = szenario.AddHyperlink();
            mschl.Address = (System.IO.Path.Combine(this._application.ActiveDocument.Path, systemname + "_RVP_MSC.vsdx"));

            sphl         = struktPerspektive.AddHyperlink();
            sphl.Address = (System.IO.Path.Combine(this._application.ActiveDocument.Path, systemname + "_RVP_stP.vsdx"));
            fphl         = funktPerspektive.AddHyperlink();
            fphl.Address = (System.IO.Path.Combine(this._application.ActiveDocument.Path, systemname + "_RVP_fuP.vsdx"));
            vphl         = verhaltensPerspektive.AddHyperlink();
            vphl.Address = (System.IO.Path.Combine(this._application.ActiveDocument.Path, systemname + "_RVP_BP.vsdx"));
        }
예제 #12
0
        /// <summary>
        /// takes the current ModelList and invokes a reonstruct action on Visio to load a model from an XML file
        /// </summary>
        private void Reconstruct()
        {
            //get current document
            IVDocument doc = _visioApplication.ActiveDocument;

            //clear
            foreach (var page in this._visioApplication.ActiveDocument.Pages)
            {
                page.Delete(0);
            }

            //create temp sheet (because visio can not have 0 sheets)
            String deletename = "deletemelater" + new Random(1337).Next(0, 1000);

            this._visioApplication.ActiveDocument.Pages.First().Name = deletename;

            //reconstruct each model one by one
            foreach (Model model in ModelList)
            {
                //create visio page
                var page = this._visioApplication.ActiveDocument.Pages.Add();
                page.Name = model.PageName;

                //iterate through all elements and set fields
                foreach (var item in model.ObjectList)
                {
                    //create new visio shape
                    var master = GetMasters().FirstOrDefault(t => t.Name == item.TypeName);
                    if (master != null)
                    {
                        try
                        {
                            //drop shape at position
                            var shape = page.Drop(master, item.Locationx, item.Locationy);

                            //set text if applicable
                            if (!String.IsNullOrEmpty(item.Text))
                            {
                                shape.Text = item.Text;
                            }

                            //set height and width; does not work for connection types
                            if (!(item is Connection))
                            {
                                shape.Cells("Height").set_Result(NetOffice.VisioApi.Enums.VisMeasurementSystem.visMSMetric, item.Height);
                                shape.Cells("Width").set_Result(NetOffice.VisioApi.Enums.VisMeasurementSystem.visMSMetric, item.Width);
                            }
                            item.Visioshape = shape;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                            throw;
                        }
                    }
                    else
                    {
                        throw new Exception($"Master for {item.TypeName} not found");
                    }
                }

                //iterate through all connectors and set connections
                foreach (var item in model.ObjectList)
                {
                    if (item is Connection)
                    {
                        try
                        {
                            //find to and from shapes
                            var connection = (Connection)item;
                            var toshape    = model.ObjectList.First(t => t.Uniquename == connection.ToObject.Uniquename)
                                             .Visioshape;
                            var fromshape = model.ObjectList
                                            .First(t => t.Uniquename == connection.FromObject.Uniquename).Visioshape;

                            //set connection and glue together
                            var beginxcell = connection.Visioshape.CellsSRC((short)NetOffice.VisioApi.Enums.VisSectionIndices.visSectionObject,
                                                                            (short)NetOffice.VisioApi.Enums.VisRowIndices.visRowXForm1D,
                                                                            (short)NetOffice.VisioApi.Enums.VisCellIndices.vis1DBeginX);
                            beginxcell.GlueTo(fromshape.CellsSRC(
                                                  (short)NetOffice.VisioApi.Enums.VisSectionIndices.visSectionObject,
                                                  (short)NetOffice.VisioApi.Enums.VisRowIndices.visRowXFormOut,
                                                  (short)NetOffice.VisioApi.Enums.VisCellIndices.visXFormPinX));

                            var beginycell = connection.Visioshape.CellsSRC((short)NetOffice.VisioApi.Enums.VisSectionIndices.visSectionObject,
                                                                            (short)NetOffice.VisioApi.Enums.VisRowIndices.visRowXForm1D,
                                                                            (short)NetOffice.VisioApi.Enums.VisCellIndices.vis1DEndX);
                            beginycell.GlueTo(toshape.CellsSRC(
                                                  (short)NetOffice.VisioApi.Enums.VisSectionIndices.visSectionObject,
                                                  (short)NetOffice.VisioApi.Enums.VisRowIndices.visRowXFormOut,
                                                  (short)NetOffice.VisioApi.Enums.VisCellIndices.visXFormPinX));
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                            throw;
                        }
                    }
                }

                //delete stub page
                this._visioApplication.ActiveDocument.Pages.First(t => t.Name == deletename).Delete(0);
            }
        }
예제 #13
0
 /// <summary>
 /// define extra operations to be set during document initialization, e.g. settings
 /// </summary>
 /// <param name="doc"></param>
 protected virtual void VisioApplication_DocumentCreatedOrLoadedEvent(IVDocument doc)
 {
 }
예제 #14
0
 public static IEnumerable <Page> getPages(this IVDocument document)
 {
     return(document.Pages.Cast <Page>());
 }