Merge pull request #915 from berndhahnebach/bhbdev090

FEM: add unit test and small fixes
This commit is contained in:
Yorik van Havre
2017-08-04 13:57:44 -03:00
committed by GitHub
12 changed files with 90 additions and 14 deletions

View File

@@ -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();

View File

@@ -54,6 +54,9 @@
#include "FemConstraint.h"
#include "FemTools.h"
#include <App/DocumentObjectPy.h>
#include <App/FeaturePythonPyImp.h>
#include <Mod/Part/App/PartFeature.h>
#include <Base/Console.h>
#include <Base/Exception.h>
@@ -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<App::DocumentObjectPy>(this),true);
}
return Py::new_reference_to(PythonObject);
}
// explicit template instantiation
template class AppFemExport FeaturePythonT<Fem::Constraint>;
/// @endcond
}

View File

@@ -25,6 +25,7 @@
#define FEM_CONSTRAINT_H
#include <Base/Vector3D.h>
#include <App/FeaturePython.h>
#include <App/DocumentObject.h>
#include <App/PropertyLinks.h>
#include <App/PropertyGeo.h>
@@ -75,6 +76,9 @@ protected:
};
typedef App::FeaturePythonT<Constraint> ConstraintPython;
} //namespace Fem

View File

@@ -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

View File

@@ -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();

View File

@@ -490,3 +490,15 @@ void ViewProviderFemConstraint::checkForWizard()
wizardSubLayout = wiz->findChild<QVBoxLayout*>(QString::fromLatin1("ShaftWizardLayout"));
}
}
// Python feature -----------------------------------------------------------------------
namespace Gui {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(FemGui::ViewProviderFemConstraintPython, FemGui::ViewProviderFemConstraint)
/// @endcond
// explicit template instantiation
template class FemGuiExport ViewProviderPythonFeatureT<ViewProviderFemConstraint>;
}

View File

@@ -25,6 +25,7 @@
#define GUI_VIEWPROVIDERFEMCONSTRAINT_H
#include <Gui/ViewProviderGeometryObject.h>
#include <Gui/ViewProviderPythonFeature.h>
#include <QObject>
#include <QVBoxLayout>
@@ -117,6 +118,9 @@ protected:
static QObject* findChildByName(const QObject* parent, const QString& name);
};
typedef Gui::ViewProviderPythonFeatureT<ViewProviderFemConstraint> ViewProviderFemConstraintPython;
} //namespace FemGui

View File

@@ -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:

View File

@@ -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

View File

@@ -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:

View File

@@ -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

View File

@@ -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