diff --git a/src/Mod/Fem/App/FemPostFunction.cpp b/src/Mod/Fem/App/FemPostFunction.cpp index 6b1034402c..1da8e93f56 100644 --- a/src/Mod/Fem/App/FemPostFunction.cpp +++ b/src/Mod/Fem/App/FemPostFunction.cpp @@ -96,6 +96,11 @@ void FemPostPlaneFunction::onChanged(const Property* prop) { Fem::FemPostFunction::onChanged(prop); } +void FemPostPlaneFunction::onDocumentRestored() { + // This is to notify the view provider that the document has been fully restored + Normal.touch(); +} + diff --git a/src/Mod/Fem/App/FemPostFunction.h b/src/Mod/Fem/App/FemPostFunction.h index 8fc94e246c..ee3bb1495b 100644 --- a/src/Mod/Fem/App/FemPostFunction.h +++ b/src/Mod/Fem/App/FemPostFunction.h @@ -102,6 +102,8 @@ public: protected: virtual void onChanged(const App::Property* prop); + /// get called after a document has been fully restored + virtual void onDocumentRestored(); vtkSmartPointer m_plane; }; diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp index 1a69fd0e39..8169fedc2b 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp @@ -52,8 +52,11 @@ #include #include #include +#include +#include #include #include +#include #include "ViewProviderFemPostFunction.h" #include "ActiveAnalysisObserver.h" @@ -247,6 +250,32 @@ void ViewProviderFemPostFunction::attach(App::DocumentObject* pcObj) pcEditNode->unref(); } +SbBox3f ViewProviderFemPostFunction::getBoundingsOfView() const +{ + SbBox3f box; + Gui::Document* doc = this->getDocument(); + Gui::View3DInventor* view = qobject_cast(doc->getViewOfViewProvider(this)); + if (view) { + Gui::View3DInventorViewer* viewer = view->getViewer(); + box = viewer->getBoundingBox(); + } + + return box; +} + +bool ViewProviderFemPostFunction::findScaleFactor(double& scale) const +{ + SbBox3f bbox = getBoundingsOfView(); + if (bbox.hasVolume()) { + float dx, dy, dz; + bbox.getSize(dx, dy, dz); + scale = 0.2 * std::max(std::max(dx, dy), dz); + return true; + } + + return false; +} + bool ViewProviderFemPostFunction::doubleClicked(void) { Gui::Application::Instance->activeDocument()->setEdit(this, (int)ViewProvider::Default); return true; @@ -357,11 +386,14 @@ void ViewProviderFemPostFunction::onChanged(const App::Property* prop) { // *************************************************************************** PROPERTY_SOURCE(FemGui::ViewProviderFemPostPlaneFunction, FemGui::ViewProviderFemPostFunction) -static const App::PropertyFloatConstraint::Constraints scaleConstraint = {1.0e-6, 1.0e6, 1.0}; +//NOTE: The technical lower limit is at 1e-4 that the Coin3D manipulator can handle +static const App::PropertyFloatConstraint::Constraints scaleConstraint = {1e-4, DBL_MAX, 1.0}; -ViewProviderFemPostPlaneFunction::ViewProviderFemPostPlaneFunction() { +ViewProviderFemPostPlaneFunction::ViewProviderFemPostPlaneFunction() + : m_detectscale(false) +{ - ADD_PROPERTY_TYPE(Scale, (1.0), "Manipulator", App::Prop_None, "Scaling factor for the manipulator"); + ADD_PROPERTY_TYPE(Scale, (1000.0), "Manipulator", App::Prop_None, "Scaling factor for the manipulator"); Scale.setConstraints(&scaleConstraint); sPixmap = "fem-post-geo-plane"; @@ -402,18 +434,23 @@ void ViewProviderFemPostPlaneFunction::draggerUpdate(SoDragger* m) { void ViewProviderFemPostPlaneFunction::onChanged(const App::Property* prop) { - if (!isDragging() && prop == &Scale) { - // get current matrix - SbVec3f t, s; - SbRotation r, so; - SbMatrix matrix = getManipulator()->getDragger()->getMotionMatrix(); - matrix.getTransform(t, r, s, so); + if (prop == &Scale) { + // When loading the Scale property from a project then keep that + if (Scale.getConstraints()) + m_detectscale = true; + if (!isDragging()) { + // get current matrix + SbVec3f t, s; + SbRotation r, so; + SbMatrix matrix = getManipulator()->getDragger()->getMotionMatrix(); + matrix.getTransform(t, r, s, so); - float scale = static_cast(Scale.getValue()); - s.setValue(scale, scale, scale); + float scale = static_cast(Scale.getValue()); + s.setValue(scale, scale, scale); - matrix.setTransform(t, r, s, so); - getManipulator()->setMatrix(matrix); + matrix.setTransform(t, r, s, so); + getManipulator()->setMatrix(matrix); + } } ViewProviderFemPostFunction::onChanged(prop); } @@ -423,6 +460,13 @@ void ViewProviderFemPostPlaneFunction::updateData(const App::Property* p) { Fem::FemPostPlaneFunction* func = static_cast(getObject()); if (!isDragging() && (p == &func->Origin || p == &func->Normal)) { + if (!m_detectscale) { + double s; + if (findScaleFactor(s)) { + m_detectscale = true; + this->Scale.setValue(s); + } + } Base::Vector3d trans = func->Origin.getValue(); Base::Vector3d norm = func->Normal.getValue(); diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h index 760105884a..976d60481f 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -127,6 +128,8 @@ protected: bool autoScale() {return m_autoscale;} bool isDragging() {return m_isDragging;} + SbBox3f getBoundingsOfView() const; + bool findScaleFactor(double& scale) const; virtual SoTransformManip* setupManipulator(); virtual void draggerUpdate(SoDragger*) {} @@ -185,6 +188,9 @@ protected: virtual void draggerUpdate(SoDragger* mat); virtual void updateData(const App::Property*); virtual void onChanged(const App::Property*); + +private: + bool m_detectscale; };