diff --git a/src/Mod/Part/App/AttachableObject.cpp b/src/Mod/Part/App/AttachableObject.cpp index 300920a2db..823ab2c9c1 100644 --- a/src/Mod/Part/App/AttachableObject.cpp +++ b/src/Mod/Part/App/AttachableObject.cpp @@ -70,15 +70,17 @@ void AttachableObject::setAttacher(AttachEngine* attacher) updateAttacherVals(); } -void AttachableObject::positionBySupport() +bool AttachableObject::positionBySupport() { if (!_attacher) throw Base::Exception("AttachableObject: can't positionBySupport, because no AttachEngine is set."); updateAttacherVals(); try{ this->Placement.setValue(_attacher->calculateAttachedPlacement(this->Placement.getValue())); + return true; } catch (ExceptionCancel) { //disabled, don't do anything + return false; }; } @@ -107,6 +109,7 @@ void setReadonlyness(App::Property &prop, bool on) void AttachableObject::onChanged(const App::Property* prop) { if(! this->isRestoring()){ + bool bAttached = false; try{ if ((prop == &Support || prop == &MapMode @@ -114,11 +117,7 @@ void AttachableObject::onChanged(const App::Property* prop) || prop == &MapReversed || prop == &superPlacement)){ - eMapMode mmode = eMapMode(this->MapMode.getValue()); - setReadonlyness(this->superPlacement, mmode == mmDeactivated); - setReadonlyness(this->Placement, mmode != mmDeactivated && mmode != mmTranslate); - - positionBySupport(); + bAttached = positionBySupport(); } } catch (Base::Exception &e) { this->setError(); @@ -128,6 +127,11 @@ void AttachableObject::onChanged(const App::Property* prop) this->setError(); Base::Console().Error("PositionBySupport: %s",e.GetMessageString()); } + + eMapMode mmode = eMapMode(this->MapMode.getValue()); + setReadonlyness(this->superPlacement, !bAttached); + setReadonlyness(this->Placement, bAttached && mmode != mmTranslate); //for mmTranslate, orientation should remain editable even when attached. + } Part::Feature::onChanged(prop); } diff --git a/src/Mod/Part/App/AttachableObject.h b/src/Mod/Part/App/AttachableObject.h index 6ff41eccb8..0a3044265b 100644 --- a/src/Mod/Part/App/AttachableObject.h +++ b/src/Mod/Part/App/AttachableObject.h @@ -84,9 +84,10 @@ public: App::PropertyFloat MapPathParameter; /** calculate and update the Placement property based on the Support, and - * mode. Can throw FreeCAD and OCC exceptions. + * mode. Can throw FreeCAD and OCC exceptions. Returns true if attached, + * false if not, throws if attachment failed. */ - virtual void positionBySupport(void); + virtual bool positionBySupport(void); virtual bool isTouched_Mapping() {return true; /*support.isTouched isn't true when linked objects are changed... why?..*/}; diff --git a/src/Mod/Part/App/Part2DObjectPy.xml b/src/Mod/Part/App/Part2DObjectPy.xml index 782e28c693..4698128f17 100644 --- a/src/Mod/Part/App/Part2DObjectPy.xml +++ b/src/Mod/Part/App/Part2DObjectPy.xml @@ -15,7 +15,9 @@ - Reposition object based on Support, MapMode and MapPathParameter properties. + positionBySupport(): Reposition object based on Support, MapMode and MapPathParameter properties. +Returns True if attachment calculation was successful, false if object is not attached and Placement wasn't updated, +and raises an exception if attachment calculation fails. diff --git a/src/Mod/Part/App/Part2DObjectPyImp.cpp b/src/Mod/Part/App/Part2DObjectPyImp.cpp index 13ad5ef40c..ed5a01b2c0 100644 --- a/src/Mod/Part/App/Part2DObjectPyImp.cpp +++ b/src/Mod/Part/App/Part2DObjectPyImp.cpp @@ -20,8 +20,9 @@ PyObject* Part2DObjectPy::positionBySupport(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return 0; + bool bAttached = false; try{ - this->getPart2DObjectPtr()->positionBySupport(); + bAttached = this->getPart2DObjectPtr()->positionBySupport(); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); @@ -30,8 +31,7 @@ PyObject* Part2DObjectPy::positionBySupport(PyObject *args) PyErr_SetString(Base::BaseExceptionFreeCADError, e.what()); return NULL; } - Py_INCREF(Py_None); - return Py_None; + return Py::new_reference_to(Py::Boolean(bAttached)); }