/// <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);
            ModelProcessMergeCopy(protoElement, protoGroup);
            return protoElement;
        }
Exemple #2
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 (protoGroup.Operation == ModelProtoGroupOperation.Move)
            {
                return(false);
            }

            if (protoElement.CustomArguments is DiagramModelMergeOptions)
            {
                DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions;

                return(this.CanHostShape(options.ShapeDomainClassId));
            }

            return(false);
        }
        /// <summary>
        /// Executes the paste operation on the given element.
        /// </summary>
        /// <param name="modelElement">Element.</param>
        /// <returns>Validation result, indicating problems during the paste operation.</returns>
        public static ValidationResult ExecutePaste(ModelElement modelElement)
        {
            System.Windows.IDataObject idataObject = System.Windows.Clipboard.GetDataObject();

            ValidationResult result = null;

            using (Transaction transaction = modelElement.Store.TransactionManager.BeginTransaction("Paste", true))
            {
                result = ModelElementOperations.Merge(modelElement, idataObject);

                List <Guid> shapes = DiagramsShapeStore.GetFromStore(modelElement.Id);
                if (shapes != null)
                {
                    foreach (Guid s in shapes)
                    {
                        NodeShape shape = modelElement.Store.ElementDirectory.FindElement(s) as NodeShape;
                        if (shape != null)
                        {
                            using (Transaction tShape = modelElement.Store.TransactionManager.BeginTransaction("Create shape", true))
                            {
                                shape.FixUpMissingShapes();
                                tShape.Commit();
                            }
                            using (Transaction tLinkShapes = modelElement.Store.TransactionManager.BeginTransaction("Fixup missing link shapes", true))
                            {
                                shape.FixUpMissingLinkShapes();
                                tLinkShapes.Commit();
                            }
                        }
                    }
                }
                transaction.Commit();
            }

            ModelProtoGroup group = ModelElementOperations.GetModelProtoGroup(idataObject);

            if (group != null)
            {
                if (group.Operation == ModelProtoGroupOperation.Move)
                {
                    System.Windows.Clipboard.Clear();
                    ElementsInMoveMode.Clear();
                }
            }

            return(result);
        }
        /// <summary>
        /// Helper method of the cut opeation.
        /// </summary>
        /// <param name="eventManager">Event manager.</param>
        /// <param name="idataObject">Data object.</param>
        public static void ProcessMoveMode(ViewModelEventManager eventManager, System.Windows.IDataObject idataObject)
        {
            bool isInMoveMode = false;

            if (idataObject != null)
            {
                ModelProtoGroup group = ModelElementOperations.GetModelProtoGroup(idataObject);
                if (group != null)
                {
                    if (group.Operation == ModelProtoGroupOperation.Move)
                    {
                        isInMoveMode = true;

                        List <System.Guid> guids = new List <System.Guid>();
                        foreach (ModelProtoElement root in group.ProtoRootElements)
                        {
                            guids.Add(root.ElementId);
                        }
                        foreach (System.Guid id in guids)
                        {
                            if (!ElementsInMoveMode.Contains(id))
                            {
                                eventManager.GetEvent <ModelElementCustomEvent <bool> >().Publish(true, ModelElementCustomEventNames.ModelElementMoveModeStatus, id);
                                ElementsInMoveMode.Add(id);
                            }
                        }
                        for (int i = ElementsInMoveMode.Count - 1; i >= 0; i--)
                        {
                            if (!guids.Contains(ElementsInMoveMode[i]))
                            {
                                eventManager.GetEvent <ModelElementCustomEvent <bool> >().Publish(false, ModelElementCustomEventNames.ModelElementMoveModeStatus, ElementsInMoveMode[i]);
                                ElementsInMoveMode.RemoveAt(i);
                            }
                        }
                    }
                }
            }

            if (!isInMoveMode)
            {
                // remove all elements from the current list and notify them to change status
                foreach (System.Guid id in ElementsInMoveMode)
                {
                    eventManager.GetEvent <ModelElementCustomEvent <bool> >().Publish(false, ModelElementCustomEventNames.ModelElementMoveModeStatus, id);
                }
            }
        }
Exemple #5
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);
            ModelProcessMergeCopy(protoElement, protoGroup);
            return(protoElement);
        }
Exemple #6
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 (protoGroup.Operation == ModelProtoGroupOperation.Move)
            {
                return(false);
            }

            if (protoElement.CustomArguments is DiagramModelMergeOptions)
            {
                DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions;

                Guid elementID             = options.ElementId;
                ModelProtoElement elementP = protoGroup.GetProtoElementFor(elementID, this.Partition);
                if (elementP != null)
                {
                    return((this.Element as IModelMergeElements).ModelCanMerge(elementP, protoGroup));
                }
            }

            return(false);
        }
Exemple #7
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)
        {
            if (protoGroup.Operation == ModelProtoGroupOperation.Copy)
            {
                (this.Element as IModelMergeElements).ModelCreateMergeCopy(protoGroup);
            }
            else
            {
                (this.Element as IModelMergeElements).ModelCreateMoveCopy(protoGroup);
            }

            // TODO: get parent element.

            this.Store.UndoManager.UndoState = UndoState.DisabledNoFlush;
            using (Transaction t = this.Store.TransactionManager.BeginTransaction())
            {
                DiagramModelMergeOptions operations = new DiagramModelMergeOptions(LayoutHelper.CreateLayoutInfo(
                                                                                       this, this.Diagram), this.Element.Id, this.Element.GetDomainClass().Id, this.GetDomainClass().Id);

                PointD relativeLocation = this.Location;
                if (!this.IsRelativeChildShape)
                {
                    if (RelativeMinCopyPoint.X <= relativeLocation.X)
                    {
                        relativeLocation.X -= RelativeMinCopyPoint.X;
                    }
                    if (RelativeMinCopyPoint.Y <= relativeLocation.Y)
                    {
                        relativeLocation.Y -= RelativeMinCopyPoint.Y;
                    }
                    operations.RelativeLocation  = relativeLocation;
                    protoElement.CustomArguments = operations;
                }
                t.Commit();
            }
            this.Store.UndoManager.UndoState = UndoState.Enabled;
        }
        /// <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)
        {
            if( protoGroup.Operation == ModelProtoGroupOperation.Copy )
                (this.Element as IModelMergeElements).ModelCreateMergeCopy(protoGroup);
            else
                (this.Element as IModelMergeElements).ModelCreateMoveCopy(protoGroup);

            // TODO: get parent element.

            this.Store.UndoManager.UndoState = UndoState.DisabledNoFlush;
            using (Transaction t = this.Store.TransactionManager.BeginTransaction())
            {
                DiagramModelMergeOptions operations = new DiagramModelMergeOptions(LayoutHelper.CreateLayoutInfo(
                    this, this.Diagram), this.Element.Id, this.Element.GetDomainClass().Id, this.GetDomainClass().Id);

                PointD relativeLocation = this.Location;
                if (!this.IsRelativeChildShape)
                {
                    if (RelativeMinCopyPoint.X <= relativeLocation.X)
                        relativeLocation.X -= RelativeMinCopyPoint.X;
                    if (RelativeMinCopyPoint.Y <= relativeLocation.Y)
                        relativeLocation.Y -= RelativeMinCopyPoint.Y;
                    operations.RelativeLocation = relativeLocation;
                    protoElement.CustomArguments = operations;
                }
                t.Commit();
            }
            this.Store.UndoManager.UndoState = UndoState.Enabled;
        }
        /// <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 (protoGroup.Operation == ModelProtoGroupOperation.Move)
                return false;

            if (protoElement.CustomArguments is DiagramModelMergeOptions)
            {
                DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions;

                Guid elementID = options.ElementId;
                ModelProtoElement elementP = protoGroup.GetProtoElementFor(elementID, this.Partition);
                if (elementP != null)
                {
                    return (this.Element as IModelMergeElements).ModelCanMerge(elementP, protoGroup);
                }
            }

            return false;
        }
Exemple #10
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)
 {
 }
        public override void ModelProcessMergeCopy(ModelProtoElement protoElement, ModelProtoGroup protoGroup)
        {
            base.ModelProcessMergeCopy(protoElement, protoGroup);

            bool isInFull    = false;
            bool isTargetInc = false;
            SerializationClass sClass;

            if (this is ReferenceRelationship)
            {
                sClass   = (this as ReferenceRelationship).SerializedReferenceRelationship;
                isInFull = (this as ReferenceRelationship).SerializedReferenceRelationship.IsInFullSerialization;
            }
            else
            {
                sClass      = (this as EmbeddingRelationship).SerializedEmbeddingRelationship;
                isInFull    = (this as EmbeddingRelationship).SerializedEmbeddingRelationship.IsInFullSerialization;
                isTargetInc = (this as EmbeddingRelationship).SerializedEmbeddingRelationship.IsTargetIncludedSubmodel;
            }

            // copy order of attributes and children
            DomainRelationshipSerializationInfo info = new DomainRelationshipSerializationInfo(
                sClass.Children.Count,
                sClass.Attributes.Count);

            info.IsInFullSerialization    = isInFull;
            info.IsTargetIncludedSubmodel = isTargetInc;

            for (int i = 0; i < sClass.Attributes.Count; i++)
            {
                SerializationAttributeElement aatr = sClass.Attributes[i];
                if (aatr is SerializedDomainProperty)
                {
                    SerializedDomainProperty sP    = aatr as SerializedDomainProperty;
                    ElementSerializationInfo sInfo = new ElementSerializationInfo(
                        sP.DomainProperty.Name, sP.DomainProperty.Id);
                    if (sP.OmitProperty)
                    {
                        sInfo.OmitElement = true;
                    }

                    info.AttributesOrder.Add(sInfo);
                }
                else if (aatr is SerializedIdProperty)
                {
                    SerializedIdProperty     sI    = aatr as SerializedIdProperty;
                    ElementSerializationInfo sInfo = new ElementSerializationInfo("SerializedIdProperty", Guid.Empty);
                    if (sI.OmitIdProperty)
                    {
                        sInfo.OmitElement = true;
                    }

                    info.AttributesOrder.Add(sInfo);
                }
            }

            for (int i = 0; i < sClass.Children.Count; i++)
            {
                SerializationElement sE = sClass.Children[i];
                if (sE is SerializedDomainProperty)
                {
                    SerializedDomainProperty sP    = sE as SerializedDomainProperty;
                    ElementSerializationInfo sInfo = new ElementSerializationInfo(
                        sP.DomainProperty.Name, sP.DomainProperty.Id);
                    if (sP.OmitProperty)
                    {
                        sInfo.OmitElement = true;
                    }

                    info.ChildrenOrder.Add(sInfo);
                }
            }

            protoElement.CustomArguments = info;
        }
 /// <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)
 {
 }
        /// <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 (protoGroup.Operation == ModelProtoGroupOperation.Move)
                return false;

            if (protoElement.CustomArguments is DiagramModelMergeOptions)
            {
                DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions;

                return this.CanHostShape(options.ShapeDomainClassId);
            }

            return false;
        }