public static void SetFromShape(SourceAnchor element, NodeShape newNodeShape) { DslModeling::DomainRoleInfo.SetLinkedElement(element, SourceAnchorDomainRoleId, newNodeShape); }
/// <summary> /// Called whenever elements properties are changed. /// </summary> /// <param name="e"></param> public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e) { base.ElementPropertyChanged(e); if (e.ModelElement == null) { return; } if (e.ModelElement.Store.InSerializationTransaction == true) { return; } if (e.ModelElement.IsDeleted || e.ModelElement.IsDeleting) { return; } SourceAnchor sourceAnchor = e.ModelElement as SourceAnchor; if (sourceAnchor != null) { if (sourceAnchor.LinkShape != null) { if (sourceAnchor.LinkShape.IsDeleted || sourceAnchor.LinkShape.IsDeleting) { return; } } if (e.DomainProperty.Id == Anchor.AbsoluteLocationDomainPropertyId && sourceAnchor.LinkShape != null) { if (!sourceAnchor.LinkShape.IsLayoutInProgress) { if (!sourceAnchor.DiscardLocationChange) { sourceAnchor.LinkShape.InternalLayout(FixedGeometryPoints.Source); } else { sourceAnchor.DiscardLocationChange = false; } } } } TargetAnchor targetAnchor = e.ModelElement as TargetAnchor; if (targetAnchor != null) { if (targetAnchor.LinkShape != null) { if (targetAnchor.LinkShape.IsDeleted || targetAnchor.LinkShape.IsDeleting) { return; } } if (e.DomainProperty.Id == Anchor.AbsoluteLocationDomainPropertyId && targetAnchor.LinkShape != null) { if (!targetAnchor.LinkShape.IsLayoutInProgress) { if (!targetAnchor.DiscardLocationChange) { targetAnchor.LinkShape.InternalLayout(FixedGeometryPoints.Target); } else { targetAnchor.DiscardLocationChange = false; } } } } }
/// <summary> /// Constructor /// Creates a SourceAnchorReferencesFromShape link in the same Partition as the given SourceAnchor /// </summary> /// <param name="source">SourceAnchor to use as the source of the relationship.</param> /// <param name="target">NodeShape to use as the target of the relationship.</param> public SourceAnchorReferencesFromShape(SourceAnchor source, NodeShape target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(SourceAnchorReferencesFromShape.SourceAnchorDomainRoleId, source), new DslModeling::RoleAssignment(SourceAnchorReferencesFromShape.NodeShapeDomainRoleId, target)}, null) { }
public static NodeShape GetFromShape(SourceAnchor element) { return DslModeling::DomainRoleInfo.GetLinkedElement(element, SourceAnchorDomainRoleId) as NodeShape; }
public static void SetSourceAnchor(LinkShape element, SourceAnchor newSourceAnchor) { DslModeling::DomainRoleInfo.SetLinkedElement(element, LinkShapeDomainRoleId, newSourceAnchor); }
/// <summary> /// Constructor /// Creates a LinkShapeHasSourceAnchor link in the same Partition as the given LinkShape /// </summary> /// <param name="source">LinkShape to use as the source of the relationship.</param> /// <param name="target">SourceAnchor to use as the target of the relationship.</param> public LinkShapeHasSourceAnchor(LinkShape source, SourceAnchor target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(LinkShapeHasSourceAnchor.LinkShapeDomainRoleId, source), new DslModeling::RoleAssignment(LinkShapeHasSourceAnchor.SourceAnchorDomainRoleId, target)}, null) { }
private static void WriteChildElements(DslModeling::SerializationContext serializationContext, SourceAnchor element, global::System.Xml.XmlWriter writer) { // SourceAnchorReferencesFromShape SourceAnchorReferencesFromShape theSourceAnchorReferencesFromShapeInstance = SourceAnchorReferencesFromShape.GetLinkToFromShape(element); if (!serializationContext.Result.Failed && theSourceAnchorReferencesFromShapeInstance != null) { writer.WriteStartElement("fromShape"); DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(theSourceAnchorReferencesFromShapeInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + theSourceAnchorReferencesFromShapeInstance.GetDomainClass().Name + "!"); relSerializer.Write(serializationContext, theSourceAnchorReferencesFromShapeInstance, writer); writer.WriteEndElement(); } }
private static void ReadSourceAnchorReferencesFromShapeInstance(DslModeling::SerializationContext serializationContext, SourceAnchor element, global::System.Xml.XmlReader reader) { if (DslModeling::DomainRoleInfo.GetElementLinks<SourceAnchorReferencesFromShape> (element, SourceAnchorReferencesFromShape.SourceAnchorDomainRoleId).Count > 0) { // Only allow one instance, which already exists, so skip everything DslModeling::SerializationUtilities.Skip(reader); // Moniker contains no child XML elements, so just skip. return; } while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { DslModeling::DomainClassXmlSerializer newSourceAnchorReferencesFromShapeSerializer = serializationContext.Directory.GetSerializer(SourceAnchorReferencesFromShape.DomainClassId); global::System.Diagnostics.Debug.Assert(newSourceAnchorReferencesFromShapeSerializer != null, "Cannot find serializer for SourceAnchorReferencesFromShape!"); SourceAnchorReferencesFromShape newSourceAnchorReferencesFromShape = newSourceAnchorReferencesFromShapeSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as SourceAnchorReferencesFromShape; if (newSourceAnchorReferencesFromShape != null) { DslModeling::DomainRoleInfo.SetRolePlayer (newSourceAnchorReferencesFromShape, SourceAnchorReferencesFromShape.SourceAnchorDomainRoleId, element); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newSourceAnchorReferencesFromShape.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newSourceAnchorReferencesFromShape.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newSourceAnchorReferencesFromShape, reader); break; // Only allow one instance. } else { // Maybe the relationship is serialized in short-form by mistake. DslModeling::DomainClassXmlSerializer newNodeShapeMonikerOfSourceAnchorReferencesFromShapeSerializer = serializationContext.Directory.GetSerializer(NodeShape.DomainClassId); global::System.Diagnostics.Debug.Assert(newNodeShapeMonikerOfSourceAnchorReferencesFromShapeSerializer != null, "Cannot find serializer for NodeShape!"); DslModeling::Moniker newNodeShapeMonikerOfSourceAnchorReferencesFromShape = newNodeShapeMonikerOfSourceAnchorReferencesFromShapeSerializer.TryCreateMonikerInstance(serializationContext, reader, element, SourceAnchorReferencesFromShape.DomainClassId, element.Partition); if (newNodeShapeMonikerOfSourceAnchorReferencesFromShape != null) { TestDslDefinitionSerializationBehaviorSerializationMessages.ExpectingFullFormRelationship(serializationContext, reader, typeof(SourceAnchorReferencesFromShape)); new SourceAnchorReferencesFromShape(element.Partition, new DslModeling::RoleAssignment(SourceAnchorReferencesFromShape.SourceAnchorDomainRoleId, element), new DslModeling::RoleAssignment(SourceAnchorReferencesFromShape.NodeShapeDomainRoleId, newNodeShapeMonikerOfSourceAnchorReferencesFromShape)); DslModeling::SerializationUtilities.Skip(reader); // Moniker contains no child XML elements, so just skip. break; // Only allow one instance. } else { // Unknown element, skip. DslModeling::SerializationUtilities.Skip(reader); } } } }
/// <summary> /// This method deserializes all child model elements. /// </summary> /// <remarks> /// The caller will position the reader at the open tag of the first child XML element to deserialized. /// This method will read as many child elements as it can. It returns under three circumstances: /// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the /// open tag of the unknown element. This implies that if the first child XML element is unknown, this method /// should return immediately and do nothing. /// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element. /// 3) EOF. /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="reader">XmlReader to read serialized data from.</param> /// <param name="element">In-memory SourceAnchor instance that will get the deserialized data.</param> private static void ReadChildElements(DslModeling::SerializationContext serializationContext, SourceAnchor element, global::System.Xml.XmlReader reader) { if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { if (string.Compare(reader.LocalName, "fromShape", global::System.StringComparison.CurrentCulture) == 0) { if (reader.IsEmptyElement) { // No instance of this relationship, just skip DslModeling::SerializationUtilities.Skip(reader); } else { DslModeling::SerializationUtilities.SkipToFirstChild(reader); // Skip the open tag of <fromShape> ReadSourceAnchorReferencesFromShapeInstance(serializationContext, element, reader); DslModeling::SerializationUtilities.Skip(reader); // Skip the close tag of </fromShape> } } } }