From ef85389cbc194cf1d6f0b53297dd98ce7f6b0ea8 Mon Sep 17 00:00:00 2001 From: Markus Hovorka Date: Thu, 3 Aug 2017 12:58:17 +0200 Subject: [PATCH] FEM: add ConstraintPython object type Constraints implemented in python can use this object as their base. That makes it easier to identify them as constraint objects. --- src/Mod/Fem/App/AppFem.cpp | 1 + src/Mod/Fem/App/FemConstraint.cpp | 27 +++++++++++++++++++ src/Mod/Fem/App/FemConstraint.h | 4 +++ src/Mod/Fem/Gui/AppFemGui.cpp | 1 + src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp | 12 +++++++++ src/Mod/Fem/Gui/ViewProviderFemConstraint.h | 4 +++ 6 files changed, 49 insertions(+) diff --git a/src/Mod/Fem/App/AppFem.cpp b/src/Mod/Fem/App/AppFem.cpp index ebd41249c5..c03c11dad1 100644 --- a/src/Mod/Fem/App/AppFem.cpp +++ b/src/Mod/Fem/App/AppFem.cpp @@ -148,6 +148,7 @@ PyMOD_INIT_FUNC(Fem) Fem::FemSetNodesObject ::init(); Fem::Constraint ::init(); + Fem::ConstraintPython ::init(); Fem::ConstraintBearing ::init(); Fem::ConstraintFixed ::init(); Fem::ConstraintForce ::init(); diff --git a/src/Mod/Fem/App/FemConstraint.cpp b/src/Mod/Fem/App/FemConstraint.cpp index e6b16b0840..0e931dc1c5 100644 --- a/src/Mod/Fem/App/FemConstraint.cpp +++ b/src/Mod/Fem/App/FemConstraint.cpp @@ -54,6 +54,9 @@ #include "FemConstraint.h" #include "FemTools.h" +#include +#include + #include #include #include @@ -391,3 +394,27 @@ const Base::Vector3d Constraint::getDirection(const App::PropertyLinkSub &direct return Fem::Tools::getDirectionFromShape(sh); } + +// Python feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(Fem::ConstraintPython, Fem::Constraint) +template<> const char* Fem::ConstraintPython::getViewProviderName(void) const { + return "FemGui::ViewProviderFemConstraintPython"; +} + +template<> PyObject* Fem::ConstraintPython::getPyObject(void) { + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new App::FeaturePythonPyT(this),true); + } + return Py::new_reference_to(PythonObject); +} + +// explicit template instantiation +template class AppFemExport FeaturePythonT; + +/// @endcond + +} diff --git a/src/Mod/Fem/App/FemConstraint.h b/src/Mod/Fem/App/FemConstraint.h index 73cf76a9e5..00576ee3a6 100644 --- a/src/Mod/Fem/App/FemConstraint.h +++ b/src/Mod/Fem/App/FemConstraint.h @@ -25,6 +25,7 @@ #define FEM_CONSTRAINT_H #include +#include #include #include #include @@ -75,6 +76,9 @@ protected: }; +typedef App::FeaturePythonT ConstraintPython; + + } //namespace Fem diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index ff25b5c2fb..5dd9d54282 100644 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -120,6 +120,7 @@ PyMOD_INIT_FUNC(FemGui) FemGui::ViewProviderSetFaces ::init(); FemGui::ViewProviderSetGeometry ::init(); FemGui::ViewProviderFemConstraint ::init(); + FemGui::ViewProviderFemConstraintPython ::init(); FemGui::ViewProviderFemConstraintBearing ::init(); FemGui::ViewProviderFemConstraintFixed ::init(); FemGui::ViewProviderFemConstraintForce ::init(); diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp index ebbf1b7ed4..51db299055 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp @@ -490,3 +490,15 @@ void ViewProviderFemConstraint::checkForWizard() wizardSubLayout = wiz->findChild(QString::fromLatin1("ShaftWizardLayout")); } } + + +// Python feature ----------------------------------------------------------------------- + +namespace Gui { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(FemGui::ViewProviderFemConstraintPython, FemGui::ViewProviderFemConstraint) +/// @endcond + +// explicit template instantiation +template class FemGuiExport ViewProviderPythonFeatureT; +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraint.h b/src/Mod/Fem/Gui/ViewProviderFemConstraint.h index 5c5f33d292..85d9bc318e 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraint.h +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraint.h @@ -25,6 +25,7 @@ #define GUI_VIEWPROVIDERFEMCONSTRAINT_H #include +#include #include #include @@ -117,6 +118,9 @@ protected: static QObject* findChildByName(const QObject* parent, const QString& name); }; +typedef Gui::ViewProviderPythonFeatureT ViewProviderFemConstraintPython; + + } //namespace FemGui