private static void DoChangeLabelStyle(DiagramObject portObj, LabelStyle style)
        {
            switch (style)
            {
                case LabelStyle.IsHidden:
                    ChangeLabel(portObj, @"HDN=0", "HDN=1");
                    break;

                case LabelStyle.IsShown:
                    ChangeLabel(portObj, @"HDN=1", "HDN=0");
                    break;

                case LabelStyle.PositionLeft:
                    ChangeLabel(portObj, @"OX=[\+\-0-9]*", @"OX=-200");
                    break;

                case LabelStyle.PositionRight:
                    ChangeLabel(portObj, @"OX=[\+\-0-9]*", @"OX=24");
                    break;

                case LabelStyle.PositionMinus:
                    // get old x position
                    Match match = Regex.Match(portObj.Style, @"OX=([\+\-0-9]*)");
                    if (match.Success)
                    {
                        int xPos = Convert.ToInt32(match.Groups[1].Value) - 15;
                        ChangeLabel(portObj, @"OX=[\+\-0-9]*", String.Format("OX={0}", xPos));
                    }
                    break;

                case LabelStyle.PositionPlus:
                    // get old x position
                    match = Regex.Match(portObj.Style, @"OX=([\+\-0-9]*)");
                    if (match.Success)
                    {
                        int xPos = Convert.ToInt32(match.Groups[1].Value) + 15;
                        ChangeLabel(portObj, @"OX=[\+\-0-9]*", String.Format("OX={0}", xPos)  );
                    }
                    break;
            }

            //string style = (string)portObj.Style;
            //if (isHidden) style = style.Replace("HDN=0", "HDN=1");
            //else style = style.Replace("HDN=1", "HDN=0");
            //portObj.Style = style;
        }
Ejemplo n.º 2
0
        //DIAGRAM CONTENT
        public void Generate_otDiagram_content(EA.Repository m_Repository, string TOI_GUID, string SP_BaseURL,
                                               out List <string> listOfElements,
                                               out List <string> listOfElementsNames,
                                               out List <string> listOfLinks,
                                               out List <string> listOfLinkNames,
                                               out Dictionary <string, string> DiagramDictionary)
        {
            listOfElements      = new List <string>();
            listOfElementsNames = new List <string>();
            listOfLinks         = new List <string>();
            listOfLinkNames     = new List <string>();

            EA.Diagram DiagramToShow = (EA.Diagram)m_Repository.GetDiagramByGuid(TOI_GUID);



            //STORE DIAGRAM ELEMENTS
            for (short iDO = 0; iDO < DiagramToShow.DiagramObjects.Count; iDO++)
            {
                EA.DiagramObject MyDO = (EA.DiagramObject)DiagramToShow.DiagramObjects.GetAt(iDO);
                int        ID         = m_Repository.GetElementByID(MyDO.ElementID).ElementID;
                EA.Element MyEle      = (EA.Element)m_Repository.GetElementByID(ID);
                listOfElements.Add(MyEle.Name + "|" + MyEle.ObjectType + "|" + MyEle.ElementGUID);
                listOfElementsNames.Add(MyEle.Name);
            }



            //STORE DIAGRAM LINKS
            for (short iDO = 0; iDO < DiagramToShow.DiagramLinks.Count; iDO++)
            {
                EA.DiagramLink MyLink = (EA.DiagramLink)DiagramToShow.DiagramLinks.GetAt(iDO);
                int            ID     = m_Repository.GetConnectorByID(MyLink.ConnectorID).ConnectorID;

                EA.Connector con;

                try //Try and get the connector object from the repository
                {
                    con = (EA.Connector)m_Repository.GetConnectorByID(ID);
                    listOfLinks.Add(con.Name + "|" + con.ObjectType + "|" + con.ConnectorGUID);
                    listOfLinkNames.Add(con.Name);
                }
                catch { }
            }



            //JSON Content
            string DiagramURL = SP_BaseURL + "/" + DiagramToShow.Name + "|otDiagram|" + TOI_GUID;


            DiagramDictionary = new Dictionary <string, string>();
            DiagramDictionary.Add("Diagram Name", DiagramToShow.Name);
            DiagramDictionary.Add("Created Data", DiagramToShow.CreatedDate.ToString());
            DiagramDictionary.Add("Meta Type", DiagramToShow.MetaType);
            DiagramDictionary.Add("Notes", DiagramToShow.Notes);
            DiagramDictionary.Add("Package ID", DiagramToShow.PackageID.ToString());
            DiagramDictionary.Add("Big Preview", DiagramURL + "/BigPreview");
            DiagramDictionary.Add("Small Preview", DiagramURL + "/SmallPreview");
        }
        /// <summary>
        /// Align Label
        /// </summary>
        /// <param name="portObj"></param>
        /// <param name="edge"></param>
        /// <param name="settingsInterface"></param>
        private void AlignLabel(DiagramObject portObj, EaExtensionClass.EmbeddedPosition edge, PortAlignmentItem settingsInterface)
        {
            switch (edge)
            {
            case EaExtensionClass.EmbeddedPosition.Top:
                ChangeDiagramObjectLabel(portObj, x: settingsInterface.XTop, y: settingsInterface.YTop,
                                         rotation: settingsInterface.RotationTop);
                break;

            case EaExtensionClass.EmbeddedPosition.Bottom:
                ChangeDiagramObjectLabel(portObj, x: settingsInterface.XBottom, y: settingsInterface.YBottom,
                                         rotation: settingsInterface.RotationBottom);
                break;

            case EaExtensionClass.EmbeddedPosition.Right:
                ChangeDiagramObjectLabel(portObj, x: settingsInterface.XRight, y: settingsInterface.YRight,
                                         rotation: settingsInterface.RotationRight);
                break;

            case EaExtensionClass.EmbeddedPosition.Left:
                ChangeDiagramObjectLabel(portObj, x: settingsInterface.XLeft, y: settingsInterface.YLeft,
                                         rotation: settingsInterface.RotationLeft);
                break;
            }
        }
        public SpecIfMetadata CreateMetaDataForDiagramObject(EAAPI.DiagramObject diagramObject,
                                                             EAAPI.Element element)
        {
            SpecIfMetadata result = new SpecIfMetadata();

            Shape shape = new Shape
            {
                Bounds            = new Bounds(),
                ResourceReference = new ResourceReference
                {
                    IdReference       = EaSpecIfGuidConverter.ConvertEaGuidToSpecIfGuid(element.ElementGUID),
                    RevisionReference = EaDateToRevisionConverter.ConvertDateToRevision(element.Modified)
                }
            };

            int recatangleWidth = (diagramObject.right - diagramObject.left);
            int rectangleHeight = (-diagramObject.bottom) - (-diagramObject.top);

            shape.Bounds.X      = diagramObject.left;
            shape.Bounds.Y      = (diagramObject.top * -1);
            shape.Bounds.Width  = recatangleWidth;
            shape.Bounds.Height = rectangleHeight;

            result.Shape = shape;

            return(result);
        }
Ejemplo n.º 5
0
        private void UpdateElementOnDiagram(
            EAAPI.Diagram lifeCycleDiagram, int elementID, String backgroundColor)
        {
            // Parse out the old BCol and add the new.
            if (!String.IsNullOrEmpty(backgroundColor))
            {
                EAAPI.DiagramObject obj = null;
                for (short nIndex = 0; nIndex < lifeCycleDiagram.DiagramObjects.Count; nIndex++)
                {
                    obj = (EAAPI.DiagramObject)lifeCycleDiagram.DiagramObjects.GetAt(nIndex);
                    if (obj.ElementID == elementID)
                    {
                        break;
                    }
                }

                if (null != obj)
                {
                    String   styleString = obj.Style.ToString();
                    String[] styleList   = styleString.Split(';');
                    for (int nIndex = 0; nIndex < styleList.Count(); nIndex++)
                    {
                        if (true == styleList[nIndex].Contains("BCol"))
                        {
                            styleList[nIndex] = backgroundColor;
                        }
                    }
                    styleString = String.Join(";", styleList);
                    obj.Style   = styleString;

                    obj.Update();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get the current Diagram with it's selected objects and connectors.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="getAllDiagramObject">True if you want all diagram objects if nothing no diagram object is selected</param>
        public EaDiagram(Repository rep, bool getAllDiagramObject = false)
        {
            _rep = rep;
            _dia = _rep.GetCurrentDiagram();
            IsSelectedObjects = false;
            if (_dia == null)
            {
                return;
            }
            if (_dia.SelectedObjects.Count == 0 && getAllDiagramObject)
            {
                // overall diagram objects
                foreach (EA.DiagramObject obj in _dia.DiagramObjects)
                {
                    _selectedObjects.Add(obj);
                    SelElements.Add(rep.GetElementByID(obj.ElementID));
                }
            }
            // If an context element exists than this is the last selected element
            if (_dia.SelectedObjects.Count > 0)
            {
                EA.ObjectType type = _rep.GetContextItemType();
                // only package and object makes sense, or no context element (than go for selected elements)
                if (type == EA.ObjectType.otElement ||
                    type == EA.ObjectType.otPackage ||
                    type == EA.ObjectType.otNone)
                {
                    // 1. store context element/ last selected element
                    EA.Element elContext = (EA.Element)rep.GetContextObject();
                    // no context element available, take first element
                    if (elContext == null)
                    {
                        EA.DiagramObject obj = (EA.DiagramObject)_dia.SelectedObjects.GetAt(0);
                        elContext = rep.GetElementByID(obj.ElementID);
                    }
                    _conTextDiagramObject = _dia.GetDiagramObjectByID(elContext.ElementID, "");

                    SelElements.Add(elContext);
                    _selectedObjects.Add(_conTextDiagramObject);
                    IsSelectedObjects = true;

                    // over all selected diagram objects
                    foreach (EA.DiagramObject obj in _dia.SelectedObjects)
                    {
                        // skip last selected element / context element
                        if (obj.ElementID == _conTextDiagramObject.ElementID)
                        {
                            continue;
                        }

                        _selectedObjects.Add(obj);
                        SelElements.Add(rep.GetElementByID(obj.ElementID));
                    }
                }
            }
            _selectedConnector = _dia.SelectedConnector;
        }
        /// <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();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Select diagram object for the passed connector. Save diagram and reload / refresh it.
        /// </summary>
        public void SelectDiagramObject(EA.Connector con)
        {
            Unselect();
            Save();
            Rep.ReloadDiagram(_dia.DiagramID);


            EA.DiagramObject diaObj = _dia.GetDiagramObjectByID(con.SupplierID, "");
            _dia.SelectedObjects.AddNew(diaObj.ElementID.ToString(), diaObj.ObjectType.ToString());
        }
Ejemplo n.º 9
0
        // ReSharper disable once UnusedMember.Global
        public void SortSelectedObjects()
        {
            // estimate sort criteria (left/right, top/bottom)
            bool isVerticalSorted = true;

            EA.DiagramObject obj1 = (EA.DiagramObject)_dia.SelectedObjects.GetAt(0);
            EA.DiagramObject obj2 = (EA.DiagramObject)_dia.SelectedObjects.GetAt(1);
            if (Math.Abs(obj1.left - obj2.left) > Math.Abs(obj1.top - obj2.top))
            {
                isVerticalSorted = false;
            }

            // fill the diagram objects to sort by name / by position
            var lIdsByName     = new List <DiagramObject>();
            var lObjByPosition = new List <DiagramObjectSelected>();

            foreach (EA.DiagramObject obj in _selectedObjects)
            {
                EA.Element el = Rep.GetElementByID(obj.ElementID);
                lIdsByName.Add(new DiagramObject(el.Name, el.ElementID));
                int position = obj.left;
                if (isVerticalSorted)
                {
                    position = obj.top;
                }
                lObjByPosition.Add(new DiagramObjectSelected(obj, position, obj.left));
            }

            // sort name list and position list
            lIdsByName.Sort(new DiagramObjectComparer());
            // sort diagram objects according to position and vertical / horizontal sorting
            if (isVerticalSorted)
            {
                lObjByPosition.Sort(new DiagramObjectSelectedVerticalComparer());
            }
            else
            {
                lObjByPosition.Sort(new DiagramObjectSelectedHorizontalComparer());
            }


            foreach (EA.DiagramObject obj in _dia.SelectedObjects)
            {
                // find position of element in sorted selected objects
                int pos = lIdsByName.FindIndex(x => x.Id == obj.ElementID);

                int length = obj.right - obj.left;
                int high   = obj.top - obj.bottom;
                obj.left   = lObjByPosition[pos].Left;
                obj.bottom = lObjByPosition[pos].Obj.bottom;
                obj.right  = obj.left + length;
                obj.top    = obj.bottom + high;
                obj.Update();
            }
        }
        public SpecIfMetadata CreateMetaDataForDiagramLink(EAAPI.DiagramLink diagramLink,
                                                           EAAPI.Connector connector,
                                                           EAAPI.DiagramObject sourceDiagramObject,
                                                           EAAPI.DiagramObject targetDiagramObject,
                                                           EAAPI.Element sourceElement,
                                                           EAAPI.Element targetElement)

        {
            SpecIfMetadata result = new SpecIfMetadata();

            EAAPI.Element srcElement  = sourceElement;
            EAAPI.Element trgtElement = targetElement;

            string directionAttribute = null; // unspecified

            if (connector.Direction == "Source -> Destination")
            {
                directionAttribute = "unidirectional";
            }
            else if (connector.Direction == "Destination -> Source")
            {
                srcElement         = targetElement;
                trgtElement        = sourceElement;
                directionAttribute = "unidirectional";
            }
            else if (connector.Direction == "Bi-Directional")
            {
                directionAttribute = "bidirectional";
            }

            Edge edge = new Edge
            {
                Waypoints  = new List <Waypoint>(),
                References = new List <SpecIfReferenceBase>(),
                SourceResourceReference = new ResourceReference
                {
                    IdReference       = EaSpecIfGuidConverter.ConvertEaGuidToSpecIfGuid(srcElement.ElementGUID),
                    RevisionReference = EaDateToRevisionConverter.ConvertDateToRevision(srcElement.Modified)
                },
                TargetResourceReference = new ResourceReference
                {
                    IdReference       = EaSpecIfGuidConverter.ConvertEaGuidToSpecIfGuid(trgtElement.ElementGUID),
                    RevisionReference = EaDateToRevisionConverter.ConvertDateToRevision(trgtElement.Modified)
                },
                Direction = directionAttribute
            };

            edge.Waypoints = CalculateWaypointsForDiagramLink(diagramLink, sourceDiagramObject, targetDiagramObject);

            result.Edge = edge;

            return(result);
        }
        /// <summary>
        /// Returns the edge an embedded element is bound to (left, right, top, bottom)
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="rep"></param>
        /// <returns></returns>
        public static EmbeddedPosition Edge(this EA.DiagramObject obj, EA.Repository rep)
        {
            EA.Element el = rep.GetElementByID(obj.ElementID);


            EA.Element elParent = el.GetParentOfEmbedded(rep);
            if (elParent == null)
            {
                return(EmbeddedPosition.Undefined);
            }
            // for Required/Required Interface use the owning Port for the position
            if (el.Type == "ProvidedInterface" ||
                el.Type == "RequiredInterface")
            {
                if (el.ParentID == 0)
                {
                    return(EmbeddedPosition.Undefined);
                }
                el = rep.GetElementByID(el.ParentID);
            }


            EA.Diagram       dia              = rep.GetDiagramByID(obj.DiagramID);
            EA.DiagramObject objParent        = dia.GetDiagramObjectByID(elParent.ElementID, "");
            EA.DiagramObject objFirstEmbedded = dia.GetDiagramObjectByID(el.ElementID, "");
            if (objParent == null)
            {
                return(EmbeddedPosition.Undefined);
            }

            int horicontalCenter = objFirstEmbedded.left + (objFirstEmbedded.right - objFirstEmbedded.left) / 2;
            int verticalCenter   = objFirstEmbedded.top - (objFirstEmbedded.top - objFirstEmbedded.bottom) / 2;

            if (horicontalCenter < objParent.left + 10 && horicontalCenter > objParent.left - 10)
            {
                return(EmbeddedPosition.Left);
            }
            if (horicontalCenter < objParent.right + 10 && horicontalCenter > objParent.right - 10)
            {
                return(EmbeddedPosition.Right);
            }


            if (verticalCenter < objParent.top + 10 && verticalCenter > objParent.top - 10)
            {
                return(EmbeddedPosition.Top);
            }
            if (verticalCenter < objParent.bottom + 10 && verticalCenter > objParent.bottom - 10)
            {
                return(EmbeddedPosition.Bottom);
            }
            return(EmbeddedPosition.Undefined);
        }
        /// <summary>
        /// Get Style of a DiagramObject.
        /// </summary>
        /// <param name="portObj"></param>
        /// <param name="styleName"></param>
        private static string GetDiagramObjectStyle(DiagramObject portObj, string styleName)
        {
            var style = (string)portObj.Style;

            Match match = Regex.Match(style, $"{styleName}=[;]*;");

            if (match.Success)
            {
                return(match.Value);
            }
            return("");
        }
        // ReSharper disable once UnusedMember.Global
        public static void VisualizePortForDiagramobject(int pos, EA.Diagram dia, EA.DiagramObject diaObjSource, EA.Element port, EA.Element interf)
        {
            // check if port already exists
            foreach (EA.DiagramObject diaObj in dia.DiagramObjects)
            {
                if (diaObj.ElementID == port.ElementID)
                {
                    return;
                }
            }

            // visualize ports
            int length = 6;
            // calculate target position
            int left  = diaObjSource.right - length / 2;
            int right = left + length;
            int top   = diaObjSource.top;

            top = top - 10 - pos * 10;
            int    bottom    = top - length;
            string position  = "l=" + left + ";r=" + right + ";t=" + top + ";b=" + bottom + ";";
            var    diaObject = (EA.DiagramObject)dia.DiagramObjects.AddNew(position, "");

            dia.Update();
            if (port.Type.Equals("Port"))
            {
                // not showing label
                diaObject.Style = "LBL=CX=97:CY=13:OX=0:OY=0:HDN=1:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;";
            }
            else
            {
                // not showing label
                diaObject.Style = "LBL=CX=97:CY=13:OX=39:OY=3:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;";
            }
            diaObject.ElementID = port.ElementID;


            diaObject.Update();

            if (interf == null)
            {
                return;
            }

            // visualize interface
            var diaObject2 = (EA.DiagramObject)dia.DiagramObjects.AddNew(position, "");

            dia.Update();
            diaObject.Style      = "LBL=CX=69:CY=13:OX=-69:OY=0:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;";
            diaObject2.ElementID = interf.ElementID;
            diaObject2.Update();
        }
        private static void ChangeLabel(DiagramObject portObj, string from, string to)
        {
            var style = (string)portObj.Style;

            Match match = Regex.Match(style, from);

            if (match.Success)
            {
                style         = style.Replace(match.Value, to);
                portObj.Style = style;
                portObj.Update();
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Set DiagramObject properties. You can use 'style' and/or 'properties'. 'style' can be 'none' to not use the style.
        /// First set style (overwrite all styles or none) than update styles by properties.
        /// style:      set according to style (overwrite everything)
        /// properties: set the EA properties (only the chosen properties)
        ///
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="diaObject"></param>
        /// <param name="style">Either style or properties</param>
        /// <param name="properties"></param>
        public static void SetDiagramObjectStyle(Repository rep, EA.DiagramObject diaObject, string style, string properties)
        {
            if (!String.IsNullOrEmpty(style))
            {
                // only use style if not 'none'
                if (style.ToLower() != "none")
                {
                    // preserve DUID Diagram Unit Identifier
                    string s     = (string)diaObject.Style;
                    Match  match = Regex.Match(s, @"DUID=[A-Z0-9a-z]+;");
                    string duid  = "";
                    if (match.Success)
                    {
                        duid = match.Groups[0].Value;
                    }

                    s = duid + style.Replace(",", ";").Replace("   ", "").Replace("  ", "")
                        .Replace(" ", "")
                        .Trim();
                    // ensure string ends with ";"
                    if (s.Trim() != "" & (!s.EndsWith(";")))
                    {
                        s = s + ";";
                    }
                    diaObject.Style = s;
                    try
                    {
                        diaObject.Update();
                    }
                    catch (Exception e)
                    {
                        // Probably style is to long to contain all features
                        MessageBox.Show($@"EA has a restriction of the length of the Database field.
{e}
", @"Style is to long, make it shorter!");
                    }
                }
            }

            // always use properties
            if (!String.IsNullOrEmpty(properties))
            {
                // Check if there is a DiagramObject property to use
                properties = properties.Replace(",", ";").Replace("   ", "").Replace("  ", "").Replace(" ", "").Trim();
                foreach (var property in properties.Split(';'))
                {
                    SetDiagramObjectStyle(rep, diaObject, property.Trim());
                }
                diaObject.Update();
            }
        }
Ejemplo n.º 16
0
        //returns
        public static List <string> GetStringListOfElements(Diagram selectedDiagram, Repository m_Repository)
        {
            List <string> ListOfElements = new List <string>();

            for (short iDO = 0; iDO < selectedDiagram.DiagramObjects.Count; iDO++)
            {
                EA.DiagramObject MyDO = (EA.DiagramObject)selectedDiagram.DiagramObjects.GetAt(iDO);
                //ListAdd("       " + m_Repository.GetElementByID(MyDO.ElementID).Name + "   ( ID=" + MyDO.ElementID + " )");
                ListOfElements.Add(m_Repository.GetElementByID(MyDO.ElementID).Name);
            }


            return(ListOfElements);
        }
        private static void DoChangeLabelStyle(DiagramObject portObj, LabelStyle style)
        {
            switch (style)
            {
            case LabelStyle.IsHidden:
                ChangeLabel(portObj, @"HDN=0", "HDN=1");
                break;

            case LabelStyle.IsShown:
                ChangeLabel(portObj, @"HDN=1", "HDN=0");
                break;

            case LabelStyle.PositionLeft:
                ChangeLabel(portObj, @"OX=[\+\-0-9]*", @"OX=-200");
                break;

            case LabelStyle.PositionRight:
                ChangeLabel(portObj, @"OX=[\+\-0-9]*", @"OX=24");
                break;

            case LabelStyle.PositionMinus:
                // get old x position
                Match match = Regex.Match(portObj.Style, @"OX=([\+\-0-9]*)");
                if (match.Success)
                {
                    int xPos = Convert.ToInt32(match.Groups[1].Value) - 15;
                    ChangeLabel(portObj, @"OX=[\+\-0-9]*", String.Format("OX={0}", xPos));
                }
                break;

            case LabelStyle.PositionPlus:
                // get old x position
                match = Regex.Match(portObj.Style, @"OX=([\+\-0-9]*)");
                if (match.Success)
                {
                    int xPos = Convert.ToInt32(match.Groups[1].Value) + 15;
                    ChangeLabel(portObj, @"OX=[\+\-0-9]*", String.Format("OX={0}", xPos));
                }
                break;
            }

            //string style = (string)portObj.Style;
            //if (isHidden) style = style.Replace("HDN=0", "HDN=1");
            //else style = style.Replace("HDN=1", "HDN=0");
            //portObj.Style = style;
        }
Ejemplo n.º 18
0
        private void FixDiagramObjectsSequence(EAAPI.Diagram lifeCycleDiagram, Dictionary <String, EAAPI.Element> elements)
        {
            // Get a list of the diagram elements that are actually on the diagram in the repository.
            String resultString = eaRepo.SQLQuery(
                "Select DO.Diagram_ID, DO.Object_ID, DO.Sequence, O.Alias from t_diagramobjects DO, t_object O where DO.Object_ID = o.Object_ID and DO.Diagram_ID = "
                + lifeCycleDiagram.DiagramID.ToString());
            List <Utility.EA.Sequence.SequenceRow> sequenceRows = Utility.EA.Sequence.DeSerialiseEASQLQueryResult.DeSerialiseAsDiagramRow(resultString);

            EAAPI.DiagramObject             diagramObject = null;
            Utility.EA.Sequence.SequenceRow sequenceRow;
            int nAliasIndex;
            int maxSequence = diagramConfig.Elements.Element.Count();
            int oldSequence;

            // Build a list of aliases
            List <String> elementAliases = new List <string>();

            foreach (Element elementName in diagramConfig.Elements.Element)
            {
                elementAliases.Add(FormatDiagramElementAlias(lifeCycleDiagram.DiagramID, elementName.Name));
            }

            for (int nIndex = 0; nIndex < sequenceRows.Count; nIndex++)
            {
                sequenceRow = sequenceRows[nIndex];

                // Is it one of our aliases?
                if (elementAliases.Contains(sequenceRow.Alias))
                {
                    nAliasIndex            = elementAliases.IndexOf(sequenceRow.Alias);
                    diagramObject          = (EAAPI.DiagramObject)lifeCycleDiagram.GetDiagramObjectByID(SafeToInt(sequenceRow.Object_ID, 0), null);
                    diagramObject.Sequence = maxSequence - nAliasIndex;                     // EA goes backwards putting the last element to draw first.
                    diagramObject.Update();
                }
                else
                {
                    oldSequence = diagramObject.Sequence;
                    if (EA_ELEMENT_NOT_SEQUENCED != oldSequence && oldSequence <= maxSequence)
                    {
                        diagramObject          = (EAAPI.DiagramObject)lifeCycleDiagram.GetDiagramObjectByID(SafeToInt(sequenceRow.Object_ID, 0), null);
                        diagramObject.Sequence = oldSequence + (maxSequence - oldSequence) + 1;                         // EA goes backwards putting the last element to draw first.
                        diagramObject.Update();
                    }
                }
            }
        }
        public void DoChangeLabelGui(LabelStyle style)
        {
            Diagram dia = _rep.GetCurrentDiagram();

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

            _rep.SaveDiagram(dia.DiagramID);

            // target object/element
            Element el;

            // for each selected element
            foreach (DiagramObject obj in dia.SelectedObjects)
            {
                el = _rep.GetElementByID(obj.ElementID);
                if (EmbeddedElementTypes.Contains(el.Type))
                {
                    DiagramObject portObj = Util.GetDiagramObjectById(_rep, dia, el.ElementID);
                    //EA.DiagramObject portObj = dia.GetDiagramObjectByID(el.ElementID, "");
                    DoChangeLabelStyle(portObj, style);
                }
                else
                {   // all element like Class, Component,..
                    foreach (Element p in el.EmbeddedElements)
                    {
                        if (!(EmbeddedElementTypes.Contains(p.Type)))
                        {
                            continue;
                        }
                        DiagramObject portObj = Util.GetDiagramObjectById(_rep, dia, p.ElementID);
                        if (portObj != null)
                        {
                            //EA.DiagramObject portObj = dia.GetDiagramObjectByID(p.ElementID, "");
                            // HDN=1;  Label hidden
                            // HDN=0;  Label visible
                            DoChangeLabelStyle(portObj, style);
                        }
                    }
                }
            }
        }
Ejemplo n.º 20
0
        // subtype=100 init node
        // subtype=101 final node

        public static EA.DiagramObject CreateInitFinalNode(EA.Repository rep, EA.Diagram dia, EA.Element act,
                                                           int subType, string position)
        {
            EA.Element initNode = (EA.Element)act.Elements.AddNew("", "StateNode");
            initNode.Subtype = subType;
            initNode.Update();
            if (dia != null)
            {
                HoUtil.AddSequenceNumber(rep, dia);
                EA.DiagramObject initDiaNode = (EA.DiagramObject)dia.DiagramObjects.AddNew(position, "");
                initDiaNode.ElementID = initNode.ElementID;
                initDiaNode.Sequence  = 1;
                initDiaNode.Update();
                HoUtil.SetSequenceNumber(rep, dia, initDiaNode, "1");
                return(initDiaNode);
            }
            return(null);
        }
        /// <summary>
        /// Change Style of a DiagramObject.
        /// </summary>
        /// <param name="portObj"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        private static void ChangeDiagramObjectStyle(DiagramObject portObj, string from, string to)
        {
            var style = (string)portObj.Style;

            Match match = Regex.Match(style, from);

            if (match.Success)
            {
                style = style.Replace(match.Value, to);
            }
            else // Empty style, just add new style
            {
                style = style.Replace($"{to};", "");// delete possible new value
                style = style + $" {to};";// insert new value
            }
            // update style
            portObj.Style = style;
            portObj.Update();
        }
Ejemplo n.º 22
0
        private void AddElementToDiagram(
            EAAPI.Diagram lifeCycleDiagram, int elementID, String type,
            int left, int right, int top, int bottom, String font, String backgroundColor)
        {
            String size = String.Format("l={0};r={1};t={2};b={3};", left, right, top, bottom);

            EAAPI.DiagramObject obj = (EAAPI.DiagramObject)lifeCycleDiagram.DiagramObjects.AddNew(size, type);

            obj.ElementID = elementID;
            if (!String.IsNullOrEmpty(font))
            {
                obj.Style = obj.Style + ";" + font;
            }
            if (!String.IsNullOrEmpty(backgroundColor))
            {
                obj.Style = obj.Style + ";" + backgroundColor;
            }

            obj.Update();
        }
Ejemplo n.º 23
0
        private void ExecuteSynchronizeReference()
        {
            EAAPI.Diagram diagram = _repository.GetCurrentDiagram();

            if (diagram != null)
            {
                if (diagram.SelectedObjects.Count == 1)
                {
                    EAAPI.DiagramObject diagramObject = (EAAPI.DiagramObject)diagram.SelectedObjects.GetAt(0);

                    EAAPI.Element referenceElement = _repository.GetElementByID(diagramObject.ElementID);

                    ReferenceSynchronizer referenceSynchronizer = new ReferenceSynchronizer(_repository, referenceElement);

                    referenceSynchronizer.SynchronizeReferenceWithOriginal();

                    MessageBox.Show("Synchronization finished.", "Reference Synchronization");
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Create an Activity diagram beneath selected Activity.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="act"></param>
        /// <returns></returns>

        public static Diagram CreateActivityCompositeDiagram(Repository rep, EA.Element act)
        {
            // create activity diagram beneath Activity
            EA.Diagram actDia = (Diagram)act.Diagrams.AddNew(act.Name, "Activity");
            // update diagram properties
            actDia.ShowDetails = 0; // hide details
            // scale page to din A4

            if (actDia.StyleEx.Length > 0)
            {
                actDia.StyleEx = actDia.StyleEx.Replace("HideQuals=0", "HideQuals=1"); // hide qualifier
            }
            else
            {
                actDia.StyleEx = "HideQuals=1;";
            }
            // Hide Qualifier
            if (actDia.ExtendedStyle.Length > 0)
            {
                actDia.ExtendedStyle = actDia.ExtendedStyle.Replace("ScalePI=0", "ScalePI=1");
            }
            else
            {
                actDia.ExtendedStyle = "ScalePI=1;";
            }
            actDia.Update();
            act.Diagrams.Refresh();

            // put the activity on the diagram
            HoUtil.AddSequenceNumber(rep, actDia);
            EA.DiagramObject actObj = (EA.DiagramObject)actDia.DiagramObjects.AddNew("l=30;r=780;t=30;b=1120", "");
            actObj.ElementID = act.ElementID;
            actObj.Update();
            actDia.DiagramObjects.Refresh();

            // add default nodes (init/final)
            CreateDefaultElementsForActivity(rep, actDia, act);
            act.Elements.Refresh();
            actDia.DiagramObjects.Refresh();
            return(actDia);
        }
Ejemplo n.º 25
0
 public DiagramObjectSelected(EA.DiagramObject obj, int position, int left)
 {
     Position = position;
     Obj      = obj;
     Left     = left;
 }
        /// <summary>
        /// Add Element note for diagram Object from:<para/>
        /// Element, Attribute, Operation, Package
        /// 
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="diaObj"></param>
        public static void AddElementNote(Repository rep, DiagramObject diaObj)
        {
            Element el = rep.GetElementByID(diaObj.ElementID);
            if (el != null)
            {
                Diagram dia = rep.GetCurrentDiagram();
                Package pkg = rep.GetPackageByID(el.PackageID);
                if (pkg.IsProtected || dia.IsLocked || el.Locked) return;

                // save diagram;//
                rep.SaveDiagram(dia.DiagramID);

                Element elNote;
                try
                {
                    elNote = (Element) pkg.Elements.AddNew("", "Note");
                    elNote.Update();
                    pkg.Update();
                }
                catch
                {
                    return;
                }

                // add element to diagram
                // "l=200;r=400;t=200;b=600;"

                int left = diaObj.right + 50;
                int right = left + 100;
                int top = diaObj.top;
                int bottom = top - 100;

                string position = "l=" + left + ";r=" + right + ";t=" + top + ";b=" + bottom + ";";
                var diaObject = (DiagramObject) dia.DiagramObjects.AddNew(position, "");
                dia.Update();
                diaObject.ElementID = elNote.ElementID;
                diaObject.Sequence = 1; // put element to top
                diaObject.Update();
                pkg.Elements.Refresh();
                // make a connector
                var con = (Connector) el.Connectors.AddNew("test", "NoteLink");
                con.SupplierID = elNote.ElementID;
                con.Update();
                el.Connectors.Refresh();
                Util.SetElementHasAttchaedLink(rep, el, elNote);
                rep.ReloadDiagram(dia.DiagramID);
            }
           
        }
        private List <Waypoint> CalculateWaypointsForDiagramLink(EAAPI.DiagramLink diagramLink,
                                                                 EAAPI.DiagramObject sourceDiagramObject,
                                                                 EAAPI.DiagramObject targetDiagramObject)
        {
            List <Waypoint> result = new List <Waypoint>();

            int startX;
            int endX;
            int startY;
            int endY;

            List <Point> linkPathPoints = ParseEaLinkPath(diagramLink.Path);

            // horizontal coordinates calculation
            if (linkPathPoints.Count == 0) // direct line
            {
                // horizontal calculation
                // source --> target
                if (sourceDiagramObject.right < targetDiagramObject.left)
                {
                    startX = sourceDiagramObject.right;
                    endX   = targetDiagramObject.left;
                }
                else if (sourceDiagramObject.left > targetDiagramObject.right) // target <-- source
                {
                    startX = sourceDiagramObject.left;
                    endX   = targetDiagramObject.right;
                }
                else
                {
                    startX = sourceDiagramObject.left + (sourceDiagramObject.right - sourceDiagramObject.left) / 2;
                    endX   = startX;
                }
            }
            else // bended line
            {
                // start of path

                // horizontal calculation
                // source --> target
                if (sourceDiagramObject.right < linkPathPoints[0].X)
                {
                    startX = sourceDiagramObject.right;
                }
                else if (sourceDiagramObject.left > linkPathPoints[0].X) // target <-- source
                {
                    startX = sourceDiagramObject.left;
                }
                else
                {
                    startX = linkPathPoints[0].X;
                }

                // end of path

                // horizontal calculation
                // target <-- last path
                if (targetDiagramObject.right < linkPathPoints[linkPathPoints.Count - 1].X)
                {
                    endX = targetDiagramObject.right;
                }
                else if (targetDiagramObject.left > linkPathPoints[linkPathPoints.Count - 1].X) // target --> last path
                {
                    endX = targetDiagramObject.left;
                }
                else
                {
                    endX = linkPathPoints[linkPathPoints.Count - 1].X;
                }
            }

            // vertical coordinates calculation
            if (linkPathPoints.Count == 0)
            {
                // vertical calculation
                // source above target, vertical
                if (-sourceDiagramObject.bottom < -targetDiagramObject.top)
                {
                    startY = -sourceDiagramObject.bottom;
                    endY   = -targetDiagramObject.top;
                }
                // source below target, vertival
                else if (-sourceDiagramObject.top > -targetDiagramObject.bottom)
                {
                    startY = -sourceDiagramObject.top;
                    endY   = -targetDiagramObject.bottom;
                }
                else
                {
                    startY = -sourceDiagramObject.top + (-sourceDiagramObject.bottom + sourceDiagramObject.top) / 2;
                    endY   = startY;
                }
            }
            else
            {
                // source above target, vertical
                if (-sourceDiagramObject.bottom < linkPathPoints[0].Y)
                {
                    startY = -sourceDiagramObject.bottom;
                }
                // source below target, vertival
                else if (-sourceDiagramObject.top > linkPathPoints[0].Y)
                {
                    startY = -sourceDiagramObject.top;
                }
                else
                {
                    startY = linkPathPoints[0].Y; // -sourceDiagramObject.top + (-sourceDiagramObject.bottom + sourceDiagramObject.top) / 2;
                }

                // source above target, vertical
                if (-targetDiagramObject.top > linkPathPoints[linkPathPoints.Count - 1].Y)
                {
                    endY = -targetDiagramObject.top;
                }
                // source below target, vertival
                else if (-targetDiagramObject.bottom < linkPathPoints[linkPathPoints.Count - 1].Y)
                {
                    endY = -targetDiagramObject.bottom;
                }
                else
                {
                    endY = linkPathPoints[linkPathPoints.Count - 1].Y; //-targetDiagramObject.top + (-targetDiagramObject.bottom + targetDiagramObject.top) / 2;
                }
            }

            result.Add(new Waypoint
            {
                X = startX,
                Y = startY
            });

            foreach (Point bendPoint in linkPathPoints)
            {
                result.Add(new Waypoint
                {
                    X = bendPoint.X,
                    Y = bendPoint.Y
                });
            }

            result.Add(new Waypoint
            {
                X = endX,
                Y = endY
            });


            return(result);
        }
Ejemplo n.º 28
0
        private EA.Element createNewCorrespondenceLink(EA.Package tggOutermostePackage, out EA.Connector connectorToSource, out EA.Connector connectorToTarget)
        {
            EA.Element tggLink = tggOutermostePackage.Elements.AddNew(textBoxLinkName.Text, Main.EAClassType) as EA.Element;
            tggLink.StereotypeEx = TGGModelingMain.TggCorrespondenceTypeStereotype;
            tggLink.Update();

            TGGCorrespondenceType correspondenceType = new TGGCorrespondenceType(sqlRepository.GetElementByID(tggLink.ElementID), sqlRepository);

            correspondenceType.saveTreeToEATaggedValue(false);

            connectorToSource                         = tggLink.Connectors.AddNew("", ECOREModelingMain.EReferenceConnectorType) as EA.Connector;
            connectorToSource.SupplierID              = clientClassifier.ElementID;
            connectorToSource.Direction               = Main.EASourceTargetDirection;
            connectorToSource.SupplierEnd.Role        = "source";
            connectorToSource.SupplierEnd.Navigable   = "Navigable";
            connectorToSource.SupplierEnd.Cardinality = "1";
            connectorToSource.SupplierEnd.IsNavigable = true;

            connectorToSource.Update();

            EReference refToSource = new EReference(sqlRepository.GetConnectorByID(connectorToSource.ConnectorID), sqlRepository);

            refToSource.saveTreeToEATaggedValue(true);


            tggLink.Connectors.Refresh();

            connectorToTarget                         = tggLink.Connectors.AddNew("", ECOREModelingMain.EReferenceConnectorType) as EA.Connector;
            connectorToTarget.SupplierID              = supplierClassifier.ElementID;
            connectorToTarget.Direction               = Main.EASourceTargetDirection;
            connectorToTarget.SupplierEnd.Role        = "target";
            connectorToTarget.SupplierEnd.Cardinality = "1";
            connectorToTarget.SupplierEnd.Navigable   = "Navigable";
            connectorToTarget.SupplierEnd.IsNavigable = true;

            connectorToTarget.Update();

            EReference refToTarget = new EReference(sqlRepository.GetConnectorByID(connectorToTarget.ConnectorID), sqlRepository);

            refToTarget.saveTreeToEATaggedValue(true);

            selectedCorrespondenceLinkId = tggLink.ElementID;

            EA.Diagram       curDiagram    = null;
            EA.DiagramObject sourceDiagObj = null;
            EA.DiagramObject targetDiagObj = null;
            foreach (EA.Diagram diag in tggOutermostePackage.Diagrams)
            {
                foreach (EA.DiagramObject diagObj in diag.DiagramObjects)
                {
                    if (diagObj.ElementID == clientClassifier.ElementID)
                    {
                        sourceDiagObj = diagObj;
                    }
                    else if (diagObj.ElementID == supplierClassifier.ElementID)
                    {
                        targetDiagObj = diagObj;
                    }

                    if (sourceDiagObj != null && targetDiagObj != null)
                    {
                        curDiagram = diag;
                    }
                }
            }

            if (curDiagram != null)
            {
                sqlRepository.SaveDiagram(curDiagram.DiagramID);
                int sourceLeft   = (sourceDiagObj == null) ? 0 : sourceDiagObj.left;
                int sourceRight  = (sourceDiagObj == null) ? 0 : sourceDiagObj.right;
                int sourceBottom = (sourceDiagObj == null) ? 0 : sourceDiagObj.bottom;
                int sourceTop    = (sourceDiagObj == null) ? 0 : sourceDiagObj.top;

                int targetLeft   = (targetDiagObj == null) ? 0 : targetDiagObj.left;
                int targetRight  = (targetDiagObj == null) ? 0 : targetDiagObj.right;
                int targetBottom = (targetDiagObj == null) ? 0 : targetDiagObj.bottom;
                int targetTop    = (targetDiagObj == null) ? 0 : targetDiagObj.top;

                EA.DiagramObject tggLinkDiagObj = curDiagram.DiagramObjects.AddNew("", "") as EA.DiagramObject;
                tggLinkDiagObj.ElementID = tggLink.ElementID;
                tggLinkDiagObj.Update();
                tggLinkDiagObj.left   = (sourceLeft + targetLeft) / 2;
                tggLinkDiagObj.right  = (sourceRight + targetRight) / 2;
                tggLinkDiagObj.bottom = (sourceBottom + targetBottom) / 2;
                tggLinkDiagObj.top    = (sourceTop + targetTop) / 2;
                tggLinkDiagObj.Update();
                curDiagram.DiagramObjects.Refresh();

                sqlRepository.ReloadDiagram(curDiagram.DiagramID);

                tggOutermostePackage.Elements.Refresh();
            }
            return(tggLink);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Set Ea Diagram Object Style according to properties passed in the form 'properyName=propertyValue'
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="diaObj"></param>
        /// <param name="style"></param>
        private static void SetDiagramObjectStyle(Repository rep, EA.DiagramObject diaObj, string style)
        {
            // extract name and value
            Match match = Regex.Match(style, $@"(\w+)=(\w+)");

            if (!match.Success)
            {
                MessageBox.Show($"PropertyStyle='{style}', should be 'Property=xxxx;'",
                                "Invalid Property DiagramObject Style");
                return;
            }
            if (match.Groups.Count != 3)
            {
                MessageBox.Show($"PropertyStyle='{style}', should be 'Property=xxxx;'",
                                "Invalid Property DiagramObject Style");
                return;
            }


            string propertyName  = match.Groups[1].Value;
            string propertyValue = match.Groups[2].Value;
            string propertyTyp;

            var propertyInfo = diaObj.GetType().GetProperty(propertyName);

            if (propertyInfo == null)
            {
                // don't know why it doesn't work
                propertyTyp = "Boolean";
                //MessageBox.Show($"PropertyStyle='{style}'",
                //    $@"No valid DiagramObject Property '{propertyName}'");
                //return;
            }
            else
            {
                propertyTyp = propertyInfo.PropertyType.Name;
                if (!(propertyTyp == "Boolean" ||
                      propertyTyp == "String" ||
                      propertyTyp == "Int32"))
                {
                    // Most things works well with Int32
                    propertyTyp = "Int32";
                    //return;
                }
            }



            try
            {
                switch (propertyTyp)
                {
                case "Boolean":
                    bool boolProperty;
                    if (!bool.TryParse(propertyValue, out boolProperty))
                    {
                        MessageBox.Show($"Property='{propertyValue}', should be Bool",
                                        "Property DiagramObject Style isn't Bool");
                        return;
                    }
                    // Com.SetProperty(diaObj, propertyName, boolProperty);
                    switch (propertyName)
                    {
                    case "FontBold":
                        diaObj.FontBold = boolProperty;
                        break;

                    case "FontItalic":
                        diaObj.FontItalic = boolProperty;
                        break;

                    case "FontUnderline":
                        diaObj.FontUnderline = boolProperty;
                        break;

                    case "IsSelectable":
                        diaObj.IsSelectable = boolProperty;
                        break;

                    case "ShowConstraints":
                        diaObj.ShowConstraints = boolProperty;
                        break;

                    case "ShowFormattedNotes":
                        diaObj.ShowFormattedNotes = boolProperty;
                        break;

                    case "ShowFullyQualifiedTags":
                        diaObj.ShowFullyQualifiedTags = boolProperty;
                        break;

                    case "ShowInheritedAttributes":
                        diaObj.ShowInheritedAttributes = boolProperty;
                        break;

                    case "ShowInheritedConstraints":
                        diaObj.ShowInheritedConstraints = boolProperty;
                        break;

                    case "ShowInheritedOperations":
                        diaObj.ShowInheritedOperations = boolProperty;
                        break;

                    case "ShowInheritedResponsibilities":
                        diaObj.ShowInheritedResponsibilities = boolProperty;
                        break;

                    case "ShowInheritedTags":
                        diaObj.ShowInheritedTags = boolProperty;
                        break;

                    case "ShowNotes":
                        diaObj.ShowNotes = boolProperty;
                        break;

                    case "ShowPortType":
                        diaObj.ShowPortType = boolProperty;
                        break;

                    case "ShowPrivateAttributes":
                        diaObj.ShowPrivateAttributes = boolProperty;
                        break;

                    case "ShowPublicAttributes":
                        diaObj.ShowPublicAttributes = boolProperty;
                        break;

                    case "ShowProtectedAttributes":
                        diaObj.ShowProtectedAttributes = boolProperty;
                        break;

                    case "ShowPrivateOperations":
                        diaObj.ShowPrivateOperations = boolProperty;
                        break;

                    case "ShowPublicOperations":
                        diaObj.ShowPublicOperations = boolProperty;
                        break;

                    case "ShowProtectedOperations":
                        diaObj.ShowProtectedOperations = boolProperty;
                        break;

                    case "ShowPackageOperations":
                        diaObj.ShowPackageOperations = boolProperty;
                        break;

                    case "ShowPackageAttributes":
                        diaObj.ShowPackageAttributes = boolProperty;
                        break;

                    case "ShowResponsibilities":
                        diaObj.ShowResponsibilities = boolProperty;
                        break;

                    case "ShowRunstates":
                        diaObj.ShowRunstates = boolProperty;
                        break;

                    case "ShowStructuredCompartments":
                        diaObj.ShowStructuredCompartments = boolProperty;
                        break;

                    case "ShowTags":
                        diaObj.ShowTags = boolProperty;
                        break;

                    default:
                        MessageBox.Show($"Style={style}'\r\nProperty:'{propertyName}'", $@"Invalid DiagramObjectStyle '{propertyName}'");
                        break;
                    }

                    break;

                case "Int32":
                    int int32Property;
                    if (!Int32.TryParse(propertyValue, out int32Property))
                    {
                        MessageBox.Show($"Property='{propertyValue}', should be Integer (int32, long)",
                                        "Property DiagramObject Style isn't Integer");
                        return;
                    }
                    Com.SetProperty(diaObj, propertyName, int32Property);
                    //diaObj.GetType().InvokeMember(propertyName, System.Reflection.BindingFlags.SetProperty, null, diaObj, new object[] { int32Property });
                    break;

                case "String":
                    Com.SetProperty(diaObj, propertyName, propertyValue);
                    //diaObj.GetType().InvokeMember(propertyName, System.Reflection.BindingFlags.SetProperty, null, diaObj, new object[] {propertyValue});
                    break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show($"Property: '{style}'\r\n{e}", $@"Error from EA DiagramObject API '{propertyName}:{propertyTyp}");
            }
        }
        private static void ChangeLabel(DiagramObject portObj, string from, string to)
        {
            var style = (string)portObj.Style;

            Match match = Regex.Match(style, from);
            if (match.Success)
            {
                style = style.Replace(match.Value, to);
                portObj.Style = style;
                portObj.Update();
            }
        }
        /// <summary>
        /// Create Activity for operation
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="m"></param>
        /// <param name="treePos"></param>
        /// <param name="pkgSrc"></param>
        /// <param name="elClass"></param>
        private static void CreateActivityFromOperation(Repository rep, Method m, int treePos, EA.Package pkgSrc, EA.Element elClass)
        {
            // create a package with the name of the operation
            EA.Package pkgTrg = (EA.Package)pkgSrc.Packages.AddNew(m.Name, "");
            pkgTrg.TreePos = treePos;
            pkgTrg.Update();
            pkgSrc.Packages.Refresh();

            EA.Element frm = null; // frame beneath package
            if (ActivityIsSimple == false)
            {
                // create Class Activity Diagram in target package
                EA.Diagram pkgActDia = (EA.Diagram)pkgTrg.Diagrams.AddNew("Operation:" + m.Name + " Content", "Activity");
                pkgActDia.Update();
                pkgTrg.Diagrams.Refresh();
                // prevent information loss
                Util.SetDiagramStyleFitToPage(pkgActDia); // after save diagram!

                // add frame in Activity diagram
                EA.DiagramObject frmObj = (EA.DiagramObject)pkgActDia.DiagramObjects.AddNew("l=100;r=400;t=25;b=50", "");
                frm = (EA.Element)pkgTrg.Elements.AddNew(m.Name, "UMLDiagram");
                frm.Update();
                frmObj.ElementID = frm.ElementID;
                //frmObj.Style = "fontsz=200;pitch=34;DUID=265D32D5;font=Arial Narrow;bold=0;italic=0;ul=0;charset=0;";
                frmObj.Update();
                pkgTrg.Elements.Refresh();
                pkgActDia.DiagramObjects.Refresh();
            }

            // create activity with the name of the operation
            EA.Element act = (EA.Element)pkgTrg.Elements.AddNew(m.Name, "Activity");
            if (ActivityIsSimple == false)
            {
                act.Notes = "Generated from Operation:\r\n" + m.Visibility + " " + m.Name + ":" + m.ReturnType +
                            ";\r\nDetails see Operation definition!!";
            }

            act.StereotypeEx = m.StereotypeEx;
            act.Update();
            pkgTrg.Elements.Refresh();

            // create activity diagram beneath Activity
            EA.Diagram actDia = (EA.Diagram)act.Diagrams.AddNew(m.Name, "Activity");
            // update diagram properties
            actDia.ShowDetails = 0; // hide details
            // scale page to din A4

            if (actDia.StyleEx.Length > 0)
            {
                actDia.StyleEx = actDia.StyleEx.Replace("HideQuals=0", "HideQuals=1"); // hide qualifier
            }
            else
            {
                actDia.StyleEx = "HideQuals=1;";
            }

            // Hide Qualifier
            if (actDia.ExtendedStyle.Length > 0)
            {
                actDia.ExtendedStyle = actDia.ExtendedStyle.Replace("ScalePI=0", "ScalePI=1");
            }
            else
            {
                actDia.ExtendedStyle = "ScalePI=1;";
            }

            actDia.Update();
            act.Diagrams.Refresh();


            // put the activity on the diagram
            Util.AddSequenceNumber(rep, actDia);
            EA.DiagramObject actObj = (EA.DiagramObject)actDia.DiagramObjects.AddNew("l=30;r=780;t=30;b=1120", "");
            actObj.ElementID = act.ElementID;
            actObj.Sequence  = 1;
            actObj.Update();
            Util.SetSequenceNumber(rep, actDia, actObj, "1");
            actDia.DiagramObjects.Refresh();

            // add default nodes (init/final)
            CreateDefaultElementsForActivity(rep, actDia, act);

            if (ActivityIsSimple == false)
            {
                // Add Heading to diagram
                Util.AddSequenceNumber(rep, actDia);
                EA.DiagramObject noteObj = (EA.DiagramObject)actDia.DiagramObjects.AddNew("l=40;r=700;t=25;b=50", "");
                EA.Element       note    = (EA.Element)pkgTrg.Elements.AddNew("Text", "Text");

                note.Notes = m.Visibility + " " + elClass.Name + "_" + m.Name + ":" + m.ReturnType;
                note.Update();
                noteObj.ElementID = note.ElementID;
                noteObj.Style     = "fontsz=200;pitch=34;DUID=265D32D5;font=Arial Narrow;bold=0;italic=0;ul=0;charset=0;";
                noteObj.Sequence  = 1;
                noteObj.Update();
                Util.SetSequenceNumber(rep, actDia, noteObj, "1");
            }

            pkgTrg.Elements.Refresh();
            actDia.DiagramObjects.Refresh();


            // Link Operation to activity
            Util.SetBehaviorForOperation(rep, m, act);

            // Set show behavior
            Util.SetShowBehaviorInDiagram(rep, m);

            // add parameters to activity
            UpdateParameterFromOperation(rep, act, m);
            int pos = 0;

            foreach (EA.Element actPar in act.EmbeddedElements)
            {
                if (!actPar.Type.Equals("ActivityParameter"))
                {
                    continue;
                }
                Util.VisualizePortForDiagramobject(rep, pos, actDia, actObj, actPar, null);
                pos = pos + 1;
            }

            if (ActivityIsSimple == false)
            {
                // link Overview frame to diagram
                Util.SetFrameLinksToDiagram(rep, frm, actDia);
                frm.Update();
            }

            // select operation
            rep.ShowInProjectView(m);
        }
        static void AddInterfaceToElement(Repository rep, int pos, Element elSource, Element elTarget, Diagram dia,
            DiagramObject diaObjSource)
        {
            // check if interface already exists on diagram

            var diaObjTarget = Util.GetDiagramObjectById(rep, dia, elTarget.ElementID);
            //diaObjTarget = dia.GetDiagramObjectByID(elTarget.ElementID, "");
            if (diaObjTarget == null)
            {
                int length = 250;
                //if (elTarget.Type != "Interface") length = 250;
                // calculate target position
                // int left = diaObjSource.right - 75;
                int left = diaObjSource.right;
                int right = left + length;
                int top = diaObjSource.bottom - 25;

                top = top - 20 - pos*70;
                var bottom = top - 50;
                string position = "l=" + left + ";r=" + right + ";t=" + top + ";b=" + bottom + ";";


                // create target diagram object
                diaObjTarget = (DiagramObject) dia.DiagramObjects.AddNew(position, "");

                diaObjTarget.ElementID = elTarget.ElementID;
                diaObjTarget.Sequence = 1;
                // suppress attributes/operations
                diaObjTarget.Style =
                    "DUID=1263D775;AttPro=0;AttPri=0;AttPub=0;AttPkg=0;AttCustom=0;OpCustom=0;PType=0;RzO=1;OpPro=0;OpPri=0;OpPub=0;OpPkg=0;";
                diaObjTarget.Update();
            }
            // connect source to target by Usage

            // make a connector/ or link if notes
            // check if connector already exists
            Connector con;
            foreach (Connector c in elSource.Connectors)
            {
                if (c.SupplierID == elTarget.ElementID &
                    (c.Type == "Usage" | c.Stereotype == "use" |
                     c.Type == "Realisation")) return;
            }


            if (elTarget.Type.Equals("Interface"))
            {
                con = (Connector) elSource.Connectors.AddNew("", "Usage");
            }
            else
            {
                con = (Connector) elSource.Connectors.AddNew("", "NoteLink");
            }
            con.SupplierID = elTarget.ElementID;
            try
            {
                con.Update();
                elSource.Connectors.Refresh();
                elTarget.Connectors.Refresh();
                // set line style
                dia.DiagramLinks.Refresh();
                //rep.ReloadDiagram(dia.DiagramID);
                foreach (DiagramLink link in dia.DiagramLinks)
                {
                    if (link.ConnectorID == con.ConnectorID)
                    {
                        Util.SetLineStyleForDiagramLink("LV", link);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), $"Error create connector between '{elSource.Name}  and '{elTarget.Name}' ");
            }
        }
 public DiagramObjectStyle(EA.Repository rep, EA.DiagramObject diaObj, string type, string style, string property)
     : base(rep, type, style, property)
 {
     _diaObj = diaObj;
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Get the current Diagram with it's selected objects and connectors.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="getAllDiagramObject">True if you want all diagram objects if nothing no diagram object is selected</param>
        public EaDiagram(Repository rep, bool getAllDiagramObject = false)
        {
            _rep = rep;
            _selectedConnector = null;
            IsSelectedObjects  = false;

            _dia = rep.GetCurrentDiagram();
            // Nothing selected
            if (_dia == null || (_dia.SelectedConnector == null && _dia.SelectedObjects.Count == 0))
            {
                GetTreeSelected();
                return;
            }

            EA.ObjectType contextObjectType = Rep.GetContextItemType();


            // Check if context is diagram or something inside the current diagram is selected (selected things are never old)
            if (contextObjectType != ObjectType.otDiagram && _dia.SelectedObjects.Count == 0 &&
                _dia.SelectedConnector == null)
            {
                return;
            }


            // Diagram is context or something inside the diagram is selected
            IsSelectedObjects = false;
            if (_dia.SelectedObjects.Count == 0 && getAllDiagramObject)
            {
                // overall diagram objects
                foreach (EA.DiagramObject obj in _dia.DiagramObjects)
                {
                    _selectedObjects.Add(obj);
                    SelElements.Add(rep.GetElementByID(obj.ElementID));
                }
            }
            // If an context element exists than this is the last selected element
            if (_dia.SelectedObjects.Count > 0)
            {
                // The context item isn't always set, try to estimate it
                if (contextObjectType == EA.ObjectType.otElement ||
                    contextObjectType == EA.ObjectType.otPackage ||
                    contextObjectType == EA.ObjectType.otNone ||
                    contextObjectType == EA.ObjectType.otDiagram
                    )
                {
                    // 1. store context element/ last selected element
                    // Context Element may be a Package. EA also stores the package as Element
                    EA.Element elContext = null;
                    switch (rep.GetContextItemType())
                    {
                    case EA.ObjectType.otElement:
                        elContext = (EA.Element)rep.GetContextObject();
                        break;

                    case EA.ObjectType.otPackage:
                        var pkg = (EA.Package)rep.GetContextObject();
                        elContext = rep.GetElementByGuid(pkg.PackageGUID);
                        break;
                    }

                    // no context element available, take first element
                    if (elContext == null)
                    {
                        EA.DiagramObject obj = (EA.DiagramObject)_dia.SelectedObjects.GetAt(0);
                        elContext = rep.GetElementByID(obj.ElementID);
                    }
                    _conTextDiagramObject = _dia.GetDiagramObjectByID(elContext.ElementID, "");

                    SelElements.Add(elContext);
                    _selectedObjects.Add(_conTextDiagramObject);
                    IsSelectedObjects = true;

                    // over all selected diagram objects
                    foreach (EA.DiagramObject obj in _dia.SelectedObjects)
                    {
                        // skip last selected element / context element
                        if (_conTextDiagramObject != null && obj.ElementID == _conTextDiagramObject.ElementID)
                        {
                            continue;
                        }

                        _selectedObjects.Add(obj);
                        SelElements.Add(rep.GetElementByID(obj.ElementID));
                    }
                }
            }
            _selectedConnector = _dia.SelectedConnector;
        }