From d6571e5a9b8fc2bed416ff4798e3a29136004ff5 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 9 Jan 2014 16:50:51 +0000 Subject: beginnng json output --- NT/src/factory.cpp | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 182 insertions(+), 4 deletions(-) (limited to 'NT/src/factory.cpp') diff --git a/NT/src/factory.cpp b/NT/src/factory.cpp index 6888a19..db50919 100644 --- a/NT/src/factory.cpp +++ b/NT/src/factory.cpp @@ -5,7 +5,185 @@ using namespace Rotor; Node_factory::Node_factory(){ //for now, statically load prototype map in constructor - add_type("time",new Time(),"nodes"); - add_type("multiply",new Multiply(),"nodes"); - add_type("print",new Print(),"nodes"); -} \ No newline at end of file + add_type(new Time(),"nodes"); + add_type(new Multiply(),"nodes"); + add_type(new Print(),"nodes"); +} +bool Node_factory::list_node(const string &t,xmlIO XML){ + for (auto& type: type_map) { + if (type.first==t) { + list_node(type.second,XML); + return true; + } + } + XML.addValue("error","Node /"+t+"/ not found"); + return false; +}; +bool Node_factory::list_node(const string &t,Json::Value &JSON){ + for (auto& type: type_map) { + if (type.first==t) { + JSON["node"]=list_node(type.second); + return true; + } + } + JSON["error"]="Node /"+t+"/ not found"; + return false; +}; +Json::Value Node_factory::list_node(Rotor::Node* _node){ + Json::Value node; + node["node_type"]=_node->node_type; + node["title"]=_node->title; + node["output_type"]=_node->output_type; + node["description"]=_node->description; + node["node_id"]=_node->node_id; + node["ui_type"]=_node->ui_type; + + if (_node->vars.size()){ + node["vars"]=Json::arrayValue; + for (auto& var: _node->vars) { + Json::Value newvar; + newvar["type"]=var.second->get_type(); + newvar["connectable"]=var.second->connectable?"yes":"no"; + node["vars"].append(newvar); + } + } +/* + if (_node->inputs.size()){ + node["signal_inputs"]=Json::arrayValue; + for (auto& input: _node->inputs) { + Json::Value signal_input; + signal_input["title"]=input->title; + signal_input["description"]=input->description; + node["signal_inputs"].append(signal_input); + } + } + if (dynamic_cast (_node)!=nullptr) { + if ((dynamic_cast(_node))->image_inputs.size()){ + node["image_inputs"]=Json::arrayValue; + for (auto& input: (dynamic_cast(_node))->image_inputs) { + Json::Value image_input; + image_input["title"]=input->title; + image_input["description"]=input->description; + node["image_inputs"].append(image_input); + } + } + } + if (_node->parameters.size()){ + node["parameters"]=Json::arrayValue; + for (auto& param: _node->parameters) { + Json::Value parameter; + parameter["name"]=param.first; + parameter["type"]=param.second->type; + parameter["title"]=param.second->title; + parameter["description"]=param.second->description; + parameter["value"]=param.second->value; + parameter["min"]=param.second->min; + parameter["max"]=param.second->max; + parameter["step"]=param.second->step; + node["parameters"].append(parameter); + } + } + if (_node->attributes.size()){ + node["attributes"]=Json::arrayValue; + for (auto& attr: _node->attributes) { + Json::Value attribute; + attribute["name"]=attr.first; + attribute["title"]=attr.second->title; + attribute["description"]=attr.second->description; + if (attr.second->vals.size()){ //document attribute enumeration + attribute["value"]=attr.second->value; + attribute["type"]="enum"; + attribute["options"]=Json::arrayValue; + for (auto val: attr.second->vals){ + attribute["options"].append(val); + } + } + else { + attribute["type"]=attr.second->type; + if (attr.second->type=="array"){ + attribute["value"]=Json::arrayValue; + } + else attribute["value"]=attr.second->value; + } + node["attributes"].append(attribute); + } + } +*/ + return node; +} + +void Node_factory::list_node(Rotor::Node* type,xmlIO XML,int i){ + XML.addTag("node"); + XML.addAttribute("node","output_type",type->output_type,i); + XML.addAttribute("node","node_type",type->node_type,i); + XML.addAttribute("node","title",type->title,i); + XML.addAttribute("node","description",type->description,i); + XML.addAttribute("node","node_id",type->node_id,i); + XML.addAttribute("node","ui_type",type->ui_type,i); + XML.pushTag("node",i); +/* + //if (type->description!="") { + // XML.addTag("description"); + // XML.setValue("description",type->description,0); + //} + int j=0; + for (auto& input: type->inputs) { + XML.addTag("signal_input"); + XML.addAttribute("signal_input","title",input->title,j); + XML.addAttribute("signal_input","description",input->description,j); + j++; + } + j=0; + if (dynamic_cast (type)!=nullptr) { + for (auto& input: (dynamic_cast(type))->image_inputs) { + XML.addTag("image_input"); + XML.addAttribute("image_input","title",input->title,j); + XML.addAttribute("image_input","description",input->description,j); + j++; + } + } + j=0; + for (auto& parameter: type->parameters) { + XML.addTag("parameter"); + XML.addAttribute("parameter","name",parameter.first,j); + XML.addAttribute("parameter","type",parameter.second->type,j); + XML.addAttribute("parameter","title",parameter.second->title,j); + XML.addAttribute("parameter","description",parameter.second->description,j); + XML.addAttribute("parameter","value",parameter.second->value,j); + XML.addAttribute("parameter","min",parameter.second->min,j); + XML.addAttribute("parameter","max",parameter.second->max,j); + XML.addAttribute("parameter","step",parameter.second->step,j); + j++; + } + j=0; + for (auto& attribute: type->attributes) { + XML.addTag("attribute"); + XML.addAttribute("attribute","name",attribute.first,j); + XML.addAttribute("attribute","title",attribute.second->title,j); + XML.addAttribute("attribute","description",attribute.second->description,j); + if (attribute.second->vals.size()){ //document attribute enumeration + XML.addAttribute("attribute","value",attribute.second->value,j); + XML.addAttribute("attribute","type","enum",j); + XML.pushTag("attribute",j); + int k=0; + for (auto val: attribute.second->vals){ + XML.addTag("option"); + XML.addAttribute("option","value",val,k); + k++; + } + XML.popTag(); + } + else { + XML.addAttribute("attribute","type",attribute.second->type,j); + if (attribute.second->type=="array"){ + XML.pushTag("attribute",j); + XML.addTag("value"); + XML.popTag(); + } + else XML.addAttribute("attribute","value",attribute.second->value,j); + } + j++; + } +*/ + XML.popTag(); +} -- cgit v1.2.3