Skip to content

Commit

Permalink
+ introduce proper enum for property status to replace plain integers
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 1, 2016
1 parent 342198e commit 50d7793
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 50 deletions.
38 changes: 34 additions & 4 deletions src/App/Property.h
Expand Up @@ -52,6 +52,18 @@ class AppExport Property : public Base::Persistence
TYPESYSTEM_HEADER();

public:
enum Status
{
Touched = 0, // touched property
Immutable = 1, // can't modify property
ReadOnly = 2, // for property editor
Hidden = 3, // for property editor
User1 = 28, // user-defined status
User2 = 29, // user-defined status
User3 = 30, // user-defined status
User4 = 31 // user-defined status
};

Property();
virtual ~Property();

Expand Down Expand Up @@ -99,12 +111,30 @@ class AppExport Property : public Base::Persistence
/// Get valid paths for this property; used by auto completer
virtual void getPaths(std::vector<App::ObjectIdentifier> & paths) const;

/** Property status handling
*/
//@{
/// Set the property touched
void touch();
/// Test if this property is touched
bool isTouched(void) const {return StatusBits.test(0);}
inline bool isTouched(void) const {
return StatusBits.test(0);
}
/// Reset this property touched
void purgeTouched(void){StatusBits.reset(0);}
inline void purgeTouched(void) {
StatusBits.reset(0);
}
/// return the status bits
inline unsigned long getStatus() const {
return StatusBits.to_ulong();
}
inline bool testStatus(Status pos) const {
return StatusBits.test(static_cast<size_t>(pos));
}
inline void setStatus(Status pos, bool on) {
StatusBits.set(static_cast<size_t>(pos), on);
}
//@}

/// Returns a new copy of the property (mainly for Undo/Redo and transactions)
virtual Property *Copy(void) const = 0;
Expand All @@ -116,18 +146,18 @@ class AppExport Property : public Base::Persistence

friend class PropertyContainer;

protected:
/** 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)
* 2 - object is marked as 'read-only' (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);
Expand Down
16 changes: 8 additions & 8 deletions src/App/PropertyContainerPyImp.cpp
Expand Up @@ -110,8 +110,8 @@ PyObject* PropertyContainerPy::setEditorMode(PyObject *args)
return 0;
}

prop->StatusBits.set(2,(type & 1) > 0);
prop->StatusBits.set(3,(type & 2) > 0);
prop->setStatus(Property::ReadOnly,(type & 1) > 0);
prop->setStatus(Property::Hidden,(type & 2) > 0);

Py_Return;
}
Expand All @@ -128,15 +128,15 @@ PyObject* PropertyContainerPy::setEditorMode(PyObject *args)
}

// reset all bits first
prop->StatusBits.reset(2);
prop->StatusBits.reset(3);
prop->setStatus(Property::ReadOnly, false);
prop->setStatus(Property::Hidden, false);

for (Py::Sequence::iterator it = seq.begin();it!=seq.end();++it) {
std::string str = (std::string)Py::String(*it);
if (str == "ReadOnly")
prop->StatusBits.set(2);
prop->setStatus(Property::ReadOnly, true);
else if (str == "Hidden")
prop->StatusBits.set(3);
prop->setStatus(Property::Hidden, true);
}

Py_Return;
Expand All @@ -157,9 +157,9 @@ PyObject* PropertyContainerPy::getEditorMode(PyObject *args)
Py::List ret;
if (prop) {
short Type = prop->getType();
if ((prop->StatusBits.test(2)) || (Type & Prop_ReadOnly))
if ((prop->testStatus(Property::ReadOnly)) || (Type & Prop_ReadOnly))
ret.append(Py::String("ReadOnly"));
if ((prop->StatusBits.test(3)) || (Type & Prop_Hidden))
if ((prop->testStatus(Property::Hidden)) || (Type & Prop_Hidden))
ret.append(Py::String("Hidden"));
}
return Py::new_reference_to(ret);
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/Placement.cpp
Expand Up @@ -52,7 +52,7 @@ class find_placement
{
if (elem.first == propertyname) {
// flag set that property is read-only or hidden
if (elem.second->StatusBits.test(2) || elem.second->StatusBits.test(3))
if (elem.second->testStatus(App::Property::ReadOnly) || elem.second->testStatus(App::Property::Hidden))
return false;
App::PropertyContainer* parent = elem.second->getContainer();
if (parent) {
Expand Down
6 changes: 3 additions & 3 deletions src/Gui/PropertyView.cpp
Expand Up @@ -128,7 +128,7 @@ void PropertyView::slotChangePropertyView(const Gui::ViewProvider&, const App::P
void PropertyView::slotAppendDynamicProperty(const App::Property& prop)
{
App::PropertyContainer* parent = prop.getContainer();
if (parent->isHidden(&prop) || prop.StatusBits.test(3))
if (parent->isHidden(&prop) || prop.testStatus(App::Property::Hidden))
return;

if (parent && parent->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
Expand Down Expand Up @@ -205,7 +205,7 @@ void PropertyView::onSelectionChanged(const SelectionChanges& msg)
nameType.propName = ob->getPropertyName(*pt);
nameType.propId = (*pt)->getTypeId().getKey();

if (!ob->isHidden(*pt) && !(*pt)->StatusBits.test(3)) {
if (!ob->isHidden(*pt) && !(*pt)->testStatus(App::Property::Hidden)) {
std::vector<PropInfo>::iterator pi = std::find_if(propDataMap.begin(), propDataMap.end(), PropFind(nameType));
if (pi != propDataMap.end()) {
pi->propList.push_back(*pt);
Expand All @@ -225,7 +225,7 @@ void PropertyView::onSelectionChanged(const SelectionChanges& msg)
nameType.propName = pt->first;
nameType.propId = pt->second->getTypeId().getKey();

if (!vp->isHidden(pt->second) && !pt->second->StatusBits.test(3)) {
if (!vp->isHidden(pt->second) && !pt->second->testStatus(App::Property::Hidden)) {
std::vector<PropInfo>::iterator pi = std::find_if(propViewMap.begin(), propViewMap.end(), PropFind(nameType));
if (pi != propViewMap.end()) {
pi->propList.push_back(pt->second);
Expand Down
18 changes: 9 additions & 9 deletions src/Gui/ViewProviderDocumentObject.cpp
Expand Up @@ -86,10 +86,10 @@ void ViewProviderDocumentObject::onChanged(const App::Property* prop)
}
else if (prop == &Visibility) {
// use this bit to check whether show() or hide() must be called
if (Visibility.StatusBits.test(8) == false) {
Visibility.StatusBits.set(8);
if (Visibility.testStatus(App::Property::User2) == false) {
Visibility.setStatus(App::Property::User2, true);
Visibility.getValue() ? show() : hide();
Visibility.StatusBits.reset(8);
Visibility.setStatus(App::Property::User2, false);
}
}

Expand All @@ -99,21 +99,21 @@ void ViewProviderDocumentObject::onChanged(const App::Property* prop)
void ViewProviderDocumentObject::hide(void)
{
// use this bit to check whether 'Visibility' must be adjusted
if (Visibility.StatusBits.test(8) == false) {
Visibility.StatusBits.set(8);
if (Visibility.testStatus(App::Property::User2) == false) {
Visibility.setStatus(App::Property::User2, true);
Visibility.setValue(false);
Visibility.StatusBits.reset(8);
Visibility.setStatus(App::Property::User2, false);
}
ViewProvider::hide();
}

void ViewProviderDocumentObject::show(void)
{
// use this bit to check whether 'Visibility' must be adjusted
if (Visibility.StatusBits.test(8) == false) {
Visibility.StatusBits.set(8);
if (Visibility.testStatus(App::Property::User2) == false) {
Visibility.setStatus(App::Property::User2, true);
Visibility.setValue(true);
Visibility.StatusBits.reset(8);
Visibility.setStatus(App::Property::User2, false);
}
ViewProvider::show();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Gui/ViewProviderDocumentObjectGroup.cpp
Expand Up @@ -162,7 +162,7 @@ void ViewProviderDocumentObjectGroup::hide(void)
{
// when reading the Visibility property from file then do not hide the
// objects of this group because they have stored their visibility status, too
if (!Visibility.StatusBits.test(9) && this->visible) {
if (!Visibility.testStatus(App::Property::User1) && this->visible) {
App::DocumentObject * group = getObject();
if (group && group->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
const std::vector<App::DocumentObject*> & links = static_cast<App::DocumentObjectGroup*>
Expand All @@ -183,7 +183,7 @@ void ViewProviderDocumentObjectGroup::show(void)
{
// when reading the Visibility property from file then do not hide the
// objects of this group because they have stored their visibility status, too
if (!Visibility.StatusBits.test(9) && !this->visible) {
if (!Visibility.testStatus(App::Property::User1) && !this->visible) {
App::DocumentObject * group = getObject();
if (group && group->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
const std::vector<App::DocumentObject*> & links = static_cast<App::DocumentObjectGroup*>
Expand All @@ -207,9 +207,9 @@ bool ViewProviderDocumentObjectGroup::isShow(void) const

void ViewProviderDocumentObjectGroup::Restore(Base::XMLReader &reader)
{
Visibility.StatusBits.set(9); // tmp. set
Visibility.setStatus(App::Property::User1, true); // tmp. set
ViewProviderDocumentObject::Restore(reader);
Visibility.StatusBits.reset(9); // unset
Visibility.setStatus(App::Property::User1, false); // unset
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -116,7 +116,7 @@ void PropertyItem::updateData()
it != propertyItems.end(); ++it) {
App::PropertyContainer* parent = (*it)->getContainer();
if (parent)
ro &= (parent->isReadOnly(*it) || (*it)->StatusBits.test(2));
ro &= (parent->isReadOnly(*it) || (*it)->testStatus(App::Property::ReadOnly));
}
this->setReadOnly(ro);
}
Expand Down Expand Up @@ -318,7 +318,7 @@ void PropertyItem::setPropertyValue(const QString& value)
for (std::vector<App::Property*>::const_iterator it = propertyItems.begin();
it != propertyItems.end(); ++it) {
App::PropertyContainer* parent = (*it)->getContainer();
if (parent && !parent->isReadOnly(*it) && !(*it)->StatusBits.test(2)) {
if (parent && !parent->isReadOnly(*it) && !(*it)->testStatus(App::Property::ReadOnly)) {
QString cmd = QString::fromAscii("%1 = %2").arg(pythonIdentifier(*it)).arg(value);
Gui::Application::Instance->runPythonCode((const char*)cmd.toUtf8());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Drawing/Gui/ViewProviderPage.cpp
Expand Up @@ -64,8 +64,8 @@ ViewProviderDrawingPage::ViewProviderDrawingPage()
ADD_PROPERTY(HintOffsetY,(10.0));

// do not show this in the property editor
Visibility.StatusBits.set(3, true);
DisplayMode.StatusBits.set(3, true);
Visibility.setStatus(App::Property::Hidden, true);
DisplayMode.setStatus(App::Property::Hidden, true);
}

ViewProviderDrawingPage::~ViewProviderDrawingPage()
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Drawing/Gui/ViewProviderView.cpp
Expand Up @@ -50,7 +50,7 @@ ViewProviderDrawingView::ViewProviderDrawingView()
sPixmap = "Page";

// Do not show in property editor
DisplayMode.StatusBits.set(3, true);
DisplayMode.setStatus(App::Property::Hidden, true);
}

ViewProviderDrawingView::~ViewProviderDrawingView()
Expand Down Expand Up @@ -148,7 +148,7 @@ ViewProviderDrawingClip::ViewProviderDrawingClip()
sPixmap = "Page";

// Do not show in property editor
DisplayMode.StatusBits.set(3, true);
DisplayMode.setStatus(App::Property::Hidden, true);
}

ViewProviderDrawingClip::~ViewProviderDrawingClip()
Expand Down
12 changes: 6 additions & 6 deletions src/Mod/Fem/App/FemResultObject.cpp
Expand Up @@ -47,12 +47,12 @@ FemResultObject::FemResultObject()
ADD_PROPERTY_TYPE(EigenmodeFrequency,(0), "Fem",Prop_None,"Frequency of the eigenmode");

// make read-only for property editor
NodeNumbers.StatusBits.set(2, true);
DisplacementVectors.StatusBits.set(2, true);
DisplacementLengths.StatusBits.set(2, true);
StressValues.StatusBits.set(2, true);
Eigenmode.StatusBits.set(2, true);
EigenmodeFrequency.StatusBits.set(2, true);
NodeNumbers.setStatus(App::Property::ReadOnly, true);
DisplacementVectors.setStatus(App::Property::ReadOnly, true);
DisplacementLengths.setStatus(App::Property::ReadOnly, true);
StressValues.setStatus(App::Property::ReadOnly, true);
Eigenmode.setStatus(App::Property::ReadOnly, true);
EigenmodeFrequency.setStatus(App::Property::ReadOnly, true);
}

FemResultObject::~FemResultObject()
Expand Down
8 changes: 4 additions & 4 deletions src/Mod/Part/App/FeaturePartBox.cpp
Expand Up @@ -178,7 +178,7 @@ void Box::Restore(Base::XMLReader &reader)
if (location_xyz) {
plm.setPosition(Base::Vector3d(x.getValue(),y.getValue(),z.getValue()));
this->Placement.setValue(this->Placement.getValue() * plm);
this->Shape.StatusBits.set(10); // override the shape's location later on
this->Shape.setStatus(App::Property::User1, true); // override the shape's location later on
}
// for 0.8 releases
else if (location_axis) {
Expand All @@ -189,7 +189,7 @@ void Box::Restore(Base::XMLReader &reader)
plm.setRotation(rot);
plm.setPosition(Base::Vector3d(p.x,p.y,p.z));
this->Placement.setValue(this->Placement.getValue() * plm);
this->Shape.StatusBits.set(10); // override the shape's location later on
this->Shape.setStatus(App::Property::User1, true); // override the shape's location later on
}

reader.readEndElement("Properties");
Expand All @@ -205,8 +205,8 @@ void Box::onChanged(const App::Property* prop)
}
else if (prop == &this->Shape) {
// see Box::Restore
if (this->Shape.StatusBits.test(10)) {
this->Shape.StatusBits.reset(10);
if (this->Shape.testStatus(App::Property::User1)) {
this->Shape.setStatus(App::Property::User1, false);
App::DocumentObjectExecReturn *ret = recompute();
delete ret;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/App/FeatureDressUp.cpp
Expand Up @@ -60,7 +60,7 @@ void DressUp::onChanged(const App::Property* prop)
{
if (prop == &Base) {
// if attached to a sketch then mark it as read-only
this->Placement.StatusBits.set(2, Base.getValue() != 0);
this->Placement.setStatus(App::Property::ReadOnly, Base.getValue() != 0);
}

Feature::onChanged(prop);
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/App/FeatureSketchBased.cpp
Expand Up @@ -243,7 +243,7 @@ void SketchBased::onChanged(const App::Property* prop)
{
if (prop == &Sketch) {
// if attached to a sketch then mark it as read-only
this->Placement.StatusBits.set(2, Sketch.getValue() != 0);
this->Placement.setStatus(App::Property::ReadOnly, Sketch.getValue() != 0);
}

Feature::onChanged(prop);
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/App/FeatureTransformed.cpp
Expand Up @@ -60,7 +60,7 @@ Transformed::Transformed() : rejected(0)
{
ADD_PROPERTY(Originals,(0));
Originals.setSize(0);
Placement.StatusBits.set(2, true);
Placement.setStatus(App::Property::ReadOnly, true);
}

void Transformed::positionBySupport(void)
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Points/App/ViewFeature.cpp
Expand Up @@ -70,8 +70,8 @@ ViewFeature::ViewFeature()
ADD_PROPERTY_TYPE(Height,(0), "View", type, "The height of the point view");
ADD_PROPERTY_TYPE(Direction ,(Base::Vector3d(0,0,1)), "View", type, "The direction of the point view");

Width.StatusBits.set(2, true);
Height.StatusBits.set(2, true);
Width.setStatus(App::Property::ReadOnly, true);
Height.setStatus(App::Property::ReadOnly, true);
}

ViewFeature::~ViewFeature()
Expand Down

0 comments on commit 50d7793

Please sign in to comment.