Developer documentation | Axl-2.5.1

axlCylinder.cpp
Go to the documentation of this file.
1 /* axlCylinder.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Tue Nov 9 16:58:59 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Nov 9 17:09:38 2010 (+0100)
8  * By: Meriadeg Perrinel
9  * Update #: 19
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlCylinder.h"
21 
22 #include "axlPoint.h"
23 
24 #include <dtkCoreSupport/dtkGlobal.h>
25 
26 // /////////////////////////////////////////////////////////////////
27 // axlCylinderPrivate
28 // /////////////////////////////////////////////////////////////////
29 
30 class axlCylinderPrivate
31 {
32 public:
33  axlPoint *p1;
34  axlPoint *p2;
35  double radius;
36 
37 };
38 
39 // /////////////////////////////////////////////////////////////////
40 // axlCylinder implementation
41 // /////////////////////////////////////////////////////////////////
42 
44 
49 axlCylinder::axlCylinder(QObject *parent) : axlAbstractData(), d(new axlCylinderPrivate)
50 {
51  this->setObjectName(this->identifier());
52 
53  d->p1 = new axlPoint();
54  d->p2 = new axlPoint(1.0, 0.0, 0.0);
55  d->radius = 1.0;
56 }
57 
59 
64 axlCylinder::axlCylinder(axlPoint *p1, axlPoint *p2, double radius, QObject *parent) : axlAbstractData(), d(new axlCylinderPrivate)
65 {
66  this->setObjectName(this->identifier());
67 
68  d->p1 = new axlPoint(p1);
69  d->p2 = new axlPoint(p2);
70  d->radius = radius;
71 }
72 
74 
79 axlCylinder::axlCylinder(const axlPoint& p1, const axlPoint& p2, double radius, QObject *parent) : axlAbstractData(), d(new axlCylinderPrivate) {
80  this->setObjectName(this->identifier());
81 
82  d->p1 = new axlPoint(p1);
83  d->p2 = new axlPoint(p2);
84  d->radius = radius;
85 }
86 
88 
91 axlCylinder::axlCylinder(const axlCylinder& other) : axlAbstractData(), d(new axlCylinderPrivate)
92 {
93  this->setObjectName(this->identifier());
94  this->setParent(other.parent());
95  d->p1 = new axlPoint(other.d->p1);
96  d->p2 = new axlPoint(other.d->p2);
97  d->radius = other.radius();
98 }
99 
101 
105 {
106  if (d->p1)
107  {
108  delete(d->p1);
109  d->p1 = NULL;
110  }
111  if (d->p2)
112  {
113  delete(d->p2);
114  d->p2 = NULL;
115  }
116  delete d;
117  d = NULL;
118 }
119 
121 
125 {
126  *(d->p1) = *(other.d->p1);
127  *(d->p2) = *(other.d->p2);
128  d->radius = other.radius();
129 
130  return (*this);
131 }
132 
134 
138 {
139  return d->p1;
140 }
141 
143 
147 {
148  return d->p2;
149 }
150 
152 
155 double axlCylinder::radius(void) const
156 {
157  return d->radius;
158 }
159 
161 
164 double axlCylinder::length(void) const
165 {
166  return axlPoint::distance(d->p1, d->p2);
167 }
168 
169 
171 
174 void axlCylinder::setValues(axlPoint *p1, axlPoint *p2, double radius)
175 {
176  *(d->p1) = *p1;
177  *(d->p2) = *p2;
178  d->radius = radius;
179 
180  //this->touchGeometry();
181 
182 }
183 
185 
189 {
190  *(d->p1) = *p1;
191 
192  //this->touchGeometry();
193 }
194 
196 
200 {
201  d->p1->coordinates()[0] = p1[0];
202  d->p1->coordinates()[1] = p1[1];
203  d->p1->coordinates()[2] = p1[2];
204 }
205 
207 
211 {
212  d->p2->coordinates()[0] = p2[0];
213  d->p2->coordinates()[1] = p2[1];
214  d->p2->coordinates()[2] = p2[2];
215 }
216 
217 
219 
223 {
224  *(d->p2) = *p2;
225 
226  //this->touchGeometry();
227 }
228 
230 
233 void axlCylinder::setRadius(double radius)
234 {
235  d->radius = radius;
236 
237  this->touchGeometry();
238 }
239 
241 
244 void axlCylinder::setLength(double length)
245 {
246  double oldLength = this->length();
247  if(oldLength != 0)
248  {
249  (*d->p2) = *(d->p1) + (*(d->p2) - *(d->p1)) * (length/oldLength) ;
250  this->touchGeometry();
251  }
252  else
253  qDebug()<< "cylinder is not correctly defined length = 0.0";
254 }
255 
257  {
258  d->p1->setCoordinates(p1.x(),p1.y(),p1.z());
259  this->touchGeometry();
260  }
261 
263  {
264  d->p2->setCoordinates(p2.x(),p2.y(),p2.z());
265  this->touchGeometry();
266  }
267 
268  void axlCylinder::touchRadius(double radius)
269  {
270  d->radius = radius;
271  this->touchGeometry();
272  }
273 
274 // /////////////////////////////////////////////////////////////////
275 // Debug operators
276 // /////////////////////////////////////////////////////////////////
277 
278 QDebug operator<<(QDebug dbg, axlCylinder cylinder)
279 {
280  dbg.nospace() << cylinder.description();
281 
282  return dbg.space();
283 }
284 
285 QDebug operator<<(QDebug dbg, axlCylinder& cylinder)
286 {
287  dbg.nospace() << cylinder.description();
288 
289  return dbg.space();
290 }
291 
292 QDebug operator<<(QDebug dbg, axlCylinder *cylinder)
293 {
294  dbg.nospace() << cylinder->description();
295 
296  return dbg.space();
297 }
298 
299 QString axlCylinder::description(void) const
300 {
301  QString result = "axlCylinder";
302  result.append("\nfirstPoint : "+d->p1->description() + "\nsecondPoint : "+d->p2->description() + "\nradius : "+ QString::number(d->radius));
303  return result;
304 }
305 
306 QString axlCylinder::identifier(void) const
307 {
308  return "axlCylinder";
309 }
310 
311 //SLOT
313 {
314  *(d->p1) = *p1;
315 }
316 
318 {
319  *(d->p2) = *p2;
320 }
321 
322 void axlCylinder::onRadiusChanged(double radius)
323 {
324  d->radius = radius;
325 }
326 
327 
328 QVariantList axlCylinder::convertDataToQVariant(void) const{
329  QVariantList list;
330  QVariant id = QVariant::fromValue(identifier());
331  QVariant radius = QVariant::fromValue(d->radius);
332  QVariantList p1 = d->p1->convertDataToQVariant();
333  QVariantList p2 = d->p2->convertDataToQVariant();
334  list.append(id);
335  list.append(radius);
336  list.append(p1);
337  list.append(p2);
338  QVariant name = QVariant::fromValue(objectName());
339  return list;
340 
341 }
342 
343 int axlCylinder::convertQVariantToData(const QVariantList &data){
344  setRadius(data.at(1).toDouble());
345  QVariantList p1List;
346  p1List.append(data.at(2));
347  p1List.append(data.at(3));
348  p1List.append(data.at(4));
349  p1List.append(data.at(5));
350  p1List.append(data.at(6));
351  d->p1->convertQVariantToData(p1List);
352  QVariantList p2List;
353  p2List.append(data.at(7));
354  p2List.append(data.at(8));
355  p2List.append(data.at(9));
356  p2List.append(data.at(10));
357  p2List.append(data.at(11));
358  d->p2->convertQVariantToData(p2List);
359  setObjectName(data.last().toString());
360  return 1;
361 
362 }
363 
364 //to be registered to the data factory.
365 dtkAbstractData *createaxlCylinder(void)
366 {
367  return new axlCylinder;
368 }
369 
370 // /////////////////////////////////////////////////////////////////
371 // axlCylinder documentation
372 // /////////////////////////////////////////////////////////////////
373 
void touchGeometry(void)
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
dtkAbstractData * createaxlCylinder(void)
void setFirstPoint(axlPoint *p1)
Change first point of this cylinder.
void touchFirstPoint(axlPoint p1)
void onFirstPointChanged(axlPoint *p1)
void setRadius(double radius)
Change radius of this cylinder.
QVariantList convertDataToQVariant(void) const
Convert an axlAbstractData into a QVariantList that specifies all properties of the axlAbstractData...
axlPoint * secondPoint(void) const
Returns second point of the cylinder.
Class axlCylinder defines 3D cylinders.
Definition: axlCylinder.h:33
void setSecondPoint(axlPoint *p2)
Change second point of this cylinder.
int convertQVariantToData(const QVariantList &data)
Modify properties and geometry variables of the axlAbstractData. Return 1 if the modification was suc...
void setLength(double length)
Change length of this cylinder we considered then first point is the origin of the cylinder and we ch...
~axlCylinder(void)
Destroys the axel cylinder.
axlPoint * firstPoint(void) const
Returns first point of the cylinder.
void onSecondPointChanged(axlPoint *p2)
void touchSecondPoint(axlPoint p2)
double length(void) const
Returns length of the cylinder.
virtual QString description(void) const
QDebug operator<<(QDebug dbg, axlCylinder cylinder)
axlCylinder(QObject *parent=0)
Constructs a axel cylinder of with firstPoint and second point are NULL and 1.0 radius with parent pa...
Definition: axlCylinder.cpp:49
void onRadiusChanged(double radius)
void touchRadius(double radius)
double y
Definition: axlPoint.h:37
double z
Definition: axlPoint.h:38
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point.
Definition: axlPoint.cpp:459
axlCylinder & operator=(const axlCylinder &other)
Assigns other to this cylinder and returns a reference to this cylinder.
double radius
Definition: axlCylinder.h:37
double x
Definition: axlPoint.h:37
double radius(void) const
Returns radius of the cylinder.
void setValues(axlPoint *p1, axlPoint *p2, double radius)
Change first point and second point of this cylinder.
Class axlAbstractData defines an API for all type of axel data.
virtual QString identifier(void) const