Example #1
0
        private void SetTask()
        {
            Behaviac.Design.Nodes.Behavior refB = ((Behaviac.Design.Nodes.Behavior)_referencedBehavior);

            if (refB.Children.Count > 0 && refB.Children[0] is Task)
            {
                Task rootTask = refB.Children[0] as Task;
                this._task = (MethodDef)rootTask.Prototype.Clone();
            }
        }
Example #2
0
        private void LoadDescriptorRefs(List<Nodes.Node.ErrorCheck> result, XmlNode xmlNode, Behavior b)
        {
            b.DescriptorRefs.Clear();

            if (xmlNode != null) {
                Type type = b.DescriptorRefs.GetType();
                string valueString = xmlNode.Attributes["value"].Value;

                b.DescriptorRefs = (List<Behavior.DescriptorRef>)DesignerPropertyUtility.ParseStringValue(result, type, valueString, b);
            }
        }
Example #3
0
        public static bool IsInstanceName(string instance, Behavior behavior)
        {
            if (!string.IsNullOrEmpty(instance))
            {
                // global instances
                if (_instanceNamesDict.ContainsKey(instance))
                    return true;

                // local instances
                List<InstanceName_t> instances = GetLocalInstanceNames(behavior);
                foreach (InstanceName_t instanceName in instances)
                {
                    if (instanceName.name_ == instance)
                        return true;
                }
            }

            return false;
        }
Example #4
0
        public static int InstanceNameIndex(string instance, Behavior behavior)
        {
            instance = GetInstanceNameFromClassName(instance);

            // global instances
            int index = InstanceNames.FindIndex(delegate(InstanceName_t instanceName_t)
            {
                return instanceName_t.name_ == instance;
            });

            if (index >= 0)
                return index;

            // local instances
            index = InstanceNames.Count;

            List<InstanceName_t> instances = GetLocalInstanceNames(behavior);
            foreach (InstanceName_t instanceName in instances)
            {
                if (instanceName.name_ == instance)
                    return index;

                index++;
            }

            return -1;
        }
Example #5
0
        public static List<InstanceName_t> GetLocalInstanceNames(Behavior behavior)
        {
            List<InstanceName_t> instanceNames = new List<InstanceName_t>();

            if (behavior != null && behavior.AgentType != null)
            {
                foreach (PropertyDef prop in behavior.AgentType.GetProperties())
                {
                    if (Plugin.IsDerived(prop.Type, typeof(Agent)))
                    {
                        InstanceName_t instanceName = new InstanceName_t();

                        instanceName.name_ = prop.BasicName;
                        instanceName.className_ = prop.AgentType.AgentTypeName;
                        instanceName.agentType_ = Plugin.GetAgentType(prop.Type);
                        instanceName.displayName_ = prop.DisplayName;
                        instanceName.desc_ = prop.BasicDescription;

                        instanceNames.Add(instanceName);
                    }
                }
            }

            return instanceNames;
        }
Example #6
0
        public static AgentType GetInstanceAgentType(string instance, Behavior behavior, AgentType selfType)
        {
            if (!string.IsNullOrEmpty(instance))
            {
                // self
                if (instance == VariableDef.kSelf)
                    return selfType;

                // global instances
                if (_instanceNamesDict.ContainsKey(instance))
                    return _instanceNamesDict[instance].agentType_;

                // local instances
                List<InstanceName_t> instances = GetLocalInstanceNames(behavior);
                foreach (InstanceName_t instanceName in instances)
                {
                    if (instanceName.name_ == instance)
                        return instanceName.agentType_;
                }
            }

            return GetAgentType(instance);
        }
Example #7
0
        private void ExportDescritorRefs(BsonSerializer file, Behavior b) {
            if (Plugin.IsQueryFiltered)
            {
                return;
            }

            if (b.DescriptorRefs.Count > 0)
            {
                string propValue = DesignerArray.RetrieveExportValue(b.DescriptorRefs);
                file.WriteAttributeString("DescriptorRefs", propValue);
            }

            string propValue2 = b.Domains;
            if (!string.IsNullOrEmpty(propValue2))
            {
                file.WriteAttributeString("Domains", propValue2);
            }
        }
Example #8
0
        private void ExportPars(XmlWriter file, Behavior behavior) {
            if (behavior.LocalVars.Count == 0) {
                return;
            }

            file.WriteStartElement("pars");

            for (int i = 0; i < behavior.LocalVars.Count; ++i) {
                ParInfo par = behavior.LocalVars[i];

                //for node, only display pars are exported
                //if (bIsBehaviorRoot || par.Display)
                {
                    ExportPar(file, par, true);
                }
            }

            file.WriteEndElement();
        }
Example #9
0
        private void ExportDescritorRefs(XmlWriter file, Behavior b) {
            if (Plugin.IsQueryFiltered)
            { 
                return; 
            }

            if (b.DescriptorRefs.Count > 0)
            {
                file.WriteStartElement("property");
                string propValue = DesignerArray.RetrieveExportValue(b.DescriptorRefs);
                file.WriteAttributeString("DescriptorRefs", propValue);
                file.WriteEndElement();
            }

            {
                string propValue = b.Domains;
                if (!string.IsNullOrEmpty(propValue))
                {
                    file.WriteStartElement("property");
                    file.WriteAttributeString("Domains", propValue);
                    file.WriteEndElement();
                }
            }
        }
Example #10
0
        public Behavior(Behavior other)
            : this(string.Empty) {
            // Clone the hierarchy.
            //Nodes.BehaviorNode behavior = (Nodes.BehaviorNode)this.CloneBranch();

            // Set the agent type.
            this.AgentType = other.AgentType;

            // Clone the file manager.
            if (other.FileManager != null) {
                this.FileManager = (FileManagers.FileManager)other.FileManager.Clone();
                this.FileManager.Behavior = this;

            } else {
                this.Filename = other.Filename;
            }
        }
Example #11
0
        private void ExportPars(XmlWriter file, Behavior behavior)
        {
            if (behavior.LocalVars.Count == 0)
            {
                return;
            }

            file.WriteStartElement("pars");

            for (int i = 0; i < behavior.LocalVars.Count; ++i)
            {
                ParInfo par = behavior.LocalVars[i];

                ExportPar(file, par, true);
            }

            file.WriteEndElement();
        }
Example #12
0
        private void ExportDescritorRefs(BsonSerializer file, Behavior b)
        {
            if (b.DescriptorRefs.Count == 0)
                return;

            string propValue = DesignerArray.RetrieveExportValue(b.DescriptorRefs);
            file.WriteAttributeString("DescriptorRefs", propValue);
        }
Example #13
0
        private void ExportDescritorRefs(XmlWriter file, Behavior b)
        {
            if (b.DescriptorRefs.Count == 0)
                return;

            file.WriteStartElement("property");

            string propValue = DesignerArray.RetrieveExportValue(b.DescriptorRefs);
            file.WriteAttributeString("DescriptorRefs", propValue);

            file.WriteEndElement();
        }
Example #14
0
        private void checkErrorForSubTree(BehaviorNode rootBehavior, BehaviorNode referencedBehavior, List <ErrorCheck> result)
        {
            if (referencedBehavior != null)
            {
                // if our referenced behaviour could be loaded, check it as well for errors
                Behavior b = referencedBehavior as Behavior;

                if (b != null && b.AgentType != null)
                {
                    Behavior rootB = rootBehavior as Behavior;
                    Debug.Check(rootB != null);

                    if (rootB != null && rootB.AgentType != null)
                    {
                        string childBTAgent = b.AgentType.ToString();
                        string rootBTAgent  = rootB.AgentType.ToString();

                        //the agent type specified at root bt should be derived from the agent type at child bt
                        if (!Plugin.IsAgentDerived(rootBTAgent, childBTAgent) && !Plugin.IsAgentDerived(childBTAgent, rootBTAgent))
                        {
                            result.Add(new Node.ErrorCheck(this, ErrorCheckLevel.Error, Resources.AgentTypeError));
                        }
                    }
                }

                if (Plugin.EditMode == EditModes.Design)
                {
                    // circular reference
                    if (referencedBehavior != rootBehavior)
                    {
                        List <Node.ErrorCheck> childResult = new List <Node.ErrorCheck>();

                        if (referencedBehavior != null)
                        {
                            ((Node)referencedBehavior).CheckForErrors(rootBehavior, childResult);
                        }

                        if (childResult.Count > 0)
                        {
                            int    start    = 0;
                            string errorMsg = Resources.BehaviorIsEmptyError;

                            if (childResult[0].Level == ErrorCheckLevel.Error && childResult[0].Description.IndexOf(errorMsg) > 0)
                            {
                                start = 1;
                            }

                            bool bErrorFound = false;

                            for (int i = start; i < childResult.Count; ++i)
                            {
                                Node.ErrorCheck c = childResult[i];

                                if (c.Level == ErrorCheckLevel.Error)
                                {
                                    bErrorFound = true;
                                    break;
                                }
                            }

                            if (bErrorFound)
                            {
                                result.Add(new Node.ErrorCheck(this, bErrorFound ? ErrorCheckLevel.Error : ErrorCheckLevel.Warning, bErrorFound ? Resources.ReferenceError : Resources.ReferenceWarning));
                            }
                        }
                    }
                }

                if (this.Task != null)
                {
                    bool isParamCompleted = true;

                    foreach (MethodDef.Param param in this.Task.Params)
                    {
                        if (param.Value == null)
                        {
                            isParamCompleted = false;
                            break;
                        }
                    }

                    if (!isParamCompleted)
                    {
                        result.Add(new Node.ErrorCheck(this, ErrorCheckLevel.Error, Resources.NoParam));
                    }
                }
            }
        }
Example #15
0
        private void SaveDescriptorRefs(XmlElement root, Behavior b) {
            XmlElement elem = _xmlfile.CreateElement("DescriptorRefs");

            string value = DesignerArray.RetrieveExportValue(b.DescriptorRefs);

            elem.SetAttribute("value", value);

            root.AppendChild(elem);
        }
Example #16
0
        private void ExportPars(BsonSerializer file, Behavior behavior) {
            if (behavior.LocalVars.Count == 0)
            { return; }

            file.WriteStartElement("pars");

            for (int i = 0; i < behavior.LocalVars.Count; ++i) {
                ParInfo par = behavior.LocalVars[i];

                if (par.Display) {
                    ExportPar(file, par, true);
                }
            }

            file.WriteEndElement();
        }
Example #17
0
        //return true if rootBehavior's agent type is derived from the agent type of childBehavior.
        public static bool IsCompatibleAgentType(Behavior rootBehavior, Behavior childBehavior) {
            if (rootBehavior != null && childBehavior != null && rootBehavior.AgentType != null && childBehavior.AgentType != null) {
                string rootBTAgent = rootBehavior.AgentType.ToString();
                string childBTAgent = childBehavior.AgentType.ToString();

                // the agent type specified at root bt should be derived from the agent type at child bt
                if (!Plugin.IsAgentDerived(rootBTAgent, childBTAgent)) {
                    string errorMsg = string.Format(Resources.AgentErrorInfo, rootBTAgent, rootBehavior.Label, childBTAgent, childBehavior.Label);
                    MessageBox.Show(errorMsg, Resources.DesignerError, MessageBoxButtons.OK);
                    return false;
                }
            }

            return true;
        }
Example #18
0
        private void SetReferenceBehavior(BehaviorNode referencedBehavior_) {
            Debug.Check(referencedBehavior_ != null);

            Behavior refTree = null;
            bool bPlanningExpand = this.IsPlanningExpand();

            if (bPlanningExpand) {
                //set it first here as it might recursively point to itself
                //otherwise in the following Clone, referencedBehavior_  will be null
                this._referencedBehavior = referencedBehavior_;

                refTree = (Behavior)referencedBehavior_.Clone();
                refTree.ParentNode = this;
                refTree.PlanningProcess = Plugin.PlanningProcess;

                //TrimForPlanning_(refTree);

            } else {
                Behavior b = referencedBehavior_ as Behavior;
                refTree = new Behavior(b);
            }

            this._referencedBehavior = refTree;

            _referencedBehavior.WasModified += new WasModifiedEventDelegate(referencedBehavior_WasModified);
            _referencedBehavior.WasRenamed += new WasRenamedEventDelegate(referencedBehavior_WasRenamed);

            if (bPlanningExpand) {
                // assign the connector of the behaviour
                _genericChildren = _referencedBehavior.GenericChildren;
                _children.SetConnector(_genericChildren);

                this._planningProcess = Plugin.PlanningProcess;

                ms_expanding++;
                ExpandRefBehavior(refTree);
                ms_expanding--;
            }

            //when expand planning process, don't update _task, as it will be set wrongly
            if (Plugin.EditMode == EditModes.Design) {
                Behavior refTree_ = referencedBehavior_ as Behavior;

                if (refTree_.Children.Count > 0 && refTree_.Children[0] is Task) {
                    Task rootTask = refTree_.Children[0] as Task;
                    this._task = (MethodDef)rootTask.Prototype.Clone();
                }
            }
        }