summaryrefslogtreecommitdiff
path: root/NT/src/factory.cpp
blob: dd395332f9c522fbe6cc8ec350ebd976edcf20ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "factory.h"

using namespace Rotor;

Node_factory::Node_factory(){
	//for now, statically load prototype map in constructor

	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"]=type.second->list_json();
			return true;
		}
	}
	JSON["error"]="Node /"+t+"/ not found";
	return false;
};


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<Image_node*> (type)!=nullptr) {
			for (auto& input: (dynamic_cast<Image_node*>(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();
}