Esempio n. 1
0
        public void CreateModel(XmlElement modelData)
        {
            XmlElementHelper helper   = new XmlElementHelper(modelData);
            string           typeName = helper.ReadString("type", String.Empty);

            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto
                // the name of the XmlElement itself, which is usually the type
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                              string.Format("No type information: {0}", guid));
                }
            }

#if USE_DSENGINE
            if (typeName.Equals("Dynamo.Nodes.DSFunction") ||
                typeName.Equals("Dynamo.Nodes.DSVarArgFunction"))
            {
                // For DSFunction and DSVarArgFunction node types, the type name
                // is actually embedded within "name" attribute (for an example,
                // "UV.ByCoordinates@double,double").
                //
                typeName = modelData.Attributes["name"].Value;
            }
#endif

            if (typeName.StartsWith("Dynamo.Models.ConnectorModel"))
            {
                ConnectorModel connector = ConnectorModel.Make();
                connector.Deserialize(modelData, SaveContext.Undo);
                Connectors.Add(connector);
            }
            else if (typeName.StartsWith("Dynamo.Models.NoteModel"))
            {
                NoteModel noteModel = new NoteModel(0.0, 0.0);
                noteModel.Deserialize(modelData, SaveContext.Undo);
                Notes.Add(noteModel);
            }
            else // Other node types.
            {
                NodeModel nodeModel = DynamoModel.CreateNodeInstance(typeName);
                nodeModel.WorkSpace = this;
                nodeModel.Deserialize(modelData, SaveContext.Undo);
                Nodes.Add(nodeModel);
            }
        }
Esempio n. 2
0
        public void CreateModel(XmlElement modelData)
        {
            XmlElementHelper helper   = new XmlElementHelper(modelData);
            string           typeName = helper.ReadString("type", String.Empty);

            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto
                // the name of the XmlElement itself, which is usually the type
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                              string.Format("No type information: {0}", guid));
                }
            }

            if (typeName.StartsWith("Dynamo.Nodes"))
            {
                NodeModel nodeModel = DynamoModel.CreateNodeInstance(typeName);
                nodeModel.WorkSpace = this;
                nodeModel.Deserialize(modelData, SaveContext.Undo);
                Nodes.Add(nodeModel);
            }
            else if (typeName.StartsWith("Dynamo.Models.ConnectorModel"))
            {
                ConnectorModel connector = ConnectorModel.Make();
                connector.Deserialize(modelData, SaveContext.Undo);
                Connectors.Add(connector);
            }
            else if (typeName.StartsWith("Dynamo.Models.NoteModel"))
            {
                NoteModel noteModel = new NoteModel(0.0, 0.0);
                noteModel.Deserialize(modelData, SaveContext.Undo);
                Notes.Add(noteModel);
            }
        }