30 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
31 #include <dtkCoreSupport/dtkAbstractProcess.h>
32 #include <dtkGuiSupport/dtkColorButton.h>
36 class axlInspectorToolCreatorCircleArcPrivate {
38 QSlider *sliderOpacity;
39 dtkColorButton *colorButton;
42 QDoubleSpinBox* coordinatePoint1_x;
43 QDoubleSpinBox* coordinatePoint1_y;
44 QDoubleSpinBox* coordinatePoint1_z;
46 QDoubleSpinBox* coordinatePoint2_x;
47 QDoubleSpinBox* coordinatePoint2_y;
48 QDoubleSpinBox* coordinatePoint2_z;
50 QDoubleSpinBox* coordinateCenter_x;
51 QDoubleSpinBox* coordinateCenter_y;
52 QDoubleSpinBox* coordinateCenter_z;
54 QDoubleSpinBox* coordinateNormal_x;
55 QDoubleSpinBox* coordinateNormal_y;
56 QDoubleSpinBox* coordinateNormal_z;
58 QLabel* coordinateNormalLabel_x;
59 QLabel* coordinateNormalLabel_y;
60 QLabel* coordinateNormalLabel_z;
62 QCheckBox* counterClockWiseCheckBox;
66 QLabel* linedUpMessage;
67 QLabel* centerModifiedMessage;
74 d->linedUpMessage =
new QLabel(
"Point1, Point2 and Center are lined up.\nPlease provide the normal of the plane\ncontaining the circle arc.");
75 d->linedUpMessage->setStyleSheet(
"color: #0000FF;");
76 d->linedUpMessage->setVisible(
false);
79 d->centerModifiedMessage =
new QLabel(
"Warning: your center has been modified\nto be on the mediatory of [Point1;Point2].");
80 d->centerModifiedMessage->setStyleSheet(
"color: #FF6600;");
81 d->centerModifiedMessage->setVisible(
false);
84 d->sliderOpacity =
new QSlider(Qt::Horizontal,
this);
86 QHBoxLayout *layoutOpacity =
new QHBoxLayout;
87 layoutOpacity->addWidget(
new QLabel(
"Opacity",
this));
88 layoutOpacity->addWidget(d->sliderOpacity);
89 d->sliderOpacity->setMaximum(100);
92 d->colorButton =
new dtkColorButton(
this);
94 QHBoxLayout *layoutColorButton =
new QHBoxLayout;
95 layoutColorButton->addWidget(
new QLabel(
"Color",
this));
96 layoutColorButton->addWidget(d->colorButton);
97 d->colorButton->setColor(QColor(
"#a0a0a4"));
100 d->coordinatePoint1_x =
new QDoubleSpinBox(
this);
101 d->coordinatePoint1_x->setRange(-1000, 1000);
102 d->coordinatePoint1_x->setValue(1.0);
103 d->coordinatePoint1_x->setSingleStep(0.1);
105 QHBoxLayout *layoutPoint1_x =
new QHBoxLayout;
106 layoutPoint1_x->addWidget(
new QLabel(
"X",
this));
107 layoutPoint1_x->addWidget(d->coordinatePoint1_x);
109 d->coordinatePoint1_y =
new QDoubleSpinBox(
this);
110 d->coordinatePoint1_y->setRange(-1000, 1000);
111 d->coordinatePoint1_y->setValue(0.0);
112 d->coordinatePoint1_y->setSingleStep(0.1);
114 QHBoxLayout *layoutPoint1_y =
new QHBoxLayout;
115 layoutPoint1_y->addWidget(
new QLabel(
"Y",
this));
116 layoutPoint1_y->addWidget(d->coordinatePoint1_y);
118 d->coordinatePoint1_z =
new QDoubleSpinBox(
this);
119 d->coordinatePoint1_z->setRange(-1000, 1000);
120 d->coordinatePoint1_z->setValue(0.0);
121 d->coordinatePoint1_z->setSingleStep(0.1);
123 QHBoxLayout *layoutPoint1_z =
new QHBoxLayout;
124 layoutPoint1_z->addWidget(
new QLabel(
"Z",
this));
125 layoutPoint1_z->addWidget(d->coordinatePoint1_z);
127 QVBoxLayout *layoutPoint1 =
new QVBoxLayout;
129 layoutPoint1->addWidget(
new QLabel(
"Point1:",
this));
130 layoutPoint1->addLayout(layoutPoint1_x);
131 layoutPoint1->addLayout(layoutPoint1_y);
132 layoutPoint1->addLayout(layoutPoint1_z);
135 d->coordinatePoint2_x =
new QDoubleSpinBox(
this);
136 d->coordinatePoint2_x->setRange(-1000, 1000);
137 d->coordinatePoint2_x->setValue(0.0);
138 d->coordinatePoint2_x->setSingleStep(0.1);
140 QHBoxLayout *layoutPoint2_x =
new QHBoxLayout;
141 layoutPoint2_x->addWidget(
new QLabel(
"X",
this));
142 layoutPoint2_x->addWidget(d->coordinatePoint2_x);
144 d->coordinatePoint2_y =
new QDoubleSpinBox(
this);
145 d->coordinatePoint2_y->setRange(-1000, 1000);
146 d->coordinatePoint2_y->setValue(1.0);
147 d->coordinatePoint2_y->setSingleStep(0.1);
149 QHBoxLayout *layoutPoint2_y =
new QHBoxLayout;
150 layoutPoint2_y->addWidget(
new QLabel(
"Y",
this));
151 layoutPoint2_y->addWidget(d->coordinatePoint2_y);
153 d->coordinatePoint2_z =
new QDoubleSpinBox(
this);
154 d->coordinatePoint2_z->setRange(-1000, 1000);
155 d->coordinatePoint2_z->setValue(0.0);
156 d->coordinatePoint2_z->setSingleStep(0.1);
158 QHBoxLayout *layoutPoint2_z =
new QHBoxLayout;
159 layoutPoint2_z->addWidget(
new QLabel(
"Z",
this));
160 layoutPoint2_z->addWidget(d->coordinatePoint2_z);
162 QVBoxLayout *layoutPoint2 =
new QVBoxLayout;
164 layoutPoint2->addWidget(
new QLabel(
"Point2:",
this));
165 layoutPoint2->addLayout(layoutPoint2_x);
166 layoutPoint2->addLayout(layoutPoint2_y);
167 layoutPoint2->addLayout(layoutPoint2_z);
170 d->coordinateCenter_x =
new QDoubleSpinBox(
this);
171 d->coordinateCenter_x->setRange(-1000, 1000);
172 d->coordinateCenter_x->setValue(0.0);
173 d->coordinateCenter_x->setSingleStep(0.1);
175 QHBoxLayout *layoutCenter_x =
new QHBoxLayout;
176 layoutCenter_x->addWidget(
new QLabel(
"X",
this));
177 layoutCenter_x->addWidget(d->coordinateCenter_x);
179 d->coordinateCenter_y =
new QDoubleSpinBox(
this);
180 d->coordinateCenter_y->setRange(-1000, 1000);
181 d->coordinateCenter_y->setValue(0.0);
182 d->coordinateCenter_y->setSingleStep(0.1);
184 QHBoxLayout *layoutCenter_y =
new QHBoxLayout;
185 layoutCenter_y->addWidget(
new QLabel(
"Y",
this));
186 layoutCenter_y->addWidget(d->coordinateCenter_y);
188 d->coordinateCenter_z =
new QDoubleSpinBox(
this);
189 d->coordinateCenter_z->setRange(-1000, 1000);
190 d->coordinateCenter_z->setValue(0.0);
191 d->coordinateCenter_z->setSingleStep(0.1);
193 QHBoxLayout *layoutCenter_z =
new QHBoxLayout;
194 layoutCenter_z->addWidget(
new QLabel(
"Z",
this));
195 layoutCenter_z->addWidget(d->coordinateCenter_z);
197 QVBoxLayout *layoutCenter =
new QVBoxLayout;
199 layoutCenter->addWidget(
new QLabel(
"Center:",
this));
200 layoutCenter->addLayout(layoutCenter_x);
201 layoutCenter->addLayout(layoutCenter_y);
202 layoutCenter->addLayout(layoutCenter_z);
205 d->radiusLabel =
new QLabel(
"1.0");
207 QHBoxLayout *layoutRadius =
new QHBoxLayout;
208 layoutRadius->addWidget(
new QLabel(
"Radius",
this));
209 layoutRadius->addWidget(d->radiusLabel);
212 d->coordinateNormal_x =
new QDoubleSpinBox(
this);
213 d->coordinateNormal_x->setRange(-1000, 1000);
214 d->coordinateNormal_x->setValue(0.0);
215 d->coordinateNormal_x->setSingleStep(0.1);
217 d->coordinateNormalLabel_x =
new QLabel(
"0.0");
219 QHBoxLayout *layoutNormal_x =
new QHBoxLayout;
220 layoutNormal_x->addWidget(
new QLabel(
"X",
this));
221 layoutNormal_x->addWidget(d->coordinateNormalLabel_x);
222 layoutNormal_x->addWidget(d->coordinateNormal_x);
224 d->coordinateNormal_y =
new QDoubleSpinBox(
this);
225 d->coordinateNormal_y->setRange(-1000, 1000);
226 d->coordinateNormal_y->setValue(0.0);
227 d->coordinateNormal_y->setSingleStep(0.1);
229 d->coordinateNormalLabel_y =
new QLabel(
"0.0");
231 QHBoxLayout *layoutNormal_y =
new QHBoxLayout;
232 layoutNormal_y->addWidget(
new QLabel(
"Y",
this));
233 layoutNormal_y->addWidget(d->coordinateNormalLabel_y);
234 layoutNormal_y->addWidget(d->coordinateNormal_y);
236 d->coordinateNormal_z =
new QDoubleSpinBox(
this);
237 d->coordinateNormal_z->setRange(-1000, 1000);
238 d->coordinateNormal_z->setValue(1.0);
239 d->coordinateNormal_z->setSingleStep(0.1);
241 d->coordinateNormalLabel_z =
new QLabel(
"1.0");
243 QHBoxLayout *layoutNormal_z =
new QHBoxLayout;
244 layoutNormal_z->addWidget(
new QLabel(
"Z",
this));
245 layoutNormal_z->addWidget(d->coordinateNormalLabel_z);
246 layoutNormal_z->addWidget(d->coordinateNormal_z);
248 QVBoxLayout *layoutNormal =
new QVBoxLayout;
250 layoutNormal->addWidget(
new QLabel(
"Normal:",
this));
251 layoutNormal->addWidget(d->linedUpMessage);
252 layoutNormal->addLayout(layoutNormal_x);
253 layoutNormal->addLayout(layoutNormal_y);
254 layoutNormal->addLayout(layoutNormal_z);
256 d->coordinateNormal_x->setVisible(
false);
257 d->coordinateNormal_y->setVisible(
false);
258 d->coordinateNormal_z->setVisible(
false);
261 d->counterClockWiseCheckBox =
new QCheckBox(
"Counter Clock Wise",
this);
262 d->counterClockWiseCheckBox->setChecked(
true);
265 QPushButton *button =
new QPushButton(
"Create",
this);
266 connect(button, SIGNAL(clicked()),
this, SLOT(
run()));
269 QVBoxLayout *layout =
new QVBoxLayout(
this);
271 layout->addWidget(
new QLabel(
"axlInspectorToolCreatorCircleArc",
this));
272 layout->addLayout(layoutPoint1);
273 layout->addLayout(layoutPoint2);
274 layout->addLayout(layoutCenter);
275 layout->addLayout(layoutRadius);
276 layout->addLayout(layoutNormal);
277 layout->addWidget(d->counterClockWiseCheckBox);
278 layout->addLayout(layoutOpacity);
279 layout->addLayout(layoutColorButton);
280 layout->addWidget(d->centerModifiedMessage);
281 layout->addWidget(button);
283 connect(d->coordinatePoint1_x, SIGNAL(valueChanged(
double)),
this, SLOT(
manageNormal(
double)));
284 connect(d->coordinatePoint1_y, SIGNAL(valueChanged(
double)),
this, SLOT(
manageNormal(
double)));
285 connect(d->coordinatePoint1_z, SIGNAL(valueChanged(
double)),
this, SLOT(
manageNormal(
double)));
287 connect(d->coordinatePoint1_x, SIGNAL(valueChanged(
double)),
this, SLOT(
manageCenter(
double)));
288 connect(d->coordinatePoint1_y, SIGNAL(valueChanged(
double)),
this, SLOT(
manageCenter(
double)));
289 connect(d->coordinatePoint1_z, SIGNAL(valueChanged(
double)),
this, SLOT(
manageCenter(
double)));
291 connect(d->coordinatePoint2_x, SIGNAL(valueChanged(
double)),
this, SLOT(
manageNormal(
double)));
292 connect(d->coordinatePoint2_y, SIGNAL(valueChanged(
double)),
this, SLOT(
manageNormal(
double)));
293 connect(d->coordinatePoint2_z, SIGNAL(valueChanged(
double)),
this, SLOT(
manageNormal(
double)));
295 connect(d->coordinatePoint2_x, SIGNAL(valueChanged(
double)),
this, SLOT(
manageCenter(
double)));
296 connect(d->coordinatePoint2_y, SIGNAL(valueChanged(
double)),
this, SLOT(
manageCenter(
double)));
297 connect(d->coordinatePoint2_z, SIGNAL(valueChanged(
double)),
this, SLOT(
manageCenter(
double)));
299 connect(d->coordinateCenter_x, SIGNAL(valueChanged(
double)),
this, SLOT(
manageNormal(
double)));
300 connect(d->coordinateCenter_y, SIGNAL(valueChanged(
double)),
this, SLOT(
manageNormal(
double)));
301 connect(d->coordinateCenter_z, SIGNAL(valueChanged(
double)),
this, SLOT(
manageNormal(
double)));
303 connect(d->counterClockWiseCheckBox, SIGNAL(clicked()),
this, SLOT(
inverseNormal()));
336 QList<axlAbstractData *> list;
337 bool condition =
true;
339 axlPoint *newCenter =
new axlPoint(d->coordinateCenter_x->value(), d->coordinateCenter_y->value(), d->coordinateCenter_z->value());
340 axlPoint *point1 =
new axlPoint(d->coordinatePoint1_x->value(), d->coordinatePoint1_y->value(), d->coordinatePoint1_z->value());
341 axlPoint *point2 =
new axlPoint(d->coordinatePoint2_x->value(), d->coordinatePoint2_y->value(), d->coordinatePoint2_z->value());
342 axlPoint *normal =
new axlPoint(d->coordinateNormal_x->value(), d->coordinateNormal_y->value(), d->coordinateNormal_z->value());
345 list << newCenter << point1 << point2 << normal << direct;
353 axlPoint p1(d->coordinatePoint1_x->text().toDouble(), d->coordinatePoint1_y->text().toDouble(), d->coordinatePoint1_z->text().toDouble());
354 axlPoint p2(d->coordinatePoint2_x->text().toDouble(), d->coordinatePoint2_y->text().toDouble(), d->coordinatePoint2_z->text().toDouble());
355 axlPoint c(d->coordinateCenter_x->text().toDouble(), d->coordinateCenter_y->text().toDouble(), d->coordinateCenter_z->text().toDouble());
360 bool linedUpPoints = calculatedNormal.
norm() < 0.001;
362 d->coordinateNormal_x->setVisible(linedUpPoints);
364 d->coordinateNormalLabel_x->setVisible(!linedUpPoints);
365 d->coordinateNormalLabel_x->setText(QString(
"%1").arg(calculatedNormal.
x()));
367 d->coordinateNormal_y->setVisible(linedUpPoints);
369 d->coordinateNormalLabel_y->setVisible(!linedUpPoints);
370 d->coordinateNormalLabel_y->setText(QString(
"%1").arg(calculatedNormal.
y()));
372 d->coordinateNormal_z->setVisible(linedUpPoints);
374 d->coordinateNormalLabel_z->setVisible(!linedUpPoints);
375 d->coordinateNormalLabel_z->setText(QString(
"%1").arg(calculatedNormal.
z()));
377 d->linedUpMessage->setVisible(linedUpPoints);
381 axlPoint p1(d->coordinatePoint1_x->text().toDouble(), d->coordinatePoint1_y->text().toDouble(), d->coordinatePoint1_z->text().toDouble());
382 axlPoint p2(d->coordinatePoint2_x->text().toDouble(), d->coordinatePoint2_y->text().toDouble(), d->coordinatePoint2_z->text().toDouble());
383 axlPoint c(d->coordinateCenter_x->text().toDouble(), d->coordinateCenter_y->text().toDouble(), d->coordinateCenter_z->text().toDouble());
386 calculatedNormal =
axlPoint(d->coordinateNormal_x->value(), d->coordinateNormal_y->value(), d->coordinateNormal_z->value());
392 axlPoint newCenter = middle+mediatory*ps;
394 d->coordinateCenter_x->setValue(newCenter.
x());
395 d->coordinateCenter_y->setValue(newCenter.
y());
396 d->coordinateCenter_z->setValue(newCenter.
z());
400 d->coordinateNormal_x->setValue(-d->coordinateNormal_x->value());
401 d->coordinateNormal_y->setValue(-d->coordinateNormal_y->value());
402 d->coordinateNormal_z->setValue(-d->coordinateNormal_z->value());
404 d->coordinateNormalLabel_x->setText(QString(
"%1").arg(-d->coordinateNormalLabel_x->text().toDouble()));
405 d->coordinateNormalLabel_y->setText(QString(
"%1").arg(-d->coordinateNormalLabel_y->text().toDouble()));
406 d->coordinateNormalLabel_z->setText(QString(
"%1").arg(-d->coordinateNormalLabel_z->text().toDouble()));
410 axlPoint oldCenter(d->coordinateCenter_x->value(), d->coordinateCenter_y->value(), d->coordinateCenter_z->value());
412 axlPoint newCenter(d->coordinateCenter_x->value(), d->coordinateCenter_y->value(), d->coordinateCenter_z->value());
414 d->centerModifiedMessage->setVisible(
axlPoint::distance(oldCenter, newCenter) > 0.01);
416 axlPoint point1(d->coordinatePoint1_x->value(), d->coordinatePoint1_y->value(), d->coordinatePoint1_z->value());
417 axlPoint point2(d->coordinatePoint2_x->value(), d->coordinatePoint2_y->value(), d->coordinatePoint2_z->value());
418 axlPoint normal(d->coordinateNormal_x->value(), d->coordinateNormal_y->value(), d->coordinateNormal_z->value());
420 axlCircleArc* newArc =
new axlCircleArc(point1, point2, newCenter, normal, d->counterClockWiseCheckBox->isChecked());
421 newArc->
setColor(d->colorButton->color());
422 double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
423 newArc->setOpacity(opacity);
Class axlPoint defines 3D points.
axlPoint & normalized(void)
static double dotProduct(const axlPoint &lhs, const axlPoint &rhs)
Class axlInteger defines an integer.
static axlPoint crossProduct(const axlPoint &lhs, const axlPoint &rhs)
Returns the cross product between lhs (coords) and rhs (coords).
void setColor(double r, double g, double b)
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point.