/// <summary>
        /// Verifies if a paste operation can be executed in the current context.
        /// </summary>
        /// <param name="rootElement">Root element, on which to paste the current data object's data.</param>
        /// <param name="dataObject">Data to be pasted.</param>
        /// <returns>True if paste can be executed. False otherwise.</returns>
        public static bool CanMerge(ModelElement rootElement, IDataObject dataObject)
        {
            if (rootElement is IModelMergeElements)
            {
                ModelProtoGroup group = GetModelProtoGroup(dataObject);
                if (group == null)
                {
                    return(false);
                }

                if (group.ProtoRootElements.Count == 0)
                {
                    return(false);
                }

                foreach (ModelProtoElement p in group.ProtoRootElements)
                {
                    if (!(rootElement as IModelMergeElements).ModelCanMerge(p, group))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Copies the given elements to the dataObject for the move operation.
        /// </summary>
        /// <param name="elements">Elements to copy.</param>
        /// <param name="dataObject">DataObject to add the data to.</param>
        /// <returns>DataObjects with the added data.</returns>
        public static IDataObject CopyToMove(ICollection <ModelElement> elements, IDataObject dataObject)
        {
            ModelProtoGroup protoGroup = new ModelProtoGroup(elements, ModelProtoGroupOperation.Move);

            dataObject.SetData(ModelProtoGroup.DefaultDataFormatName, protoGroup);
            dataObject.SetData(ModelProtoGroup.DefaultDataIdentifierName, Guid.NewGuid());
            return(dataObject);
        }
        /// <summary>
        /// Executes the paste operation.
        /// </summary>
        /// <param name="rootElement">Root element, on which to paste the current data object's data.</param>
        /// <param name="dataObject">Data to be pasted.</param>
        /// <returns>ValidationResult holding errors, warning or information messages.</returns>
        public static ValidationResult Merge(ModelElement rootElement, IDataObject dataObject)
        {
            if (!CanMerge(rootElement, dataObject))
            {
                return(null);
            }

            ModelProtoGroup       group       = GetModelProtoGroup(dataObject);
            ModelProtoGroupMerger protoMerger = new ModelProtoGroupMerger(group, rootElement);

            return(protoMerger.MergeResult);
        }
        /// <summary>
        /// Copies the given elements to the dataObject.
        /// </summary>
        /// <param name="elements">Elements to copy.</param>
        /// <param name="dataObject">DataObject to add the data to.</param>
        /// <returns>DataObjects with the added data.</returns>
        public static IDataObject Copy(ICollection <ModelElement> elements, IDataObject dataObject)
        {
            Guid guid = Guid.NewGuid();

            ModelProtoGroup protoGroup = new ModelProtoGroup(elements, ModelProtoGroupOperation.Copy);

            dataObject.SetData(ModelProtoGroup.DefaultDataFormatName, protoGroup);
            dataObject.SetData(ModelProtoGroup.DefaultDataIdentifierName, guid);

            // update cached prototype
            cachedPrototype = new CachedModelProtoGroup(guid, protoGroup);
            return(dataObject);
        }
예제 #5
0
        /// <summary>
        /// Decides whether the element that is represented by the proto element can be pasted or not.
        /// </summary>
        /// <param name="protoElement">Proto element representation of the element.</param>
        /// <param name="protoGroup">Proto group the proto element belongs to.</param>
        /// <returns>True if the element can be pasted. False otherwise.</returns>
        public virtual bool ModelCanMerge(ModelProtoElement protoElement, ModelProtoGroup protoGroup)
        {
            if (protoElement != null)
            {
                DomainClassInfo elementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(protoElement.DomainClassId);
                foreach (DomainRoleInfo info in elementDomainInfo.AllDomainRolesPlayed)
                {
                    if (!info.IsSource)
                    {
                        if (info.OppositeDomainRole.RolePlayer.Id == this.GetDomainClassId())
                        {
                            if (this.Store.DomainDataAdvDirectory.IsEmbeddingRelationship(info.DomainRelationship.Id) &&
                                !this.Store.DomainDataAdvDirectory.IsAbstractRelationship(info.DomainRelationship.Id))
                            {
                                if (info.OppositeDomainRole.Multiplicity == Multiplicity.One || info.OppositeDomainRole.Multiplicity == Multiplicity.ZeroOne)
                                {
                                    // Check that creating a link with this path doesn't cause multiplicity overflow
                                    if (DomainRoleInfo.GetLinkedElement(this, info.OppositeDomainRole.Id) != null)
                                    {
                                        return(false);
                                    }

                                    return(true);
                                }
                                else
                                {
                                    if (protoGroup.Operation == ModelProtoGroupOperation.Move)
                                    {
                                        foreach (ElementLink link in DomainRoleInfo.GetElementLinks <ElementLink>(this, info.OppositeDomainRole.Id))
                                        {
                                            if (DomainRoleInfo.GetTargetRolePlayer(link).Id == protoElement.ElementId)
                                            {
                                                return(false);
                                            }
                                        }
                                    }
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
예제 #6
0
        /// <summary>
        /// Create a proto element representation of the element, which can be used for paste later.
        /// </summary>
        /// <param name="protoGroup">Proto group to add the element to.</param>
        /// <returns>Proto element representation of the element.</returns>
        public virtual ModelProtoElement ModelCreateMoveCopy(ModelProtoGroup protoGroup)
        {
            if (protoGroup.Operation == ModelProtoGroupOperation.Move)
            {
                if (!ModelIsMoveAllowed())
                {
                    return(null);
                }
            }

            if (protoGroup.Operation == ModelProtoGroupOperation.Copy)
            {
                return(null);
            }

            ModelProtoElement protoElement = new ModelProtoElement(this);

            protoGroup.AddNewElement(protoElement);

            return(protoElement);
        }
예제 #7
0
        /// <summary>
        /// Deserialize.
        /// </summary>
        public void OnDeserialization(object sender)
        {
            elementId     = (Guid)serializationInfo.GetValue("elementId", typeof(Guid));
            domainClassId = (Guid)serializationInfo.GetValue("domainClassId", typeof(Guid));
            properties    = (System.Collections.ArrayList)serializationInfo.GetValue("properties", typeof(System.Collections.ArrayList));
            name          = (string)serializationInfo.GetValue("name", typeof(string));

            try
            {
                customChildGroup = (ModelProtoGroup)serializationInfo.GetValue("customChildGroup", typeof(ModelProtoGroup));
            }
            catch { }

            try
            {
                CustomArguments = serializationInfo.GetValue("customArguments", typeof(IModelMergeCustomArguments)) as IModelMergeCustomArguments;
            }
            catch
            {
            }
        }
        /// <summary>
        /// Deserialize.
        /// </summary>
        public void OnDeserialization(object sender)
        {
            elementId = (Guid)serializationInfo.GetValue("elementId", typeof(Guid));
            domainClassId = (Guid)serializationInfo.GetValue("domainClassId", typeof(Guid));
            properties = (System.Collections.ArrayList)serializationInfo.GetValue("properties", typeof(System.Collections.ArrayList));
            name = (string)serializationInfo.GetValue("name", typeof(string));

            try
            {
                customChildGroup = (ModelProtoGroup)serializationInfo.GetValue("customChildGroup", typeof(ModelProtoGroup));
            }
            catch { }

            try
            {
                CustomArguments = serializationInfo.GetValue("customArguments", typeof(IModelMergeCustomArguments)) as IModelMergeCustomArguments;
            }
            catch
            {
        }

        }
        /// <summary>
        /// Retrieves a model proto group from the given data object if one exists.
        /// </summary>
        /// <param name="dataObject">Data objects to retrieve a model proto group from.</param>
        /// <returns>ModelProtoGroup instance or null.</returns>
        public static ModelProtoGroup GetModelProtoGroup(IDataObject dataObject)
        {
            ModelProtoGroup group = null;

            if (dataObject.GetDataPresent(ModelProtoGroup.DefaultDataFormatName))
            {
                Guid guid = Guid.Empty;
                if (dataObject.GetDataPresent(ModelProtoGroup.DefaultDataIdentifierName))
                {
                    guid = (System.Guid)dataObject.GetData(ModelProtoGroup.DefaultDataIdentifierName);
                }

                if ((cachedPrototype != null) && guid == cachedPrototype.InstanceId)
                {
                    return(cachedPrototype.Prototype);
                }

                object obj = dataObject.GetData(ModelProtoGroup.DefaultDataFormatName);
                group           = obj as ModelProtoGroup;
                cachedPrototype = new CachedModelProtoGroup(guid, group);
            }

            return(group);
        }
        /// <summary>
        /// Create a proto element representation of the element, which can be used for paste later.
        /// </summary>
        /// <param name="protoGroup">Proto group to add the element to.</param>
        /// <returns>Proto element representation of the element.</returns>
        public virtual ModelProtoElement ModelCreateMoveCopy(ModelProtoGroup protoGroup)
        {
            if (protoGroup.Operation == ModelProtoGroupOperation.Move)
                if (!ModelIsMoveAllowed())
                    return null;

            if (protoGroup.Operation == ModelProtoGroupOperation.Copy)
                return null;

            ModelProtoElement protoElement = new ModelProtoElement(this);
            protoGroup.AddNewElement(protoElement);

            return protoElement;
        }
예제 #11
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);
             *          }
             *      }
             *  }
             */
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="instanceID"></param>
 /// <param name="prototype"></param>
 public CachedModelProtoGroup(Guid instanceID, ModelProtoGroup prototype)
 {
     this.instanceID = instanceID;
     this.prototype = prototype;
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="protoGroup">Proto group to paste/move.</param>
        /// <param name="rootElement">Element to execute paste/move on.</param>
        public ModelProtoGroupMerger(ModelProtoGroup protoGroup, ModelElement rootElement)
        {
            this.protoGroup = protoGroup;
            this.validationResult = new ValidationResult();

            this.idMapping = new Dictionary<Guid, Guid>();
            this.embeddingMapping = new Dictionary<Guid, List<ModelProtoElement>>();
            this.referencingMapping = new Dictionary<Guid, List<ModelProtoLink>>();
            this.referencingMappingTarget = new Dictionary<Guid, List<ModelProtoLink>>();
            this.elementMapping = new Dictionary<Guid, ModelProtoElement>();

            if (protoGroup.Operation == ModelProtoGroupOperation.Move)
            {
                // move element
                foreach (ModelProtoElement protoElement in protoGroup.ProtoRootElements)
                {
                    (rootElement as IModelMergeElements).ModelMove(protoElement, this);
                }
                return;
            }

            foreach (ModelProtoElement element in protoGroup.ProtoElements)
            {
                idMapping.Add(element.ElementId, Guid.Empty);
                embeddingMapping.Add(element.ElementId, new List<ModelProtoElement>());
                referencingMapping.Add(element.ElementId, new List<ModelProtoLink>());
                referencingMappingTarget.Add(element.ElementId, new List<ModelProtoLink>());
                elementMapping.Add(element.ElementId, element);
            }
            foreach (ModelProtoLink link in protoGroup.ProtoEmbeddingLinks)
            {
                ModelProtoRolePlayer rolePlayer = link.GetSourceRolePlayer(rootElement.Store.DefaultPartition);
                ModelProtoElement p = GetElementById(rolePlayer.RolePlayerId);
                if (p != null)
                {
                    embeddingMapping[p.ElementId].Add(
                       GetElementById(link.GetTargetRolePlayer(rootElement.Store.DefaultPartition).RolePlayerId));
                }
            }            

            foreach (ModelProtoLink link in protoGroup.ProtoReferenceLinks)
            {
                ModelProtoRolePlayer sourceRP = link.GetSourceRolePlayer(rootElement.Store.DefaultPartition);
                ModelProtoElement p = GetElementById(sourceRP.RolePlayerId);
                if (p != null)
                    referencingMapping[p.ElementId].Add(link);

                ModelProtoRolePlayer targetRP = link.GetTargetRolePlayer(rootElement.Store.DefaultPartition);
                p = GetElementById(targetRP.RolePlayerId);
                if (p != null)
                    referencingMappingTarget[p.ElementId].Add(link);
            }

            // start merging
            foreach (ModelProtoElement protoElement in protoGroup.ProtoRootElements)
            {
                (rootElement as IModelMergeElements).ModelMerge(protoElement, this, true);
            }

            // process reference relationships
            foreach (ModelProtoLink link in protoGroup.ProtoReferenceLinks)
            {
                ModelProtoRolePlayer sourceRP = link.GetSourceRolePlayer(rootElement.Store.DefaultPartition);
                if (this.idMapping.ContainsKey(sourceRP.RolePlayerId))
                {
                    System.Guid id = this.idMapping[sourceRP.RolePlayerId];
                    if (id != Guid.Empty)
                    {
                        ModelElement copiedModelElement = rootElement.Store.ElementDirectory.FindElement(id);
                        if (copiedModelElement != null)
                            if (copiedModelElement is IModelMergeElements)
                            {
                                (copiedModelElement as IModelMergeElements).ModelMerge(link, this);
                            }
                        continue;
                    }
                }

                System.Guid elementId = sourceRP.RolePlayerId;
                ModelElement modelElement = rootElement.Store.ElementDirectory.FindElement(elementId);
                if (modelElement != null)
                    if (modelElement is IModelMergeElements)
                    {
                        (modelElement as IModelMergeElements).ModelMerge(link, this);
                    }                
            }

            // finalize merging
            foreach (ModelProtoElement protoElement in protoGroup.ProtoElements)
            {
                Guid id = Guid.Empty;
                try
                {
                    id = GetIdMapping(protoElement.ElementId);
                }
                catch
                {
                    id = Guid.Empty;
                    continue;
                }

                /*
                if (id == Guid.Empty)
                {
                    ModelElement m = rootElement.Store.ElementDirectory.FindElement(id);
                    if (m != null)
                        id = m.Id;
                    else
                        continue;
                }*/

                ModelElement m = rootElement.Store.ElementDirectory.FindElement(id);
                if( m != null )
                    (m as IModelMergeElements).ModelFinalize(protoElement, this);
            }

            // finalize merging
            foreach (ModelProtoElement protoElement in protoGroup.ProtoRootElements)
            {
                (rootElement as IModelMergeElements).ModelFinalizeMerge(protoElement, this);
            }
        }
예제 #14
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="protoGroup">Proto group to paste/move.</param>
        /// <param name="rootElement">Element to execute paste/move on.</param>
        public ModelProtoGroupMerger(ModelProtoGroup protoGroup, ModelElement rootElement)
        {
            this.protoGroup       = protoGroup;
            this.validationResult = new ValidationResult();

            this.idMapping                = new Dictionary <Guid, Guid>();
            this.embeddingMapping         = new Dictionary <Guid, List <ModelProtoElement> >();
            this.referencingMapping       = new Dictionary <Guid, List <ModelProtoLink> >();
            this.referencingMappingTarget = new Dictionary <Guid, List <ModelProtoLink> >();
            this.elementMapping           = new Dictionary <Guid, ModelProtoElement>();

            if (protoGroup.Operation == ModelProtoGroupOperation.Move)
            {
                // move element
                foreach (ModelProtoElement protoElement in protoGroup.ProtoRootElements)
                {
                    (rootElement as IModelMergeElements).ModelMove(protoElement, this);
                }
                return;
            }

            foreach (ModelProtoElement element in protoGroup.ProtoElements)
            {
                idMapping.Add(element.ElementId, Guid.Empty);
                embeddingMapping.Add(element.ElementId, new List <ModelProtoElement>());
                referencingMapping.Add(element.ElementId, new List <ModelProtoLink>());
                referencingMappingTarget.Add(element.ElementId, new List <ModelProtoLink>());
                elementMapping.Add(element.ElementId, element);
            }
            foreach (ModelProtoLink link in protoGroup.ProtoEmbeddingLinks)
            {
                ModelProtoRolePlayer rolePlayer = link.GetSourceRolePlayer(rootElement.Store.DefaultPartition);
                ModelProtoElement    p          = GetElementById(rolePlayer.RolePlayerId);
                if (p != null)
                {
                    embeddingMapping[p.ElementId].Add(
                        GetElementById(link.GetTargetRolePlayer(rootElement.Store.DefaultPartition).RolePlayerId));
                }
            }

            foreach (ModelProtoLink link in protoGroup.ProtoReferenceLinks)
            {
                ModelProtoRolePlayer sourceRP = link.GetSourceRolePlayer(rootElement.Store.DefaultPartition);
                ModelProtoElement    p        = GetElementById(sourceRP.RolePlayerId);
                if (p != null)
                {
                    referencingMapping[p.ElementId].Add(link);
                }

                ModelProtoRolePlayer targetRP = link.GetTargetRolePlayer(rootElement.Store.DefaultPartition);
                p = GetElementById(targetRP.RolePlayerId);
                if (p != null)
                {
                    referencingMappingTarget[p.ElementId].Add(link);
                }
            }

            // start merging
            foreach (ModelProtoElement protoElement in protoGroup.ProtoRootElements)
            {
                (rootElement as IModelMergeElements).ModelMerge(protoElement, this, true);
            }

            // process reference relationships
            foreach (ModelProtoLink link in protoGroup.ProtoReferenceLinks)
            {
                ModelProtoRolePlayer sourceRP = link.GetSourceRolePlayer(rootElement.Store.DefaultPartition);
                if (this.idMapping.ContainsKey(sourceRP.RolePlayerId))
                {
                    System.Guid id = this.idMapping[sourceRP.RolePlayerId];
                    if (id != Guid.Empty)
                    {
                        ModelElement copiedModelElement = rootElement.Store.ElementDirectory.FindElement(id);
                        if (copiedModelElement != null)
                        {
                            if (copiedModelElement is IModelMergeElements)
                            {
                                (copiedModelElement as IModelMergeElements).ModelMerge(link, this);
                            }
                        }
                        continue;
                    }
                }

                System.Guid  elementId    = sourceRP.RolePlayerId;
                ModelElement modelElement = rootElement.Store.ElementDirectory.FindElement(elementId);
                if (modelElement != null)
                {
                    if (modelElement is IModelMergeElements)
                    {
                        (modelElement as IModelMergeElements).ModelMerge(link, this);
                    }
                }
            }

            // finalize merging
            foreach (ModelProtoElement protoElement in protoGroup.ProtoElements)
            {
                Guid id = Guid.Empty;
                try
                {
                    id = GetIdMapping(protoElement.ElementId);
                }
                catch
                {
                    id = Guid.Empty;
                    continue;
                }

                /*
                 * if (id == Guid.Empty)
                 * {
                 *  ModelElement m = rootElement.Store.ElementDirectory.FindElement(id);
                 *  if (m != null)
                 *      id = m.Id;
                 *  else
                 *      continue;
                 * }*/

                ModelElement m = rootElement.Store.ElementDirectory.FindElement(id);
                if (m != null)
                {
                    (m as IModelMergeElements).ModelFinalize(protoElement, this);
                }
            }

            // finalize merging
            foreach (ModelProtoElement protoElement in protoGroup.ProtoRootElements)
            {
                (rootElement as IModelMergeElements).ModelFinalizeMerge(protoElement, this);
            }
        }
        /// <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);
                        }
                    }
                }
            */
        }
예제 #16
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="instanceID"></param>
 /// <param name="prototype"></param>
 public CachedModelProtoGroup(Guid instanceID, ModelProtoGroup prototype)
 {
     this.instanceID = instanceID;
     this.prototype  = prototype;
 }
 /// <summary>
 /// Copies the given elements to the dataObject for the move operation.
 /// </summary>
 /// <param name="elements">Elements to copy.</param>
 /// <param name="dataObject">DataObject to add the data to.</param>
 /// <returns>DataObjects with the added data.</returns>
 public static IDataObject CopyToMove(ICollection<ModelElement> elements, IDataObject dataObject)
 {
     ModelProtoGroup protoGroup = new ModelProtoGroup(elements, ModelProtoGroupOperation.Move);
     dataObject.SetData(ModelProtoGroup.DefaultDataFormatName, protoGroup);
     dataObject.SetData(ModelProtoGroup.DefaultDataIdentifierName, Guid.NewGuid());
     return dataObject;
 }
        /// <summary>
        /// Decides whether the element that is represented by the proto element can be pasted or not.
        /// </summary>
        /// <param name="protoElement">Proto element representation of the element.</param>
        /// <param name="protoGroup">Proto group the proto element belongs to.</param>
        /// <returns>True if the element can be pasted. False otherwise.</returns>
        public virtual bool ModelCanMerge(ModelProtoElement protoElement, ModelProtoGroup protoGroup)
        {
            if (protoElement != null)
            {
                DomainClassInfo elementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(protoElement.DomainClassId);
                foreach (DomainRoleInfo info in elementDomainInfo.AllDomainRolesPlayed)
                {
                    if (!info.IsSource)
                        if( info.OppositeDomainRole.RolePlayer.Id == this.GetDomainClassId() )
                            if (this.Store.DomainDataAdvDirectory.IsEmbeddingRelationship(info.DomainRelationship.Id) &&
                                !this.Store.DomainDataAdvDirectory.IsAbstractRelationship(info.DomainRelationship.Id))
                            {
                                if (info.OppositeDomainRole.Multiplicity == Multiplicity.One || info.OppositeDomainRole.Multiplicity == Multiplicity.ZeroOne)
                                {
                                    // Check that creating a link with this path doesn't cause multiplicity overflow
                                    if (DomainRoleInfo.GetLinkedElement(this, info.OppositeDomainRole.Id) != null)
                                        return false;

                                    return true;
                                }
                                else
                                {
                                    if (protoGroup.Operation == ModelProtoGroupOperation.Move)
                                    {
                                        foreach (ElementLink link in DomainRoleInfo.GetElementLinks<ElementLink>(this, info.OppositeDomainRole.Id))
                                            if (DomainRoleInfo.GetTargetRolePlayer(link).Id == protoElement.ElementId)
                                                return false;
                                    }
                                    return true;
                                }
                            }
                }
            }

            return false;
        }
        /// <summary>
        /// Copies the given elements to the dataObject.
        /// </summary>
        /// <param name="elements">Elements to copy.</param>
        /// <param name="dataObject">DataObject to add the data to.</param>
        /// <returns>DataObjects with the added data.</returns>
        public static IDataObject Copy(ICollection<ModelElement> elements, IDataObject dataObject)
        {
            Guid guid = Guid.NewGuid();

            ModelProtoGroup protoGroup = new ModelProtoGroup(elements, ModelProtoGroupOperation.Copy);
            dataObject.SetData(ModelProtoGroup.DefaultDataFormatName, protoGroup);
            dataObject.SetData(ModelProtoGroup.DefaultDataIdentifierName, guid);

            // update cached prototype
            cachedPrototype = new CachedModelProtoGroup(guid, protoGroup);
            return dataObject;
        }