24 #include <dtkCoreSupport/dtkAbstractData.h>
25 #include <dtkCoreSupport/dtkAbstractProcess>
26 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
27 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
49 return "axlDataDynamicReader";
54 return "axlDataDynamicReader";
59 return QStringList() <<
"axlDataDynamic";
64 return dtkAbstractDataFactory::instance()->registerDataReaderType(
"axlDataDynamicReader", QStringList(),
createaxlDataDynamicReader);
69 QDomElement element = node.toElement();
71 if(element.tagName() !=
"process")
79 return !this->
accept(node);
86 QDomElement element = node.toElement();
87 QString typeElement = element.attribute(
"status");
93 QString status = element.attribute(
"status");
94 if(!status.isEmpty()){
95 if(status ==
"static"){
100 QString name = element.attribute(
"name");
103 currentData->setObjectName(name);
106 QString color = element.attribute(
"color");
109 QStringList colorList = color.split(
" ");
110 if(colorList.size() == 3)
111 currentData->
setColor(QColor(colorList.at(0).toInt(), colorList.at(1).toInt(), colorList.at(2).toInt()));
115 QString size = element.attribute(
"size");
118 currentData->
setSize(size.toDouble());
122 QString processName = element.attribute(
"type");
123 if(!processName.isEmpty())
141 QDomNodeList nodeListField = element.elementsByTagName(
"field");
142 if(!nodeListField.isEmpty()){
143 for(
int i =0; i < nodeListField.size(); i++){
144 QDomElement fieldElement = nodeListField.at(i).toElement();
145 QString fieldType = fieldElement.attribute(
"type");
146 if(!fieldType.isEmpty()){
208 dtkWarn() << Q_FUNC_INFO<<list.
size();
209 QDomElement element = node.toElement();
211 QDomNodeList nextChild = element.childNodes();
213 QDomNodeList nodelistinput = element.elementsByTagName(
"input") ;
216 for (
int i = 0; i < nodelistinput.size(); i++) {
217 QDomElement childElement = nodelistinput.at(i).toElement();
223 if (!childElement.attribute(
"channel").isEmpty()) {
224 channel=childElement.attribute(
"channel").toInt();
228 QString typeChild = childElement.attribute(
"type");
231 if (typeChild ==
"data") {
232 QString nameInput = childElement.attribute(
"name");
235 if (!list.isEmpty()) {
236 bool input_found =
false;
237 for (
int j = 0; j < list.size(); j++) {
239 if (list.at(j)->name() == nameInput) {
240 dynamic_cast<axlDataDynamic *
>(data)->setInput(list.at(j), channel);
244 }
else if (
axlDataDynamic *ddata = dynamic_cast<axlDataDynamic *>(list.at(j))) {
246 for (
int i = 0; i < ddata->numberOfChannels(); i++) {
247 if(ddata->outputs(i)->name() == nameInput){
249 dynamic_cast<axlDataDynamic *
>(data)->setInput(ddata->outputs(i));
262 dtkWarn()<<
"Input" << nameInput <<
"not found";
265 }
else if(typeChild ==
"double"){
266 QString valueDouble = childElement.attribute(
"value");
281 QDomNodeList nodelistparam = element.elementsByTagName(
"parameter") ;
282 bool several_params = (nodelistparam.size()>0);
285 for(
int i = 0; i< nodelistparam.size();i++){
287 QDomElement childElement = nodelistparam.at(i).toElement();
290 channel = num_params;
292 if (!childElement.attribute(
"channel").isEmpty()) {
293 channel=childElement.attribute(
"channel").toInt();
297 QString typeChild = childElement.attribute(
"type");
311 if(typeChild ==
"double") {
312 QString valueDouble = childElement.attribute(
"value");
315 dtkWarn() << Q_FUNC_INFO << 2;
317 dynamic_cast<axlDataDynamic *
>(data)->setParameter(valueDouble.toDouble(),channel);
319 dynamic_cast<axlDataDynamic *
>(data)->setParameter(valueDouble.toDouble());
328 }
else if(typeChild ==
"int") {
329 QString valueInt = childElement.attribute(
"value");
332 dtkWarn()<<
"Set parameter"<<valueInt<<num_params<<several_params;
334 dynamic_cast<axlDataDynamic *
>(data)->setParameter(valueInt.toInt(),channel);
336 dynamic_cast<axlDataDynamic *
>(data)->setParameter(valueInt.toInt());
354 QDomNodeList nodelistoutputs = element.elementsByTagName(
"output") ;
356 QString typeProcess = element.attribute(
"type");
358 dtkWarn() << Q_FUNC_INFO << typeProcess;
360 if (!typeProcess.isEmpty()) {
362 dtkWarn() << Q_FUNC_INFO <<
"update dynamic data";
366 for(
int i = 0; i < dynamic_cast<axlDataDynamic *>(data)->numberOfChannels(); i++){
368 QDomElement childElement = nodelistoutputs.at(i).toElement();
374 QString color = childElement.attribute(
"color");
375 if (!color.isEmpty()) {
376 dtkWarn() << Q_FUNC_INFO <<
"color";
377 QStringList colorList = color.split(
" ");
378 if (colorList.size() > 2) {
379 dynamic_cast<axlDataDynamic *
>(data)->outputs(i)->
setColor(QColor(colorList.at(0).toInt(), colorList.at(1).toInt(), colorList.at(2).toInt()));
381 }
else if(colorList.size() == 4) {
387 QString shader = childElement.attribute(
"shader");
389 if (!shader.isEmpty()) {
391 dirShader =
":axlShader/shader/"+shader;
392 if (!QFile::exists(dirShader)) {
393 QSettings settings(
"inria",
"dtk");
395 settings.beginGroup(
"shader");
396 dirShader = settings.value(
"path", defaultPath).toString();
398 dirShader.append(
"/"+shader);
404 QString size = childElement.attribute(
"size");
405 if (!size.isEmpty()) {
410 QString nameO = childElement.attribute(
"name");
413 if (!nameO.isEmpty()) {
414 dynamic_cast<axlDataDynamic *
>(data)->outputs(i)->setObjectName(nameO);
427 if(!axl_reader->
accept(node))
430 axl_reader->dtkAbstractDataReader::read(this->file());
bool accept(const QDomNode &node)
static bool registered(void)
~axlDataDynamicReader(void)
int setProcess(QString processName)
Create the dynamic object process only with the name of its latter.
void setType(axlDataDynamic::Type type)
Sets the type of the object. Type could be dynamic or static.
QStringList handled(void) const
Class axlDouble defines a double.
void setShader(const QString &shader)
dtkAbstractDataReader * create(const QString &interface_name)
bool reject(const QDomNode &node)
QString description(void) const
Class axlDataDynamic defines a dynamic object.
virtual axlAbstractData * read(const QDomNode &node)=0
Class axlAbstractField defines an API for arrays of numeric data.
Class axlInteger defines an integer.
axlAbstractData * dataByReader(axlAbstractDataReader *axl_reader, const QDomNode &node)
void setOpacity(const double &opacity)
QString identifier(void) const
axlAbstractData * readInputs(axlDataDynamic *data, const QDomNode &node, const QList< axlAbstractData * > &list)
Construct an axlAbstractData from a node and a list of data.
axlAbstractData * read(const QDomNode &node)
virtual bool accept(const QDomNode &node)=0
dtkAbstractDataReader * createaxlDataDynamicReader(void)
static axlFieldReadersFactory * instance(void)
void addField(axlAbstractField *field)
Add a field to the field list of the object.
void setSize(const double &size)
void setColor(double r, double g, double b)
Class axlAbstractData defines an API for all type of axel data.
axlDataDynamicReader(void)