예제 #1
0
 /// <summary>
 /// Sets the value of the property for the given event from a string.
 /// </summary>
 /// <param name="evnt">The event we want to set the value on.</param>
 /// <param name="valueString">The string holding the value.</param>
 public void SetValueFromString(List <Nodes.Node.ErrorCheck> result, Attachments.Attachment attach, string valueString)
 {
     if (_property != null)
     {
         _property.SetValue(attach, FromStringValue(result, attach, null, _property.PropertyType, valueString), null);
     }
 }
예제 #2
0
        private List <ParInfo> getPars()
        {
            List <ParInfo> pars = new List <ParInfo>();

            Nodes.Node             node   = _object as Nodes.Node;
            Attachments.Attachment attach = _object as Attachments.Attachment;

            if (node != null || attach != null || this._root != null)
            {
                Behaviac.Design.Nodes.BehaviorNode bn = (node != null ? node.Behavior : null);
                if (bn == null)
                {
                    bn = (attach != null ? attach.Behavior : null);
                }
                if (bn == null && this._root != null)
                {
                    bn = this._root.Behavior;
                }

                List <ParInfo> allPars = new List <ParInfo>();
                ((Nodes.Node)bn).GetAllPars(ref allPars);
                foreach (ParInfo par in allPars)
                {
                    if (!string.IsNullOrEmpty(par.Name))
                    {
                        if (Plugin.IsCompatibleType(FilterType, par.Type))
                        {
                            pars.Add(par);
                        }
                    }
                }
            }

            return(pars);
        }
        protected void OnValueChanged(DesignerPropertyInfo property)
        {
            if (!_valueWasAssigned)
            {
                return;
            }

            Nodes.Node node = _object as Nodes.Node;

            if (node != null)
            {
                node.OnPropertyValueChanged(true);
            }
            else
            {
                Attachments.Attachment attach = _object as Attachments.Attachment;
                if (attach != null)
                {
                    attach.OnPropertyValueChanged(true);
                }
            }

            if (ValueWasChanged != null)
            {
                ValueWasChanged(this, property);
            }
        }
예제 #4
0
        private void ExportParameters(BsonSerializer file, Attachments.Attachment attachment)
        {
            Attachments.Event evt = attachment as Attachments.Event;

            if (evt == null || evt.Pars.Count == 0)
            {
                return;
            }

            file.WriteStartElement("pars");

            for (int i = 0; i < evt.Pars.Count; ++i)
            {
                file.WriteStartElement("par");

                file.WriteString(evt.Pars[i].Name);
                file.WriteString(Plugin.GetNativeTypeName(evt.Pars[i].Type));
                file.WriteString(evt.Pars[i].DefaultValue);

                if (!string.IsNullOrEmpty(evt.Pars[i].EventParam))
                {
                    file.WriteString(evt.Pars[i].EventParam);
                }

                file.WriteEndElement();
            }

            file.WriteEndElement();
        }
예제 #5
0
        /// <summary>
        /// Loads an attachment which is attached to a node.
        /// </summary>
        /// <param name="node">The node the attachment is created for.</param>
        /// <param name="xml">The XML node the attachment retrieves its name and attributes from.</param>
        /// <returns>Returns the created Attachment.</returns>
        protected Attachments.Attachment CreateAttachment(List <Nodes.Node.ErrorCheck> result, Node node, XmlNode xml)
        {
            try
            {
                // get the type of the attachment and create it

                // maintain compatibility with version 1
                //string clss= GetAttribute(xml, "Class");
                string clss;

                if (!GetAttribute(xml, "Class", out clss))
                {
                    string find  = ".Events." + GetAttribute(xml, "name");
                    Type   found = Plugin.FindType(find);

                    if (found != null)
                    {
                        clss = found.FullName;
                    }
                }

                Type t = Plugin.GetType(clss);

                if (t == null)
                {
                    throw new Exception(string.Format(Resources.ExceptionUnknownEventType, clss));
                }

                Attachments.Attachment attach = Attachments.Attachment.Create(t, node);

                // initialise the attachments properties
                IList <DesignerPropertyInfo> properties = attach.GetDesignerProperties();

                for (int p = 0; p < properties.Count; ++p)
                {
                    if (properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        continue;
                    }

                    InitProperty(result, xml, attach, properties[p]);
                }

                // update attacheent with attributes
                attach.OnPropertyValueChanged(false);

                return(attach);
            }
            catch (Exception ex)
            {
                string msgError = string.Format("{0}\n{1}:\n{2} Of Node {3}", ex.Message, this.Filename, "Attachment", node.Id);

                //throw new Exception(msg);
                MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);
            }

            return(null);
        }
예제 #6
0
        /// <summary>
        /// Initialises a property on a given attachment.
        /// </summary>
        /// <param name="xml">The XML element containing the attribute we want to get.</param>
        /// <param name="node">The attachment whose property we want to set.</param>
        /// <param name="property">The property on the attachment we want to set.</param>
        protected void InitProperty(XmlNode xml, Attachments.Attachment attach, DesignerPropertyInfo property)
        {
            string value;

            if (GetAttribute(xml, property.Property.Name, out value))
            {
                property.SetValueFromString(attach, value);
            }
        }
예제 #7
0
        public override void Update()
        {
            if (_obj != null)
            {
                DesignerPropertyEditor binaryOperatorEditor = GetEditor(_obj, "BinaryOperator");
                Debug.Check(binaryOperatorEditor != null);

                Attachments.Attachment attach = _obj as Attachments.Attachment;
                if (attach != null && attach.Node != null && attach.Node.Attachments != null &&
                    attach.Node.Attachments.Count > 0 && attach.Node.Attachments[0] == attach)
                {
                    binaryOperatorEditor.Visible = false;
                }
            }
        }
        private void setObject(object obj)
        {
            _object = obj;
            _node   = _object as Nodes.Node;

            if (_node == null)
            {
                Attachments.Attachment attach = _object as Attachments.Attachment;

                if (attach != null)
                {
                    _node = attach.Node;
                }
            }
        }
예제 #9
0
        private void ExportProperties(BsonSerializer file, Attachments.Attachment a)
        {
            file.WriteStartElement("properties");
            IList <DesignerPropertyInfo> properties = a.GetDesignerProperties();

            foreach (DesignerPropertyInfo p in properties)
            {
                // we skip properties which are not marked to be exported
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                WriteProperty(file, p, a);
            }
            file.WriteEndElement();
        }
예제 #10
0
        private void ExportProperties(Attachments.Attachment a, int indent)
        {
            //DesignerPropertyInfo propertyEffector = new DesignerPropertyInfo();
            IList <DesignerPropertyInfo> properties = a.GetDesignerProperties(true);

            foreach (DesignerPropertyInfo p in properties)
            {
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                object v       = p.Property.GetValue(a, null);
                bool   bExport = !Plugin.IsExportArray(v);

                if (bExport)
                {
                    if (p.Property.Name != "Effectors")
                    {
                        string propValue = p.GetExportValue(a);
                        string name      = p.Property.Name;

                        if (propValue != string.Empty && propValue != "\"\"")
                        {
                            if (!ExportTypeMap.ContainsKey(name))
                            {
                                _err(String.Format("not support property!!! name:{0} value:{0}", name, propValue));
                            }
                            else if (ExportTypeMap[name] == PropertyType.Method)
                            {
                                ExportMethod(name, propValue, indent);
                            }
                            else if (ExportTypeMap[name] == PropertyType.Property)
                            {
                                ExportProperty(name, propValue, indent);
                            }
                            else
                            {
                                AddContent(String.Format("{0} = {1},", p.Property.Name, _quota(propValue)), indent);
                            }
                        }
                    }
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Loads an attachment which is attached to a node.
        /// </summary>
        /// <param name="node">The node the attachment is created for.</param>
        /// <param name="xml">The XML node the attachment retrieves its name and attributes from.</param>
        /// <returns>Returns the created Attachment.</returns>
        protected Attachments.Attachment CreateAttachment(Node node, XmlNode xml)
        {
            // get the type of the attachment and create it

            // maintain compatibility with version 1
            //string clss= GetAttribute(xml, "Class");
            string clss;

            if (!GetAttribute(xml, "Class", out clss))
            {
                string find  = ".Events." + GetAttribute(xml, "name");
                Type   found = Plugin.FindType(find);
                if (found != null)
                {
                    clss = found.FullName;
                }
            }

            Type t = Plugin.GetType(clss);

            if (t == null)
            {
                throw new Exception(string.Format(Resources.ExceptionUnknownEventType, clss));
            }

            Attachments.Attachment attach = Attachments.Attachment.Create(t, node);

            // initialise the attachments properties
            IList <DesignerPropertyInfo> properties = attach.GetDesignerProperties();

            for (int p = 0; p < properties.Count; ++p)
            {
                if (properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                {
                    continue;
                }

                InitProperty(xml, attach, properties[p]);
            }

            // update attacheent with attributes
            attach.OnPropertyValueChanged(false);

            return(attach);
        }
예제 #12
0
        public override bool ShouldAddProperty(DesignerPropertyInfo property)
        {
            if (_obj != null)
            {
                DesignerPropertyInfo binaryOperator = DesignerProperty.GetDesignerProperty(_obj.GetType(), "BinaryOperator");
                if (property.Property == binaryOperator.Property)
                {
                    Attachments.Attachment attach = _obj as Attachments.Attachment;
                    if (attach != null && attach.Node != null && attach.Node.Attachments != null &&
                        attach.Node.Attachments.Count > 0 && attach.Node.Attachments[0] == attach)
                    {
                        return(false);
                    }
                }
            }

            return(base.ShouldAddProperty(property));
        }
예제 #13
0
        private void ExportProperties(XmlWriter file, Attachments.Attachment a)
        {
            IList <DesignerPropertyInfo> properties = a.GetDesignerProperties();

            foreach (DesignerPropertyInfo p in properties)
            {
                // we skip properties which are not marked to be exported
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                // create the code which assigns the value to the node's property
                //file.Write(string.Format("{0}\t{1}.{2} = {3};\r\n", indent, nodeName, properties[p].Property.Name, properties[p].GetExportValue(node)));
                file.WriteStartElement("property");
                file.WriteAttributeString(p.Property.Name, p.GetExportValue(a));
                file.WriteEndElement();
            }
        }
예제 #14
0
        /// <summary>
        /// Returns the property this one is linked to.
        /// </summary>
        /// <param name="linkBroken">Is true if a link was found but it does not work.</param>
        /// <returns>The info of the property this is linked to.</returns>
        public DesignerPropertyInfo GetLinkedProperty(object obj, out bool linkBroken)
        {
            linkBroken = false;

            if (string.IsNullOrEmpty(_linkedToProperty))
            {
                return(new DesignerPropertyInfo());
            }

            DesignerPropertyInfo dpi = DesignerProperty.GetDesignerProperty(obj.GetType(), _linkedToProperty);

            // if we are linked to a DesignerNodeProperty we get the information of its assigned property
            DesignerNodeProperty dnp = dpi.Attribute as DesignerNodeProperty;

            if (dnp == null)
            {
                return(dpi);
            }

            Attachments.Attachment attach = (Attachments.Attachment)obj;

            // check if a valid property is associated
            object objvalue = dpi.Property.GetValue(obj, null);

            string value = dnp.GetDisplayValue(objvalue);

            if (string.IsNullOrEmpty(value) || value == Resources.DesignerNodePropertyNone)
            {
                linkBroken = true;

                return(new DesignerPropertyInfo());
            }

            // return the property we are pointing at
            return(DesignerProperty.GetDesignerProperty(attach.Node.GetType(), value));
        }
예제 #15
0
 public virtual void AddAttachment(Attachments.Attachment attach)
 {
     _attachments.Add(attach);
 }
예제 #16
0
 /// <summary>
 /// Returns the property's value as a string for exporting, skipping any encoding.
 /// </summary>
 /// <param name="obj">The value stored in the property unencoded.</param>
 /// <returns>The value as a string.</returns>
 public string GetExportValue(Attachments.Attachment attach)
 {
     return(_attribute.GetExportValue(_property.GetValue(attach, null)));
 }
        private string getValueType(MethodDef.Param param, string propertyName)
        {
            if (param.IsLocalVar)
            {
                Behaviac.Design.Nodes.Node node = _object as Behaviac.Design.Nodes.Node;

                if (node == null)
                {
                    Attachments.Attachment attach = (_object as Attachments.Attachment);

                    if (attach != null)
                    {
                        node = attach.Node;
                    }
                }

                Behaviac.Design.Nodes.Behavior behavior = (node != null) ? node.Behavior as Behaviac.Design.Nodes.Behavior : null;

                // Try to find the Agent property with the name.
                if (behavior != null && behavior.AgentType != null)
                {
                    IList <PropertyDef> properties = behavior.AgentType.GetProperties();
                    foreach (PropertyDef p in properties)
                    {
                        if (p.Name == propertyName
#if BEHAVIAC_NAMESPACE_FIX
                            || p.Name.EndsWith(propertyName)
#endif
                            )
                        {
                            return(VariableDef.kSelf);
                        }
                    }
                }

                // Try to find the global property with the name.
                string className = Plugin.GetClassName(propertyName);

                if (!string.IsNullOrEmpty(className))
                {
                    AgentType agent = Plugin.GetInstanceAgentType(className);

                    if (agent != null)
                    {
                        IList <PropertyDef> properties = agent.GetProperties();
                        foreach (PropertyDef p in properties)
                        {
                            if (p.Name == propertyName
#if BEHAVIAC_NAMESPACE_FIX
                                || p.Name.EndsWith(propertyName)
#endif
                                )
                            {
                                return(className);
                            }
                        }
                    }
                }
            }

            return(VariableDef.kConst);
        }
예제 #18
0
        private void ExportProperties(BsonSerializer file, Attachments.Attachment a)
        {
            DesignerPropertyInfo propertyEffector = new DesignerPropertyInfo();

            file.WriteStartElement("properties");
            IList <DesignerPropertyInfo> properties = a.GetDesignerProperties(true);

            foreach (DesignerPropertyInfo p in properties)
            {
                // we skip properties which are not marked to be exported
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                object v       = p.Property.GetValue(a, null);
                bool   bExport = !Plugin.IsExportArray(v);

                if (bExport)
                {
                    if (p.Property.Name == "Effectors")
                    {
                        propertyEffector = p;
                    }
                    else
                    {
                        WriteProperty(file, p, a);
                    }
                }
            }

            file.WriteEndElement();

            if (propertyEffector.Property != null)
            {
                List <TransitionEffector> listV = (List <TransitionEffector>)propertyEffector.Property.GetValue(a, null);

                if (listV != null)
                {
                    file.WriteStartElement("attachments");
                    foreach (TransitionEffector te in listV)
                    {
                        file.WriteStartElement("attachment");
                        file.WriteStartElement("properties");
                        IList <DesignerPropertyInfo> effectorProperties = te.GetDesignerProperties();
                        foreach (DesignerPropertyInfo p in effectorProperties)
                        {
                            // we skip properties which are not marked to be exported
                            if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                            {
                                continue;
                            }

                            WriteProperty(file, p, te);
                        }

                        file.WriteEndElement();
                        file.WriteEndElement();
                    }

                    file.WriteEndElement();
                }
            }
        }
예제 #19
0
        private void ExportProperties(XmlWriter file, Attachments.Attachment a)
        {
            DesignerPropertyInfo         propertyEffector = new DesignerPropertyInfo();
            IList <DesignerPropertyInfo> properties       = a.GetDesignerProperties(true);

            foreach (DesignerPropertyInfo p in properties)
            {
                // we skip properties which are not marked to be exported
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                object v       = p.Property.GetValue(a, null);
                bool   bExport = !Plugin.IsExportArray(v);

                if (bExport)
                {
                    if (p.Property.Name == "Effectors")
                    {
                        propertyEffector = p;
                    }
                    else
                    {
                        // create the code which assigns the value to the node's property
                        //file.Write(string.Format("{0}\t{1}.{2} = {3};\r\n", indent, nodeName, properties[p].Property.Name, properties[p].GetExportValue(node)));
                        string propValue = p.GetExportValue(a);

                        if (propValue != string.Empty && propValue != "\"\"")
                        {
                            file.WriteStartElement("property");
                            file.WriteAttributeString(p.Property.Name, propValue);
                            file.WriteEndElement();
                        }
                    }
                }
            }

            if (propertyEffector.Property != null)
            {
                List <TransitionEffector> listV = (List <TransitionEffector>)propertyEffector.Property.GetValue(a, null);

                if (listV != null)
                {
                    foreach (TransitionEffector te in listV)
                    {
                        IList <DesignerPropertyInfo> effectorProperties = te.GetDesignerProperties();
                        file.WriteStartElement("attachment");

                        foreach (DesignerPropertyInfo p in effectorProperties)
                        {
                            // we skip properties which are not marked to be exported
                            if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                            {
                                continue;
                            }

                            string propValue = p.GetExportValue(te);

                            if (propValue != string.Empty && propValue != "\"\"")
                            {
                                file.WriteStartElement("property");
                                file.WriteAttributeString(p.Property.Name, propValue);
                                file.WriteEndElement();
                            }
                        }

                        file.WriteEndElement();
                    }
                }
            }
        }
예제 #20
0
        public static MethodDef parseMethodString(List <Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, MethodType methodType, string str)
        {
            try {
                if (agentType != null)
                {
                    int pos = str.IndexOf('(');

                    if (pos < 0)
                    {
                        return(null);
                    }

                    string ownerName  = agentType.ToString();
                    int    pointIndex = str.IndexOf('.');

                    if (pointIndex > -1 && pointIndex < pos)
                    {
                        ownerName = str.Substring(0, pointIndex);

                        if (ownerName != VariableDef.kSelf && !Plugin.IsInstanceName(ownerName))
                        {
                            throw new Exception("The instance does not exist.");
                        }

                        str       = str.Substring(pointIndex + 1, str.Length - pointIndex - 1);
                        agentType = Plugin.GetInstanceAgentType(ownerName, agentType);
                        //if (agentType == node.Behavior.AgentType)
                        //    ownerName = VariableDef.kSelf;
                        pos = str.IndexOf('(');
                    }

                    IList <MethodDef> actions    = agentType.GetMethods(methodType);
                    string            actionName = str.Substring(0, pos);
                    foreach (MethodDef actionTypeIt in actions)
                    {
                        if (actionTypeIt.Name == actionName
#if BEHAVIAC_NAMESPACE_FIX
                            || actionTypeIt.Name.EndsWith(actionName)
#endif
                            )
                        {
                            MethodDef method = new MethodDef(actionTypeIt);
                            method.Owner = ownerName;

                            List <string> paras = parseParams(str.Substring(pos + 1, str.Length - pos - 2));
                            //Debug.Check((paras.Count == actionTypeIt.Params.Count));

                            //if (paras.Count == actionTypeIt.Params.Count)
                            {
                                for (int i = 0; i < paras.Count; ++i)
                                {
                                    if (i >= method.Params.Count)
                                    {
                                        break;
                                    }

                                    string          param = paras[i];
                                    MethodDef.Param par   = method.Params[i];
                                    bool            bOk   = parseParam(result, node, method, par, param);

                                    if (!bOk)
                                    {
                                        throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str));
                                    }
                                }
                            }

                            return(method);
                        }
                    }
                }
            } catch (Exception) {
                //System.Windows.Forms.MessageBox.Show(str, Resources.LoadError, System.Windows.Forms.MessageBoxButtons.OK);
                if (result != null)
                {
                    Nodes.Node n     = node as Nodes.Node;
                    string     label = "";
                    if (n == null)
                    {
                        Attachments.Attachment a = node as Attachments.Attachment;
                        if (a != null)
                        {
                            n     = a.Node;
                            label = a.Label;
                        }
                    }
                    else
                    {
                        label = n.Label;
                    }

                    Nodes.Node.ErrorCheck error = new Nodes.Node.ErrorCheck(n, node.Id, label, Nodes.ErrorCheckLevel.Error, str);
                    result.Add(error);
                }
            }

            return(null);
        }
예제 #21
0
        /// <summary>
        /// Initialises a property on a given attachment.
        /// </summary>
        /// <param name="xml">The XML element containing the attribute we want to get.</param>
        /// <param name="node">The attachment whose property we want to set.</param>
        /// <param name="property">The property on the attachment we want to set.</param>
        protected void InitProperty(List <Nodes.Node.ErrorCheck> result, XmlNode xml, Attachments.Attachment attach, DesignerPropertyInfo property)
        {
            string value;

            if (GetAttribute(xml, property.Property.Name, out value))
            {
                property.SetValueFromString(result, attach, value);
            }
        }
예제 #22
0
        /// <summary>
        /// Loads a node from a given XML node.
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        /// <param name="xml">The XML node we want to create the node from.</param>
        /// <param name="parent">The parent this node will be added to.</param>
        /// <param name="connector">The connector used to add this node to the parent.</param>
        /// <returns>Returns the created node.</returns>
        protected Node CreateNodeAndAdd(List <Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode, XmlNode xml, Node parent, Node.Connector connector)
        {
            try {
                // get the type of the node and create it
                string clss = GetAttribute(xml, "Class");
                Type   t    = Plugin.GetType(clss);

                if (t == null)
                {
                    string msg = string.Format(Resources.ExceptionUnknownNodeType, clss);

                    string msgError = string.Format("{0}:\n{1}", this.Filename, msg);

                    //throw new Exception(msg);
                    MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);

                    parent.Behavior.TriggerWasModified(parent);

                    return(null);
                }

                Node node = Nodes.Node.Create(t);

                if (parent == null)
                {
                    //if this._version == 0, it means there is no Version attribute in the file
                    node.Behavior.Version = this._version;
                }

                // update the loaded behaviour member
                if (node is BehaviorNode)
                {
                    ((BehaviorNode)node).FileManager = this;
                }

                // add the node to the parent
                if (parent != null)
                {
                    if (connector != null)
                    {
                        parent.AddChildNotModified(connector, node);
                    }

                    else
                    {
                        parent.AddFSMNode(node);
                    }
                }

                int version = 0;

                if (node.Behavior != null)
                {
                    version = node.Behavior.Version;
                }
                else
                {
                    Debug.Check(true);
                }

                SetEnterExitSlot(result, xml, node, version);

                // initialise the properties
                IList <DesignerPropertyInfo> properties = node.GetDesignerProperties();
                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        InitProperty(result, xml, node, property);
                    }
                }

                // return the created behaviour node
                if (node is BehaviorNode)
                {
                    getBehaviorNode((BehaviorNode)node);
                }

                // maintain compatibility with version 1
                if (node is ReferencedBehaviorNode)
                {
                    ReferencedBehaviorNode refbehavior = (ReferencedBehaviorNode)node;

                    if (refbehavior.ReferenceFilename == null)
                    {
                        refbehavior.ReferenceFilename = GetAttribute(xml, "Reference");
                    }
                }

                // update node with properties
                node.OnPropertyValueChanged(false);

                // load child objects
                foreach (XmlNode xnode in xml.ChildNodes)
                {
                    if (xnode.NodeType == XmlNodeType.Element)
                    {
                        switch (xnode.Name)
                        {
                        // load parameters
                        case ("Parameters"):
                            if (node is Behavior || node is ReferencedBehavior)
                            {
                                LoadParameters(result, xnode, node, node.LocalVars);
                                node.Behavior.PostLoadPars();
                            }

                            break;

                        case ("DescriptorRefs"):
#if QUERY_EANBLED
                            LoadDescriptorRefs(result, xnode, node.Behavior as Behavior);
#endif//#if QUERY_EANBLED
                            break;

                        // maintain compatibility with version 1
                        case ("Node"):
                            CreateNodeAndAdd(result, getBehaviorNode, xnode, node, node.GetConnector(BaseNode.Connector.kGeneric));
                            break;

                        // maintain compatibility with version 2.1
                        case ("Event"):
                        case ("Attachment"): {
                            Attachments.Attachment a = CreateAttachment(result, node, xnode);

                            if (a != null)
                            {
                                node.AddAttachment(a);

                                a.PostCreate(result, version, node, xnode);
                            }
                        }
                        break;

                        case ("Comment"):
                            // create a comment object
                            node.CommentText = "temp";

                            // initialise the attributes
                            properties = node.CommentObject.GetDesignerProperties();
                            foreach (DesignerPropertyInfo property in properties)
                            {
                                if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                                {
                                    continue;
                                }

                                string value;

                                if (GetAttribute(xnode, property.Property.Name, out value))
                                {
                                    property.SetValueFromString(result, node.CommentObject, value);
                                }
                            }
                            break;

                        case ("Connector"):
                            string identifier         = GetAttribute(xnode, "Identifier");
                            Nodes.Node.Connector conn = node.GetConnector(identifier);

                            foreach (XmlNode connected in xnode.ChildNodes)
                            {
                                if (connected.NodeType == XmlNodeType.Element && connected.Name == "Node")
                                {
                                    CreateNodeAndAdd(result, getBehaviorNode, connected, node, conn);
                                }
                            }
                            break;

                        case ("FSMNodes"):
                            string locationX = GetAttribute(xnode, "ScreenLocationX");
                            string locationY = GetAttribute(xnode, "ScreenLocationY");

                            if (!string.IsNullOrEmpty(locationX) && !string.IsNullOrEmpty(locationY))
                            {
                                try {
                                    float x = float.Parse(locationX);
                                    float y = float.Parse(locationY);
                                    node.ScreenLocation = new System.Drawing.PointF(x, y);
                                } catch {
                                }
                            }

                            foreach (XmlNode fsmNode in xnode.ChildNodes)
                            {
                                if (fsmNode.NodeType == XmlNodeType.Element && fsmNode.Name == "Node")
                                {
                                    CreateNodeAndAdd(result, getBehaviorNode, fsmNode, node, null);
                                }
                            }
                            break;
                        }
                    }
                }

                // update attachments with attributes
                foreach (Attachments.Attachment attach in node.Attachments)
                {
                    attach.OnPropertyValueChanged(false);
                }

                // set the properties from its prefab
                bool isPrefabInstance = !string.IsNullOrEmpty(node.PrefabName) && !node.HasOwnPrefabData;

                if (isPrefabInstance)
                {
                    Node prefabNode = Plugin.GetPrefabNode(node);

                    if (prefabNode != null)
                    {
                        node.ResetByPrefab(node.PrefabName, prefabNode);

                        Behavior b = node.Behavior as Behavior;
                        b.AgentType.AddPars(b.LocalVars);
                    }
                }

                node.PostCreate(result, version, xml);

                return(node);
            } catch (Exception e) {
                string idNode   = xml.Attributes["Id"].Value;
                string msgError = string.Format("{0}:\r\nNode Id:{1}\r\n{2}", this.Filename, idNode, e.Message);

                //throw new Exception(msg);
                MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);
            }

            return(null);
        }
예제 #23
0
 /// <summary>
 /// Returns the property's value.
 /// </summary>
 /// <param name="node">The attachment we want to get the value from.</param>
 /// <returns>The value as an object.</returns>
 public object GetValue(Attachments.Attachment attach)
 {
     return(_property.GetValue(attach, null));
 }
예제 #24
0
 /// <summary>
 /// Sets the value of the property for the given event from a string.
 /// </summary>
 /// <param name="evnt">The event we want to set the value on.</param>
 /// <param name="valueString">The string holding the value.</param>
 public void SetValueFromString(Attachments.Attachment attach, string valueString)
 {
     _property.SetValue(attach, FromStringValue(attach, null, _property.PropertyType, valueString), null);
 }
예제 #25
0
        /// <summary>
        /// Loads an attachment which is attached to a node.
        /// </summary>
        /// <param name="node">The node the attachment is created for.</param>
        /// <param name="xml">The XML node the attachment retrieves its name and attributes from.</param>
        /// <returns>Returns the created Attachment.</returns>
        protected Attachments.Attachment CreateAttachment(Node node, XmlNode xml)
        {
            try
            {
                // get the type of the attachment and create it

                // maintain compatibility with version 1
                //string clss= GetAttribute(xml, "Class");
                string clss;
                if (!GetAttribute(xml, "Class", out clss))
                {
                    string find  = ".Events." + GetAttribute(xml, "name");
                    Type   found = Plugin.FindType(find);
                    if (found != null)
                    {
                        clss = found.FullName;
                    }
                }

                Type t = Plugin.GetType(clss);

                if (t == null)
                {
                    throw new Exception(string.Format(Resources.ExceptionUnknownEventType, clss));
                }

                Attachments.Attachment attach = Attachments.Attachment.Create(t, node);

                // initialise the attachments properties
                IList <DesignerPropertyInfo> properties = attach.GetDesignerProperties();
                for (int p = 0; p < properties.Count; ++p)
                {
                    if (properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        continue;
                    }

                    InitProperty(xml, attach, properties[p]);
                }

                // update attacheent with attributes
                attach.OnPropertyValueChanged(false);

                Attachments.Event evt = attach as Attachments.Event;

                if (evt != null)
                {
                    foreach (XmlNode xnode in xml.ChildNodes)
                    {
                        if (xnode.NodeType == XmlNodeType.Element)
                        {
                            switch (xnode.Name.ToLowerInvariant())
                            {
                            // load parameters
                            case ("parameters"):
                                LoadParameters(xnode, node, evt.Pars);
                                break;
                            }
                        }
                    }
                }

                return(attach);
            }
            catch (Exception ex)
            {
                string msgError = string.Format("{0}\n{1}:\n{2}", ex.Message, this.Filename, "Attachment");

                //throw new Exception(msg);
                MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);
            }

            return(null);
        }
예제 #26
0
 public virtual void RemoveAttachment(Attachments.Attachment attach)
 {
     _attachments.Remove(attach);
 }
예제 #27
0
        /// <summary>
        /// Loads a node from a given XML node.
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        /// <param name="xml">The XML node we want to create the node from.</param>
        /// <param name="parent">The parent this node will be added to.</param>
        /// <param name="connector">The connector used to add this node to the parent.</param>
        /// <returns>Returns the created node.</returns>
        protected Node CreateNodeAndAdd(GetBehaviorNode getBehaviorNode, XmlNode xml, Node parent, Node.Connector connector)
        {
            try
            {
                // get the type of the node and create it
                string clss = GetAttribute(xml, "Class");
                Type   t    = Plugin.GetType(clss);

                if (t == null)
                {
                    string msg = string.Format(Resources.ExceptionUnknownNodeType, clss);

                    string msgError = string.Format("{0}:\n{1}", this.Filename, msg);

                    //throw new Exception(msg);
                    MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);

                    parent.Behavior.IsModified = true;

                    return(null);
                }

                Node node = Nodes.Node.Create(t);

                // update the loaded behaviour member
                if (node is BehaviorNode)
                {
                    ((BehaviorNode)node).FileManager = this;
                }

                // add the node to the parent
                if (parent != null)
                {
                    Debug.Check(connector != null);
                    parent.AddChildNotModified(connector, node);
                }

                // initialise the properties
                IList <DesignerPropertyInfo> properties = node.GetDesignerProperties();
                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        InitProperty(xml, node, property);
                        node.PostPropertyInit(property);
                    }
                }

                // return the created behaviour node
                if (node is BehaviorNode)
                {
                    getBehaviorNode((BehaviorNode)node);
                }

                // maintain compatibility with version 1
                if (node is ReferencedBehaviorNode)
                {
                    ReferencedBehaviorNode refbehavior = (ReferencedBehaviorNode)node;
                    if (refbehavior.ReferenceFilename == null)
                    {
                        refbehavior.ReferenceFilename = GetAttribute(xml, "Reference");
                    }
                }

                // update node with properties
                node.OnPropertyValueChanged(false);

                // load child objects
                foreach (XmlNode xnode in xml.ChildNodes)
                {
                    if (xnode.NodeType == XmlNodeType.Element)
                    {
                        switch (xnode.Name.ToLowerInvariant())
                        {
                        // load parameters
                        case ("parameters"):
                            LoadParameters(xnode, node, node.Pars);
                            break;

                        case ("descriptorrefs"):
#if QUERY_EANBLED
                            LoadDescriptorRefs(xnode, node.Behavior as Behavior);
#endif//#if QUERY_EANBLED
                            break;

                        // maintain compatibility with version 1
                        case ("node"):
                            CreateNodeAndAdd(getBehaviorNode, xnode, node, node.GetConnector("GenericChildren"));
                            break;

                        // maintain compatibility with version 2.1
                        case ("event"):

                        case ("attachment"):
                        {
                            Attachments.Attachment a = CreateAttachment(node, xnode);

                            if (a != null)
                            {
                                node.AddAttachment(a);
                            }
                        }
                        break;

                        case ("comment"):
                            // create a comment object
                            node.CommentText = "temp";

                            // initialise the attributes
                            properties = node.CommentObject.GetDesignerProperties();
                            foreach (DesignerPropertyInfo property in properties)
                            {
                                if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                                {
                                    continue;
                                }

                                string value;
                                if (GetAttribute(xnode, property.Property.Name, out value))
                                {
                                    property.SetValueFromString(node.CommentObject, value);
                                }
                            }
                            break;

                        case ("connector"):
                            string identifier         = GetAttribute(xnode, "Identifier");
                            Nodes.Node.Connector conn = node.GetConnector(identifier);

                            foreach (XmlNode connected in xnode.ChildNodes)
                            {
                                if (connected.NodeType == XmlNodeType.Element &&
                                    connected.Name.ToLowerInvariant() == "node")
                                {
                                    CreateNodeAndAdd(getBehaviorNode, connected, node, conn);
                                }
                            }
                            break;
                        }
                    }
                }

                // update attachments with attributes
                foreach (Attachments.Attachment attach in node.Attachments)
                {
                    attach.OnPropertyValueChanged(false);
                }

                // set the properties from its prefab
                bool isPrefabInstance = !string.IsNullOrEmpty(node.PrefabName) && !node.HasOwnPrefabData;
                if (isPrefabInstance)
                {
                    Node prefabNode = Plugin.GetPrefabNode(node);
                    if (prefabNode != null)
                    {
                        node.ResetByPrefab(node.PrefabName, prefabNode);
                    }
                }

                return(node);
            }
            catch (Exception e)
            {
                string idNode   = xml.Attributes["Id"].Value;
                string msgError = string.Format("{0}:\r\nNode Id:{1}\r\n{2}", this.Filename, idNode, e.Message);

                //throw new Exception(msg);
                MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);
            }

            return(null);
        }