Exemplo n.º 1
0
        /// <summary>
        /// Update source and target dependency parts.
        /// </summary>
        protected virtual void UpdateParts()
        {
            if (this.MainElement == null)
            {
                return;
            }

            DomainClassInfo elementInfo = this.MainElement.GetDomainClass();

            Dictionary <Guid, GraphicalDependencyShape> sParts = new Dictionary <Guid, GraphicalDependencyShape>();
            Dictionary <Guid, GraphicalDependencyShape> tParts = new Dictionary <Guid, GraphicalDependencyShape>();

            ReadOnlyCollection <ElementLink> links = DomainRoleInfo.GetAllElementLinks(this.MainElement);

            foreach (ElementLink link in links)
            {
                DomainRelationshipInfo info = link.GetDomainRelationship();
                if (this.Store.DomainDataAdvDirectory.IsReferenceIncludedInModel(info.Id))
                {
                    if (DomainRoleInfo.GetSourceRolePlayer(link) == this.MainElement)
                    {
                        UpdatePart(elementInfo.Id, tParts, true, link, info);
                    }
                    else
                    {
                        UpdatePart(elementInfo.Id, sParts, false, link, info);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static ModelElement GetCompartmentElementFirstParent(ModelElement modelElement)
        {
            // Get the domain class associated with model element.
            DomainClassInfo domainClass = modelElement.GetDomainClass();

            if (domainClass != null)
            {
                // A element is only considered to be in a compartment if it participates in only 1 embedding relationship
                // This might be wrong for some models

                if (domainClass.AllEmbeddedByDomainRoles.Count == 1)
                {
                    // Get a collection of all the links to this model element
                    // Since this is in a compartment there will only be one
                    ReadOnlyCollection <ElementLink> links = DomainRoleInfo.GetAllElementLinks(modelElement);
                    if (links.Count == 1)
                    {
                        // Get the model element participating in the link that isn't the current one
                        // That will be the parent
                        // Probably there is a better way to achieve the same result
                        foreach (ModelElement linkedElement in links[0].LinkedElements)
                        {
                            if (!modelElement.Equals(linkedElement))
                            {
                                return(linkedElement);
                            }
                        }
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Looks for compartment connections of Type CONNECTION on the compartment parent that have the
        /// compartment element as source or target and deletes this compartment connection from the model.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="element"></param>
        private void DeleteReferencesFromParentToChild(ModelElement parent, ModelElement element)
        {
            // i don't want to change my list inside the foreach loop
            List <ElementLink> toDelete = new List <ElementLink>();

            foreach (ElementLink link in DomainRoleInfo.GetAllElementLinks(parent))
            {
                if (link is CONNECTION)
                {
                    if ((DomainRoleInfo.GetSourceRolePlayer(link) == parent &&
                         element is SOURCE_COMPARTMENT_ENTRY &&
                         GetBuilderInstance().IsEntryConnectionSource(element as SOURCE_COMPARTMENT_ENTRY, (CONNECTION)link)) ||
                        (DomainRoleInfo.GetTargetRolePlayer(link) == parent &&
                         element is TARGET_COMPARTMENT_ENTRY &&
                         GetBuilderInstance().IsEntryConnectionTarget(element as TARGET_COMPARTMENT_ENTRY, (CONNECTION)link)))
                    {
                        toDelete.Add(link);
                    }
                }
            }

            // now do the deleting
            foreach (ElementLink link in toDelete)
            {
                link.Delete();
            }
        }
        /// <summary>
        /// This method is called when the rule is fired, that is when a compartment entry is deleting from the model.
        /// </summary>
        /// <param name="e">the ElementDeletingEventArgs</param>
        public override void ElementDeleting(ElementDeletingEventArgs e)
        {
            // it is not easy to find the compartment parent of a compartment entry
            if (e.ModelElement != null)
            {
                foreach (ElementLink link in DomainRoleInfo.GetAllElementLinks(e.ModelElement))
                {
                    // I have to find the ElementLink where the compartment entry is the target
                    if (DomainRoleInfo.GetTargetRolePlayer(link) == e.ModelElement)
                    {
                        // and check if this ElementLink is annotated with the DomainRelationshipAttribute
                        object[] attrs = link.GetType().GetCustomAttributes(typeof(DomainRelationshipAttribute), true);
                        if (attrs.Length > 0)
                        {
                            DomainRelationshipAttribute attr = attrs[0] as DomainRelationshipAttribute;
                            if (attr != null)
                            {
                                // and only if the DomainRelationshipAttribute is set to IsEmbedding == true
                                if (attr.IsEmbedding)  // follow only embedded links - there is only one embedded link with a concret class (the child) as target
                                {
                                    // finally we found the parent of the compartment entry
                                    ModelElement parent = DomainRoleInfo.GetSourceRolePlayer(link);

                                    // check all links from parent if anyone uses this child as source or target
                                    DeleteReferencesFromParentToChild(parent, e.ModelElement);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Processes a proto element representation of the element and adds required proto links.
        /// This method is called on base classes from derived classes.
        ///
        /// Hint: Properties do not need to be added in this method.
        /// </summary>
        /// <param name="protoElement">Proto element representation of the element.</param>
        /// <param name="protoGroup">Proto group the proto element belongs to.</param>
        public virtual void ModelProcessMergeCopy(ModelProtoElement protoElement, ModelProtoGroup protoGroup)
        {
            foreach (ElementLink link in DomainRoleInfo.GetAllElementLinks(this))
            {
                if (link is DomainModelLink)
                {
                    DomainModelLink modelLink           = link as DomainModelLink;
                    DomainRelationshipAdvancedInfo info = this.Store.DomainDataAdvDirectory.GetRelationshipInfo(modelLink.GetDomainClassId());
                    if (info is ReferenceRelationshipAdvancedInfo)
                    {
                        if (DomainRoleInfo.GetSourceRolePlayer(modelLink) == this)
                        {
                            if (!(info as ReferenceRelationshipAdvancedInfo).PropagatesCopyToTarget)
                            {
                                continue;
                            }
                        }
                        else
                        if (!(info as ReferenceRelationshipAdvancedInfo).PropagatesCopyToSource)
                        {
                            continue;
                        }

                        ModelProtoLink protoLink = new ModelProtoLink(link);
                        protoGroup.AddNewReferenceLink(protoLink);
                    }
                    else
                    {
                        DomainModelElement child = DomainRoleInfo.GetTargetRolePlayer(link) as DomainModelElement;
                        if (child == this || child == null)
                        {
                            continue;
                        }
                        if ((info as EmbeddingRelationshipAdvancedInfo).PropagatesCopyToChild)
                        {
                            if (!(info as EmbeddingRelationshipAdvancedInfo).IsTargetIncludedSubmodel)
                            {
                                ModelProtoLink protoLink = new ModelProtoLink(link);
                                protoGroup.AddNewEmbeddingLink(protoLink);
                                child.ModelCreateMergeCopy(protoGroup);
                            }
                            else if (child is IParentModelElement)
                            {
                                ModelProtoLink protoLink = new ModelProtoLink(link);
                                protoLink.IsTargetIncludedSubmodel = true;
                                protoLink.DomainFilePath           = (child as IParentModelElement).DomainFilePath;
                                protoGroup.AddNewReferenceLink(protoLink);
                            }
                        }
                    }
                }
            }

            /*
             * // process reference relationships
             * List<ReferenceRelationshipAdvancedInfo> infos = this.Store.DomainDataAdvDirectory.FindDomainClassSourceReferences(this.GetDomainClassId());
             * if (infos != null)
             *  foreach (ReferenceRelationshipAdvancedInfo info in infos)
             *  {
             *      if (info.PropagatesCopyToTarget)
             *      {
             *          System.Collections.ObjectModel.ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(this, info.SourceRoleId);
             *          foreach (ElementLink link in links)
             *          {
             *              ModelProtoLink protoLink = new ModelProtoLink(link);
             *              protoGroup.AddNewReferenceLink(protoLink);
             *          }
             *      }
             *  }
             * infos = this.Store.DomainDataAdvDirectory.FindDomainClassTargetReferences(this.GetDomainClassId());
             * if (infos != null)
             *  foreach (ReferenceRelationshipAdvancedInfo info in infos)
             *  {
             *      if (info.PropagatesCopyToSource)
             *      {
             *          System.Collections.ObjectModel.ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(this, info.TargetRoleId);
             *          foreach (ElementLink link in links)
             *          {
             *              ModelProtoLink protoLink = new ModelProtoLink(link);
             *              protoGroup.AddNewReferenceLink(protoLink);
             *          }
             *      }
             *  }
             *
             * // process embedding relationships
             * List<EmbeddingRelationshipAdvancedInfo> infosEmb = this.Store.DomainDataAdvDirectory.FindDomainClassSourceEmbeddings(this.GetDomainClassId());
             * if (infosEmb != null)
             *  foreach (EmbeddingRelationshipAdvancedInfo info in infosEmb)
             *  {
             *      if (info.PropagatesCopyToChild)
             *      {
             *          System.Collections.ObjectModel.ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(this, info.SourceRoleId);
             *          foreach (ElementLink link in links)
             *          {
             *              ModelProtoLink protoLink = new ModelProtoLink(link);
             *              protoGroup.AddNewEmbeddingLink(protoLink);
             *
             *              DomainModelElement child = DomainRoleInfo.GetTargetRolePlayer(link) as DomainModelElement;
             *              if( child != null )
             *                  child.ModelCreateMergeCopy(protoGroup);
             *          }
             *      }
             *  }
             */
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates the displayed dependencies based on filter information.
        /// </summary>
        public virtual void UpdateBasedOnFilter(GraphicalDependenciesFilterItem filterItem)
        {
            this.Store.UndoManager.UndoState = UndoState.DisabledNoFlush;
            using (Transaction t = this.Store.TransactionManager.BeginTransaction("", true))
            {
                if (filterItem.IsFiltered)
                {
                    // remove elements
                    for (int i = 0; i < this.Diagram.SourceDependencyShapes.Count; i++)
                    {
                        if (this.Diagram.SourceDependencyShapes[i].RelationshipTypeId == filterItem.RelationshipType &&
                            this.Diagram.SourceDependencyShapes[i].RelationshipTypeId != Guid.Empty)
                        {
                            RemoveHostShape(this.Diagram.SourceDependencyShapes[i]);
                            break;
                        }

                        if (this.Diagram.SourceDependencyShapes[i].CustomInfo == filterItem.CustomFilterInformation &&
                            !String.IsNullOrEmpty(this.Diagram.SourceDependencyShapes[i].CustomInfo))
                        {
                            RemoveHostShape(this.Diagram.SourceDependencyShapes[i]);
                            break;
                        }
                    }

                    for (int i = 0; i < this.Diagram.TargetDependencyShapes.Count; i++)
                    {
                        if (this.Diagram.TargetDependencyShapes[i].RelationshipTypeId == filterItem.RelationshipType &&
                            this.Diagram.TargetDependencyShapes[i].RelationshipTypeId != Guid.Empty)
                        {
                            RemoveHostShape(this.Diagram.TargetDependencyShapes[i]);
                            break;
                        }

                        if (this.Diagram.TargetDependencyShapes[i].CustomInfo == filterItem.CustomFilterInformation &&
                            !String.IsNullOrEmpty(this.Diagram.TargetDependencyShapes[i].CustomInfo))
                        {
                            RemoveHostShape(this.Diagram.TargetDependencyShapes[i]);
                            break;
                        }
                    }
                    UpdateLayout();
                }
                else
                {
                    // add elements
                    GraphicalDependencyShape hostShape = null;
                    bool bSource = true;

                    DomainClassInfo elementInfo            = this.MainElement.GetDomainClass();
                    ReadOnlyCollection <ElementLink> links = DomainRoleInfo.GetAllElementLinks(this.MainElement);
                    foreach (ElementLink link in links)
                    {
                        DomainRelationshipInfo info = link.GetDomainRelationship();
                        if (info.Id == filterItem.RelationshipType)
                        {
                            if (DomainRoleInfo.GetSourceRolePlayer(link) != this.MainElement)
                            {
                                bSource = false;
                            }

                            if (hostShape == null)
                            {
                                hostShape = CreateHostShape(link, info);

                                if (bSource)
                                {
                                    this.Diagram.TargetDependencyShapes.Add(hostShape);
                                }
                                else
                                {
                                    this.Diagram.SourceDependencyShapes.Add(hostShape);
                                }
                            }

                            if (bSource)
                            {
                                hostShape.AddNestedChild(CreateChildShape(link, true));
                            }
                            else
                            {
                                hostShape.AddNestedChild(CreateChildShape(link, false));
                            }
                        }
                    }

                    UpdateLayout();

                    if (hostShape != null)
                    {
                        UpdateLink(hostShape, !bSource);
                    }
                }

                t.Commit();
            }
            this.Store.UndoManager.UndoState = UndoState.Enabled;
        }