From 03dc23497088091ffc1159c3815f52291fddec1c Mon Sep 17 00:00:00 2001 From: marioalexis Date: Wed, 8 May 2024 10:13:26 -0300 Subject: [PATCH] Fem: Update view provider of the rigid body constraint --- src/Mod/Fem/Gui/CMakeLists.txt | 1 + .../Resources/symbols/ConstraintRigidBody.iv | 32 +++++++ .../ViewProviderFemConstraintRigidBody.cpp | 96 ++++++------------- .../Gui/ViewProviderFemConstraintRigidBody.h | 2 + 4 files changed, 62 insertions(+), 69 deletions(-) create mode 100644 src/Mod/Fem/Gui/Resources/symbols/ConstraintRigidBody.iv diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 2842895ba4..65d871e137 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -360,6 +360,7 @@ SET(FemGuiSymbol_IV Resources/symbols/ConstraintHeatFlux.iv Resources/symbols/ConstraintPlaneRotation.iv Resources/symbols/ConstraintPressure.iv + Resources/symbols/ConstraintRigidBody.iv Resources/symbols/ConstraintSpring.iv Resources/symbols/ConstraintTemperature.iv Resources/symbols/ConstraintTie.iv diff --git a/src/Mod/Fem/Gui/Resources/symbols/ConstraintRigidBody.iv b/src/Mod/Fem/Gui/Resources/symbols/ConstraintRigidBody.iv new file mode 100644 index 0000000000..66d3d0fc8b --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/symbols/ConstraintRigidBody.iv @@ -0,0 +1,32 @@ +#Inventor V2.1 ascii + + +Separator { + + Separator { + + Translation { + translation 0 2.5 0 + } + Sphere { + radius 0.5 + + } + Translation { + translation 0 -1.25 0 + + } + Cylinder { + radius 0.25 + height 2.5 + + } + } + Separator { + + Sphere { + radius 0.25 + + } + } +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintRigidBody.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintRigidBody.cpp index d7a7f23430..0364b65b12 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraintRigidBody.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintRigidBody.cpp @@ -24,17 +24,14 @@ #ifndef _PreComp_ #include -#include -#include -#include -#include +#include #endif -#include #include "Gui/Control.h" +#include -#include "ViewProviderFemConstraintRigidBody.h" #include "TaskFemConstraintRigidBody.h" +#include "ViewProviderFemConstraintRigidBody.h" using namespace FemGui; @@ -46,10 +43,11 @@ PROPERTY_SOURCE(FemGui::ViewProviderFemConstraintRigidBody, ViewProviderFemConstraintRigidBody::ViewProviderFemConstraintRigidBody() { sPixmap = "FEM_ConstraintRigidBody"; + loadSymbol((resourceSymbolDir + "ConstraintRigidBody.iv").c_str()); + ShapeAppearance.setDiffuseColor(0.0f, 0.5f, 0.0f); } -ViewProviderFemConstraintRigidBody::~ViewProviderFemConstraintRigidBody() -{} +ViewProviderFemConstraintRigidBody::~ViewProviderFemConstraintRigidBody() = default; bool ViewProviderFemConstraintRigidBody::setEdit(int ModNum) { @@ -110,71 +108,31 @@ bool ViewProviderFemConstraintRigidBody::setEdit(int ModNum) } } -#define WIDTH (2) -#define HEIGHT (1) -// #define USE_MULTIPLE_COPY //OvG: MULTICOPY fails to update scaled display on initial drawing - -// so disable - void ViewProviderFemConstraintRigidBody::updateData(const App::Property* prop) { - // Gets called whenever a property of the attached object changes - Fem::ConstraintRigidBody* pcConstraint = - static_cast(this->getObject()); - float scaledwidth = - WIDTH * pcConstraint->Scale.getValue(); // OvG: Calculate scaled values once only - float scaledheight = HEIGHT * pcConstraint->Scale.getValue(); + auto obj = static_cast(this->getObject()); -#ifdef USE_MULTIPLE_COPY - // OvG: always need access to cp for scaling - SoMultipleCopy* cp = new SoMultipleCopy(); - if (pShapeSep->getNumChildren() == 0) { - // Set up the nodes - cp->matrix.setNum(0); - cp->addChild((SoNode*)createRigidBody(scaledheight, scaledwidth)); // OvG: Scaling - pShapeSep->addChild(cp); - } -#endif - - if (strcmp(prop->getName(), "Points") == 0) { - const std::vector& points = pcConstraint->Points.getValues(); - const std::vector& normals = pcConstraint->Normals.getValues(); - if (points.size() != normals.size()) { - return; - } - std::vector::const_iterator n = normals.begin(); - -#ifdef USE_MULTIPLE_COPY - cp = static_cast(pShapeSep->getChild(0)); - cp->matrix.setNum(points.size()); - SbMatrix* matrices = cp->matrix.startEditing(); - int idx = 0; -#else - // Note: Points and Normals are always updated together - Gui::coinRemoveAllChildren(pShapeSep); -#endif - - for (std::vector::const_iterator p = points.begin(); p != points.end(); - p++) { - SbVec3f base(p->x, p->y, p->z); - SbVec3f dir(n->x, n->y, n->z); - SbRotation rot(SbVec3f(0, -1, 0), dir); -#ifdef USE_MULTIPLE_COPY - SbMatrix m; - m.setTransform(base, rot, SbVec3f(1, 1, 1)); - matrices[idx] = m; - idx++; -#else - SoSeparator* sep = new SoSeparator(); - createPlacement(sep, base, rot); - createFixed(sep, scaledheight, scaledwidth); // OvG: Scaling - pShapeSep->addChild(sep); -#endif - n++; - } -#ifdef USE_MULTIPLE_COPY - cp->matrix.finishEditing(); -#endif + if (prop == &obj->ReferenceNode) { + updateSymbol(); } ViewProviderFemConstraint::updateData(prop); } + +void ViewProviderFemConstraintRigidBody::transformExtraSymbol() const +{ + SoTransform* symTrans = getExtraSymbolTransform(); + if (symTrans) { + auto obj = static_cast(this->getObject()); + float s = obj->getScaleFactor(); + const Base::Vector3d& refNode = obj->ReferenceNode.getValue(); + SbVec3f tra(refNode.x, refNode.y, refNode.z); + SbVec3f sca(s, s, s); + SbRotation rot(SbVec3f(0, 0, 1), 0); + + SbMatrix mat; + mat.setTransform(tra, rot, sca); + + symTrans->setMatrix(mat); + } +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintRigidBody.h b/src/Mod/Fem/Gui/ViewProviderFemConstraintRigidBody.h index 19008b3c15..5f35b4e0f8 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraintRigidBody.h +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintRigidBody.h @@ -43,6 +43,8 @@ public: protected: bool setEdit(int ModNum) override; + + void transformExtraSymbol() const override; }; } // namespace FemGui