public static void SynchronizeTaggedValues(EA.Repository rep)
        {
            // over all selected elements
            EaDiagram curDiagram = new EaDiagram(rep);

            if (curDiagram.Dia == null)
            {
                return;
            }
            int indexLast = curDiagram.SelElements.Count - 1;

            if (indexLast < 0)
            {
                return;
            }

            EA.Element elLast   = curDiagram.SelElements[0];
            string     stereoEx = "";



            // over all elements, skip first element because that is the property template
            for (int i = 1; i <= indexLast; i++)
            {
                // synchronize all stereotypes
                if (stereoEx != curDiagram.SelElements[i].StereotypeEx)
                {
                    stereoEx = curDiagram.SelElements[i].StereotypeEx;
                    TaggedValue.ElTagValue elTagValues = new TaggedValue.ElTagValue(elLast, stereoEx);
                    elTagValues.SyncTaggedValues(rep, curDiagram.SelElements[i]);
                }
            }
        }
        /// <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;
                }
            }
        }
示例#6
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;
                }
            }
        }
示例#7
0
        public static void CopyTaggedValues(EA.Repository rep)
        {
            // over all selected elements
            EaDiagram curDiagram = new EaDiagram(rep);

            if (curDiagram.Dia == null)
            {
                return;
            }
            int indexLast = curDiagram.SelElements.Count - 1;

            // only synchronize TaggedValues
            if (indexLast == 0)
            {
                EaService.SynchronizeTaggedValues(rep);
            }
            if (indexLast < 1)
            {
                return;
            }

            EA.Element elLast   = curDiagram.SelElements[0];
            string     stereoEx = elLast.StereotypeEx;


            ElTagValue elTagValues = new ElTagValue(elLast, stereoEx);

            // over all elements, skip first element because that is the property template
            for (int i = 1; i <= indexLast; i++)
            {
                // Set stereotypes if changed
                if (curDiagram.SelElements[i].StereotypeEx != stereoEx)
                {
                    curDiagram.SelElements[i].StereotypeEx = stereoEx;
                }
                var error = rep.GetLastError();
                curDiagram.SelElements[i].Update();
                elTagValues.Copy(curDiagram.SelElements[i]);
                curDiagram.SelElements[i].Update();
            }
            // synchronize all stereotypes
            elTagValues.SyncTaggedValues(rep, elLast);
        }
        /// <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 EaCollectionDiagramObjects(EaDiagram eaDia) : base(eaDia.Rep)
 {
     _eaDia = eaDia;
 }
        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);


        }
示例#16
0
        public static void DiagramObjectMove(Repository rep)
        {
            // Package in browser selected
            // only copy elements of type element
            EA.ObjectType objType = rep.GetTreeSelectedItemType();

            // if diagram: get the Element or Package

            EA.Package pkg      = null;
            EA.Element elTarget = null;
            if (objType == EA.ObjectType.otDiagram)
            {
                var dia = (EA.Diagram)rep.GetTreeSelectedObject();
                if (dia.ParentID == 0)
                {
                    pkg = rep.GetPackageByID(dia.PackageID);
                }
                else
                {
                    elTarget = rep.GetElementByID(dia.ParentID);
                }
            }

            if (objType == EA.ObjectType.otPackage || pkg != null)
            {
                // get selected DiagramObjects
                EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: false);

                // Handle selected diagram and its selected items (connector/objects)
                if (eaDia.Dia != null)
                {
                    if (objType == EA.ObjectType.otPackage && pkg == null)
                    {
                        pkg = (EA.Package)rep.GetTreeSelectedObject();
                    }
                    // over all selected objects
                    var count = 0;

                    foreach (var dObj in eaDia.SelObjects)
                    {
                        EA.Element el = rep.GetElementByID(dObj.ElementID);
                        // don't change nested elements, you have to move the root element
                        if (el.Type != "Package" && el.ObjectType == EA.ObjectType.otElement && el.ParentID == 0)
                        {
                            el.PackageID = pkg.PackageID;
                            el.Update();
                            count = count + 1;
                        }
                    }
                    rep.RefreshModelView(pkg.PackageID);
                    if (count != eaDia.SelObjects.Count)
                    {
                        MessageBox.Show($@"Total items: {eaDia.SelObjects.Count}
Moved items: {count}

If item is a nested item only the root will be copied.
", @"not all items moved");
                    }
                }
            }
            // Element in browser selected, or element to copy beneath exists
            if (rep.GetTreeSelectedItemType() == EA.ObjectType.otElement || elTarget != null)
            {
                if (elTarget == null)
                {
                    elTarget = (EA.Element)rep.GetTreeSelectedObject();
                }

                // get selected DiagramObjects
                EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: false);

                // Handle selected diagram and its selected items (connector/objects)
                if (eaDia.Dia != null)
                {
                    // over all selected objects
                    foreach (var dObj in eaDia.SelObjects)
                    {
                        EA.Element el = rep.GetElementByID(dObj.ElementID);
                        // don't change nested elements, you have to move the root element
                        // don't copy to itself
                        if (el.Type != "Package" && el.ObjectType == EA.ObjectType.otElement && el.ParentID == 0 && el.ElementID != elTarget.ElementID)
                        {
                            el.ParentID = elTarget.ElementID;
                            el.Update();
                        }
                    }
                }
            }
        }