Esempio n. 1
0
        private static void ProcessNodeShape(NodeShape shapeElement, LinkedElementCollection <NodeShapeInfo> infos)
        {
            // try to find NodeShapeInfo for shape element
            NodeShapeInfo info = null;

            foreach (NodeShapeInfo i in infos)
            {
                if (i.ElementId == shapeElement.Element.Id)
                {
                    info = i;
                    break;
                }
            }

            if (info == null)
            {
                shapeElement.UpdateAbsoluteLocation();
                return;
            }

            shapeElement.Size = info.Size;
            shapeElement.SetLocation(info.RelativeLocation);

            // children
            foreach (NodeShape shape in shapeElement.Children)
            {
                ProcessNodeShape(shape, info.ChildrenInfos);
            }
        }
    public GameObject ShapeFromInfo(NodeShapeInfo info)
    {
        Vector3    position = new Vector3(info.px, info.py, info.pz);
        int        type     = info.type;
        GameObject shape    = Instantiate(shapePrefabs[type]);

        shape.transform.position   = position;
        shape.transform.rotation   = new Quaternion(info.qx, info.qy, info.qz, info.qw);
        shape.transform.localScale = new Vector3(.3f, .3f, .3f);

        return(shape);
    }
        private static NodeShapeInfo CreateNodeShapeInfo(NodeShape shapeElement, List<NodeShape> allShapes)
        {
            NodeShapeInfo info = new NodeShapeInfo(shapeElement.Store);
            info.ElementId = shapeElement.Element.Id;
            info.Size = shapeElement.Size;
            info.RelativeLocation = shapeElement.Location;

            foreach (NodeShape shape in shapeElement.Children)
            {
                allShapes.Add(shape);
                info.ChildrenInfos.Add(CreateNodeShapeInfo(shape, allShapes));
            }

            return info;
        }
Esempio n. 4
0
        private static NodeShapeInfo CreateNodeShapeInfo(NodeShape shapeElement, List <NodeShape> allShapes)
        {
            NodeShapeInfo info = new NodeShapeInfo(shapeElement.Store);

            info.ElementId        = shapeElement.Element.Id;
            info.Size             = shapeElement.Size;
            info.RelativeLocation = shapeElement.Location;

            foreach (NodeShape shape in shapeElement.Children)
            {
                allShapes.Add(shape);
                info.ChildrenInfos.Add(CreateNodeShapeInfo(shape, allShapes));
            }

            return(info);
        }
    public GameObject ShapeFromJSON(int id, NodeShapeInfo info)
    {
        Vector3    position = new Vector3(info.px, info.py, info.pz);
        int        type     = info.type;
        GameObject shape    = Instantiate(shapePrefabs[type]);

        if (shape.GetComponent <Node>() != null)
        {
            shape.GetComponent <Node>().id  = id;
            shape.GetComponent <Node>().pos = position;
        }

        shape.transform.position   = position;
        shape.transform.rotation   = new Quaternion(info.qx, info.qy, info.qz, info.qw);
        shape.transform.localScale = new Vector3(.3f, .3f, .3f);

        return(shape);
    }
    public void CreateWay(Vector3 position)
    {
        NodeShapeInfo info = new NodeShapeInfo();

        info.px   = position.x;
        info.py   = position.y;
        info.pz   = position.z;
        info.qx   = 0;
        info.qy   = 0;
        info.qz   = 0;
        info.qw   = 0;
        info.type = TYPE_WAY.GetHashCode();
        NodeShape waypoint = new NodeShape();

        waypoint.id   = id;
        waypoint.info = info;
        shapeList.Add(waypoint);
        id++;

        Debug.Log("ShapeFromInfo");
        GameObject gameObject = ShapeFromInfo(waypoint.info);

        shapeObjList.Add(gameObject);
        Debug.Log("Add Shape");

        Collider[] hitColliders = Physics.OverlapSphere(position, MAX_DISTANCE);
        numEdgeList.Add(hitColliders.Length);
        Debug.Log(hitColliders.Length);
        int i = 0;

        while (i < hitColliders.Length)
        {
            if (hitColliders[i].CompareTag("Node"))
            {
                GameObject edge = Instantiate(shapePrefabs[TYPE_EDGE]);
                edge.GetComponent <LineRenderer>().SetPosition(0, gameObject.transform.position);
                edge.GetComponent <LineRenderer>().SetPosition(1, hitColliders[i].transform.position);
                edgeObjList.Add(edge);
                Debug.Log(gameObject.transform.position);
                Debug.Log(hitColliders[i].transform.position);
            }
            i++;
        }
    }
    public void CreateDest(GameObject selectedNode, string destName)
    {
        int index = shapeObjList.FindIndex(shape => shape.transform.position == selectedNode.transform.position);

        if (index >= 0)
        {
            NodeShape shape = shapeList[index];
            if (selectedNode.name == "Destination(Clone)")
            {
                shape.name       = destName;
                shapeList[index] = shape;
                selectedNode.transform.GetChild(0).GetComponent <TextMeshPro>().text = destName;
            }
            else
            {
                NodeShapeInfo info = new NodeShapeInfo();
                info.px   = shape.info.px;
                info.py   = shape.info.py;
                info.pz   = shape.info.pz;
                info.qx   = 0;
                info.qy   = 0;
                info.qz   = 0;
                info.qw   = 0;
                info.type = TYPE_DEST.GetHashCode();
                NodeShape dest = new NodeShape();
                dest.id   = shape.id;
                dest.name = destName;
                dest.info = info;

                Destroy(selectedNode);
                shapeObjList.RemoveAt(index);
                GameObject gameObject = ShapeFromInfo(dest.info);
                gameObject.transform.GetChild(0).GetComponent <TextMeshPro>().text = dest.name;
                shapeObjList.Insert(index, gameObject);

                shapeList.RemoveAt(index);
                shapeList.Insert(index, dest);
                Debug.Log((shapeList[index]).name);
                numDest++;
            }
        }
    }
		public static void SetParentInfo(NodeShapeInfo element, NodeShapeInfo newSourceNodeShapeInfo)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, TargetNodeShapeInfoDomainRoleId, newSourceNodeShapeInfo);
		}
		public static DslModeling::LinkedElementCollection<NodeShapeInfo> GetChildrenInfos(NodeShapeInfo element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<NodeShapeInfo>, NodeShapeInfo>(element, SourceNodeShapeInfoDomainRoleId);
		}
		/// <summary>
		/// Constructor
		/// Creates a NodeShapeInfoHasChildrenInfos link in the same Partition as the given NodeShapeInfo
		/// </summary>
		/// <param name="source">NodeShapeInfo to use as the source of the relationship.</param>
		/// <param name="target">NodeShapeInfo to use as the target of the relationship.</param>
		public NodeShapeInfoHasChildrenInfos(NodeShapeInfo source, NodeShapeInfo target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(NodeShapeInfoHasChildrenInfos.SourceNodeShapeInfoDomainRoleId, source), new DslModeling::RoleAssignment(NodeShapeInfoHasChildrenInfos.TargetNodeShapeInfoDomainRoleId, target)}, null)
		{
		}
		public static NodeShapeInfo GetParentInfo(NodeShapeInfo element)
		{
			return DslModeling::DomainRoleInfo.GetLinkedElement(element, TargetNodeShapeInfoDomainRoleId) as NodeShapeInfo;
		}
		public static void SetLayoutInfo(NodeShapeInfo element, LayoutInfo newLayoutInfo)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, NodeShapeInfoDomainRoleId, newLayoutInfo);
		}
		public static LayoutInfo GetLayoutInfo(NodeShapeInfo element)
		{
			return DslModeling::DomainRoleInfo.GetLinkedElement(element, NodeShapeInfoDomainRoleId) as LayoutInfo;
		}
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, NodeShapeInfo element, global::System.Xml.XmlWriter writer)
		{
			// NodeShapeInfoHasChildrenInfos
			global::System.Collections.ObjectModel.ReadOnlyCollection<NodeShapeInfoHasChildrenInfos> allNodeShapeInfoHasChildrenInfosInstances = NodeShapeInfoHasChildrenInfos.GetLinksToChildrenInfos(element);
			if (!serializationContext.Result.Failed && allNodeShapeInfoHasChildrenInfosInstances.Count > 0)
			{
				writer.WriteStartElement("childrenInfos");
				foreach (NodeShapeInfoHasChildrenInfos eachNodeShapeInfoHasChildrenInfosInstance in allNodeShapeInfoHasChildrenInfosInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachNodeShapeInfoHasChildrenInfosInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachNodeShapeInfoHasChildrenInfosInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachNodeShapeInfoHasChildrenInfosInstance, writer);
				}
				writer.WriteEndElement();
			}
	
		}
		/// <summary>
		/// Reads all instances of relationship NodeShapeInfoHasChildrenInfos.
		/// </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 NodeShapeInfo instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadNodeShapeInfoHasChildrenInfosInstances(DslModeling::SerializationContext serializationContext, NodeShapeInfo element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newNodeShapeInfoHasChildrenInfosSerializer = serializationContext.Directory.GetSerializer(NodeShapeInfoHasChildrenInfos.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newNodeShapeInfoHasChildrenInfosSerializer != null, "Cannot find serializer for NodeShapeInfoHasChildrenInfos!");
				NodeShapeInfoHasChildrenInfos newNodeShapeInfoHasChildrenInfos = newNodeShapeInfoHasChildrenInfosSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as NodeShapeInfoHasChildrenInfos;
				if (newNodeShapeInfoHasChildrenInfos != null)
				{
					DslModeling::DomainRoleInfo.SetRolePlayer (newNodeShapeInfoHasChildrenInfos, NodeShapeInfoHasChildrenInfos.SourceNodeShapeInfoDomainRoleId, element);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newNodeShapeInfoHasChildrenInfos.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newNodeShapeInfoHasChildrenInfos.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newNodeShapeInfoHasChildrenInfos, reader);
				}
				else
				{	// Maybe the relationship is serialized in short-form by mistake.
					DslModeling::DomainClassXmlSerializer newNodeShapeInfoOfNodeShapeInfoHasChildrenInfosSerializer = serializationContext.Directory.GetSerializer(NodeShapeInfo.DomainClassId);
					global::System.Diagnostics.Debug.Assert(newNodeShapeInfoOfNodeShapeInfoHasChildrenInfosSerializer != null, "Cannot find serializer for NodeShapeInfo!");
					NodeShapeInfo newNodeShapeInfoOfNodeShapeInfoHasChildrenInfos = newNodeShapeInfoOfNodeShapeInfoHasChildrenInfosSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as NodeShapeInfo;
					if (newNodeShapeInfoOfNodeShapeInfoHasChildrenInfos != null)
					{
						TestDslDefinitionSerializationBehaviorSerializationMessages.ExpectingFullFormRelationship(serializationContext, reader, typeof(NodeShapeInfoHasChildrenInfos));
						element.ChildrenInfos.Add(newNodeShapeInfoOfNodeShapeInfoHasChildrenInfos);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newNodeShapeInfoOfNodeShapeInfoHasChildrenInfos.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newNodeShapeInfoOfNodeShapeInfoHasChildrenInfos.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newNodeShapeInfoOfNodeShapeInfoHasChildrenInfos, reader);
					}
					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 NodeShapeInfo instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, NodeShapeInfo element, global::System.Xml.XmlReader reader)
		{
			if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				if (string.Compare(reader.LocalName, "childrenInfos", 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 <childrenInfos>
						ReadNodeShapeInfoHasChildrenInfosInstances(serializationContext, element, reader);
						DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </childrenInfos>
					}
				}
			}
		}