Merge pull request #24201 from marioalexis84/fem-fix_plane_function
Fem:Fix plane manipulator - fixes #14523
This commit is contained in:
@@ -2468,6 +2468,10 @@ void CmdFemPostFunctions::activated(int iMsg)
|
||||
center[0],
|
||||
center[1],
|
||||
center[2]);
|
||||
doCommand(Doc,
|
||||
"Gui.ActiveDocument.%s.Scale = %f",
|
||||
FeatName.c_str(),
|
||||
box.GetDiagonalLength());
|
||||
}
|
||||
else if (iMsg == 1) { // Sphere
|
||||
doCommand(Doc,
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <Inventor/actions/SoSearchAction.h>
|
||||
#include <Inventor/draggers/SoDragPointDragger.h>
|
||||
#include <Inventor/draggers/SoHandleBoxDragger.h>
|
||||
#include <Inventor/draggers/SoJackDragger.h>
|
||||
#include <Inventor/manips/SoCenterballManip.h>
|
||||
@@ -759,17 +760,17 @@ static const App::PropertyFloatConstraint::Constraints scaleConstraint = {
|
||||
1.0};
|
||||
|
||||
ViewProviderFemPostPlaneFunction::ViewProviderFemPostPlaneFunction()
|
||||
: m_detectscale(false)
|
||||
: m_detectscale {true}
|
||||
{
|
||||
ADD_PROPERTY_TYPE(Scale,
|
||||
(1000.0),
|
||||
(10),
|
||||
"Manipulator",
|
||||
App::Prop_None,
|
||||
"Scaling factor for the manipulator");
|
||||
Scale.setConstraints(&scaleConstraint);
|
||||
sPixmap = "fem-post-geo-plane";
|
||||
|
||||
setAutoScale(true);
|
||||
setAutoScale(false);
|
||||
|
||||
// setup the visualisation geometry
|
||||
getGeometryNode()->addChild(ShapeNodes::postPlane());
|
||||
@@ -786,7 +787,7 @@ void ViewProviderFemPostPlaneFunction::draggerUpdate(SoDragger* m)
|
||||
const SbVec3f& base = dragger->translation.getValue();
|
||||
const SbVec3f& scale = dragger->scaleFactor.getValue();
|
||||
|
||||
SbVec3f norm(0.0, 1.0, 0.0);
|
||||
SbVec3f norm(0.0, 0.0, 1.0);
|
||||
dragger->rotation.getValue().multVec(norm, norm);
|
||||
func->Origin.setValue(base[0], base[1], base[2]);
|
||||
func->Normal.setValue(norm[0], norm[1], norm[2]);
|
||||
@@ -795,27 +796,25 @@ void ViewProviderFemPostPlaneFunction::draggerUpdate(SoDragger* m)
|
||||
|
||||
void ViewProviderFemPostPlaneFunction::onChanged(const App::Property* prop)
|
||||
{
|
||||
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(); // clazy:exclude=rule-of-two-soft
|
||||
matrix.getTransform(t, r, s, so);
|
||||
|
||||
float scale = static_cast<float>(Scale.getValue());
|
||||
s.setValue(scale, scale, scale);
|
||||
|
||||
matrix.setTransform(t, r, s, so);
|
||||
getManipulator()->setMatrix(matrix);
|
||||
}
|
||||
if (prop == &Scale && m_detectscale) {
|
||||
// Scale property detected at restore
|
||||
m_detectscale = false;
|
||||
}
|
||||
|
||||
if (prop == &Scale && !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<float>(Scale.getValue());
|
||||
s.setValue(scale, scale, scale);
|
||||
|
||||
matrix.setTransform(t, r, s, so);
|
||||
getManipulator()->setMatrix(matrix);
|
||||
}
|
||||
|
||||
ViewProviderFemPostFunction::onChanged(prop);
|
||||
}
|
||||
|
||||
@@ -824,32 +823,39 @@ void ViewProviderFemPostPlaneFunction::updateData(const App::Property* p)
|
||||
Fem::FemPostPlaneFunction* func = getObject<Fem::FemPostPlaneFunction>();
|
||||
|
||||
if (!isDragging() && (p == &func->Origin || p == &func->Normal)) {
|
||||
if (!m_detectscale) {
|
||||
// Auto-scale from geometry size at restore
|
||||
if (m_detectscale) {
|
||||
double s;
|
||||
if (findScaleFactor(s)) {
|
||||
m_detectscale = true;
|
||||
this->Scale.setValue(s);
|
||||
bool find = findScaleFactor(s);
|
||||
if (find) {
|
||||
Scale.setValue(s);
|
||||
m_detectscale = false;
|
||||
}
|
||||
}
|
||||
|
||||
Base::Vector3d trans = func->Origin.getValue();
|
||||
Base::Vector3d norm = func->Normal.getValue();
|
||||
|
||||
norm.Normalize();
|
||||
SbRotation rot(SbVec3f(0.0, 1.0, 0.0), SbVec3f(norm.x, norm.y, norm.z));
|
||||
SbRotation rot(SbVec3f(0.0, 0.0, 1.0), SbVec3f(norm.x, norm.y, norm.z));
|
||||
float scale = static_cast<float>(Scale.getValue());
|
||||
|
||||
SbMatrix mat;
|
||||
mat.setTransform(SbVec3f(trans.x, trans.y, trans.z), rot, SbVec3f(scale, scale, scale));
|
||||
getManipulator()->setMatrix(mat);
|
||||
}
|
||||
|
||||
Gui::ViewProviderDocumentObject::updateData(p);
|
||||
}
|
||||
|
||||
|
||||
SoTransformManip* ViewProviderFemPostPlaneFunction::setupManipulator()
|
||||
{
|
||||
return new SoJackManip;
|
||||
auto manip = new SoJackManip;
|
||||
|
||||
// Set axis translator to Z-axis
|
||||
SoNode* trans = manip->getDragger()->getPart("translator", false);
|
||||
static_cast<SoDragPointDragger*>(trans)->showNextDraggerSet();
|
||||
|
||||
return manip;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user