53 #include <QXmlResultItems> 59 #include "function.hh" 61 #include "types/number.hh" 62 #include "types/string.hh" 63 #include "types/bool.hh" 64 #include "types/filename.hh" 65 #include "types/selection.hh" 66 #include "types/vec3d.hh" 67 #include "types/vec4d.hh" 68 #include "types/matrix4x4.hh" 69 #include "types/objectId/objectId.hh" 70 #include "types/any.hh" 72 #define DATA_NAME "DataFlow" 85 scriptEngine_ (_engine)
91 e->category_ =
"Undefined";
93 e->shortDesc_ =
"Start";
94 e->longDesc_ =
"Start";
96 e->dataOut_ =
new Output (e);
97 e->dataOut_->name_ =
"data";
98 e->dataOut_->type_ =
"data";
100 e->dataOut_->shortDesc_ = DATA_NAME;
101 e->dataOut_->longDesc_ = DATA_NAME;
103 e->flags_ = ELEMENT_FLAG_NO_DELETE | ELEMENT_FLAG_SKIP_TOOLBOX;
107 elements_.append (e);
109 e->category_ =
"Undefined";
111 e->shortDesc_ =
"End";
112 e->longDesc_ =
"End";
114 e->dataIn_ =
new Input (e);
115 e->dataIn_->name_ =
"data";
116 e->dataIn_->type_ =
"data";
118 e->dataIn_->shortDesc_ = DATA_NAME;
119 e->dataIn_->longDesc_ = DATA_NAME;
121 e->flags_ = ELEMENT_FLAG_NO_DELETE | ELEMENT_FLAG_SKIP_TOOLBOX;
142 foreach (
Element *e, elements_)
144 foreach (
Type *t, types_)
153 QVector <Element *> rv;
154 foreach (
Element *e, elements_)
165 foreach (
Element *e, elements_)
166 if (e->
name () == _name)
178 foreach (
Element *e, elements_)
179 if (!sl.contains (e->
category ()) && !(e->
flags () & ELEMENT_FLAG_SKIP_TOOLBOX))
190 QBuffer device (&_xml);
191 device.open(QIODevice::ReadOnly);
194 query.setFocus (&device);
197 query.setQuery (
"OpenFlipper//element");
201 if (query.isValid ())
203 query.evaluateTo (&elements);
204 QXmlItem item (elements.next ());
205 while (!item.isNull ())
210 item = elements.next ();
220 void Context::parseElement (QXmlQuery &_xml)
227 elements_.append (e);
229 e->category_ =
getXmlString (_xml,
"category/string(text())",
"Undefined");
232 e->longDesc_ =
getXmlString (_xml,
"long/string(text())", e->shortDesc_);
238 e->dataIn_ =
new Input (e);
239 e->dataIn_->name_ =
"data";
240 e->dataIn_->type_ = QVariant::Invalid;
242 e->dataIn_->shortDesc_ = DATA_NAME;
243 e->dataIn_->longDesc_ = DATA_NAME;
244 e->dataIn_->
setState (Input::NoRuntimeUserInput | Input::NoUserInput);
246 e->dataOut_ =
new Output (e);
247 e->dataOut_->name_ =
"data";
248 e->dataOut_->type_ = QVariant::Invalid;
250 e->dataOut_->shortDesc_ = DATA_NAME;
251 e->dataOut_->longDesc_ = DATA_NAME;
255 _xml.setQuery (
"inputs/input");
257 QXmlResultItems inouts;
261 _xml.evaluateTo (&inouts);
262 QXmlItem item (inouts.next ());
263 while (!item.isNull ())
267 Input *i = parseInput (q, e);
270 e->inputs_.append (i);
272 item = inouts.next ();
278 _xml.setQuery (
"outputs/output");
282 _xml.evaluateTo (&inouts);
283 QXmlItem item (inouts.next ());
284 while (!item.isNull ())
288 Output *o = parseOutput (q, e);
292 e->outputs_.append (o);
294 item = inouts.next ();
300 _xml.setQuery (
"functions/function");
304 _xml.evaluateTo (&inouts);
305 QXmlItem item (inouts.next ());
306 while (!item.isNull ())
313 e->functions_.append (f);
315 item = inouts.next ();
321 e->precode_ =
getXmlString (_xml,
"precode/string(text())",
"");
322 e->code_ =
getXmlString (_xml,
"code/string(text())",
"");
325 e->precode_ = e->precode_.replace (QRegExp (
"\\n\\s*"),
"\n");
326 e->code_ = e->code_.replace (QRegExp (
"\\n\\s*"),
"\n");
333 Input* Context::parseInput (QXmlQuery &_xml,
Element *_e)
338 if (!parseInOutBase (_xml, i))
345 QString stateStr =
getXmlString (_xml,
"string(@external)");
346 unsigned int state = 0;
348 if (!stateStr.isEmpty () && !
strToBool (stateStr))
349 state |= Input::NoExternalInput;
353 if (!stateStr.isEmpty () && !
strToBool (stateStr))
354 state |= Input::NoUserInput;
358 if (!stateStr.isEmpty () && !
strToBool (stateStr))
359 state |= Input::NoRuntimeUserInput;
363 if (!stateStr.isEmpty () &&
strToBool (stateStr))
364 state |= Input::Optional;
379 if (!parseInOutBase (_xml, o))
391 bool Context::parseInOutBase (QXmlQuery &_xml,
InOut *_io)
402 _io->shortDesc_ =
getXmlString (_xml,
"short/string(text())", _io->
name ());
403 _io->longDesc_ =
getXmlString (_xml,
"long/string(text())", _io->shortDesc_);
408 foreach (QString hint, supportedTypes_[type]->supportedHints ())
410 QString value =
getXmlString (_xml, hint +
"/string(text())",
"");
411 if (!value.isEmpty ())
412 _io->hints_[hint] = value;
431 f->longDesc_ =
getXmlString (_xml,
"long/string(text())", f->shortDesc_);
436 f->start_->category_ =
"Undefined";
438 f->start_->shortDesc_ =
"Start";
439 f->start_->longDesc_ =
"Start";
441 f->start_->dataOut_ =
new Output (f->start_);
442 f->start_->dataOut_->name_ =
"data";
443 f->start_->dataOut_->type_ =
"data";
445 f->start_->dataOut_->shortDesc_ = DATA_NAME;
446 f->start_->dataOut_->longDesc_ = DATA_NAME;
448 f->start_->flags_ = ELEMENT_FLAG_NO_DELETE | ELEMENT_FLAG_SKIP_TOOLBOX;
450 elements_.append (f->start_);
455 f->end_->category_ =
"Undefined";
457 f->end_->shortDesc_ =
"End";
458 f->end_->longDesc_ =
"End";
460 f->end_->dataIn_ =
new Input (f->end_);
461 f->end_->dataIn_->name_ =
"data";
462 f->end_->dataIn_->type_ =
"data";
464 f->end_->dataIn_->shortDesc_ = DATA_NAME;
465 f->end_->dataIn_->longDesc_ = DATA_NAME;
467 f->end_->flags_ = ELEMENT_FLAG_NO_DELETE | ELEMENT_FLAG_SKIP_TOOLBOX;
469 elements_.append (f->end_);
472 _xml.setQuery (
"inputs/input");
474 QXmlResultItems inouts;
478 _xml.evaluateTo (&inouts);
479 QXmlItem item (inouts.next ());
480 while (!item.isNull ())
485 if (parseInOutBase(q, o))
487 f->start_->outputs_.append (o);
491 item = inouts.next ();
497 _xml.setQuery (
"outputs/output");
501 _xml.evaluateTo (&inouts);
502 QXmlItem item (inouts.next ());
503 while (!item.isNull ())
508 if (parseInOutBase(q, i))
510 i->state_ = Input::NoUserInput | Input::NoRuntimeUserInput;
511 f->end_->inputs_.append (i);
515 item = inouts.next ();
521 if (!f->end_->
inputs ().isEmpty ())
525 QString endCode =
"return { ";
527 endCode += i->
name () +
" : [input=\"" + i->
name () +
"\"], ";
528 endCode.remove (endCode.length () - 2, 2);
531 f->end_->code_ = endCode;
544 _xml.setQuery (_expr);
546 if (_xml.isValid () && _xml.evaluateTo (&sl) && sl.length () == 1)
557 if (_str ==
"1" || _str ==
"true" || _str ==
"True" || _str ==
"TRUE" ||
558 _str ==
"yes" || _str ==
"Yes" || _str ==
"YES")
568 types_.append (_type);
571 supportedTypes_.insert (s, _type);
579 return supportedTypes_.contains (_type);
589 return supportedTypes_[_type1]->canConvertTo (_type2) ||
590 supportedTypes_[_type2]->canConvertTo (_type1);
599 return supportedTypes_[_type];
unsigned int flags() const
Flags.
const QVector< Input * > & inputs() const
Inputs.
const QString & category() const
Element category.
QString name() const
Name.
const QVector< Element * > & elements() const
Returns all available elements.
bool typeSupported(QString _type)
Is the given type supported.
QStringList categories()
List of categories.
void parse(QByteArray _xml)
Parse xml content.
Context * context() const
Context of element.
Element * element(QString _name)
Returns the element with a given name.
static bool strToBool(QString _str)
Converts the given string to bool.
const QString & name() const
Name.
Context(QScriptEngine *_engine)
Constructor.
bool canConvert(QString _type1, QString _type2)
Can the given types be converted to each other.
QString name() const
Element name.
void setState(unsigned int _state)
Sets the state.
static QString getXmlString(QXmlQuery &_xml, QString _expr, QString _default="")
Gets the string of a xml query.
virtual QStringList supportedTypes()
Names of Types.
void registerType(Type *_type)
Registers a supported datatype.
Type * getType(QString _type)
Get type object for given type name.