コード例 #1
0
ファイル: LayoutHelper.cs プロジェクト: ckimpel/FSE-2011-PDE
        public static bool RestoreLayout(NodeShape shapeElement, Diagram diagram)
        {
            DiagramsModel model = GetDiagramsModel(shapeElement);

            foreach (LayoutInfo layout in model.LayoutInfos)
            {
                if (layout.HostElementId == shapeElement.Element.Id)
                {
                    // apply layout
                    ApplyLayout(shapeElement, diagram, layout);

                    return(true);
                }
            }

            Tum.PDE.ToolFramework.Modeling.Diagrams.Layout.GleeLayouter.Layout(shapeElement);

            return(false);
        }
コード例 #2
0
ファイル: LayoutHelper.cs プロジェクト: ckimpel/FSE-2011-PDE
        public static void SaveLayout(NodeShape shapeElement, Diagram diagram)
        {
            DiagramsModel model = GetDiagramsModel(shapeElement);

            // see if there is already a layout for the given shape element
            foreach (LayoutInfo layout in model.LayoutInfos)
            {
                if (layout.HostElementId == shapeElement.Element.Id)
                {
                    // delete existing layout
                    model.LayoutInfos.Remove(layout);
                    break;
                }
            }

            // create new layout
            List <NodeShape> allShapes = new List <NodeShape>();
            LayoutInfo       l         = CreateLayoutInfo(shapeElement, diagram);

            model.LayoutInfos.Add(l);
        }
コード例 #3
0
		public static DslModeling::LinkedElementCollection<Diagram> GetDiagrams(DiagramsModel element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<Diagram>, Diagram>(element, DiagramsModelDomainRoleId);
		}
コード例 #4
0
		public static DslModeling::LinkedElementCollection<LayoutInfo> GetLayoutInfos(DiagramsModel element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<LayoutInfo>, LayoutInfo>(element, DiagramsModelDomainRoleId);
		}
コード例 #5
0
		public static void SetDiagramsModel(Diagram element, DiagramsModel newDiagramsModel)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, DiagramDomainRoleId, newDiagramsModel);
		}
コード例 #6
0
		/// <summary>
		/// Constructor
		/// Creates a DiagramsModelHasLayoutInfos link in the same Partition as the given DiagramsModel
		/// </summary>
		/// <param name="source">DiagramsModel to use as the source of the relationship.</param>
		/// <param name="target">LayoutInfo to use as the target of the relationship.</param>
		public DiagramsModelHasLayoutInfos(DiagramsModel source, LayoutInfo target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(DiagramsModelHasLayoutInfos.DiagramsModelDomainRoleId, source), new DslModeling::RoleAssignment(DiagramsModelHasLayoutInfos.LayoutInfoDomainRoleId, target)}, null)
		{
		}
コード例 #7
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, DiagramsModel element, global::System.Xml.XmlWriter writer)
		{
			// DiagramsModelHasDiagrams
			global::System.Collections.ObjectModel.ReadOnlyCollection<DiagramsModelHasDiagrams> allDiagramsModelHasDiagramsInstances = DiagramsModelHasDiagrams.GetLinksToDiagrams(element);
			if (!serializationContext.Result.Failed && allDiagramsModelHasDiagramsInstances.Count > 0)
			{
				writer.WriteStartElement("diagrams");
				global::System.Type typeofDiagramsModelHasDiagrams = typeof(DiagramsModelHasDiagrams);
				foreach (DiagramsModelHasDiagrams eachDiagramsModelHasDiagramsInstance in allDiagramsModelHasDiagramsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachDiagramsModelHasDiagramsInstance.GetType() != typeofDiagramsModelHasDiagrams)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachDiagramsModelHasDiagramsInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachDiagramsModelHasDiagramsInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachDiagramsModelHasDiagramsInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachDiagramsModelHasDiagramsInstance.Diagram;
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!");			
						targetSerializer.Write(serializationContext, targetElement, writer);
					}
				}
				writer.WriteEndElement();
			}
	
			// DiagramsModelHasLayoutInfos
			global::System.Collections.ObjectModel.ReadOnlyCollection<DiagramsModelHasLayoutInfos> allDiagramsModelHasLayoutInfosInstances = DiagramsModelHasLayoutInfos.GetLinksToLayoutInfos(element);
			if (!serializationContext.Result.Failed && allDiagramsModelHasLayoutInfosInstances.Count > 0)
			{
				writer.WriteStartElement("layoutInfos");
				foreach (DiagramsModelHasLayoutInfos eachDiagramsModelHasLayoutInfosInstance in allDiagramsModelHasLayoutInfosInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachDiagramsModelHasLayoutInfosInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachDiagramsModelHasLayoutInfosInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachDiagramsModelHasLayoutInfosInstance, writer);
				}
				writer.WriteEndElement();
			}
	
		}
コード例 #8
0
		/// <summary>
		/// Reads all instances of relationship DiagramsModelHasLayoutInfos.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be
		/// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the
		/// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens).
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="element">In-memory DiagramsModel instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadDiagramsModelHasLayoutInfosInstances(DslModeling::SerializationContext serializationContext, DiagramsModel element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newDiagramsModelHasLayoutInfosSerializer = serializationContext.Directory.GetSerializer(DiagramsModelHasLayoutInfos.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newDiagramsModelHasLayoutInfosSerializer != null, "Cannot find serializer for DiagramsModelHasLayoutInfos!");
				DiagramsModelHasLayoutInfos newDiagramsModelHasLayoutInfos = newDiagramsModelHasLayoutInfosSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as DiagramsModelHasLayoutInfos;
				if (newDiagramsModelHasLayoutInfos != null)
				{
					DslModeling::DomainRoleInfo.SetRolePlayer (newDiagramsModelHasLayoutInfos, DiagramsModelHasLayoutInfos.DiagramsModelDomainRoleId, element);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newDiagramsModelHasLayoutInfos.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newDiagramsModelHasLayoutInfos.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newDiagramsModelHasLayoutInfos, reader);
				}
				else
				{	// Maybe the relationship is serialized in short-form by mistake.
					DslModeling::DomainClassXmlSerializer newLayoutInfoOfDiagramsModelHasLayoutInfosSerializer = serializationContext.Directory.GetSerializer(LayoutInfo.DomainClassId);
					global::System.Diagnostics.Debug.Assert(newLayoutInfoOfDiagramsModelHasLayoutInfosSerializer != null, "Cannot find serializer for LayoutInfo!");
					LayoutInfo newLayoutInfoOfDiagramsModelHasLayoutInfos = newLayoutInfoOfDiagramsModelHasLayoutInfosSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as LayoutInfo;
					if (newLayoutInfoOfDiagramsModelHasLayoutInfos != null)
					{
						TestDslDefinitionSerializationBehaviorSerializationMessages.ExpectingFullFormRelationship(serializationContext, reader, typeof(DiagramsModelHasLayoutInfos));
						element.LayoutInfos.Add(newLayoutInfoOfDiagramsModelHasLayoutInfos);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newLayoutInfoOfDiagramsModelHasLayoutInfos.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newLayoutInfoOfDiagramsModelHasLayoutInfos.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newLayoutInfoOfDiagramsModelHasLayoutInfos, reader);
					}
					else
					{	// Unknown element, skip.
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
コード例 #9
0
		/// <summary>
		/// Reads all instances of relationship DiagramsModelHasDiagrams.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be
		/// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the
		/// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens).
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="element">In-memory DiagramsModel instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadDiagramsModelHasDiagramsInstances(DslModeling::SerializationContext serializationContext, DiagramsModel element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newDiagramOfDiagramsModelHasDiagramsSerializer = serializationContext.Directory.GetSerializer(Diagram.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newDiagramOfDiagramsModelHasDiagramsSerializer != null, "Cannot find serializer for Diagram!");
				Diagram newDiagramOfDiagramsModelHasDiagrams = newDiagramOfDiagramsModelHasDiagramsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as Diagram;
				if (newDiagramOfDiagramsModelHasDiagrams != null)
				{
					element.Diagrams.Add(newDiagramOfDiagramsModelHasDiagrams);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newDiagramOfDiagramsModelHasDiagrams.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newDiagramOfDiagramsModelHasDiagrams.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newDiagramOfDiagramsModelHasDiagrams, reader);
				}
				else
				{
					global::System.Type typeofDiagramsModelHasDiagrams = typeof(DiagramsModelHasDiagrams);
					DslModeling::DomainRelationshipXmlSerializer newDiagramsModelHasDiagramsSerializer = serializationContext.Directory.GetSerializer(DiagramsModelHasDiagrams.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newDiagramsModelHasDiagramsSerializer != null, "Cannot find serializer for DiagramsModelHasDiagrams!");
					DiagramsModelHasDiagrams newDiagramsModelHasDiagrams = newDiagramsModelHasDiagramsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as DiagramsModelHasDiagrams;
					if (newDiagramsModelHasDiagrams != null)
					{
						if (newDiagramsModelHasDiagrams.GetType() == typeofDiagramsModelHasDiagrams)
						{	// The relationship should be serialized in short-form.
							TestDslDefinitionSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(DiagramsModelHasDiagrams));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newDiagramsModelHasDiagrams, DiagramsModelHasDiagrams.DiagramsModelDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newDiagramsModelHasDiagrams.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newDiagramsModelHasDiagrams.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newDiagramsModelHasDiagrams, reader);
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
コード例 #10
0
		/// <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 DiagramsModel instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, DiagramsModel element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "diagrams":	// Relationship "DiagramsModelHasDiagrams"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <diagrams>
							ReadDiagramsModelHasDiagramsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </diagrams>
						}
						break;
					case "layoutInfos":	// Relationship "DiagramsModelHasLayoutInfos"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <layoutInfos>
							ReadDiagramsModelHasLayoutInfosInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </layoutInfos>
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}