Developer documentation | Axl-2.5.1

axlInspectorToolCreatorDataDynamicDialog.cpp
Go to the documentation of this file.
1 /* axlInspectorToolCreatorDataDynamicDialog.cpp ---
2  *
3  * Author: Anais Ducoffe
4  * Copyright (C) 2013 - Anais Ducoffe, Inria.
5  */
6 
7 /* Commentary:
8  *
9  */
10 
11 /* Change log:
12  *
13  */
14 
18 
19 #include <axlCore/axlDataDynamic.h>
20 #include <axlCore/axlDouble.h>
21 #include <axlCore/axlInteger.h>
23 #include <dtkGuiSupport/dtkColorButton.h>
24 
26 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
27 
30 
31 #include <QtGui>
32 
33 class axlInspectorToolCreatorDataDynamicDialogPrivate
34 {
35 public:
36  QSlider *sliderOpacity;
37  dtkColorButton *colorButton;
38  axlInspectorObjectController *controller;
39 
40  QLineEdit *process_name;
41  QLineEdit *listDoubleValues;
42 
43  //display number of double inputs needed and their meanings.
44  QLabel *messageToDisplay;
45  QLabel *errorMessage;
46 
47  //main frame
48  QVBoxLayout *layout;
49 
50  //process dialog
52 
53  //determine if it is a dynamic object or a computation node
54  QCheckBox *isStatic;
55 
56 };
57 
58 axlInspectorToolCreatorDataDynamicDialog::axlInspectorToolCreatorDataDynamicDialog(QWidget *parent) : QFrame(parent), d(new axlInspectorToolCreatorDataDynamicDialogPrivate)
59 {
60 
61  d->dialog = new axlInspectorToolInterface(this);
62  // d->dialog->setImplementation("axlLineCreator");
63  d->dialog->hide();
64 
65  d->layout = new QVBoxLayout(this);
66 
67  //OPACITY//
68  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
69 
70  QHBoxLayout *layoutOpacity = new QHBoxLayout;
71  layoutOpacity->addWidget(new QLabel("Opacity",this));
72  layoutOpacity->addWidget(d->sliderOpacity);
73  d->sliderOpacity->setMaximum(100);
74 
75  //COLOR//
76  d->colorButton = new dtkColorButton(this);
77 
78  QHBoxLayout *layoutColorButton = new QHBoxLayout;
79  layoutColorButton->addWidget(new QLabel("Color",this));
80  layoutColorButton->addWidget(d->colorButton);
81  d->colorButton->setColor(QColor("#a0a0a4"));
82 
83  // PROCESS NAME
84  QHBoxLayout *layoutProcessName = new QHBoxLayout;
85  layoutProcessName->addWidget(new QLabel("Process name",this));
86  d->process_name = new QLineEdit(this);
87  QCompleter *completer = new QCompleter(dtkAbstractProcessFactory::instance()->creators(), this);
88  completer->setCaseSensitivity(Qt::CaseSensitive);
89  d->process_name->setCompleter(completer);
90 
91  layoutProcessName->addWidget(d->process_name);
92  connect(d->process_name, SIGNAL(textChanged(QString)), this, SLOT(setProcessName()));
93 
94  // DOUBLE VALUES
95  QHBoxLayout *layoutDoubleValues = new QHBoxLayout;
96  QLabel *labelParameters = new QLabel("double inputs values",this);
97  layoutDoubleValues->addWidget(labelParameters);
98  d->listDoubleValues = new QLineEdit(this);
99  layoutDoubleValues->addWidget(d->listDoubleValues);
100 
101  // DOUBLE NAMES
102  d->messageToDisplay = new QLabel("", this);
103  d->messageToDisplay->setStyleSheet("color: #ff0000;");
104  d->messageToDisplay->setVisible(false);// on ne l'affiche qu'en cas de besoin
105 
106  // ERROR MESSAGE
107  d->errorMessage = new QLabel("wrong inputs number or type,\n please select them as describe above");
108  d->errorMessage->setStyleSheet("color: #ff0000;");
109  d->errorMessage->setVisible(false);// on ne l'affiche qu'en cas de besoin
110 
111  // checkbox
112  QHBoxLayout *layoutIsDynamic = new QHBoxLayout(this);
113  QLabel *labelIsStatic = new QLabel("static",this);
114  layoutIsDynamic->addWidget(labelIsStatic);
115  d->isStatic = new QCheckBox(this);
116  layoutIsDynamic->addWidget(d->isStatic);
117 
118 
119  QPushButton *button = new QPushButton("Create", this);
120  connect(button, SIGNAL(clicked()), this, SLOT(run()));
121 
122  d->layout->addWidget(new QLabel("axlInspectorToolCreatorDataDynamic", this));
123  d->layout->addLayout(layoutOpacity);
124  d->layout->addLayout(layoutColorButton);
125  d->layout->addLayout(layoutProcessName);
126  d->layout->addWidget(d->messageToDisplay);
127  d->layout->addLayout(layoutDoubleValues);
128  d->layout->addWidget(d->dialog);
129  d->layout->addLayout(layoutIsDynamic);
130  d->layout->addWidget(button);
131  d->layout->addWidget(d->errorMessage);
132 
133  d->listDoubleValues->hide();
134  labelParameters->hide();
135 
136 }
137 
139 
143 {
144  delete d;
145 
146  d = NULL;
147 }
148 
150 
154 {
155  d->controller = controller;
156  d->dialog->setController(controller);
157 }
158 
159 
160 
162 
166 
167  if(d->dialog)
168  d->dialog->hide();
169  // list process inputs needed
170  QString processName = d->process_name->text();
171 
172  if(!processName.isEmpty()){
173  axlAbstractProcess *process = dynamic_cast<axlAbstractProcess *>(dtkAbstractProcessFactory::instance()->create(processName));
174  if(process){
176  if(newDialog){
177  // d->messageToDisplay->setText(process->description());
178  // d->messageToDisplay->show();
179  d->layout->removeWidget(d->dialog);
180  delete d->dialog;
181  d->dialog = NULL;
182  // delete newDialog;
183  // d->dialog->setImplementation(process->identifier());
184  d->dialog = newDialog;
185  d->dialog->setController(d->controller);
186  d->messageToDisplay->hide();
187  d->listDoubleValues->hide();
188  //utiliser le dialog du process
189  if(dynamic_cast<axlInspectorToolCreator *>(d->dialog))
190  dynamic_cast<axlInspectorToolCreator *>(d->dialog)->setController(d->controller);
191  else
192  d->dialog->setController(d->controller);
193 
194  QObjectList listChildren = d->dialog->children();
195  for(int i = 0; i < listChildren.size();i++){
196  if(dynamic_cast<QPushButton *>(listChildren.at(i)) /*&& !dynamic_cast<dtkColorButton *>(listChildren.at(i))*/ ){
197  dynamic_cast<QWidget *>(listChildren.at(i))->hide();
198  }else if(dynamic_cast<QSlider *>(listChildren.at(i))){
199  dynamic_cast<QWidget *>(listChildren.at(i))->hide();
200  }else if(dynamic_cast<QLabel *>(listChildren.at(i))){
201  if(dynamic_cast<QLabel *>(listChildren.at(i))->text() == "Opacity" || dynamic_cast<QLabel *>(listChildren.at(i))->text() == "Color")
202  dynamic_cast<QWidget *>(listChildren.at(i))->hide();
203  }
204  }
205  // for(int j = 0;j < listChildren.size();j++){
206  // if(dynamic_cast<axlInspectorToolInterface *>(listChildren.at(j)))
207  // qDebug() << "axlInspectorToolCreatorDataDynamicDialog::setProcessName" << j;
208  // }
209 
210  d->layout->insertWidget(6, d->dialog);
211  d->dialog->show();
212 
213  }else{
214  QString textToDisplay ;
215  textToDisplay.append(process->description());
216  //si le process necessite des parameters
217  if(process->hasParameters())
218  textToDisplay.append("\n double inputs values: ");
219  d->messageToDisplay->setText(textToDisplay);
220  d->messageToDisplay->show();
221  if(process->hasParameters())
222  d->listDoubleValues->show();
223 
224  }
225  }else{
226  d->listDoubleValues->hide();
227  d->messageToDisplay->setText("This process doesn't exist");
228  d->messageToDisplay->show();
229  }
230  delete process;
231  }
232 }
233 
235 
239 {
240  d->errorMessage->hide();
241  axlDataDynamic *dynamicData = new axlDataDynamic();
242  //create right process
243  QString processName = d->process_name->text();
244  if(!processName.isEmpty()){
245  dynamicData->setProcess(processName);
246  }
247 
248  //check if it is a computation node or a dynamic object.
249  if(d->isStatic->isChecked()){
250  dynamicData->setType(axlDataDynamic::Static);
251  }
252 
253  if(dynamicData->process()){
254  //setting inputs data
255  //first by selecting inputs data in the axlinspectorObjectTree
256  foreach(axlInspectorObjectManagerTreeItem *item, d->controller->items()) {
257 
258  if(item->text(2) == "Selected"|| item->text(2) == "Editable")
259  {
260  if(dynamic_cast<axlAbstractData *>(d->controller->data(item))) {
261  if(axlDataDynamic *axldata = dynamic_cast<axlDataDynamic *>(d->controller->data(item)))
262  dynamicData->setInput(axldata->outputs());
263  else
264  dynamicData->setInput(d->controller->data(item));
265  }
266  }
267 
268  }
269 
270  //setting inputs numbers (parameters)
271  QString doubleValues = d->listDoubleValues->text();
272  if(d->listDoubleValues->isVisible() && !doubleValues.isEmpty()){
273  int sizeList = doubleValues.size();
274  int indice = 0;
275  QString value = "";
276  while(indice <= sizeList){
277  if(doubleValues.at(indice).isSpace() || indice ==(sizeList)){
278  if(!value.isEmpty()){
279  bool hasLetter = false;
280  for(int j = 0;j <value.size();j++){
281  if(value.at(j).isLetter())
282  hasLetter = true;
283  }
284  if(!hasLetter){
285  double newInputValue = value.toDouble();
286  axlDouble *input = new axlDouble(newInputValue);
287  dynamicData->setInput(input);
288  }
289  value.clear();
290  }
291 
292  }else{
293  value.append(doubleValues.at(indice));
294  }
295  indice++;
296  }
297  }
298  QObjectList list = this->children();
299  for(int i = 0;i < list.size();i++){
300  if(QFrame *frame = dynamic_cast<QFrame *>(list.at(i))){
301  QObjectList list1 = frame->children();
302  for(int j = 0;j < list1.size();j++){
303  if(QDoubleSpinBox *box = dynamic_cast<QDoubleSpinBox *>(list1.at(j))){
304  double value = box->value();
305  axlDouble *input = new axlDouble(value);
306  dynamicData->setInput(input);
307  }else if(QSpinBox *box = dynamic_cast<QSpinBox *>(list1.at(j))){
308  int value = box->value();
309  axlInteger *input = new axlInteger(value);
310  dynamicData->setInput(input);
311  }
312  }
313  }
314 
315  }
316 
317 
318  dynamicData->update();
319  if(!dynamicData->outputs()){
320  dynamicData->clearInputs();
321  if(d->dialog && dynamic_cast<axlInspectorToolCreator *>(d->dialog)){
322  QList<axlAbstractData *>listInputs = dynamic_cast<axlInspectorToolCreator *>(d->dialog)->returnInputsList();
323  for(int j = 0;j< listInputs.size();j++){
324  dynamicData->setInput(listInputs.at(j));
325  }
326 
327  dynamicData->update();
328  if(dynamicData->outputs()){
329  for(int k = 0; k < dynamicData->inputs().size();k++){
330  if(!(dynamicData->inputs().at(k)->identifier() == "axlDouble") && !(dynamicData->inputs().at(k)->identifier() == "axlInteger")){
331  dynamicData->inputs().at(k)->setColor(d->colorButton->color());
332  double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
333  dynamicData->inputs().at(k)->setOpacity(opacity);
334  emit dataInserted(dynamicData->inputs().at(k));
335  }
336 
337  }
338 
339  dynamicData->setColor(d->colorButton->color());
340  double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
341  dynamicData->setOpacity(opacity);
342  emit dataInserted(dynamicData);
343  // d->dialog->hide();
344  }else{
345  // not enough or appropriated inputs
346  d->errorMessage->show();
347  if(d->dialog && dynamic_cast<axlInspectorToolCreator *>(d->dialog)){
348  d->dialog->show();
349  dynamic_cast<axlInspectorToolCreator *>(d->dialog)->run();
350  }
351 
352  }
353 
354 
355  }
356 
357  }else{
358  //compute outputs
359  dynamicData->setColor(d->colorButton->color());
360  double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
361  dynamicData->setOpacity(opacity);
362  emit dataInserted(dynamicData);
363  if(d->dialog){
364  d->dialog->hide();
365  }
366  }
367 
368 
369  }
370 
371 
372 }
373 // /////////////////////////////////////////////////////////////////
374 // axlInspectorToolCreatorDataDynamicDialog documentation
375 // /////////////////////////////////////////////////////////////////
376 
virtual void update(void)
Update the dynamic object.
void run(void)
Create the dynamic Object when the create button is clicked.
int setProcess(QString processName)
Create the dynamic object process only with the name of its latter.
virtual bool hasParameters(void)
void setType(axlDataDynamic::Type type)
Sets the type of the object. Type could be dynamic or static.
Class axlDouble defines a double.
Definition: axlDouble.h:29
void setProcessName(void)
Checks if the process exits and then display appropriated dialog to enter and select inputs...
axlInspectorToolInterface * create(const QString &type)
axlAbstractData * outputs(void)
Return the first output of the list.
axlAbstractProcess * process(void)
Return the process.
Class axlDataDynamic defines a dynamic object.
void setInput(dtkAbstractData *data, int channel=0)
Add input;.
virtual QString description(void) const
void dataInserted(axlAbstractData *data)
void setController(axlInspectorObjectController *controller)
Assigns a controller.
Class axlInteger defines an integer.
Definition: axlInteger.h:28
QList< axlAbstractData * > inputs(void)
Return input list;.
void setOpacity(const double &opacity)
void clearInputs(void)
Clear input list.
static axlInspectorToolFactory * instance(void)
void setColor(double r, double g, double b)
virtual QString identifier(void) const