diff --git a/src/Mod/Part/App/AttachExtension.cpp b/src/Mod/Part/App/AttachExtension.cpp index 0e6929b41a..cf16903dd7 100644 --- a/src/Mod/Part/App/AttachExtension.cpp +++ b/src/Mod/Part/App/AttachExtension.cpp @@ -119,6 +119,7 @@ bool AttachExtension::changeAttacherType(const char* typeName) bool AttachExtension::positionBySupport() { + _active = 0; if (!_attacher) throw Base::RuntimeError("AttachExtension: can't positionBySupport, because no AttachEngine is set."); updateAttacherVals(); @@ -126,6 +127,7 @@ bool AttachExtension::positionBySupport() if (_attacher->mapMode == mmDeactivated) return false; getPlacement().setValue(_attacher->calculateAttachedPlacement(getPlacement().getValue())); + _active = 1; return true; } catch (ExceptionCancel&) { //disabled, don't do anything @@ -133,6 +135,18 @@ bool AttachExtension::positionBySupport() }; } +bool AttachExtension::isAttacherActive() const { + if(_active < 0) { + _active = 0; + try { + _attacher->calculateAttachedPlacement(getPlacement().getValue()); + _active = 1; + } catch (ExceptionCancel&) { + } + } + return _active!=0; +} + short int AttachExtension::extensionMustExecute(void) { return DocumentObjectExtension::extensionMustExecute(); } @@ -258,12 +272,12 @@ void AttachExtension::updateAttacherVals() this->AttachmentOffset.getValue()); } -App::PropertyPlacement& AttachExtension::getPlacement() { - - if(!getExtendedObject()->isDerivedFrom(App::GeoFeature::getClassTypeId())) - throw Base::RuntimeError("AttachExtension not added to GeooFeature!"); - - return static_cast(getExtendedObject())->Placement; +App::PropertyPlacement& AttachExtension::getPlacement() const { + auto pla = Base::freecad_dynamic_cast( + getExtendedObject()->getPropertyByName("Placement")); + if(!pla) + throw Base::RuntimeError("AttachExtension cannot find placement property"); + return *pla; } PyObject* AttachExtension::getExtensionPyObject(void) { diff --git a/src/Mod/Part/App/AttachExtension.h b/src/Mod/Part/App/AttachExtension.h index 23cee0093f..75bf63da47 100644 --- a/src/Mod/Part/App/AttachExtension.h +++ b/src/Mod/Part/App/AttachExtension.h @@ -110,6 +110,10 @@ public: */ virtual bool positionBySupport(void); + /** Return whether this attacher is active + */ + bool isAttacherActive() const; + virtual bool isTouched_Mapping() {return true; /*support.isTouched isn't true when linked objects are changed... why?..*/} @@ -122,13 +126,14 @@ protected: virtual void extensionOnChanged(const App::Property* /*prop*/); virtual void extHandleChangedPropertyName(Base::XMLReader &reader, const char* TypeName, const char* PropName); - App::PropertyPlacement& getPlacement(); + App::PropertyPlacement& getPlacement() const; public: void updateAttacherVals(); private: Attacher::AttachEngine* _attacher; + mutable int _active = -1; }; diff --git a/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp b/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp index fc7b9044bc..bbedb010cb 100644 --- a/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp +++ b/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp @@ -51,16 +51,7 @@ QIcon ViewProviderAttachExtension::extensionMergeOverlayIcons(const QIcon & orig if (attach) { - bool attached = false; - - try{ - attached = attach->positionBySupport(); - } - catch (...) { // We are just trying to get an icon, if no placement can be calculated, set unattached. - // set unattached - } - - if(!attached) { + if(!attach->isAttacherActive()) { QPixmap px; static const char * const feature_detached_xpm[]={