47 #include <QXmlResultItems> 53 #include "function.hh" 55 #include "types/number.hh" 56 #include "types/string.hh" 57 #include "types/bool.hh" 58 #include "types/filename.hh" 59 #include "types/selection.hh" 60 #include "types/vec3d.hh" 61 #include "types/vec4d.hh" 62 #include "types/matrix4x4.hh" 63 #include "types/objectId/objectId.hh" 64 #include "types/any.hh" 66 #define DATA_NAME "DataFlow" 79 scriptEngine_ (_engine)
85 e->category_ =
"Undefined";
87 e->shortDesc_ =
"Start";
88 e->longDesc_ =
"Start";
90 e->dataOut_ =
new Output (e);
91 e->dataOut_->name_ =
"data";
92 e->dataOut_->type_ =
"data";
94 e->dataOut_->shortDesc_ = DATA_NAME;
95 e->dataOut_->longDesc_ = DATA_NAME;
97 e->flags_ = ELEMENT_FLAG_NO_DELETE | ELEMENT_FLAG_SKIP_TOOLBOX;
101 elements_.append (e);
103 e->category_ =
"Undefined";
105 e->shortDesc_ =
"End";
106 e->longDesc_ =
"End";
108 e->dataIn_ =
new Input (e);
109 e->dataIn_->name_ =
"data";
110 e->dataIn_->type_ =
"data";
112 e->dataIn_->shortDesc_ = DATA_NAME;
113 e->dataIn_->longDesc_ = DATA_NAME;
115 e->flags_ = ELEMENT_FLAG_NO_DELETE | ELEMENT_FLAG_SKIP_TOOLBOX;
136 foreach (
Element *e, elements_)
138 foreach (
Type *t, types_)
147 QVector <Element *> rv;
148 foreach (
Element *e, elements_)
159 foreach (
Element *e, elements_)
160 if (e->
name () == _name)
172 foreach (
Element *e, elements_)
173 if (!sl.contains (e->
category ()) && !(e->
flags () & ELEMENT_FLAG_SKIP_TOOLBOX))
184 QBuffer device (&_xml);
185 device.open(QIODevice::ReadOnly);
188 query.setFocus (&device);
191 query.setQuery (
"OpenFlipper//element");
195 if (query.isValid ())
197 query.evaluateTo (&elements);
198 QXmlItem item (elements.next ());
199 while (!item.isNull ())
204 item = elements.next ();
214 void Context::parseElement (QXmlQuery &_xml)
221 elements_.append (e);
223 e->category_ =
getXmlString (_xml,
"category/string(text())",
"Undefined");
226 e->longDesc_ =
getXmlString (_xml,
"long/string(text())", e->shortDesc_);
232 e->dataIn_ =
new Input (e);
233 e->dataIn_->name_ =
"data";
234 e->dataIn_->type_ = QVariant::Invalid;
236 e->dataIn_->shortDesc_ = DATA_NAME;
237 e->dataIn_->longDesc_ = DATA_NAME;
238 e->dataIn_->
setState (Input::NoRuntimeUserInput | Input::NoUserInput);
240 e->dataOut_ =
new Output (e);
241 e->dataOut_->name_ =
"data";
242 e->dataOut_->type_ = QVariant::Invalid;
244 e->dataOut_->shortDesc_ = DATA_NAME;
245 e->dataOut_->longDesc_ = DATA_NAME;
249 _xml.setQuery (
"inputs/input");
251 QXmlResultItems inouts;
255 _xml.evaluateTo (&inouts);
256 QXmlItem item (inouts.next ());
257 while (!item.isNull ())
261 Input *i = parseInput (q, e);
264 e->inputs_.append (i);
266 item = inouts.next ();
272 _xml.setQuery (
"outputs/output");
276 _xml.evaluateTo (&inouts);
277 QXmlItem item (inouts.next ());
278 while (!item.isNull ())
282 Output *o = parseOutput (q, e);
286 e->outputs_.append (o);
288 item = inouts.next ();
294 _xml.setQuery (
"functions/function");
298 _xml.evaluateTo (&inouts);
299 QXmlItem item (inouts.next ());
300 while (!item.isNull ())
307 e->functions_.append (f);
309 item = inouts.next ();
315 e->precode_ =
getXmlString (_xml,
"precode/string(text())",
"");
316 e->code_ =
getXmlString (_xml,
"code/string(text())",
"");
319 e->precode_ = e->precode_.replace (QRegExp (
"\\n\\s*"),
"\n");
320 e->code_ = e->code_.replace (QRegExp (
"\\n\\s*"),
"\n");
327 Input* Context::parseInput (QXmlQuery &_xml,
Element *_e)
332 if (!parseInOutBase (_xml, i))
339 QString stateStr =
getXmlString (_xml,
"string(@external)");
340 unsigned int state = 0;
342 if (!stateStr.isEmpty () && !
strToBool (stateStr))
343 state |= Input::NoExternalInput;
347 if (!stateStr.isEmpty () && !
strToBool (stateStr))
348 state |= Input::NoUserInput;
352 if (!stateStr.isEmpty () && !
strToBool (stateStr))
353 state |= Input::NoRuntimeUserInput;
357 if (!stateStr.isEmpty () &&
strToBool (stateStr))
358 state |= Input::Optional;
373 if (!parseInOutBase (_xml, o))
385 bool Context::parseInOutBase (QXmlQuery &_xml,
InOut *_io)
396 _io->shortDesc_ =
getXmlString (_xml,
"short/string(text())", _io->
name ());
397 _io->longDesc_ =
getXmlString (_xml,
"long/string(text())", _io->shortDesc_);
402 foreach (QString hint, supportedTypes_[type]->supportedHints ())
404 QString value =
getXmlString (_xml, hint +
"/string(text())",
"");
405 if (!value.isEmpty ())
406 _io->hints_[hint] = value;
425 f->longDesc_ =
getXmlString (_xml,
"long/string(text())", f->shortDesc_);
430 f->start_->category_ =
"Undefined";
432 f->start_->shortDesc_ =
"Start";
433 f->start_->longDesc_ =
"Start";
435 f->start_->dataOut_ =
new Output (f->start_);
436 f->start_->dataOut_->name_ =
"data";
437 f->start_->dataOut_->type_ =
"data";
439 f->start_->dataOut_->shortDesc_ = DATA_NAME;
440 f->start_->dataOut_->longDesc_ = DATA_NAME;
442 f->start_->flags_ = ELEMENT_FLAG_NO_DELETE | ELEMENT_FLAG_SKIP_TOOLBOX;
444 elements_.append (f->start_);
449 f->end_->category_ =
"Undefined";
451 f->end_->shortDesc_ =
"End";
452 f->end_->longDesc_ =
"End";
454 f->end_->dataIn_ =
new Input (f->end_);
455 f->end_->dataIn_->name_ =
"data";
456 f->end_->dataIn_->type_ =
"data";
458 f->end_->dataIn_->shortDesc_ = DATA_NAME;
459 f->end_->dataIn_->longDesc_ = DATA_NAME;
461 f->end_->flags_ = ELEMENT_FLAG_NO_DELETE | ELEMENT_FLAG_SKIP_TOOLBOX;
463 elements_.append (f->end_);
466 _xml.setQuery (
"inputs/input");
468 QXmlResultItems inouts;
472 _xml.evaluateTo (&inouts);
473 QXmlItem item (inouts.next ());
474 while (!item.isNull ())
479 if (parseInOutBase(q, o))
481 f->start_->outputs_.append (o);
485 item = inouts.next ();
491 _xml.setQuery (
"outputs/output");
495 _xml.evaluateTo (&inouts);
496 QXmlItem item (inouts.next ());
497 while (!item.isNull ())
502 if (parseInOutBase(q, i))
504 i->state_ = Input::NoUserInput | Input::NoRuntimeUserInput;
505 f->end_->inputs_.append (i);
509 item = inouts.next ();
515 if (!f->end_->
inputs ().isEmpty ())
519 QString endCode =
"return { ";
521 endCode += i->
name () +
" : [input=\"" + i->
name () +
"\"], ";
522 endCode.remove (endCode.length () - 2, 2);
525 f->end_->code_ = endCode;
538 _xml.setQuery (_expr);
540 if (_xml.isValid () && _xml.evaluateTo (&sl) && sl.length () == 1)
551 if (_str ==
"1" || _str ==
"true" || _str ==
"True" || _str ==
"TRUE" ||
552 _str ==
"yes" || _str ==
"Yes" || _str ==
"YES")
562 types_.append (_type);
565 supportedTypes_.insert (s, _type);
573 return supportedTypes_.contains (_type);
583 return supportedTypes_[_type1]->canConvertTo (_type2) ||
584 supportedTypes_[_type2]->canConvertTo (_type1);
593 return supportedTypes_[_type];
Context(QScriptEngine *_engine)
Constructor.
const QString & name() const
Name.
QString name() const
Name.
bool canConvert(QString _type1, QString _type2)
Can the given types be converted to each other.
QStringList categories()
List of categories.
Context * context() const
Context of element.
bool typeSupported(QString _type)
Is the given type supported.
QString name() const
Element name.
const QVector< Element * > & elements() const
Returns all available elements.
static bool strToBool(QString _str)
Converts the given string to bool.
void parse(QByteArray _xml)
Parse xml content.
const QVector< Input * > & inputs() const
Inputs.
void setState(unsigned int _state)
Sets the state.
Element * element(QString _name)
Returns the element with a given name.
void registerType(Type *_type)
Registers a supported datatype.
const QString & category() const
Element category.
Type * getType(QString _type)
Get type object for given type name.
virtual QStringList supportedTypes()
Names of Types.
unsigned int flags() const
Flags.
static QString getXmlString(QXmlQuery &_xml, QString _expr, QString _default="")
Gets the string of a xml query.