private void ExportNode(StreamWriter file, string btClassName, string agentType, string parentName, Node node, int indentDepth) { // generate the indent string string indent = string.Empty; for (int i = 0; i < indentDepth; ++i) { indent += '\t'; } string nodeName = string.Format("node{0}", node.Id); // open some brackets for a better formatting in the generated code file.WriteLine("{0}{{", indent); // export its instance and the properties NodeCsExporter nodeExporter = NodeCsExporter.CreateInstance(node); nodeExporter.GenerateInstance(node, file, indent, nodeName, agentType, btClassName); ExportPars(file, nodeName, node, indent); ExportAttachment(file, btClassName, agentType, nodeName, node, indent + "\t"); // add the node to its parent file.WriteLine("{0}\t{1}.AddChild({2});", indent, parentName, nodeName); // export the child nodes if (!(node is ReferencedBehavior)) { foreach (Node child in node.Children) { ExportNode(file, btClassName, agentType, nodeName, child, indentDepth + 1); } } file.WriteLine("{0}\t{1}.SetHasEvents({1}.HasEvents() | {2}.HasEvents());", indent, parentName, nodeName); // close the brackets for a better formatting in the generated code file.WriteLine("{0}}}", indent); }
private void ExportNode(StreamWriter file, string btClassName, string agentType, string parentName, Node node, int indentDepth) { if (!node.Enable) { return; } // generate the indent string string indent = string.Empty; for (int i = 0; i < indentDepth; ++i) { indent += '\t'; } string nodeName = string.Format("node{0}", node.Id); // open some brackets for a better formatting in the generated code file.WriteLine("{0}{{", indent); // export its instance and the properties NodeCsExporter nodeExporter = NodeCsExporter.CreateInstance(node); nodeExporter.GenerateInstance(node, file, indent, nodeName, agentType, btClassName); ExportPars(file, agentType, nodeName, node, indent); ExportAttachment(file, btClassName, agentType, nodeName, node, indent + "\t"); bool isAsChild = true; if (node.Parent != null) { BaseNode.Connector connector = node.Parent.GetConnector(node); if (connector != null && !connector.IsAsChild) { isAsChild = false; } } if (isAsChild) { // add the node to its parent file.WriteLine("{0}\t{1}.AddChild({2});", indent, parentName, nodeName); } else { // add the node as its customized children file.WriteLine("{0}\t{1}.SetCustomCondition({2});", indent, parentName, nodeName); } // export the child nodes if (!node.IsFSM && !(node is ReferencedBehavior)) { foreach (Node child in node.GetChildNodes()) { ExportNode(file, btClassName, agentType, nodeName, child, indentDepth + 1); } } file.WriteLine("{0}\t{1}.SetHasEvents({1}.HasEvents() | {2}.HasEvents());", indent, parentName, nodeName); // close the brackets for a better formatting in the generated code file.WriteLine("{0}}}", indent); }