/// <summary>
        /// Show Ports of selected elements in Diagram. The ports are on the right side of the element.
        /// If isOptimized=true:
        /// - Receiving Ports on the left side (Server, Receiver)
        /// - Sending Ports on the right side (Client, Sender)
        /// </summary>
        /// <param name="isOptimizePortLayout"></param>
        public void ShowPortsInDiagram(bool isOptimizePortLayout = false)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                // remember Diagram data of current selected diagram
                var eaDia = new EaDiagram(_rep);

                // hide all ports
                RemovePortFromDiagramGui();
                // show all ports
                eaDia.ReloadSelectedObjectsAndConnector();// reload selection
                EaService.ShowEmbeddedElementsGui(_rep, "Port", isOptimizePortLayout);
                // set selction

                eaDia.ReloadSelectedObjectsAndConnector();
                Cursor.Current = Cursors.Default;
            }
            catch (Exception e11)
            {
                MessageBox.Show(e11.ToString(), "Error show ports on diagram");
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        /// <summary>
        /// Set Diagram styles in PDATA and StyleEx.
        ///
        /// HideQuals=1 HideQualifiers:
        /// OpParams=2  Show full Operation Parameter
        /// ScalePI=1   Scale to fit page
        /// Theme=:119  Set the diagram theme and the used features of the theme (here 119, see StyleEx of t_diagram)
        ///
        /// par[0] contains the values as a semicolon/comma separated Style
        /// par[1] contains the values as a semicolon/comma separated PDATA
        /// par[2] contains the values as a semicolon/comma separated properties
        /// par[3] contains the possible diagram types
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="dia"></param>
        /// <param name="par">par[] </param>
        private static void SetDiagramStyle(Repository rep, EA.Diagram dia, string[] par)
        {
            EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: false);

            if (eaDia.Dia == null)
            {
                return;
            }
            rep.SaveDiagram(eaDia.Dia.DiagramID);

            string styles     = par[0].Replace(",", ";");
            string pdatas     = par[1].Replace(",", ";");
            string properties = par[2].Replace(",", ";");
            string types      = par[3];



            var diagramStyle = new DiagramStyle(rep, dia, types, styles, pdatas, properties);

            if (diagramStyle.IsToProcess())
            {
                diagramStyle.UpdateStyles();
                diagramStyle.SetProperties(withSql: false);
                diagramStyle.SetProperties(withSql: true);
            }

            eaDia.ReloadSelectedObjectsAndConnector(saveDiagram: false);
        }
        /// <summary>
        /// Worker for change the type of nodes:
        /// - All nodes
        /// - Selected nodes
        /// - Pass the LabelStyle attribute you want to change (see type LabelStyle)
        ///   hoTools updates: DiagramObjects.Styles
        /// </summary>
        /// <param name="style"></param>
        /// <param name="embeddedCheckSub"></param>
        private void DoChangeLabelGui(EA.Repository rep, LabelStyle style, bool embeddedCheckSub = false)
        {
            EaDiagram eaDia = new EaDiagram(rep);
            Diagram   dia   = eaDia.Dia;

            if (dia == null)
            {
                return;
            }
            _rep.SaveDiagram(dia.DiagramID);

            // target object/element

            // for each selected element
            foreach (DiagramObject obj in eaDia.SelObjects)
            {
                var el = _rep.GetElementByID(obj.ElementID);
                if (el.IsEmbeddedElement(rep, true))
                {
                    DiagramObject portObj = dia.GetDiagramObjectByID(el.ElementID, "");
                    //EA.DiagramObject portObj = dia.GetDiagramObjectByID(el.ElementID, "");
                    DoChangeLabelStyle(el, portObj, style);
                }
                else
                {   // all element like Class, Component,..
                    foreach (Element p in el.EmbeddedElements)
                    {
                        if (p.IsEmbeddedElement(rep, true))
                        {
                            DiagramObject portObj = dia.GetDiagramObjectByID(p.ElementID, "");
                            if (portObj != null)
                            {
                                //EA.DiagramObject portObj = dia.GetDiagramObjectByID(p.ElementID, "");
                                // HDN=1;  Label hidden
                                // HDN=0;  Label visible
                                DoChangeLabelStyle(p, portObj, style);
                                if (p.Type == "Port" && embeddedCheckSub)
                                {
                                    // Check if embedded interface
                                    foreach (EA.Element p1 in p.EmbeddedElements)
                                    {
                                        DiagramObject portObj1 = dia.GetDiagramObjectByID(p1.ElementID, "");
                                        if (portObj1 != null)
                                        {
                                            DoChangeLabelStyle(p, portObj, style);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            _rep.ReloadDiagram(dia.DiagramID);
            eaDia.ReloadSelectedObjectsAndConnector();
        }
        /// <summary>
        /// Wrapper to change DiagramLink style
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="type"></param>
        /// <param name="style"></param>
        /// <param name="property"></param>
        /// <param name="changeScope"></param>
        public static void DiagramLinkStyleWrapper(Repository rep, string type, string style, string property, ChangeScope changeScope)
        {
            EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: false);

            // Handle selected diagram and its selected items (connector/objects)
            if (eaDia.Dia != null)
            {
                rep.SaveDiagram(eaDia.Dia.DiagramID);
                // over all links
                foreach (var link in eaDia.GetSelectedLinks())
                {
                    var linkStyle = new DiagramLinkStyle(rep, link, type, style, property);
                    if (linkStyle.IsToProcess())
                    {
                        linkStyle.UpdateStyles();
                        linkStyle.SetProperties();
                        linkStyle.SetEaLayoutStyles();
                    }
                }
                eaDia.ReloadSelectedObjectsAndConnector(saveDiagram: false);
            }
            else
            {
                var liParameter = new string[4];
                liParameter[0] = type;
                liParameter[1] = style;
                liParameter[2] = property;

                switch (rep.GetContextItemType())
                {
                case EA.ObjectType.otPackage:
                    EA.Package pkg = (EA.Package)rep.GetContextObject();
                    RecursivePackages.DoRecursivePkg(rep, pkg, null, null,
                                                     SetDiagramLinkStyle,
                                                     liParameter,
                                                     changeScope);
                    break;

                case EA.ObjectType.otElement:
                    EA.Element el = (EA.Element)rep.GetContextObject();
                    RecursivePackages.DoRecursiveEl(rep, el, null,
                                                    SetDiagramLinkStyle,
                                                    liParameter,
                                                    changeScope);
                    break;
                }
            }
        }
Example #5
0
        /// <summary>
        /// Wrapper to change DiagramObject style
        /// - Selected Diagramobjects
        /// - Package (Diagrams and their DiagramObjects in package and below Elements)
        /// - Element (Diagrams and their DiagramObjects below Elements)
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="type"></param>
        /// <param name="style"></param>
        /// <param name="property"></param>
        /// <param name="changeScope"></param>
        public static void DiagramObjectStyleWrapper(Repository rep, string type, string style, string property, ChangeScope changeScope)
        {
            EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: true);

            if (eaDia.Dia != null)
            {
                rep.SaveDiagram(eaDia.Dia.DiagramID);
                foreach (var diaObj in eaDia.SelObjects)
                {
                    var a           = new DiagramObjectStyle(rep, diaObj, type, style, property);
                    var objectStyle = new DiagramObjectStyle(rep, diaObj, type, style, property);
                    if (objectStyle.IsToProcess())
                    {
                        objectStyle.UpdateStyles();
                        objectStyle.SetProperties();
                        objectStyle.SetEaLayoutStyles();
                        objectStyle.SetCompleteNessMarker();
                    }
                }
                eaDia.ReloadSelectedObjectsAndConnector(saveDiagram: false);
            }
            else
            {
                var liParameter = new string[4];
                liParameter[0] = type;
                liParameter[1] = style;
                liParameter[2] = property;

                switch (rep.GetContextItemType())
                {
                case ObjectType.otPackage:
                    Package pkg = (Package)rep.GetContextObject();
                    RecursivePackages.DoRecursivePkg(rep, pkg, null, null,
                                                     SetDiagramObjectStyle,
                                                     liParameter,
                                                     changeScope);
                    break;

                case ObjectType.otElement:
                    Element el = (Element)rep.GetContextObject();
                    RecursivePackages.DoRecursiveEl(rep, el, null,
                                                    SetDiagramObjectStyle,
                                                    liParameter,
                                                    changeScope);
                    break;
                }
            }
        }
        /// <summary>
        /// Connect Ports between selected Elements from GUI with Mouse Wait
        /// It connects Ports of different elements with the same name with a not directed connector
        /// </summary>
        public void ConnectPortsGui()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                var eaDia = new EaDiagram(_rep);
                DoConnectPortGui();

                eaDia.ReloadSelectedObjectsAndConnector();
                Cursor.Current = Cursors.Default;
                MessageBox.Show($@"{_count} ports connected!");
            }
            catch (Exception e11)
            {
                MessageBox.Show(e11.ToString(), @"Error generating ports");
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        public void SetConnectionDirectionUnspecifiedGui()
        {
            var     eaDia = new EaDiagram(_rep);
            Diagram dia   = eaDia.Dia;

            if (eaDia.Dia == null)
            {
                return;
            }
            if (eaDia.SelectedObjectsCount == 0)
            {
                return;
            }
            eaDia.Save();

            // target object/element
            DiagramObject obj;
            Element       el;

            for (int i = 0; i < eaDia.SelectedObjectsCount; i++)
            {
                obj = (DiagramObject)dia.SelectedObjects.GetAt((short)i);
                el  = _rep.GetElementByID(obj.ElementID);

                if (el.Type == "Port")
                {
                    // selected element was port
                    SetElementConnectorDirectionUnspecified(el);
                }
                else
                {   // selected element was "Element"
                    foreach (Element port in el.EmbeddedElements)
                    {
                        SetElementConnectorDirectionUnspecified(port);
                    }
                }
            }
            eaDia.ReloadSelectedObjectsAndConnector();
        }
        public void DoOrderDiagramObjectsGui()
        {
            Diagram dia = _rep.GetCurrentDiagram();

            if (dia == null)
            {
                return;
            }
            int count = dia.SelectedObjects.Count;

            if (count < 2)
            {
                return;
            }
            _rep.SaveDiagram(dia.DiagramID);

            var eadia = new EaDiagram(_rep);

            eadia.SortSelectedObjects();
            eadia.ReloadSelectedObjectsAndConnector();

            //_rep.ReloadDiagram(dia.DiagramID);
        }
        public void SetConnectionDirectionUnspecifiedGui()
        {
            var eaDia = new EaDiagram(_rep);
            Diagram dia = eaDia.Dia;
            if (eaDia.Dia == null) return;
            if (eaDia.SelectedObjectsCount == 0) return;
            eaDia.Save();

            // target object/element
            DiagramObject obj;
            Element el;

            for (int i = 0; i < eaDia.SelectedObjectsCount; i++)
            {
                obj = (DiagramObject)dia.SelectedObjects.GetAt((short)i);
                el = _rep.GetElementByID(obj.ElementID);

                if (el.Type == "Port")
                {
                    // selected element was port
                    SetElementConnectorDirectionUnspecified(el);
                }
                else
                {   // selected element was "Element"
                    foreach (Element port in el.EmbeddedElements)
                    {
                        SetElementConnectorDirectionUnspecified(port);
                    }

                }

            }
            eaDia.ReloadSelectedObjectsAndConnector();
        }
        /// <summary>
        /// Connect Ports between selected Elements from GUI with Mouse Wait
        /// It connects Ports of different elements with the same name with a not directed connector
        /// </summary>
        public void ConnectPortsGui()
        {
            try
            {

                Cursor.Current = Cursors.WaitCursor;
                var eaDia = new EaDiagram(_rep);
                DoConnectPortGui();

                eaDia.ReloadSelectedObjectsAndConnector();
                Cursor.Current = Cursors.Default;
                MessageBox.Show(String.Format("{0} ports connected!", _count));
            }
            catch (Exception e11)
            {
                MessageBox.Show(e11.ToString(), "Error generating ports");
            }
            finally
            {
                Cursor.Current = Cursors.Default;

            }
        }
        /// <summary>
        /// Show Ports of selected elements in Diagram. The ports are on the right side of the element.
        /// If isOptimized=true:
        /// - Receiving Ports on the left side (Server, Receiver)
        /// - Sending Ports on the right side (Client, Sender)
        /// </summary>
        /// <param name="isOptimizePortLayout"></param>
        public void ShowPortsInDiagram(bool isOptimizePortLayout=false)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                // remember Diagram data of current selected diagram
                var eaDia = new EaDiagram(_rep);
                
                // hide all ports
                RemovePortFromDiagramGui();
                // show all ports
                eaDia.ReloadSelectedObjectsAndConnector();// reload selection
                EaService.ShowEmbeddedElementsGui(_rep, "Port", isOptimizePortLayout);
                // set selction

                eaDia.ReloadSelectedObjectsAndConnector();
                Cursor.Current = Cursors.Default;

            }
            catch (Exception e11)
            {
                MessageBox.Show(e11.ToString(), "Error show ports on diagram");
            }
            finally
            {
                Cursor.Current = Cursors.Default;

            }
        }
        public void DoOrderDiagramObjectsGui()
        {
            Diagram dia = _rep.GetCurrentDiagram();
            if (dia == null) return;
            int count = dia.SelectedObjects.Count;

            if (count < 2) return;
            _rep.SaveDiagram(dia.DiagramID);

            var eadia = new EaDiagram(_rep);
            eadia.SortSelectedObjects();
            eadia.ReloadSelectedObjectsAndConnector();
 
            //_rep.ReloadDiagram(dia.DiagramID);


        }