diff --git a/src/App/Property.h b/src/App/Property.h index cd3908357983..89ad23216baa 100644 --- a/src/App/Property.h +++ b/src/App/Property.h @@ -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(); @@ -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 & 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(pos)); + } + inline void setStatus(Status pos, bool on) { + StatusBits.set(static_cast(pos), on); + } + //@} /// Returns a new copy of the property (mainly for Undo/Redo and transactions) virtual Property *Copy(void) const = 0; @@ -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); diff --git a/src/App/PropertyContainerPyImp.cpp b/src/App/PropertyContainerPyImp.cpp index 879873970859..3ab96b856ef1 100644 --- a/src/App/PropertyContainerPyImp.cpp +++ b/src/App/PropertyContainerPyImp.cpp @@ -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; } @@ -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; @@ -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); diff --git a/src/Gui/Placement.cpp b/src/Gui/Placement.cpp index 5b6d35929834..0902f0dbaf58 100644 --- a/src/Gui/Placement.cpp +++ b/src/Gui/Placement.cpp @@ -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) { diff --git a/src/Gui/PropertyView.cpp b/src/Gui/PropertyView.cpp index 8161e20ae447..e2253a1b7fd8 100644 --- a/src/Gui/PropertyView.cpp +++ b/src/Gui/PropertyView.cpp @@ -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())) { @@ -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::iterator pi = std::find_if(propDataMap.begin(), propDataMap.end(), PropFind(nameType)); if (pi != propDataMap.end()) { pi->propList.push_back(*pt); @@ -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::iterator pi = std::find_if(propViewMap.begin(), propViewMap.end(), PropFind(nameType)); if (pi != propViewMap.end()) { pi->propList.push_back(pt->second); diff --git a/src/Gui/ViewProviderDocumentObject.cpp b/src/Gui/ViewProviderDocumentObject.cpp index d1f81ee66918..a3a650e02bcd 100644 --- a/src/Gui/ViewProviderDocumentObject.cpp +++ b/src/Gui/ViewProviderDocumentObject.cpp @@ -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); } } @@ -99,10 +99,10 @@ 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(); } @@ -110,10 +110,10 @@ void ViewProviderDocumentObject::hide(void) 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(); } diff --git a/src/Gui/ViewProviderDocumentObjectGroup.cpp b/src/Gui/ViewProviderDocumentObjectGroup.cpp index b9055a112145..bec1cb7e6ed9 100644 --- a/src/Gui/ViewProviderDocumentObjectGroup.cpp +++ b/src/Gui/ViewProviderDocumentObjectGroup.cpp @@ -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 & links = static_cast @@ -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 & links = static_cast @@ -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 } /** diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 5ed167461fc9..8897c2ea9dec 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -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); } @@ -318,7 +318,7 @@ void PropertyItem::setPropertyValue(const QString& value) for (std::vector::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()); } diff --git a/src/Mod/Drawing/Gui/ViewProviderPage.cpp b/src/Mod/Drawing/Gui/ViewProviderPage.cpp index c0f088137d96..e9836f51ccd6 100644 --- a/src/Mod/Drawing/Gui/ViewProviderPage.cpp +++ b/src/Mod/Drawing/Gui/ViewProviderPage.cpp @@ -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() diff --git a/src/Mod/Drawing/Gui/ViewProviderView.cpp b/src/Mod/Drawing/Gui/ViewProviderView.cpp index 60f91a702ffa..f8858d7e11ee 100644 --- a/src/Mod/Drawing/Gui/ViewProviderView.cpp +++ b/src/Mod/Drawing/Gui/ViewProviderView.cpp @@ -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() @@ -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() diff --git a/src/Mod/Fem/App/FemResultObject.cpp b/src/Mod/Fem/App/FemResultObject.cpp index 50c4a844bfc0..18bcf9fd49d8 100644 --- a/src/Mod/Fem/App/FemResultObject.cpp +++ b/src/Mod/Fem/App/FemResultObject.cpp @@ -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() diff --git a/src/Mod/Part/App/FeaturePartBox.cpp b/src/Mod/Part/App/FeaturePartBox.cpp index 8d56a698bd65..64152a745295 100644 --- a/src/Mod/Part/App/FeaturePartBox.cpp +++ b/src/Mod/Part/App/FeaturePartBox.cpp @@ -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) { @@ -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"); @@ -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; diff --git a/src/Mod/PartDesign/App/FeatureDressUp.cpp b/src/Mod/PartDesign/App/FeatureDressUp.cpp index b957fedfc480..4abaedf53d5d 100644 --- a/src/Mod/PartDesign/App/FeatureDressUp.cpp +++ b/src/Mod/PartDesign/App/FeatureDressUp.cpp @@ -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); diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index 32f20c2b594c..147e8fb20db6 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -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); diff --git a/src/Mod/PartDesign/App/FeatureTransformed.cpp b/src/Mod/PartDesign/App/FeatureTransformed.cpp index 01ef3ecc1eb1..1d3534b048e8 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.cpp +++ b/src/Mod/PartDesign/App/FeatureTransformed.cpp @@ -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) diff --git a/src/Mod/Points/App/ViewFeature.cpp b/src/Mod/Points/App/ViewFeature.cpp index 5f902e0d8bd6..4004e5013b6e 100644 --- a/src/Mod/Points/App/ViewFeature.cpp +++ b/src/Mod/Points/App/ViewFeature.cpp @@ -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()