Example #1
0
        void item_Click(object sender, EventArgs e)
        {
            MenuItem item = (MenuItem)sender;

            Type  editorType = (Type)item.Tag;
            Label label      = (Label)item.Parent.Tag;
            DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag;

            Debug.Check(_selectedObject == editor.SelectedObject);

            Nodes.Node node = _selectedObject as Nodes.Node;

            if (node != null)
            {
                node.OnPropertyValueChanged(true);
            }

            Attachments.Attachment attach = _selectedObject as Attachments.Attachment;

            if (attach != null)
            {
                attach.OnPropertyValueChanged(true);
            }

            SelectedObject = _selectedObject;
        }
        protected override void CloneProperties(Behaviac.Design.Attachments.Attachment newattach)
        {
            base.CloneProperties(newattach);

            TransitionCondition con = (TransitionCondition)newattach;

            con.TargetFSMNodeId = this.TargetFSMNodeId;

            if (this._opl != null)
            {
                con._opl = (RightValueDef)this._opl.Clone();
            }

            if (this._opr1 != null)
            {
                con._opr1 = (RightValueDef)this._opr1.Clone();
            }

            con._operator = this._operator;

            if (_opr2 != null)
            {
                con._opr2 = (RightValueDef)_opr2.Clone();
            }

            con._effectors = new List <TransitionEffector>();
            foreach (TransitionEffector effector in this._effectors)
            {
                con._effectors.Add(new TransitionEffector(effector));
            }
        }
Example #3
0
        protected override void CloneProperties(Behaviac.Design.Attachments.Attachment newattach)
        {
            base.CloneProperties(newattach);

            Effector prec = (Effector)newattach;

            prec._phase = _phase;
        }
Example #4
0
        protected override void CloneProperties(Behaviac.Design.Attachments.Attachment newattach)
        {
            base.CloneProperties(newattach);

            StartCondition con = (StartCondition)newattach;

            con.TargetFSMNodeId = this.TargetFSMNodeId;
        }
Example #5
0
        protected override void CloneProperties(Behaviac.Design.Attachments.Attachment newattach)
        {
            base.CloneProperties(newattach);

            Precondition prec = (Precondition)newattach;

            prec._binary = _binary;
            prec._phase  = _phase;
        }
        protected string GetGeneratedClassName(Attachment attachment, string btClassName, string nodeName)
        {
            if (ShouldGenerateClass())
            {
                return string.Format("{0}_{1}_{2}", attachment.ExportClass, btClassName, nodeName);
            }

            return attachment.ExportClass;
        }
        protected override void GenerateConstructor(Attachment attachment, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(attachment, stream, indent, className);

            AlwaysTransition alwaysTransition = attachment as AlwaysTransition;
            if (alwaysTransition == null)
                return;

            stream.WriteLine("{0}\t\t\tthis->SetTargetStateId({1}, {2});", indent, alwaysTransition.TargetFSMNodeId, alwaysTransition.TransitionPhase);
        }
Example #8
0
        protected override void CloneProperties(Behaviac.Design.Attachments.Attachment newattach)
        {
            base.CloneProperties(newattach);

            AlwaysTransition con = (AlwaysTransition)newattach;

            con.TargetFSMNodeId = this.TargetFSMNodeId;

            con._statusPhase = this._statusPhase;
        }
        protected override void GenerateConstructor(Attachment attachment, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(attachment, stream, indent, className);

            WaitTransition waitTransition = attachment as WaitTransition;
            if (waitTransition == null)
                return;

            stream.WriteLine("{0}\t\t\tthis.TargetStateId = {1};", indent, waitTransition.TargetFSMNodeId);
        }
Example #10
0
        public static AttachmentCsExporter CreateInstance(Attachment attachment)
        {
            if (attachment != null)
            {
                Type exporterType = getExporterType(attachment.GetType());
                if (exporterType != null)
                    return (AttachmentCsExporter)Activator.CreateInstance(exporterType);
            }

            return new AttachmentCsExporter();
        }
Example #11
0
        public void GenerateClass(Attachment attachment, StreamWriter stream, string indent, string nodeName, string btClassName)
        {
            if (ShouldGenerateClass())
            {
                string className = GetGeneratedClassName(attachment, btClassName, nodeName);

                stream.WriteLine("{0}\tclass {1} : behaviac.{2}\r\n{0}\t{{", indent, className, attachment.ExportClass);

                GenerateMethod(attachment, stream, indent);

                stream.WriteLine("{0}\t}}\r\n", indent);
            }
        }
Example #12
0
        protected override void GenerateMethod(Attachment attachment, StreamWriter stream, string indent)
        {
            Event evt = attachment as Event;
            Debug.Check(evt != null);

            stream.WriteLine("{0}\t\tpublic void Initialize(string eventName, string referencedBehavior, TriggerMode mode, bool once)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tthis.m_event = Action.LoadMethod(eventName);", indent);
            stream.WriteLine("{0}\t\t\tthis.m_referencedBehaviorPath = referencedBehavior;", indent);
            stream.WriteLine("{0}\t\t\tthis.m_triggerMode = mode;", indent);
            stream.WriteLine("{0}\t\t\tthis.m_bTriggeredOnce = once;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Example #13
0
        public override void GenerateInstance(Attachment attachment, StreamWriter stream, string indent, string nodeName, string agentType, string btClassName)
        {
            base.GenerateInstance(attachment, stream, indent, nodeName, agentType, btClassName);

            Event evt = attachment as Event;
            if (evt == null)
                return;

            string triggerMode = (evt.TriggerMode == TriggerMode.Transfer) ? "TM_Transfer" : "TM_Return";
            string triggeredOnce = evt.TriggeredOnce ? "true" : "false";

            stream.WriteLine("{0}\t{1}->Initialize(\"{2}\", \"{3}\", {4}, {5});", indent, nodeName, evt.Task.GetExportValue(), evt.ReferenceFilename, triggerMode, triggeredOnce);
        }
Example #14
0
        public virtual void GenerateInstance(Attachment attachment, StreamWriter stream, string indent, string nodeName, string agentType, string btClassName)
        {
            string className = GetGeneratedClassName(attachment, btClassName, nodeName);

            // create a new instance of the node
            stream.WriteLine("{0}\t{1} {2} = new {1}();", indent, className, nodeName);

            // set its basic properties
            stream.WriteLine("{0}\t{1}.SetClassNameString(\"{2}\");", indent, nodeName, attachment.ExportClass);
            stream.WriteLine("{0}\t{1}.SetId({2});", indent, nodeName, attachment.Id);
            stream.WriteLine("#if !BEHAVIAC_RELEASE");
            stream.WriteLine("{0}\t{1}.SetAgentType(\"{2}\");", indent, nodeName, agentType.Replace("::", "."));
            stream.WriteLine("#endif");
        }
        public static AttachmentCppExporter CreateInstance(Attachment attachment)
        {
            if (attachment != null)
            {
                string attachmentExporter = "PluginBehaviac.NodeExporters." + attachment.ExportClass + "CppExporter";
                Type exporterType = Type.GetType(attachmentExporter);
                if (exporterType != null)
                {
                    return (AttachmentCppExporter)Activator.CreateInstance(exporterType);
                }
            }

            return new AttachmentCppExporter();
        }
Example #16
0
        public override void GenerateInstance(Attachment attachment, StreamWriter stream, string indent, string nodeName, string agentType, string btClassName)
        {
            string className = GetGeneratedClassName(attachment, btClassName, nodeName);

            // create a new instance of the node
            stream.WriteLine("{0}\t{1}* {2} = BEHAVIAC_NEW {1};", indent, className, nodeName);

            // set its basic properties
            stream.WriteLine("{0}\t{1}->SetClassNameString(\"{2}\");", indent, nodeName, attachment.ExportClass);
            stream.WriteLine("{0}\t{1}->SetId({2});", indent, nodeName, attachment.Id);
            stream.WriteLine("#if !BEHAVIAC_RELEASE");
            stream.WriteLine("{0}\t{1}->SetAgentType(\"{2}\");", indent, nodeName, agentType);
            stream.WriteLine("#endif");
        }
Example #17
0
        protected override void GenerateConstructor(Attachment attachment, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(attachment, stream, indent, className);

            Event evt = attachment as Event;
            if (evt == null)
                return;

            string triggerMode = (evt.TriggerMode == TriggerMode.Transfer) ? "TriggerMode.TM_Transfer" : "TriggerMode.TM_Return";
            string triggeredOnce = evt.TriggeredOnce ? "true" : "false";

            stream.WriteLine("{0}\t\t\tthis.Initialize(\"{1}\", \"{2}\", {3}, {4});",
                indent, evt.Task.GetExportValue(), evt.ReferenceFilename, triggerMode, triggeredOnce);
        }
        public void GenerateClass(Attachment attachment, StreamWriter stream, string indent, string nodeName, string btClassName)
        {
            if (ShouldGenerateClass())
            {
                string className = GetGeneratedClassName(attachment, btClassName, nodeName);

                stream.WriteLine("{0}\tclass BEHAVIAC_API {1} : public {2}\r\n{0}\t{{", indent, className, attachment.ExportClass);
                stream.WriteLine("{0}\tpublic:\r\n{0}\t\tBEHAVIAC_DECLARE_DYNAMIC_TYPE({1}, {2});", indent, className, attachment.ExportClass);

                GenerateMethod(attachment, stream, indent);

                stream.WriteLine("{0}\t}};\r\n", indent);
            }
        }
Example #19
0
        protected override void GenerateMethod(Attachment attachment, StreamWriter stream, string indent)
        {
            Event evt = attachment as Event;
            if (evt == null)
                return;

            stream.WriteLine("{0}\tpublic:", indent);

            stream.WriteLine("{0}\t\tvoid Initialize(const char* eventName, const char* referencedBehavior, TriggerMode mode, bool once)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tthis->m_event = Action::LoadMethod(eventName);", indent);
            stream.WriteLine("{0}\t\t\tthis->m_referencedBehaviorPath = referencedBehavior;", indent);
            stream.WriteLine("{0}\t\t\tthis->m_triggerMode = mode;", indent);
            stream.WriteLine("{0}\t\t\tthis->m_bTriggeredOnce = once;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Example #20
0
        public override void GenerateInstance(Attachment attachment, StreamWriter stream, string indent, string nodeName, string agentType, string btClassName)
        {
            base.GenerateInstance(attachment, stream, indent, nodeName, agentType, btClassName);

            Event evt = attachment as Event;
            Debug.Check(evt != null);

            if (evt.EventName != null)
            {
                string eventName = evt.EventName.GetExportValue().Replace("\"", "\\\"");

                stream.WriteLine("{0}\t{1}.Initialize(\"{2}\", \"{3}\", {4}, {5});",
                    indent, nodeName, eventName, evt.ReferenceFilename,
                    (evt.TriggerMode == TriggerMode.Transfer) ? "TriggerMode.TM_Transfer" : "TriggerMode.TM_Return",
                    evt.TriggeredOnce ? "true" : "false");
            }
        }
        protected override void GenerateMember(Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMember(attachment, stream, indent);

            TransitionCondition transition = attachment as TransitionCondition;
            if (transition == null)
                return;

            if (transition.Opl != null)
            {
                RightValueCppExporter.GenerateClassMember(transition.Opl, stream, indent, "opl");
            }

            if (transition.Opr2 != null)
            {
                RightValueCppExporter.GenerateClassMember(transition.Opr2, stream, indent, "opr2");
            }
        }
Example #22
0
        protected override void CloneProperties(Behaviac.Design.Attachments.Attachment newattach)
        {
            base.CloneProperties(newattach);

            Predicate prec = (Predicate)newattach;

            //prec._negate = _negate;
            if (this._opl != null)
            {
                prec._opl = (RightValueDef)this._opl.Clone();
            }

            if (this._opr != null)
            {
                prec._opr = (VariableDef)this._opr.Clone();
            }

            prec._operator = this._operator;
        }
        protected override void GenerateConstructor(Attachment attachment, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(attachment, stream, indent, className);

            TransitionCondition transition = attachment as TransitionCondition;
            if (transition == null)
                return;

            stream.WriteLine("{0}\t\t\tthis->SetTargetStateId({1});", indent, transition.TargetFSMNodeId);

            if (transition.Opl != null)
            {
                RightValueCppExporter.GenerateClassConstructor(transition.Opl, stream, indent, "opl");
            }

            if (transition.Opr2 != null)
            {
                RightValueCppExporter.GenerateClassConstructor(transition.Opr2, stream, indent, "opr2");
            }
        }
Example #24
0
        protected override void GenerateConstructor(Attachment attachment, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(attachment, stream, indent, className);

            PluginBehaviac.Events.Effector effector = attachment as PluginBehaviac.Events.Effector;
            if (effector == null)
                return;

            string phase = "Effector.EPhase.E_SUCCESS";
            switch (effector.Phase)
            {
                case EffectorPhase.Failure:
                    phase = "Effector.EPhase.E_FAILURE";
                    break;

                case EffectorPhase.Both:
                    phase = "Effector.EPhase.E_BOTH";
                    break;
            }
            stream.WriteLine("{0}\t\t\tthis.Phase = {1};", indent, phase);
        }
Example #25
0
        public static void ShowObject(ObjectPair obj)
        {
            BehaviorTreeList behaviorTreeList = BehaviorManager.Instance as BehaviorTreeList;

            if (behaviorTreeList == null)
            {
                return;
            }

            Nodes.Node             node   = null;
            Attachments.Attachment attach = null;

            if (obj.Obj is Nodes.Node)
            {
                node = (Nodes.Node)obj.Obj;
            }
            else if (obj.Obj is Attachments.Attachment)
            {
                attach = (Attachments.Attachment)obj.Obj;
                node   = attach.Node;
            }

            if (node != null)
            {
                behaviorTreeList.ShowNode(node, obj.Root);

                if (BehaviorTreeViewDock.LastFocused != null)
                {
                    BehaviorTreeView behaviorTreeView = BehaviorTreeViewDock.LastFocused.BehaviorTreeView;

                    if (behaviorTreeView != null)
                    {
                        behaviorTreeView.SelectedNodePending       = node;
                        behaviorTreeView.SelectedAttachmentPending = attach;

                        behaviorTreeView.Refresh();
                    }
                }
            }
        }
        protected override void GenerateMember(Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMember(attachment, stream, indent);

            AttachAction attach = attachment as AttachAction;
            if (attach == null)
                return;

            RightValueCsExporter.GenerateClassMember(attach.Opl, stream, indent, "opl");

            if (!attach.IsAction())
            {
                if (attach.IsCompute() && attach.Opr1 != null)
                {
                    RightValueCsExporter.GenerateClassMember(attach.Opr1, stream, indent, "opr1");
                }

                if (attach.Opr2 != null)
                {
                    RightValueCsExporter.GenerateClassMember(attach.Opr2, stream, indent, "opr2");
                }
            }
        }
Example #27
0
        public override void GenerateClass(Attachment attachment, StreamWriter stream, string indent, string nodeName, string btClassName)
        {
            if (ShouldGenerateClass())
            {
                string className = GetGeneratedClassName(attachment, btClassName, nodeName);

                stream.WriteLine("{0}\t[behaviac.GeneratedTypeMetaInfo()]", indent);
                stream.WriteLine("{0}\tclass {1} : behaviac.{2}\r\n{0}\t{{", indent, className, attachment.ExportClass);

                stream.WriteLine("{0}\t\tpublic {1}()", indent, className);
                stream.WriteLine("{0}\t\t{{", indent);

                GenerateConstructor(attachment, stream, indent, className);

                stream.WriteLine("{0}\t\t}}", indent);

                GenerateMethod(attachment, stream, indent);

                GenerateMember(attachment, stream, indent);

                stream.WriteLine("{0}\t}}\r\n", indent);
            }
        }
        protected override void GenerateConstructor(Attachment attachment, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(attachment, stream, indent, className);

            PluginBehaviac.Events.Precondition precondition = attachment as PluginBehaviac.Events.Precondition;
            if (precondition == null)
                return;

            string phase = "Precondition.EPhase.E_ENTER";
            switch (precondition.Phase)
            {
                case PreconditionPhase.Update:
                    phase = "Precondition.EPhase.E_UPDATE";
                    break;

                case PreconditionPhase.Both:
                    phase = "Precondition.EPhase.E_BOTH";
                    break;
            }
            stream.WriteLine("{0}\t\t\tthis.Phase = {1};", indent, phase);

            string isAnd = (precondition.BinaryOperator == BinaryOperator.And) ? "true" : "false";
            stream.WriteLine("{0}\t\t\tthis.IsAnd = {1};", indent, isAnd);
        }
Example #29
0
 protected virtual void CloneProperties(Attachment newattach) {
     newattach._id = this._id;
     newattach._enable = this._enable;
     newattach._prefabAttachmentId = this._prefabAttachmentId;
     //newattach._node = this._node; // The node should be the new one.
     newattach._label = this._label;
     newattach._baselabel = this._baselabel;
     newattach._description = this._description;
 }
Example #30
0
 protected override void CloneProperties(Attachment newattach)
 {
     base.CloneProperties(newattach);
 }
Example #31
0
 /// <summary>
 /// Creates a new subitm which can render an attachment on the node.
 /// </summary>
 /// <param name="backgroundNormal">The background brush used when the subitem is not selected.</param>
 /// <param name="backgroundSelected">The background brush used when the subitem is selected. If it cannot be selected, use null.</param>
 /// <param name="labelFont">The font used to draw the label.</param>
 /// <param name="labelBrush">The brush used to draw the label.</param>
 protected SubItemAttachment(Attachments.Attachment attach, Brush backgroundNormal, Brush backgroundSelected, Font labelFont, Brush labelBrush) :
     base(backgroundNormal, backgroundSelected, labelFont, labelBrush, Alignment.Center, false)
 {
     _attachment = attach;
 }
Example #32
0
 protected override void CloneProperties(Attachment newattach)
 {
     base.CloneProperties(newattach);
 }
Example #33
0
        protected override void GenerateMethod(Behaviac.Design.Attachments.Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            TransitionCondition transition = attachment as TransitionCondition;

            if (transition == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent);

            {
                string typeName = Plugin.GetNativeTypeName(transition.Opl.ValueType);
                typeName = typeName.Replace("::", ".");

                RightValueCsExporter.GenerateCode(attachment, transition.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                RightValueCsExporter.GenerateCode(attachment, transition.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");

                if (transition.Opl != null && transition.Opl.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(transition.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                }

                if (transition.Opr2 != null && transition.Opr2.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(transition.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");
                }

                switch (transition.Operator)
                {
                case OperatorTypes.Equal:
                    stream.WriteLine("{0}\t\t\tbool op = (opl == opr2);", indent);
                    break;

                case OperatorTypes.NotEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl != opr2);", indent);
                    break;

                case OperatorTypes.Greater:
                    stream.WriteLine("{0}\t\t\tbool op = (opl > opr2);", indent);
                    break;

                case OperatorTypes.GreaterEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl >= opr2);", indent);
                    break;

                case OperatorTypes.Less:
                    stream.WriteLine("{0}\t\t\tbool op = (opl < opr2);", indent);
                    break;

                case OperatorTypes.LessEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl <= opr2);", indent);
                    break;

                default:
                    stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                    break;
                }
            }

            stream.WriteLine("{0}\t\t\tif (!op)", indent);
            stream.WriteLine("{0}\t\t\t\tresult = EBTStatus.BT_FAILURE;", indent);

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
        protected override void GenerateMethod(Behaviac.Design.Attachments.Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            TransitionCondition transition = attachment as TransitionCondition;

            if (transition == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tvirtual EBTStatus update_impl(Agent* pAgent, EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(childStatus);", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = BT_SUCCESS;", indent);

            {
                string typeName = Plugin.GetNativeTypeName(transition.Opl.ValueType);

                RightValueCppExporter.GenerateCode(attachment, transition.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                RightValueCppExporter.GenerateCode(attachment, transition.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");

                if (transition.Opl != null && transition.Opl.IsMethod)
                {
                    RightValueCppExporter.PostGenerateCode(transition.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                }

                if (transition.Opr2 != null && transition.Opr2.IsMethod)
                {
                    RightValueCppExporter.PostGenerateCode(transition.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");
                }

                switch (transition.Operator)
                {
                case OperatorTypes.Equal:
                    stream.WriteLine("{0}\t\t\tbool op = Details::Equal(opl, opr2);", indent);
                    break;

                case OperatorTypes.NotEqual:
                    stream.WriteLine("{0}\t\t\tbool op = !Details::Equal(opl, opr2);", indent);
                    break;

                case OperatorTypes.Greater:
                    stream.WriteLine("{0}\t\t\tbool op = Details::Greater(opl, opr2);", indent);
                    break;

                case OperatorTypes.GreaterEqual:
                    stream.WriteLine("{0}\t\t\tbool op = Details::GreaterEqual(opl, opr2);", indent);
                    break;

                case OperatorTypes.Less:
                    stream.WriteLine("{0}\t\t\tbool op = Details::Less(opl, opr2);", indent);
                    break;

                case OperatorTypes.LessEqual:
                    stream.WriteLine("{0}\t\t\tbool op = Details::LessEqual(opl, opr2);", indent);
                    break;

                default:
                    stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                    break;
                }
            }

            stream.WriteLine("{0}\t\t\tif (!op)", indent);
            stream.WriteLine("{0}\t\t\t\tresult = BT_FAILURE;", indent);

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
 protected virtual void GenerateMethod(Attachment attachment, StreamWriter stream, string indent)
 {
     stream.WriteLine("{0}\tprotected:", indent);
 }
        protected override void GenerateMethod(Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            AttachAction attach = attachment as AttachAction;
            if (attach == null)
                return;

            stream.WriteLine("{0}\t\tvirtual EBTStatus update_impl(Agent* pAgent, EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = BT_SUCCESS;", indent);

            if (attach.IsAction())
            {
                string method = MethodCppExporter.GenerateCode(attach.Opl.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl");

                stream.WriteLine("{0}\t\t\t{1};", indent, method);
                MethodCppExporter.PostGenerateCode(attach.Opl.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl");
            }
            else if (attach.IsAssign())
            {
                if (attach.Opl != null && !attach.Opl.IsMethod && attach.Opl.Var != null && attach.Opr2 != null)
                {
                    PropertyDef prop = attach.Opl.Var.Property;
                    if (prop != null)
                    {
                        RightValueCppExporter.GenerateCode(attach.Opr2, stream, indent + "\t\t\t", attach.Opr2.NativeType, "opr2", "opr2");

                        string property = PropertyCppExporter.GetProperty(prop, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "attach");
                        string propName = prop.BasicName.Replace("[]", "");

                        if (prop.IsArrayElement && attach.Opl.Var.ArrayIndexElement != null)
                        {
                            ParameterCppExporter.GenerateCode(attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "attach_opl");
                            property = string.Format("({0})[opl_index]", property);
                        }

                        string propBasicName = prop.BasicName.Replace("[]", "");
                        if (!prop.IsArrayElement && (prop.IsPar || prop.IsCustomized))
                        {
                            uint id = Behaviac.Design.CRC32.CalcCRC(propBasicName);

                            stream.WriteLine("{0}\t\t\tBEHAVIAC_ASSERT(behaviac::MakeVariableId(\"{1}\") == {2}u);", indent, propBasicName, id);
                            stream.WriteLine("{0}\t\t\tpAgent->SetVariable(\"{1}\", opr2, {2}u);", indent, propBasicName, id);
                        }
                        else
                        {
                            stream.WriteLine("{0}\t\t\t{1} = opr2;", indent, property);
                        }

                        if (attach.Opr2.IsMethod)
                        {
                            RightValueCppExporter.PostGenerateCode(attach.Opr2, stream, indent + "\t\t\t", attach.Opr2.NativeType, "opr2", string.Empty);
                        }
                    }
                }
            }
            else if (attach.IsCompare())
            {
                string typeName = DataCppExporter.GetGeneratedNativeType(attach.Opl.ValueType);

                RightValueCppExporter.GenerateCode(attach.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                RightValueCppExporter.GenerateCode(attach.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");

                if (attach.Opl != null && attach.Opl.IsMethod)
                {
                    RightValueCppExporter.PostGenerateCode(attach.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                }

                if (attach.Opr2 != null && attach.Opr2.IsMethod)
                {
                    RightValueCppExporter.PostGenerateCode(attach.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");
                }

                switch (attach.Operator)
                {
                    case OperatorTypes.Equal:
                        stream.WriteLine("{0}\t\t\tbool op = Details::Equal(opl, opr2);", indent);
                        break;

                    case OperatorTypes.NotEqual:
                        stream.WriteLine("{0}\t\t\tbool op = !Details::Equal(opl, opr2);", indent);
                        break;

                    case OperatorTypes.Greater:
                        stream.WriteLine("{0}\t\t\tbool op = Details::Greater(opl, opr2);", indent);
                        break;

                    case OperatorTypes.GreaterEqual:
                        stream.WriteLine("{0}\t\t\tbool op = Details::GreaterEqual(opl, opr2);", indent);
                        break;

                    case OperatorTypes.Less:
                        stream.WriteLine("{0}\t\t\tbool op = Details::Less(opl, opr2);", indent);
                        break;

                    case OperatorTypes.LessEqual:
                        stream.WriteLine("{0}\t\t\tbool op = Details::LessEqual(opl, opr2);", indent);
                        break;

                    default:
                        stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                        break;
                }

                stream.WriteLine("{0}\t\t\tif (!op)", indent);
                stream.WriteLine("{0}\t\t\t\tresult = BT_FAILURE;", indent);
            }
            else if (attach.IsCompute())
            {
                if (attach.Opl != null && !attach.Opl.IsMethod && attach.Opl.Var != null && attach.Opr1 != null && attach.Opr2 != null)
                {
                    PropertyDef prop = attach.Opl.Var.Property;
                    if (prop != null)
                    {
                        string typeName = DataCppExporter.GetGeneratedNativeType(attach.Opr1.ValueType);

                        RightValueCppExporter.GenerateCode(attach.Opr1, stream, indent + "\t\t\t", typeName, "opr1", "opr1");
                        RightValueCppExporter.GenerateCode(attach.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "opr2");

                        string oprStr = string.Empty;
                        switch (attach.Operator)
                        {
                            case OperatorTypes.Add:
                                oprStr = "opr1 + opr2";
                                break;

                            case OperatorTypes.Sub:
                                oprStr = "opr1 - opr2";
                                break;

                            case OperatorTypes.Mul:
                                oprStr = "opr1 * opr2";
                                break;

                            case OperatorTypes.Div:
                                oprStr = "opr1 / opr2";
                                break;

                            default:
                                Debug.Check(false, "The operator is wrong!");
                                break;
                        }

                        oprStr = string.Format("({0})({1})", typeName, oprStr);

                        string property = PropertyCppExporter.GetProperty(prop, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "attach");
                        string propName = prop.BasicName.Replace("[]", "");

                        if (prop.IsArrayElement && attach.Opl.Var.ArrayIndexElement != null)
                        {
                            ParameterCppExporter.GenerateCode(attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "attach_opl");
                            property = string.Format("({0})[opl_index]", property);
                        }

                        string propBasicName = prop.BasicName.Replace("[]", "");
                        if (!prop.IsArrayElement && (prop.IsPar || prop.IsCustomized))
                        {
                            uint id = Behaviac.Design.CRC32.CalcCRC(propBasicName);

                            stream.WriteLine("{0}\t\t\tBEHAVIAC_ASSERT(behaviac::MakeVariableId(\"{1}\") == {2}u);", indent, propBasicName, id);
                            stream.WriteLine("{0}\t\t\tpAgent->SetVariable(\"{1}\", {2}, {3}u);", indent, propBasicName, oprStr, id);
                        }
                        else
                        {
                            stream.WriteLine("{0}\t\t\t{1} = {2};", indent, property, oprStr);
                        }

                        if (attach.Opr1.IsMethod)
                        {
                            RightValueCppExporter.PostGenerateCode(attach.Opr1, stream, indent + "\t\t\t", typeName, "opr1", string.Empty);
                        }

                        if (attach.Opr2.IsMethod)
                        {
                            RightValueCppExporter.PostGenerateCode(attach.Opr2, stream, indent + "\t\t\t", typeName, "opr2", string.Empty);
                        }
                    }
                }
            }

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Example #37
0
 protected virtual void GenerateConstructor(Attachment attachment, StreamWriter stream, string indent, string className)
 {
 }
Example #38
0
        //if there is a 'Predicate' attachment, convert it to a Condition node and attach it to the '_custom_condition' connector.
        private void AutoRestruct(List <Node.ErrorCheck> result, int version, Behaviac.Design.Attachments.Attachment a, Node node)
        {
            if (version <= 1)
            {
                string attachClass = a.GetType().FullName;
                if (attachClass.IndexOf("PluginBehaviac.Events.Predicate") >= 0)
                {
                    DesignerPropertyInfo propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Opl");
                    RightValueDef        opl      = propInfo.GetValue(a) as RightValueDef;
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Opr");
                    RightValueDef opr = propInfo.GetValue(a) as RightValueDef;
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Operator");
                    OperatorType  oprr    = (OperatorType)propInfo.GetValue(a);
                    OperatorTypes oprType = (OperatorTypes)((int)OperatorTypes.Equal - (int)OperatorType.Equal + (int)oprr);
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "BinaryOperator");
                    Behaviac.Design.Attachments.BinaryOperator binaryOpr = (Behaviac.Design.Attachments.BinaryOperator)propInfo.GetValue(a);

                    string clss      = node.GetType().FullName;
                    bool   bIsSeqSel = (node.GetType().IsSubclassOf(typeof(Sequence)) ||
                                        node.GetType().IsSubclassOf(typeof(Selector)));

                    bool bCare = (bIsSeqSel ||
                                  node.GetType().IsSubclassOf(typeof(Impulse))
                                  );

                    if (bCare ||
                        clss == "PluginBehaviac.Nodes.Query" ||
                        clss == "PluginBehaviac.Nodes.DecoratorCountLimit")
                    {
                        node.RemoveAttachment(a);
                        node.Behavior.TriggerWasModified(node);

                        Type newType = Plugin.GetType("PluginBehaviac.Nodes.Condition");

                        Behaviac.Design.Nodes.Node           newNode   = Behaviac.Design.Nodes.Node.Create(newType);
                        Behaviac.Design.Nodes.Node.Connector connector = node.GetConnector(Node.Connector.kInterupt);

                        if (connector != null && connector.Identifier == Node.Connector.kInterupt && connector.ChildCount > 0)
                        {
                            //it has multiple Predicates, so insert all of them to a newly created Sequence
                            Node oldOne = (Node)connector.GetChild(0);
                            if (oldOne.GetType().IsSubclassOf(typeof(Condition)))
                            {
                                AddAfterConditions(node, binaryOpr, newNode, connector, oldOne);
                            }
                            else
                            {
                                if (bIsSeqSel)
                                {
                                    Debug.Check(oldOne.GetType().IsSubclassOf(typeof(Decorator)));
                                    Decorator d = oldOne as Decorator;
                                    node      = oldOne;
                                    connector = node.GetConnector(BaseNode.Connector.kGeneric);
                                    oldOne    = (Node)d.Children[0];
                                }

                                if (oldOne.GetType() == typeof(PluginBehaviac.Nodes.And))
                                {
                                    if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.Or)
                                    {
                                        node.RemoveChild(connector, oldOne);
                                        Type selType1 = Plugin.GetType("PluginBehaviac.Nodes.Or");

                                        Behaviac.Design.Nodes.Node sel = Behaviac.Design.Nodes.Node.Create(selType1);
                                        sel.AddChild(BaseNode.Connector.kGeneric, oldOne);
                                        sel.AddChild(BaseNode.Connector.kGeneric, newNode);

                                        node.AddChild(BaseNode.Connector.kInterupt, sel);
                                    }
                                    else
                                    {
                                        oldOne.AddChild(BaseNode.Connector.kGeneric, newNode);
                                    }
                                }
                                else if (oldOne.GetType() == typeof(PluginBehaviac.Nodes.Or))
                                {
                                    if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.And)
                                    {
                                        node.RemoveChild(connector, oldOne);
                                        Type selType1 = Plugin.GetType("PluginBehaviac.Nodes.And");

                                        Behaviac.Design.Nodes.Node sel = Behaviac.Design.Nodes.Node.Create(selType1);
                                        sel.AddChild(BaseNode.Connector.kGeneric, oldOne);
                                        sel.AddChild(BaseNode.Connector.kGeneric, newNode);

                                        node.AddChild(BaseNode.Connector.kInterupt, sel);
                                    }
                                    else
                                    {
                                        oldOne.AddChild(BaseNode.Connector.kGeneric, newNode);
                                    }
                                }
                                else if (oldOne.GetType().IsSubclassOf(typeof(Condition)))
                                {
                                    AddAfterConditions(node, binaryOpr, newNode, connector, oldOne);
                                }
                                else
                                {
                                    Debug.Check(false);
                                }
                            }
                        }
                        else
                        {
                            //the first condition
                            Behaviac.Design.Nodes.Node notNode = null;
                            if (bIsSeqSel)
                            {
                                //for sequence/selector, it is reverted
                                Type notType = Plugin.GetType("PluginBehaviac.Nodes.DecoratorNot");

                                notNode = Behaviac.Design.Nodes.Node.Create(notType);
                                node.AddChild(BaseNode.Connector.kInterupt, notNode);
                                notNode.AddChild(BaseNode.Connector.kGeneric, newNode);
                            }
                            else
                            {
                                node.AddChild(BaseNode.Connector.kInterupt, newNode);
                            }
                        }

                        // initialise the attachments properties
                        IList <DesignerPropertyInfo> lp = newNode.GetDesignerProperties();
                        for (int p = 0; p < lp.Count; ++p)
                        {
                            if (lp[p].Property.Name == "Opl")
                            {
                                lp[p].Property.SetValue(newNode, opl, null);
                            }
                            else if (lp[p].Property.Name == "Opr")
                            {
                                lp[p].Property.SetValue(newNode, opr, null);
                            }
                            else if (lp[p].Property.Name == "Operator")
                            {
                                lp[p].Property.SetValue(newNode, oprr, null);
                            }
                        }

                        // update attacheent with attributes
                        newNode.OnPropertyValueChanged(false);
                    }
                    else if (clss == "PluginBehaviac.Nodes.Action")
                    {
                        Type newType = Plugin.GetType("PluginBehaviac.Events.Precondition");

                        Behaviac.Design.Attachments.Attachment newNode = Behaviac.Design.Attachments.Attachment.Create(newType, node);
                        node.AddAttachment(newNode);
                        node.RemoveAttachment(a);
                        node.Behavior.TriggerWasModified(node);

                        // initialise the attachments properties
                        IList <DesignerPropertyInfo> lp = newNode.GetDesignerProperties();
                        for (int p = 0; p < lp.Count; ++p)
                        {
                            if (lp[p].Property.Name == "BinaryOperator")
                            {
                                lp[p].Property.SetValue(newNode, binaryOpr, null);
                            }
                            else if (lp[p].Property.Name == "Opl")
                            {
                                lp[p].Property.SetValue(newNode, opl, null);
                            }
                            else if (lp[p].Property.Name == "Opr2")
                            {
                                lp[p].Property.SetValue(newNode, opr, null);
                            }
                            else if (lp[p].Property.Name == "Operator")
                            {
                                lp[p].Property.SetValue(newNode, oprType, null);
                            }
                            else if (lp[p].Property.Name == "IsAlive")
                            {
                                lp[p].SetValueFromString(result, newNode, "true");
                            }
                        }

                        // update attacheent with attributes
                        newNode.OnPropertyValueChanged(false);
                    }
                    else
                    {
                        Debug.Check(false);
                    }
                }
            } // if (version <= 1)
        }
Example #39
0
 public virtual void GenerateInstance(Attachment attachment, StreamWriter stream, string indent, string nodeName, string agentType, string btClassName)
 {
 }
Example #40
0
 public virtual void GenerateClass(Attachment attachment, StreamWriter stream, string indent, string nodeName, string btClassName)
 {
 }
        protected override void GenerateMethod(Behaviac.Design.Attachments.Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            PluginBehaviac.Events.Predicate predicate = attachment as PluginBehaviac.Events.Predicate;
            Debug.Check(predicate != null);

            stream.WriteLine("{0}\t\tvirtual EBTStatus update_impl(Agent* pAgent, EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(childStatus);", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = BT_FAILURE;", indent);

            // BinaryOperator
            switch (predicate.BinaryOperator)
            {
            case BinaryOperator.And:
                stream.WriteLine("{0}\t\t\tthis->m_bAnd = true;", indent);
                break;

            case BinaryOperator.Or:
            default:
                stream.WriteLine("{0}\t\t\tthis->m_bAnd = false;", indent);
                break;
            }

            string typeName = Plugin.GetNativeTypeName(predicate.Opl.ValueType);

            // opl
            RightValueCppExporter.GenerateCode(predicate.Opl, stream, indent + "\t\t\t", typeName, "opl", string.Empty);

            // opr
            VariableCppExporter.GenerateCode(predicate.Opr, stream, indent + "\t\t\t", typeName, "opr", string.Empty);

            // Operator
            switch (predicate.Operator)
            {
            case OperatorType.Equal:
                stream.WriteLine("{0}\t\t\tbool op = Details::Equal(opl, opr);", indent);
                break;

            case OperatorType.NotEqual:
                stream.WriteLine("{0}\t\t\tbool op = !Details::Equal(opl, opr);", indent);
                break;

            case OperatorType.Greater:
                stream.WriteLine("{0}\t\t\tbool op = Details::Greater(opl, opr);", indent);
                break;

            case OperatorType.GreaterEqual:
                stream.WriteLine("{0}\t\t\tbool op = Details::GreaterEqual(opl, opr);", indent);
                break;

            case OperatorType.Less:
                stream.WriteLine("{0}\t\t\tbool op = Details::Less(opl, opr);", indent);
                break;

            case OperatorType.LessEqual:
                stream.WriteLine("{0}\t\t\tbool op = Details::LessEqual(opl, opr);", indent);
                break;

            case OperatorType.And:
                stream.WriteLine("{0}\t\t\tbool op = opl && opr;", indent);
                break;

            case OperatorType.Or:
                stream.WriteLine("{0}\t\t\tbool op = opl || opr;", indent);
                break;

            default:
                stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                break;
            }
            stream.WriteLine("{0}\t\t\tif (op)", indent);
            stream.WriteLine("{0}\t\t\t\tresult = BT_SUCCESS;", indent);

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Example #42
0
        /// <summary>
        /// Handles the drawing and updating of the graph.
        /// </summary>
        protected override void OnPaint(PaintEventArgs e) {
            base.OnPaint(e);

            // calculate the mouse position in the graph
            PointF graphMousePos = _nodeLayoutManager.ViewToGraph(_lastMousePosition);

            // when the layout was changed it needs to be recalculated
            bool layoutChanged = _nodeLayoutManager.LayoutChanged;

            if (layoutChanged) {
                _nodeLayoutManager.UpdateLayout(e.Graphics, _forceChangeLayout);
                _forceChangeLayout = false;
            }

            // center the root behaviour if requested
            if (_pendingCenterBehavior) {
                _pendingCenterBehavior = false;
                CenterNode(_rootNodeView);
            }

            // select the pending node
            if (_selectedNodePending != null) {
                if (_selectedNodePendingParent != null) {
                    if (_selectedNodePendingParent.CanBeExpanded() && !_selectedNodePendingParent.IsExpanded) {
                        _selectedNodePendingParent.IsExpanded = true;
                        LayoutChanged();
                    }

                    SelectedNode = _selectedNodePendingParent.GetChild(_selectedNodePending);

                } else {
                    SelectedNode = RootNodeView.FindNodeViewData(_selectedNodePending);
                }

                if (SelectedNode != null) {
                    if (SelectedNode.CanBeExpanded() && !SelectedNode.IsExpanded) {
                        SelectedNode.IsExpanded = true;
                        LayoutChanged();
                    }

                    SelectedNode.SelectedSubItem = SelectedNode.GetSubItem(_selectedAttachmentPending);
                    ShowNode(SelectedNode);
                }

                _selectedNodePending = null;
                _selectedNodePendingParent = null;
                _selectedAttachmentPending = null;

                if (ClickEvent != null) {
                    ClickEvent(SelectedNode);
                }
            }

            // check if we must keep the original position of the mouse
            if (_maintainMousePosition) {
                _maintainMousePosition = false;

                // move the graph so that _graphOrigin is at the same position in the view as it was before
                float mouseX = (graphMousePos.X - _graphOrigin.X) * _nodeLayoutManager.Scale + _nodeLayoutManager.Offset.X;
                float mouseY = (graphMousePos.Y - _graphOrigin.Y) * _nodeLayoutManager.Scale + _nodeLayoutManager.Offset.Y;

                _nodeLayoutManager.Offset = new PointF(mouseX, mouseY);
            }

            // check if we must keep the original position of _maintainNodePosition
            else if (_maintainNodePosition != null) {
                // move the graph so that _graphOrigin is at the same position in the view as it was before
                RectangleF bbox = _maintainNodePosition.IsFSM ? _maintainNodePosition.GetTotalBoundingBox() : _maintainNodePosition.BoundingBox;
                PointF viewpos = new PointF(bbox.X * _nodeLayoutManager.Scale, bbox.Y * _nodeLayoutManager.Scale);

                _nodeLayoutManager.Offset = new PointF(_graphOrigin.X - viewpos.X, _graphOrigin.Y - viewpos.Y);
            }

            // reset the node whose position we want to keep
            _maintainNodePosition = null;

            // draw the graph to the view
            _nodeLayoutManager.DrawGraph(e.Graphics, graphMousePos, _currentNode, SelectedNode, _highlightedNodeIds, _updatedNodeIds, _highlightedTransitionIds, _highlightBreakPoint, _profileInfos);

            // check if we are currently dragging a node and we must draw additional data
            if (_dragTargetNode != null && _dragAttachment == null && (KeyCtrlIsDown && _movedNode != null || _dragTargetNode.Node != _movedNode)) {
                if (_dragAttachMode == NodeAttachMode.Attachment) {
                    // we could draw some stuff for attachements here
                } else {
                    // draw the arrows for the attach modes

                    // get the bounding box of the node
                    RectangleF bbox = _dragTargetNode.BoundingBox;

                    // get the bounding box of the connector
                    _dragTargetConnector = null;

                    // the depth of the area for the mouse
                    const float offset = 12.0f;

                    // the distance of the arrow from the border and its height
                    const float innerOffset = 2.0f;

                    // the horizintal middle of the node
                    float centerX = bbox.Left + bbox.Width * 0.5f;
                    float centerY = bbox.Top + bbox.Height * 0.5f;
                    float centerBoxX = bbox.X + bbox.Width * 0.4f;
                    float centerBoxWidth = bbox.Width * 0.2f;

                    // the half width of the arrow depending of the node's height
                    float arrowHalfWidth = (bbox.Height - innerOffset - innerOffset) * 0.5f;

                    // calculate the mouse areas for the different attach modes
                    RectangleF top    = new RectangleF(centerBoxX, bbox.Top, centerBoxWidth, offset);
                    RectangleF bottom = new RectangleF(centerBoxX, bbox.Bottom - offset, centerBoxWidth, offset);
                    RectangleF center = new RectangleF(centerBoxX, centerY - offset * 0.5f, centerBoxWidth, offset);
                    RectangleF left   = new RectangleF(bbox.X, bbox.Y, offset, bbox.Height);

                    // update for dragging in a new node
                    BehaviorNode behavior = _dragNodeDefaults as BehaviorNode;

                    if (behavior != null && behavior.FileManager == null) {
                        behavior = null;
                    }

                    // the node that is currently dragged
                    Node draggedNode = (_movedNode != null) ? _movedNode : (_dragNodeDefaults as Node);

                    if (draggedNode == null) {
                        return;
                    }

                    Node.Connector parentConnector = _dragTargetNode.Node.ParentConnector;
                    bool canBeAdoptedByParent = parentConnector != null && (!parentConnector.IsAsChild || AdoptNodeByAncestor(_dragTargetNode.Node.Parent, draggedNode));
                    //bool targetCanBeAdoptedByParent = (_movedNode == null) || (_movedNode.ParentConnector != null) && _movedNode.ParentConnector.AcceptsChild(_dragTargetNode.Node);
                    bool hasParentBehavior = _dragTargetNode.HasParentBehavior(behavior);
                    bool parentHasParentBehavior = (_dragTargetNode.Parent == null);

                    bool isFSM = _rootNodeView.IsFSM || (_rootNodeView.Children.Count == 0);

                    bool mayTop = !isFSM && canBeAdoptedByParent /*&& targetCanBeAdoptedByParent*/ && !parentHasParentBehavior &&
                                  parentConnector != null && parentConnector.AcceptsChild(draggedNode);

                    bool mayBottom = mayTop;

                    bool mayCenter = !parentHasParentBehavior && (_rootNodeView.IsFSM && draggedNode.IsFSM || canBeAdoptedByParent && 
                                     draggedNode.GetType() != _dragTargetNode.Node.GetType() &&
                                     parentConnector != null && !parentConnector.IsReadOnly && parentConnector.AcceptsChild(draggedNode, true) &&
                                     draggedNode.CanAdoptChildren(_dragTargetNode.Node));

                    bool mayLeft = !isFSM && (_dragTargetNode.Node.Parent != _movedNode) &&
                                   canBeAdoptedByParent && !parentHasParentBehavior && !hasParentBehavior &&
                                   parentConnector != null && !parentConnector.IsReadOnly && parentConnector.AcceptsChild(draggedNode, true) &&
                                   !(draggedNode is BehaviorNode) && draggedNode.CanAdoptNode(_dragTargetNode.Node);

                    // update for moving an existing node
                    bool dragTargetHasParentMovedNode = false;

                    if (_movedNode != null) {
                        mayCenter = false;
                        dragTargetHasParentMovedNode = KeyShiftIsDown && _dragTargetNode.Node.HasParent(_movedNode);

                        // a node may not dragged on itself and may not dragged on one of its own children
                        if (_dragTargetNode.Node == _movedNode || dragTargetHasParentMovedNode) {
                            //mayTop = KeyCtrlIsDown;
                            mayTop &= KeyCtrlIsDown && (_dragTargetNode.Node.ParentConnector != null) && _dragTargetNode.Node.ParentConnector.AcceptsChild(_movedNode);
                            mayBottom = mayTop;
                            mayLeft = false;

                        } else {
                            // a dragged node cannot be placed in the same position again
                            mayTop &= (KeyCtrlIsDown || _dragTargetNode.Node.PreviousNode != _movedNode);
                            mayBottom &= (KeyCtrlIsDown || _dragTargetNode.Node.NextNode != _movedNode);
                            mayLeft &= _movedNode.CanAdoptChildren(_dragTargetNode.Node) && (!KeyShiftIsDown || _movedNode.Children.Count == 0);
                        }
                    }

                    if (_copiedNode != null) {
                        mayCenter = false;
                        mayLeft &= _copiedNode.CanAdoptChildren(_dragTargetNode.Node) && (!KeyShiftIsDown || _copiedNode.Children.Count == 0);
                        mayTop &= (_dragTargetNode.Node.ParentConnector != null) && _dragTargetNode.Node.ParentConnector.AcceptsChild(_copiedNode);
                        mayBottom = mayTop;

                    } else if (_clipboardPasteMode) {
                        mayCenter = false;
                        mayLeft &= !KeyShiftIsDown;
                    }

                    // reset the attach mode
                    _dragAttachMode = NodeAttachMode.None;

                    // the vertices needed to draw the arrows
                    PointF[] vertices = new PointF[3];

                    // draw the top arrow if this action is allowed
                    if (mayTop) {
                        vertices[0] = new PointF(centerX - arrowHalfWidth, top.Bottom - innerOffset);
                        vertices[1] = new PointF(centerX, top.Top + innerOffset);
                        vertices[2] = new PointF(centerX + arrowHalfWidth, top.Bottom - innerOffset);

                        if (top.Contains(graphMousePos)) {
                            _dragAttachMode = NodeAttachMode.Top;
                            e.Graphics.FillPolygon(Brushes.White, vertices);

                        } else {
                            e.Graphics.FillPolygon(Brushes.Black, vertices);
                        }
                    }

                    // draw the bottom arrow if this action is allowed
                    if (mayBottom) {
                        vertices[0] = new PointF(centerX - arrowHalfWidth, bottom.Top + innerOffset);
                        vertices[1] = new PointF(centerX + arrowHalfWidth, bottom.Top + innerOffset);
                        vertices[2] = new PointF(centerX, bottom.Bottom - innerOffset);

                        if (_dragAttachMode == NodeAttachMode.None && bottom.Contains(graphMousePos)) {
                            _dragAttachMode = NodeAttachMode.Bottom;
                            e.Graphics.FillPolygon(Brushes.White, vertices);

                        } else {
                            e.Graphics.FillPolygon(Brushes.Black, vertices);
                        }
                    }

                    // draw the center rectangle if this action is allowed
                    if (mayCenter) {
                        if (center.Contains(graphMousePos)) {
                            _dragAttachMode = NodeAttachMode.Center;
                            e.Graphics.FillRectangle(Brushes.White, centerX - arrowHalfWidth * 0.5f, centerY - innerOffset * 2.0f, arrowHalfWidth, innerOffset * 4.0f);

                        } else {
                            e.Graphics.FillRectangle(Brushes.Black, centerX - arrowHalfWidth * 0.5f, centerY - innerOffset * 2.0f, arrowHalfWidth, innerOffset * 4.0f);
                        }
                    }

                    // draw the left arrow if this action is allowed
                    if (mayLeft) {
                        vertices[0] = new PointF(left.Right - innerOffset, left.Top + innerOffset);
                        vertices[1] = new PointF(left.Right - innerOffset, left.Bottom - innerOffset);
                        vertices[2] = new PointF(left.Left + innerOffset, left.Top + left.Height * 0.5f);

                        if (_dragAttachMode == NodeAttachMode.None && left.Contains(graphMousePos)) {
                            _dragAttachMode = NodeAttachMode.Left;
                            e.Graphics.FillPolygon(Brushes.White, vertices);

                        } else {
                            e.Graphics.FillPolygon(Brushes.Black, vertices);
                        }
                    }

                    // draw the right arrow if this action is allowed
                    foreach(Node.Connector connector in _dragTargetNode.Connectors) {
                        RectangleF bboxConnector = _dragTargetNode.GetConnectorBoundingBox(bbox, connector);
                        RectangleF right = new RectangleF(bboxConnector.Right - offset, bboxConnector.Y, offset, bboxConnector.Height);

                        bool mayRight = !_rootNodeView.IsFSM && !dragTargetHasParentMovedNode &&
                                        !hasParentBehavior &&
                                        !connector.IsReadOnly &&
                                        connector.AcceptsChild(draggedNode) &&
                                        (!connector.IsAsChild || AdoptNodeByAncestor(_dragTargetNode.Node, draggedNode));

                        if (mayRight && draggedNode != null && connector == draggedNode.ParentConnector) {
                            mayRight = false;
                        }

                        if (mayRight) {
                            float inOffset = bboxConnector.Height > innerOffset * 4.0f ? innerOffset : 3.0f;

                            vertices[0] = new PointF(right.Left + inOffset, right.Top + inOffset);
                            vertices[1] = new PointF(right.Right - inOffset, right.Top + right.Height * 0.5f);
                            vertices[2] = new PointF(right.Left + inOffset, right.Bottom - inOffset);

                            if (_dragAttachMode == NodeAttachMode.None && right.Contains(graphMousePos)) {
                                _dragTargetConnector = _dragTargetNode.Node.GetConnector(connector.Identifier);
                                _dragAttachMode = NodeAttachMode.Right;
                                e.Graphics.FillPolygon(Brushes.White, vertices);

                            } else {
                                e.Graphics.FillPolygon(Brushes.Black, vertices);
                            }
                        }
                    }
                }
            }

            // draw last mouse pos
            //e.Graphics.DrawRectangle(Pens.Red, graphMousePos.X -1.0f, graphMousePos.Y -1.0f, 2.0f, 2.0f);

            //when we are dragging an existing node we draw a small graph representing it
            if (_movedNodeGraph != null) {
                // update the layout for the graph. This happens only once inside the function.
                _movedNodeGraph.UpdateLayout(e.Graphics);

                // offset the graph to the mouse position
                _movedNodeGraph.Offset = new PointF(_nodeLayoutManager.Offset.X + graphMousePos.X * _nodeLayoutManager.Scale,
                                                    _nodeLayoutManager.Offset.Y + graphMousePos.Y * _nodeLayoutManager.Scale - _movedNodeGraph.RootNodeLayout.LayoutRectangle.Height * 0.5f * _movedNodeGraph.Scale);

                // draw the graph
                _movedNodeGraph.DrawGraph(e.Graphics, graphMousePos);
            }

            // attachment
            if (_currentNode != null && _dragTargetNode != null &&
                _dragAttachment != null && _dragTargetAttachment != null && _dragAttachment != _dragTargetAttachment &&
                _dragTargetNode.Node.AcceptsAttachment(_dragAttachment.Attachment)) {
                _dragAttachMode = NodeAttachMode.None;

                Attachments.Attachment sourceAttach = _dragAttachment.SelectableObject as Attachments.Attachment;
                Attachments.Attachment targetAttach = _dragTargetAttachment.SelectableObject as Attachments.Attachment;

                if (sourceAttach != null && targetAttach != null &&
                    sourceAttach.IsPrecondition == targetAttach.IsPrecondition &&
                    sourceAttach.IsTransition == targetAttach.IsTransition &&
                    sourceAttach.IsEffector == targetAttach.IsEffector)
                {
                    SubItemRegin regin = _dragTargetNode.GetSubItemRegin(graphMousePos);
                    int itemIndex = _currentNode.GetSubItemIndex(_dragAttachment);
                    int targetItemIndex = _dragTargetNode.GetSubItemIndex(_dragTargetAttachment);

                    if (regin != SubItemRegin.Out && itemIndex >= 0 && targetItemIndex >= 0) {
                        RectangleF bbox = _dragTargetNode.GetSubItemBoundingBox(graphMousePos);

                        const float offset = 8.0f;
                        const float innerOffset = 2.0f;

                        float centerX = bbox.Left + bbox.Width * 0.5f;
                        float centerY = bbox.Top + bbox.Height * 0.5f;
                        float centerBoxX = bbox.X + bbox.Width * 0.4f;
                        float arrowHalfWidth = bbox.Width * 0.12f;

                        RectangleF top = new RectangleF(centerX - arrowHalfWidth, bbox.Top, arrowHalfWidth * 2.0f, offset);
                        RectangleF bottom = new RectangleF(centerX - arrowHalfWidth, bbox.Bottom - offset, arrowHalfWidth * 2.0f, offset);

                        PointF[] vertices = new PointF[3];

                        switch (regin) {
                            case SubItemRegin.Top:
                                if (KeyCtrlIsDown || _currentNode != _dragTargetNode || itemIndex != targetItemIndex - 1) {
                                    vertices[0] = new PointF(centerX - arrowHalfWidth, top.Bottom - innerOffset);
                                    vertices[1] = new PointF(centerX, top.Top + innerOffset);
                                    vertices[2] = new PointF(centerX + arrowHalfWidth, top.Bottom - innerOffset);

                                    if (top.Contains(graphMousePos)) {
                                        _dragAttachMode = NodeAttachMode.Top;
                                        e.Graphics.FillPolygon(Brushes.White, vertices);

                                    } else {
                                        e.Graphics.FillPolygon(Brushes.Black, vertices);
                                    }
                                }

                                break;

                            case SubItemRegin.Bottom:
                                if (KeyCtrlIsDown || _currentNode != _dragTargetNode || itemIndex != targetItemIndex + 1) {
                                    vertices[0] = new PointF(centerX - arrowHalfWidth, bottom.Top + innerOffset);
                                    vertices[1] = new PointF(centerX + arrowHalfWidth, bottom.Top + innerOffset);
                                    vertices[2] = new PointF(centerX, bottom.Bottom - innerOffset);

                                    if (bottom.Contains(graphMousePos)) {
                                        _dragAttachMode = NodeAttachMode.Bottom;
                                        e.Graphics.FillPolygon(Brushes.White, vertices);

                                    } else {
                                        e.Graphics.FillPolygon(Brushes.Black, vertices);
                                    }
                                }

                                break;
                        }
                    }
                }
            }

            if (_movedSubItem != null) {
                NodeViewData.SubItemText subitem = _movedSubItem as NodeViewData.SubItemText;

                if (subitem != null) {
                    RectangleF boundingBox = new RectangleF(graphMousePos, new SizeF(50, 12));
                    e.Graphics.FillRectangle(subitem.BackgroundBrush, boundingBox);
                }
            }

            // draw FSM related
            DrawFSMArrow(e, graphMousePos);
            DrawFSMDragCurve(e, graphMousePos);

            //the first time of paint, to collapse plan failed branch by default
            Behavior b = this.RootNode as Behavior;

            if (b.PlanIsCollapseFailedBranch > 0) {
                if (b.PlanIsCollapseFailedBranch == Behavior.kPlanIsCollapseFailedBranch) {
                    NodeViewData root = (NodeViewData)this.RootNodeView.Children[0];
                    CollapseFailedBrach(root);
                }

                b.PlanIsCollapseFailedBranch--;

                this.CenterNode(this._rootNodeView);
                this.LayoutChanged();
            }
        }
Example #43
0
        protected override void GenerateMethod(Behaviac.Design.Attachments.Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            AttachAction attach = attachment as AttachAction;

            if (attach == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent);

            if (attach.IsAction())
            {
                string method = MethodCsExporter.GenerateCode(attachment, attach.Opl.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl");

                stream.WriteLine("{0}\t\t\t{1};", indent, method);
                MethodCsExporter.PostGenerateCode(attach.Opl.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl");
            }
            else if (attach.IsAssign())
            {
                if (attach.Opl != null && !attach.Opl.IsMethod && attach.Opl.Var != null && attach.Opr2 != null)
                {
                    PropertyDef prop = attach.Opl.Var.Property;
                    if (prop != null)
                    {
                        RightValueCsExporter.GenerateCode(attachment, attach.Opr2, stream, indent + "\t\t\t", attach.Opr2.NativeType.Replace("::", "."), "opr2", "opr2");

                        string property = PropertyCsExporter.GetProperty(attachment, prop, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "attach");
                        string propName = prop.BasicName.Replace("[]", "");

                        if (prop.IsArrayElement && attach.Opl.Var.ArrayIndexElement != null)
                        {
                            ParameterCsExporter.GenerateCode(attachment, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "attach_opl");
                            property = string.Format("({0})[opl_index]", property);
                        }

                        string propBasicName = prop.BasicName.Replace("[]", "");

                        if (!prop.IsArrayElement && (prop.IsPar || prop.IsCustomized))
                        {
                            uint   id           = Behaviac.Design.CRC32.CalcCRC(propBasicName);
                            string oplAgentName = PropertyCsExporter.GetGenerateAgentName(prop, "opl", "attach");

                            stream.WriteLine("{0}\t\t\t{1}.SetVariable(\"{2}\", {3}u, opr2);", indent, oplAgentName, propBasicName, id);
                        }
                        else
                        {
                            if (prop.IsPublic)
                            {
                                stream.WriteLine("{0}\t\t\t{1} = opr2;", indent, property);
                            }
                            else
                            {
                                string agentName = PropertyCsExporter.GetGenerateAgentName(prop, "opr2", "opr2");
                                stream.WriteLine("{0}\t\t\tAgentExtra_Generated.SetProperty({1}, \"{2}\", opr2);", indent, agentName, propBasicName);
                            }
                        }

                        if (attach.Opr2.IsMethod)
                        {
                            RightValueCsExporter.PostGenerateCode(attach.Opr2, stream, indent + "\t\t\t", attach.Opr2.NativeType.Replace("::", "."), "opr2", string.Empty);
                        }
                    }
                }
            }
            else if (attach.IsCompare())
            {
                ConditionCsExporter.GenerateOperand(attachment, stream, indent + "\t\t\t", attach.Opl, "opl", "");
                ConditionCsExporter.GenerateOperand(attachment, stream, indent + "\t\t\t", attach.Opr2, "opr2", "");

                switch (attach.Operator)
                {
                case OperatorTypes.Equal:
                    stream.WriteLine("{0}\t\t\tbool op = (opl == opr2);", indent);
                    break;

                case OperatorTypes.NotEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl != opr2);", indent);
                    break;

                case OperatorTypes.Greater:
                    stream.WriteLine("{0}\t\t\tbool op = (opl > opr2);", indent);
                    break;

                case OperatorTypes.GreaterEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl >= opr2);", indent);
                    break;

                case OperatorTypes.Less:
                    stream.WriteLine("{0}\t\t\tbool op = (opl < opr2);", indent);
                    break;

                case OperatorTypes.LessEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl <= opr2);", indent);
                    break;

                default:
                    stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                    break;
                }
                stream.WriteLine("{0}\t\t\tif (!op)", indent);
                stream.WriteLine("{0}\t\t\t\tresult = EBTStatus.BT_FAILURE;", indent);
            }
            else if (attach.IsCompute())
            {
                if (attach.Opl != null && !attach.Opl.IsMethod && attach.Opl.Var != null && attach.Opr1 != null && attach.Opr2 != null)
                {
                    PropertyDef prop = attach.Opl.Var.Property;
                    if (prop != null)
                    {
                        string typeName = Plugin.GetNativeTypeName(attach.Opr1.ValueType);
                        typeName = typeName.Replace("::", ".");

                        RightValueCsExporter.GenerateCode(attachment, attach.Opr1, stream, indent + "\t\t\t", typeName, "opr1", "opr1");
                        RightValueCsExporter.GenerateCode(attachment, attach.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "opr2");

                        string oprStr = string.Empty;
                        switch (attach.Operator)
                        {
                        case OperatorTypes.Add:
                            oprStr = "opr1 + opr2";
                            break;

                        case OperatorTypes.Sub:
                            oprStr = "opr1 - opr2";
                            break;

                        case OperatorTypes.Mul:
                            oprStr = "opr1 * opr2";
                            break;

                        case OperatorTypes.Div:
                            oprStr = "opr1 / opr2";
                            break;

                        default:
                            Debug.Check(false, "The operator is wrong!");
                            break;
                        }

                        oprStr = string.Format("({0})({1})", typeName, oprStr);

                        string property = PropertyCsExporter.GetProperty(attachment, prop, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "attach");
                        string propName = prop.BasicName.Replace("[]", "");

                        if (prop.IsArrayElement && attach.Opl.Var.ArrayIndexElement != null)
                        {
                            ParameterCsExporter.GenerateCode(attachment, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "attach_opl");
                            property = string.Format("({0})[opl_index]", property);
                        }

                        string propBasicName = prop.BasicName.Replace("[]", "");
                        string agentName     = PropertyCsExporter.GetGenerateAgentName(prop, "opl", "attach");

                        if (!prop.IsArrayElement && (prop.IsPar || prop.IsCustomized))
                        {
                            uint id = Behaviac.Design.CRC32.CalcCRC(propBasicName);

                            stream.WriteLine("{0}\t\t\t{1}.SetVariable(\"{2}\", {3}u, {4});", indent, agentName, propBasicName, id, oprStr);
                        }
                        else if (prop.IsPublic)
                        {
                            stream.WriteLine("{0}\t\t\t{1} = {2};", indent, property, oprStr);
                        }
                        else
                        {
                            stream.WriteLine("{0}\t\t\tAgentExtra_Generated.SetProperty({1}, \"{2}\", {3});", indent, agentName, propBasicName, oprStr);
                        }

                        if (attach.Opr1.IsMethod)
                        {
                            RightValueCsExporter.PostGenerateCode(attach.Opr1, stream, indent + "\t\t\t", typeName, "opr1", string.Empty);
                        }

                        if (attach.Opr2.IsMethod)
                        {
                            RightValueCsExporter.PostGenerateCode(attach.Opr2, stream, indent + "\t\t\t", typeName, "opr2", string.Empty);
                        }
                    }
                }
            }

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Example #44
0
 protected virtual void GenerateMethod(Attachment attachment, StreamWriter stream, string indent)
 {
 }
 /// <summary>
 /// Creates a new subitm which can render an attachment on the node.
 /// </summary>
 /// <param name="backgroundNormal">The background brush used when the subitem is not selected.</param>
 /// <param name="backgroundSelected">The background brush used when the subitem is selected. If it cannot be selected, use null.</param>
 /// <param name="labelFont">The font used to draw the label.</param>
 /// <param name="labelBrush">The brush used to draw the label.</param>
 protected SubItemAttachment(Attachments.Attachment attach, Brush backgroundNormal, Brush backgroundSelected, Font labelFont, Brush labelBrush) :
     base(backgroundNormal, backgroundSelected, labelFont, labelBrush, Alignment.Center, false) {
     _attachment = attach;
 }