/
Property.h
148 lines (118 loc) · 5.56 KB
/
Property.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef APP_PROPERTY_H
#define APP_PROPERTY_H
// Std. configurations
#include <Base/Persistence.h>
#include <string>
#include <bitset>
namespace App
{
class PropertyContainer;
/** Base class of all properties
* This is the father of all properties. Properties are objects which are used
* in the document tree to parametrize e.g. features and their graphical output.
* They are also used to gain access from the scripting facility.
* /par
* This abstract base class defines all methods shared by all
* possible properties. It is also possible to define user properties
* and use them in the framework...
*/
class AppExport Property : public Base::Persistence
{
TYPESYSTEM_HEADER();
public:
Property();
virtual ~Property();
/** This method is used to get the size of objects
* It is not meant to have the exact size, it is more or less an estimation
* which runs fast! Is it two bytes or a GB?
* This method is defined in Base::Persistence
* @see Base::Persistence
*/
virtual unsigned int getMemSize (void) const {
// you have to implement this method in all property classes!
return sizeof(father) + sizeof(StatusBits);
}
/// get the name of this property in the belonging container
const char* getName(void) const;
/// Get the class name of the associated property editor item
virtual const char* getEditorName(void) const { return ""; }
/// Get the type of the property in the container
short getType(void) const;
/// Get the group of this property
const char* getGroup(void) const;
/// Get the documentation of this property
const char* getDocumentation(void) const;
/// Is called by the framework to set the father (container)
void setContainer(PropertyContainer *Father);
/// Get a pointer to the PropertyContainer derived class the property belongs to
PropertyContainer *getContainer(void) const {return father;}
/// Set the property touched
void touch();
/// Test if this property is touched
bool isTouched(void) const {return StatusBits.test(0);}
/// Reset this property touched
void purgeTouched(void){StatusBits.reset(0);}
/// Returns a new copy of the property (mainly for Undo/Redo and transactions)
virtual Property *Copy(void) const = 0;
/// Paste the value from the property (mainly for Undo/Redo and transactions)
virtual void Paste(const Property &from) = 0;
/// Encodes an attribute upon saving.
static std::string encodeAttribute(const std::string&);
friend class PropertyContainer;
/** Status bits of the property
* The first 8 bits are used for the base system the rest can be used in
* descendent classes to to mark special stati on the objects.
* The bits and their meaning are listed below:
* 0 - object is marked as 'touched'
* 1 - object is marked as 'immutable'
* 2 - object is marked as 'read-ony' (for property editor)
* 3 - object is marked as 'hidden' (for property editor)
*/
std::bitset<32> StatusBits;
protected:
/// Gets called by all setValue() methods after the value has changed
void hasSetValue(void);
/// Gets called by all setValue() methods before the value has changed
void aboutToSetValue(void);
private:
// forbidden
Property(const Property&);
Property& operator = (const Property&);
private:
PropertyContainer *father;
};
/** Base class of all property lists.
* The PropertyLists class is the base class for properties which can contain
* multiple values, not only a single value.
* All property types which may contain more than one value inherits this class.
*/
class AppExport PropertyLists : public Property
{
TYPESYSTEM_HEADER();
public:
virtual void setSize(int newSize)=0;
virtual int getSize(void) const =0;
};
} // namespace App
#endif // APP_PROPERTY_H