Debian Codegraph @

src/App/PropertyStandard.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_PROPERTYSTANDARD_H
25 #define APP_PROPERTYSTANDARD_H
26
27 #include <list>
28 #include <memory>
29 #include <string>
30 #include <vector>
31 #include <boost/dynamic_bitset.hpp>
32 #include <Base/Uuid.h>
33
34 #include "Property.h"
35 #include "Enumeration.h"
36 #include "Material.h"
37
38
39 namespace Base
40 {
41 class InputStream;
42 class OutputStream;
43 class Writer;
44 } // namespace Base
45
46
47 namespace App
48 {
49
50 /** Integer properties
51 * This is the father of all properties handling Integers.
52 */
53 class AppExport PropertyInteger: public Property
54 {
55 TYPESYSTEM_HEADER_WITH_OVERRIDE();
56
57 public:
58 PropertyInteger();
59 ~PropertyInteger() override;
60
61 /** Sets the property
62 */
63 void setValue(long);
64
65 /** This method returns a string representation of the property
66 */
67 long getValue() const;
68 const char* getEditorName() const override
69 {
70 return "Gui::PropertyEditor::PropertyIntegerItem";
71 }
72
73 PyObject* getPyObject() override;
74 void setPyObject(PyObject* py) override;
75
76 void Save(Base::Writer& writer) const override;
77 void Restore(Base::XMLReader& reader) override;
78
79 Property* Copy() const override;
80 void Paste(const Property& from) override;
81
82 unsigned int getMemSize() const override
83 {
84 return sizeof(long);
85 }
86
87 void setPathValue(const App::ObjectIdentifier& path, const boost::any& value) override;
88 const boost::any getPathValue(const App::ObjectIdentifier& /*path*/) const override
89 {
90 return _lValue;
91 }
92
93 bool isSame(const Property& other) const override
94 {
95 if (&other == this) {
96 return true;
97 }
98 return getTypeId() == other.getTypeId()
99 && getValue() == static_cast<decltype(this)>(&other)->getValue();
100 }
101
102 protected:
103 long _lValue;
104 };
105
106 /** Path properties
107 * Properties handling file system paths.
108 */
109 class AppExport PropertyPath: public Property
110 {
111 TYPESYSTEM_HEADER_WITH_OVERRIDE();
112
113 public:
114 PropertyPath();
115 ~PropertyPath() override;
116
117 /** Sets the property
118 */
119 void setValue(const std::filesystem::path&);
120
121 /** Sets the property
122 */
123 void setValue(const char*);
124
125 /** This method returns a string representation of the property
126 */
127 const std::filesystem::path& getValue() const;
128
129 const char* getEditorName() const override
130 {
131 return "Gui::PropertyEditor::PropertyPathItem";
132 }
133
134 PyObject* getPyObject() override;
135 void setPyObject(PyObject* py) override;
136
137 void Save(Base::Writer& writer) const override;
138 void Restore(Base::XMLReader& reader) override;
139
140 Property* Copy() const override;
141 void Paste(const Property& from) override;
142
143 unsigned int getMemSize() const override;
144
145 bool isSame(const Property& other) const override
146 {
147 if (&other == this) {
148 return true;
149 }
150 return getTypeId() == other.getTypeId()
151 && getValue() == static_cast<decltype(this)>(&other)->getValue();
152 }
153
154 protected:
155 std::filesystem::path _cValue;
156 };
157
158 /// Property wrapper around an Enumeration object.
159 class AppExport PropertyEnumeration: public Property
160 {
161 TYPESYSTEM_HEADER_WITH_OVERRIDE();
162
163 public:
164 /// Standard constructor
165 PropertyEnumeration();
166
167 /// Obvious constructor
168 explicit PropertyEnumeration(const Enumeration& e);
169
170 /// destructor
171 ~PropertyEnumeration() override;
172
173 /// Enumeration methods
174 /*!
175 * These all function as per documentation in Enumeration
176 */
177 //@{
178 /** setting the enumeration string list
179 * The list is a NULL terminated array of pointers to a const char* string
180 * \code
181 * const char enums[] = {"Black","White","Other",NULL}
182 * \endcode
183 */
184 void setEnums(const char** plEnums);
185
186 /** setting the enumeration string as vector of strings
187 * This makes the enumeration custom.
188 */
189 void setEnums(const std::vector<std::string>& Enums);
190
191 /** set the enum by a string
192 * is slower than setValue(long). Use long if possible
193 */
194 void setValue(const char* value);
195
196 /** set directly the enum value
197 * In DEBUG checks for boundaries.
198 * Is faster than using setValue(const char*).
199 */
200 void setValue(long);
201
202 /// Setter using Enumeration
203 void setValue(const Enumeration& source);
204
205 /// Returns current value of the enumeration as an integer
206 long getValue() const;
207
208 /// checks if the property is set to a certain string value
209 bool isValue(const char* value) const;
210
211 /// checks if a string is included in the enumeration
212 bool isPartOf(const char* value) const;
213
214 /// get the value as string
215 const char* getValueAsString() const;
216
217 /// Returns Enumeration object
218 const Enumeration& getEnum() const;
219
220 /// get all possible enum values as vector of strings
221 std::vector<std::string> getEnumVector() const;
222
223 /// set enum values as vector of strings
224 void setEnumVector(const std::vector<std::string>&);
225 /// get the pointer to the enum list
226 bool hasEnums() const;
227
228 /// Returns true if the instance is in a usable state
229 bool isValid() const;
230 //@}
231
232 const char* getEditorName() const override
233 {
234 return _editorTypeName.c_str();
235 }
236 void setEditorName(const char* name)
237 {
238 _editorTypeName = name;
239 }
240
241 PyObject* getPyObject() override;
242 void setPyObject(PyObject* py) override;
243
244 void Save(Base::Writer& writer) const override;
245 void Restore(Base::XMLReader& reader) override;
246
247 Property* Copy() const override;
248 void Paste(const Property& from) override;
249
250 void setPathValue(const App::ObjectIdentifier& path, const boost::any& value) override;
251 virtual bool setPyPathValue(const App::ObjectIdentifier& path, const Py::Object& value);
252 const boost::any getPathValue(const App::ObjectIdentifier& /*path*/) const override;
253 bool getPyPathValue(const ObjectIdentifier& path, Py::Object& r) const override;
254
255 bool isSame(const Property& other) const override
256 {
257 if (&other == this) {
258 return true;
259 }
260 return getTypeId() == other.getTypeId()
261 && getEnum() == static_cast<decltype(this)>(&other)->getEnum();
262 }
263
264 private:
265 Enumeration _enum;
266 std::string _editorTypeName;
267 };
268
269 /** Constraint integer properties
270 * This property fulfills the need of a constraint integer. It holds basically a
271 * state (integer) and a struct of boundaries. If the boundaries
272 * is not set it acts basically like an IntegerProperty and does no checking.
273 * The constraints struct can be created on the heap or build in.
274 */
275 class AppExport PropertyIntegerConstraint: public PropertyInteger
276 {
277 TYPESYSTEM_HEADER_WITH_OVERRIDE();
278
279 public:
280 /// Standard constructor
281 PropertyIntegerConstraint();
282
283 /// destructor
284 ~PropertyIntegerConstraint() override;
285
286 /// Constraint methods
287 //@{
288 /// the boundary struct
289 struct Constraints
290 {
291 long LowerBound, UpperBound, StepSize;
292 Constraints()
293 : LowerBound(0)
294 , UpperBound(0)
295 , StepSize(0)
296 , candelete(false)
297 {}
298 Constraints(long l, long u, long s)
299 : LowerBound(l)
300 , UpperBound(u)
301 , StepSize(s)
302 , candelete(false)
303 {}
304 ~Constraints() = default;
305 void setDeletable(bool on)
306 {
307 candelete = on;
308 }
309 bool isDeletable() const
310 {
311 return candelete;
312 }
313
314 private:
315 bool candelete;
316 };
317 /** setting the boundaries
318 * This sets the constraint struct. It can be dynamically
319 * allocated or set as a static in the class the property
320 * belongs to:
321 * \code
322 * const Constraints percent = {0,100,1}
323 * \endcode
324 */
325 void setConstraints(const Constraints* sConstraint);
326 /// get the constraint struct
327 const Constraints* getConstraints() const;
328 //@}
329
330 long getMinimum() const;
331 long getMaximum() const;
332 long getStepSize() const;
333
334 const char* getEditorName() const override
335 {
336 return "Gui::PropertyEditor::PropertyIntegerConstraintItem";
337 }
338 void setPyObject(PyObject* py) override;
339
340 protected:
341 const Constraints* _ConstStruct {nullptr};
342 };
343
344 /** Percent property
345 * This property is a special integer property and holds only
346 * numbers between 0 and 100.
347 */
348
349 class AppExport PropertyPercent: public PropertyIntegerConstraint
350 {
351 TYPESYSTEM_HEADER_WITH_OVERRIDE();
352
353 public:
354 /// Standard constructor
355 PropertyPercent();
356
357 /// destructor
358 ~PropertyPercent() override;
359 };
360
361 /** Integer list properties
362 *
363 */
364 class AppExport PropertyIntegerList: public PropertyListsT<long>
365 {
366 TYPESYSTEM_HEADER_WITH_OVERRIDE();
367
368 public:
369 /**
370
371 * A constructor.
372 * A more elaborate description of the constructor.
373 */
374 PropertyIntegerList();
375
376 /**
377 * A destructor.
378 * A more elaborate description of the destructor.
379 */
380 ~PropertyIntegerList() override;
381
382 const char* getEditorName() const override
383 {
384 return "Gui::PropertyEditor::PropertyIntegerListItem";
385 }
386
387 PyObject* getPyObject() override;
388
389 void Save(Base::Writer& writer) const override;
390 void Restore(Base::XMLReader& reader) override;
391
392 Property* Copy() const override;
393 void Paste(const Property& from) override;
394 unsigned int getMemSize() const override;
395
396 protected:
397 long getPyValue(PyObject* item) const override;
398 };
399
400 /** Integer list properties
401 *
402 */
403 class AppExport PropertyIntegerSet: public Property
404 {
405 TYPESYSTEM_HEADER_WITH_OVERRIDE();
406
407 public:
408 /**
409
410 * A constructor.
411 * A more elaborate description of the constructor.
412 */
413 PropertyIntegerSet();
414
415 /**
416 * A destructor.
417 * A more elaborate description of the destructor.
418 */
419 ~PropertyIntegerSet() override;
420
421 /** Sets the property
422 */
423 void setValue(long);
424 void setValue()
425 {
426 ;
427 }
428
429 void addValue(long value)
430 {
431 _lValueSet.insert(value);
432 }
433 void setValues(const std::set<long>& values);
434
435 const std::set<long>& getValues() const
436 {
437 return _lValueSet;
438 }
439
440 PyObject* getPyObject() override;
441 void setPyObject(PyObject* py) override;
442
443 void Save(Base::Writer& writer) const override;
444 void Restore(Base::XMLReader& reader) override;
445
446 Property* Copy() const override;
447 void Paste(const Property& from) override;
448 unsigned int getMemSize() const override;
449
450 bool isSame(const Property& other) const override
451 {
452 if (&other == this) {
453 return true;
454 }
455 return getTypeId() == other.getTypeId()
456 && getValues() == static_cast<decltype(this)>(&other)->getValues();
457 }
458
459 private:
460 std::set<long> _lValueSet;
461 };
462
463
464 /** implements a key/value list as property
465 * The key ought to be ASCII the Value should be treated as UTF8 to be saved.
466 */
467 class AppExport PropertyMap: public Property
468 {
469 TYPESYSTEM_HEADER_WITH_OVERRIDE();
470
471 public:
472 /**
473 * A constructor.
474 * A more elaborate description of the constructor.
475 */
476 PropertyMap();
477
478 /**
479 * A destructor.
480 * A more elaborate description of the destructor.
481 */
482 ~PropertyMap() override;
483
484 virtual int getSize() const;
485
486 /** Sets the property
487 */
488 void setValue()
489 {}
490 void setValue(const std::string& key, const std::string& value);
491 void setValues(const std::map<std::string, std::string>&);
492
493 /// index operator
494 const std::string& operator[](const std::string& key) const;
495
496 void set1Value(const std::string& key, const std::string& value)
497 {
498 _lValueList.operator[](key) = value;
499 }
500
501 const std::map<std::string, std::string>& getValues() const
502 {
503 return _lValueList;
504 }
505
506 // virtual const char* getEditorName(void) const { return
507 // "Gui::PropertyEditor::PropertyStringListItem"; }
508
509 PyObject* getPyObject() override;
510 void setPyObject(PyObject* py) override;
511
512 void Save(Base::Writer& writer) const override;
513 void Restore(Base::XMLReader& reader) override;
514
515 Property* Copy() const override;
516 void Paste(const Property& from) override;
517
518 unsigned int getMemSize() const override;
519
520 bool isSame(const Property& other) const override
521 {
522 if (&other == this) {
523 return true;
524 }
525 return getTypeId() == other.getTypeId()
526 && getValues() == static_cast<decltype(this)>(&other)->getValues();
527 }
528
529 private:
530 std::map<std::string, std::string> _lValueList;
531 };
532
533
534 /** Float properties
535 * This is the father of all properties handling floats.
536 * Use this type only in rare cases. Mostly you want to
537 * use the more specialized types like e.g. PropertyLength.
538 * These properties also fulfill the needs of the unit system.
539 * See PropertyUnits.h for all properties with units.
540 */
541 class AppExport PropertyFloat: public Property
542 {
543 TYPESYSTEM_HEADER_WITH_OVERRIDE();
544
545 public:
546 /** Value Constructor
547 * Construct with explicit Values
548 */
549 PropertyFloat();
550
551 /**
552 * A destructor.
553 * A more elaborate description of the destructor.
554 */
555 ~PropertyFloat() override;
556
557
558 void setValue(double lValue);
559 double getValue() const;
560
561 const char* getEditorName() const override
562 {
563 return "Gui::PropertyEditor::PropertyFloatItem";
564 }
565
566 PyObject* getPyObject() override;
567 void setPyObject(PyObject* py) override;
568
569 void Save(Base::Writer& writer) const override;
570 void Restore(Base::XMLReader& reader) override;
571
572 Property* Copy() const override;
573 void Paste(const Property& from) override;
574
575 unsigned int getMemSize() const override
576 {
577 return sizeof(double);
578 }
579
580 void setPathValue(const App::ObjectIdentifier& path, const boost::any& value) override;
581 const boost::any getPathValue(const App::ObjectIdentifier& path) const override;
582
583 bool isSame(const Property& other) const override
584 {
585 if (&other == this) {
586 return true;
587 }
588 return getTypeId() == other.getTypeId()
589 && getValue() == static_cast<decltype(this)>(&other)->getValue();
590 }
591
592 protected:
593 double _dValue;
594 };
595
596 /** Constraint float properties
597 * This property fulfills the need of a constraint float. It holds basically a
598 * state (float) and a struct of boundaries. If the boundaries
599 * is not set it acts basically like a PropertyFloat and does no checking
600 * The constraints struct can be created on the heap or built-in.
601 */
602 class AppExport PropertyFloatConstraint: public PropertyFloat
603 {
604 TYPESYSTEM_HEADER_WITH_OVERRIDE();
605
606 public:
607 /** Value Constructor
608 * Construct with explicit Values
609 */
610 PropertyFloatConstraint();
611
612 /**
613 * A destructor.
614 * A more elaborate description of the destructor.
615 */
616 ~PropertyFloatConstraint() override;
617
618
619 /// Constraint methods
620 //@{
621 /// the boundary struct
622 struct Constraints
623 {
624 double LowerBound, UpperBound, StepSize;
625 Constraints()
626 : LowerBound(0)
627 , UpperBound(0)
628 , StepSize(0)
629 , candelete(false)
630 {}
631 Constraints(double l, double u, double s)
632 : LowerBound(l)
633 , UpperBound(u)
634 , StepSize(s)
635 , candelete(false)
636 {}
637 ~Constraints() = default;
638 void setDeletable(bool on)
639 {
640 candelete = on;
641 }
642 bool isDeletable() const
643 {
644 return candelete;
645 }
646
647 private:
648 bool candelete;
649 };
650 /** setting the boundaries
651 * This sets the constraint struct. It can be dynamically
652 * allocated or set as an static in the class the property
653 * belongs to:
654 * \code
655 * const Constraints percent = {0.0,100.0,1.0}
656 * \endcode
657 */
658 void setConstraints(const Constraints* sConstrain);
659 /// get the constraint struct
660 const Constraints* getConstraints() const;
661 //@}
662
663 double getMinimum() const;
664 double getMaximum() const;
665 double getStepSize() const;
666
667 const char* getEditorName() const override
668 {
669 return "Gui::PropertyEditor::PropertyFloatConstraintItem";
670 }
671
672 void setPyObject(PyObject* py) override;
673
674 protected:
675 const Constraints* _ConstStruct {nullptr};
676 };
677
678
679 /** Precision properties
680 * This property fulfills the need of a floating value with many decimal points,
681 * e.g. for holding values like Precision::Confusion(). The value has a default
682 * constraint for non-negative, but can be overridden
683 */
684 class AppExport PropertyPrecision: public PropertyFloatConstraint
685 {
686 TYPESYSTEM_HEADER_WITH_OVERRIDE();
687
688 public:
689 PropertyPrecision();
690 ~PropertyPrecision() override;
691 const char* getEditorName() const override
692 {
693 return "Gui::PropertyEditor::PropertyPrecisionItem";
694 }
695 };
696
697
698 class AppExport PropertyFloatList: public PropertyListsT<double>
699 {
700 TYPESYSTEM_HEADER_WITH_OVERRIDE();
701
702 public:
703 /**
704 * A constructor.
705 * A more elaborate description of the constructor.
706 */
707 PropertyFloatList();
708
709 /**
710 * A destructor.
711 * A more elaborate description of the destructor.
712 */
713 ~PropertyFloatList() override;
714
715 const char* getEditorName() const override
716 {
717 return "Gui::PropertyEditor::PropertyFloatListItem";
718 }
719
720 PyObject* getPyObject() override;
721
722 void Save(Base::Writer& writer) const override;
723 void Restore(Base::XMLReader& reader) override;
724
725 void SaveDocFile(Base::Writer& writer) const override;
726 void RestoreDocFile(Base::Reader& reader) override;
727
728 Property* Copy() const override;
729 void Paste(const Property& from) override;
730 unsigned int getMemSize() const override;
731
732 protected:
733 double getPyValue(PyObject* item) const override;
734 };
735
736
737 /** String properties
738 * This is the father of all properties handling Strings.
739 */
740 class AppExport PropertyString: public Property
741 {
742 TYPESYSTEM_HEADER_WITH_OVERRIDE();
743
744 public:
745 /**
746 * A constructor.
747 * A more elaborate description of the constructor.
748 */
749 PropertyString();
750
751 /**
752 * A destructor.
753 * A more elaborate description of the destructor.
754 */
755 ~PropertyString() override;
756
757 virtual void setValue(const char* sString);
758 void setValue(const std::string& sString);
759 const char* getValue() const;
760 const std::string& getStrValue() const
761 {
762 return _cValue;
763 }
764 bool isEmpty()
765 {
766 return _cValue.empty();
767 }
768
769 const char* getEditorName() const override
770 {
771 return "Gui::PropertyEditor::PropertyStringItem";
772 }
773 PyObject* getPyObject() override;
774 void setPyObject(PyObject* py) override;
775
776 void Save(Base::Writer& writer) const override;
777 void Restore(Base::XMLReader& reader) override;
778
779 Property* Copy() const override;
780 void Paste(const Property& from) override;
781 unsigned int getMemSize() const override;
782
783 void setPathValue(const App::ObjectIdentifier& path, const boost::any& value) override;
784 const boost::any getPathValue(const App::ObjectIdentifier& path) const override;
785
786 bool isSame(const Property& other) const override
787 {
788 if (&other == this) {
789 return true;
790 }
791 return getTypeId() == other.getTypeId()
792 && getStrValue() == static_cast<decltype(this)>(&other)->getStrValue();
793 }
794
795 protected:
796 std::string _cValue;
797 };
798
799 /** UUID properties
800 * This property handles unique identifiers
801 */
802 class AppExport PropertyUUID: public Property
803 {
804 TYPESYSTEM_HEADER_WITH_OVERRIDE();
805
806 public:
807 /**
808 * A constructor.
809 * A more elaborate description of the constructor.
810 */
811 PropertyUUID();
812
813 /**
814 * A destructor.
815 * A more elaborate description of the destructor.
816 */
817 ~PropertyUUID() override;
818
819
820 void setValue(const Base::Uuid&);
821 void setValue(const char* sString);
822 void setValue(const std::string& sString);
823 const std::string& getValueStr() const;
824 const Base::Uuid& getValue() const;
825
826 // virtual const char* getEditorName(void) const { return
827 // "Gui::PropertyEditor::PropertyStringItem"; }
828 PyObject* getPyObject() override;
829 void setPyObject(PyObject* py) override;
830
831 void Save(Base::Writer& writer) const override;
832 void Restore(Base::XMLReader& reader) override;
833
834 Property* Copy() const override;
835 void Paste(const Property& from) override;
836 unsigned int getMemSize() const override;
837
838 bool isSame(const Property& other) const override
839 {
840 if (&other == this) {
841 return true;
842 }
843 return getTypeId() == other.getTypeId()
844 && _uuid.getValue() == static_cast<decltype(this)>(&other)->_uuid.getValue();
845 }
846
847 private:
848 Base::Uuid _uuid;
849 };
850
851
852 /** Property handling with font names.
853 */
854 class AppExport PropertyFont: public PropertyString
855 {
856 TYPESYSTEM_HEADER_WITH_OVERRIDE();
857
858 public:
859 PropertyFont();
860 ~PropertyFont() override;
861 const char* getEditorName() const override
862 {
863 return "Gui::PropertyEditor::PropertyFontItem";
864 }
865
866 bool isSame(const Property& other) const override
867 {
868 if (&other == this) {
869 return true;
870 }
871 return getTypeId() == other.getTypeId()
872 && getValue() == static_cast<decltype(this)>(&other)->getValue();
873 }
874 };
875
876 class AppExport PropertyStringList: public PropertyListsT<std::string>
877 {
878 TYPESYSTEM_HEADER_WITH_OVERRIDE();
879 using inherited = PropertyListsT<std::string>;
880
881 public:
882 /**
883 * A constructor.
884 * A more elaborate description of the constructor.
885 */
886 PropertyStringList();
887
888 /**
889 * A destructor.
890 * A more elaborate description of the destructor.
891 */
892 ~PropertyStringList() override;
893
894 void setValues(const std::list<std::string>&);
895 using inherited::setValues;
896
897 const char* getEditorName() const override
898 {
899 return "Gui::PropertyEditor::PropertyStringListItem";
900 }
901
902 PyObject* getPyObject() override;
903
904 void Save(Base::Writer& writer) const override;
905 void Restore(Base::XMLReader& reader) override;
906
907 Property* Copy() const override;
908 void Paste(const Property& from) override;
909
910 unsigned int getMemSize() const override;
911
912 protected:
913 std::string getPyValue(PyObject* item) const override;
914 };
915
916 /** Bool properties
917 * This is the father of all properties handling booleans.
918 */
919 class AppExport PropertyBool: public Property
920 {
921 TYPESYSTEM_HEADER_WITH_OVERRIDE();
922
923 public:
924 /**
925 * A constructor.
926 * A more elaborate description of the constructor.
927 */
928 PropertyBool();
929
930 /**
931 * A destructor.
932 * A more elaborate description of the destructor.
933 */
934 ~PropertyBool() override;
935
936 void setValue(bool lValue);
937 bool getValue() const;
938
939 const char* getEditorName() const override
940 {
941 return "Gui::PropertyEditor::PropertyBoolItem";
942 }
943
944 PyObject* getPyObject() override;
945 void setPyObject(PyObject* py) override;
946
947 void Save(Base::Writer& writer) const override;
948 void Restore(Base::XMLReader& reader) override;
949
950 Property* Copy() const override;
951 void Paste(const Property& from) override;
952
953 unsigned int getMemSize() const override
954 {
955 return sizeof(bool);
956 }
957
958 void setPathValue(const App::ObjectIdentifier& path, const boost::any& value) override;
959 const boost::any getPathValue(const App::ObjectIdentifier& path) const override;
960
961 bool isSame(const Property& other) const override
962 {
963 if (&other == this) {
964 return true;
965 }
966 return getTypeId() == other.getTypeId()
967 && getValue() == static_cast<decltype(this)>(&other)->getValue();
968 }
969
970 private:
971 bool _lValue;
972 };
973
974 /** Bool list properties
975 *
976 */
977 class AppExport PropertyBoolList: public PropertyListsT<bool, boost::dynamic_bitset<>>
978 {
979 TYPESYSTEM_HEADER_WITH_OVERRIDE();
980 using inherited = PropertyListsT<bool, boost::dynamic_bitset<>>;
981
982 public:
983 PropertyBoolList();
984 ~PropertyBoolList() override;
985
986 PyObject* getPyObject() override;
987 void setPyObject(PyObject* py) override;
988
989 void Save(Base::Writer& writer) const override;
990 void Restore(Base::XMLReader& reader) override;
991
992 Property* Copy() const override;
993 void Paste(const Property& from) override;
994 unsigned int getMemSize() const override;
995
996 protected:
997 bool getPyValue(PyObject* py) const override;
998 };
999
1000
1001 /** Base::Color properties
1002 * This is the father of all properties handling colors.
1003 */
1004 class AppExport PropertyColor: public Property
1005 {
1006 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1007
1008 public:
1009 /**
1010 * A constructor.
1011 * A more elaborate description of the constructor.
1012 */
1013 PropertyColor();
1014
1015 /**
1016 * A destructor.
1017 * A more elaborate description of the destructor.
1018 */
1019 ~PropertyColor() override;
1020
1021 /** Sets the property
1022 */
1023 void setValue(const Base::Color& col);
1024 void setValue(float r, float g, float b, float a = 1.0F);
1025 void setValue(uint32_t rgba);
1026
1027 /** This method returns a string representation of the property
1028 */
1029 const Base::Color& getValue() const;
1030
1031 const char* getEditorName() const override
1032 {
1033 return "Gui::PropertyEditor::PropertyColorItem";
1034 }
1035
1036 PyObject* getPyObject() override;
1037 void setPyObject(PyObject* py) override;
1038
1039 void Save(Base::Writer& writer) const override;
1040 void Restore(Base::XMLReader& reader) override;
1041
1042 Property* Copy() const override;
1043 void Paste(const Property& from) override;
1044
1045 unsigned int getMemSize() const override
1046 {
1047 return sizeof(Base::Color);
1048 }
1049
1050 bool isSame(const Property& other) const override
1051 {
1052 if (&other == this) {
1053 return true;
1054 }
1055 return getTypeId() == other.getTypeId()
1056 && getValue() == static_cast<decltype(this)>(&other)->getValue();
1057 }
1058
1059 private:
1060 Base::Color _cCol;
1061 };
1062
1063 class AppExport PropertyColorList: public PropertyListsT<Base::Color>
1064 {
1065 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1066
1067 public:
1068 /**
1069 * A constructor.
1070 * A more elaborate description of the constructor.
1071 */
1072 PropertyColorList();
1073
1074 /**
1075 * A destructor.
1076 * A more elaborate description of the destructor.
1077 */
1078 ~PropertyColorList() override;
1079
1080 PyObject* getPyObject() override;
1081
1082 void Save(Base::Writer& writer) const override;
1083 void Restore(Base::XMLReader& reader) override;
1084
1085 void SaveDocFile(Base::Writer& writer) const override;
1086 void RestoreDocFile(Base::Reader& reader) override;
1087
1088 Property* Copy() const override;
1089 void Paste(const Property& from) override;
1090 unsigned int getMemSize() const override;
1091
1092 protected:
1093 Base::Color getPyValue(PyObject* py) const override;
1094
1095 private:
1096 bool requiresAlphaConversion {false}; // In 1.1 the handling of alpha was inverted
1097 };
1098
1099
1100 /** Material properties
1101 * This is the father of all properties handling colors.
1102 */
1103 class AppExport PropertyMaterial: public Property
1104 {
1105 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1106
1107 public:
1108 /**
1109 * A constructor.
1110 * A more elaborate description of the constructor.
1111 */
1112 PropertyMaterial();
1113
1114 /**
1115 * A destructor.
1116 * A more elaborate description of the destructor.
1117 */
1118 ~PropertyMaterial() override;
1119
1120 /** Sets the property
1121 */
1122 void setValue(const Material& mat);
1123 void setValue(const Base::Color& col);
1124 void setValue(float r, float g, float b, float a = 1.0F);
1125 void setValue(uint32_t rgba);
1126 void setAmbientColor(const Base::Color& col);
1127 void setAmbientColor(float r, float g, float b, float a = 1.0F);
1128 void setAmbientColor(uint32_t rgba);
1129 void setDiffuseColor(const Base::Color& col);
1130 void setDiffuseColor(float r, float g, float b, float a = 1.0F);
1131 void setDiffuseColor(uint32_t rgba);
1132 void setSpecularColor(const Base::Color& col);
1133 void setSpecularColor(float r, float g, float b, float a = 1.0F);
1134 void setSpecularColor(uint32_t rgba);
1135 void setEmissiveColor(const Base::Color& col);
1136 void setEmissiveColor(float r, float g, float b, float a = 1.0F);
1137 void setEmissiveColor(uint32_t rgba);
1138 void setShininess(float);
1139 void setTransparency(float);
1140
1141 /** This method returns a string representation of the property
1142 */
1143 const Material& getValue() const;
1144 const Base::Color& getAmbientColor() const;
1145 const Base::Color& getDiffuseColor() const;
1146 const Base::Color& getSpecularColor() const;
1147 const Base::Color& getEmissiveColor() const;
1148 double getShininess() const;
1149 double getTransparency() const;
1150
1151 PyObject* getPyObject() override;
1152 void setPyObject(PyObject* py) override;
1153
1154 void Save(Base::Writer& writer) const override;
1155 void Restore(Base::XMLReader& reader) override;
1156
1157 const char* getEditorName() const override;
1158
1159 Property* Copy() const override;
1160 void Paste(const Property& from) override;
1161
1162 unsigned int getMemSize() const override
1163 {
1164 return sizeof(_cMat);
1165 }
1166
1167 bool isSame(const Property& other) const override
1168 {
1169 if (&other == this) {
1170 return true;
1171 }
1172 return getTypeId() == other.getTypeId()
1173 && getValue() == static_cast<decltype(this)>(&other)->getValue();
1174 }
1175
1176 private:
1177 Material _cMat;
1178 };
1179
1180 /** Material properties
1181 */
1182 class AppExport PropertyMaterialList: public PropertyListsT<Material>
1183 {
1184 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1185
1186 public:
1187 /**
1188 * A constructor.
1189 * A more elaborate description of the constructor.
1190 */
1191 PropertyMaterialList();
1192
1193 /**
1194 * A destructor.
1195 * A more elaborate description of the destructor.
1196 */
1197 ~PropertyMaterialList() override;
1198
1199 void setValue();
1200 void setValue(const std::vector<App::Material>& materials)
1201 {
1202 PropertyListsT<Material>::setValue(materials);
1203 }
1204 void
1205 setValues(const std::vector<App::Material>& newValues = std::vector<App::Material>()) override;
1206 void setValue(const Material& mat);
1207 void setValue(int index, const Material& mat);
1208
1209 void setAmbientColor(const Base::Color& col);
1210 void setAmbientColor(float r, float g, float b, float a = 1.0F);
1211 void setAmbientColor(uint32_t rgba);
1212 void setAmbientColor(int index, const Base::Color& col);
1213 void setAmbientColor(int index, float r, float g, float b, float a = 1.0F);
1214 void setAmbientColor(int index, uint32_t rgba);
1215
1216 void setDiffuseColor(const Base::Color& col);
1217 void setDiffuseColor(float r, float g, float b, float a = 1.0F);
1218 void setDiffuseColor(uint32_t rgba);
1219 void setDiffuseColor(int index, const Base::Color& col);
1220 void setDiffuseColor(int index, float r, float g, float b, float a = 1.0F);
1221 void setDiffuseColor(int index, uint32_t rgba);
1222 void setDiffuseColors(const std::vector<Base::Color>& colors);
1223
1224 void setSpecularColor(const Base::Color& col);
1225 void setSpecularColor(float r, float g, float b, float a = 1.0F);
1226 void setSpecularColor(uint32_t rgba);
1227 void setSpecularColor(int index, const Base::Color& col);
1228 void setSpecularColor(int index, float r, float g, float b, float a = 1.0F);
1229 void setSpecularColor(int index, uint32_t rgba);
1230
1231 void setEmissiveColor(const Base::Color& col);
1232 void setEmissiveColor(float r, float g, float b, float a = 1.0F);
1233 void setEmissiveColor(uint32_t rgba);
1234 void setEmissiveColor(int index, const Base::Color& col);
1235 void setEmissiveColor(int index, float r, float g, float b, float a = 1.0F);
1236 void setEmissiveColor(int index, uint32_t rgba);
1237
1238 void setShininess(float);
1239 void setShininess(int index, float);
1240
1241 void setTransparency(float);
1242 void setTransparency(int index, float);
1243 void setTransparencies(const std::vector<float>& transparencies);
1244
1245 const Base::Color& getAmbientColor() const;
1246 const Base::Color& getAmbientColor(int index) const;
1247
1248 const Base::Color& getDiffuseColor() const;
1249 const Base::Color& getDiffuseColor(int index) const;
1250 std::vector<Base::Color> getDiffuseColors() const;
1251
1252 const Base::Color& getSpecularColor() const;
1253 const Base::Color& getSpecularColor(int index) const;
1254
1255 const Base::Color& getEmissiveColor() const;
1256 const Base::Color& getEmissiveColor(int index) const;
1257
1258 float getShininess() const;
1259 float getShininess(int index) const;
1260
1261 float getTransparency() const;
1262 float getTransparency(int index) const;
1263 std::vector<float> getTransparencies() const;
1264
1265 PyObject* getPyObject() override;
1266
1267 void Save(Base::Writer& writer) const override;
1268 void Restore(Base::XMLReader& reader) override;
1269
1270 void SaveDocFile(Base::Writer& writer) const override;
1271 void RestoreDocFile(Base::Reader& reader) override;
1272
1273 const char* getEditorName() const override;
1274
1275 Property* Copy() const override;
1276 void Paste(const Property& from) override;
1277 unsigned int getMemSize() const override;
1278
1279 protected:
1280 Material getPyValue(PyObject* py) const override;
1281
1282 private:
1283 enum Format
1284 {
1285 Version_0,
1286 Version_1,
1287 Version_2,
1288 Version_3
1289 };
1290
1291 void RestoreDocFileV0(uint32_t count, Base::Reader& reader);
1292 void RestoreDocFileV3(Base::Reader& reader);
1293
1294 void writeString(Base::OutputStream& str, const std::string& value) const;
1295 void readString(Base::InputStream& str, std::string& value);
1296
1297 void verifyIndex(int index) const;
1298 void setMinimumSizeOne();
1299 int resizeByOneIfNeeded(int index);
1300 void convertAlpha(std::vector<App::Material>& materials) const;
1301
1302 Format formatVersion {Version_0};
1303 bool requiresAlphaConversion {false}; // In 1.1 the handling of alpha was inverted
1304 };
1305
1306
1307 /** Property for dynamic creation of a FreeCAD persistent object
1308 *
1309 * In Python, this property can be assigned a type string to create a dynamic FreeCAD
1310 * object, and then read back as the Python binding of the newly created object.
1311 */
1312 class AppExport PropertyPersistentObject: public PropertyString
1313 {
1314 TYPESYSTEM_HEADER_WITH_OVERRIDE();
1315 using inherited = PropertyString;
1316
1317 public:
1318 PyObject* getPyObject() override;
1319 void setValue(const char* type) override;
1320
1321 void Save(Base::Writer& writer) const override;
1322 void Restore(Base::XMLReader& reader) override;
1323
1324 Property* Copy() const override;
1325 void Paste(const Property& from) override;
1326 unsigned int getMemSize() const override;
1327
1328 std::shared_ptr<Base::Persistence> getObject() const
1329 {
1330 return _pObject;
1331 }
1332
1333 protected:
1334 std::shared_ptr<Base::Persistence> _pObject;
1335 };
1336
1337 } // namespace App
1338
1339 #endif // APP_PROPERTYSTANDARD_H