38 #include <dtkCoreSupport/dtkGlobal.h>
39 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
40 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
44 class axlDataDynamicPrivate
47 QList<axlAbstractData *> inputs;
48 QList<axlAbstractData *> parameters;
50 QList<axlAbstractData*> output;
74 for(
int k = 0; k < d->inputs.size();k++){
76 if(!dynamic_cast<axlDouble *>(d->inputs.at(k)) && !dynamic_cast<axlInteger *>(d->inputs.at(k))){
77 disconnect(d->inputs.at(k), SIGNAL(destroyed()),
this, SLOT(
onRemoved()));
79 delete d->inputs.at(k);
83 d->parameters.clear();
86 if(!d->output.isEmpty()){
87 for(
int i = 0; i < d->output.size();i++){
89 delete d->output.at(i);
105 emit destroyed(
this);
142 if (d->output.size() > channel) {
143 return d->output.at(channel);
145 qDebug() << Q_FUNC_INFO <<
"no channel-th output available";
155 if (d->output.size() > 0) {
156 return d->output.at(0);
158 qDebug() << Q_FUNC_INFO <<
"no output computed" << d->process->identifier();
178 if(dynamic_cast<axlAbstractData *>(data)){
179 return !(d->inputs.contains(dynamic_cast<axlAbstractData *>(data)));
190 if(dynamic_cast<axlAbstractData *>(data)){
191 return !(d->output.contains(dynamic_cast<axlAbstractData *>(data)));
220 if (
axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(data)) {
221 d->inputs.append(axlData);
230 if (!dynamic_cast<axlDouble *>(data) && !dynamic_cast<axlInteger *>(data)) {
232 connect(axlData, SIGNAL(destroyed()),
this, SLOT(
onRemoved()));
242 if(d->process!= NULL)
243 d->process->setParameter(value);
245 dtkWarn()<<
"axlDataDynamic: process NULL";
253 if(d->process!= NULL)
254 d->process->setParameter(value,channel);
256 dtkWarn()<<
"axlDataDynamic: process NULL";
264 if(d->process!= NULL)
265 d->process->setParameter(value);
267 dtkWarn()<<
"axlDataDynamic: process NULL";
275 if(d->process!= NULL)
276 d->process->setParameter(value,channel);
278 dtkWarn()<<
"axlDataDynamic: process NULL";
286 d->process =
dynamic_cast<axlAbstractProcess *
>(dtkAbstractProcessFactory::instance()->create(processName));
287 dtkWarn() <<
"Process" << processName;
291 dtkWarn() <<
"Process" << processName <<
"not found";
302 d->process->copyProcess(process);
313 if(d->output.empty()){
314 return " create a dynamic object";
316 if(!d->output.isEmpty()){
319 return " create a dynamic object \n" + output->description();
333 return "axlDataDynamic";
342 return d->output.size();
354 if (!(d->output.empty())) {
355 for (
int i = 0; i < d->output.size(); i++) {
356 this->
remove(d->output.at(i));
362 int compteurParametre = 0;
363 for (
int i = 0;i < d->inputs.size(); i++) {
364 if(dynamic_cast<axlDouble *>(d->inputs.at(i)) || dynamic_cast<axlInteger *>(d->inputs.at(i)) ) {
370 int countParametersDouble = 0;
371 int countParametersInt = 0;
376 for (
int i = 0; i < d->inputs.size(); i++) {
377 if (
axlDouble *axldata = dynamic_cast<axlDouble *>(d->inputs.at(i))) {
378 if (compteurParametre == 1){
379 d->process->setParameter(axldata->value());
381 d->process->setParameter(axldata->value(), countParametersDouble);
383 countParametersDouble++;
384 }
else if(
axlInteger *axldata = dynamic_cast<axlInteger *>(d->inputs.at(i))) {
385 if (compteurParametre == 1) {
386 d->process->setParameter(axldata->value());
388 d->process->setParameter(axldata->value(), countParametersInt);
390 countParametersInt++;
393 d->process->setInput(d->inputs.at(i),countData);
398 result = d->process->update();
401 dtkWarn()<<Q_FUNC_INFO <<
"no process found";
406 dtkWarn() << Q_FUNC_INFO <<
"problem in process, should return 1" << d->process->identifier() <<
"update";
410 if (d->process->channelCount() > 1) {
411 for (
int i = 0; i< d->process->channelCount(); i++) {
413 d->output.append(dynamic_cast<axlAbstractData *>(d->process->output(i)));
416 if(dynamic_cast<axlAbstractData *>(d->output.at(i))){
423 axlData->setObjectName(axlData->identifier());
431 d->output.append(dynamic_cast<axlAbstractData *>(d->process->output()));
433 if(dynamic_cast<axlAbstractData *>(d->output.at(0))){
440 axlData->setObjectName(axlData->identifier());
447 for(
int i = 0; i < d->inputs.size(); i++){
448 for (
int j = 0; j< d->output.size();j++){
449 if(d->output.at(j) == d->inputs.at(i)){
450 d->inputs.at(i)->setEditable(
true);
456 for(
int i = 0; i < d->output.size();i++){
457 this->
add(d->output.at(i));
462 if(!this->
fields().isEmpty())
471 QVariant
id = QVariant::fromValue(
identifier());
473 QVariant nbUp = QVariant::fromValue(d->nbUp);
475 QVariant
process = QVariant::fromValue(d->process->identifier());
476 list.append(process);
478 QVariant type = QVariant::fromValue(1);
481 QVariant type = QVariant::fromValue(2);
487 for(
int i = 0; i < d->inputs.size();i++){
488 QVariantList in = d->inputs.at(i)->convertDataToQVariant();
490 list.append(
"input");
497 for(
int i = 0; i < d->parameters.size();i++){
498 QVariantList param = d->parameters.at(i)->convertDataToQVariant();
499 int s = param.size();
500 list.append(
"parameter");
507 for(
int i = 0; i < d->output.size();i++){
508 QVariantList out = d->output.at(i)->convertDataToQVariant();
510 list.append(
"output");
516 QVariant name = QVariant::fromValue(objectName());
524 d->nbUp = data.at(1).toInt();
526 int type = data.at(3).toInt();
533 int currentIndice = 4;
534 while(currentIndice < (data.size()-1)){
535 QString what = data.at(currentIndice).toString();
536 int count = data.at(currentIndice+1).toInt();
537 QString
id = data.at(currentIndice+2).toString();
540 for(
int i = 0;i <
count;i++){
541 list.append(data.at(currentIndice+2+i));
546 d->inputs.append(obj);
549 }
else if(what==
"parameter"){
550 d->parameters.append(obj);
553 d->output.append(obj);
556 currentIndice = currentIndice+count+2;
559 setObjectName(data.last().toString());
virtual void update(void)
Update the dynamic object.
void add(dtkAbstractData *data)
axlDataDynamic::Type getType(void)
Return the type : dynamic if it is a dynamic object or static if it is just a computation node...
bool isNotInputProcess(dtkAbstractData *data)
Check whether the output of the process is a different object that one of its inputs.
virtual void touchField(void)
int setProcess(QString processName)
Create the dynamic object process only with the name of its latter.
virtual int numberOfChannels(void)
Return the number of output(s);.
QVariantList convertDataToQVariant(void) const
void setType(axlDataDynamic::Type type)
Sets the type of the object. Type could be dynamic or static.
Class axlDouble defines a double.
void onRemoved(void)
This slot is called whenever one of the dynamic object input is deleted.
void setEditable(bool edit)
virtual QString description(void) const
Return a description of the dynamic object.
virtual int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
axlAbstractData * outputs(void)
Return the first output of the list.
void modifiedGeometry(void)
dtkAbstractData * createAxlDataDynamic(void)
int convertQVariantToData(const QVariantList &data)
axlAbstractProcess * process(void)
Return the process.
Class axlDataDynamic defines a dynamic object.
void setInput(dtkAbstractData *data, int channel=0)
Add input;.
bool isNotOutputProcess(dtkAbstractData *data)
Check whether the data is an output of the process.
void setParameter(int parameter)
Set parameter.
Class axlInteger defines an integer.
QList< axlAbstractData * > inputs(void)
Return input list;.
int numberOfUpdate(void)
Return how many times the geometry of the dynamic object has been updated.
void clearInputs(void)
Clear input list.
virtual QString identifier(void) const
Return the identifier "axlDataDynamic".
virtual ~axlDataDynamic(void)
QList< axlAbstractField * > fields(void)
virtual QString identifier(void) const
Class axlAbstractData defines an API for all type of axel data.