/// <summary> /// Loads a behaviour from the given filename /// </summary> /// <param name="getBehaviorNode">The callback used to return the behavior.</param> public override void Load(List <Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode) { try { //FileStream fs = Plugin.ConcurrentSourceFileStreams.GetValueUnsafe(_filename); //if (fs == null) //{ // fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read); //} FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read); _xmlfile.Load(fs); fs.Close(); XmlNode rootNode = _xmlfile.ChildNodes[1]; int versionLoaded = (rootNode.Attributes != null) ? int.Parse(rootNode.Attributes["Version"] != null ? rootNode.Attributes["Version"].Value : "0") : 0; this._version = versionLoaded; if (versionLoaded > Nodes.Behavior.NewVersion) { MessageBox.Show(Resources.FileVersionWarning, Resources.LoadWarning, MessageBoxButtons.OK); } foreach (XmlNode xmlNode in rootNode.ChildNodes) { if (xmlNode.Name == "Node") { _behavior = (BehaviorNode)CreateNodeAndAdd(result, getBehaviorNode, xmlNode, null, null); ProcessedBehaviors processedBehaviors = new ProcessedBehaviors(); DoPostLoad(processedBehaviors, (Node)_behavior); break; } } if (_behavior != null) { if (versionLoaded != Nodes.Behavior.NewVersion) { _behavior.Version = Nodes.Behavior.NewVersion; _behavior.TriggerWasModified((Node)_behavior); } string noError = rootNode.Attributes["NoError"] != null ? rootNode.Attributes["NoError"].Value : "false"; _behavior.HasNoError = (noError == "true"); } } catch (Exception e) { string errorInfo = string.Format("{0}\n{1}", _filename, e.Message); MessageBox.Show(errorInfo, Resources.LoadError, MessageBoxButtons.OK); _xmlfile.RemoveAll(); throw; } }
public override void SynchronizeWithNode(ProcessedBehaviors processedBehaviors) { Nodes.Precondition pre = (Nodes.Precondition)_node; _defaultStyle.Background = pre.Negate ? _backgroundBrushNeg : _backgroundBrush; _draggedStyle.Background = pre.Negate ? _draggedBackgroundBrushNeg : _draggedBackgroundBrush; base.SynchronizeWithNode(processedBehaviors); }
/// <summary> /// This function adapts the children of the view that they represent the children of the node this view is for. /// Children are added and removed. /// </summary> /// <param name="processedBehaviors">A list of previously processed behaviours to deal with circular references.</param> public override void SynchronizeWithNode(ProcessedBehaviors processedBehaviors) { // if we have a circular reference, we must skip it if (!processedBehaviors.MayProcessCheckOnly(_node)) { _children.ClearChildren(); return; } base.SynchronizeWithNode(processedBehaviors); }
/// <summary> /// This method allows nodes to process the loaded attributes. /// </summary> /// <param name="processedBehaviors">The behaviours which have already been processed to avoid circular references.</param> /// <param name="node">The node which is processed.</param> protected void DoPostLoad(ProcessedBehaviors processedBehaviors, Node node) { if (processedBehaviors.MayProcess(node)) { node.PostLoad(_behavior); foreach (Node child in node.Children) { DoPostLoad(processedBehaviors.Branch(child), child); } } }
/// <summary> /// Adds nodes to the referenced behaviour which represent sub-referenced behaviours. /// </summary> /// <param name="processedBehaviors">A list of processed behaviours to handle circular references.</param> /// <param name="parent">The node the sub-referenced behaviours will be added to.</param> /// <param name="node">The current node we are checking.</param> protected void GenerateReferencedBehaviorsTree(ProcessedBehaviors processedBehaviors, NodeViewData parent, Node node) { if (!processedBehaviors.MayProcess(node)) { return; } // check if this is a referenced behaviour if (node is ReferencedBehaviorNode) { // create the dummy node and add it without marking the behaviour as being modified as these are no REAL nodes. NodeViewData rb = node.CreateNodeViewData(parent, _rootBehavior); #if DEBUG rb.IsSubreferencedGraphNode(); #endif rb.DoSynchronizeWithNode(processedBehaviors); Connector conn = parent.GetConnector("Tasks"); Debug.Check(conn != null); Connector rbconn = parent.GetConnector("Tasks"); Debug.Check(rbconn != null); parent.AddChildNotModified(conn, rb); // we have a circular reference here. Skip the children if (((ReferencedBehaviorNode)node).Reference == _rootBehavior) { rbconn.IsReadOnly = true; return; } // do the same for all the children foreach (Node child in node.Children) { GenerateReferencedBehaviorsTree(processedBehaviors.Branch(child), rb, child); } rbconn.IsReadOnly = true; } else { // do the same for all the children foreach (Node child in node.Children) { GenerateReferencedBehaviorsTree(processedBehaviors.Branch(child), parent, child); } } }
public override void DoSynchronizeWithNode(ProcessedBehaviors processedBehaviors) { _forceSynchronization = false; // make all connectors changable for (int i = 0; i < _children.Connectors.Count; ++i) { _children.Connectors[i].IsReadOnly = false; } base.DoSynchronizeWithNode(processedBehaviors); // add all methods we can find Nodes.CompoundTask compoundTask = (Nodes.CompoundTask)_node; _usedMethodType = compoundTask.MethodType; if (compoundTask.MethodType.Length < 1) { return; } Connector methods = GetConnector("Methods"); Debug.Check(methods != null); List <Nodes.Method> methodList = new List <Nodes.Method>(); // collect all the methods we find IList <string> allMethods = BehaviorManager.Instance.GetAllBehaviors(); for (int i = 0; i < allMethods.Count; ++i) { Nodes.Method method = (Nodes.Method)BehaviorManager.Instance.LoadBehavior(allMethods[i]); Debug.Check(method != null); if (method != _rootBehavior && method.MethodType == compoundTask.MethodType) { methodList.Add(method); } } // sort methods by priority methodList.Sort(SortMethodsByPriority); // add methods to node foreach (Nodes.Method method in methodList) { Debug.Verify(AddChildNotModified(methods, method.CreateNodeViewData(this, _rootBehavior))); } }
/// <summary> /// Loads a behaviour from the given filename /// </summary> /// <param name="getBehaviorNode">The callback used to return the behavior.</param> public override void Load(List <Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode) { try { FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read); _xmlfile.Load(fs); fs.Close(); XmlNode rootNode = _xmlfile.ChildNodes[1]; int versionLoaded = (rootNode.Attributes != null) ? int.Parse(rootNode.Attributes["Version"] != null ? rootNode.Attributes["Version"].Value : "0") : 0; this._version = versionLoaded; if (versionLoaded > Nodes.Behavior.NewVersion) { MessageBox.Show(Resources.FileVersionWarning, Resources.LoadWarning, MessageBoxButtons.OK); } foreach (XmlNode xmlNode in rootNode.ChildNodes) { if (xmlNode.Name == "Node") { _behavior = (BehaviorNode)CreateNodeAndAdd(result, getBehaviorNode, xmlNode, null, null); ProcessedBehaviors processedBehaviors = new ProcessedBehaviors(); DoPostLoad(processedBehaviors, (Node)_behavior); break; } } if (_behavior != null && versionLoaded != Nodes.Behavior.NewVersion) { _behavior.Version = Nodes.Behavior.NewVersion; _behavior.TriggerWasModified((Node)_behavior); } } catch (Exception e) { MessageBox.Show(e.Message, Resources.LoadError, MessageBoxButtons.OK); _xmlfile.RemoveAll(); throw; } }
/// <summary> /// Loads a behaviour from the given filename /// </summary> /// <param name="getBehaviorNode">The callback used to return the behavior.</param> public override void Load(GetBehaviorNode getBehaviorNode) { try { FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read); _xmlfile.Load(fs); fs.Close(); foreach (XmlNode xmlNode in _xmlfile.ChildNodes[1].ChildNodes) { if (xmlNode.Name == "Node") { _behavior = (BehaviorNode)CreateNodeAndAdd(getBehaviorNode, xmlNode, null, null); ProcessedBehaviors processedBehaviors = new ProcessedBehaviors(); DoPostLoad(processedBehaviors, (Node)_behavior); } else if (xmlNode.Name == "Parameters") { Debug.Check(_behavior != null); if (((Node)_behavior).Version == 0) { LoadParameters(xmlNode, (Node)_behavior, ((Node)_behavior).Pars); } } else if (xmlNode.Name == "DescriptorRefs") { #if QUERY_EANBLED LoadDescriptorRefs(xmlNode, _behavior as Behavior); #endif//#if QUERY_EANBLED } } } catch (Exception e) { MessageBox.Show(e.Message, Resources.LoadError, MessageBoxButtons.OK); _xmlfile.RemoveAll(); throw; } }
/// <summary> /// Loads a behaviour from the given filename /// </summary> /// <param name="getBehaviorNode">The callback used to return the behavior.</param> public override void Load(GetBehaviorNode getBehaviorNode) { try { _xmlfile.Load(_filename); XmlNode root = _xmlfile.ChildNodes[1].ChildNodes[0]; _node = (BehaviorNode)CreateNodeAndAdd(getBehaviorNode, root, null, null); ProcessedBehaviors processedBehaviors = new ProcessedBehaviors(); DoPostLoad(processedBehaviors, (Node)_node); } catch { _xmlfile.RemoveAll(); throw; } }
public override void DoSynchronizeWithNode(ProcessedBehaviors processedBehaviors) { // make all connectors changable for (int i = 0; i < _children.Connectors.Count; ++i) { _children.Connectors[i].IsReadOnly = false; } if (_isExpanded) { base.DoSynchronizeWithNode(processedBehaviors); } else { _subGraphNeedsToBeRebuilt = false; _children.ClearConnectors(); RemoveAllConnectorSubItems(); //foreach(Connector connector in _node.Connectors) // connector.Clone(_children); new ConnectorMultiple(_children, string.Empty, "GenericChildren", 1, int.MaxValue); // generate the dummy nodes for the sub-referenced behaviours foreach (Node child in ((Node)((ReferencedBehaviorNode)_node).Reference).Children) { GenerateReferencedBehaviorsTree(processedBehaviors, this, child); } // make all connectors readonly for (int i = 0; i < _children.Connectors.Count; ++i) { _children.Connectors[i].IsReadOnly = true; } GenerateNewLabel(); } }
/// <summary> /// Loads a behaviour from the given filename /// </summary> /// <param name="getBehaviorNode">The callback used to return the behavior.</param> public override void Load(List<Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode) { try { FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read); _xmlfile.Load(fs); fs.Close(); XmlNode rootNode = _xmlfile.ChildNodes[1]; int versionLoaded = (rootNode.Attributes != null) ? int.Parse(rootNode.Attributes["Version"] != null ? rootNode.Attributes["Version"].Value : "0") : 0; this._version = versionLoaded; if (versionLoaded > Nodes.Behavior.NewVersion) { MessageBox.Show(Resources.FileVersionWarning, Resources.LoadWarning, MessageBoxButtons.OK); } foreach(XmlNode xmlNode in rootNode.ChildNodes) { if (xmlNode.Name == "Node") { _behavior = (BehaviorNode)CreateNodeAndAdd(result, getBehaviorNode, xmlNode, null, null); ProcessedBehaviors processedBehaviors = new ProcessedBehaviors(); DoPostLoad(processedBehaviors, (Node)_behavior); break; } } if (_behavior != null && versionLoaded != Nodes.Behavior.NewVersion) { _behavior.Version = Nodes.Behavior.NewVersion; _behavior.TriggerWasModified((Node)_behavior); } } catch (Exception e) { MessageBox.Show(e.Message, Resources.LoadError, MessageBoxButtons.OK); _xmlfile.RemoveAll(); throw; } }
/// <summary> /// This method allows nodes to process the loaded attributes. /// </summary> /// <param name="processedBehaviors">The behaviours which have already been processed to avoid circular references.</param> /// <param name="node">The node which is processed.</param> protected void DoPostLoad(ProcessedBehaviors processedBehaviors, Node node) { if (processedBehaviors.MayProcess(node)) { node.PostLoad(_behavior); foreach(Node child in node.Children) DoPostLoad(processedBehaviors.Branch(child), child); } }
/// <summary> /// Loads a behaviour from the given filename /// </summary> /// <param name="getBehaviorNode">The callback used to return the behavior.</param> public override void Load(GetBehaviorNode getBehaviorNode) { try { FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read); _xmlfile.Load(fs); fs.Close(); foreach (XmlNode xmlNode in _xmlfile.ChildNodes[1].ChildNodes) { if (xmlNode.Name == "Node") { _behavior = (BehaviorNode)CreateNodeAndAdd(getBehaviorNode, xmlNode, null, null); ProcessedBehaviors processedBehaviors = new ProcessedBehaviors(); DoPostLoad(processedBehaviors, (Node)_behavior); } else if (xmlNode.Name == "Parameters") { Debug.Check(_behavior != null); if (((Node)_behavior).Version == 0) LoadParameters(xmlNode, (Node)_behavior, ((Node)_behavior).Pars); } else if (xmlNode.Name == "DescriptorRefs") { #if QUERY_EANBLED LoadDescriptorRefs(xmlNode, _behavior as Behavior); #endif//#if QUERY_EANBLED } } } catch(Exception e) { MessageBox.Show(e.Message, Resources.LoadError, MessageBoxButtons.OK); _xmlfile.RemoveAll(); throw; } }