Vuo  2.4.0
VuoNode.cc
Go to the documentation of this file.
1
10#include "VuoNode.hh"
11
12#include "VuoNodeClass.hh"
13#include "VuoPort.hh"
14#include "VuoStringUtilities.hh"
15
16#include <stdio.h>
17
18
24VuoNode::VuoNode(VuoNodeClass * nodeClass, string title, VuoPort * refreshPort, vector<VuoPort *> inputPorts, vector<VuoPort *> outputPorts, double x, double y, bool collapsed, VuoNode::TintColor tintColor)
26{
27 this->nodeClass = nodeClass;
28 this->title = title;
29 this->refreshPort = refreshPort;
30 this->inputPorts = inputPorts;
31 this->outputPorts = outputPorts;
32 this->x = x;
33 this->y = y;
34 this->collapsed = collapsed;
35 this->tintColor = tintColor;
36 this->forbidden = false;
37}
38
43{
44 return nodeClass;
45}
46
51{
52 for (vector<VuoPort *>::iterator i = inputPorts.begin(); i != inputPorts.end(); ++i)
53 if (portName == (*i)->getClass()->getName())
54 return *i;
55
56 return NULL;
57}
58
63{
64 for (vector<VuoPort *>::iterator i = outputPorts.begin(); i != outputPorts.end(); ++i)
65 if (portName == (*i)->getClass()->getName())
66 return *i;
67
68 return NULL;
69}
70
75{
76 return refreshPort;
77}
78
82vector<VuoPort *> VuoNode::getInputPorts(void)
83{
84 return inputPorts;
85}
86
93{
94 vector<VuoPort *> foundPorts;
95 for (vector<VuoPort *>::iterator i = inputPorts.begin(); i != inputPorts.end(); ++i)
96 if ((*i) == port)
97 return foundPorts;
98 else
99 foundPorts.push_back(*i);
100 return vector<VuoPort *>();
101}
102
109{
110 vector<VuoPort *> foundPorts;
111 bool found = false;
112 for (vector<VuoPort *>::iterator i = inputPorts.begin(); i != inputPorts.end(); ++i)
113 {
114 if (found)
115 foundPorts.push_back(*i);
116 if ((*i) == port)
117 found = true;
118 }
119 return foundPorts;
120}
121
125vector<VuoPort *> VuoNode::getOutputPorts(void)
126{
127 return outputPorts;
128}
129
136{
137 vector<VuoPort *> foundPorts;
138 for (vector<VuoPort *>::iterator i = outputPorts.begin(); i != outputPorts.end(); ++i)
139 if ((*i) == port)
140 return foundPorts;
141 else
142 foundPorts.push_back(*i);
143 return vector<VuoPort *>();
144}
145
152{
153 vector<VuoPort *> foundPorts;
154 bool found = false;
155 for (vector<VuoPort *>::iterator i = outputPorts.begin(); i != outputPorts.end(); ++i)
156 {
157 if (found)
158 foundPorts.push_back(*i);
159 if ((*i) == port)
160 found = true;
161 }
162 return foundPorts;
163}
164
173{
174 return title;
175}
176
184void VuoNode::setTitle(string title)
185{
186 this->title = title;
187}
188
193{
194 return nodeClass->isTypecastNodeClass();
195}
196
201{
202 return x;
203}
204
209{
210 return y;
211}
212
216void VuoNode::setX(int x)
217{
218 this->x = x;
219}
220
224void VuoNode::setY(int y)
225{
226 this->y = y;
227}
228
233{
234 return collapsed;
235}
236
240void VuoNode::setCollapsed(bool collapsed)
241{
242 this->collapsed = collapsed;
243}
244
249{
250 return tintColor;
251}
252
257{
258 return getGraphvizNameForTint(tintColor);
259}
260
265{
266 this->tintColor = tintColor;
267}
268
273{
274 return forbidden;
275}
276
280void VuoNode::setForbidden(bool forbidden)
281{
282 this->forbidden = forbidden;
283}
284
289{
290 this->rawGraphvizDeclaration = declaration;
291}
292
298{
299 return rawGraphvizDeclaration;
300}
301
307{
308 string identifier;
309 for (int j = 0; j < rawGraphvizDeclaration.length() && VuoStringUtilities::isValidCharInIdentifier(rawGraphvizDeclaration[j]); ++j)
310 identifier += rawGraphvizDeclaration[j];
311 return identifier;
312}
313
318{
319 printf("VuoNode(%p,\"%s\")",this,title.c_str());
320 if (hasCompiler())
321 printf(" VuoCompilerNode(%p)",getCompiler());
322 if (hasRenderer())
323 printf(" VuoRendererNode(%p)",getRenderer());
324 printf("\n");
325
326 printf("\tposition (%d,%d)\n", x, y);
327 printf("\tcollapsed %s\n", collapsed ? "true" : "false");
328 printf("\ttintColor %s\n", getTintColorGraphvizName().c_str());
329
330 for (vector<VuoPort *>::iterator it = inputPorts.begin(); it != inputPorts.end(); ++it)
331 {
332 printf("\tinput ");
333 (*it)->print();
334 }
335
336 for (vector<VuoPort *>::iterator it = outputPorts.begin(); it != outputPorts.end(); ++it)
337 {
338 printf("\toutput ");
339 (*it)->print();
340 }
341
342 fflush(stdout);
343}
344
349{
350 switch (tintColor)
351 {
352 case VuoNode::TintYellow:
353 return "yellow";
354 case VuoNode::TintTangerine:
355 return "tangerine";
356 case VuoNode::TintOrange:
357 return "orange";
358 case VuoNode::TintMagenta:
359 return "magenta";
360 case VuoNode::TintViolet:
361 return "violet";
362 case VuoNode::TintBlue:
363 return "blue";
364 case VuoNode::TintCyan:
365 return "cyan";
366 case VuoNode::TintGreen:
367 return "green";
368 case VuoNode::TintLime:
369 return "lime";
370 default:
371 return "";
372 }
373}
374
379{
380 if (tintName == "yellow")
381 return VuoNode::TintYellow;
382 else if (tintName == "tangerine")
383 return VuoNode::TintTangerine;
384 else if (tintName == "orange")
385 return VuoNode::TintOrange;
386 else if (tintName == "magenta")
387 return VuoNode::TintMagenta;
388 else if (tintName == "violet")
389 return VuoNode::TintViolet;
390 else if (tintName == "blue")
391 return VuoNode::TintBlue;
392 else if (tintName == "cyan")
393 return VuoNode::TintCyan;
394 else if (tintName == "green")
395 return VuoNode::TintGreen;
396 else if (tintName == "lime")
397 return VuoNode::TintLime;
398 else
399 return VuoNode::TintNone;
400}