This class implements an interface to add properties at run-time to an object derived from PropertyContainer. More...
#include <DynamicProperty.h>
Classes | |
struct | PropData |
Public Member Functions | |
DynamicProperty (PropertyContainer *pc) | |
virtual | ~DynamicProperty () |
Access properties | |
void | addDynamicProperties (const PropertyContainer *) |
Property * | addDynamicProperty (const char *type, const char *name=0, const char *group=0, const char *doc=0, short attr=0, bool ro=false, bool hidden=false) |
Property * | getDynamicPropertyByName (const char *name) const |
find a property by its name | |
std::vector< std::string > | getDynamicPropertyNames () const |
const char * | getName (const Property *prop) const |
get the name of a property | |
Property * | getPropertyByName (const char *name) const |
find a property by its name | |
void | getPropertyList (std::vector< Property * > &List) const |
get all properties of the class (including parent) | |
void | getPropertyMap (std::map< std::string, Property * > &Map) const |
get all properties of the class (including parent) | |
Property serialization | |
unsigned int | getMemSize (void) const |
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? | |
void | Restore (Base::XMLReader &reader) |
This method is used to restore properties from an XML document. | |
void | Save (Base::Writer &writer) const |
This method is used to save properties to an XML document. | |
Property attributes | |
const char * | getPropertyDocumentation (const char *name) const |
get the Group of a named Property | |
const char * | getPropertyDocumentation (const Property *prop) const |
get the Group of a Property | |
const char * | getPropertyGroup (const char *name) const |
get the Group of a named Property | |
const char * | getPropertyGroup (const Property *prop) const |
get the Group of a Property | |
short | getPropertyType (const char *name) const |
get the Type of a named Property | |
short | getPropertyType (const Property *prop) const |
get the Type of a Property | |
bool | isHidden (const char *name) const |
check if the named property is hidden | |
bool | isHidden (const Property *prop) const |
check if the property is hidden | |
bool | isReadOnly (const char *name) const |
check if the nameed property is read-only | |
bool | isReadOnly (const Property *prop) const |
check if the property is read-only |
This class implements an interface to add properties at run-time to an object derived from PropertyContainer.
The additional properties are made persistent.
Definition at line 46 of file DynamicProperty.h.
DynamicProperty::DynamicProperty | ( | PropertyContainer * | pc | ) |
Definition at line 42 of file DynamicProperty.cpp.
DynamicProperty::~DynamicProperty | ( | ) | [virtual] |
Definition at line 46 of file DynamicProperty.cpp.
void DynamicProperty::addDynamicProperties | ( | const PropertyContainer * | cont | ) |
Definition at line 91 of file DynamicProperty.cpp.
References addDynamicProperty(), App::Property::getDocumentation(), App::PropertyContainer::getDynamicPropertyByName(), App::PropertyContainer::getDynamicPropertyNames(), App::Property::getGroup(), App::Property::getName(), Base::Type::getName(), App::Property::getType(), App::Property::getTypeId(), App::PropertyContainer::isHidden(), and App::PropertyContainer::isReadOnly().
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::addDynamicProperties(), and App::FeaturePythonT< FeatureT >::addDynamicProperties().
Property * DynamicProperty::addDynamicProperty | ( | const char * | type, | |
const char * | name = 0 , |
|||
const char * | group = 0 , |
|||
const char * | doc = 0 , |
|||
short | attr = 0 , |
|||
bool | ro = false , |
|||
bool | hidden = false | |||
) |
Definition at line 214 of file DynamicProperty.cpp.
References App::DynamicProperty::PropData::attr, Base::Type::createInstanceByName(), App::DynamicProperty::PropData::doc, App::Property::getClassTypeId(), Base::BaseClass::getTypeId(), App::DynamicProperty::PropData::group, App::DynamicProperty::PropData::hidden, App::DynamicProperty::PropData::property, App::DynamicProperty::PropData::readonly, and App::Property::setContainer().
Referenced by addDynamicProperties(), Gui::ViewProviderPythonFeatureT< ViewProviderT >::addDynamicProperty(), App::FeaturePythonT< FeatureT >::addDynamicProperty(), and Restore().
Property * DynamicProperty::getDynamicPropertyByName | ( | const char * | name | ) | const |
find a property by its name
Definition at line 74 of file DynamicProperty.cpp.
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::getDynamicPropertyByName(), and App::FeaturePythonT< FeatureT >::getDynamicPropertyByName().
std::vector< std::string > DynamicProperty::getDynamicPropertyNames | ( | ) | const |
Definition at line 82 of file DynamicProperty.cpp.
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::getDynamicPropertyNames(), and App::FeaturePythonT< FeatureT >::getDynamicPropertyNames().
unsigned int DynamicProperty::getMemSize | ( | void | ) | const [virtual] |
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?
Implements Base::Persistence.
Definition at line 118 of file DynamicProperty.cpp.
References getPropertyMap().
const char * DynamicProperty::getName | ( | const Property * | prop | ) | const |
get the name of a property
Definition at line 109 of file DynamicProperty.cpp.
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::getName(), and App::FeaturePythonT< FeatureT >::getName().
Property * DynamicProperty::getPropertyByName | ( | const char * | name | ) | const |
find a property by its name
Definition at line 66 of file DynamicProperty.cpp.
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::getPropertyByName(), App::FeaturePythonT< FeatureT >::getPropertyByName(), and Restore().
const char * DynamicProperty::getPropertyDocumentation | ( | const char * | name | ) | const |
get the Group of a named Property
Definition at line 172 of file DynamicProperty.cpp.
const char * DynamicProperty::getPropertyDocumentation | ( | const Property * | prop | ) | const |
get the Group of a Property
Definition at line 163 of file DynamicProperty.cpp.
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::getPropertyDocumentation(), and App::FeaturePythonT< FeatureT >::getPropertyDocumentation().
const char * DynamicProperty::getPropertyGroup | ( | const char * | name | ) | const |
get the Group of a named Property
Definition at line 155 of file DynamicProperty.cpp.
const char * DynamicProperty::getPropertyGroup | ( | const Property * | prop | ) | const |
get the Group of a Property
Definition at line 146 of file DynamicProperty.cpp.
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::getPropertyGroup(), and App::FeaturePythonT< FeatureT >::getPropertyGroup().
void DynamicProperty::getPropertyList | ( | std::vector< Property * > & | List | ) | const |
get all properties of the class (including parent)
Definition at line 50 of file DynamicProperty.cpp.
Referenced by App::FeaturePythonT< FeatureT >::getPropertyList().
void DynamicProperty::getPropertyMap | ( | std::map< std::string, Property * > & | Map | ) | const |
get all properties of the class (including parent)
Definition at line 58 of file DynamicProperty.cpp.
Referenced by getMemSize(), Gui::ViewProviderPythonFeatureT< ViewProviderT >::getPropertyMap(), App::FeaturePythonT< FeatureT >::getPropertyMap(), and Save().
short DynamicProperty::getPropertyType | ( | const char * | name | ) | const |
get the Type of a named Property
Definition at line 138 of file DynamicProperty.cpp.
short DynamicProperty::getPropertyType | ( | const Property * | prop | ) | const |
get the Type of a Property
Definition at line 129 of file DynamicProperty.cpp.
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::getPropertyType(), and App::FeaturePythonT< FeatureT >::getPropertyType().
bool DynamicProperty::isHidden | ( | const char * | name | ) | const |
check if the named property is hidden
Definition at line 206 of file DynamicProperty.cpp.
bool DynamicProperty::isHidden | ( | const Property * | prop | ) | const |
check if the property is hidden
Definition at line 197 of file DynamicProperty.cpp.
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::isHidden(), and App::FeaturePythonT< FeatureT >::isHidden().
bool DynamicProperty::isReadOnly | ( | const char * | name | ) | const |
check if the nameed property is read-only
Definition at line 189 of file DynamicProperty.cpp.
bool DynamicProperty::isReadOnly | ( | const Property * | prop | ) | const |
check if the property is read-only
Definition at line 180 of file DynamicProperty.cpp.
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::isReadOnly(), and App::FeaturePythonT< FeatureT >::isReadOnly().
void DynamicProperty::Restore | ( | Base::XMLReader & | ) | [virtual] |
This method is used to restore properties from an XML document.
It uses the XMLReader class, which bases on SAX, to read the in Save() written information. Again the Vector as an example:
void PropertyVector::Restore(Base::XMLReader &reader) { // read my Element reader.readElement("PropertyVector"); // get the value of my Attribute _cVec.x = (float)reader.getAttributeAsFloat("valueX"); _cVec.y = (float)reader.getAttributeAsFloat("valueY"); _cVec.z = (float)reader.getAttributeAsFloat("valueZ"); }
Implements Base::Persistence.
Definition at line 348 of file DynamicProperty.cpp.
References addDynamicProperty(), Base::Console(), Base::XMLReader::getAttribute(), Base::XMLReader::getAttributeAsInteger(), App::Property::getName(), Base::Type::getName(), getPropertyByName(), App::PropertyContainer::getTypeId(), App::Property::getTypeId(), group, Base::XMLReader::hasAttribute(), Mod::PartDesign::Scripts::Gear::hide(), Base::XMLReader::readElement(), Base::XMLReader::readEndElement(), Base::Persistence::Restore(), and Base::Exception::what().
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::Restore(), and App::FeaturePythonT< FeatureT >::Restore().
void DynamicProperty::Save | ( | Base::Writer & | ) | const [virtual] |
This method is used to save properties to an XML document.
A good example you'll find in PropertyStandard.cpp, e.g. the vector:
void PropertyVector::Save (Writer &writer) const { writer << writer.ind() << "<PropertyVector valueX=\"" << _cVec.x << "\" valueY=\"" << _cVec.y << "\" valueZ=\"" << _cVec.z <<"\"/>" << endl; }
The writer.ind() expression writes the indention, just for pretty printing of the XML. As you see, the writing of the XML document is not done with a DOM implementation because of performance reasons. Therefore the programmer has to take care that a valid XML document is written. This means closing tags and writing UTF-8.
Implements Base::Persistence.
Definition at line 293 of file DynamicProperty.cpp.
References Base::Console(), Base::Writer::decInd(), getPropertyMap(), Base::Writer::incInd(), Base::Writer::ind(), Base::Writer::Stream(), and Base::Exception::what().
Referenced by Gui::ViewProviderPythonFeatureT< ViewProviderT >::Save(), and App::FeaturePythonT< FeatureT >::Save().