public static bool Save(string filename, string currentWorkspace) { try { Stream stream = File.Open(filename, FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); // Save the workspace. formatter.Serialize(stream, currentWorkspace); // Save all agent instances. AgentInstancePool.Serialize(stream, formatter); // Save all parameters. Serialize(stream, formatter); formatter.Serialize(stream, TotalFrames); // Save all frame states. FrameStatePool.Serialize(stream, formatter); // Save all messages. MessageQueue.Serialize(stream, formatter); stream.Close(); return(true); } catch (Exception) { return(false); } }
internal static void Inspect(AgentType agentType, string agentName, string agentFullName, FrameStatePool.PlanningState nodeState) { ParametersDock dock = findParametersDock(agentType, agentName); if (dock == null) { dock = new ParametersDock(); dock.Show(MainWindow.Instance.DockPanel, WeifenLuo.WinFormsUI.Docking.DockState.DockBottom); } dock.InspectObject(agentType, agentName, agentFullName, nodeState); }
internal static void Inspect(string agentFullName, FrameStatePool.PlanningState nodeState) { Debug.Check(!string.IsNullOrEmpty(agentFullName)); string[] tokens = agentFullName.Split('#'); string agentName = tokens[tokens.Length - 1]; Debug.Check(tokens.Length == 2); // Agent if (tokens.Length > 1) { AgentType agentType = Plugin.GetAgentType(tokens[0]); Inspect(agentType, agentName, agentFullName, nodeState); } // Global else { Inspect(Plugin.GetInstanceAgentType(agentFullName, null, null), agentName, agentFullName, nodeState); } }
public static bool LoadDump(string filename, string currentWorkspace) { try { Stream stream = File.Open(filename, FileMode.Open); BinaryFormatter formatter = new BinaryFormatter(); // Load the workspace. currentWorkspace = formatter.Deserialize(stream) as string; if (Plugin.WorkspaceDelegateHandler != null) { Plugin.WorkspaceDelegateHandler(currentWorkspace, false); } // Load all agent instances. AgentInstancePool.Deserialize(stream, formatter); // Load all parameters. Deserialize(stream, formatter); TotalFrames = (int)formatter.Deserialize(stream); CurrentFrame = 0; // Load all frame states. FrameStatePool.Deserialize(stream, formatter); // Load all messages. MessageQueue.Deserialize(stream, formatter); stream.Close(); return(true); } catch (Exception ex) { string msgError = string.Format(Resources.LoadDebugDataError, filename, ex.Message); MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK); } return(false); }
private static object GetPropertyValue(FrameStatePool.PlanningState nodeState, string agentFullName, string propertyName) { FrameStatePool.PlanningState ns = nodeState; bool bOk = ns._agents.ContainsKey(agentFullName) && ns._agents[agentFullName].ContainsKey(propertyName); //if the current node has no value, to look for it in the parent's object v = null; while (!bOk) { ns = ns._parent; if (ns == null) { break; } bOk = ns._agents.ContainsKey(agentFullName) && ns._agents[agentFullName].ContainsKey(propertyName); } if (bOk) { Debug.Check(ns._agents[agentFullName].ContainsKey(propertyName)); v = ns._agents[agentFullName][propertyName]; } return v; }
public void SetProperty(FrameStatePool.PlanningState nodeState, string agentFullName) { Debug.Check(nodeState != null); //iterate all the properties for (int i = 0; i < _rowControls.Count; ++i) { RowControl rc = _rowControls[i]; object v = GetPropertyValue(nodeState, agentFullName, rc.Name); if (v != null) { SetProperty(rc.Name, v.ToString()); } } }
private void setProperty(FrameStatePool.PlanningState nodeState, string agentFullName) { parametersPanel.SetProperty(nodeState, agentFullName); }
private void InspectObject(AgentType agentType, string agentName, string agentFullName, FrameStatePool.PlanningState nodeState) { Nodes.Node node = null; if (agentType == null && !string.IsNullOrEmpty(agentFullName)) { int frame = AgentDataPool.CurrentFrame > -1 ? AgentDataPool.CurrentFrame : 0; string behaviorFilename = FrameStatePool.GetBehaviorFilename(agentFullName, frame); List<string> transitionIds = FrameStatePool.GetHighlightTransitionIds(agentFullName, frame, behaviorFilename); List<string> highlightNodeIds = FrameStatePool.GetHighlightNodeIds(agentFullName, frame, behaviorFilename); List<string> updatedNodeIds = FrameStatePool.GetUpdatedNodeIds(agentFullName, frame, behaviorFilename); Dictionary<string, FrameStatePool.NodeProfileInfos.ProfileInfo> profileInfos = FrameStatePool.GetProfileInfos(frame, behaviorFilename); BehaviorNode behavior = UIUtilities.ShowBehaviorTree(agentFullName, frame, transitionIds, highlightNodeIds, updatedNodeIds, HighlightBreakPoint.Instance, profileInfos); node = behavior as Nodes.Node; } _agentType = agentType; _agentName = agentName; Hide(); setText(agentType, agentName); if (nodeState != null) { foreach(string agentFullName1 in nodeState._agents.Keys) { string[] tokens = agentFullName1.Split('#'); Debug.Check(tokens.Length == 2); string at = tokens[0]; string an = tokens[1]; AgentType agentType1 = Plugin.GetAgentType(at); ParametersDock dock = findParametersDock(agentType1, an); dock.InspectObject(agentType1, agentFullName1); dock.setProperty(nodeState, agentFullName1); } } else if (AgentDataPool.CurrentFrame > -1 && !string.IsNullOrEmpty(agentName)) { ParametersDock dock = findParametersDock(agentType, agentName); dock.InspectObject(agentType, agentFullName); List<AgentDataPool.ValueMark> valueSet = AgentDataPool.GetValidValues(agentType, agentFullName, AgentDataPool.CurrentFrame); foreach(AgentDataPool.ValueMark value in valueSet) { dock.setProperty(value.Name, value.Value); } } lostAnyFocus(); Show(); }
private static void showPlanning(FrameStatePool.PlanningProcess planning) { BehaviorTreeView view = UIUtilities.ShowPlanning(planning); view.ClickNode += new BehaviorTreeView.ClickNodeEventDelegate(Planning_ClikcNode); }
private void AgentInstancePool_AddPlanningHandler(string agentFullName, int frame, FrameStatePool.PlanningProcess planning) { string[] types = agentFullName.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); Debug.Check(types.Length == 2); string agentType = types[0]; string agentName = types[1]; TreeNode agentTreeNode = this.treeView.Nodes[agentType]; Debug.Check(agentTreeNode != null); TreeNode[] agentInstance = agentTreeNode.Nodes.Find(agentFullName, true); if (agentInstance != null) { string planningName = string.Format("PLanning_{0}_{1}", planning._frame, planning._index); TreeNode planningNode = agentInstance[0].Nodes.Insert(agentInstance[0].GetNodeCount(false), planningName); planningNode.Tag = planning; } }
public static BehaviorTreeView ShowPlanning(FrameStatePool.PlanningProcess planning) { string behaviorFilename = FileManagers.FileManager.GetFullPath(planning._behaviorTree); if (!File.Exists(behaviorFilename)) { return null; } string planningName = string.Format("PLanning_{0}_{1}", planning._frame, planning._index); Dictionary<string, BehaviorNode> list_plannings = null; if (!_agent_plannings.ContainsKey(planning._agentFullName)) { list_plannings = new Dictionary<string, BehaviorNode>(); _agent_plannings.Add(planning._agentFullName, list_plannings); } else { list_plannings = _agent_plannings[planning._agentFullName]; } BehaviorNode behavior = null; if (!list_plannings.ContainsKey(planningName)) { Plugin.PlanningProcess = planning; behavior = BehaviorManager.Instance.LoadBehavior(behaviorFilename, true); Behavior b = behavior as Behavior; b.PlanningProcess = planning; Plugin.PlanningProcess = null; b.PlanIsCollapseFailedBranch = Behavior.kPlanIsCollapseFailedBranch; list_plannings.Add(planningName, behavior); behavior.Filename = planningName; ((Node)behavior).Label = planningName; } else { behavior = list_plannings[planningName]; } Debug.Check(behavior is Node); BehaviorTreeList behaviorTreeList = BehaviorManager.Instance as BehaviorTreeList; Debug.Check(behaviorTreeList != null); behaviorTreeList.ShowNode(behavior as Node); BehaviorTreeView view = BehaviorTreeViewDock.GetBehaviorTreeView(behavior); return view; }