Skip to content

Commit bbf0322

Browse files
committed
Fem: Symbol scaling continue
1 parent 764b230 commit bbf0322

5 files changed

+102
-29
lines changed

src/Mod/Fem/App/FemConstraintPressure.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,3 @@ void ConstraintPressure::handleChangedPropertyType(Base::XMLReader& reader,
6363
Constraint::handleChangedPropertyType(reader, TypeName, prop);
6464
}
6565
}
66-
67-
void ConstraintPressure::onChanged(const App::Property* prop)
68-
{
69-
Constraint::onChanged(prop);
70-
71-
if (prop == &Reversed) {
72-
Points.touch();
73-
}
74-
}

src/Mod/Fem/App/FemConstraintPressure.h

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class FemExport ConstraintPressure: public Fem::Constraint
5050
void handleChangedPropertyType(Base::XMLReader& reader,
5151
const char* TypeName,
5252
App::Property* prop) override;
53-
void onChanged(const App::Property* prop) override;
5453
};
5554

5655
} // namespace Fem

src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp

+56-13
Original file line numberDiff line numberDiff line change
@@ -219,26 +219,27 @@ void ViewProviderFemConstraint::onChanged(const App::Property* prop)
219219

220220
void ViewProviderFemConstraint::updateData(const App::Property* prop)
221221
{
222-
auto pcConstraint = static_cast<Fem::Constraint*>(this->getObject());
222+
auto pcConstraint = static_cast<const Fem::Constraint*>(this->getObject());
223223

224224
if (prop == &pcConstraint->Points || prop == &pcConstraint->Scale) {
225225
const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValue();
226226
const std::vector<Base::Vector3d>& normals = pcConstraint->Normals.getValue();
227-
SbVec3f axisY(0, 1, 0);
228227
pMultCopy->matrix.setNum(points.size());
229228
SbMatrix* mat = pMultCopy->matrix.startEditing();
230-
float s = static_cast<float>(pcConstraint->Scale.getValue());
231-
s = s > 0 ? s : 0;
232-
SbVec3f scale(s, s, s);
229+
// SbVec3f axisY(0, 1, 0);
230+
// float s = static_cast<float>(pcConstraint->Scale.getValue());
231+
// s = s > 0 ? s : 0;
232+
// SbVec3f scale(s, s, s);
233233
int i = 0;
234234
for (const auto& point : points) {
235235
const auto& normal = normals[i];
236-
SbVec3f norm = rotateSymbol ? SbVec3f(normal.x, normal.y, normal.z) : axisY;
237-
SbRotation rot(axisY, norm);
238-
SbVec3f tra(static_cast<float>(point.x),
239-
static_cast<float>(point.y),
240-
static_cast<float>(point.z));
241-
mat[i].setTransform(tra, rot, scale);
236+
// SbVec3f norm = rotateSymbol ? SbVec3f(normal.x, normal.y, normal.z) :
237+
// axisY; SbRotation rot(axisY, norm); SbVec3f
238+
// tra(static_cast<float>(point.x),
239+
// static_cast<float>(point.y),
240+
// static_cast<float>(point.z));
241+
// mat[i].setTransform(tra, rot, scale);
242+
transformSymbol(pcConstraint, point, normal, mat[i]);
242243
++i;
243244
}
244245

@@ -249,6 +250,25 @@ void ViewProviderFemConstraint::updateData(const App::Property* prop)
249250
}
250251
}
251252

253+
void ViewProviderFemConstraint::transformSymbol(const App::DocumentObject* obj,
254+
const Base::Vector3d& point,
255+
const Base::Vector3d& normal,
256+
SbMatrix& mat) const
257+
{
258+
SbVec3f axisY(0, 1, 0);
259+
auto pcConstraint = static_cast<const Fem::Constraint*>(obj);
260+
float s = static_cast<float>(pcConstraint->Scale.getValue());
261+
s = s > 0 ? s : 0;
262+
SbVec3f scale(s, s, s);
263+
SbVec3f norm = rotateSymbol ? SbVec3f(normal.x, normal.y, normal.z) : axisY;
264+
SbRotation rot(axisY, norm);
265+
SbVec3f tra(static_cast<float>(point.x),
266+
static_cast<float>(point.y),
267+
static_cast<float>(point.z));
268+
mat.setTransform(tra, rot, scale);
269+
}
270+
271+
252272
// OvG: Visibility automation show parts and hide meshes on activation of a constraint
253273
std::string ViewProviderFemConstraint::gethideMeshShowPartStr(const std::string showConstr)
254274
{
@@ -711,13 +731,36 @@ void ViewProviderFemConstraint::checkForWizard()
711731

712732

713733
// Python feature -----------------------------------------------------------------------
734+
template<>
735+
void /*FemGui::*/
736+
ViewProviderFemConstraintPythonT</*FemGui::*/ ViewProviderFemConstraint>::transformSymbol(
737+
const App::DocumentObject* obj,
738+
const Base::Vector3d& point,
739+
const Base::Vector3d& normal,
740+
SbMatrix& mat) const
741+
{
742+
Py::Object prop =
743+
Base::freecad_dynamic_cast<App::PropertyPythonObject>(getPropertyByName("Proxy"))
744+
->getValue();
745+
746+
#ifdef FC_PY_VIEW_OBJECT
747+
748+
printf("aca\n");
749+
#endif
750+
}
714751

715752
namespace Gui
716753
{
717754
/// @cond DOXERR
755+
// PROPERTY_SOURCE_TEMPLATE(FemGui::ViewProviderFemConstraintPython,
756+
// FemGui::ViewProviderFemConstraint)
718757
PROPERTY_SOURCE_TEMPLATE(FemGui::ViewProviderFemConstraintPython, FemGui::ViewProviderFemConstraint)
719758
/// @endcond
720759

721-
// explicit template instantiation
722-
template class FemGuiExport ViewProviderPythonFeatureT<ViewProviderFemConstraint>;
760+
// namespace Gui {
761+
// template class FemGuiExport ViewProviderPythonFeatureT<ViewProviderFemConstraint>;
762+
// }
763+
// explicit template instantiation
764+
template class FemGuiExport
765+
ViewProviderPythonFeatureT<ViewProviderFemConstraintPythonT<ViewProviderFemConstraint>>;
723766
} // namespace Gui

src/Mod/Fem/Gui/ViewProviderFemConstraint.h

+26-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ class FemGuiExport ViewProviderFemConstraint: public Gui::ViewProviderGeometryOb
103103
bool setEdit(int ModNum) override;
104104
void unsetEdit(int ModNum) override;
105105

106+
virtual void transformSymbol(const App::DocumentObject* obj,
107+
const Base::Vector3d& point,
108+
const Base::Vector3d& normal,
109+
SbMatrix& mat) const;
110+
106111
static void createPlacement(SoSeparator* sep, const SbVec3f& base, const SbRotation& r);
107112
static void updatePlacement(const SoSeparator* sep,
108113
const int idx,
@@ -193,8 +198,6 @@ class FemGuiExport ViewProviderFemConstraint: public Gui::ViewProviderGeometryOb
193198
static QObject* findChildByName(const QObject* parent, const QString& name);
194199
};
195200

196-
using ViewProviderFemConstraintPython = Gui::ViewProviderPythonFeatureT<ViewProviderFemConstraint>;
197-
198201

199202
inline SoSeparator* ViewProviderFemConstraint::getSymbolSeparator() const
200203
{
@@ -222,6 +225,27 @@ inline void ViewProviderFemConstraint::setRotateSymbol(bool rotate)
222225
}
223226

224227

228+
template<typename ViewProviderT>
229+
class ViewProviderFemConstraintPythonT: public ViewProviderT
230+
{
231+
// PROPERTY_HEADER(FemGui::ViewProviderFemConstraintPythonT<ViewProviderT>);
232+
public:
233+
ViewProviderFemConstraintPythonT() = default;
234+
~ViewProviderFemConstraintPythonT() override = default;
235+
236+
protected:
237+
void transformSymbol(const App::DocumentObject* obj,
238+
const Base::Vector3d& point,
239+
const Base::Vector3d& normal,
240+
SbMatrix& mat) const override;
241+
};
242+
243+
// using ViewProviderFemConstraintPythonExt =
244+
// Gui::ViewProviderPythonFeatureT<ViewProviderFemConstraint>;
245+
using ViewProviderFemConstraintPython =
246+
Gui::ViewProviderPythonFeatureT<ViewProviderFemConstraintPythonT<ViewProviderFemConstraint>>;
247+
248+
225249
} // namespace FemGui
226250

227251

src/Mod/Fem/Gui/ViewProviderFemConstraintForce.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ ViewProviderFemConstraintForce::ViewProviderFemConstraintForce()
4444
{
4545
sPixmap = "FEM_ConstraintForce";
4646
loadSymbol((resourceSymbolDir + "ConstraintForce.iv").c_str());
47+
48+
// do not rotate symbol according to boundary normal
49+
setRotateSymbol(false);
4750
}
4851

4952
ViewProviderFemConstraintForce::~ViewProviderFemConstraintForce() = default;
@@ -110,11 +113,24 @@ void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
110113
{
111114
auto pcConstraint = static_cast<Fem::ConstraintForce*>(this->getObject());
112115

113-
if (prop == &pcConstraint->Reversed) {
116+
if (prop == &pcConstraint->Reversed || prop == &pcConstraint->DirectionVector) {
114117
SoTransform* trans = getSymbolTransform();
115-
trans->center.setValue(SbVec3f(0, 2, 0));
116-
float rotAngle = pcConstraint->Reversed.getValue() ? F_PI : 0.0f;
117-
trans->rotation.setValue(SbVec3f(0, 0, 1), rotAngle);
118+
bool rev = pcConstraint->Reversed.getValue();
119+
Base::Vector3d dir = (rev ? -1.0d : 1.0d) * pcConstraint->DirectionVector.getValue();
120+
float rotAngle = rev ? F_PI : 0.0f;
121+
SbMatrix mat0, mat1;
122+
mat0.setTransform(SbVec3f(0, 0, 0),
123+
SbRotation(SbVec3f(0, 0, 1), rotAngle),
124+
SbVec3f(1, 1, 1),
125+
SbRotation(SbVec3f(0, 0, 1), 0.0f),
126+
SbVec3f(0, 2, 0));
127+
128+
mat1.setRotate(SbRotation(SbVec3f(0, 1, 0), SbVec3f(dir.x, dir.y, dir.z)));
129+
130+
mat0 *= mat1;
131+
trans->setMatrix(mat0);
132+
// trans->center.setValue();
133+
// trans->rotation.setValue(SbVec3f(0, 0, 1), rotAngle);
118134
}
119135
else {
120136
ViewProviderFemConstraint::updateData(prop);

0 commit comments

Comments
 (0)