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:
@@ -29,6 +29,7 @@
|
||||
#include <Inventor/nodes/SoCube.h>
|
||||
#include <Inventor/nodes/SoCylinder.h>
|
||||
#include <Inventor/nodes/SoFontStyle.h>
|
||||
#include <Inventor/nodes/SoMultipleCopy.h>
|
||||
#include <Inventor/nodes/SoRotation.h>
|
||||
#include <Inventor/nodes/SoSeparator.h>
|
||||
#include <Inventor/nodes/SoShapeHints.h>
|
||||
@@ -40,10 +41,12 @@
|
||||
#include <QStackedWidget>
|
||||
#endif
|
||||
|
||||
#include "App/Application.h"
|
||||
#include "Gui/Command.h"
|
||||
#include "Gui/Control.h"
|
||||
#include "Gui/Document.h"
|
||||
#include "Gui/MainWindow.h"
|
||||
#include "Mod/Fem/App/FemConstraint.h"
|
||||
|
||||
#include "TaskFemConstraint.h"
|
||||
#include "ViewProviderFemConstraint.h"
|
||||
@@ -56,6 +59,13 @@ PROPERTY_SOURCE(FemGui::ViewProviderFemConstraint, Gui::ViewProviderGeometryObje
|
||||
|
||||
|
||||
ViewProviderFemConstraint::ViewProviderFemConstraint()
|
||||
: rotateSymbol(true)
|
||||
, pSymbol(nullptr)
|
||||
, pExtraSymbol(nullptr)
|
||||
, ivFile(nullptr)
|
||||
, wizardWidget(nullptr)
|
||||
, wizardSubLayout(nullptr)
|
||||
, constraintDialog(nullptr)
|
||||
{
|
||||
ADD_PROPERTY(TextColor, (0.0f, 0.0f, 0.0f));
|
||||
ADD_PROPERTY(FaceColor, (1.0f, 0.0f, 0.2f));
|
||||
@@ -69,22 +79,19 @@ ViewProviderFemConstraint::ViewProviderFemConstraint()
|
||||
pLabel->ref();
|
||||
pTextColor = new SoBaseColor();
|
||||
pTextColor->ref();
|
||||
pShapeSep = new SoSeparator();
|
||||
pShapeSep->ref();
|
||||
pMultCopy = new SoMultipleCopy();
|
||||
pMultCopy->ref();
|
||||
|
||||
pMaterials = new SoBaseColor();
|
||||
pMaterials->ref();
|
||||
pMaterials->rgb.setValue(1.0f, 0.0f, 0.2f);
|
||||
|
||||
pShapeSep = new SoSeparator();
|
||||
pShapeSep->ref();
|
||||
|
||||
TextColor.touch();
|
||||
FontSize.touch();
|
||||
FaceColor.touch();
|
||||
|
||||
wizardWidget = nullptr;
|
||||
wizardSubLayout = nullptr;
|
||||
constraintDialog = nullptr;
|
||||
|
||||
Gui::ViewProviderSuppressibleExtension::initExtension(this);
|
||||
}
|
||||
|
||||
@@ -94,6 +101,7 @@ ViewProviderFemConstraint::~ViewProviderFemConstraint()
|
||||
pLabel->unref();
|
||||
pTextColor->unref();
|
||||
pMaterials->unref();
|
||||
pMultCopy->unref();
|
||||
pShapeSep->unref();
|
||||
}
|
||||
|
||||
@@ -115,6 +123,41 @@ void ViewProviderFemConstraint::attach(App::DocumentObject* pcObject)
|
||||
addDisplayMaskMode(sep, "Base");
|
||||
}
|
||||
|
||||
std::string ViewProviderFemConstraint::resourceSymbolDir =
|
||||
App::Application::getResourceDir() + "Mod/Fem/Resources/symbols/";
|
||||
|
||||
void ViewProviderFemConstraint::loadSymbol(const char* fileName)
|
||||
{
|
||||
ivFile = fileName;
|
||||
SoInput in;
|
||||
if (!in.openFile(ivFile)) {
|
||||
std::stringstream str;
|
||||
str << "Error opening symbol file " << fileName;
|
||||
throw Base::ImportError(str.str());
|
||||
}
|
||||
SoSeparator* nodes = SoDB::readAll(&in);
|
||||
if (!nodes) {
|
||||
std::stringstream str;
|
||||
str << "Error reading symbol file " << fileName;
|
||||
throw Base::ImportError(str.str());
|
||||
}
|
||||
|
||||
nodes->ref();
|
||||
pSymbol = dynamic_cast<SoSeparator*>(nodes->getChild(0));
|
||||
pShapeSep->addChild(pMultCopy);
|
||||
if (pSymbol) {
|
||||
pMultCopy->addChild(pSymbol);
|
||||
}
|
||||
if (nodes->getNumChildren() == 2) {
|
||||
pExtraSymbol = dynamic_cast<SoSeparator*>(nodes->getChild(1));
|
||||
if (pExtraSymbol) {
|
||||
pShapeSep->addChild(pExtraSymbol);
|
||||
}
|
||||
}
|
||||
pMultCopy->matrix.setNum(0);
|
||||
nodes->unref();
|
||||
}
|
||||
|
||||
std::vector<std::string> ViewProviderFemConstraint::getDisplayModes() const
|
||||
{
|
||||
// add modes
|
||||
@@ -148,7 +191,7 @@ void ViewProviderFemConstraint::setupContextMenu(QMenu* menu, QObject* receiver,
|
||||
|
||||
void ViewProviderFemConstraint::onChanged(const App::Property* prop)
|
||||
{
|
||||
if (prop == &Mirror || prop == &DistFactor) {
|
||||
if (prop == &Mirror) {
|
||||
updateData(prop);
|
||||
}
|
||||
else if (prop == &TextColor) {
|
||||
@@ -167,6 +210,51 @@ void ViewProviderFemConstraint::onChanged(const App::Property* prop)
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderFemConstraint::updateData(const App::Property* prop)
|
||||
{
|
||||
auto pcConstraint = static_cast<const Fem::Constraint*>(this->getObject());
|
||||
|
||||
if (prop == &pcConstraint->Points || prop == &pcConstraint->Normals
|
||||
|| prop == &pcConstraint->Scale) {
|
||||
updateSymbol();
|
||||
}
|
||||
else {
|
||||
ViewProviderGeometryObject::updateData(prop);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderFemConstraint::updateSymbol()
|
||||
{
|
||||
auto obj = static_cast<const Fem::Constraint*>(this->getObject());
|
||||
const std::vector<Base::Vector3d>& points = obj->Points.getValue();
|
||||
const std::vector<Base::Vector3d>& normals = obj->Normals.getValue();
|
||||
pMultCopy->matrix.setNum(points.size());
|
||||
SbMatrix* mat = pMultCopy->matrix.startEditing();
|
||||
|
||||
for (size_t i = 0; i < points.size(); ++i) {
|
||||
transformSymbol(points[i], normals[i], mat[i]);
|
||||
}
|
||||
|
||||
pMultCopy->matrix.finishEditing();
|
||||
}
|
||||
|
||||
void ViewProviderFemConstraint::transformSymbol(const Base::Vector3d& point,
|
||||
const Base::Vector3d& normal,
|
||||
SbMatrix& mat) const
|
||||
{
|
||||
auto obj = static_cast<const Fem::Constraint*>(this->getObject());
|
||||
SbVec3f axisY(0, 1, 0);
|
||||
float s = obj->getScaleFactor();
|
||||
SbVec3f scale(s, s, s);
|
||||
SbVec3f norm = rotateSymbol ? SbVec3f(normal.x, normal.y, normal.z) : axisY;
|
||||
SbRotation rot(axisY, norm);
|
||||
SbVec3f tra(static_cast<float>(point.x),
|
||||
static_cast<float>(point.y),
|
||||
static_cast<float>(point.z));
|
||||
mat.setTransform(tra, rot, scale);
|
||||
}
|
||||
|
||||
|
||||
// OvG: Visibility automation show parts and hide meshes on activation of a constraint
|
||||
std::string ViewProviderFemConstraint::gethideMeshShowPartStr(const std::string showConstr)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user