Developer documentation | Axl-2.5.1

axlInspectorToolCreatorSphere.cpp
Go to the documentation of this file.
1 /* axlInspectorToolCreatorSphere.cpp ---
2  *
3  * Author: Julien Wintz
4  * Copyright (C) 2008 - Julien Wintz, Inria.
5  * Created: Wed Mar 16 17:19:51 2011 (+0100)
6  * Version: $Id$
7  * Last-Updated: Wed Mar 16 17:38:31 2011 (+0100)
8  * By: Julien Wintz
9  * Update #: 31
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
23 
24 #include <axlCore/axlSphere.h>
26 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
27 #include <dtkCoreSupport/dtkAbstractProcess.h>
28 #include <dtkGuiSupport/dtkColorButton.h>
29 
30 #include <axlCore/axlDouble.h>
31 #include <axlCore/axlPoint.h>
32 #include <axlCore/axlDataDynamic.h>
34 
35 #include <QtGui>
36 
37 class axlInspectorToolCreatorSpherePrivate
38 {
39 public:
40  QSlider *sliderOpacity;
41  dtkColorButton *colorButton;
42  axlInspectorObjectController *controller;
43 
44  QDoubleSpinBox *spinBoxCoordonate_x;
45  QDoubleSpinBox *spinBoxCoordonate_y;
46  QDoubleSpinBox *spinBoxCoordonate_z;
47  QDoubleSpinBox *spinBoxRadius;
48 
49  QGroupBox *coordinates;
50  QLabel *messageToDisplay;
51 
52 };
53 
54 axlInspectorToolCreatorSphere::axlInspectorToolCreatorSphere(QWidget *parent) : axlInspectorToolCreator(parent), d(new axlInspectorToolCreatorSpherePrivate)
55 {
56  QVBoxLayout *layout = new QVBoxLayout(this);
57 
58  //OPACITY//
59  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
60 
61  QHBoxLayout *layoutOpacity = new QHBoxLayout;
62  layoutOpacity->addWidget(new QLabel("Opacity",this));
63  layoutOpacity->addWidget(d->sliderOpacity);
64  d->sliderOpacity->setMaximum(100);
65 
66  //COLOR//
67  d->colorButton = new dtkColorButton(this);
68 
69  QHBoxLayout *layoutColorButton = new QHBoxLayout;
70  layoutColorButton->addWidget(new QLabel("Color",this));
71  layoutColorButton->addWidget(d->colorButton);
72  d->colorButton->setColor(QColor("#a0a0a4"));
73 
74 
75  QVBoxLayout *layoutCoordonate = new QVBoxLayout();
76  QHBoxLayout *layoutCoordonate_x = new QHBoxLayout();
77  QHBoxLayout *layoutCoordonate_y = new QHBoxLayout();
78  QHBoxLayout *layoutCoordonate_z = new QHBoxLayout();
79  QHBoxLayout *layoutRadius = new QHBoxLayout();
80  QLabel *labelCoordonate_x = new QLabel("x",this);
81  QLabel *labelCoordonate_y = new QLabel("y",this);
82  QLabel *labelCoordonate_z = new QLabel("z",this);
83  QLabel *labelRadius = new QLabel("radius",this);
84  d->spinBoxCoordonate_x = new QDoubleSpinBox(this);
85  d->spinBoxCoordonate_y = new QDoubleSpinBox(this);
86  d->spinBoxCoordonate_z = new QDoubleSpinBox(this);
87  d->spinBoxRadius = new QDoubleSpinBox(this);
88 
89  d->spinBoxCoordonate_x->setValue(0.0);
90  d->spinBoxCoordonate_y->setValue(0.0);
91  d->spinBoxCoordonate_z->setValue(0.0);
92  d->spinBoxRadius->setValue(1.0);
93  d->spinBoxCoordonate_x->setSingleStep(0.1);
94  d->spinBoxCoordonate_y->setSingleStep(0.1);
95  d->spinBoxCoordonate_z->setSingleStep(0.1);
96  d->spinBoxRadius->setSingleStep(0.1);
97  d->spinBoxCoordonate_x->setRange(-1000, 1000);
98  d->spinBoxCoordonate_y->setRange(-1000, 1000);
99  d->spinBoxCoordonate_z->setRange(-1000, 1000);
100  layoutCoordonate_x->addWidget(labelCoordonate_x);
101  layoutCoordonate_x->addWidget(d->spinBoxCoordonate_x);
102  layoutCoordonate_y->addWidget(labelCoordonate_y);
103  layoutCoordonate_y->addWidget(d->spinBoxCoordonate_y);
104  layoutCoordonate_z->addWidget(labelCoordonate_z);
105  layoutCoordonate_z->addWidget(d->spinBoxCoordonate_z);
106  layoutRadius->addWidget(labelRadius);
107  layoutRadius->addWidget(d->spinBoxRadius);
108 
109  layoutCoordonate->addLayout(layoutCoordonate_x);
110  layoutCoordonate->addLayout(layoutCoordonate_y);
111  layoutCoordonate->addLayout(layoutCoordonate_z);
112 
113  d->coordinates = new QGroupBox(tr("Enter coordinates"),this);
114  d->coordinates->setLayout(layoutCoordonate);
115 
116  //message to display
117  d->messageToDisplay = new QLabel("",this);
118  axlSphereCreator *creator = new axlSphereCreator();
119  d->messageToDisplay->setText(creator->description());
120  delete creator;
121  d->messageToDisplay->setStyleSheet("color: #ff0000;");
122 
123  QPushButton *button = new QPushButton("Create", this);
124  connect(button, SIGNAL(clicked()), this, SLOT(run()));
125 
126  layout->addWidget(new QLabel("axlInspectorToolCreatorSphere", this));
127  // layout->addLayout(layoutCoordonate);
128  layout->addWidget(d->messageToDisplay);
129  layout->addWidget(d->coordinates);
130  layout->addLayout(layoutRadius);
131  layout->addLayout(layoutOpacity);
132  layout->addLayout(layoutColorButton);
133  layout->addWidget(button);
134  d->coordinates->hide();
135 }
136 
138 {
139  delete d;
140 
141  d = NULL;
142 }
143 
145 {
146  d->controller = controller;
147  if(d->controller->size() < 1){
148  d->messageToDisplay->hide();
149  d->coordinates->show();
150  }else{
151  d->coordinates->hide();
152  bool hasRigthType = false;
153  int nbRigthType = 0;
154  foreach(axlInspectorObjectManagerTreeItem *item, d->controller->items()){
155  if(dynamic_cast<axlPoint *>(d->controller->data(item)))
156  nbRigthType++;
157  else if(dynamic_cast<axlDataDynamic *>(d->controller->data(item)))
158  if(dynamic_cast<axlDataDynamic *>(d->controller->data(item))->outputs())
159  if(dynamic_cast<axlPoint *>(dynamic_cast<axlDataDynamic *>(d->controller->data(item))->outputs()))
160  nbRigthType++;
161  }
162 
163  if(nbRigthType > 0)
164  hasRigthType = true;
165  if(!hasRigthType){
166  d->messageToDisplay->hide();
167  d->coordinates->show();
168  }
169  }
170 }
171 
172 
173 QList<axlAbstractData *> axlInspectorToolCreatorSphere::returnInputsList(void){
174  QList<axlAbstractData *> list;
175  if(d->coordinates->isVisible()){
176  axlPoint *center = new axlPoint(d->spinBoxCoordonate_x->value(), d->spinBoxCoordonate_y->value(), d->spinBoxCoordonate_z->value());
177  axlDouble *radius = new axlDouble(d->spinBoxRadius->value());
178 
179  list << center << radius;
180  }
181  return list;
182 
183 }
184 
186 {
187 
188  if(!d->coordinates->isVisible()){
189  d->messageToDisplay->show();
190  axlSphereCreator *creator = new axlSphereCreator();
191  int nbPoints = 0;
192  if(d->controller->size()!=0){
193  foreach(axlInspectorObjectManagerTreeItem *item, d->controller->items()){
194 
195  if(item->text(2) == "Selected"|| item->text(2) == "Editable")
196  {
197  if(nbPoints < 2){
198  if(dynamic_cast<axlPoint *>(d->controller->data(item))) {
199  axlPoint *point = dynamic_cast<axlPoint *>(d->controller->data(item));
200  creator->setInput(point,nbPoints);
201  nbPoints++;
202  }
203  }else{
204  qDebug() << "To many inputs selected, only the two first points were used";
205  }
206  }
207 
208  }
209  }
210  if(nbPoints == 2){
211  creator->setParameter(d->spinBoxRadius->value());
212  creator->update();
213  axlSphere *sphere = dynamic_cast<axlSphere *>(creator->output());
214  sphere->setColor(d->colorButton->color());
215  double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
216  sphere->setOpacity(opacity);
217  emit dataInserted(sphere);
218 
219  }else {
220  //display the coordinates to be chosen for the extremal points
221  d->coordinates->show();
222  d->messageToDisplay->hide();
223  }
224  delete creator;
225  }else{
226  d->messageToDisplay->hide();
227  axlSphere *newSphere = new axlSphere(d->spinBoxCoordonate_x->value(), d->spinBoxCoordonate_y->value(), d->spinBoxCoordonate_z->value(), d->spinBoxRadius->value());
228 
229  newSphere->setColor(d->colorButton->color());
230  double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
231  newSphere->setOpacity(opacity);
232  emit dataInserted(newSphere);
233  }
234 }
235 
237 {
239 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
void setController(axlInspectorObjectController *controller)
virtual void setInput(dtkAbstractData *newData, int channel)
Class axlDouble defines a double.
Definition: axlDouble.h:29
virtual QString description(void) const
virtual void setParameter(double data)
virtual int update(void)
virtual dtkAbstractData * output(void)
Class axlSphere defines 3D spheres.
Definition: axlSphere.h:33
void setOpacity(const double &opacity)
axlInspectorToolInterface * createaxlInspectorToolCreatorSphere(void)
void dataInserted(axlAbstractData *data)
QList< axlAbstractData * > returnInputsList(void)
void setColor(double r, double g, double b)