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/FemGmshTools.py b/src/Mod/Fem/FemGmshTools.py index 916c7688b2..6b3e42ef09 100644 --- a/src/Mod/Fem/FemGmshTools.py +++ b/src/Mod/Fem/FemGmshTools.py @@ -30,7 +30,7 @@ __url__ = "http://www.freecadweb.org" import FreeCAD import Fem import FemMeshTools -import Units +from FreeCAD import Units import subprocess import tempfile from platform import system 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 diff --git a/src/Mod/Fem/ObjectsFem.py b/src/Mod/Fem/ObjectsFem.py index 5966cfb37a..04ee4bfd9a 100644 --- a/src/Mod/Fem/ObjectsFem.py +++ b/src/Mod/Fem/ObjectsFem.py @@ -112,7 +112,7 @@ def makeConstraintPulley(name="ConstraintPulley"): def makeConstraintSelfWeight(name="ConstraintSelfWeight"): '''makeConstraintSelfWeight([name]): creates an self weight object to define a gravity load''' - obj = FreeCAD.ActiveDocument.addObject("Fem::FeaturePython", name) + obj = FreeCAD.ActiveDocument.addObject("Fem::ConstraintPython", name) import PyObjects._FemConstraintSelfWeight PyObjects._FemConstraintSelfWeight._FemConstraintSelfWeight(obj) if FreeCAD.GuiUp: diff --git a/src/Mod/Fem/PyGui/_TaskPanelFemMaterial.py b/src/Mod/Fem/PyGui/_TaskPanelFemMaterial.py index 650b2540ee..ab58a2941b 100644 --- a/src/Mod/Fem/PyGui/_TaskPanelFemMaterial.py +++ b/src/Mod/Fem/PyGui/_TaskPanelFemMaterial.py @@ -29,7 +29,7 @@ __url__ = "http://www.freecadweb.org" import FreeCAD import FreeCADGui -import Units +from FreeCAD import Units from PySide import QtCore, QtGui from PySide.QtGui import QFileDialog, QMessageBox diff --git a/src/Mod/Fem/PyGui/_TaskPanelFemSolverCalculix.py b/src/Mod/Fem/PyGui/_TaskPanelFemSolverCalculix.py index 625038319d..03229b0d7a 100644 --- a/src/Mod/Fem/PyGui/_TaskPanelFemSolverCalculix.py +++ b/src/Mod/Fem/PyGui/_TaskPanelFemSolverCalculix.py @@ -172,7 +172,7 @@ class _TaskPanelFemSolverCalculix: majorVersion, minorVersion = fea.get_ccx_version() if majorVersion == 2 and minorVersion <= 10: message = "The used CalculiX version {}.{} creates broken output files.\n" \ - "Please upgrade to a newer version.".format(majorVersion, minorVersion) + "Please upgrade to a newer version.".format(majorVersion, minorVersion) QtGui.QMessageBox.warning(None, "Upgrade CalculiX", message) raise else: diff --git a/src/Mod/Fem/PyGui/_ViewProviderFemConstraintSelfWeight.py b/src/Mod/Fem/PyGui/_ViewProviderFemConstraintSelfWeight.py index 267cabc1f1..e1c981a862 100644 --- a/src/Mod/Fem/PyGui/_ViewProviderFemConstraintSelfWeight.py +++ b/src/Mod/Fem/PyGui/_ViewProviderFemConstraintSelfWeight.py @@ -27,8 +27,6 @@ __url__ = "http://www.freecadweb.org" ## @package ViewProviderFemConstraintSelfWeight # \ingroup FEM -from pivy import coin - class _ViewProviderFemConstraintSelfWeight: "A View Provider for the FemConstraintSelfWeight object" @@ -41,14 +39,6 @@ class _ViewProviderFemConstraintSelfWeight: def attach(self, vobj): self.ViewObject = vobj self.Object = vobj.Object - self.standard = coin.SoGroup() - vobj.addDisplayMode(self.standard, "Standard") - - def getDisplayModes(self, obj): - return ["Standard"] - - def getDefaultDisplayMode(self): - return "Standard" def updateData(self, obj, prop): return diff --git a/src/Mod/Fem/TestFem.py b/src/Mod/Fem/TestFem.py index e564129dc0..4021525754 100644 --- a/src/Mod/Fem/TestFem.py +++ b/src/Mod/Fem/TestFem.py @@ -340,6 +340,43 @@ class FemTest(unittest.TestCase): self.assertEqual(read_mflow, expected_mflow, "Values of read mflow result data are unexpected") self.assertEqual(read_npressure, expected_npressure, "Values of read npressure result data are unexpected") + def test_pyimport_all_FEM_modules(self): + # collect all Python modules in Fem + # Mod/Fem/ + pydir = FreeCAD.ConfigGet("AppHomePath") + 'Mod/Fem/' + fcc_print(pydir) + pymodules = [] + for pyfile in sorted(os.listdir(pydir)): + if pyfile.endswith(".py") and not pyfile.startswith('Init'): + pymodules.append(os.path.splitext(os.path.basename(pyfile))[0]) + + # Mod/Fem/PyObjects/ + pydir = FreeCAD.ConfigGet("AppHomePath") + 'Mod/Fem/PyObjects/' + fcc_print(pydir) + for pyfile in sorted(os.listdir(pydir)): + if pyfile.endswith(".py"): + pymodules.append('PyObjects.' + os.path.splitext(os.path.basename(pyfile))[0]) + + # Mod/Fem/PyOGui/ + if FreeCAD.GuiUp: + pydir = FreeCAD.ConfigGet("AppHomePath") + 'Mod/Fem/PyGui/' + fcc_print(pydir) + for pyfile in sorted(os.listdir(pydir)): + if pyfile.endswith(".py"): + pymodules.append('PyGui.' + os.path.splitext(os.path.basename(pyfile))[0]) + + # import all collected modules + # fcc_print(pymodules) + for mod in pymodules: + fcc_print('Try importing {0} ...'.format(mod)) + try: + im = __import__('{0}'.format(mod)) + except: + im = False + if not im: + __import__('{0}'.format(mod)) # to get an error message what was going wrong + self.assertTrue(im, 'Problem importing {0}'.format(mod)) + def tearDown(self): FreeCAD.closeDocument("FemTest") pass