Fem: Constraint symbol scaling (#13274)
* Fem: Constraint symbols rescaling * Fem: Add constraint symbol .iv files * Fem: Fix contact constraint symbol rescaling * Fem: Fix displacement constraint symbol rescaling * Fem: Fix fixed constraint symbol rescaling * Fem: Fix force constraint symbol rescaling * Fem: Fix heat flux constraint symbol rescaling * Fem: Fix plane rotation constraint symbol rescaling * Fem: Fix pressure constraint symbol rescaling * Fem: Fix spring constraint symbol rescaling * Fem: Fix temperature constraint symbol rescaling * Fem: Add tie constraint symbol
This commit is contained in:
@@ -24,11 +24,9 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
#include <Inventor/SbMatrix.h>
|
||||
#include <Inventor/SbRotation.h>
|
||||
#include <Inventor/SbVec3f.h>
|
||||
#include <Inventor/nodes/SoMultipleCopy.h>
|
||||
#include <Inventor/nodes/SoSeparator.h>
|
||||
#include <Precision.hxx>
|
||||
#include <QMessageBox>
|
||||
#endif
|
||||
|
||||
@@ -47,6 +45,7 @@ PROPERTY_SOURCE(FemGui::ViewProviderFemConstraintForce, FemGui::ViewProviderFemC
|
||||
ViewProviderFemConstraintForce::ViewProviderFemConstraintForce()
|
||||
{
|
||||
sPixmap = "FEM_ConstraintForce";
|
||||
loadSymbol((resourceSymbolDir + "ConstraintForce.iv").c_str());
|
||||
}
|
||||
|
||||
ViewProviderFemConstraintForce::~ViewProviderFemConstraintForce() = default;
|
||||
@@ -109,117 +108,41 @@ bool ViewProviderFemConstraintForce::setEdit(int ModNum)
|
||||
}
|
||||
}
|
||||
|
||||
#define ARROWLENGTH (4)
|
||||
#define ARROWHEADRADIUS (ARROWLENGTH / 3.0f)
|
||||
// #define USE_MULTIPLE_COPY //OvG: MULTICOPY fails to update scaled arrows on initial drawing - so
|
||||
// disable
|
||||
|
||||
void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
|
||||
{
|
||||
// Gets called whenever a property of the attached object changes
|
||||
Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(this->getObject());
|
||||
float scaledheadradius =
|
||||
ARROWHEADRADIUS * pcConstraint->Scale.getValue(); // OvG: Calculate scaled values once only
|
||||
float scaledlength = ARROWLENGTH * pcConstraint->Scale.getValue();
|
||||
auto pcConstraint = static_cast<Fem::ConstraintForce*>(this->getObject());
|
||||
|
||||
#ifdef USE_MULTIPLE_COPY
|
||||
// OvG: 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*)createArrow(scaledlength, scaledheadradius)); // OvG: Scaling
|
||||
pShapeSep->addChild(cp);
|
||||
if (prop == &pcConstraint->Reversed || prop == &pcConstraint->DirectionVector) {
|
||||
updateSymbol();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (prop == &pcConstraint->Points) {
|
||||
const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues();
|
||||
|
||||
#ifdef USE_MULTIPLE_COPY
|
||||
cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0));
|
||||
cp->matrix.setNum(points.size());
|
||||
SbMatrix* matrices = cp->matrix.startEditing();
|
||||
int idx = 0;
|
||||
#else
|
||||
// Redraw all arrows
|
||||
Gui::coinRemoveAllChildren(pShapeSep);
|
||||
#endif
|
||||
// This should always point outside of the solid
|
||||
Base::Vector3d normal = pcConstraint->NormalDirection.getValue();
|
||||
|
||||
// Get default direction (on first call to method)
|
||||
Base::Vector3d forceDirection = pcConstraint->DirectionVector.getValue();
|
||||
if (forceDirection.Length() < Precision::Confusion()) {
|
||||
forceDirection = normal;
|
||||
}
|
||||
|
||||
SbVec3f dir(forceDirection.x, forceDirection.y, forceDirection.z);
|
||||
SbRotation rot(SbVec3f(0, 1, 0), dir);
|
||||
|
||||
for (const auto& point : points) {
|
||||
SbVec3f base(point.x, point.y, point.z);
|
||||
if (forceDirection.GetAngle(normal)
|
||||
< M_PI_2) { // Move arrow so it doesn't disappear inside the solid
|
||||
base = base + dir * scaledlength; // OvG: Scaling
|
||||
}
|
||||
#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);
|
||||
createArrow(sep, scaledlength, scaledheadradius); // OvG: Scaling
|
||||
pShapeSep->addChild(sep);
|
||||
#endif
|
||||
}
|
||||
#ifdef USE_MULTIPLE_COPY
|
||||
cp->matrix.finishEditing();
|
||||
#endif
|
||||
else {
|
||||
ViewProviderFemConstraint::updateData(prop);
|
||||
}
|
||||
else if (prop == &pcConstraint->DirectionVector) {
|
||||
// Note: "Reversed" also triggers "DirectionVector"
|
||||
// Re-orient all arrows
|
||||
Base::Vector3d normal = pcConstraint->NormalDirection.getValue();
|
||||
Base::Vector3d forceDirection = pcConstraint->DirectionVector.getValue();
|
||||
if (forceDirection.Length() < Precision::Confusion()) {
|
||||
forceDirection = normal;
|
||||
}
|
||||
|
||||
SbVec3f dir(forceDirection.x, forceDirection.y, forceDirection.z);
|
||||
SbRotation rot(SbVec3f(0, 1, 0), dir);
|
||||
|
||||
const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues();
|
||||
|
||||
#ifdef USE_MULTIPLE_COPY
|
||||
SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0));
|
||||
cp->matrix.setNum(points.size());
|
||||
SbMatrix* matrices = cp->matrix.startEditing();
|
||||
#endif
|
||||
int idx = 0;
|
||||
|
||||
for (const auto& point : points) {
|
||||
SbVec3f base(point.x, point.y, point.z);
|
||||
if (forceDirection.GetAngle(normal) < M_PI_2) {
|
||||
base = base + dir * scaledlength; // OvG: Scaling
|
||||
}
|
||||
#ifdef USE_MULTIPLE_COPY
|
||||
SbMatrix m;
|
||||
m.setTransform(base, rot, SbVec3f(1, 1, 1));
|
||||
matrices[idx] = m;
|
||||
#else
|
||||
SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(idx));
|
||||
updatePlacement(sep, 0, base, rot);
|
||||
updateArrow(sep, 2, scaledlength, scaledheadradius); // OvG: Scaling
|
||||
#endif
|
||||
idx++;
|
||||
}
|
||||
#ifdef USE_MULTIPLE_COPY
|
||||
cp->matrix.finishEditing();
|
||||
#endif
|
||||
}
|
||||
|
||||
ViewProviderFemConstraint::updateData(prop);
|
||||
}
|
||||
|
||||
void ViewProviderFemConstraintForce::transformSymbol(const Base::Vector3d& point,
|
||||
const Base::Vector3d& normal,
|
||||
SbMatrix& mat) const
|
||||
{
|
||||
auto obj = static_cast<const Fem::ConstraintForce*>(this->getObject());
|
||||
bool rev = obj->Reversed.getValue();
|
||||
float s = obj->getScaleFactor();
|
||||
// Symbol length from .iv file
|
||||
float symLen = 4.0f;
|
||||
// Place each symbol outside the boundary
|
||||
Base::Vector3d dir = (rev ? -1.0 : 1.0) * obj->DirectionVector.getValue();
|
||||
float symTraY = dir.Dot(normal) < 0 ? -1 * symLen : 0.0f;
|
||||
float rotAngle = rev ? F_PI : 0.0f;
|
||||
SbMatrix mat0, mat1;
|
||||
mat0.setTransform(SbVec3f(0, symTraY, 0),
|
||||
SbRotation(SbVec3f(0, 0, 1), rotAngle),
|
||||
SbVec3f(1, 1, 1),
|
||||
SbRotation(SbVec3f(0, 0, 1), 0),
|
||||
SbVec3f(0, symLen / 2.0f, 0));
|
||||
|
||||
mat1.setTransform(SbVec3f(point.x, point.y, point.z),
|
||||
SbRotation(SbVec3f(0, 1, 0), SbVec3f(dir.x, dir.y, dir.z)),
|
||||
SbVec3f(s, s, s));
|
||||
|
||||
mat = mat0 * mat1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user