+ introduce proper enum for property status to replace plain integers
This commit is contained in:
parent
342198ea87
commit
50d7793442
|
@ -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 @@ public:
|
|||
/// 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;
|
||||
|
@ -116,18 +146,18 @@ public:
|
|||
|
||||
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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
{
|
||||
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) {
|
||||
|
|
|
@ -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<PropInfo>::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<PropInfo>::iterator pi = std::find_if(propViewMap.begin(), propViewMap.end(), PropFind(nameType));
|
||||
if (pi != propViewMap.end()) {
|
||||
pi->propList.push_back(pt->second);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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*>
|
||||
|
@ -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*>
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<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());
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user