App::DynamicProperty Class Reference

This class implements an interface to add properties at run-time to an object derived from PropertyContainer. More...

#include <DynamicProperty.h>

Inheritance diagram for App::DynamicProperty:
Base::Persistence Base::BaseClass

List of all members.

Classes

struct  PropData

Public Member Functions

 DynamicProperty (PropertyContainer *pc)
virtual ~DynamicProperty ()
Access properties



void addDynamicProperties (const PropertyContainer *)
PropertyaddDynamicProperty (const char *type, const char *name=0, const char *group=0, const char *doc=0, short attr=0, bool ro=false, bool hidden=false)
PropertygetDynamicPropertyByName (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
PropertygetPropertyByName (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

Detailed Description

This class implements an interface to add properties at run-time to an object derived from PropertyContainer.

The additional properties are made persistent.

Author:
Werner Mayer

Definition at line 46 of file DynamicProperty.h.


Constructor & Destructor Documentation

DynamicProperty::DynamicProperty ( PropertyContainer pc  ) 

Definition at line 42 of file DynamicProperty.cpp.

DynamicProperty::~DynamicProperty (  )  [virtual]

Definition at line 46 of file DynamicProperty.cpp.


Member Function Documentation

void DynamicProperty::addDynamicProperties ( const PropertyContainer cont  ) 
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 
)
Property * DynamicProperty::getDynamicPropertyByName ( const char *  name  )  const
std::vector< std::string > DynamicProperty::getDynamicPropertyNames (  )  const
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
Property * DynamicProperty::getPropertyByName ( const char *  name  )  const
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
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
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
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.

See also:
Base::Writer

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().


The documentation for this class was generated from the following files:

Generated on Wed Nov 23 19:01:43 2011 for FreeCAD by  doxygen 1.6.1