Debian Codegraph @

src/App/PropertyGeo.h

raw
1 /***************************************************************************
2 * Copyright (c) 2002 Jürgen Riegel <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef APP_PROPERTYGEO_H
25 #define APP_PROPERTYGEO_H
26
27 #include <Base/BoundBox.h>
28 #include <Base/Matrix.h>
29 #include <Base/Placement.h>
30 #include <Base/Unit.h>
31 #include <Base/Vector3D.h>
32
33 #include "PropertyLinks.h"
34 #include <FCGlobal.h>
35
36
37 namespace Base
38 {
39 class Writer;
40 }
41
42 namespace Data
43 {
44 class ComplexGeoData;
45 }
46
47 namespace App
48 {
49 class Placement;
50
51
52 /** Vector properties
53 * This is the father of all properties handling Integers.
54 */
55 class AppExport PropertyVector: public Property
56 {
57 TYPESYSTEM_HEADER_WITH_OVERRIDE();
58
59 public:
60 /**
61 * A constructor.
62 * A more elaborate description of the constructor.
63 */
64 PropertyVector();
65
66 /**
67 * A destructor.
68 * A more elaborate description of the destructor.
69 */
70 ~PropertyVector() override;
71
72 /** Sets the property
73 */
74 void setValue(const Base::Vector3d& vec);
75 void setValue(double x, double y, double z);
76
77 /// Get valid paths for this property; used by auto completer
78 void getPaths(std::vector<ObjectIdentifier>& paths) const override;
79
80 /** This method returns a string representation of the property
81 */
82 const Base::Vector3d& getValue() const;
83 const char* getEditorName() const override
84 {
85 return "Gui::PropertyEditor::PropertyVectorItem";
86 }
87
88 PyObject* getPyObject() override;
89 void setPyObject(PyObject*) override;
90
91 void Save(Base::Writer& writer) const override;
92 void Restore(Base::XMLReader& reader) override;
93
94 Property* Copy() const override;
95 void Paste(const Property& from) override;
96
97 unsigned int getMemSize() const override
98 {
99 return sizeof(Base::Vector3d);
100 }
101
102 const boost::any getPathValue(const ObjectIdentifier& path) const override;
103
104 bool getPyPathValue(const ObjectIdentifier& path, Py::Object& res) const override;
105
106 virtual Base::Unit getUnit() const
107 {
108 return {};
109 }
110
111 bool isSame(const Property& other) const override
112 {
113 if (&other == this) {
114 return true;
115 }
116 return getTypeId() == other.getTypeId()
117 && getValue() == dynamic_cast<decltype(this)>(&other)->getValue();
118 }
119
120 private:
121 Base::Vector3d _cVec;
122 };
123
124
125 class AppExport PropertyVectorDistance: public PropertyVector
126 {
127 TYPESYSTEM_HEADER_WITH_OVERRIDE();
128
129 public:
130 /**
131 * A constructor.
132 * A more elaborate description of the constructor.
133 */
134 PropertyVectorDistance();
135
136 /**
137 * A destructor.
138 * A more elaborate description of the destructor.
139 */
140 ~PropertyVectorDistance() override;
141
142 Base::Unit getUnit() const override
143 {
144 return Base::Unit::Length;
145 }
146
147 const char* getEditorName() const override
148 {
149 return "Gui::PropertyEditor::PropertyVectorDistanceItem";
150 }
151 };
152
153 class AppExport PropertyPosition: public PropertyVector
154 {
155 TYPESYSTEM_HEADER_WITH_OVERRIDE();
156
157 public:
158 /**
159 * A constructor.
160 * A more elaborate description of the constructor.
161 */
162 PropertyPosition();
163
164 /**
165 * A destructor.
166 * A more elaborate description of the destructor.
167 */
168 ~PropertyPosition() override;
169
170 Base::Unit getUnit() const override
171 {
172 return Base::Unit::Length;
173 }
174
175 const char* getEditorName() const override
176 {
177 return "Gui::PropertyEditor::PropertyPositionItem";
178 }
179 };
180
181 class AppExport PropertyDirection: public PropertyVector
182 {
183 TYPESYSTEM_HEADER_WITH_OVERRIDE();
184
185 public:
186 /**
187 * A constructor.
188 * A more elaborate description of the constructor.
189 */
190 PropertyDirection();
191
192 /**
193 * A destructor.
194 * A more elaborate description of the destructor.
195 */
196 ~PropertyDirection() override;
197
198 Base::Unit getUnit() const override
199 {
200 return Base::Unit::Length;
201 }
202
203 const char* getEditorName() const override
204 {
205 return "Gui::PropertyEditor::PropertyDirectionItem";
206 }
207 };
208
209 class AppExport PropertyVectorList: public PropertyListsT<Base::Vector3d>
210 {
211 TYPESYSTEM_HEADER_WITH_OVERRIDE();
212
213 using inherited = PropertyListsT<Base::Vector3d>;
214
215 public:
216 /**
217 * A constructor.
218 * A more elaborate description of the constructor.
219 */
220 PropertyVectorList();
221
222 /**
223 * A destructor.
224 * A more elaborate description of the destructor.
225 */
226 ~PropertyVectorList() override;
227
228 void setValue(double x, double y, double z);
229 using inherited::setValue;
230
231 PyObject* getPyObject() override;
232
233 void Save(Base::Writer& writer) const override;
234 void Restore(Base::XMLReader& reader) override;
235
236 void SaveDocFile(Base::Writer& writer) const override;
237 void RestoreDocFile(Base::Reader& reader) override;
238
239 Property* Copy() const override;
240 void Paste(const Property& from) override;
241
242 unsigned int getMemSize() const override;
243 const char* getEditorName() const override
244 {
245 return "Gui::PropertyEditor::PropertyVectorListItem";
246 }
247
248 protected:
249 Base::Vector3d getPyValue(PyObject*) const override;
250 };
251
252 /// Property representing a 4x4 matrix
253 /*!
254 * Encapsulates a Base::Matrix4D in a Property
255 */
256 class AppExport PropertyMatrix: public Property
257 {
258 TYPESYSTEM_HEADER_WITH_OVERRIDE();
259
260 public:
261 /**
262 * A constructor.
263 * Initialises to an identity matrix
264 */
265 PropertyMatrix();
266
267 /**
268 * A destructor.
269 * A more elaborate description of the destructor.
270 */
271 ~PropertyMatrix() override;
272
273 /** Sets the property
274 */
275 void setValue(const Base::Matrix4D& mat);
276
277 /** This method returns a string representation of the property
278 */
279 const Base::Matrix4D& getValue() const;
280 const char* getEditorName() const override
281 {
282 return "Gui::PropertyEditor::PropertyMatrixItem";
283 }
284
285 PyObject* getPyObject() override;
286 void setPyObject(PyObject*) override;
287
288 void Save(Base::Writer& writer) const override;
289 void Restore(Base::XMLReader& reader) override;
290
291 Property* Copy() const override;
292 void Paste(const Property& from) override;
293
294 unsigned int getMemSize() const override
295 {
296 return sizeof(Base::Matrix4D);
297 }
298
299 bool isSame(const Property& other) const override
300 {
301 if (&other == this) {
302 return true;
303 }
304 return getTypeId() == other.getTypeId()
305 && getValue() == static_cast<decltype(this)>(&other)->getValue();
306 }
307
308 private:
309 Base::Matrix4D _cMat;
310 };
311
312 /// Property representing a placement
313 /*!
314 * Encapsulates a Base::Placement in a Property
315 */
316 class AppExport PropertyPlacement: public Property
317 {
318 TYPESYSTEM_HEADER_WITH_OVERRIDE();
319
320 public:
321 /**
322 * A constructor.
323 * A more elaborate description of the constructor.
324 */
325 PropertyPlacement();
326
327 /**
328 * A destructor.
329 * A more elaborate description of the destructor.
330 */
331 ~PropertyPlacement() override;
332
333 /** Sets the property
334 */
335 void setValue(const Base::Placement& pos);
336
337 /** Sets property only if changed
338 * @param pos: input placement
339 * @param tol: position tolerance
340 * @param atol: angular tolerance
341 */
342 bool setValueIfChanged(const Base::Placement& pos, double tol = 1e-7, double atol = 1e-12);
343
344 /** This method returns a string representation of the property
345 */
346 const Base::Placement& getValue() const;
347
348 /// Get valid paths for this property; used by auto completer
349 void getPaths(std::vector<ObjectIdentifier>& paths) const override;
350
351 void setPathValue(const ObjectIdentifier& path, const boost::any& value) override;
352
353 const boost::any getPathValue(const ObjectIdentifier& path) const override;
354
355 bool getPyPathValue(const ObjectIdentifier& path, Py::Object& res) const override;
356
357 const char* getEditorName() const override
358 {
359 return "Gui::PropertyEditor::PropertyPlacementItem";
360 }
361
362 PyObject* getPyObject() override;
363 void setPyObject(PyObject*) override;
364
365 void Save(Base::Writer& writer) const override;
366 void Restore(Base::XMLReader& reader) override;
367
368 Property* Copy() const override;
369 void Paste(const Property& from) override;
370
371 unsigned int getMemSize() const override
372 {
373 return sizeof(Base::Placement);
374 }
375
376 bool isSame(const Property& other) const override
377 {
378 if (&other == this) {
379 return true;
380 }
381 return getTypeId() == other.getTypeId()
382 && getValue() == static_cast<decltype(this)>(&other)->getValue();
383 }
384
385 static const Placement Null;
386
387 private:
388 Base::Placement _cPos;
389 };
390
391 /** the general Link Property
392 * Main Purpose of this property is to Link Objects and Features in a document.
393 */
394 class AppExport PropertyPlacementLink: public PropertyLink
395 {
396 TYPESYSTEM_HEADER_WITH_OVERRIDE();
397
398 public:
399 /**
400 * A constructor.
401 * A more elaborate description of the constructor.
402 */
403 PropertyPlacementLink();
404
405 /**
406 * A destructor.
407 * A more elaborate description of the destructor.
408 */
409 ~PropertyPlacementLink() override;
410
411 /** This method returns the linked DocumentObject
412 */
413 App::Placement* getPlacementObject() const;
414
415 Property* Copy() const override;
416 void Paste(const Property& from) override;
417 };
418
419
420 class AppExport PropertyPlacementList: public PropertyListsT<Base::Placement>
421 {
422 TYPESYSTEM_HEADER_WITH_OVERRIDE();
423
424 public:
425 /**
426 * A property that stores a list of placements
427 */
428 PropertyPlacementList();
429
430 ~PropertyPlacementList() override;
431
432 PyObject* getPyObject() override;
433
434 void Save(Base::Writer& writer) const override;
435 void Restore(Base::XMLReader& reader) override;
436
437 void SaveDocFile(Base::Writer& writer) const override;
438 void RestoreDocFile(Base::Reader& reader) override;
439
440 Property* Copy() const override;
441 void Paste(const Property& from) override;
442
443 unsigned int getMemSize() const override;
444
445 protected:
446 Base::Placement getPyValue(PyObject* item) const override;
447 };
448
449
450 /// Property representing a rotation
451 /*!
452 * Encapsulates a Base::Rotation in a Property
453 */
454 class AppExport PropertyRotation: public Property
455 {
456 TYPESYSTEM_HEADER_WITH_OVERRIDE();
457
458 public:
459 /**
460 * A constructor.
461 * A more elaborate description of the constructor.
462 */
463 PropertyRotation();
464
465 /**
466 * A destructor.
467 * A more elaborate description of the destructor.
468 */
469 ~PropertyRotation() override;
470
471 /** Sets the property
472 */
473 void setValue(const Base::Rotation& rot);
474
475 /** Sets property only if changed
476 * @param pos: input placement
477 * @param tol: position tolerance
478 * @param atol: angular tolerance
479 */
480 bool setValueIfChanged(const Base::Rotation& rot, double atol = 1e-12);
481
482 /** This method returns a string representation of the property
483 */
484 const Base::Rotation& getValue() const;
485
486 /// Get valid paths for this property; used by auto completer
487 void getPaths(std::vector<ObjectIdentifier>& paths) const override;
488
489 void setPathValue(const ObjectIdentifier& path, const boost::any& value) override;
490
491 const boost::any getPathValue(const ObjectIdentifier& path) const override;
492
493 bool getPyPathValue(const ObjectIdentifier& path, Py::Object& res) const override;
494
495 const char* getEditorName() const override
496 {
497 return "Gui::PropertyEditor::PropertyRotationItem";
498 }
499
500 PyObject* getPyObject() override;
501 void setPyObject(PyObject*) override;
502
503 void Save(Base::Writer& writer) const override;
504 void Restore(Base::XMLReader& reader) override;
505
506 Property* Copy() const override;
507 void Paste(const Property& from) override;
508
509 unsigned int getMemSize() const override
510 {
511 return sizeof(Base::Placement);
512 }
513
514 private:
515 Base::Rotation _rot;
516 };
517
518
519 /** The base class for all basic geometry properties.
520 * @author Werner Mayer
521 */
522 class AppExport PropertyGeometry: public App::Property
523 {
524 TYPESYSTEM_HEADER_WITH_OVERRIDE();
525
526 public:
527 PropertyGeometry();
528 ~PropertyGeometry() override;
529
530 /** @name Modification */
531 //@{
532 /// Set the placement of the geometry
533 virtual void setTransform(const Base::Matrix4D& rclTrf) = 0;
534 /// Get the placement of the geometry
535 virtual Base::Matrix4D getTransform() const = 0;
536 /// Applies a transformation on the real geometric data type
537 virtual void transformGeometry(const Base::Matrix4D& rclMat) = 0;
538 /// Retrieve bounding box information
539 virtual Base::BoundBox3d getBoundingBox() const = 0;
540 //@}
541 };
542
543 /** The base class for all complex data properties.
544 * @author Werner Mayer
545 */
546 class AppExport PropertyComplexGeoData: public App::PropertyGeometry
547 {
548 TYPESYSTEM_HEADER_WITH_OVERRIDE();
549
550 public:
551 PropertyComplexGeoData();
552 ~PropertyComplexGeoData() override;
553
554 /** @name Modification */
555 //@{
556 /// Applies a transformation on the real geometric data type
557 void transformGeometry(const Base::Matrix4D& rclMat) override = 0;
558 //@}
559
560 /** @name Getting basic geometric entities */
561 //@{
562 virtual const Data::ComplexGeoData* getComplexData() const = 0;
563 Base::BoundBox3d getBoundingBox() const override = 0;
564 //@}
565
566 /** Return the element map version
567 *
568 * @param persisted: if true, return the restored element map version. Or
569 * else, return the current element map version
570 */
571 virtual std::string getElementMapVersion(bool restored = false) const;
572
573 /// Return true to signal element map version change
574 virtual bool checkElementMapVersion(const char* ver) const;
575
576 void afterRestore() override;
577 };
578
579 } // namespace App
580
581
582 #endif // APP_PROPERTYGEO_H