/// <summary>
        /// Gets the current dependencies of the package.
        /// </summary>
        /// <param name="package">The package.</param>
        /// <returns>a list of the current package dependencies</returns>
        private static DependingPackageList CurrentDependencies(Package package)
        {
            ProgressInfo.Info = Resources.stateListConnectors;
            DependingPackageList dpList     = new DependingPackageList();
            List <Connector>     connectors = Manipulation.GetAllPackageConnectors(package);

            ProgressInfo.Reset(Resources.stateSearchCurDep, 0, connectors.Count);

            foreach (Connector connector in connectors)
            {
                ProgressInfo.Next();
                if (connector.Stereotype.Equals(appSettings.Stereotype))
                {
                    Element clientPackage   = pRepository.GetElementByID(connector.ClientID);
                    Element supplierPackage = pRepository.GetElementByID(connector.SupplierID);

                    //string client = connector.ClientID.ToString();
                    //string supplier = connector.SupplierID.ToString();

                    if ((supplierPackage != null) && (clientPackage != null))
                    {
                        if (clientPackage.ElementID != supplierPackage.ElementID)
                        {
                            if (!dpList.IsInList(supplierPackage.ElementID, clientPackage.ElementID))
                            {
                                dpList.AddNew(supplierPackage, clientPackage, connector.Direction, connector);
                            }
                        }
                    }
                }
            }
            ProgressInfo.Reset();
            return(dpList);
        }
 public EAElementWrapper(EA.Connector con, Repository repository)
 {
     EA.Element client   = repository.GetElementByID(con.ClientID);
     EA.Element supplier = repository.GetElementByID(con.SupplierID);
     this.name       = con.Name + "(from: " + client.Name + " to: " + supplier.Name + ")";
     this.stereotype = con.Stereotype;
     this.type       = con.Type;
 }
        private void AddConnectors(Package model)
        {
            var ccLibrary          = (Package)model.Packages.GetByName("CCLibrary");
            var existingConnectors = new Dictionary <int, List <int> >();

            foreach (Element element in ccLibrary.Elements)
            {
                List <Element> originalElements = GetClassElementsByName(element.Name,
                                                                         (Package)model.Packages.GetByName("Class"),
                                                                         new List <Element>());
                foreach (Element originalElement in originalElements)
                {
                    foreach (Connector originalConnector in originalElement.Connectors)
                    {
                        Element targetElement =
                            GetClassElementsByName(_eaRepo.GetElementByID(originalConnector.SupplierID).Name,
                                                   ccLibrary, new List <Element>())[0];
                        Element sourceElement =
                            GetClassElementsByName(_eaRepo.GetElementByID(originalConnector.ClientID).Name,
                                                   ccLibrary, new List <Element>())[0];

                        List <int> output;
                        existingConnectors.TryGetValue(sourceElement.ElementID, out output);
                        if (output == null)
                        {
                            output = new List <int>();
                            var connector =
                                (Connector)
                                ccLibrary.Connectors.AddNew(originalConnector.Name, originalConnector.Type);
                            connector.StereotypeEx = originalConnector.Stereotype;
                            connector.Stereotype   = "ASCC";
                            connector.ClientID     = sourceElement.ElementID;
                            connector.SupplierID   = targetElement.ElementID;
                            output.Add(targetElement.ElementID);
                            existingConnectors.Add(sourceElement.ElementID, output);
                            connector.Update();
                        }
                        else
                        {
                            if (!output.Contains(targetElement.ElementID))
                            {
                                var connector =
                                    (Connector)
                                    ccLibrary.Connectors.AddNew(originalConnector.Name, originalConnector.Type);
                                connector.StereotypeEx = originalConnector.Stereotype;
                                connector.Stereotype   = "ASCC";
                                connector.ClientID     = sourceElement.ElementID;
                                connector.SupplierID   = targetElement.ElementID;
                                output.Add(targetElement.ElementID);
                                existingConnectors[sourceElement.ElementID] = output;
                                connector.Update();
                            }
                        }
                    }
                    element.Connectors.Refresh();
                }
            }
        }
        /// <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;
        }
 private void CopyConnectors()
 {
     foreach (Connector sourceConnector in connectors)
     {
         Element targetClient   = targetRepository.GetElementByID(elementMapping[sourceConnector.ClientID]);
         Element targetSupplier = targetRepository.GetElementByID(elementMapping[sourceConnector.SupplierID]);
         CopyConnector(sourceConnector, targetClient.Connectors, targetClient.ElementID, targetSupplier.ElementID);
         targetClient.Connectors.Refresh();
     }
 }
        public int DoCopyPortsGui()
        {
            Diagram dia = _rep.GetCurrentDiagram();

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

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

            // target object/element
            var trgEl = (Element)_rep.GetContextObject();

            if (trgEl.Type != "Class" && trgEl.Type != "Component")
            {
                MessageBox.Show($"Target Element is '{trgEl.Type}'", @"Target element for copy Port has to be Class or Component");
                return(0);
            }

            // over all selected DiagramObjects
            for (int i = 0; i < count; i = i + 1)
            {
                var srcObj = (DiagramObject)dia.SelectedObjects.GetAt((short)i);
                var srcEl  = _rep.GetElementByID(srcObj.ElementID);
                if (srcEl.ElementID == trgEl.ElementID)
                {
                    continue;
                }

                if (srcEl.Type == "Port")
                {
                    // selected element was port
                    CopyPort(_rep, srcEl, trgEl);
                    _count += 1;
                }
                else
                {   // selected element was "Port"
                    foreach (Element p in srcEl.EmbeddedElements)
                    {
                        if (srcEl.ElementID == trgEl.ElementID)
                        {
                            continue;
                        }
                        if (p.Type == "Port")
                        {
                            CopyPort(_rep, p, trgEl);
                            _count += 1;
                        }
                    }
                }
            }
            return(_count);
            //_rep.ReloadDiagram(dia.DiagramID);
        }
Example #7
0
        private int ZmielElement(Element jaElem)
        {
            int wynik = 0;

            //ZmielElement(rodzicPckg,jaElem
            foreach (Element e in jaElem.Elements)
            {
                wynik += ZmielElement(e);
            }
            //mielenie
            //daj wszystkie konektory
            foreach (Connector c in jaElem.Connectors)
            {
                ////dla kazdego konektora typu information flow daj source
                if (c.Type != "InformationFlow")
                {
                    continue;
                }
                ////dla kazdego konektora daj destination
                Element elSource      = Repo.GetElementByID(c.ClientID);
                Element elDestination = Repo.GetElementByID(c.SupplierID);
                //patrz tylko na te ktorych realizatorem jest jaElem
                if (jaElem.ElementID == elDestination.ElementID)
                {
                    //wez interfejs lub go dodaj
                    Element interf = EAUtils.dodajElement(ref jaElem, "Interfejs " + jaElem.Name, "", "Interface");

                    ////do interfejsu dodaj operację (nazwa to fid, notatka to notatka, parametr to nazwa systemu target)
                    EA.Method m = EAUtils.dodajOperacje(ref interf, c.Name, c.Notes);
                    try{
                        m.Parameters.AddNew(elSource.Name, "");
                        m.Update();
                        m.Parameters.Refresh();
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + "( " + System.Reflection.MethodBase.GetCurrentMethod().Attributes.ToString() + ") #" + exc.Message);
                    }
                    ////utworz relacje use z source do interfejs
                    Connector conUse = EAUtils.dodajRelacje(elSource, interf, "Usage", "", "");
                    ////utworz relacje realize z destination do interfejs
                    Connector conReal = EAUtils.dodajRelacje(elSource, interf, "Realisation", "", "");

                    wynik++;
                }
            }
            return(wynik);
        }
 /// <summary>
 /// Return true if Element is an Embedded Element Type. With the parameter
 /// 'alsoEmbeddedInterfaces' you can decide whether to use Required/Provide -Interface as embedded element
 /// - Port
 /// - Activity Parameter
 /// - Parameter
 /// - ExpansionNode
 /// - Pin
 /// - RequiredInterface Only if alsoEmbeddedInterfaces=true
 /// - ProvidedInterface Only if alsoEmbeddedInterfaces=true
 /// </summary>
 /// <param name="el"></param>
 /// <param name="rep"></param>
 /// <param name="alsoEmbeddedInterfaces">Handle Provided, Required Interface as Embedded</param>
 /// <returns>EA Version</returns>
 // ReSharper disable once UnusedMember.Global
 public static bool IsEmbeddedElement(this EA.Element el, Repository rep, bool alsoEmbeddedInterfaces = false)
 {
     if (el.ParentID == 0)
     {
         return(false);
     }
     if (alsoEmbeddedInterfaces)
     {
         return(el.Type == "Port" ||
                el.Type == "ActivityParameter" ||
                el.Type == "Parameter" ||
                el.Type == "ExpansionNode" ||
                el.Type == "ActionPin" ||
                el.Type == "RequiredInterface" ||
                el.Type == "ProvidedInterface");
     }
     else
     {
         if (el.Type == "ExpansionNode" && rep != null)
         {
             EA.Element elAction = rep.GetElementByID(el.ParentID);
             if (elAction.Type == "Action")
             {
                 return(false);
             }
         }
         return(el.Type == "Port" ||
                el.Type == "ActivityParameter" ||
                el.Type == "Parameter" ||
                el.Type == "ExpansionNode" ||
                el.Type == "ActionPin");
     }
 }
Example #9
0
        public override MocaNode serializeToMocaTree(MocaNode actNode)
        {
            MocaNode dummyNode = null;

            EcoreUtil.computeLowerUpperBound(ConnectorEnd.getRealConnectorEnd().Cardinality, ref lowerBound, ref upperBound);

            if (ConnectorEnd.getRealConnectorEnd().End == "Client")
            {
                dummyNode = actNode.appendChildNode("ClientReference");

                SQLElement clientEClass = Repository.GetElementByID(this.EaConnector.getRealConnector().ClientID);
                typeGUID = clientEClass.ElementGUID;
                refGUID  = this.EaConnector.getRealConnector().ConnectorGUID + "Client";
                if (this.EaConnector.getRealConnector().SupplierEnd.Role != "")
                {
                    oppositeGUID = this.EaConnector.getRealConnector().ConnectorGUID + "Supplier";
                }


                containment = this.EaConnector.getRealConnector().SupplierEnd.Aggregation == 2;
            }

            else if (ConnectorEnd.getRealConnectorEnd().End == "Supplier")
            {
                dummyNode = actNode.appendChildNode("SupplierReference");
                SQLElement supplierEClass = Repository.GetElementByID(this.EaConnector.getRealConnector().SupplierID);
                typeGUID = supplierEClass.ElementGUID;
                refGUID  = this.EaConnector.getRealConnector().ConnectorGUID + "Supplier";
                if (this.EaConnector.getRealConnector().ClientEnd.Role != "")
                {
                    oppositeGUID = this.EaConnector.getRealConnector().ConnectorGUID + "Client";
                }


                containment = this.EaConnector.getRealConnector().ClientEnd.Aggregation == 2;
            }

            if (Navigable)
            {
                MocaNode ereferenceNode = dummyNode.appendChildNode("EReference");
                ereferenceNode.appendChildAttribute("typeGuid", typeGUID);
                if ((ConnectorEnd.Role == "" || ConnectorEnd.getRealConnectorEnd().Role == null))
                {
                    ereferenceNode.appendChildAttribute("name", this.Name);
                }
                else
                {
                    ereferenceNode.appendChildAttribute("name", ConnectorEnd.getRealConnectorEnd().Role);
                }
                ereferenceNode.appendChildAttribute(Main.GuidStringName, refGUID);
                ereferenceNode.appendChildAttribute("lowerBound", lowerBound);
                ereferenceNode.appendChildAttribute("upperBound", upperBound);
                ereferenceNode.appendChildAttribute("containment", (containment + "").ToLower());
                if (oppositeGUID != "")
                {
                    ereferenceNode.appendChildAttribute("oppositeGuid", oppositeGUID);
                }
            }
            return(dummyNode);
        }
Example #10
0
        /// <summary>
        /// This method takes an Listener (a logging table filled by a trigger), gets the updates and refreshes the affected views.
        /// </summary>
        /// <param name="syncTable"></param>
        private void sync(TableAdapter syncTable)
        {
            List <String> updates = syncTable.getUpdates();

            foreach (String update in updates)
            {
                // FIXME: Different Objects for packages, connectors, etc.?
                Element e = null;

                try
                {
                    e = repository.GetElementByID(int.Parse(update));
                } catch
                {
                    MessageBox.Show("Error with update: " + update);
                }

                if (e == null)
                {
                    MessageBox.Show("No Element: " + update);
                    continue;
                }

                if (showAlert && MessageBox.Show("Update detected. Refresh now?", "Auto Refresh", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    continue;
                }

                // See: http://www.sparxsystems.com/enterprise_architect_user_guide/9.3/automation/repository3.html
                repository.AdviseElementChange(e.ElementID);
            }
        }
Example #11
0
        public String getGuidOfAttributeByURIString(String uriString)
        {
            List<String> values = new List<String>();
            String[] splitted = uriString.Split('/');
            foreach (String entry in splitted)
            {
                if (entry != "")
                    values.Add(entry.Replace("#", ""));
            }

            String result = Repository.SQLQuery("select * from t_attribute where name = '" + this.AttributeName + "'");
            foreach (String row in EAEcoreAddin.Util.EAUtil.getXMLNodeContentFromSQLQueryString(result, "Row"))
            {
                if (row != "")
                {
                    SQLAttribute attribute = new SQLAttribute(row, Repository);
                    SQLElement parentElement = Repository.GetElementByID(attribute.ParentID);
                    SQLPackage parentPackage = Repository.GetPackageByID(parentElement.PackageID);
                    if (parentElement.Name == values[values.Count - 2] && parentPackage.Name == values[values.Count - 3])
                    {
                        return attribute.AttributeGUID;
                    }
                }
            }
            return "";
        }
Example #12
0
        public override void addAttributesDuringExport(MocaNode activityEdgeNode)
        {
            SQLElement target = Repository.GetElementByID(this.EaConnector.SupplierID);
            SQLElement client = Repository.GetElementByID(this.EaConnector.ClientID);

            activityEdgeNode.appendChildAttribute("sourceGuid", client.ElementGUID);
            activityEdgeNode.appendChildAttribute("targetGuid", target.ElementGUID);
        }
Example #13
0
 public ActivityEdge(SQLRepository sqlRepository, SQLConnector eaConnector)
 {
     this.Repository  = sqlRepository;
     this.EaConnector = eaConnector;
     this.Guid        = this.EaConnector.ConnectorGUID;
     Source           = Repository.GetElementByID(eaConnector.ClientID);
     Target           = Repository.GetElementByID(eaConnector.SupplierID);
     this.sourceGuid  = Source.ElementGUID;
     this.targetGuid  = Target.ElementGUID;
 }
        // 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();
            }
        }
Example #15
0
 private string computeKernelString()
 {
     foreach (SQLConnector connector in rule.Connectors)
     {
         if (connector.SupplierID == rule.ElementID && connector.Stereotype == TGGModelingMain.TGGkernelMorphismStereotype)
         {
             return(Repository.GetElementByID(connector.ClientID).ElementGUID);
         }
     }
     return("");
 }
Example #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);
        }
 /// <summary>
 /// Delete dependencies of element within the ReqIF Packages
 /// </summary>
 /// <param name="el"></param>
 /// <param name="packageGuidList"></param>
 private void DeleteDependencies(EA.Element el, List <ReqIfModuleAssign> packageGuidList)
 {
     for (int i = el.Connectors.Count - 1; i >= 0; i--)
     {
         var    elConnector   = (EA.Connector)el.Connectors.GetAt((short)i);
         var    elTarget      = _rep.GetElementByID(elConnector.SupplierID);
         string pkgTargetGuid = _rep.GetPackageByID(elTarget.PackageID).PackageGUID;
         // Check if guid exists
         if (packageGuidList.Exists(y => y.Guid == pkgTargetGuid))
         {
             el.Connectors.DeleteAt((short)i, true);
         }
     }
     el.Refresh();
     el.Update();
 }
        /// <inheritdoc />
        public override void Initialize()
        {
            SaveCommand   = new SaveCommand();
            CancelCommand = new CancelCommand();
            AddCommand    = new AddCommand();
            RemoveCommand = new RemoveCommand();

            Connector = Repository.GetContextObject();
            SourceEnd = Connector.SupplierEnd;
            TargetEnd = Connector.ClientEnd;

            switch (SourceEnd.Stereotype)
            {
            case "ObjectProperty":
                ShowSourceEnd = SourceEnd.Stereotype == "ObjectProperty" ? Visibility.Visible : Visibility.Collapsed;

                break;

            case "RdfsProperty":
                ShowSourceEnd = SourceEnd.Stereotype == "RdfsProperty" ? Visibility.Visible : Visibility.Collapsed;
                break;
            }

            switch (TargetEnd.Stereotype)
            {
            case "ObjectProperty":
                ShowTargetEnd = TargetEnd.Stereotype == "ObjectProperty" ? Visibility.Visible : Visibility.Collapsed;
                break;

            case "RdfsProperty":
                ShowTargetEnd = TargetEnd.Stereotype == "RdfsProperty" ? Visibility.Visible : Visibility.Collapsed;
                break;
            }

            SourceViewModel = new ConnectorUserControlViewModel {
                ConnectorEnd = SourceEnd, ElementNameValue = Repository.GetElementByID(Connector.SupplierID).Name
            };
            TargetViewModel = new ConnectorUserControlViewModel {
                ConnectorEnd = TargetEnd, ElementNameValue = Repository.GetElementByID(Connector.ClientID).Name
            };

            SourceViewModel.ResourceDictionary = ResourceDictionary;
            TargetViewModel.ResourceDictionary = ResourceDictionary;

            SourceViewModel.Initialize();
            TargetViewModel.Initialize();
        }
Example #19
0
        public override void addAttributesDuringExport(MocaNode linkVariableMocaNode)
        {
            SQLElement target = Repository.GetElementByID(this.LinkVariableEA.SupplierID);
            SQLElement client = Repository.GetElementByID(this.LinkVariableEA.ClientID);

            linkVariableMocaNode.appendChildAttribute("sourceGuid", client.ElementGUID);
            linkVariableMocaNode.appendChildAttribute("targetGuid", target.ElementGUID);
            linkVariableMocaNode.appendChildAttribute("sourceName", LinkVariableEA.ClientEnd.Role);
            linkVariableMocaNode.appendChildAttribute("textOfReference", LinkVariable.getTextOfReference(LinkVariableEA));
            linkVariableMocaNode.appendChildAttribute("textOfReferenceOpposite", LinkVariable.getOppositeTextOfReference(LinkVariableEA));
            String oldRefId = LinkVariable.getIdOfReference(LinkVariableEA, Repository);

            if (oldRefId != "")
            {
                linkVariableMocaNode.appendChildAttribute("idOfReference", oldRefId);
            }
        }
Example #20
0
        public void computeAttributes()
        {
            this.Name          = EaParameter.Name;
            this.parameterType = EaParameter.Type;

            if (this.EaParameter.ClassifierID != "0" && this.EaParameter.ClassifierID != "")
            {
                try
                {
                    SQLElement classifier = Repository.GetElementByID(int.Parse(this.EaParameter.ClassifierID));
                    this.typeGuid = classifier.ElementGUID;
                }
                catch
                {
                }
            }
        }
        //---------------------------------------------------------------------------------------------
        // updateActionParameter(EA.Repository rep, EA.Element actionPin)
        //---------------------------------------------------------------------------------------------
        public static bool UpdateActionPinParameter(Repository rep, EA.Element action)
        {
            foreach (EA.Element actionPin in action.EmbeddedElements)
            {
                // pin target for the return type of the action
                if (actionPin.Name == "target")
                {
                    //// return type
                    //Int32 parTypeID = Util.getTypeID(rep, m.ReturnType);
                    //if (parTypeID != 0)
                    //{
                    //    //pin.Name = par.
                    //    pin.ClassfierID = parTypeID;
                    //    EA.Element el = rep.GetElementByID(parTypeID);
                    //    pin.Update(); // do it before update table
                    //    Util.setElementPDATA1(rep, pin, el.ElementGUID);// set PDATA1

                    //}
                }
                else
                {
                    // get type of synchronized parameter
                    // if parameter isn't synchronized it will not work
                    string type = HoUtil.GetParameterType(rep, actionPin.ElementGUID);
                    if (type == "")
                    {
                        string txt = "No type is available for action:'" + action.Name + "'";
                        rep.WriteOutput("hoReverse", txt, 0);
                    }
                    else
                    {
                        Int32 parTypeId = HoUtil.GetTypeId(rep, type);
                        if (parTypeId != 0)
                        {
                            //pin.Name = par.
                            EA.Element el = rep.GetElementByID(parTypeId);
                            HoUtil.SetElementPdata1(rep, actionPin, el.ElementGUID);// set PDATA1
                        }
                    }
                }
            }

            return(true);
        }
Example #22
0
        public bool EA_OnPreNewDiagramObject(Repository repository, EventProperties info)
        {
            var     elementId = 0;
            var     diagramId = 0;
            Element element;

            foreach (EventProperty eventProperty in info)
            {
                if (eventProperty.Name == "ID")
                {
                    elementId = int.Parse(eventProperty.Value.ToString());
                }
                if (eventProperty.Name == "DiagramID")
                {
                    diagramId = int.Parse(eventProperty.Value.ToString());
                }
            }

            try
            {
                element = repository.GetElementByID(elementId);
            }
            catch (Exception)
            {
                //if we don't get any ID the new Diagram Object seems to be created from the toolbox, that's ok so we just allow it
                return(true);
            }
            var diagram        = repository.GetDiagramByID(diagramId);
            var diagramLibrary = repository.GetPackageByID(diagram.PackageID);
            var elementLibrary = repository.GetPackageByID(element.PackageID);

            if (element.Stereotype == "ACC" && diagramLibrary.StereotypeEx == "BIELibrary")
            {
                new AbieEditor(elementLibrary.Name, element.Name, diagramLibrary.Name, diagramId, repository).ShowDialog();
                return(false);
            }
            if (element.Stereotype == "CDT" && diagramLibrary.StereotypeEx == "BDTLibrary")
            {
                new BdtEditor(elementLibrary.Name, element.Name, diagramLibrary.Name, diagramId, repository).ShowDialog();
                return(false);
            }
            return(true);
        }
Example #23
0
        public List <SQLElement> getDirectBaseRules(SQLElement rule)
        {
            List <SQLElement> list = new List <SQLElement>();

            //if rule is contained in Rule-Set
            if (rule.ParentID != 0)
            {
                SQLElement parentElement = Repository.GetElementByID(rule.ParentID);
                if (parentElement.Stereotype == TGGModelingMain.TggRuleSetStereotype)
                {
                    list.AddRange(getDirectBaseRules(parentElement));
                }
            }

            foreach (SQLElement baseClass in rule.BaseClasses)
            {
                list.Add(baseClass);
            }



            foreach (SQLConnector con in rule.Connectors)
            {
                if (con.Stereotype == TGGModelingMain.TggCustomGeneralizationStereotype && con.ClientID == rule.ElementID)
                {
                    SQLElement targetElement = Repository.GetElementByID(con.SupplierID);
                    if (targetElement.Stereotype == TGGModelingMain.TggRuleSetStereotype)
                    {
                        foreach (SQLElement ruleInsideBoundary in targetElement.Elements)
                        {
                            list.Add(ruleInsideBoundary);
                        }
                    }
                    else if (targetElement.Stereotype == TGGModelingMain.TggRuleStereotype)
                    {
                        list.Add(targetElement);
                    }
                }
            }
            return(list);
        }
Example #24
0
        public override void doEaGuiStuff()
        {
            base.doEaGuiStuff();

            EA.Element sdmContainer = ActivityNodeEAElement.getRealElement();
            if (sdmContainer.Stereotype == SDMModelingMain.SdmContainerStereotype)
            {
                try
                {
                    SQLMethod  associatedMethod = Repository.GetMethodByGuid(EAUtil.findTaggedValue(ActivityNodeEAElement, SDMModelingMain.SDMContainerAssociatedMethodTaggedValueName).Value);
                    SQLElement containingEClass = Repository.GetElementByID(associatedMethod.ParentID);
                    ActivityNodeEAElement.getRealElement().Name = SDMUtil.computeStartNodeName(associatedMethod, containingEClass);
                }
                catch (Exception)
                {
                }
            }

            sdmContainer.StereotypeEx = SDMModelingMain.StartNodeStereotype;
            sdmContainer.Update();
        }
        private Boolean isLocked()
        {
            //checks if ObjectToBeTagged is locked and adds outermost package name to Export
            Boolean    locked        = false;
            SQLElement lockedElement = null;

            if (getObjectToBeTagged() is SQLElement)
            {
                SQLElement elemn = getObjectToBeTagged() as SQLElement;
                locked        = elemn.Locked;
                lockedElement = elemn;
            }
            else if (getObjectToBeTagged() is SQLPackage)
            {
                SQLPackage elemn = getObjectToBeTagged() as SQLPackage;
                if (elemn.Element != null)
                {
                    locked = elemn.Element.Locked;
                }
                lockedElement = elemn.Element;
            }
            else if (getObjectToBeTagged() is SQLConnector)
            {
                SQLConnector elemn  = getObjectToBeTagged() as SQLConnector;
                SQLElement   source = Repository.GetElementByID(elemn.ClientID);
                locked        = source.Locked;
                lockedElement = source;
            }
            if (locked)
            {
                SQLPackage outermostPkg = EAUtil.getOutermostPackage(lockedElement, Repository);

                if (outermostPkg != null && !Export.AutoUpdatePackages.Contains(outermostPkg.Name))
                {
                    Export.AutoUpdatePackages.Add(outermostPkg.Name);
                }
            }
            return(locked);
        }
Example #26
0
        public void computeAttributes()
        {
            this.EParameters = new List <EParameter>();
            this.returnType  = EaMethod.ReturnType;
            foreach (SQLParameter parameter in EaMethod.Parameters)
            {
                EParameter eParameter = new EParameter(parameter, Repository);
                EParameters.Add(eParameter);
            }

            if (this.EaMethod.ClassifierID != "0" && this.EaMethod.ClassifierID != "")
            {
                try
                {
                    SQLElement classifier = Repository.GetElementByID(int.Parse(this.EaMethod.ClassifierID));
                    this.typeGuid = classifier.ElementGUID;
                }
                catch
                {
                }
            }
        }
        /// <summary>
        ///  Create/Update an Activity Diagram for the operation
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="m"></param>
        /// <param name="treePos">If a new package is created the new tree position to show the package in the correct order</param>
        /// <returns></returns>
        public static bool CreateActivityForOperation(Repository rep, Method m, int treePos = 100)
        {
            // get class
            EA.Element elClass = rep.GetElementByID(m.ParentID);
            EA.Package pkgSrc  = rep.GetPackageByID(elClass.PackageID);

            // Check if update behavior, behavior exists
            string behaviorGuid = m.Behavior;

            // Check if update Activity or Create a new one
            if (behaviorGuid.StartsWith("{") && behaviorGuid.EndsWith("}"))
            {
                //behaviorGuid = behaviorGuid.Substring(1, behaviorGuid.Length-2);
                EA.Element actForUpdate = rep.GetElementByGuid(behaviorGuid);
                if (actForUpdate == null)
                {
                    var res = MessageBox.Show($@"Can't update Activity for Operation, invalid link to Activity found

Behavior GUID =GUID of expected Activity:
{behaviorGuid}

Unable to find Activity for this GUID",
                                              @"Invalid link to Activity found, Create a new one?",
                                              MessageBoxButtons.OKCancel);
                    if (res != DialogResult.OK)
                    {
                        return(false);
                    }
                    CreateActivityFromOperation(rep, m, treePos, pkgSrc, elClass);
                }
                else
                {
                    UpdateParameterFromOperation(rep, actForUpdate, m); // update parameters from Operation for Activity
                }
                return(true);
            }
            CreateActivityFromOperation(rep, m, treePos, pkgSrc, elClass);
            return(true);
        }
Example #28
0
        //returns an element
        public static EA.Element GetElementObject(string SelectedElement, string SelectedDiagram, Repository m_Repository)
        {
            string x = m_Repository.SQLQuery("SELECT * FROM t_object where name = \"" + SelectedElement + "\""); //Do a SQL Query to get the ID number of the element in question
            string y = x.Replace("\r", "").Replace("\n", "").Replace("\t", "");                                  //Strip out new line characters in the sql

            XmlReader   reader = XmlReader.Create(new System.IO.StringReader(y));
            XmlDocument xmlDoc = new XmlDocument(); // Create an XML document object

            xmlDoc.Load(reader);                    // Load the XML document from the specified file

            // Get elements
            XmlNodeList Name = xmlDoc.GetElementsByTagName("Name");
            XmlNodeList ID   = xmlDoc.GetElementsByTagName("Object_ID");

            //If we have nothing then return nothing here
            if (Name.Count == 0)
            {
                return(null);
            }

            string result = Name[0].InnerText;
            string IDs    = ID[0].InnerText;

            EA.Diagram SelectedDiagramObject = GetDiagramObject(SelectedDiagram, m_Repository);
            if (SelectedDiagramObject == null)
            {
                return(null);
            }


            EA.Element ElementToReturn = m_Repository.GetElementByID(Convert.ToInt16(IDs));



            return(ElementToReturn);
        }
Example #29
0
        public void handleDiagramObjectCreation(Repository repository, int elementID, int diagramID, string DUID)
        {
            try
            {
                changed = false;

                EA.Element el = repository.GetElementByID(elementID);
                EA.Diagram diag = repository.GetDiagramByID(diagramID);

                Wrapper.Diagram diagram = new Wrapper.Diagram(model, diag);
                Wrapper.ElementWrapper elWrapper = new Wrapper.ElementWrapper(model, el);

                DiagramObject cur = diagram.getdiagramObjectForElement(elWrapper);
                string coordinates = "";
                coordinates += "l=" + cur.left + ";";
                coordinates += "r=" + cur.right + ";";
                coordinates += "t=" + cur.top + ";";
                coordinates += "b=" + cur.bottom + ";";
                currentDiagramObjectPositions.Add(cur.ElementID, coordinates);

                ItemCreation itemCreation = new ItemCreation();
                itemCreation.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                itemCreation.itemGUID = el.ElementGUID;
                itemCreation.diagramGUID = diag.DiagramGUID;
                itemCreation.elementType = 700;
                itemCreation.coordinates = "";

                for (short i = 0; i < diag.DiagramObjects.Count; i++)
                {
                    EA.DiagramObject diagramObject = (EA.DiagramObject)diag.DiagramObjects.GetAt(i);
                    if (diagramObject.ElementID == el.ElementID)
                    {
                        coordinates = "";
                        coordinates += "l=" + diagramObject.left + ";";
                        coordinates += "r=" + diagramObject.right + ";";
                        coordinates += "t=" + diagramObject.top + ";";
                        coordinates += "b=" + diagramObject.bottom + ";";
                        itemCreation.coordinates = coordinates;
                        break;
                    }
                }

                changeService.saveChange(itemCreation);
            }
            catch (Exception ex) { }
        }
Example #30
0
        public void handleConnectorDeletion(Repository repository, int connectorID)
        {
            try
            {
                changed = false;
                EA.Connector connector = repository.GetConnectorByID(connectorID);
                EA.Element sourceElement = (EA.Element)repository.GetElementByID(connector.ClientID);

                PropertyChange modelChange = new PropertyChange();
                modelChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                modelChange.itemGUID = connector.ConnectorGUID;
                modelChange.elementType = itemTypes.getConnectorType(connector.ConnectorGUID);
                modelChange.elementDeleted = 1;
                changeService.saveChange(modelChange);
            }
            catch (Exception ex) { }
        }
Example #31
0
        public void handleDiagramCreation(Repository repository, int diagramID)
        {
            try
            {
                changed = false;
                EA.Diagram diagram = repository.GetDiagramByID(diagramID);

                ItemCreation itemCreation = new ItemCreation();
                itemCreation.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                itemCreation.itemGUID = diagram.DiagramGUID;
                itemCreation.elementType = itemTypes.getDiagramType(diagram.DiagramGUID);
                itemCreation.author = diagram.Author;
                itemCreation.name = diagram.Name;
                itemCreation.parentGUID = "0";

                if (diagram.ParentID != 0)
                {
                    EA.Element parent = repository.GetElementByID(diagram.ParentID);
                    if (parent != null)
                    {
                        itemCreation.parentGUID = parent.ElementGUID;
                    }
                }

                EA.Package package = repository.GetPackageByID(diagram.PackageID);
                if (package != null)
                {
                    itemCreation.packageGUID = package.PackageGUID;
                }

                changeService.saveChange(itemCreation);
            }
            catch (Exception ex) { }
        }
        /// <summary>insertDiagramElement insert a diagram element and connects it to all selected diagramobject 
        /// <para>type: type of the node like "Action", Activity", "MergeNode"</para>
        ///       MergeNode may have the subType "no" to draw a transition with a "no" guard.
        /// <para>subTyp: subType of the node:
        ///       StateNode: 100=ActivityInitial, 101 ActivityFinal
        /// </para>guardString  of the connector "","yes","no",..
        ///        if "yes" or "" it will locate the node under the last selected element
        /// </summary> 
        // ReSharper disable once UnusedMember.Global
        public static void InsertDiagramElementAndConnect(Repository rep, string type, string subType,
            string guardString = "")
        {
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            if (dia.Type != "Activity") return;

            int count = dia.SelectedObjects.Count;
            if (count == 0) return;

            rep.SaveDiagram(dia.DiagramID);
            var oldCollection = new List<DiagramObject>();

            // get context element (last selected element)
            Element originalSrcEl = Util.GetElementFromContextObject(rep);
            if (originalSrcEl == null) return;
            int originalSrcId = originalSrcEl.ElementID;

            for (int i = count - 1; i > -1; i = i - 1)
            {
                oldCollection.Add((DiagramObject) dia.SelectedObjects.GetAt((short) i));
                // keep last selected element
                //if (i > 0) dia.SelectedObjects.DeleteAt((short)i, true);
            }

            Util.GetDiagramObjectById(rep, dia, originalSrcId);
            //EA.DiagramObject originalSrcObj = dia.GetDiagramObjectByID(originalSrcID, "");

            DiagramObject trgObj = CreateDiagramObjectFromContext(rep, "", type, subType, 0, 0, guardString,
                originalSrcEl);
            Element trgtEl = rep.GetElementByID(trgObj.ElementID);

            // if connection to more than one element make sure the new element is on the deepest position
            int offset = 50;
            if (guardString == "yes") offset = 0;
            int bottom = 1000;
            int diff = trgObj.top - trgObj.bottom;


            foreach (DiagramObject diaObj in oldCollection)
            {
                Element srcEl = rep.GetElementByID(diaObj.ElementID);
                // don't connect two times
                if (originalSrcId != diaObj.ElementID)
                {
                    var con = (Connector) srcEl.Connectors.AddNew("", "ControlFlow");
                    con.SupplierID = trgObj.ElementID;
                    if (type == "MergeNode" && guardString == "no" && srcEl.Type == "Decision")
                        con.TransitionGuard = "no";
                    con.Update();
                    srcEl.Connectors.Refresh();
                    dia.DiagramLinks.Refresh();
                    //trgtEl.Connectors.Refresh();

                    // set line style
                    string style = "LV";
                    if ((srcEl.Type == "Action" | srcEl.Type == "Activity") & guardString == "no") style = "LH";
                    var link = GetDiagramLinkForConnector(dia, con.ConnectorID);
                    if (link != null) Util.SetLineStyleForDiagramLink(style, link);
                }
                // set new high/bottom_Position
                var srcObj = Util.GetDiagramObjectById(rep, dia, srcEl.ElementID);
                //srcObj = dia.GetDiagramObjectByID(srcEl.ElementID, "");
                if (srcObj.bottom < bottom) bottom = srcObj.bottom;
            }
            if (oldCollection.Count > 1)
            {
                // set bottom/high of target
                trgObj.top = bottom + diff - offset;
                trgObj.bottom = bottom - offset;
                trgObj.Sequence = 1;
                trgObj.Update();
                // final
                if (subType == "101" && trgtEl.ParentID > 0)
                {
                    Element parEl = rep.GetElementByID(trgtEl.ParentID);
                    if (parEl.Type == "Activity")
                    {
                        DiagramObject parObj = Util.GetDiagramObjectById(rep, dia, parEl.ElementID);
                        //EA.DiagramObject parObj = dia.GetDiagramObjectByID(parEl.ElementID, "");
                        if (parObj != null)
                        {
                            parObj.bottom = trgObj.bottom - 30;
                            parObj.Update();
                        }
                    }
                }
            }

            rep.ReloadDiagram(dia.DiagramID);
            dia.SelectedObjects.AddNew(trgtEl.ElementID.ToString(), trgtEl.ObjectType.ToString());
        }
Example #33
0
        public void handleConnectorCreation(Repository repository, int connectorID)
        {
            try
            {
                currentItem = null;
                currentDiagram = null;
                changed = false;
                EA.Connector connector = repository.GetConnectorByID(connectorID);
                currentConnector = connector;

                ItemCreation itemCreation = new ItemCreation();
                itemCreation.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                itemCreation.itemGUID = connector.ConnectorGUID;
                itemCreation.elementType = itemTypes.getConnectorType(connector.ConnectorGUID);
                itemCreation.name = connector.Name;
                itemCreation.srcGUID = repository.GetElementByID(connector.ClientID).ElementGUID;
                itemCreation.targetGUID = repository.GetElementByID(connector.SupplierID).ElementGUID;

                changeService.saveChange(itemCreation);
            }
            catch (Exception ex) { }
        }
        // ReSharper disable once UnusedMember.Global
        // dynamical usage as configurable service by reflection
        public static void JoinDiagramObjectsToLastSelected(Repository rep)
        {
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            int count = dia.SelectedObjects.Count;
            if (count < 2) return;
            rep.SaveDiagram(dia.DiagramID);

            // target object/element
            var trgEl = (Element) rep.GetContextObject();

            for (int i = 0; i < count; i = i + 1)
            {
                var srcObj = (DiagramObject) dia.SelectedObjects.GetAt((short) i);
                var srcEl = rep.GetElementByID(srcObj.ElementID);
                if (srcEl.ElementID == trgEl.ElementID) continue;
                Connectors.Connector connector = GetConnectionDefault();

                var con = (Connector) srcEl.Connectors.AddNew("", connector.Type);
                con.SupplierID = trgEl.ElementID;
                con.Stereotype = connector.Stereotype;
                con.Update();
                srcEl.Connectors.Refresh();
                trgEl.Connectors.Refresh();
                dia.DiagramLinks.Refresh();
                // set line style
                DiagramLink link = GetDiagramLinkForConnector(dia, con.ConnectorID);
                if (link != null) Util.SetLineStyleForDiagramLink("LV", link);
            }

            rep.ReloadDiagram(dia.DiagramID);
            dia.SelectedObjects.AddNew(trgEl.ElementID.ToString(), trgEl.ObjectType.ToString());
        }
        static void GenerateComponentPorts(Repository rep)
        {
            int pos = 0;
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            if (!rep.GetContextItemType().Equals(ObjectType.otElement)) return;
            var elSource = (Element) rep.GetContextObject();
            if (elSource.Type != "Component") return;

            Util.GetDiagramObjectById(rep, dia, elSource.ElementID);
            //diaObjSource = dia.GetDiagramObjectByID(elSource.ElementID, "");

            rep.SaveDiagram(dia.DiagramID);
            foreach (DiagramObject obj in dia.DiagramObjects)
            {
                var elTarget = rep.GetElementByID(obj.ElementID);
                if (!("Class Interface".Contains(elTarget.Type))) continue;
                if (!(elTarget.Name.EndsWith("_i", StringComparison.Ordinal)))
                {
                    AddPortToComponent(elSource, elTarget);
                    pos = pos + 1;
                }

                if ("Interface Class".Contains(elTarget.Type))
                {
                    List<Element> lEl = GetIncludedHeaderFiles(rep, elTarget);
                    foreach (Element el in lEl)
                    {
                        if (el == null) continue;
                        if (!(el.Name.EndsWith("_i", StringComparison.Ordinal)))
                        {
                            AddPortToComponent(elSource, el);
                            pos = pos + 1;
                        }
                    }
                }
            }
            ShowEmbeddedElementsGui(rep);
        }
        // ReSharper disable once UnusedMember.Local
        static void InsertInterface(Repository rep, Diagram dia, string text)
        {
            bool isComponent = false;
            Package pkg = rep.GetPackageByID(dia.PackageID);
            int pos = 0;

            // only one diagram object selected as source
            if (dia.SelectedObjects.Count != 1) return;

            // save selected object
            DiagramObject objSelected = null;
            if (!(dia == null && dia.SelectedObjects.Count > 0))
            {
                objSelected = (DiagramObject) dia.SelectedObjects.GetAt(0);
            }

            rep.SaveDiagram(dia.DiagramID);
            var diaObjSource = (DiagramObject) dia.SelectedObjects.GetAt(0);
            var elSource = rep.GetElementByID(diaObjSource.ElementID);
            isComponent |= elSource.Type == "Component";
            // remember selected object

            List<Element> ifList = GetInterfacesFromText(rep, pkg, text);
            foreach (Element elTarget in ifList)
            {
                if (elSource.Locked)
                {
                    MessageBox.Show($"Source '{elSource.Name}' is locked", @"Element locked");
                    continue;
                }
                if (isComponent)
                {
                    AddPortToComponent(elSource, elTarget);
                }
                else
                {
                    AddInterfaceToElement(rep, pos, elSource, elTarget, dia, diaObjSource);
                }
                pos = pos + 1;
            }
            // visualize ports
            if (isComponent)
            {
                dia.SelectedObjects.AddNew(diaObjSource.ElementID.ToString(), ObjectType.otElement.ToString());
                dia.SelectedObjects.Refresh();
                ShowEmbeddedElementsGui(rep);
            }

            // reload selected object
            if (objSelected != null)
            {
                dia.SelectedObjects.AddNew(elSource.ElementID.ToString(), elSource.ObjectType.ToString());
                dia.SelectedObjects.Refresh();
            }
            rep.ReloadDiagram(dia.DiagramID);
            dia.SelectedObjects.AddNew(elSource.ElementID.ToString(), elSource.ObjectType.ToString());
            dia.SelectedObjects.Refresh();
        }
        // ReSharper disable once UnusedMember.Global
        // dynamical usage as configurable service by reflection
        public static void SplitAllDiagramObjectsToLastSelected(Repository rep)
        {
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            int count = dia.SelectedObjects.Count;
            if (count == 0) return;
            rep.SaveDiagram(dia.DiagramID);

            // target object/element
            ObjectType objType = rep.GetContextItemType();
            if (!(objType.Equals(ObjectType.otElement))) return;
            var trgEl = (Element) rep.GetContextObject();

            foreach (DiagramObject srcObj in dia.DiagramObjects)
            {
                var srcEl = rep.GetElementByID(srcObj.ElementID);
                if (srcEl.ElementID == trgEl.ElementID) continue;
                SplitElementsByConnectorType(srcEl, trgEl);
            }

            rep.ReloadDiagram(dia.DiagramID);
            dia.SelectedObjects.AddNew(trgEl.ElementID.ToString(), trgEl.ObjectType.ToString());
        }
        public static void MoveEmbeddedUpGui(Repository rep)
        {
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            int selCount = dia.SelectedObjects.Count;
            if (selCount == 0) return;
            rep.SaveDiagram(dia.DiagramID);

            // check if port,..
            var objPort0 = (DiagramObject) dia.SelectedObjects.GetAt(0);
            Element port = rep.GetElementByID(objPort0.ElementID);
            if (!EmbeddedElementTypes.Contains(port.Type)) return;

            // get parent of embedded element
            Element el = rep.GetElementByID(port.ParentID);

            DiagramObject obj = Util.GetDiagramObjectById(rep, dia, el.ElementID);
            //EA.DiagramObject obj = dia.GetDiagramObjectByID(el.ElementID, "");


            // check if upper limit element is crossed
            int upLimit = obj.top - 10; // limit cross over upper 
            bool isUpperLimitCrossed = false;
            foreach (DiagramObject objPort in dia.SelectedObjects)
            {
                if (objPort.top > upLimit)
                {
                    isUpperLimitCrossed = true;
                    break;
                }
            }
            // move all to left upper corner of element
            int startValueTop = obj.top + 8;
            int startValueLeft = obj.left + 8;
            int pos = 0;
            foreach (DiagramObject objPort in dia.SelectedObjects)
            {
                if (!isUpperLimitCrossed)
                {
                    // move to top
                    objPort.top = objPort.top + 10;
                    objPort.Update();
                }
                else
                {
                    // move from left to right
                    objPort.top = startValueTop;
                    objPort.left = startValueLeft + pos*20;
                    objPort.Update();
                    pos = pos + 1;
                }
            }
        }
Example #39
0
        public void handleDiagramObjectDeletion(Repository repository, int elementID)
        {
            try
            {
                changed = false;

                EA.Element element = repository.GetElementByID(elementID);
                EA.Diagram diagram = repository.GetCurrentDiagram();

                PropertyChange modelChange = new PropertyChange();
                modelChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                modelChange.itemGUID = element.ElementGUID;
                modelChange.propertyBody = diagram.DiagramGUID;
                modelChange.elementType = 700;
                modelChange.elementDeleted = 1;

                changeService.saveChange(modelChange);

                currentDiagramObjectPositions.Remove(element.ElementID);
            }
            catch (Exception ex) { }
        }
        // ReSharper disable once UnusedMember.Local
        static void DeleteInvisibleUseRealizationDependencies(Repository rep)
        {
            Connector con;
            var dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            if (!rep.GetContextItemType().Equals(ObjectType.otElement)) return;

            // only one diagram object selected as source
            if (dia.SelectedObjects.Count != 1) return;

            rep.SaveDiagram(dia.DiagramID);
            var diaObjSource = (DiagramObject) dia.SelectedObjects.GetAt(0);
            var elSource = rep.GetElementByID(diaObjSource.ElementID);
            var elSourceId = elSource.ElementID;
            if (!("Interface Class".Contains(elSource.Type))) return;

            // list of all connectorIDs
            var lInternalId = new List<int>();
            foreach (DiagramLink link in dia.DiagramLinks)
            {
                con = rep.GetConnectorByID(link.ConnectorID);
                if (con.ClientID != elSourceId) continue;
                if (!("Usage Realisation".Contains(con.Type))) continue;
                lInternalId.Add(con.ConnectorID);
            }


            for (int i = elSource.Connectors.Count - 1; i >= 0; i = i - 1)
            {
                con = (Connector) elSource.Connectors.GetAt((short) i);
                var conType = con.Type;
                if ("Usage Realisation".Contains(conType))
                {
                    // check if target is..
                    var elTarget = rep.GetElementByID(con.SupplierID);
                    if (elTarget.Type == "Interface")
                    {
                        if (lInternalId.BinarySearch(con.ConnectorID) < 0)
                        {
                            elSource.Connectors.DeleteAt((short) i, true);
                        }
                    }
                }
            }
        }
        static void CreateTypeDefStructFromText(Repository rep, Diagram dia, Package pkg, Element el, string txt)
        {
            Element elTypedef = null;


            // delete comment
            txt = DeleteComment(txt);

            bool update = false;
            bool isStruct = true;
            string elType = "Class";

            // find start
            string regex = @"[\s]*typedef[\s]+(struct|enum)[\s]*([^{]*){";
            Match match = Regex.Match(txt, regex);
            if (!match.Success) return;
            if (txt.Contains(" enum"))
            {
                elType = "Enumeration";
                isStruct = false;
            }
            txt = txt.Replace(match.Value, "");

            // find name
            regex = @"}[\s]*([^;]*);";
            match = Regex.Match(txt, regex);
            if (!match.Success) return;
            string name = match.Groups[1].Value.Trim();
            if (name == "") return;
            txt = txt.Remove(match.Index, match.Length);

            // check if typedef already exists
            int targetId = Util.GetTypeId(rep, name);
            if (targetId != 0)
            {
                elTypedef = rep.GetElementByID(targetId);
                update = true;
                for (int i = elTypedef.Attributes.Count - 1; i > -1; i = i - 1)
                {
                    elTypedef.Attributes.DeleteAt((short) i, true);
                }
            }


            // create typedef
            if (update == false)
            {
                if (el != null)
                {
                    // create class below element
                    if ("Interface Class Component".Contains(el.Type))
                    {
                        elTypedef = (Element) el.Elements.AddNew(name, elType);
                        el.Elements.Refresh();
                    }
                    else
                    {
                        MessageBox.Show(@"Can't create element below selected Element");
                    }
                }
                else // create class in package
                {
                    elTypedef = (Element) pkg.Elements.AddNew(name, elType);
                    pkg.Elements.Refresh();
                }
            }
            if (isStruct)
            {
                elTypedef.Stereotype = @"struct";
                EA.TaggedValue tag = TaggedValue.AddTaggedValue(elTypedef, "typedef");
                tag.Value = "true";
                tag.Update();
            }
            if (update == false)
            {
                elTypedef.Name = name;
                elTypedef.Update();
            }

            // add elements
            if (isStruct) CreateClassAttributesFromText(rep, elTypedef, txt);
            else CreateEnumerationAttributesFromText(rep, elTypedef, txt);

            if (update)
            {
                rep.RefreshModelView(elTypedef.PackageID);
                rep.ShowInProjectView(elTypedef);
            }
            else
            {
                // put diagram object on diagram
                int left = 0;
                int right = left + 200;
                int top = 0;
                int bottom = top + 100;
                //int right = diaObj.right + 2 * (diaObj.right - diaObj.left);
                rep.SaveDiagram(dia.DiagramID);
                string position = "l=" + left + ";r=" + right + ";t=" + top + ";b=" + bottom + ";";
                var diaObj = (DiagramObject) dia.DiagramObjects.AddNew(position, "");
                dia.DiagramObjects.Refresh();
                diaObj.ElementID = elTypedef.ElementID;
                diaObj.Update();
            }
            rep.ReloadDiagram(dia.DiagramID);
            dia.SelectedObjects.AddNew(elTypedef.ElementID.ToString(), elTypedef.ObjectType.ToString());
            dia.SelectedObjects.Refresh();
        }
        public static void CreateAttributesFromText(Repository rep, string txt)
        {
            DiagramObject objSelected = null;
            Element el = Util.GetElementFromContextObject(rep);
            Diagram dia = rep.GetCurrentDiagram();
            if (!(dia == null && dia.SelectedObjects.Count > 0))
            {
                objSelected = (DiagramObject) dia.SelectedObjects.GetAt(0);
            }


            if (el == null)
            {
                MessageBox.Show(@"No Element selected, probably nothing or an attribute / operation");
                return;
            }
            if (el.Type.Equals("Class") | el.Type.Equals("Interface")) CreateClassAttributesFromText(rep, el, txt);
            if (el.Type.Equals("Enumeration")) CreateEnumerationAttributesFromText(rep, el, txt);

            if (objSelected != null)
            {
                el = rep.GetElementByID(objSelected.ElementID);
                dia.SelectedObjects.AddNew(el.ElementID.ToString(), el.ObjectType.ToString());
                dia.SelectedObjects.Refresh();
            }
        }
        public static void ShowEmbeddedElementsGui(
            Repository rep,
            string embeddedElementType = "Port Pin Parameter",
            bool isOptimizePortLayout = false)
        {
            var dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            rep.SaveDiagram(dia.DiagramID);

            var sqlUtil = new UtilSql(rep);
            // over all selected elements
            foreach (DiagramObject diaObj in dia.SelectedObjects)
            {
                var elSource = rep.GetElementByID(diaObj.ElementID);
                if (!"Class Component Activity".Contains(elSource.Type)) continue;
                // find object on Diagram
                var diaObjSource = Util.GetDiagramObjectById(rep, dia, elSource.ElementID);
                //diaObjSource = dia.GetDiagramObjectByID(elSource.ElementID, "");
                if (diaObjSource == null) return;

                string[] portTypes = {"left", "right"};
                foreach (string portBoundTo in portTypes)
                {
                    // arrange sequence of ports
                    if (isOptimizePortLayout == false && portBoundTo == "left") continue;
                    int pos = 0;
                    List<int> lPorts;
                    if (isOptimizePortLayout == false)
                    {
                        lPorts = sqlUtil.GetAndSortEmbeddedElements(elSource, "", "", "");
                    }
                    else
                    {
                        if (portBoundTo == "left")
                            lPorts = sqlUtil.GetAndSortEmbeddedElements(elSource, "Port", "'Server', 'Receiver' ",
                                "DESC");
                        else lPorts = sqlUtil.GetAndSortEmbeddedElements(elSource, "Port", "'Client', 'Sender' ", "");
                    }
                    // over all sorted ports
                    string oldStereotype = "";
                    foreach (int i in lPorts)
                    {
                        Element portEmbedded = rep.GetElementByID(i);
                        if (embeddedElementType == "" | embeddedElementType.Contains(portEmbedded.Type))
                        {
                            // only ports / parameters (port has no further embedded elements
                            if (portEmbedded.Type == "ActivityParameter" | portEmbedded.EmbeddedElements.Count == 0)
                            {
                                if (isOptimizePortLayout)
                                {
                                    if (portBoundTo == "left")
                                    {
                                        if ("Sender Client".Contains(portEmbedded.Stereotype)) continue;
                                    }
                                    else
                                    {
                                        if ("Receiver Server".Contains(portEmbedded.Stereotype)) continue;
                                    }
                                }
                                // Make a gap between different stereotypes
                                if (pos == 0 && "Sender Receiver".Contains(portEmbedded.Stereotype))
                                    oldStereotype = portEmbedded.Stereotype;
                                if (pos > 0 && "Sender Receiver".Contains(oldStereotype) &&
                                    oldStereotype != portEmbedded.Stereotype)
                                {
                                    pos = pos + 1; // make a gap
                                    oldStereotype = portEmbedded.Stereotype;
                                }
                                Util.VisualizePortForDiagramobject(pos, dia, diaObjSource, portEmbedded, null,
                                    portBoundTo);
                                pos = pos + 1;
                            }
                            else
                            {
                                // Port: Visualize Port + Interface
                                foreach (Element interf in portEmbedded.EmbeddedElements)
                                {
                                    Util.VisualizePortForDiagramobject(pos, dia, diaObjSource, portEmbedded, interf);
                                    pos = pos + 1;
                                }
                            }
                        }
                    }
                }
            }
            rep.ReloadDiagram(dia.DiagramID);
        }
        public static void CreateActivityForOperation(Repository rep)
        {
            ObjectType oType = rep.GetContextItemType();
            switch (oType)
            {
                case ObjectType.otMethod:
                    var m = (Method) rep.GetContextObject();

                    // Create Activity at the end
                    Element el = rep.GetElementByID(m.ParentID);
                    Package pkg = rep.GetPackageByID(el.PackageID);
                    int pos = pkg.Packages.Count + 1;
                    ActivityPar.CreateActivityForOperation(rep, m, pos);
                    rep.Models.Refresh();
                    rep.RefreshModelView(0);
                    rep.ShowInProjectView(m);
                    break;

                case ObjectType.otElement:
                    el = (Element) rep.GetContextObject();
                    if (el.Locked) return;

                    CreateActivityForOperationsInElement(rep, el);
                    rep.Models.Refresh();
                    rep.RefreshModelView(0);
                    rep.ShowInProjectView(el);
                    break;

                case ObjectType.otPackage:
                    pkg = (Package) rep.GetContextObject();
                    CreateActivityForOperationsInPackage(rep, pkg);
                    // update sort order of packages
                    rep.Models.Refresh();
                    rep.RefreshModelView(0);
                    rep.ShowInProjectView(pkg);
                    break;
            }
        }
Example #45
0
        public void handleElementCreation(Repository repository, int elementID)
        {
            try {
                changed = false;
                EA.Element el = repository.GetElementByID(elementID);
                currentItem = el;

                ItemCreation itemCreation = new ItemCreation();
                itemCreation.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                itemCreation.itemGUID = el.ElementGUID;
                itemCreation.elementType = itemTypes.getElementType(el.ElementGUID);
                itemCreation.author = el.Author;
                itemCreation.name = el.Name;
                itemCreation.parentGUID = "0";

                if (itemTypes.getElementType(el.ElementGUID) != 6 &&
                    (itemTypes.getElementType(el.ElementGUID) < 30 || itemTypes.getElementType(el.ElementGUID) > 44))
                {
                    if (el.ParentID != 0)
                    {
                        EA.Element parent = repository.GetElementByID(el.ParentID);
                        if (parent != null)
                        {
                            itemCreation.parentGUID = parent.ElementGUID;
                        }
                    }
                }

                EA.Package package = repository.GetPackageByID(el.PackageID);
                if (package != null)
                {
                    itemCreation.packageGUID = package.PackageGUID;
                }

                changeService.saveChange(itemCreation);

                if (el.Type == "UseCase")
                {
                    currentExtensionPoints.Add(el.ElementGUID, el.ExtensionPoints);
                }
            }
            catch (Exception ex) { }
        }
        /**
         * Checks that all the definitions this class depends on are already generated
         * This includes the base classes as well as any types that appear as
         * attributes and are not marked "@Shared"
         *
         */
        private static bool GenIDL_DependenciesAlreadyGenerated(Repository repository, Element classElem,
            TextOutputInterface output, HashSet<long> completedClasses, bool outputReport)
        {
            //output.OutputTextLine("// GenIDL_DependenciesAlreadyGenerated Checking: " + classElem.Name);

            // Check base classes
            if (classElem.BaseClasses.Count > 0)
            {
                Object obj = classElem.BaseClasses.GetAt(0);
                Element elem = (Element)obj;
                if (!completedClasses.Contains(elem.ElementID))
                {
                    if (outputReport)
                    {
                        output.OutputText("    ( \"" + GenIDL_GetFullPackageName(repository, classElem) + "\" , \"" + classElem.Name + "\" )");
                        output.OutputText("  depends on  ( " + GenIDL_GetFullPackageName(repository, elem) + "\" , \"" + elem.Name + "\" )");
                        output.OutputTextLine("  dependency: baseclass");
                    }
                    return false;
                }
            }

            // Check atributes
            foreach (EA.Attribute child in classElem.Attributes)
            {
               if (child.ClassifierID == 0) /* Primitive type */
                {
                    continue;
                }
                if (!completedClasses.Contains(child.ClassifierID))
                {
                    // Not generated yet. It is only OK if this is by reference
                    if ( !IsAttributeReference(child) )
                    {
                        if (outputReport)
                        {
                            Element childTypeElem = repository.GetElementByID(child.ClassifierID);
                            output.OutputText("    ( \"" + GenIDL_GetFullPackageName(repository, classElem) + "\" , \"" + classElem.Name + "\" )");
                            output.OutputText("  depends on  ( " + GenIDL_GetFullPackageName(repository, childTypeElem) + "\" , \"" + childTypeElem.Name + "\" )");
                            output.OutputTextLine("   dependency:  attribute \"" + child.Name + "\"");
                        }

                        return false;
                    }
                }
            }

            // Check relationships (Aggregations only)
            foreach (EA.Connector conn in classElem.Connectors)
            {
                ConnectorEnd thisElemEnd;
                ConnectorEnd referencedElemEnd;
                int referencedElemId;

                if (classElem.ElementID == conn.ClientID)
                {
                    thisElemEnd = conn.ClientEnd;
                    referencedElemEnd = conn.SupplierEnd;
                    referencedElemId = conn.SupplierID;
                }
                else
                {
                    thisElemEnd = conn.SupplierEnd;
                    referencedElemEnd = conn.ClientEnd;
                    referencedElemId = conn.ClientID;
                }

                if ( (thisElemEnd.Aggregation == 0)
                      || (conn.Type.Equals("Aggregation") == false))
                {
                    continue;
                }

                if (!referencedElemEnd.IsNavigable)
                {
                    continue;
                }

                if (!completedClasses.Contains(referencedElemId))
                {
                    if (outputReport)
                    {
                        Element referencedElem = repository.GetElementByID(referencedElemId);
                        output.OutputText("    ( \"" + GenIDL_GetFullPackageName(repository, classElem) + "\" , \"" + classElem.Name + "\" )");
                        output.OutputText("  depends on  ( " + GenIDL_GetFullPackageName(repository, referencedElem) + "\" , \"" + referencedElem.Name + "\" )");
                        output.OutputTextLine("   dependency:  aggregation \"" + conn.Name + "\"");
                    }

                    return false;
                }
            }

            return true;
        }
        //----------------------------------------------------------------------------------------
        // type:      "Action", "Activity","Decision", "MergeNode","StateNode"
        // extension: "CallOperation" ,"101"=StateNode, Final, "no"= else/no Merge
        //             comp=yes:  Activity with composite Diagram
        //----------------------------------------------------------------------------------------
        private static DiagramObject CreateDiagramObjectFromContext(Repository rep, string name, string type,
            string extension, int offsetHorizental = 0, int offsetVertical = 0, string guardString = "",
            Element srcEl = null)
        {
            int widthPerCharacter = 60;
            // filter out linefeed, tab
            name = Regex.Replace(name, @"(\n|\r|\t)", "", RegexOptions.Singleline);

            if (name.Length > 255)
            {
                MessageBox.Show($"{type}: '{name}' has more than 255 characters.", @"Name is to long");
                return null;
            }
            Element elSource;
            Element elParent = null;
            Element elTarget;

            string basicType = type;
            if (type == "CallOperation") basicType = "Action";

            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return null;

            rep.SaveDiagram(dia.DiagramID);

            // only one diagram object selected as source
            if (srcEl == null) elSource = Util.GetElementFromContextObject(rep);
            else elSource = srcEl;
            if (elSource == null) return null;
            var diaObjSource = Util.GetDiagramObjectById(rep, dia, elSource.ElementID);
            //diaObjSource = dia.GetDiagramObjectByID(elSource.ElementID, "");

            string noValifTypes = "Note, Constraint, Boundary, Text, UMLDiagram, DiagramFrame";
            if (noValifTypes.Contains(elSource.Type)) return null;


            if (elSource.ParentID != 0)
            {
                Util.GetDiagramObjectById(rep, dia, elSource.ParentID);
                //diaObjParent = dia.GetDiagramObjectByID(elSource.ParentID, "");
            }

            try
            {
                if (elSource.ParentID > 0)
                {
                    elParent = rep.GetElementByID(elSource.ParentID);
                    elTarget = (Element) elParent.Elements.AddNew(name, basicType);
                    if (basicType == "StateNode") elTarget.Subtype = Convert.ToInt32(extension);
                    elParent.Elements.Refresh();
                }
                else
                {
                    var pkg = rep.GetPackageByID(elSource.PackageID);
                    elTarget = (Element) pkg.Elements.AddNew(name, basicType);
                    if (basicType == "StateNode") elTarget.Subtype = Convert.ToInt32(extension);
                    pkg.Elements.Refresh();
                }
                elTarget.ParentID = elSource.ParentID;
                elTarget.Update();
                if (basicType == "Activity" & extension.ToLower() == "comp=yes")
                {
                    Diagram actDia = ActivityPar.CreateActivityCompositeDiagram(rep, elTarget);
                    Util.SetActivityCompositeDiagram(rep, elTarget, actDia.DiagramID.ToString());
                    //elTarget.
                }
            }
            catch
            {
                return null;
            }

            int left = diaObjSource.left + offsetHorizental;
            int right = diaObjSource.right + offsetHorizental;
            int top = diaObjSource.top + offsetVertical;
            int bottom = diaObjSource.bottom + offsetVertical;
            int length;

            if (basicType == "StateNode")
            {
                left = left - 10 + (right - left)/2;
                right = left + 20;
                top = bottom - 20;
                bottom = top - 20;
            }
            if ((basicType == "Decision") | (basicType == "MergeNode"))
            {
                if (guardString == "no")
                {
                    if (elSource.Type == "Decision") left = left + (right - left) + 200;
                    else left = left + (right - left) + 50;
                    bottom = bottom - 5;
                }
                left = left - 15 + (right - left)/2;
                right = left + 30;
                top = bottom - 20;
                bottom = top - 40;
            }
            if (basicType == "Action" | basicType == "Activity")
            {
                length = name.Length*widthPerCharacter/10;

                if (extension.ToLower() == "comp=no")
                {
                    /* Activity ind diagram */
                    if (length < 500) length = 500;
                    left = left + ((right - left)/2) - (length/2);
                    right = left + length;
                    top = bottom - 20;
                    bottom = top - 200;
                    if (basicType == "Activity") bottom = top - 400;
                }
                else if (extension.ToLower() == "comp=yes")
                {
                    if (length < 220) length = 220;
                    left = left + ((right - left)/2) - (length/2);
                    right = left + length;
                    top = bottom - 40;
                    bottom = top - 40;
                }
                else
                {
                    if (length < 220) length = 220;
                    left = left + ((right - left)/2) - (length/2);
                    right = left + length;
                    top = bottom - 20;
                    bottom = top - 20;
                }
            }
            // limit values
            if (left < 5) left = 5;
            string position = "l=" + left + ";r=" + right + ";t=" + top + ";b=" + bottom + ";";
            // end note
            if (elParent != null && elParent.Type == "Activity" && extension == "101")
            {
                DiagramObject diaObj = Util.GetDiagramObjectById(rep, dia, elParent.ElementID);
                //EA.DiagramObject diaObj = dia.GetDiagramObjectByID(elParent.ElementID,"");
                if (diaObj != null)
                {
                    diaObj.bottom = bottom - 40;
                    diaObj.Update();
                }
            }


            Util.AddSequenceNumber(rep, dia);
            var diaObjTarget = (DiagramObject) dia.DiagramObjects.AddNew(position, "");
            diaObjTarget.ElementID = elTarget.ElementID;
            diaObjTarget.Sequence = 1;
            diaObjTarget.Update();
            Util.SetSequenceNumber(rep, dia, diaObjTarget, "1");

            // position the label:
            // LBL=CX=180:  length of label
            // CY=13:       hight of label
            // OX=26:       x-position of label (relative object)
            // CY=13:       y-position of label (relative object)
            if (basicType == "Decision" & name.Length > 0)
            {
                if (name.Length > 25) length = 25*widthPerCharacter/10;
                else length = name.Length*widthPerCharacter/10;
                // string s = "DUID=E2352ABC;LBL=CX=180:CY=13:OX=29:OY=-4:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;;"; 
                string s = "DUID=E2352ABC;LBL=CX=180:CY=13:OX=-" + length +
                           ":OY=-4:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;;";
                Util.SetDiagramObjectLabel(rep,
                    diaObjTarget.ElementID, diaObjTarget.DiagramID, diaObjTarget.InstanceID, s);
            }

            if (extension == "Comp=no")
            {
                /* Activity ind diagram */
                // place an init
                int initLeft = left + ((right - left)/2) - 10;
                int initRight = initLeft + 20;
                int initTop = top - 25;
                int initBottom = initTop - 20;
                string initPosition = "l=" + initLeft + ";r=" + initRight + ";t=" + initTop + ";b=" + initBottom + ";";
                ActivityPar.CreateInitFinalNode(rep, dia,
                    elTarget, 100, initPosition);
            }

            // draw a Control Flow
            var con = (Connector) elSource.Connectors.AddNew("", "ControlFlow");
            con.SupplierID = elTarget.ElementID;
            con.Update();
            elSource.Connectors.Refresh();
            // set line style LV
            foreach (DiagramLink link in dia.DiagramLinks)
            {
                if (link.ConnectorID == con.ConnectorID)
                {
                    if (guardString != "no")
                    {
                        link.Geometry =
                            "EDGE=3;$LLB=;LLT=;LMT=;LMB=CX=21:CY=13:OX=-20:OY=-19:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:DIR=0:ROT=0;LRT=;LRB=;IRHS=;ILHS=;";
                    }
                    // in case of switch case line style = LH
                    string style = "LV";
                    if ((elSource.Type == "Action" | elSource.Type == "Activity") & guardString == "no") style = "LH";
                    if (Regex.IsMatch(elSource.Name, @"switch[\s]*\(")) style = "OS";
                    Util.SetLineStyleForDiagramLink(style, link);

                    break;
                }
            }


            // set Guard
            if (guardString != "")
            {
                if (guardString == "no" && elSource.Type != "Decision")
                {
                    // mo GUARD
                }
                else
                {
                    // GUARD
                    Util.SetConnectorGuard(rep, con.ConnectorID, guardString);
                }
            }
            else if (elSource.Type.Equals("Decision") & !elSource.Name.Trim().Equals(""))
            {
                if (guardString == "no")
                {
                    Util.SetConnectorGuard(rep, con.ConnectorID, "no");
                }
                else
                {
                    Util.SetConnectorGuard(rep, con.ConnectorID, "yes");
                }
            }

            // handle subtypes of action
            if (type == "CallOperation")
            {
                Method method = CallOperationAction.GetMethodFromMethodName(rep, extension);
                if (method != null)
                {
                    CallOperationAction.CreateCallAction(rep, elTarget, method);
                }
            }

            rep.ReloadDiagram(dia.DiagramID);

            // set selected object
            dia.SelectedObjects.AddNew(diaObjTarget.ElementID.ToString(), diaObjTarget.ObjectType.ToString());
            dia.SelectedObjects.Refresh();
            return diaObjTarget;
        }
        // ReSharper disable once UnusedMember.Local
        private static void MakeNested(Repository rep)
        {
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            int count = dia.SelectedObjects.Count;
            if (count < 2) return;

            rep.SaveDiagram(dia.DiagramID);

            // target object/element

            ObjectType objType = rep.GetContextItemType();
            if (!(objType.Equals(ObjectType.otElement))) return;

            var trgEl = (Element) rep.GetContextObject();
            if (!(trgEl.Type.Equals("Activity")))
            {
                MessageBox.Show($"Target '{trgEl.Name}:{trgEl.Type}' isn't an Activity",
                    @" Only move below Activity is allowed");
                return;
            }
            for (int i = 0; i < count; i = i + 1)
            {
                var srcObj = (DiagramObject) dia.SelectedObjects.GetAt((short) i);
                var srcEl = rep.GetElementByID(srcObj.ElementID);
                if (srcEl.ElementID == trgEl.ElementID) continue;
                srcEl.ParentID = trgEl.ElementID;
                srcEl.Update();
            }
        }
        /* Generate the IDL for an attribute.
         * The attribute can appear by itself, a sequence, or an array.
         * The determination of this is based on the settings of LowerBound and UpperBound
         *
         *    UpperBound == 0                 ==>  Unbounded Sequence
         *    LowerBound == UpperBound == 1        ==>  Single member (no Array/Sequence)
         *    LowerBound == 0 && UpperBound == 1   ==>  Optional single member
         *
         *    LowerBound  < UpperBound  (other values)    ==>  Bounded Sequence
         *    LowerBound == UpperBound  (other values)    == > Array
         *
         * returns true if it outputs some attribute; otherwise returns false
         */
        private static bool GenIDL_Attributes(Repository repository, Element classElem, TextOutputInterface output, int depth)
        {
            if (classElem.Attributes.Count == 0)
            {
                return false;
            }

            foreach (EA.Attribute child in classElem.Attributes)
            {
                // This does not get the fully qualified type name. We need that to fully resolve
                // the type in the IDL...
                String typeName;

                /* This code was trying to get the fully-qualified name but it throws an exception
                 */
                if ( child.ClassifierID == 0 ) {
                    typeName = IDL_NormalizeMemberTypeNameClassiffiedID0(child.Type);
                }
                else {
                    Element attributeType = repository.GetElementByID(child.ClassifierID);
                    Package attributePackage = repository.GetPackageByID(attributeType.PackageID);
                    typeName = GenIDL_GetFullPackageName(repository, attributeType)
                        + IDL_NormalizeMemberTypeName(attributeType.Name);
                }

                //DEBUG::
                if (typeName.Equals("dateTime") )
                {
                    output.OutputTextLine(depth, "//DEBUG: typeName= " + typeName + " classifiedId= " + child.ClassifierID);
                }

                int lower  = 0;
                int upper  = 0;
                try {
                    lower = Convert.ToInt32(child.LowerBound);
                } catch (Exception) {}
                try {
                    upper = Convert.ToInt32(child.UpperBound);
                } catch (Exception) { }

                int attributeDepth = depth;

                String effectiveTypeName   = typeName;
                String effectiveMemberName = child.Name;
                String extraAnnotation = null;
                if (upper == 0) // Unbounded sequence
                {
                    //output.OutputText(attributeDepth, "sequence<" + typeName + "> " + child.Name + ";");
                    effectiveTypeName = "sequence<" + typeName + ">";
                    if (idlMappingDetail >= IDLMappingDetail.IDL_DETAILS_FULL)
                    {
                        output.OutputTextLine(depth, "// Mapping to unbounded sequence because (upper bound == 0)");
                    }

                }
                else if (lower == upper)
                {
                    if (upper != 1)  // Array
                    {
                        effectiveMemberName = child.Name + "[" + child.UpperBound + "]";
                        if (idlMappingDetail >= IDLMappingDetail.IDL_DETAILS_FULL)
                        {
                            output.OutputTextLine(depth, "// Mapping to array because (lower bound == upper bound)");
                        }
                    }
                }
                else if (lower == 0 && upper == 1)
                {
                    // Handle this the same as an @optional annotation
                    extraAnnotation = "Optional";
                    if (idlMappingDetail >= IDLMappingDetail.IDL_DETAILS_FULL)
                    {
                        output.OutputTextLine(depth, "// Mapping to optional because (lower bound == 0 && upper bound == 1)");
                    }

                }
                else // bounded sequence
                {
                    effectiveTypeName = "sequence<" + typeName + "," + child.UpperBound + ">";
                    if (idlMappingDetail >= IDLMappingDetail.IDL_DETAILS_FULL)
                    {
                        output.OutputTextLine(depth, "// Mapping to bounded sequence because (lower bound < upper bound)");
                    }
                }

                GenIDL_AttributeWithAnnotations(child, effectiveTypeName, effectiveMemberName, extraAnnotation, output, depth);
                output.OutputTextLine();
            }

            return true;
        }
 public IUmlDataType GetDataTypeById(int id)
 {
     return(new EaUmlClassifier(eaRepository, eaRepository.GetElementByID(id)));
 }
        /// <summary>
        /// Locate the type for Connector, Method, Attribute, Diagram, Element, Package
        /// </summary>
        /// <param name="rep"></param>
        public static void LocateType(Repository rep)
        {
            ObjectType oType = rep.GetContextItemType();
            Element el;
            int id;
            string triggerGuid;
            // connector
            // links to trigger
            switch (oType)
            {
                case ObjectType.otConnector:
                    var con = (Connector) rep.GetContextObject();
                    triggerGuid = Util.GetTrigger(rep, con.ConnectorGUID);
                    if (triggerGuid.StartsWith("{", StringComparison.Ordinal) &&
                        triggerGuid.EndsWith("}", StringComparison.Ordinal))
                    {
                        Element trigger = rep.GetElementByGuid(triggerGuid);

                        if (trigger != null) rep.ShowInProjectView(trigger);
                    }
                    else
                    {
                        SelectBehaviorFromConnector(rep, con, DisplayMode.Method);
                    }
                    break;


                case ObjectType.otMethod:
                    var m = (Method) rep.GetContextObject();
                    if (m.ClassifierID != "")
                    {
                        id = Convert.ToInt32(m.ClassifierID);
                        // get type
                        if (id > 0)
                        {
                            el = rep.GetElementByID(id);
                            rep.ShowInProjectView(el);
                        }
                    }
                    break;

                case ObjectType.otAttribute:
                    var attr = (EA.Attribute) rep.GetContextObject();
                    id = attr.ClassifierID;
                    // get type
                    if (id > 0)
                    {
                        el = rep.GetElementByID(attr.ClassifierID);
                        if (el.Type.Equals("Package"))
                        {
                            Package pkg = rep.GetPackageByID(Convert.ToInt32(el.MiscData[0]));
                            rep.ShowInProjectView(pkg);
                        }
                        else
                        {
                            rep.ShowInProjectView(el);
                        }
                    }
                    break;

                // Locate Diagram (e.g. from Search Window)
                case ObjectType.otDiagram:
                    var d = (Diagram) rep.GetContextObject();
                    rep.ShowInProjectView(d);
                    break;


                case ObjectType.otElement:
                    el = (Element) rep.GetContextObject();
                    if (el.ClassfierID > 0)
                    {
                        el = rep.GetElementByID(el.ClassfierID);
                        rep.ShowInProjectView(el);
                    }
                    else
                    {
//MiscData(0) PDATA1,PDATA2,
                        // pdata1 Id for parts, UmlElement
                        // object_id   for text with Hyper link to diagram

                        // locate text or frame
                        if (LocateTextOrFrame(rep, el)) return;

                        string guid = el.MiscData[0];
                        if (guid.EndsWith("}", StringComparison.Ordinal))
                        {
                            el = rep.GetElementByGuid(guid);
                            rep.ShowInProjectView(el);
                        }
                        else
                        {
                            if (el.Type.Equals("Action"))
                            {
                                foreach (CustomProperty custproperty in el.CustomProperties)
                                {
                                    if (custproperty.Name.Equals("kind") && custproperty.Value.Contains("AcceptEvent"))
                                    {
                                        // get the trigger
                                        triggerGuid = Util.GetTrigger(rep, el.ElementGUID);
                                        if (triggerGuid.StartsWith("{", StringComparison.Ordinal) &&
                                            triggerGuid.EndsWith("}", StringComparison.Ordinal))
                                        {
                                            Element trigger = rep.GetElementByGuid(triggerGuid);
                                            rep.ShowInProjectView(trigger);
                                            break;
                                        }
                                    }
                                }
                            }
                            if (el.Type.Equals("Trigger"))
                            {
                                // get the signal
                                string signalGuid = Util.GetSignal(rep, el.ElementGUID);
                                if (signalGuid.StartsWith("RefGUID={", StringComparison.Ordinal))
                                {
                                    Element signal = rep.GetElementByGuid(signalGuid.Substring(8, 38));
                                    rep.ShowInProjectView(signal);
                                }
                            }

                            if (el.Type.Equals("RequiredInterface") || el.Type.Equals("ProvidedInterface"))
                            {
                                rep.ShowInProjectView(el);
                            }
                        }
                    }
                    break;

                case ObjectType.otPackage:
                    var pkgSrc = (Package) rep.GetContextObject();
                    Package pkgTrg = Util.GetModelDocumentFromPackage(rep, pkgSrc);
                    if (pkgTrg != null) rep.ShowInProjectView(pkgTrg);
                    break;
            }
        }
        static void CopyReleaseInfoOfModule(Repository rep)
        {
            Diagram dia = rep.GetCurrentDiagram();
            if (dia == null) return;
            if (!rep.GetContextItemType().Equals(ObjectType.otElement)) return;
            var elSource = (Element) rep.GetContextObject();
            if (elSource.Type != "Component") return;

            Util.GetDiagramObjectById(rep, dia, elSource.ElementID);
            //diaObjSource = dia.GetDiagramObjectByID(elSource.ElementID, "");

            string txt = "";
            string nl = "";
            foreach (DiagramObject obj in dia.DiagramObjects)
            {
                var elTarget = rep.GetElementByID(obj.ElementID);
                if (!("Class Interface".Contains(elTarget.Type))) continue;
                txt = txt + nl + AddReleaseInformation(rep, elTarget);
                nl = "\r\n";
            }
            Clipboard.SetText(txt);
        }
        /**
         * Determines if the association to the referenced type is such that the referenced type
         * should be included as part of the referencing type.
         *
         * Returns the fully qualified normalized name for the referenced type in case it needs to be included
         * and null if it does need to be included
         */
        private static String GenIDL_GetReferencedTypeToInclude(out String annotation, out String refname,
            Repository repository,
            Element classElem, EA.Connector conn, TextOutputInterface output)
        {
            annotation = "";
            refname = conn.Name;

            string[] relevantConnectorTypes = new string[] { "Aggregation" };

            if (!relevantConnectorTypes.Contains(conn.Type))
            {
                return null;
            }

            ConnectorEnd target = conn.SupplierEnd;
            ConnectorEnd source = conn.ClientEnd;
            /*
              output.OutputTextLine("GenIDL_GetReferencedTypeToInclude type: " + conn.Type
                + " source/target.Aggr: [" + source.Aggregation + "," + target.Aggregation + "]"
                + " direction: " + conn.Direction
                + " cardinality: [" + conn.SupplierEnd.Cardinality + "|" + conn.ClientEnd.Cardinality + "]");
            */

            String refTypeName = null;
            Element referencedElem = null;
            String cardinality = null;

            ConnectorEnd thisElemEnd;
            ConnectorEnd referencedElemEnd;
            int referencedElemId;

            if (classElem.ElementID == conn.ClientID)
            {
                thisElemEnd = conn.ClientEnd;
                referencedElemEnd = conn.SupplierEnd;
                referencedElemId = conn.SupplierID;
            }
            else
            {
                thisElemEnd = conn.SupplierEnd;
                referencedElemEnd = conn.ClientEnd;
                referencedElemId = conn.ClientID;
            }

            if (   (thisElemEnd.Aggregation == 0)
                || (referencedElemEnd.IsNavigable == false) )
            {
                return null; ;
            }

            referencedElem = repository.GetElementByID(referencedElemId);
            cardinality = referencedElemEnd.Cardinality;

            /*
            if (classElem.ElementID == conn.ClientID)
            {
                // We are source of relationship
                //output.OutputTextLine("GenIDL_GetReferencedTypeToInclude source.Aggregation: " + source.Aggregation);

                if ( (source.Aggregation != 0)
                        && ( conn.Direction.Equals("Source -> Destination") ||
                             conn.Direction.Equals("Bi-Directional")) )
                {
                    //output.OutputTextLine("GenIDL_GetReferencedTypeToInclude GetElementByID: " + conn.SupplierID);
                    referencedElem = repository.GetElementByID(conn.SupplierID);
                    cardinality = conn.SupplierEnd.Cardinality;
                }
            }
            else
            {
                //output.OutputTextLine("GenIDL_GetReferencedTypeToInclude target.Aggregation: " + target.Aggregation);

                if ( (target.Aggregation != 0)
                         && ( conn.Direction.Equals("Destination -> Source") ||
                              conn.Direction.Equals("Bi-Directional")) )
                {
                    //output.OutputTextLine("GenIDL_GetReferencedTypeToInclude GetElementByID: " + conn.ClientID);
                    referencedElem = repository.GetElementByID(conn.ClientID);
                    cardinality = conn.ClientEnd.Cardinality;
                }
            }
            */

            if (referencedElem != null)
            {
                String normalizedMemberType = IDL_NormalizeMemberTypeName(referencedElem.Name);

                if (refname.Equals(""))
                {
                    refname = "ref_" + normalizedMemberType;
                }

                refTypeName = GenIDL_GetFullPackageName(repository, referencedElem) + normalizedMemberType;

                if (cardinality.Equals("") || cardinality.Equals("1"))
                {
                    // annotation = "//@Shared";
                    refTypeName =  refTypeName + "*";
                }
                else if (cardinality.Equals("*") || cardinality.EndsWith("..*"))
                {
                    // No upper limit -> unbounded sequence
                    refTypeName = "sequence<" + refTypeName + ">";
                }
                else
                {
                    // Bounded sequence
                    int upperLimit = 0;
                    if (Int32.TryParse(cardinality, out upperLimit))
                    {
                        if (upperLimit <= 0) { upperLimit = 1; }
                        refTypeName = "sequence<" + refTypeName + "," + upperLimit + ">";
                    }
                    else
                    {
                        int limitPos = cardinality.LastIndexOf("..");
                        if ((limitPos != -1) &&
                              Int32.TryParse(cardinality.Substring(limitPos + 2), out upperLimit))
                        {
                            refTypeName = "sequence<" + refTypeName + "," + upperLimit + ">";
                        }
                        else
                        {
                            refTypeName = "sequence<" + refTypeName + ">";
                        }
                    }
                }
            }

            return refTypeName;
        }
        /// <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);
            }
           
        }
Example #55
0
        private void ConvertAttributes(Element el, XElement f, Repository repository, string unikId)
        {
            //arv først alle arvede attributter
            foreach (Connector connector in el.Connectors)
            {
                //
                if (connector.MetaType == "Generalization")
                {
                    Element elm = repository.GetElementByID(connector.SupplierID);
                    if (el.Name != elm.Name) //Kan ikke arve seg selv
                    {
                        LogDebug("Arver: " + elm.Name + " på " + el.Name);
                        ConvertAttributes(elm, f, repository, unikId);
                    }
                }
            }

            foreach (global::EA.Attribute att in el.Attributes)
            {
                try
                {
                    LogDebug("Attributt: " + att.Name + " på " + el.Name);
                    //
                    Boolean kjentType = false;
                    foreach (KjentType kt in KjenteTyper)
                    {
                        if (kt.Navn == att.Type)
                        {
                            kjentType = true;
                            //
                            string verdi = "kjenttype TODO";
                            if (kt.Datatype == "CharacterString")
                            {
                                verdi = "Lorem ipsum";
                            }
                            if (kt.Datatype == "Real")
                            {
                                Random rnd = new Random();
                                double dbl = rnd.NextDouble();
                                verdi = dbl.ToString();
                            }
                            if (kt.Navn == "Link")
                            {
                                verdi = "http://kartverket.no/Standarder/SOSI/";
                            }
                            if (kt.Navn == "Organisasjonsnummer")
                            {
                                verdi = "87654321";
                            }
                            addAttributes(f, att, verdi);
                        }
                    }
                    if (kjentType)
                    {
                        //Alt utført
                    }


                    // Typene i xsd-"format": http://www.arkitektum.no/files/sosi/StandardMapEntries_sosi.xml

                    else if (att.Type.ToLower() == "integer")
                    {
                        Random rnd     = new Random();
                        int    integer = rnd.Next(1, 13);

                        addAttributes(f, att, integer);
                    }
                    else if (att.Type.ToLower() == "characterstring")
                    {
                        string verdi = "Lorem ipsum";
                        if (att.Name.ToLower() == "lokalid")
                        {
                            verdi = unikId;
                        }

                        addAttributes(f, att, verdi);
                    }
                    else if (att.Type.ToLower() == "real") // double
                    {
                        Random rnd = new Random();
                        double dbl = rnd.NextDouble();
                        addAttributes(f, att, dbl);
                    }
                    else if (att.Type.ToLower() == "date")
                    {
                        addAttributes(f, att, DateTime.Now.ToString("yyyy-MM-dd"));
                    }
                    else if (att.Type.ToLower() == "datetime")
                    {
                        addAttributes(f, att, DateTime.Now.ToLocalTime());
                    }
                    else if (att.Type.ToLower() == "boolean")
                    {
                        addAttributes(f, att, "true");
                    }

                    else if (att.Type.ToLower() == "flate") // gml:SurfacePropertyType
                    {
                        addSurface(f, att);
                    }
                    else if (att.Type.ToLower() == "punkt") // gml:PointPropertyType
                    {
                        addPoint(f, att);
                    }
                    else if (att.Type.ToLower() == "sverm") // gml:MultiPointPropertyType
                    {
                        addPointCloud(f, att);
                    }
                    else if (att.Type.ToLower() == "kurve") // gml:CurvePropertyType
                    {
                        addCurve(f, att);
                    }
                    else if (att.Type.ToLower() == "gm_solid")
                    {
                        addSolid(f, att);
                    }
                    else if (att.ClassifierID != 0)
                    {
                        Element attel = repository.GetElementByID(att.ClassifierID);
                        if (attel.Stereotype.ToLower() == "codelist" || attel.Stereotype.ToLower() == "enumeration" || attel.Type.ToLower() == "enumeration")
                        {
                            if (attel.Attributes.Count > 0)
                            {
                                Random rnd = new Random();
                                int    pos = rnd.Next(0, attel.Attributes.Count - 1);
                                global::EA.Attribute tmp = attel.Attributes.GetAt((short)pos);
                                string verdi             = tmp.Default;
                                if (String.IsNullOrEmpty(verdi))
                                {
                                    verdi = tmp.Name;
                                }
                                XElement a = new XElement(_app + att.Name, verdi);
                                //hvis asDictionary=true legge inn codespace
                                if (GetTaggedValueFromElement(attel, "asDictionary") == "true")
                                {
                                    string kodeliste = GetTaggedValueFromAttribute(att, "defaultCodespace");
                                    if (String.IsNullOrEmpty(kodeliste))
                                    {
                                        kodeliste = GetTaggedValueFromElement(attel, "codelist");
                                    }
                                    if (String.IsNullOrEmpty(kodeliste))
                                    {
                                        kodeliste = "ingen url angitt";
                                    }
                                    a.Add(new XAttribute("codeSpace", kodeliste));
                                }
                                if (geoUtil.IsMultippel(att.LowerBound + ".." + att.UpperBound))
                                {
                                    for (int i = 0; i < 3; i++)
                                    {
                                        f.Add(a);
                                    }
                                }
                                else
                                {
                                    f.Add(a);
                                }
                            }
                            else
                            {
                                XElement a = new XElement(_app + att.Name, "ingen koder i kodeliste");
                                f.Add(a);
                            }
                        }
                        else
                        {
                            if (geoUtil.IsMultippel(att.LowerBound + ".." + att.UpperBound))
                            {
                                for (int i = 0; i < 3; i++)
                                {
                                    XElement a = new XElement(_app + att.Name);
                                    XElement b = new XElement(_app + attel.Name);
                                    a.Add(b);
                                    f.Add(a);
                                    ConvertAttributes(attel, b, repository, unikId);
                                }
                            }
                            else
                            {
                                XElement a = new XElement(_app + att.Name);
                                XElement b = new XElement(_app + attel.Name);
                                a.Add(b);
                                f.Add(a);
                                ConvertAttributes(attel, b, repository, unikId);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log("FEIL: I objekt " + el.Name + " " + ex.Message);
                }
            }

            foreach (Connector connector in el.Connectors)
            {
                try
                {
                    //BUG kommer ut feil rekkefølge ifht shapechange på noen få tilfeller, har direction noe å si her?

                    //
                    if ((connector.MetaType == "Association" || connector.MetaType == "Aggregation") && connector.Stereotype.ToLower() != "topo")
                    {
                        Element source      = repository.GetElementByID(connector.SupplierID);
                        Element destination = repository.GetElementByID(connector.ClientID);
                        if (connector.SupplierID == connector.ClientID) //Selvassosiasjon
                        {
                            addClientEnd(f, repository, unikId, connector, destination);
                            addSupplierEnd(f, repository, unikId, connector, source);
                        }
                        else if (el.Name == source.Name) //Er Supplier siden
                        {
                            addClientEnd(f, repository, unikId, connector, destination);
                        }
                        else //Er destination/Client siden
                        {
                            addSupplierEnd(f, repository, unikId, connector, source);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log("FEIL: I objekt " + el.Name + " og en av relasjonene " + ex.Message);
                }
            }
        }
Example #56
0
        public void handleElementDeletion(Repository repository, int elementID)
        {
            try
            {
                changed = false;
                EA.Element element = repository.GetElementByID(elementID);

                PropertyChange modelChange = new PropertyChange();
                modelChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                modelChange.itemGUID = element.ElementGUID;
                modelChange.elementType = itemTypes.getElementType(element.ElementGUID); ;
                modelChange.elementDeleted = 1;

                changeService.saveChange(modelChange);

                if (element.Type == "UseCase")
                {
                    currentExtensionPoints.Remove(element.ElementGUID);
                }
            }
            catch (Exception ex) { }
        }
        /**
         * Checks that all the definitions this class depends on are already generated
         * This includes the base classes as well as any types that appear as
         * attributes and are not marked "@Shared"
         *
         */
        private static bool GenIDL_DependenciesAlreadyGenerated(Repository repository, Element classElem,
            TextOutputInterface output, HashSet<long> completedClasses, bool outputReport)
        {
            //output.OutputTextLine("// GenIDL_DependenciesAlreadyGenerated Checking: " + classElem.Name);

            // Check base classes
            if (classElem.BaseClasses.Count > 0)
            {
                Object obj = classElem.BaseClasses.GetAt(0);
                Element elem = (Element)obj;
                if (!completedClasses.Contains(elem.ElementID))
                {
                    if (outputReport)
                    {
                        output.OutputText("    ( \"" + GenIDL_GetFullPackageName(repository, classElem) + "\" , \"" + classElem.Name + "\" )");
                        output.OutputText("  depends on  ( " + GenIDL_GetFullPackageName(repository, elem) + "\" , \"" + elem.Name + "\" )");
                        output.OutputTextLine("  dependency: baseclass");
                    }
                    return false;
                }
            }

            // Check atributes
            foreach (EA.Attribute child in classElem.Attributes)
            {
               if (child.ClassifierID == 0) /* Primitive type */
                {
                    continue;
                }
                if (!completedClasses.Contains(child.ClassifierID))
                {
                    // Not generated yet. It is only OK if this is by reference
                    if ( !IsAttributeReference(child) )
                    {
                        if (outputReport)
                        {
                            Element childTypeElem = repository.GetElementByID(child.ClassifierID);
                            output.OutputText("    ( \"" + GenIDL_GetFullPackageName(repository, classElem) + "\" , \"" + classElem.Name + "\" )");
                            output.OutputText("  depends on  ( " + GenIDL_GetFullPackageName(repository, childTypeElem) + "\" , \"" + childTypeElem.Name + "\" )");
                            output.OutputTextLine("   dependency:  attribute \"" + child.Name + "\"");
                        }

                        return false;
                    }
                }
            }

            // Check relationships (Aggregations only)
            String explanation;
            foreach (EA.Connector conn in classElem.Connectors)
            {
                ConnectorEnd thisElemEnd;
                ConnectorEnd referencedElemEnd;
                int referencedElemId;
                Element referencedElem;
                bool includeReferencedTypeAsMember;
                String memberName;
                bool includeAsReference;

                // Resolve the reference but ommit any explanatory text
                GenIDL_ReferenceDescriptor(repository, conn, classElem.ElementID, false,
                                            out thisElemEnd, out referencedElemEnd, out referencedElemId, out referencedElem,
                                            out memberName, out includeAsReference,
                                            out includeReferencedTypeAsMember, out explanation);

                // If the reference did not have to be included, there there is no dependency on it.
                if ( includeReferencedTypeAsMember == false ) {
                    continue;
                }

                // If we are here then the referenced element must appear as a member. There is a depedency so we must make sure
                // that that class has already been generated
                if (!completedClasses.Contains(referencedElemId))
                {
                    if (outputReport)
                    {
                        output.OutputText("    ( \"" + GenIDL_GetFullPackageName(repository, classElem) + "\" , \"" + classElem.Name + "\" )");
                        output.OutputText("  depends on  ( " + GenIDL_GetFullPackageName(repository, referencedElem) + "\" , \"" + referencedElem.Name + "\" )");
                        output.OutputTextLine("   dependency:  aggregation \"" + memberName + "\"");
                    }

                    return false;
                }
            }

            return true;
        }
Example #58
0
        public void handleAttributeCreation(Repository repository, int attributeID)
        {
            try
            {
                changed = false;
                EA.Attribute attribute = repository.GetAttributeByID(attributeID);
                EA.Element element = repository.GetElementByID(attribute.ParentID);

                ItemCreation itemCreation = new ItemCreation();
                itemCreation.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                itemCreation.itemGUID = attribute.AttributeGUID;
                itemCreation.parentGUID = element.ElementGUID;
                itemCreation.elementType = 90;
                itemCreation.name = attribute.Name;
                itemCreation.coordinates = attribute.Visibility;

                changeService.saveChange(itemCreation);

                currentAttributes.Add(attribute.AttributeGUID, attribute);
            }
            catch (Exception ex) { }
        }
        // display behavior or definition for selected element
        // enum displayMode: "Behavior" or "Method"
        public static void DisplayOperationForSelectedElement(Repository repository, DisplayMode showBehavior)
        {
            ObjectType oType = repository.GetContextItemType();
            // Method found
            if (oType.Equals(ObjectType.otMethod))
            {
                // display behavior for method
                Appl.DisplayBehaviorForOperation(repository, (Method) repository.GetContextObject());
            }
            if (oType.Equals(ObjectType.otDiagram))
            {
                // find parent element
                var dia = (Diagram) repository.GetContextObject();
                if (dia.ParentID > 0)
                {
                    // find parent element
                    Element parentEl = repository.GetElementByID(dia.ParentID);
                    //
                    LocateOperationFromBehavior(repository, parentEl, showBehavior);
                }
                else
                {
                    // open diagram
                    repository.OpenDiagram(dia.DiagramID);
                }
            }


            // Connector / Message found
            if (oType.Equals(ObjectType.otConnector))
            {
                var con = (Connector) repository.GetContextObject();
                SelectBehaviorFromConnector(repository, con, showBehavior);
            }

            // Element
            if (oType.Equals(ObjectType.otElement))
            {
                var el = (Element) repository.GetContextObject();
                // locate text or frame
                if (LocateTextOrFrame(repository, el)) return;

                if (el.Type.Equals("Activity") & showBehavior.Equals(DisplayMode.Behavior))
                {
                    // Open Behavior for Activity
                    Util.OpenBehaviorForElement(repository, el);
                }
                if (el.Type.Equals("State"))
                {
                    // get operations
                    foreach (Method m in el.Methods)
                    {
                        // display behaviors for methods
                        Appl.DisplayBehaviorForOperation(repository, m);
                    }
                }

                if (el.Type.Equals("Action"))
                {
                    foreach (CustomProperty custproperty in el.CustomProperties)
                    {
                        if (custproperty.Name.Equals("kind") && custproperty.Value.Equals("CallOperation"))
                        {
                            ShowFromElement(repository, el, showBehavior);
                        }
                        if (custproperty.Name.Equals("kind") && custproperty.Value.Equals("CallBehavior"))
                        {
                            el = repository.GetElementByID(el.ClassfierID);
                            Util.OpenBehaviorForElement(repository, el);
                        }
                    }
                }
                if (showBehavior.Equals(DisplayMode.Method) & (
                    el.Type.Equals("Activity") || el.Type.Equals("StateMachine") || el.Type.Equals("Interaction")))
                {
                    LocateOperationFromBehavior(repository, el, showBehavior);
                }
            }
        }
        private static bool UpdateTypeName(Repository rep, ref int classifierId, ref string parName, ref string parType)
        {
            // no classifier defined
            // check if type is correct
            Element el = null;
            if (!classifierId.Equals(0))
            {
                try
                {
                    el = rep.GetElementByID(classifierId);
                    if (el.Name != parType) el = null;
                }
                    // empty catch, el = null
#pragma warning disable RECS0022
                catch //(Exception e)
                {
                    // ignored
                }
#pragma warning restore RECS0022
            }

            if (el == null)
            {
                // get the type
                // find type from type_name
                classifierId = Util.GetTypeId(rep, parType);
                // type not defined
                if (classifierId == 0)
                {
                    if (parType.EndsWith("*", StringComparison.Ordinal))
                    {
                        parType = parType.Substring(0, parType.Length - 1);
                        parName = "*" + parName;
                    }
                    if (parType.EndsWith("*", StringComparison.Ordinal))
                    {
                        parType = parType.Substring(0, parType.Length - 1);
                        parName = "*" + parName;
                    }
                    classifierId = Util.GetTypeId(rep, parType);
                }

                if (classifierId != 0)
                {
                    return true;
                }
                parType = "";
                return true;
            }
            return false;
        }