From 91a40b2007ec17194f6756f71ad4b50425515342 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 22 Sep 2023 12:38:37 +0200 Subject: [PATCH] Fem: Apply clang-format --- src/Mod/Fem/App/AppFem.cpp | 37 +- src/Mod/Fem/App/AppFemPy.cpp | 163 ++- src/Mod/Fem/App/FemAnalysis.cpp | 24 +- src/Mod/Fem/App/FemAnalysis.h | 24 +- src/Mod/Fem/App/FemConstraint.cpp | 257 ++-- src/Mod/Fem/App/FemConstraint.h | 36 +- src/Mod/Fem/App/FemConstraintBearing.cpp | 47 +- src/Mod/Fem/App/FemConstraintBearing.h | 11 +- src/Mod/Fem/App/FemConstraintContact.cpp | 28 +- src/Mod/Fem/App/FemConstraintContact.h | 19 +- src/Mod/Fem/App/FemConstraintDisplacement.cpp | 12 +- src/Mod/Fem/App/FemConstraintDisplacement.h | 14 +- src/Mod/Fem/App/FemConstraintFixed.cpp | 20 +- src/Mod/Fem/App/FemConstraintFixed.h | 11 +- .../Fem/App/FemConstraintFluidBoundary.cpp | 49 +- src/Mod/Fem/App/FemConstraintFluidBoundary.h | 11 +- src/Mod/Fem/App/FemConstraintForce.cpp | 56 +- src/Mod/Fem/App/FemConstraintForce.h | 11 +- src/Mod/Fem/App/FemConstraintGear.cpp | 36 +- src/Mod/Fem/App/FemConstraintGear.h | 11 +- src/Mod/Fem/App/FemConstraintHeatflux.cpp | 33 +- src/Mod/Fem/App/FemConstraintHeatflux.h | 11 +- .../App/FemConstraintInitialTemperature.cpp | 14 +- .../Fem/App/FemConstraintInitialTemperature.h | 14 +- .../Fem/App/FemConstraintPlaneRotation.cpp | 20 +- src/Mod/Fem/App/FemConstraintPlaneRotation.h | 9 +- src/Mod/Fem/App/FemConstraintPressure.cpp | 25 +- src/Mod/Fem/App/FemConstraintPressure.h | 11 +- src/Mod/Fem/App/FemConstraintPulley.cpp | 47 +- src/Mod/Fem/App/FemConstraintPulley.h | 12 +- src/Mod/Fem/App/FemConstraintSpring.cpp | 19 +- src/Mod/Fem/App/FemConstraintSpring.h | 11 +- src/Mod/Fem/App/FemConstraintTemperature.cpp | 25 +- src/Mod/Fem/App/FemConstraintTemperature.h | 14 +- src/Mod/Fem/App/FemConstraintTransform.cpp | 86 +- src/Mod/Fem/App/FemConstraintTransform.h | 16 +- src/Mod/Fem/App/FemMesh.cpp | 1295 +++++++++-------- src/Mod/Fem/App/FemMesh.h | 84 +- src/Mod/Fem/App/FemMeshObject.cpp | 24 +- src/Mod/Fem/App/FemMeshObject.h | 19 +- src/Mod/Fem/App/FemMeshProperty.cpp | 40 +- src/Mod/Fem/App/FemMeshProperty.h | 34 +- src/Mod/Fem/App/FemMeshPyImp.cpp | 867 +++++++---- src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp | 113 +- src/Mod/Fem/App/FemMeshShapeNetgenObject.h | 35 +- src/Mod/Fem/App/FemMeshShapeObject.cpp | 97 +- src/Mod/Fem/App/FemMeshShapeObject.h | 17 +- src/Mod/Fem/App/FemPostFilter.cpp | 285 ++-- src/Mod/Fem/App/FemPostFilter.h | 63 +- src/Mod/Fem/App/FemPostFunction.cpp | 37 +- src/Mod/Fem/App/FemPostFunction.h | 79 +- src/Mod/Fem/App/FemPostObject.cpp | 8 +- src/Mod/Fem/App/FemPostObject.h | 8 +- src/Mod/Fem/App/FemPostPipeline.cpp | 134 +- src/Mod/Fem/App/FemPostPipeline.h | 31 +- src/Mod/Fem/App/FemPostPipelinePyImp.cpp | 33 +- src/Mod/Fem/App/FemResultObject.cpp | 21 +- src/Mod/Fem/App/FemResultObject.h | 14 +- src/Mod/Fem/App/FemSetElementsObject.cpp | 7 +- src/Mod/Fem/App/FemSetElementsObject.h | 18 +- src/Mod/Fem/App/FemSetFacesObject.cpp | 7 +- src/Mod/Fem/App/FemSetFacesObject.h | 16 +- src/Mod/Fem/App/FemSetGeometryObject.cpp | 9 +- src/Mod/Fem/App/FemSetGeometryObject.h | 18 +- src/Mod/Fem/App/FemSetNodesObject.cpp | 9 +- src/Mod/Fem/App/FemSetNodesObject.h | 18 +- src/Mod/Fem/App/FemSetObject.cpp | 11 +- src/Mod/Fem/App/FemSetObject.h | 19 +- src/Mod/Fem/App/FemSolverObject.cpp | 21 +- src/Mod/Fem/App/FemSolverObject.h | 15 +- src/Mod/Fem/App/FemTools.cpp | 92 +- src/Mod/Fem/App/FemTools.h | 9 +- src/Mod/Fem/App/FemVTKTools.cpp | 332 +++-- src/Mod/Fem/App/FemVTKTools.h | 54 +- src/Mod/Fem/App/HypothesisPy.cpp | 701 ++++----- src/Mod/Fem/App/HypothesisPy.h | 237 +-- src/Mod/Fem/App/PreCompiled.h | 62 +- src/Mod/Fem/App/PropertyPostDataObject.cpp | 198 +-- src/Mod/Fem/App/PropertyPostDataObject.h | 26 +- 79 files changed, 3674 insertions(+), 2787 deletions(-) mode change 100755 => 100644 src/Mod/Fem/App/HypothesisPy.cpp mode change 100755 => 100644 src/Mod/Fem/App/HypothesisPy.h diff --git a/src/Mod/Fem/App/AppFem.cpp b/src/Mod/Fem/App/AppFem.cpp index e2e4f4a6c2..b71b06b2e7 100644 --- a/src/Mod/Fem/App/AppFem.cpp +++ b/src/Mod/Fem/App/AppFem.cpp @@ -30,26 +30,26 @@ #include "FemAnalysis.h" #include "FemConstraintBearing.h" -#include "FemConstraintFixed.h" -#include "FemConstraintForce.h" -#include "FemConstraintPressure.h" -#include "FemConstraintGear.h" -#include "FemConstraintPulley.h" +#include "FemConstraintContact.h" #include "FemConstraintDisplacement.h" -#include "FemConstraintTemperature.h" +#include "FemConstraintFixed.h" +#include "FemConstraintFluidBoundary.h" +#include "FemConstraintForce.h" +#include "FemConstraintGear.h" #include "FemConstraintHeatflux.h" #include "FemConstraintInitialTemperature.h" #include "FemConstraintPlaneRotation.h" -#include "FemConstraintContact.h" -#include "FemConstraintFluidBoundary.h" -#include "FemConstraintTransform.h" +#include "FemConstraintPressure.h" +#include "FemConstraintPulley.h" #include "FemConstraintSpring.h" +#include "FemConstraintTemperature.h" +#include "FemConstraintTransform.h" #include "FemMesh.h" #include "FemMeshObject.h" #include "FemMeshProperty.h" #include "FemMeshPy.h" -#include "FemMeshShapeObject.h" #include "FemMeshShapeNetgenObject.h" +#include "FemMeshShapeObject.h" #include "FemResultObject.h" #include "FemSetElementsObject.h" #include "FemSetFacesObject.h" @@ -59,14 +59,15 @@ #include "HypothesisPy.h" #ifdef FC_USE_VTK -# include "FemPostFilter.h" -# include "FemPostFunction.h" -# include "FemPostPipeline.h" -# include "PropertyPostDataObject.h" +#include "FemPostFilter.h" +#include "FemPostFunction.h" +#include "FemPostPipeline.h" +#include "PropertyPostDataObject.h" #endif -namespace Fem { +namespace Fem +{ extern PyObject* initModule(); } @@ -76,15 +77,16 @@ PyMOD_INIT_FUNC(Fem) // load dependent module try { Base::Interpreter().loadModule("Part"); - //Base::Interpreter().loadModule("Mesh"); + // Base::Interpreter().loadModule("Mesh"); } - catch(const Base::Exception& e) { + catch (const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); PyMOD_Return(nullptr); } PyObject* femModule = Fem::initModule(); Base::Console().Log("Loading Fem module... done\n"); + // clang-format off Fem::StdMeshers_Arithmetic1DPy ::init_type(femModule); Fem::StdMeshers_AutomaticLengthPy ::init_type(femModule); Fem::StdMeshers_NotConformAllowedPy ::init_type(femModule); @@ -194,6 +196,7 @@ PyMOD_INIT_FUNC(Fem) Fem::PropertyPostDataObject ::init(); #endif + // clang-format on PyMOD_Return(femModule); } diff --git a/src/Mod/Fem/App/AppFemPy.cpp b/src/Mod/Fem/App/AppFemPy.cpp index 8cb3ccbd28..6b08618a28 100644 --- a/src/Mod/Fem/App/AppFemPy.cpp +++ b/src/Mod/Fem/App/AppFemPy.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -43,65 +43,77 @@ #endif -namespace Fem { -class Module : public Py::ExtensionModule +namespace Fem +{ +class Module: public Py::ExtensionModule { public: - Module() : Py::ExtensionModule("Fem") + Module() + : Py::ExtensionModule("Fem") { - add_varargs_method("open",&Module::open, - "open(string) -- Create a new document and a Mesh::Import feature to load the file into the document." - ); - add_varargs_method("insert",&Module::insert, - "insert(string|mesh,[string]) -- Load or insert a mesh into the given or active document." - ); - add_varargs_method("export",&Module::exporter, - "export(list,string) -- Export a list of objects into a single file." - ); - add_varargs_method("read",&Module::read, - "Read a mesh from a file and returns a Mesh object." - ); + add_varargs_method("open", + &Module::open, + "open(string) -- Create a new document and a Mesh::Import feature to " + "load the file into the document."); + add_varargs_method("insert", + &Module::insert, + "insert(string|mesh,[string]) -- Load or insert a mesh into the given " + "or active document."); + add_varargs_method("export", + &Module::exporter, + "export(list,string) -- Export a list of objects into a single file."); + add_varargs_method("read", + &Module::read, + "Read a mesh from a file and returns a Mesh object."); #ifdef FC_USE_VTK - add_varargs_method("readResult",&Module::readResult, - "Read a CFD or Mechanical result (auto detect) from a file (file format detected from file suffix)" - ); - add_varargs_method("writeResult",&Module::writeResult, - "write a CFD or FEM result (auto detect) to a file (file format detected from file suffix)" - ); + add_varargs_method("readResult", + &Module::readResult, + "Read a CFD or Mechanical result (auto detect) from a file (file format " + "detected from file suffix)"); + add_varargs_method("writeResult", + &Module::writeResult, + "write a CFD or FEM result (auto detect) to a file (file format " + "detected from file suffix)"); #endif - add_varargs_method("show",&Module::show, - "show(shape,[string]) -- Add the mesh to the active document or create one if no document exists." - ); - initialize("This module is the Fem module."); // register with Python + add_varargs_method("show", + &Module::show, + "show(shape,[string]) -- Add the mesh to the active document or create " + "one if no document exists."); + initialize("This module is the Fem module."); // register with Python } private: - Py::Object invoke_method_varargs(void *method_def, const Py::Tuple &args) override + Py::Object invoke_method_varargs(void* method_def, const Py::Tuple& args) override { try { return Py::ExtensionModule::invoke_method_varargs(method_def, args); } - catch (const Standard_Failure &e) { + catch (const Standard_Failure& e) { std::string str; Standard_CString msg = e.GetMessageString(); str += typeid(e).name(); str += " "; - if (msg) {str += msg;} - else {str += "No OCCT Exception Message";} + if (msg) { + str += msg; + } + else { + str += "No OCCT Exception Message"; + } throw Py::Exception(Part::PartExceptionOCCError, str); } - catch (const Base::Exception &e) { + catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); } - catch (const std::exception &e) { + catch (const std::exception& e) { throw Py::RuntimeError(e.what()); } } Py::Object open(const Py::Tuple& args) { char* Name; - if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name)) + if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -110,9 +122,9 @@ private: mesh->read(EncodedName.c_str()); Base::FileInfo file(EncodedName.c_str()); // create new document and add Import feature - App::Document *pcDoc = App::GetApplication().newDocument(); - FemMeshObject *pcFeature = static_cast - (pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str())); + App::Document* pcDoc = App::GetApplication().newDocument(); + FemMeshObject* pcFeature = static_cast( + pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str())); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->FemMesh.setValuePtr(mesh.release()); pcFeature->purgeTouched(); @@ -123,17 +135,20 @@ private: { char* Name; const char* DocName = nullptr; - if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName)) + if (!PyArg_ParseTuple(args.ptr(), "et|s", "utf-8", &Name, &DocName)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); - App::Document *pcDoc = nullptr; - if (DocName) + App::Document* pcDoc = nullptr; + if (DocName) { pcDoc = App::GetApplication().getDocument(DocName); - else + } + else { pcDoc = App::GetApplication().getActiveDocument(); + } if (!pcDoc) { pcDoc = App::GetApplication().newDocument(DocName); @@ -145,8 +160,8 @@ private: std::unique_ptr mesh(new FemMesh); mesh->read(EncodedName.c_str()); - FemMeshObject *pcFeature = static_cast - (pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str())); + FemMeshObject* pcFeature = static_cast( + pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str())); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->FemMesh.setValuePtr(mesh.release()); pcFeature->purgeTouched(); @@ -155,8 +170,8 @@ private: #ifdef FC_USE_VTK if (FemPostPipeline::canRead(file)) { - FemPostPipeline *pcFeature = static_cast - (pcDoc->addObject("Fem::FemPostPipeline", file.fileNamePure().c_str())); + FemPostPipeline* pcFeature = static_cast( + pcDoc->addObject("Fem::FemPostPipeline", file.fileNamePure().c_str())); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->read(file); @@ -177,8 +192,9 @@ private: { PyObject* object; char* Name; - if (!PyArg_ParseTuple(args.ptr(), "Oet",&object,"utf-8",&Name)) + if (!PyArg_ParseTuple(args.ptr(), "Oet", &object, "utf-8", &Name)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -188,7 +204,8 @@ private: for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { PyObject* item = (*it).ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { - App::DocumentObject* obj = static_cast(item)->getDocumentObjectPtr(); + App::DocumentObject* obj = + static_cast(item)->getDocumentObjectPtr(); if (obj->getTypeId().isDerivedFrom(meshId)) { static_cast(obj)->FemMesh.getValue().write(EncodedName.c_str()); return Py::None(); @@ -201,8 +218,9 @@ private: Py::Object read(const Py::Tuple& args) { char* Name; - if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name)) + if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -218,21 +236,22 @@ private: char* fileName = nullptr; char* objName = nullptr; - if (!PyArg_ParseTuple(args.ptr(), "et|et","utf-8", &fileName, "utf-8", &objName)) + if (!PyArg_ParseTuple(args.ptr(), "et|et", "utf-8", &fileName, "utf-8", &objName)) { throw Py::Exception(); + } std::string EncodedName = std::string(fileName); PyMem_Free(fileName); std::string resName = std::string(objName); PyMem_Free(objName); - if (resName.length()) - { + if (resName.length()) { App::Document* pcDoc = App::GetApplication().getActiveDocument(); App::DocumentObject* obj = pcDoc->getObject(resName.c_str()); FemVTKTools::readResult(EncodedName.c_str(), obj); } - else + else { FemVTKTools::readResult(EncodedName.c_str()); // assuming activeObject can hold Result + } return Py::None(); } @@ -240,23 +259,29 @@ private: Py::Object writeResult(const Py::Tuple& args) { char* fileName = nullptr; - PyObject *pcObj = nullptr; + PyObject* pcObj = nullptr; - if (!PyArg_ParseTuple(args.ptr(), "et|O!","utf-8", &fileName, &(App::DocumentObjectPy::Type), &pcObj)) + if (!PyArg_ParseTuple(args.ptr(), + "et|O!", + "utf-8", + &fileName, + &(App::DocumentObjectPy::Type), + &pcObj)) { throw Py::Exception(); + } std::string EncodedName = std::string(fileName); PyMem_Free(fileName); - if (pcObj) - { - if (PyObject_TypeCheck(pcObj, &(App::DocumentObjectPy::Type))) - { - App::DocumentObject* obj = static_cast(pcObj)->getDocumentObjectPtr(); + if (pcObj) { + if (PyObject_TypeCheck(pcObj, &(App::DocumentObjectPy::Type))) { + App::DocumentObject* obj = + static_cast(pcObj)->getDocumentObjectPtr(); FemVTKTools::writeResult(EncodedName.c_str(), obj); } } - else + else { FemVTKTools::writeResult(EncodedName.c_str()); + } return Py::None(); } @@ -264,18 +289,20 @@ private: Py::Object show(const Py::Tuple& args) { - PyObject *pcObj; - char *name = "Mesh"; - if (!PyArg_ParseTuple(args.ptr(), "O!|s", &(FemMeshPy::Type), &pcObj, &name)) + PyObject* pcObj; + char* name = "Mesh"; + if (!PyArg_ParseTuple(args.ptr(), "O!|s", &(FemMeshPy::Type), &pcObj, &name)) { throw Py::Exception(); + } - App::Document *pcDoc = App::GetApplication().getActiveDocument(); - if (!pcDoc) + App::Document* pcDoc = App::GetApplication().getActiveDocument(); + if (!pcDoc) { pcDoc = App::GetApplication().newDocument(); + } FemMeshPy* pShape = static_cast(pcObj); - Fem::FemMeshObject *pcFeature = static_cast - (pcDoc->addObject("Fem::FemMeshObject", name)); + Fem::FemMeshObject* pcFeature = + static_cast(pcDoc->addObject("Fem::FemMeshObject", name)); // copy the data pcFeature->FemMesh.setValue(*(pShape->getFemMeshPtr())); pcDoc->recompute(); @@ -289,4 +316,4 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -} // namespace Fem +} // namespace Fem diff --git a/src/Mod/Fem/App/FemAnalysis.cpp b/src/Mod/Fem/App/FemAnalysis.cpp index 69c081af4f..ff31baedda 100644 --- a/src/Mod/Fem/App/FemAnalysis.cpp +++ b/src/Mod/Fem/App/FemAnalysis.cpp @@ -62,17 +62,20 @@ PROPERTY_SOURCE_ABSTRACT(Fem::DocumentObject, App::DocumentObject) // Python feature --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Fem::FemAnalysisPython, Fem::FemAnalysis) -template<> const char* Fem::FemAnalysisPython::getViewProviderName() const { +template<> +const char* Fem::FemAnalysisPython::getViewProviderName() const +{ return "FemGui::ViewProviderFemAnalysisPython"; } // template<> void Fem::FemAnalysisPython::Restore(Base::XMLReader& reader) { // FemAnalysis::Restore(reader); // } -//template<> PyObject* Fem::FemAnalysisPython::getPyObject(void) { +// template<> PyObject* Fem::FemAnalysisPython::getPyObject(void) { // if (PythonObject.is(Py::_None())) { // // ref counter is set to 1 // PythonObject = Py::Object(new App::DocumentObjectPy(this),true); @@ -83,17 +86,22 @@ template<> const char* Fem::FemAnalysisPython::getViewProviderName() const { // explicit template instantiation template class FemExport FeaturePythonT; -} +} // namespace App // --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Fem::FeaturePython, Fem::DocumentObject) -template<> const char* Fem::FeaturePython::getViewProviderName() const { +template<> +const char* Fem::FeaturePython::getViewProviderName() const +{ return "Gui::ViewProviderPythonFeature"; } -template<> PyObject* Fem::FeaturePython::getPyObject() { +template<> +PyObject* Fem::FeaturePython::getPyObject() +{ if (PythonObject.is(Py::_None())) { // ref counter is set to 1 PythonObject = Py::Object(new App::FeaturePythonPyT(this), true); @@ -103,4 +111,4 @@ template<> PyObject* Fem::FeaturePython::getPyObject() { // explicit template instantiation template class FemExport FeaturePythonT; /// @endcond -} +} // namespace App diff --git a/src/Mod/Fem/App/FemAnalysis.h b/src/Mod/Fem/App/FemAnalysis.h index 222da40828..884db2ea46 100644 --- a/src/Mod/Fem/App/FemAnalysis.h +++ b/src/Mod/Fem/App/FemAnalysis.h @@ -24,12 +24,13 @@ #define Fem_FemAnalysis_H #include -#include #include +#include #include -namespace Fem { +namespace Fem +{ /** * @brief Container of objects relevant to one simulation. @@ -49,7 +50,8 @@ namespace Fem { * Analysis object. Every document object of FreeCAD can be part of a * Analysis. */ -class FemExport FemAnalysis : public App::DocumentObjectGroup { +class FemExport FemAnalysis: public App::DocumentObjectGroup +{ PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemAnalysis); public: @@ -66,9 +68,10 @@ public: * directory name for an analysis. Retains its value across save/load * cycles. */ - App::PropertyUUID Uid; + App::PropertyUUID Uid; - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemAnalysis"; } @@ -82,11 +85,12 @@ protected: * property of DocumentObjectGroup. This methods translates old files * still using the "Member" property. */ - void handleChangedPropertyName( - Base::XMLReader &reader, const char * TypeName, const char *PropName) override; + void handleChangedPropertyName(Base::XMLReader& reader, + const char* TypeName, + const char* PropName) override; }; -class FemExport DocumentObject : public App::DocumentObject +class FemExport DocumentObject: public App::DocumentObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::DocumentObject); }; @@ -95,7 +99,7 @@ using FemAnalysisPython = App::FeaturePythonT; using FeaturePython = App::FeaturePythonT; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemAnalysis_H +#endif // Fem_FemAnalysis_H diff --git a/src/Mod/Fem/App/FemConstraint.cpp b/src/Mod/Fem/App/FemConstraint.cpp index eb9aafd9dd..84f5fb3477 100644 --- a/src/Mod/Fem/App/FemConstraint.cpp +++ b/src/Mod/Fem/App/FemConstraint.cpp @@ -24,32 +24,32 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include //OvG: Required for log10 -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# if OCC_VERSION_HEX < 0x070600 -# include -# include -# endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //OvG: Required for log10 +#include +#include +#include +#include +#if OCC_VERSION_HEX < 0x070600 +#include +#include +#endif #endif #include @@ -72,16 +72,29 @@ PROPERTY_SOURCE(Fem::Constraint, App::DocumentObject) Constraint::Constraint() { - ADD_PROPERTY_TYPE(References, (nullptr, nullptr), "Constraint", (App::PropertyType)(App::Prop_None), "Elements where the constraint is applied"); - ADD_PROPERTY_TYPE(NormalDirection, (Base::Vector3d(0, 0, 1)), "Constraint", App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Normal direction pointing outside of solid"); - ADD_PROPERTY_TYPE(Scale, (1), "Base", App::PropertyType(App::Prop_Output), "Scale used for drawing constraints"); //OvG: Add scale parameter inherited by all derived constraints + ADD_PROPERTY_TYPE(References, + (nullptr, nullptr), + "Constraint", + (App::PropertyType)(App::Prop_None), + "Elements where the constraint is applied"); + ADD_PROPERTY_TYPE(NormalDirection, + (Base::Vector3d(0, 0, 1)), + "Constraint", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), + "Normal direction pointing outside of solid"); + ADD_PROPERTY_TYPE(Scale, + (1), + "Base", + App::PropertyType(App::Prop_Output), + "Scale used for drawing constraints"); // OvG: Add scale parameter inherited + // by all derived constraints References.setScope(App::LinkScope::Global); } Constraint::~Constraint() = default; -App::DocumentObjectExecReturn *Constraint::execute() +App::DocumentObjectExecReturn* Constraint::execute() { try { References.touch(); @@ -93,15 +106,17 @@ App::DocumentObjectExecReturn *Constraint::execute() } } -//OvG: Provide the ability to determine how big to draw constraint arrows etc. +// OvG: Provide the ability to determine how big to draw constraint arrows etc. int Constraint::calcDrawScaleFactor(double lparam) const { - return ((int)round(log(lparam)*log(lparam)*log(lparam)/10)>1)?((int)round(log(lparam)*log(lparam)*log(lparam)/10)):1; + return ((int)round(log(lparam) * log(lparam) * log(lparam) / 10) > 1) + ? ((int)round(log(lparam) * log(lparam) * log(lparam) / 10)) + : 1; } int Constraint::calcDrawScaleFactor(double lvparam, double luparam) const { - return calcDrawScaleFactor((lvparam+luparam)/2.0); + return calcDrawScaleFactor((lvparam + luparam) / 2.0); } int Constraint::calcDrawScaleFactor() const @@ -113,8 +128,9 @@ int Constraint::calcDrawScaleFactor() const void Constraint::onChanged(const App::Property* prop) { if (prop == &References) { - // If References are changed, recalculate the normal direction. If no useful reference is found, - // use z axis or previous value. If several faces are selected, only the first one is used + // If References are changed, recalculate the normal direction. If no useful reference is + // found, use z axis or previous value. If several faces are selected, only the first one is + // used std::vector Objects = References.getValues(); std::vector SubElements = References.getSubValues(); @@ -137,7 +153,7 @@ void Constraint::onChanged(const App::Property* prop) gp_Pnt center; double u1, u2, v1, v2; props.Bounds(u1, u2, v1, v2); - props.Normal((u1+u2)/2.0, (v1+v2)/2.0, center, normal); + props.Normal((u1 + u2) / 2.0, (v1 + v2) / 2.0, center, normal); normal.Normalize(); NormalDirection.setValue(normal.X(), normal.Y(), normal.Z()); // One face is enough... @@ -157,7 +173,9 @@ void Constraint::onDocumentRestored() App::DocumentObject::onDocumentRestored(); } -bool Constraint::getPoints(std::vector &points, std::vector &normals, int * scale) const +bool Constraint::getPoints(std::vector& points, + std::vector& normals, + int* scale) const { std::vector Objects = References.getValues(); std::vector SubElements = References.getSubValues(); @@ -169,23 +187,26 @@ bool Constraint::getPoints(std::vector &points, std::vector(obj); const Part::TopoShape& toposhape = feat->Shape.getShape(); - if (toposhape.isNull()) + if (toposhape.isNull()) { return false; + } sh = toposhape.getSubShape(SubElements[i].c_str(), true); - if (sh.IsNull()) + if (sh.IsNull()) { return false; + } if (sh.ShapeType() == TopAbs_VERTEX) { const TopoDS_Vertex& vertex = TopoDS::Vertex(sh); gp_Pnt p = BRep_Tool::Pnt(vertex); points.emplace_back(p.X(), p.Y(), p.Z()); normals.push_back(NormalDirection.getValue()); - //OvG: Scale by whole object mass in case of a vertex + // OvG: Scale by whole object mass in case of a vertex GProp_GProps props; BRepGProp::VolumeProperties(toposhape.getShape(), props); double lx = props.Mass(); - *scale = this->calcDrawScaleFactor(sqrt(lx)*0.5); //OvG: setup draw scale for constraint + // OvG: setup draw scale for constraint + *scale = this->calcDrawScaleFactor(sqrt(lx) * 0.5); } else if (sh.ShapeType() == TopAbs_EDGE) { BRepAdaptor_Curve curve(TopoDS::Edge(sh)); @@ -194,26 +215,26 @@ bool Constraint::getPoints(std::vector &points, std::vector= 30) //OvG: Increase 10 units distance proportionately to l for larger objects. - { - *scale = this->calcDrawScaleFactor(l); //OvG: setup draw scale for constraint - steps = (int)round(l / (10*( *scale))); - steps = steps<3?3:steps; + // OvG: Increase 10 units distance proportionately to l for larger objects. + if (l >= 30) { + *scale = this->calcDrawScaleFactor(l); // OvG: setup draw scale for constraint + steps = (int)round(l / (10 * (*scale))); + steps = steps < 3 ? 3 : steps; } - else if (l >= 20) - { + else if (l >= 20) { steps = (int)round(l / 10); - *scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint + *scale = this->calcDrawScaleFactor(); // OvG: setup draw scale for constraint } - else - { + else { steps = 1; - *scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint + *scale = this->calcDrawScaleFactor(); // OvG: setup draw scale for constraint } - steps = steps>CONSTRAINTSTEPLIMIT?CONSTRAINTSTEPLIMIT:steps; //OvG: Place upper limit on number of steps + // OvG: Place upper limit on number of steps + steps = steps > CONSTRAINTSTEPLIMIT ? CONSTRAINTSTEPLIMIT : steps; double step = (lp - fp) / steps; for (int i = 0; i < steps + 1; i++) { // Parameter values must be in the range [fp, lp] (#0003683) @@ -256,12 +277,12 @@ bool Constraint::getPoints(std::vector &points, std::vectorValue(ulp, vfp); gp_Pnt p2 = hsurf->Value(ulp, vlp); - lv = (l + p1.Distance(p2))/2.0; + lv = (l + p1.Distance(p2)) / 2.0; } try { @@ -276,52 +297,52 @@ bool Constraint::getPoints(std::vector &points, std::vectorValue(ufp, vlp); gp_Pnt p2 = hsurf->Value(ulp, vlp); - lu = (l + p1.Distance(p2))/2.0; + lu = (l + p1.Distance(p2)) / 2.0; } + // OvG: Increase 10 units distance proportionately to lv for larger objects. int stepsv; - if (lv >= 30) //OvG: Increase 10 units distance proportionately to lv for larger objects. - { - *scale = this->calcDrawScaleFactor(lv, lu); //OvG: setup draw scale for constraint + if (lv >= 30) { + *scale = this->calcDrawScaleFactor(lv, lu); // OvG: setup draw scale for constraint stepsv = (int)round(lv / (10 * (*scale))); - stepsv = stepsv<3?3:stepsv; + stepsv = stepsv < 3 ? 3 : stepsv; } - else if (lv >= 20.0) - { + else if (lv >= 20.0) { stepsv = (int)round(lv / 10); - *scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint + *scale = this->calcDrawScaleFactor(); // OvG: setup draw scale for constraint } - else - { - stepsv = 2; // Minimum of three arrows to ensure (as much as possible) that at least one is displayed - *scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint + else { + // Minimum of three arrows to ensure (as much as possible) that at + // least one is displayed + stepsv = 2; + *scale = this->calcDrawScaleFactor(); // OvG: setup draw scale for constraint } - stepsv = stepsv>CONSTRAINTSTEPLIMIT?CONSTRAINTSTEPLIMIT:stepsv; //OvG: Place upper limit on number of steps + // OvG: Place upper limit on number of steps + stepsv = stepsv > CONSTRAINTSTEPLIMIT ? CONSTRAINTSTEPLIMIT : stepsv; int stepsu; - if (lu >= 30) //OvG: Increase 10 units distance proportionately to lu for larger objects. - { - *scale = this->calcDrawScaleFactor(lv,lu); //OvG: setup draw scale for constraint - stepsu = (int)round(lu / (10*( *scale))); - stepsu = stepsu<3?3:stepsu; + // OvG: Increase 10 units distance proportionately to lu for larger objects. + if (lu >= 30) { + *scale = this->calcDrawScaleFactor(lv, lu); // OvG: setup draw scale for constraint + stepsu = (int)round(lu / (10 * (*scale))); + stepsu = stepsu < 3 ? 3 : stepsu; } - else if (lu >= 20.0) - { + else if (lu >= 20.0) { stepsu = (int)round(lu / 10); - *scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint + *scale = this->calcDrawScaleFactor(); // OvG: setup draw scale for constraint } - else - { + else { stepsu = 2; - *scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint + *scale = this->calcDrawScaleFactor(); // OvG: setup draw scale for constraint } - stepsu = stepsu>CONSTRAINTSTEPLIMIT?CONSTRAINTSTEPLIMIT:stepsu; //OvG: Place upper limit on number of steps + // OvG: Place upper limit on number of steps + stepsu = stepsu > CONSTRAINTSTEPLIMIT ? CONSTRAINTSTEPLIMIT : stepsu; double stepv = (vlp - vfp) / stepsv; double stepu = (ulp - ufp) / stepsu; // Create points and normals @@ -333,7 +354,7 @@ bool Constraint::getPoints(std::vector &points, std::vector &points, std::vector Objects = References.getValues(); std::vector SubElements = References.getSubValues(); - if (Objects.empty()) + if (Objects.empty()) { return false; + } App::DocumentObject* obj = Objects[0]; Part::Feature* feat = static_cast(obj); const Part::TopoShape& toposhape = feat->Shape.getShape(); - if (toposhape.isNull()) + if (toposhape.isNull()) { return false; + } TopoDS_Shape sh = toposhape.getSubShape(SubElements[0].c_str()); TopoDS_Face face = TopoDS::Face(sh); BRepAdaptor_Surface surface(face); gp_Cylinder cyl = surface.Cylinder(); gp_Pnt start = surface.Value(surface.FirstUParameter(), surface.FirstVParameter()); - gp_Pnt end = surface.Value(surface.FirstUParameter(), surface.LastVParameter()); + gp_Pnt end = surface.Value(surface.FirstUParameter(), surface.LastVParameter()); height = start.Distance(end); radius = cyl.Radius(); @@ -374,14 +400,17 @@ bool Constraint::getCylinder(double &radius, double &height, Base::Vector3d& bas return true; } -Base::Vector3d Constraint::getBasePoint(const Base::Vector3d& base, const Base::Vector3d& axis, - const App::PropertyLinkSub& location, const double& dist) +Base::Vector3d Constraint::getBasePoint(const Base::Vector3d& base, + const Base::Vector3d& axis, + const App::PropertyLinkSub& location, + const double& dist) { // Get the point specified by Location and Distance App::DocumentObject* objLoc = location.getValue(); std::vector names = location.getSubValues(); - if (names.empty()) - return Base::Vector3d(0,0,0); + if (names.empty()) { + return Base::Vector3d(0, 0, 0); + } std::string subName = names.front(); Part::Feature* featLoc = static_cast(objLoc); TopoDS_Shape shloc = featLoc->Shape.getShape().getSubShape(subName.c_str()); @@ -392,7 +421,8 @@ Base::Vector3d Constraint::getBasePoint(const Base::Vector3d& base, const Base:: if (shloc.ShapeType() == TopAbs_FACE) { BRepAdaptor_Surface surface(TopoDS::Face(shloc)); plane = surface.Plane(); - } else { + } + else { BRepAdaptor_Curve curve(TopoDS::Edge(shloc)); gp_Lin line = curve.Line(); gp_Dir tang = line.Direction().Crossed(cylaxis); @@ -404,28 +434,32 @@ Base::Vector3d Constraint::getBasePoint(const Base::Vector3d& base, const Base:: Handle(Geom_Plane) pln = new Geom_Plane(plane); gp_Pnt cylbase(base.x, base.y, base.z); GeomAPI_ProjectPointOnSurf proj(cylbase, pln); - if (!proj.IsDone()) - return Base::Vector3d(0,0,0); + if (!proj.IsDone()) { + return Base::Vector3d(0, 0, 0); + } gp_Pnt projPnt = proj.NearestPoint(); - if ((fabs(dist) > Precision::Confusion()) && (projPnt.IsEqual(cylbase, Precision::Confusion()) == Standard_False)) + if ((fabs(dist) > Precision::Confusion()) + && (projPnt.IsEqual(cylbase, Precision::Confusion()) == Standard_False)) { plane.Translate(gp_Vec(projPnt, cylbase).Normalized().Multiplied(dist)); + } Handle(Geom_Plane) plnt = new Geom_Plane(plane); // Intersect translated plane with cylinder axis Handle(Geom_Curve) crv = new Geom_Line(cylbase, cylaxis); GeomAPI_IntCS intersector(crv, plnt); - if (!intersector.IsDone()) - return Base::Vector3d(0,0,0); + if (!intersector.IsDone()) { + return Base::Vector3d(0, 0, 0); + } gp_Pnt inter = intersector.Point(1); return Base::Vector3d(inter.X(), inter.Y(), inter.Z()); } -const Base::Vector3d Constraint::getDirection(const App::PropertyLinkSub &direction) +const Base::Vector3d Constraint::getDirection(const App::PropertyLinkSub& direction) { App::DocumentObject* obj = direction.getValue(); if (!obj) { - return Base::Vector3d(0,0,0); + return Base::Vector3d(0, 0, 0); } if (obj->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) { @@ -447,13 +481,15 @@ const Base::Vector3d Constraint::getDirection(const App::PropertyLinkSub &direct } std::vector names = direction.getSubValues(); - if (names.empty()) - return Base::Vector3d(0,0,0); + if (names.empty()) { + return Base::Vector3d(0, 0, 0); + } std::string subName = names.front(); Part::Feature* feat = static_cast(obj); const Part::TopoShape& shape = feat->Shape.getShape(); - if (shape.isNull()) - return Base::Vector3d(0,0,0); + if (shape.isNull()) { + return Base::Vector3d(0, 0, 0); + } TopoDS_Shape sh; try { sh = shape.getSubShape(subName.c_str()); @@ -469,17 +505,22 @@ const Base::Vector3d Constraint::getDirection(const App::PropertyLinkSub &direct // Python feature --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Fem::ConstraintPython, Fem::Constraint) -template<> const char* Fem::ConstraintPython::getViewProviderName() const { +template<> +const char* Fem::ConstraintPython::getViewProviderName() const +{ return "FemGui::ViewProviderFemConstraintPython"; } -template<> PyObject* Fem::ConstraintPython::getPyObject() { +template<> +PyObject* Fem::ConstraintPython::getPyObject() +{ if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new App::FeaturePythonPyT(this),true); + PythonObject = Py::Object(new App::FeaturePythonPyT(this), true); } return Py::new_reference_to(PythonObject); } @@ -489,4 +530,4 @@ template class FemExport FeaturePythonT; /// @endcond -} +} // namespace App diff --git a/src/Mod/Fem/App/FemConstraint.h b/src/Mod/Fem/App/FemConstraint.h index 77899c69bd..e5f9c0782f 100644 --- a/src/Mod/Fem/App/FemConstraint.h +++ b/src/Mod/Fem/App/FemConstraint.h @@ -32,7 +32,8 @@ #include -namespace Fem { +namespace Fem +{ /** * @brief Base class of all Constraint Objects of the Fem module. @@ -56,7 +57,8 @@ namespace Fem { * and @ref Scale and the protected method @ref getPoints(points&, normals&, * scale&). */ -class FemExport Constraint : public App::DocumentObject { +class FemExport Constraint: public App::DocumentObject +{ PROPERTY_HEADER_WITH_OVERRIDE(Fem::Constraint); public: @@ -113,7 +115,7 @@ public: * cleared right after the @ref execute call by the recompute mechanism. * See Document::recompute() and DocumentObject::purgeTouched(). */ - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /** * @brief Calculates scale factor based on length of edge. @@ -154,12 +156,12 @@ public: */ int calcDrawScaleFactor() const; - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemConstraint"; } protected: - /** * @brief Updates NormalDirection if References change. */ @@ -208,10 +210,9 @@ protected: * returns true. If an error occurred and the data couldn't be extracted * properly false is returned. */ - bool getPoints( - std::vector& points, - std::vector& normals, - int * scale) const; + bool getPoints(std::vector& points, + std::vector& normals, + int* scale) const; /** * @brief Extract properties of cylindrical face. @@ -220,9 +221,8 @@ protected: * This method is very specific and doesn't require access to member * variables. It should be rewritten at a different place. */ - bool getCylinder( - double& radius, double& height, - Base::Vector3d& base, Base::Vector3d& axis) const; + bool + getCylinder(double& radius, double& height, Base::Vector3d& base, Base::Vector3d& axis) const; /** * @brief Calculate point of cylindrical face where to render widget. @@ -231,8 +231,10 @@ protected: * This method is very specific and doesn't require access to member * variables. It should be rewritten at a different place. */ - Base::Vector3d getBasePoint(const Base::Vector3d& base, const Base::Vector3d& axis, - const App::PropertyLinkSub &location, const double& dist); + Base::Vector3d getBasePoint(const Base::Vector3d& base, + const Base::Vector3d& axis, + const App::PropertyLinkSub& location, + const double& dist); /** * @brief Get normal vector of point calculated by @ref getBasePoint. * @@ -240,13 +242,13 @@ protected: * This method is very specific and doesn't require access to member * variables. It should be rewritten at a different place. */ - const Base::Vector3d getDirection(const App::PropertyLinkSub &direction); + const Base::Vector3d getDirection(const App::PropertyLinkSub& direction); }; using ConstraintPython = App::FeaturePythonT; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINT_H +#endif // FEM_CONSTRAINT_H diff --git a/src/Mod/Fem/App/FemConstraintBearing.cpp b/src/Mod/Fem/App/FemConstraintBearing.cpp index e54cef3e39..69a06a86c0 100644 --- a/src/Mod/Fem/App/FemConstraintBearing.cpp +++ b/src/Mod/Fem/App/FemConstraintBearing.cpp @@ -40,19 +40,28 @@ PROPERTY_SOURCE(Fem::ConstraintBearing, Fem::Constraint) ConstraintBearing::ConstraintBearing() { - ADD_PROPERTY_TYPE(Location,(nullptr),"ConstraintBearing",(App::PropertyType)(App::Prop_None), + ADD_PROPERTY_TYPE(Location, + (nullptr), + "ConstraintBearing", + (App::PropertyType)(App::Prop_None), "Element giving axial location of constraint"); - ADD_PROPERTY(Dist,(0.0)); - ADD_PROPERTY(AxialFree,(0)); - ADD_PROPERTY(Radius,(0.0)); - ADD_PROPERTY(Height,(0.0)); - ADD_PROPERTY_TYPE(BasePoint,(Base::Vector3d(0,0,0)),"ConstraintBearing",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY(Dist, (0.0)); + ADD_PROPERTY(AxialFree, (0)); + ADD_PROPERTY(Radius, (0.0)); + ADD_PROPERTY(Height, (0.0)); + ADD_PROPERTY_TYPE(BasePoint, + (Base::Vector3d(0, 0, 0)), + "ConstraintBearing", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Base point of cylindrical bearing seat"); - ADD_PROPERTY_TYPE(Axis,(Base::Vector3d(0,1,0)),"ConstraintBearing",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(Axis, + (Base::Vector3d(0, 1, 0)), + "ConstraintBearing", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Axis of bearing seat"); } -App::DocumentObjectExecReturn *ConstraintBearing::execute() +App::DocumentObjectExecReturn* ConstraintBearing::execute() { return Constraint::execute(); } @@ -67,19 +76,21 @@ void ConstraintBearing::onChanged(const App::Property* prop) // Find data of cylinder double radius, height; Base::Vector3d base, axis; - if (!getCylinder(radius, height, base, axis)) + if (!getCylinder(radius, height, base, axis)) { return; + } Radius.setValue(radius); Axis.setValue(axis); Height.setValue(height); // Update base point - base = base + axis * height/2; + base = base + axis * height / 2; if (Location.getValue()) { base = getBasePoint(base, axis, Location, Dist.getValue()); } BasePoint.setValue(base); - BasePoint.touch(); // This triggers ViewProvider::updateData() - } else if ((prop == &Location) || (prop == &Dist)) { + BasePoint.touch(); // This triggers ViewProvider::updateData() + } + else if ((prop == &Location) || (prop == &Dist)) { App::DocumentObject* obj = Location.getValue(); std::vector names = Location.getSubValues(); if (names.empty()) { @@ -92,20 +103,22 @@ void ConstraintBearing::onChanged(const App::Property* prop) if (sh.ShapeType() == TopAbs_FACE) { BRepAdaptor_Surface surface(TopoDS::Face(sh)); if (surface.GetType() != GeomAbs_Plane) { - return; // "Location must be a planar face or linear edge" + return; // "Location must be a planar face or linear edge" } - } else if (sh.ShapeType() == TopAbs_EDGE) { + } + else if (sh.ShapeType() == TopAbs_EDGE) { BRepAdaptor_Curve line(TopoDS::Edge(sh)); if (line.GetType() != GeomAbs_Line) { - return; // "Location must be a planar face or linear edge" + return; // "Location must be a planar face or linear edge" } } double radius, height; Base::Vector3d base, axis; - if (!getCylinder(radius, height, base, axis)) + if (!getCylinder(radius, height, base, axis)) { return; - base = getBasePoint(base + axis * height/2, axis, Location, Dist.getValue()); + } + base = getBasePoint(base + axis * height / 2, axis, Location, Dist.getValue()); BasePoint.setValue(base); BasePoint.touch(); } diff --git a/src/Mod/Fem/App/FemConstraintBearing.h b/src/Mod/Fem/App/FemConstraintBearing.h index b5d91ce515..d02fc0e62b 100644 --- a/src/Mod/Fem/App/FemConstraintBearing.h +++ b/src/Mod/Fem/App/FemConstraintBearing.h @@ -33,7 +33,7 @@ namespace Fem { -class FemExport ConstraintBearing : public Fem::Constraint +class FemExport ConstraintBearing: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintBearing); @@ -54,10 +54,11 @@ public: App::PropertyVector Axis; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemConstraintBearing"; } @@ -65,7 +66,7 @@ protected: void onChanged(const App::Property* prop) override; }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTBEARING_H +#endif // FEM_CONSTRAINTBEARING_H diff --git a/src/Mod/Fem/App/FemConstraintContact.cpp b/src/Mod/Fem/App/FemConstraintContact.cpp index 7a1d09be44..d49c67c262 100644 --- a/src/Mod/Fem/App/FemConstraintContact.cpp +++ b/src/Mod/Fem/App/FemConstraintContact.cpp @@ -32,20 +32,26 @@ PROPERTY_SOURCE(Fem::ConstraintContact, Fem::Constraint) ConstraintContact::ConstraintContact() { -/*Note: Initialise parameters here*/ - ADD_PROPERTY(Slope,(0.0)); - ADD_PROPERTY(Friction,(0.0)); -/* */ + /*Note: Initialise parameters here*/ + ADD_PROPERTY(Slope, (0.0)); + ADD_PROPERTY(Friction, (0.0)); + /* */ - ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintContact",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(Points, + (Base::Vector3d()), + "ConstraintContact", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Points where symbols are drawn"); - ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintContact",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Normals where symbols are drawn"); + ADD_PROPERTY_TYPE(Normals, + (Base::Vector3d()), + "ConstraintContact", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), + "Normals where symbols are drawn"); Points.setValues(std::vector()); Normals.setValues(std::vector()); } -App::DocumentObjectExecReturn *ConstraintContact::execute() +App::DocumentObjectExecReturn* ConstraintContact::execute() { return Constraint::execute(); } @@ -62,12 +68,12 @@ void ConstraintContact::onChanged(const App::Property* prop) if (prop == &References) { std::vector points; std::vector normals; - int scale = 1; //OvG: Enforce use of scale + int scale = 1; // OvG: Enforce use of scale if (getPoints(points, normals, &scale)) { Points.setValues(points); Normals.setValues(normals); - Scale.setValue(scale); //OvG: Scale - Points.touch(); // This triggers ViewProvider::updateData() + Scale.setValue(scale); // OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() } } } diff --git a/src/Mod/Fem/App/FemConstraintContact.h b/src/Mod/Fem/App/FemConstraintContact.h index 1c48949f64..60c82cfbf9 100644 --- a/src/Mod/Fem/App/FemConstraintContact.h +++ b/src/Mod/Fem/App/FemConstraintContact.h @@ -30,7 +30,7 @@ namespace Fem { -class FemExport ConstraintContact : public Fem::Constraint +class FemExport ConstraintContact: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintContact); @@ -42,32 +42,31 @@ public: App::PropertyVectorList Points; App::PropertyVectorList Normals; -/*Note*/ - //Constraint parameters + /*Note*/ + // Constraint parameters /****** * Add the constraint parameters here, the variables or data * that needs to be eventually send over to the calculix input file. * This is only the definitions of the variables ******/ - //ex. + // ex. App::PropertyFloat Slope; App::PropertyFloat Friction; - //etc -/* */ + // etc + /* */ /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider const char* getViewProviderName() const override; protected: void onChanged(const App::Property* prop) override; - }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTCONTACT_H +#endif // FEM_CONSTRAINTCONTACT_H diff --git a/src/Mod/Fem/App/FemConstraintDisplacement.cpp b/src/Mod/Fem/App/FemConstraintDisplacement.cpp index d7f56e225c..4fcb5f4f01 100644 --- a/src/Mod/Fem/App/FemConstraintDisplacement.cpp +++ b/src/Mod/Fem/App/FemConstraintDisplacement.cpp @@ -94,7 +94,7 @@ ConstraintDisplacement::ConstraintDisplacement() Normals.setValues(std::vector()); } -App::DocumentObjectExecReturn *ConstraintDisplacement::execute() +App::DocumentObjectExecReturn* ConstraintDisplacement::execute() { return Constraint::execute(); } @@ -105,8 +105,8 @@ const char* ConstraintDisplacement::getViewProviderName() const } void ConstraintDisplacement::handleChangedPropertyType(Base::XMLReader& reader, - const char* TypeName, - App::Property* prop) + const char* TypeName, + App::Property* prop) { // properties _Displacement had App::PropertyFloat and were changed to App::PropertyDistance if (prop == &xDisplacement && strcmp(TypeName, "App::PropertyFloat") == 0) { @@ -152,12 +152,12 @@ void ConstraintDisplacement::onChanged(const App::Property* prop) if (prop == &References) { std::vector points; std::vector normals; - int scale = 1; // OvG: Enforce use of scale + int scale = 1; // OvG: Enforce use of scale if (getPoints(points, normals, &scale)) { Points.setValues(points); Normals.setValues(normals); - Scale.setValue(scale); // OvG: Scale - Points.touch(); // This triggers ViewProvider::updateData() + Scale.setValue(scale); // OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() } } } diff --git a/src/Mod/Fem/App/FemConstraintDisplacement.h b/src/Mod/Fem/App/FemConstraintDisplacement.h index 4ce17ce7ab..69fa72248f 100644 --- a/src/Mod/Fem/App/FemConstraintDisplacement.h +++ b/src/Mod/Fem/App/FemConstraintDisplacement.h @@ -32,7 +32,7 @@ namespace Fem { -class FemExport ConstraintDisplacement : public Fem::Constraint +class FemExport ConstraintDisplacement: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintDisplacement); @@ -44,7 +44,7 @@ public: App::PropertyVectorList Points; App::PropertyVectorList Normals; - //Displacement parameters + // Displacement parameters App::PropertyDistance xDisplacement; App::PropertyDistance yDisplacement; App::PropertyDistance zDisplacement; @@ -72,19 +72,19 @@ public: App::PropertyBool useFlowSurfaceForce; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider const char* getViewProviderName() const override; protected: - void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, + void handleChangedPropertyType(Base::XMLReader& reader, + const char* TypeName, App::Property* prop) override; void onChanged(const App::Property* prop) override; - }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTDISPLACEMENT_H +#endif // FEM_CONSTRAINTDISPLACEMENT_H diff --git a/src/Mod/Fem/App/FemConstraintFixed.cpp b/src/Mod/Fem/App/FemConstraintFixed.cpp index c43ca31cc1..0df6f879f5 100644 --- a/src/Mod/Fem/App/FemConstraintFixed.cpp +++ b/src/Mod/Fem/App/FemConstraintFixed.cpp @@ -32,15 +32,21 @@ PROPERTY_SOURCE(Fem::ConstraintFixed, Fem::Constraint) ConstraintFixed::ConstraintFixed() { - ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintFixed",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(Points, + (Base::Vector3d()), + "ConstraintFixed", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Points where symbols are drawn"); - ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintFixed",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Normals where symbols are drawn"); + ADD_PROPERTY_TYPE(Normals, + (Base::Vector3d()), + "ConstraintFixed", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), + "Normals where symbols are drawn"); Points.setValues(std::vector()); Normals.setValues(std::vector()); } -App::DocumentObjectExecReturn *ConstraintFixed::execute() +App::DocumentObjectExecReturn* ConstraintFixed::execute() { return Constraint::execute(); } @@ -54,12 +60,12 @@ void ConstraintFixed::onChanged(const App::Property* prop) if (prop == &References) { std::vector points; std::vector normals; - int scale = 1; //OvG: Enforce use of scale + int scale = 1; // OvG: Enforce use of scale if (getPoints(points, normals, &scale)) { Points.setValues(points); Normals.setValues(normals); - Scale.setValue(scale); //OvG: Scale - Points.touch(); // This triggers ViewProvider::updateData() + Scale.setValue(scale); // OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() } } } diff --git a/src/Mod/Fem/App/FemConstraintFixed.h b/src/Mod/Fem/App/FemConstraintFixed.h index 79fbf05bf8..a7d2d1462b 100644 --- a/src/Mod/Fem/App/FemConstraintFixed.h +++ b/src/Mod/Fem/App/FemConstraintFixed.h @@ -30,7 +30,7 @@ namespace Fem { -class FemExport ConstraintFixed : public Fem::Constraint +class FemExport ConstraintFixed: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintFixed); @@ -43,10 +43,11 @@ public: App::PropertyVectorList Normals; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemConstraintFixed"; } @@ -54,7 +55,7 @@ protected: void onChanged(const App::Property* prop) override; }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTFIXED_H +#endif // FEM_CONSTRAINTFIXED_H diff --git a/src/Mod/Fem/App/FemConstraintFluidBoundary.cpp b/src/Mod/Fem/App/FemConstraintFluidBoundary.cpp index 20f6f57f76..56a98c888d 100644 --- a/src/Mod/Fem/App/FemConstraintFluidBoundary.cpp +++ b/src/Mod/Fem/App/FemConstraintFluidBoundary.cpp @@ -24,7 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -36,6 +36,7 @@ using namespace Fem; PROPERTY_SOURCE(Fem::ConstraintFluidBoundary, Fem::Constraint) +// clang-format off // see forum topic: https://forum.freecad.org/viewtopic.php?&p=407901 // also defined in TaskFemConstraintFluidBoundary.cpp and FoamCaseBuilder/BasicBuilder.py, update simultaneously @@ -58,9 +59,11 @@ static const char* ThermalBoundaryTypes[] = {"fixedValue","zeroGradient", "fixed static const char* ThermalBoundaryHelpTexts[] = {"fixed Temperature [K]", "no heat transfer ()", "fixed value heat flux [K/m]", "mixed fixedGradient and fixedValue", "fixed heat flux [W/m2]", "Heat transfer coeff [W/(M2)/K]", "conjugate heat transfer with solid", NULL}; */ +// clang-format on ConstraintFluidBoundary::ConstraintFluidBoundary() { + // clang-format off /// momentum boundary: pressure and velocity ADD_PROPERTY_TYPE(BoundaryType,(1),"FluidBoundary",(App::PropertyType)(App::Prop_None), "Basic boundary type like inlet, wall, outlet,etc"); @@ -104,9 +107,10 @@ ConstraintFluidBoundary::ConstraintFluidBoundary() ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"FluidBoundary",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), "Normals where symbols are drawn"); Normals.setValues(std::vector()); + // clang-format on } -App::DocumentObjectExecReturn *ConstraintFluidBoundary::execute() +App::DocumentObjectExecReturn* ConstraintFluidBoundary::execute() { return Constraint::execute(); } @@ -128,40 +132,47 @@ void ConstraintFluidBoundary::onChanged(const App::Property* prop) else if (boundaryType == "freestream") { Subtype.setEnums(FreestreamSubtypes); } - else if(boundaryType == "inlet") { + else if (boundaryType == "inlet") { Subtype.setEnums(InletSubtypes); } - else if(boundaryType == "outlet") { + else if (boundaryType == "outlet") { Subtype.setEnums(OutletSubtypes); } else { Base::Console().Message(boundaryType.c_str()); Base::Console().Message(" Error: this boundaryType is not defined\n"); } - Subtype.setValue(1); // must set a default (0 or 1) as freestream has only 2 subtypes + + // must set a default (0 or 1) as freestream has only 2 subtypes + Subtype.setValue(1); // need to trigger ViewProvider::updateData() for redraw in 3D view after this method } - //naturalDirectionVector is a private member of this class + // naturalDirectionVector is a private member of this class if (prop == &References) { std::vector points; std::vector normals; - int scale = 1; //OvG: Enforce use of scale + int scale = 1; // OvG: Enforce use of scale if (getPoints(points, normals, &scale)) { Points.setValues(points); Normals.setValues(normals); - Scale.setValue(scale); //OvG: Scale - Points.touch(); // This triggers ViewProvider::updateData() + Scale.setValue(scale); // OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() } - } else if (prop == &Direction) { - Base::Vector3d direction = getDirection(Direction); // Fem::Constraint - if (direction.Length() < Precision::Confusion()) // if Direct has no link provided return Base::Vector3d(0,0,0); + } + else if (prop == &Direction) { + Base::Vector3d direction = getDirection(Direction); + // if Direct has no link provided return Base::Vector3d(0,0,0); + if (direction.Length() < Precision::Confusion()) { return; + } naturalDirectionVector = direction; - if (Reversed.getValue()) + if (Reversed.getValue()) { direction = -direction; + } DirectionVector.setValue(direction); - } else if (prop == &Reversed) { + } + else if (prop == &Reversed) { // if the direction is invalid try to compute it again if (naturalDirectionVector.Length() < Precision::Confusion()) { naturalDirectionVector = getDirection(Direction); @@ -169,16 +180,20 @@ void ConstraintFluidBoundary::onChanged(const App::Property* prop) if (naturalDirectionVector.Length() >= Precision::Confusion()) { if (Reversed.getValue() && (DirectionVector.getValue() == naturalDirectionVector)) { DirectionVector.setValue(-naturalDirectionVector); - } else if (!Reversed.getValue() && (DirectionVector.getValue() != naturalDirectionVector)) { + } + else if (!Reversed.getValue() + && (DirectionVector.getValue() != naturalDirectionVector)) { DirectionVector.setValue(naturalDirectionVector); } } - } else if (prop == &NormalDirection) { + } + else if (prop == &NormalDirection) { // Set a default direction if no direction reference has been given if (!Direction.getValue()) { Base::Vector3d direction = NormalDirection.getValue(); - if (Reversed.getValue()) + if (Reversed.getValue()) { direction = -direction; + } DirectionVector.setValue(direction); naturalDirectionVector = direction; } diff --git a/src/Mod/Fem/App/FemConstraintFluidBoundary.h b/src/Mod/Fem/App/FemConstraintFluidBoundary.h index 403e27fc12..9a43031800 100644 --- a/src/Mod/Fem/App/FemConstraintFluidBoundary.h +++ b/src/Mod/Fem/App/FemConstraintFluidBoundary.h @@ -55,14 +55,15 @@ public: App::PropertyBool Reversed; // Read-only (calculated values). These trigger changes in the ViewProvider App::PropertyVectorList Points; - App::PropertyVectorList Normals; // needed to draw diff BoundaryType + App::PropertyVectorList Normals; // needed to draw diff BoundaryType App::PropertyVector DirectionVector; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemConstraintFluidBoundary"; } @@ -73,7 +74,7 @@ private: Base::Vector3d naturalDirectionVector; }; -} //namespace Fem +} // namespace Fem -#endif // FEM_FLUIDBOUNDARY_H +#endif // FEM_FLUIDBOUNDARY_H diff --git a/src/Mod/Fem/App/FemConstraintForce.cpp b/src/Mod/Fem/App/FemConstraintForce.cpp index 7da870e3a3..68099c550a 100644 --- a/src/Mod/Fem/App/FemConstraintForce.cpp +++ b/src/Mod/Fem/App/FemConstraintForce.cpp @@ -24,7 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include "FemConstraintForce.h" @@ -36,19 +36,29 @@ PROPERTY_SOURCE(Fem::ConstraintForce, Fem::Constraint) ConstraintForce::ConstraintForce() { - ADD_PROPERTY(Force,(0.0)); - ADD_PROPERTY_TYPE(Direction,(nullptr),"ConstraintForce",(App::PropertyType)(App::Prop_None), + ADD_PROPERTY(Force, (0.0)); + ADD_PROPERTY_TYPE(Direction, + (nullptr), + "ConstraintForce", + (App::PropertyType)(App::Prop_None), "Element giving direction of constraint"); - ADD_PROPERTY(Reversed,(0)); - ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintForce",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY(Reversed, (0)); + ADD_PROPERTY_TYPE(Points, + (Base::Vector3d()), + "ConstraintForce", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Points where arrows are drawn"); - ADD_PROPERTY_TYPE(DirectionVector,(Base::Vector3d(0,0,1)),"ConstraintForce",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(DirectionVector, + (Base::Vector3d(0, 0, 1)), + "ConstraintForce", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Direction of arrows"); - naturalDirectionVector = Base::Vector3d(0,0,0); // by default use the null vector to indicate an invalid value + naturalDirectionVector = + Base::Vector3d(0, 0, 0); // by default use the null vector to indicate an invalid value Points.setValues(std::vector()); } -App::DocumentObjectExecReturn *ConstraintForce::execute() +App::DocumentObjectExecReturn* ConstraintForce::execute() { return Constraint::execute(); } @@ -62,21 +72,27 @@ void ConstraintForce::onChanged(const App::Property* prop) if (prop == &References) { std::vector points; std::vector normals; - int scale = 1; //OvG: Enforce use of scale + int scale = 1; // OvG: Enforce use of scale if (getPoints(points, normals, &scale)) { - Points.setValues(points); // We don't use the normals because all arrows should have the same direction - Scale.setValue(scale); //OvG Scale + // We don't use the normals because all arrows should have + // the same direction + Points.setValues(points); + Scale.setValue(scale); Points.touch(); } - } else if (prop == &Direction) { + } + else if (prop == &Direction) { Base::Vector3d direction = getDirection(Direction); - if (direction.Length() < Precision::Confusion()) + if (direction.Length() < Precision::Confusion()) { return; + } naturalDirectionVector = direction; - if (Reversed.getValue()) + if (Reversed.getValue()) { direction = -direction; + } DirectionVector.setValue(direction); - } else if (prop == &Reversed) { + } + else if (prop == &Reversed) { // if the direction is invalid try to compute it again if (naturalDirectionVector.Length() < Precision::Confusion()) { naturalDirectionVector = getDirection(Direction); @@ -84,16 +100,20 @@ void ConstraintForce::onChanged(const App::Property* prop) if (naturalDirectionVector.Length() >= Precision::Confusion()) { if (Reversed.getValue() && (DirectionVector.getValue() == naturalDirectionVector)) { DirectionVector.setValue(-naturalDirectionVector); - } else if (!Reversed.getValue() && (DirectionVector.getValue() != naturalDirectionVector)) { + } + else if (!Reversed.getValue() + && (DirectionVector.getValue() != naturalDirectionVector)) { DirectionVector.setValue(naturalDirectionVector); } } - } else if (prop == &NormalDirection) { + } + else if (prop == &NormalDirection) { // Set a default direction if no direction reference has been given if (!Direction.getValue()) { Base::Vector3d direction = NormalDirection.getValue(); - if (Reversed.getValue()) + if (Reversed.getValue()) { direction = -direction; + } DirectionVector.setValue(direction); naturalDirectionVector = direction; } diff --git a/src/Mod/Fem/App/FemConstraintForce.h b/src/Mod/Fem/App/FemConstraintForce.h index 7db3bb904f..8b35686f18 100644 --- a/src/Mod/Fem/App/FemConstraintForce.h +++ b/src/Mod/Fem/App/FemConstraintForce.h @@ -30,7 +30,7 @@ namespace Fem { -class FemExport ConstraintForce : public Fem::Constraint +class FemExport ConstraintForce: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintForce); @@ -46,10 +46,11 @@ public: App::PropertyVector DirectionVector; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemConstraintForce"; } @@ -60,7 +61,7 @@ private: Base::Vector3d naturalDirectionVector; }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTFORCE_H +#endif // FEM_CONSTRAINTFORCE_H diff --git a/src/Mod/Fem/App/FemConstraintGear.cpp b/src/Mod/Fem/App/FemConstraintGear.cpp index 4cd1e03502..1919e2c7b9 100644 --- a/src/Mod/Fem/App/FemConstraintGear.cpp +++ b/src/Mod/Fem/App/FemConstraintGear.cpp @@ -24,7 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include "FemConstraintGear.h" @@ -36,18 +36,24 @@ PROPERTY_SOURCE(Fem::ConstraintGear, Fem::ConstraintBearing) ConstraintGear::ConstraintGear() { - ADD_PROPERTY(Diameter,(100.0)); - ADD_PROPERTY(Force,(1000.0)); - ADD_PROPERTY(ForceAngle,(0.0)); - ADD_PROPERTY_TYPE(Direction,(nullptr),"ConstraintGear",(App::PropertyType)(App::Prop_None), + ADD_PROPERTY(Diameter, (100.0)); + ADD_PROPERTY(Force, (1000.0)); + ADD_PROPERTY(ForceAngle, (0.0)); + ADD_PROPERTY_TYPE(Direction, + (nullptr), + "ConstraintGear", + (App::PropertyType)(App::Prop_None), "Element giving direction of gear force"); - ADD_PROPERTY(Reversed,(0)); - ADD_PROPERTY_TYPE(DirectionVector,(Base::Vector3d(1,1,1).Normalize()),"ConstraintGear",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY(Reversed, (0)); + ADD_PROPERTY_TYPE(DirectionVector, + (Base::Vector3d(1, 1, 1).Normalize()), + "ConstraintGear", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Direction of gear force"); - naturalDirectionVector = Base::Vector3d(1,1,1).Normalize(); + naturalDirectionVector = Base::Vector3d(1, 1, 1).Normalize(); } -App::DocumentObjectExecReturn *ConstraintGear::execute() +App::DocumentObjectExecReturn* ConstraintGear::execute() { return ConstraintBearing::execute(); } @@ -58,18 +64,22 @@ void ConstraintGear::onChanged(const App::Property* prop) if (prop == &Direction) { Base::Vector3d direction = getDirection(Direction); - if (direction.Length() < Precision::Confusion()) + if (direction.Length() < Precision::Confusion()) { return; + } naturalDirectionVector = direction; - if (Reversed.getValue()) + if (Reversed.getValue()) { direction = -direction; + } DirectionVector.setValue(direction); DirectionVector.touch(); - } else if (prop == &Reversed) { + } + else if (prop == &Reversed) { if (Reversed.getValue() && (DirectionVector.getValue() == naturalDirectionVector)) { DirectionVector.setValue(-naturalDirectionVector); DirectionVector.touch(); - } else if (!Reversed.getValue() && (DirectionVector.getValue() != naturalDirectionVector)) { + } + else if (!Reversed.getValue() && (DirectionVector.getValue() != naturalDirectionVector)) { DirectionVector.setValue(naturalDirectionVector); DirectionVector.touch(); } diff --git a/src/Mod/Fem/App/FemConstraintGear.h b/src/Mod/Fem/App/FemConstraintGear.h index b5a5ee5ed6..ed86237105 100644 --- a/src/Mod/Fem/App/FemConstraintGear.h +++ b/src/Mod/Fem/App/FemConstraintGear.h @@ -30,7 +30,7 @@ namespace Fem { -class FemExport ConstraintGear : public Fem::ConstraintBearing +class FemExport ConstraintGear: public Fem::ConstraintBearing { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintGear); @@ -47,10 +47,11 @@ public: App::PropertyVector DirectionVector; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemConstraintGear"; } @@ -61,7 +62,7 @@ private: Base::Vector3d naturalDirectionVector; }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTGear_H +#endif // FEM_CONSTRAINTGear_H diff --git a/src/Mod/Fem/App/FemConstraintHeatflux.cpp b/src/Mod/Fem/App/FemConstraintHeatflux.cpp index 1d98082d67..fdff59ced9 100644 --- a/src/Mod/Fem/App/FemConstraintHeatflux.cpp +++ b/src/Mod/Fem/App/FemConstraintHeatflux.cpp @@ -31,27 +31,36 @@ using namespace Fem; PROPERTY_SOURCE(Fem::ConstraintHeatflux, Fem::Constraint) -static const char* ConstraintTypes[] = {"DFlux","Convection", nullptr}; +static const char* ConstraintTypes[] = {"DFlux", "Convection", nullptr}; ConstraintHeatflux::ConstraintHeatflux() { - ADD_PROPERTY(AmbientTemp,(0.0)); + ADD_PROPERTY(AmbientTemp, (0.0)); /*ADD_PROPERTY(FaceTemp,(0.0));*/ - ADD_PROPERTY(FilmCoef,(0.0)); - ADD_PROPERTY(DFlux,(0.0)); - ADD_PROPERTY_TYPE(ConstraintType,(1),"ConstraintHeatflux",(App::PropertyType)(App::Prop_None), + ADD_PROPERTY(FilmCoef, (0.0)); + ADD_PROPERTY(DFlux, (0.0)); + ADD_PROPERTY_TYPE(ConstraintType, + (1), + "ConstraintHeatflux", + (App::PropertyType)(App::Prop_None), "Type of constraint, surface convection or surface heat flux"); ConstraintType.setEnums(ConstraintTypes); - ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintHeatflux",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(Points, + (Base::Vector3d()), + "ConstraintHeatflux", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Points where symbols are drawn"); - ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintHeatflux",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Normals where symbols are drawn"); + ADD_PROPERTY_TYPE(Normals, + (Base::Vector3d()), + "ConstraintHeatflux", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), + "Normals where symbols are drawn"); Points.setValues(std::vector()); Normals.setValues(std::vector()); } -App::DocumentObjectExecReturn *ConstraintHeatflux::execute() +App::DocumentObjectExecReturn* ConstraintHeatflux::execute() { return Constraint::execute(); } @@ -70,12 +79,12 @@ void ConstraintHeatflux::onChanged(const App::Property* prop) if (prop == &References) { std::vector points; std::vector normals; - int scale = 1; //OvG: Enforce use of scale + int scale = 1; // OvG: Enforce use of scale if (getPoints(points, normals, &scale)) { Points.setValues(points); Normals.setValues(normals); - Scale.setValue(scale); //OvG: Scale - Points.touch(); // This triggers ViewProvider::updateData() + Scale.setValue(scale); // OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() } } } diff --git a/src/Mod/Fem/App/FemConstraintHeatflux.h b/src/Mod/Fem/App/FemConstraintHeatflux.h index 1031bd94c0..69a37d41e5 100644 --- a/src/Mod/Fem/App/FemConstraintHeatflux.h +++ b/src/Mod/Fem/App/FemConstraintHeatflux.h @@ -29,9 +29,10 @@ #include "FemConstraint.h" -namespace Fem { +namespace Fem +{ -class FemExport ConstraintHeatflux : public Fem::Constraint +class FemExport ConstraintHeatflux: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintHeatflux); @@ -48,7 +49,7 @@ public: App::PropertyVectorList Normals; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider const char* getViewProviderName() const override; @@ -57,6 +58,6 @@ protected: void onChanged(const App::Property* prop) override; }; -} +} // namespace Fem -#endif // FEM_CONSTRAINTHEATFLUX_H +#endif // FEM_CONSTRAINTHEATFLUX_H diff --git a/src/Mod/Fem/App/FemConstraintInitialTemperature.cpp b/src/Mod/Fem/App/FemConstraintInitialTemperature.cpp index a8ef1ea755..32b3203c10 100644 --- a/src/Mod/Fem/App/FemConstraintInitialTemperature.cpp +++ b/src/Mod/Fem/App/FemConstraintInitialTemperature.cpp @@ -36,11 +36,13 @@ ConstraintInitialTemperature::ConstraintInitialTemperature() { ADD_PROPERTY(initialTemperature, (300.0)); - ADD_PROPERTY_TYPE(Points, (Base::Vector3d()), + ADD_PROPERTY_TYPE(Points, + (Base::Vector3d()), "ConstraintInitialTemperature", App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Points where symbols are drawn"); - ADD_PROPERTY_TYPE(Normals, (Base::Vector3d()), + ADD_PROPERTY_TYPE(Normals, + (Base::Vector3d()), "ConstraintInitialTemperature", App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Normals where symbols are drawn"); @@ -51,7 +53,7 @@ ConstraintInitialTemperature::ConstraintInitialTemperature() References.setStatus(App::Property::Hidden, true); } -App::DocumentObjectExecReturn *ConstraintInitialTemperature::execute() +App::DocumentObjectExecReturn* ConstraintInitialTemperature::execute() { return Constraint::execute(); } @@ -83,12 +85,12 @@ void ConstraintInitialTemperature::onChanged(const App::Property* prop) if (prop == &References) { std::vector points; std::vector normals; - int scale = 1; //OvG: Enforce use of scale + int scale = 1; // OvG: Enforce use of scale if (getPoints(points, normals, &scale)) { Points.setValues(points); Normals.setValues(normals); - Scale.setValue(scale); //OvG: Scale - Points.touch(); // This triggers ViewProvider::updateData() + Scale.setValue(scale); // OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() } } } diff --git a/src/Mod/Fem/App/FemConstraintInitialTemperature.h b/src/Mod/Fem/App/FemConstraintInitialTemperature.h index 0f27c06d81..fc7331b002 100644 --- a/src/Mod/Fem/App/FemConstraintInitialTemperature.h +++ b/src/Mod/Fem/App/FemConstraintInitialTemperature.h @@ -32,7 +32,7 @@ namespace Fem { -class FemExport ConstraintInitialTemperature : public Fem::Constraint +class FemExport ConstraintInitialTemperature: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintInitialTemperature); @@ -44,24 +44,24 @@ public: App::PropertyVectorList Points; App::PropertyVectorList Normals; - //Temperature parameters + // Temperature parameters App::PropertyTemperature initialTemperature; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider const char* getViewProviderName() const override; protected: - void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, + void handleChangedPropertyType(Base::XMLReader& reader, + const char* TypeName, App::Property* prop) override; void onChanged(const App::Property* prop) override; - }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTINITIALTEMPERATURE_H +#endif // FEM_CONSTRAINTINITIALTEMPERATURE_H diff --git a/src/Mod/Fem/App/FemConstraintPlaneRotation.cpp b/src/Mod/Fem/App/FemConstraintPlaneRotation.cpp index 76e5b01075..fd329393a4 100644 --- a/src/Mod/Fem/App/FemConstraintPlaneRotation.cpp +++ b/src/Mod/Fem/App/FemConstraintPlaneRotation.cpp @@ -33,15 +33,21 @@ PROPERTY_SOURCE(Fem::ConstraintPlaneRotation, Fem::Constraint) ConstraintPlaneRotation::ConstraintPlaneRotation() { - ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintPlaneRotation",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(Points, + (Base::Vector3d()), + "ConstraintPlaneRotation", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Points where symbols are drawn"); - ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintPlaneRotation",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Normals where symbols are drawn"); + ADD_PROPERTY_TYPE(Normals, + (Base::Vector3d()), + "ConstraintPlaneRotation", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), + "Normals where symbols are drawn"); Points.setValues(std::vector()); Normals.setValues(std::vector()); } -App::DocumentObjectExecReturn *ConstraintPlaneRotation::execute() +App::DocumentObjectExecReturn* ConstraintPlaneRotation::execute() { return Constraint::execute(); } @@ -58,12 +64,12 @@ void ConstraintPlaneRotation::onChanged(const App::Property* prop) if (prop == &References) { std::vector points; std::vector normals; - int scale = 1; //OvG: Enforce use of scale + int scale = 1; // OvG: Enforce use of scale if (getPoints(points, normals, &scale)) { Points.setValues(points); Normals.setValues(normals); - Scale.setValue(scale); //OvG: Scale - Points.touch(); // This triggers ViewProvider::updateData() + Scale.setValue(scale); // OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() } } } diff --git a/src/Mod/Fem/App/FemConstraintPlaneRotation.h b/src/Mod/Fem/App/FemConstraintPlaneRotation.h index 04be57401f..a251ded4e8 100644 --- a/src/Mod/Fem/App/FemConstraintPlaneRotation.h +++ b/src/Mod/Fem/App/FemConstraintPlaneRotation.h @@ -30,7 +30,7 @@ namespace Fem { -class FemExport ConstraintPlaneRotation : public Fem::Constraint +class FemExport ConstraintPlaneRotation: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintPlaneRotation); @@ -44,17 +44,16 @@ public: /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider const char* getViewProviderName() const override; protected: void onChanged(const App::Property* prop) override; - }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTPLANEROTATION_H +#endif // FEM_CONSTRAINTPLANEROTATION_H diff --git a/src/Mod/Fem/App/FemConstraintPressure.cpp b/src/Mod/Fem/App/FemConstraintPressure.cpp index ee14198125..5381846f52 100644 --- a/src/Mod/Fem/App/FemConstraintPressure.cpp +++ b/src/Mod/Fem/App/FemConstraintPressure.cpp @@ -32,19 +32,23 @@ PROPERTY_SOURCE(Fem::ConstraintPressure, Fem::Constraint) ConstraintPressure::ConstraintPressure() { - ADD_PROPERTY(Pressure,(0.0)); - ADD_PROPERTY(Reversed,(0)); - ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintPressure", - App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Points where arrows are drawn"); - ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintPressure", - App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Normals where symbols are drawn"); + ADD_PROPERTY(Pressure, (0.0)); + ADD_PROPERTY(Reversed, (0)); + ADD_PROPERTY_TYPE(Points, + (Base::Vector3d()), + "ConstraintPressure", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), + "Points where arrows are drawn"); + ADD_PROPERTY_TYPE(Normals, + (Base::Vector3d()), + "ConstraintPressure", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), + "Normals where symbols are drawn"); Points.setValues(std::vector()); Normals.setValues(std::vector()); } -App::DocumentObjectExecReturn *ConstraintPressure::execute() +App::DocumentObjectExecReturn* ConstraintPressure::execute() { return Constraint::execute(); } @@ -68,7 +72,8 @@ void ConstraintPressure::onChanged(const App::Property* prop) Scale.setValue(scale); Points.touch(); } - } else if (prop == &Reversed) { + } + else if (prop == &Reversed) { Points.touch(); } } diff --git a/src/Mod/Fem/App/FemConstraintPressure.h b/src/Mod/Fem/App/FemConstraintPressure.h index e0773f072b..7ebb3ca754 100644 --- a/src/Mod/Fem/App/FemConstraintPressure.h +++ b/src/Mod/Fem/App/FemConstraintPressure.h @@ -27,9 +27,10 @@ #include "FemConstraint.h" -namespace Fem { +namespace Fem +{ -class FemExport ConstraintPressure : public Fem::Constraint +class FemExport ConstraintPressure: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintPressure); @@ -42,7 +43,7 @@ public: App::PropertyVectorList Normals; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider const char* getViewProviderName() const override; @@ -51,6 +52,6 @@ protected: void onChanged(const App::Property* prop) override; }; -} +} // namespace Fem -#endif // FEM_CONSTRAINTPRESSURE_H +#endif // FEM_CONSTRAINTPRESSURE_H diff --git a/src/Mod/Fem/App/FemConstraintPulley.cpp b/src/Mod/Fem/App/FemConstraintPulley.cpp index d23fd72fd0..d4b136adf4 100644 --- a/src/Mod/Fem/App/FemConstraintPulley.cpp +++ b/src/Mod/Fem/App/FemConstraintPulley.cpp @@ -24,7 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include "FemConstraintPulley.h" @@ -36,16 +36,25 @@ PROPERTY_SOURCE(Fem::ConstraintPulley, Fem::ConstraintGear) ConstraintPulley::ConstraintPulley() { - ADD_PROPERTY(OtherDiameter,(100.0)); - ADD_PROPERTY(CenterDistance,(500.0)); - ADD_PROPERTY(IsDriven,(0)); - ADD_PROPERTY(TensionForce,(0.0)); + ADD_PROPERTY(OtherDiameter, (100.0)); + ADD_PROPERTY(CenterDistance, (500.0)); + ADD_PROPERTY(IsDriven, (0)); + ADD_PROPERTY(TensionForce, (0.0)); - ADD_PROPERTY_TYPE(BeltAngle,(0),"ConstraintPulley",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(BeltAngle, + (0), + "ConstraintPulley", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Angle of belt forces"); - ADD_PROPERTY_TYPE(BeltForce1,(0.0),"ConstraintPulley",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(BeltForce1, + (0.0), + "ConstraintPulley", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "First belt force"); - ADD_PROPERTY_TYPE(BeltForce2,(0.0),"ConstraintPulley",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(BeltForce2, + (0.0), + "ConstraintPulley", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Second belt force"); ForceAngle.setValue(0.0); Diameter.setValue(300.0); @@ -53,7 +62,7 @@ ConstraintPulley::ConstraintPulley() onChanged(&Force); } -App::DocumentObjectExecReturn *ConstraintPulley::execute() +App::DocumentObjectExecReturn* ConstraintPulley::execute() { return ConstraintGear::execute(); } @@ -64,24 +73,30 @@ void ConstraintPulley::onChanged(const App::Property* prop) if ((prop == &Diameter) || (prop == &OtherDiameter) || (prop == &CenterDistance)) { if (CenterDistance.getValue() > Precision::Confusion()) { - BeltAngle.setValue(asin((Diameter.getValue() - OtherDiameter.getValue())/2/CenterDistance.getValue())); + BeltAngle.setValue(asin((Diameter.getValue() - OtherDiameter.getValue()) / 2 + / CenterDistance.getValue())); BeltAngle.touch(); } - } else if ((prop == &Force) || (prop == &TensionForce) || (prop == &IsDriven)) { + } + else if ((prop == &Force) || (prop == &TensionForce) || (prop == &IsDriven)) { double radius = Diameter.getValue() / 2.0; - if (radius < Precision::Confusion()) + if (radius < Precision::Confusion()) { return; - double force = Force.getValue() / (radius/1000); - if (fabs(force) < Precision::Confusion()) + } + double force = Force.getValue() / (radius / 1000); + if (fabs(force) < Precision::Confusion()) { return; + } bool neg = (force < 0.0); - if (neg) + if (neg) { force *= -1.0; + } if (IsDriven.getValue() == neg) { BeltForce1.setValue(force + TensionForce.getValue()); BeltForce2.setValue(TensionForce.getValue()); - } else { + } + else { BeltForce2.setValue(force + TensionForce.getValue()); BeltForce1.setValue(TensionForce.getValue()); } diff --git a/src/Mod/Fem/App/FemConstraintPulley.h b/src/Mod/Fem/App/FemConstraintPulley.h index b881711c51..61df7b8183 100644 --- a/src/Mod/Fem/App/FemConstraintPulley.h +++ b/src/Mod/Fem/App/FemConstraintPulley.h @@ -30,7 +30,7 @@ namespace Fem { -class FemExport ConstraintPulley : public Fem::ConstraintGear +class FemExport ConstraintPulley: public Fem::ConstraintGear { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintPulley); @@ -52,19 +52,19 @@ public: App::PropertyFloat BeltForce2; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemConstraintPulley"; } protected: void onChanged(const App::Property* prop) override; - }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTPulley_H +#endif // FEM_CONSTRAINTPulley_H diff --git a/src/Mod/Fem/App/FemConstraintSpring.cpp b/src/Mod/Fem/App/FemConstraintSpring.cpp index 87b44a5b03..6aa2dbdb6d 100644 --- a/src/Mod/Fem/App/FemConstraintSpring.cpp +++ b/src/Mod/Fem/App/FemConstraintSpring.cpp @@ -26,8 +26,7 @@ #include "FemConstraintSpring.h" -static const char* Stiffnesses[] = {"Normal Stiffness", - "Tangential Stiffness", nullptr}; +static const char* Stiffnesses[] = {"Normal Stiffness", "Tangential Stiffness", nullptr}; using namespace Fem; @@ -38,12 +37,16 @@ ConstraintSpring::ConstraintSpring() ADD_PROPERTY(NormalStiffness, (0.0)); ADD_PROPERTY(TangentialStiffness, (0.0)); ADD_PROPERTY(ElmerStiffness, (1)); - ADD_PROPERTY_TYPE(Points, (Base::Vector3d()), "ConstraintSpring", - App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), - "Points where arrows are drawn"); - ADD_PROPERTY_TYPE(Normals, (Base::Vector3d()), "ConstraintSpring", - App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), - "Normals where symbols are drawn"); + ADD_PROPERTY_TYPE(Points, + (Base::Vector3d()), + "ConstraintSpring", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), + "Points where arrows are drawn"); + ADD_PROPERTY_TYPE(Normals, + (Base::Vector3d()), + "ConstraintSpring", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), + "Normals where symbols are drawn"); ElmerStiffness.setEnums(Stiffnesses); Points.setValues(std::vector()); diff --git a/src/Mod/Fem/App/FemConstraintSpring.h b/src/Mod/Fem/App/FemConstraintSpring.h index bc6fd144bd..52caebf723 100644 --- a/src/Mod/Fem/App/FemConstraintSpring.h +++ b/src/Mod/Fem/App/FemConstraintSpring.h @@ -27,9 +27,10 @@ #include "FemConstraint.h" -namespace Fem { +namespace Fem +{ -class FemExport ConstraintSpring : public Fem::Constraint +class FemExport ConstraintSpring: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintSpring); @@ -43,7 +44,7 @@ public: App::PropertyVectorList Normals; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider const char* getViewProviderName() const override; @@ -52,6 +53,6 @@ protected: void onChanged(const App::Property* prop) override; }; -} +} // namespace Fem -#endif // FEM_CONSTRAINTPSPRING_H +#endif // FEM_CONSTRAINTPSPRING_H diff --git a/src/Mod/Fem/App/FemConstraintTemperature.cpp b/src/Mod/Fem/App/FemConstraintTemperature.cpp index 26e8042bc6..dc4037482f 100644 --- a/src/Mod/Fem/App/FemConstraintTemperature.cpp +++ b/src/Mod/Fem/App/FemConstraintTemperature.cpp @@ -32,28 +32,34 @@ using namespace Fem; PROPERTY_SOURCE(Fem::ConstraintTemperature, Fem::Constraint) -static const char* ConstraintTypes[] = {"CFlux","Temperature", nullptr}; +static const char* ConstraintTypes[] = {"CFlux", "Temperature", nullptr}; ConstraintTemperature::ConstraintTemperature() { ADD_PROPERTY(Temperature, (300.0)); ADD_PROPERTY(CFlux, (0.0)); - ADD_PROPERTY_TYPE(ConstraintType, (1), "ConstraintTemperature", + ADD_PROPERTY_TYPE(ConstraintType, + (1), + "ConstraintTemperature", (App::PropertyType)(App::Prop_None), "Type of constraint, temperature or concentrated heat flux"); ConstraintType.setEnums(ConstraintTypes); - ADD_PROPERTY_TYPE(Points, (Base::Vector3d()), "ConstraintTemperature", + ADD_PROPERTY_TYPE(Points, + (Base::Vector3d()), + "ConstraintTemperature", App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Points where symbols are drawn"); - ADD_PROPERTY_TYPE(Normals, (Base::Vector3d()), "ConstraintTemperature", + ADD_PROPERTY_TYPE(Normals, + (Base::Vector3d()), + "ConstraintTemperature", App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Normals where symbols are drawn"); Points.setValues(std::vector()); Normals.setValues(std::vector()); } -App::DocumentObjectExecReturn *ConstraintTemperature::execute() +App::DocumentObjectExecReturn* ConstraintTemperature::execute() { return Constraint::execute(); } @@ -63,7 +69,8 @@ const char* ConstraintTemperature::getViewProviderName() const return "FemGui::ViewProviderFemConstraintTemperature"; } -void ConstraintTemperature::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, +void ConstraintTemperature::handleChangedPropertyType(Base::XMLReader& reader, + const char* TypeName, App::Property* prop) { // property Temperature had App::PropertyFloat and was changed to App::PropertyTemperature @@ -90,12 +97,12 @@ void ConstraintTemperature::onChanged(const App::Property* prop) if (prop == &References) { std::vector points; std::vector normals; - int scale = 1; //OvG: Enforce use of scale + int scale = 1; // OvG: Enforce use of scale if (getPoints(points, normals, &scale)) { Points.setValues(points); Normals.setValues(normals); - Scale.setValue(scale); //OvG: Scale - Points.touch(); // This triggers ViewProvider::updateData() + Scale.setValue(scale); // OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() } } } diff --git a/src/Mod/Fem/App/FemConstraintTemperature.h b/src/Mod/Fem/App/FemConstraintTemperature.h index 9da66dc089..b857c23a7f 100644 --- a/src/Mod/Fem/App/FemConstraintTemperature.h +++ b/src/Mod/Fem/App/FemConstraintTemperature.h @@ -32,7 +32,7 @@ namespace Fem { -class FemExport ConstraintTemperature : public Fem::Constraint +class FemExport ConstraintTemperature: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintTemperature); @@ -44,26 +44,26 @@ public: App::PropertyVectorList Points; App::PropertyVectorList Normals; - //Temperature parameters + // Temperature parameters App::PropertyTemperature Temperature; App::PropertyPower CFlux; App::PropertyEnumeration ConstraintType; /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider const char* getViewProviderName() const override; protected: - void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, + void handleChangedPropertyType(Base::XMLReader& reader, + const char* TypeName, App::Property* prop) override; void onChanged(const App::Property* prop) override; - }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTTEMPERATURE_H +#endif // FEM_CONSTRAINTTEMPERATURE_H diff --git a/src/Mod/Fem/App/FemConstraintTransform.cpp b/src/Mod/Fem/App/FemConstraintTransform.cpp index ce41ca3d83..6ee538c62f 100644 --- a/src/Mod/Fem/App/FemConstraintTransform.cpp +++ b/src/Mod/Fem/App/FemConstraintTransform.cpp @@ -30,71 +30,86 @@ using namespace Fem; PROPERTY_SOURCE(Fem::ConstraintTransform, Fem::Constraint) -static const char* TransformTypes[] = {"Cylindrical","Rectangular", nullptr}; +static const char* TransformTypes[] = {"Cylindrical", "Rectangular", nullptr}; ConstraintTransform::ConstraintTransform() { ADD_PROPERTY(X_rot, (0.0)); ADD_PROPERTY(Y_rot, (0.0)); ADD_PROPERTY(Z_rot, (0.0)); - ADD_PROPERTY_TYPE(TransformType, (1), "ConstraintTransform", + ADD_PROPERTY_TYPE(TransformType, + (1), + "ConstraintTransform", (App::PropertyType)(App::Prop_None), "Type of transform, rectangular or cylindrical"); TransformType.setEnums(TransformTypes); - ADD_PROPERTY_TYPE(RefDispl, (nullptr, nullptr), - "ConstraintTransform", (App::PropertyType)(App::Prop_None), + ADD_PROPERTY_TYPE(RefDispl, + (nullptr, nullptr), + "ConstraintTransform", + (App::PropertyType)(App::Prop_None), "Elements where the constraint is applied"); // RefDispl must get a global scope, see // https://forum.freecad.org/viewtopic.php?p=671402#p671402 RefDispl.setScope(App::LinkScope::Global); - ADD_PROPERTY_TYPE(NameDispl, (nullptr), "ConstraintTransform", + ADD_PROPERTY_TYPE(NameDispl, + (nullptr), + "ConstraintTransform", (App::PropertyType)(App::Prop_None), "Elements where the constraint is applied"); - ADD_PROPERTY_TYPE(BasePoint, (Base::Vector3d(0, 0, 0)), "ConstraintTransform", + ADD_PROPERTY_TYPE(BasePoint, + (Base::Vector3d(0, 0, 0)), + "ConstraintTransform", App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Base point of cylindrical surface"); - ADD_PROPERTY_TYPE(Axis, (Base::Vector3d(0, 1, 0)), "ConstraintTransform", + ADD_PROPERTY_TYPE(Axis, + (Base::Vector3d(0, 1, 0)), + "ConstraintTransform", App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Axis of cylindrical surface"); - ADD_PROPERTY_TYPE(Points, (Base::Vector3d()), "ConstraintTransform", + ADD_PROPERTY_TYPE(Points, + (Base::Vector3d()), + "ConstraintTransform", App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Points where symbols are drawn"); - ADD_PROPERTY_TYPE(Normals, (Base::Vector3d()), "ConstraintTransform", + ADD_PROPERTY_TYPE(Normals, + (Base::Vector3d()), + "ConstraintTransform", App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Normals where symbols are drawn"); Points.setValues(std::vector()); Normals.setValues(std::vector()); } -App::DocumentObjectExecReturn *ConstraintTransform::execute() +App::DocumentObjectExecReturn* ConstraintTransform::execute() { return Constraint::execute(); } const char* ConstraintTransform::getViewProviderName() const { - return "FemGui::ViewProviderFemConstraintTransform"; + return "FemGui::ViewProviderFemConstraintTransform"; } void ConstraintTransform::handleChangedPropertyType(Base::XMLReader& reader, - const char* TypeName, App::Property* prop) + const char* TypeName, + App::Property* prop) { - // properties _rot had App::PropertyFloat and were changed to App::PropertyAngle - if (prop == &X_rot && strcmp(TypeName, "App::PropertyFloat") == 0) { - App::PropertyFloat X_rotProperty; - X_rotProperty.Restore(reader); - X_rot.setValue(X_rotProperty.getValue()); - } - else if (prop == &Y_rot && strcmp(TypeName, "App::PropertyFloat") == 0) { - App::PropertyFloat Y_rotProperty; - Y_rotProperty.Restore(reader); - Y_rot.setValue(Y_rotProperty.getValue()); - } - else if (prop == &Z_rot && strcmp(TypeName, "App::PropertyFloat") == 0) { - App::PropertyFloat Z_rotProperty; - Z_rotProperty.Restore(reader); - Z_rot.setValue(Z_rotProperty.getValue()); - } + // properties _rot had App::PropertyFloat and were changed to App::PropertyAngle + if (prop == &X_rot && strcmp(TypeName, "App::PropertyFloat") == 0) { + App::PropertyFloat X_rotProperty; + X_rotProperty.Restore(reader); + X_rot.setValue(X_rotProperty.getValue()); + } + else if (prop == &Y_rot && strcmp(TypeName, "App::PropertyFloat") == 0) { + App::PropertyFloat Y_rotProperty; + Y_rotProperty.Restore(reader); + Y_rot.setValue(Y_rotProperty.getValue()); + } + else if (prop == &Z_rot && strcmp(TypeName, "App::PropertyFloat") == 0) { + App::PropertyFloat Z_rotProperty; + Z_rotProperty.Restore(reader); + Z_rot.setValue(Z_rotProperty.getValue()); + } } void ConstraintTransform::onChanged(const App::Property* prop) @@ -104,24 +119,25 @@ void ConstraintTransform::onChanged(const App::Property* prop) if (prop == &References) { std::vector points; std::vector normals; - int scale = 1; //OvG: Enforce use of scale + int scale = 1; // OvG: Enforce use of scale if (getPoints(points, normals, &scale)) { Points.setValues(points); Normals.setValues(normals); - Scale.setValue(scale); //OvG: Scale - Points.touch(); // This triggers ViewProvider::updateData() + Scale.setValue(scale); // OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() std::string transform_type = TransformType.getValueAsString(); if (transform_type == "Cylindrical") { // Find data of cylinder double radius, height; Base::Vector3d base, axis; - if (!getCylinder(radius, height, base, axis)) - return; + if (!getCylinder(radius, height, base, axis)) { + return; + } Axis.setValue(axis); // Update base point - base = base + axis * height/2; + base = base + axis * height / 2; BasePoint.setValue(base); - BasePoint.touch(); // This triggers ViewProvider::updateData() + BasePoint.touch(); // This triggers ViewProvider::updateData() } } } diff --git a/src/Mod/Fem/App/FemConstraintTransform.h b/src/Mod/Fem/App/FemConstraintTransform.h index 417992501c..27eb133da6 100644 --- a/src/Mod/Fem/App/FemConstraintTransform.h +++ b/src/Mod/Fem/App/FemConstraintTransform.h @@ -29,7 +29,7 @@ namespace Fem { -class FemExport ConstraintTransform : public Fem::Constraint +class FemExport ConstraintTransform: public Fem::Constraint { PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintTransform); @@ -48,23 +48,23 @@ public: App::PropertyAngle Y_rot; App::PropertyAngle Z_rot; App::PropertyEnumeration TransformType; - //etc -/* */ + // etc + /* */ /// recalculate the object - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; /// returns the type name of the ViewProvider const char* getViewProviderName() const override; protected: - void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, + void handleChangedPropertyType(Base::XMLReader& reader, + const char* TypeName, App::Property* prop) override; void onChanged(const App::Property* prop) override; - }; -} //namespace Fem +} // namespace Fem -#endif // FEM_CONSTRAINTTransform_H +#endif // FEM_CONSTRAINTTransform_H diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index ceaf0bd50d..56e315f830 100644 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -23,41 +23,41 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -# include -# include //to simplify parsing input files we use the boost lib +#include +#include //to simplify parsing input files we use the boost lib #endif #include @@ -74,7 +74,7 @@ #include #ifdef FC_USE_VTK -# include "FemVTKTools.h" +#include "FemVTKTools.h" #endif @@ -88,16 +88,16 @@ static int StatCount = 0; SMESH_Gen* FemMesh::_mesh_gen = nullptr; -TYPESYSTEM_SOURCE(Fem::FemMesh , Base::Persistence) +TYPESYSTEM_SOURCE(Fem::FemMesh, Base::Persistence) FemMesh::FemMesh() { - //Base::Console().Log("FemMesh::FemMesh():%p (id=%i)\n",this,StatCount); - // create a mesh always with new StudyId to avoid overlapping destruction + // Base::Console().Log("FemMesh::FemMesh():%p (id=%i)\n",this,StatCount); + // create a mesh always with new StudyId to avoid overlapping destruction #if SMESH_VERSION_MAJOR >= 9 myMesh = getGenerator()->CreateMesh(false); #else - myMesh = getGenerator()->CreateMesh(StatCount++,false); + myMesh = getGenerator()->CreateMesh(StatCount++, false); #endif } @@ -106,33 +106,33 @@ FemMesh::FemMesh(const FemMesh& mesh) #if SMESH_VERSION_MAJOR >= 9 myMesh = getGenerator()->CreateMesh(false); #else - myMesh = getGenerator()->CreateMesh(StatCount++,false); + myMesh = getGenerator()->CreateMesh(StatCount++, false); #endif copyMeshData(mesh); } FemMesh::~FemMesh() { - //Base::Console().Log("FemMesh::~FemMesh():%p\n",this); + // Base::Console().Log("FemMesh::~FemMesh():%p\n",this); try { TopoDS_Shape aNull; myMesh->ShapeToMesh(aNull); myMesh->Clear(); - //myMesh->ClearLog(); + // myMesh->ClearLog(); delete myMesh; } catch (...) { } } -FemMesh &FemMesh::operator=(const FemMesh& mesh) +FemMesh& FemMesh::operator=(const FemMesh& mesh) { if (this != &mesh) { #if SMESH_VERSION_MAJOR >= 9 myMesh = getGenerator()->CreateMesh(true); #else - myMesh = getGenerator()->CreateMesh(0,true); + myMesh = getGenerator()->CreateMesh(0, true); #endif copyMeshData(mesh); } @@ -154,24 +154,26 @@ void FemMesh::copyMeshData(const FemMesh& mesh) SMESH_MeshEditor editor(this->myMesh); // 3. Get elements to copy - SMDS_ElemIteratorPtr srcElemIt; SMDS_NodeIteratorPtr srcNodeIt; + SMDS_ElemIteratorPtr srcElemIt; + SMDS_NodeIteratorPtr srcNodeIt; srcElemIt = srcMeshDS->elementsIterator(); srcNodeIt = srcMeshDS->nodesIterator(); // 4. Copy elements int iN; const SMDS_MeshNode *nSrc, *nTgt; - std::vector< const SMDS_MeshNode* > nodes; + std::vector nodes; while (srcElemIt->more()) { - const SMDS_MeshElement * elem = srcElemIt->next(); + const SMDS_MeshElement* elem = srcElemIt->next(); // find / add nodes nodes.resize(elem->NbNodes()); SMDS_ElemIteratorPtr nIt = elem->nodesIterator(); for (iN = 0; nIt->more(); ++iN) { - nSrc = static_cast( nIt->next() ); - nTgt = newMeshDS->FindNode( nSrc->GetID()); - if (!nTgt) - nTgt = newMeshDS->AddNodeWithID( nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID()); + nSrc = static_cast(nIt->next()); + nTgt = newMeshDS->FindNode(nSrc->GetID()); + if (!nTgt) { + nTgt = newMeshDS->AddNodeWithID(nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID()); + } nodes[iN] = nTgt; } @@ -179,25 +181,27 @@ void FemMesh::copyMeshData(const FemMesh& mesh) if (elem->GetType() != SMDSAbs_Node) { int ID = elem->GetID(); switch (elem->GetEntityType()) { - case SMDSEntity_Polyhedra: + case SMDSEntity_Polyhedra: #if SMESH_VERSION_MAJOR >= 9 - editor.GetMeshDS()->AddPolyhedralVolumeWithID( - nodes, static_cast(elem)->GetQuantities(), ID); + editor.GetMeshDS()->AddPolyhedralVolumeWithID( + nodes, + static_cast(elem)->GetQuantities(), + ID); #else - editor.GetMeshDS()->AddPolyhedralVolumeWithID( - nodes, static_cast(elem)->GetQuantities(), ID); + editor.GetMeshDS()->AddPolyhedralVolumeWithID( + nodes, + static_cast(elem)->GetQuantities(), + ID); #endif - break; - case SMDSEntity_Ball: - { - SMESH_MeshEditor::ElemFeatures elemFeat; - elemFeat.Init(static_cast(elem)->GetDiameter()); - elemFeat.SetID(ID); - editor.AddElement(nodes, elemFeat); - break; - } - default: - { + break; + case SMDSEntity_Ball: { + SMESH_MeshEditor::ElemFeatures elemFeat; + elemFeat.Init(static_cast(elem)->GetDiameter()); + elemFeat.SetID(ID); + editor.AddElement(nodes, elemFeat); + break; + } + default: { SMESH_MeshEditor::ElemFeatures elemFeat(elem->GetType(), elem->IsPoly()); elemFeat.SetID(ID); editor.AddElement(nodes, elemFeat); @@ -225,23 +229,27 @@ void FemMesh::copyMeshData(const FemMesh& mesh) // Check group type. We copy nodal groups containing nodes of copied element SMDSAbs_ElementType groupType = groupDS->GetType(); - if (groupType != SMDSAbs_Node && newMeshDS->GetMeshInfo().NbElements( groupType ) == 0) - continue; // group type differs from types of meshPart + if (groupType != SMDSAbs_Node && newMeshDS->GetMeshInfo().NbElements(groupType) == 0) { + continue; // group type differs from types of meshPart + } // Find copied elements in the group - std::vector< const SMDS_MeshElement* > groupElems; + std::vector groupElems; SMDS_ElemIteratorPtr eIt = groupDS->GetElements(); const SMDS_MeshElement* foundElem; if (groupType == SMDSAbs_Node) { while (eIt->more()) { - if ((foundElem = newMeshDS->FindNode( eIt->next()->GetID()))) + if ((foundElem = newMeshDS->FindNode(eIt->next()->GetID()))) { groupElems.push_back(foundElem); + } } } else { - while (eIt->more()) - if ((foundElem = newMeshDS->FindElement(eIt->next()->GetID()))) + while (eIt->more()) { + if ((foundElem = newMeshDS->FindElement(eIt->next()->GetID()))) { groupElems.push_back(foundElem); + } + } } // Make a new group @@ -251,8 +259,9 @@ void FemMesh::copyMeshData(const FemMesh& mesh) SMESHDS_Group* newGroupDS = dynamic_cast(newGroupObj->GetGroupDS()); if (newGroupDS) { SMDS_MeshGroup& smdsGroup = ((SMESHDS_Group*)newGroupDS)->SMDSGroup(); - for (auto it : groupElems) + for (auto it : groupElems) { smdsGroup.Add(it); + } } } } @@ -265,20 +274,20 @@ void FemMesh::copyMeshData(const FemMesh& mesh) // Some further information is still not copied: // http://forum.freecad.org/viewtopic.php?f=18&t=18982#p148114 SMDS_NodeIteratorPtr aNodeIter = mesh.myMesh->GetMeshDS()->nodesIterator(); - for (;aNodeIter->more();) { + for (; aNodeIter->more();) { const SMDS_MeshNode* aNode = aNodeIter->next(); double temp[3]; aNode->GetXYZ(temp); - meshds->AddNodeWithID(temp[0],temp[1],temp[2], aNode->GetID()); + meshds->AddNodeWithID(temp[0], temp[1], temp[2], aNode->GetID()); } SMDS_EdgeIteratorPtr aEdgeIter = mesh.myMesh->GetMeshDS()->edgesIterator(); - for (;aEdgeIter->more();) { + for (; aEdgeIter->more();) { const SMDS_MeshEdge* aEdge = aEdgeIter->next(); meshds->AddEdgeWithID(aEdge->GetNode(0), aEdge->GetNode(1), aEdge->GetID()); } SMDS_FaceIteratorPtr aFaceIter = mesh.myMesh->GetMeshDS()->facesIterator(); - for (;aFaceIter->more();) { + for (; aFaceIter->more();) { const SMDS_MeshFace* aFace = aFaceIter->next(); switch (aFace->NbNodes()) { case 3: @@ -316,15 +325,16 @@ void FemMesh::copyMeshData(const FemMesh& mesh) break; default: { std::vector aNodes; - for (int i = 0; aFace->NbNodes(); i++) + for (int i = 0; aFace->NbNodes(); i++) { aNodes.push_back(aFace->GetNode(0)); + } meshds->AddPolygonalFaceWithID(aNodes, aFace->GetID()); } break; } } SMDS_VolumeIteratorPtr aVolIter = mesh.myMesh->GetMeshDS()->volumesIterator(); - for (;aVolIter->more();) { + for (; aVolIter->more();) { const SMDS_MeshVolume* aVol = aVolIter->next(); switch (aVol->NbNodes()) { case 4: @@ -434,15 +444,18 @@ void FemMesh::copyMeshData(const FemMesh& mesh) break; default: { if (aVol->IsPoly()) { - const SMDS_PolyhedralVolumeOfNodes* aPolyVol = - dynamic_cast(aVol); - if (!aPolyVol) - break; - std::vector aNodes; - for (int i = 0; i < aPolyVol->NbNodes(); i++) - aNodes.push_back(aPolyVol->GetNode(i)); - meshds->AddPolyhedralVolumeWithID( - aNodes, aPolyVol->GetQuanities(), aPolyVol->GetID()); + const SMDS_PolyhedralVolumeOfNodes* aPolyVol = + dynamic_cast(aVol); + if (!aPolyVol) { + break; + } + std::vector aNodes; + for (int i = 0; i < aPolyVol->NbNodes(); i++) { + aNodes.push_back(aPolyVol->GetNode(i)); + } + meshds->AddPolyhedralVolumeWithID(aNodes, + aPolyVol->GetQuanities(), + aPolyVol->GetID()); } } break; } @@ -457,25 +470,27 @@ void FemMesh::copyMeshData(const FemMesh& mesh) int aId; if (sourceGroupDS->GetType() == SMDSAbs_Node) { - SMESH_Group* targetGroup = - this->myMesh->AddGroup(SMDSAbs_Node, sourceGroupDS->GetStoreName(), aId); - if (targetGroup) { - SMESHDS_Group* targetGroupDS = - dynamic_cast(targetGroup->GetGroupDS()); - if (targetGroupDS) { - SMDS_ElemIteratorPtr aIter = sourceGroupDS->GetElements(); - while (aIter->more()) { - const SMDS_MeshElement* aElem = aIter->next(); - const SMDS_MeshNode* aNode = meshds->FindNode(aElem->GetID()); - if (aNode) - targetGroupDS->SMDSGroup().Add(aNode); + SMESH_Group* targetGroup = + this->myMesh->AddGroup(SMDSAbs_Node, sourceGroupDS->GetStoreName(), aId); + if (targetGroup) { + SMESHDS_Group* targetGroupDS = + dynamic_cast(targetGroup->GetGroupDS()); + if (targetGroupDS) { + SMDS_ElemIteratorPtr aIter = sourceGroupDS->GetElements(); + while (aIter->more()) { + const SMDS_MeshElement* aElem = aIter->next(); + const SMDS_MeshNode* aNode = meshds->FindNode(aElem->GetID()); + if (aNode) { + targetGroupDS->SMDSGroup().Add(aNode); } } } + } } else { - SMESH_Group* targetGroup = this->myMesh->AddGroup( - sourceGroupDS->GetType(), sourceGroupDS->GetStoreName(), aId); + SMESH_Group* targetGroup = this->myMesh->AddGroup(sourceGroupDS->GetType(), + sourceGroupDS->GetStoreName(), + aId); if (targetGroup) { SMESHDS_Group* targetGroupDS = dynamic_cast(targetGroup->GetGroupDS()); @@ -484,8 +499,9 @@ void FemMesh::copyMeshData(const FemMesh& mesh) while (aIter->more()) { const SMDS_MeshElement* aElem = aIter->next(); const SMDS_MeshElement* aElement = meshds->FindElement(aElem->GetID()); - if (aElement) + if (aElement) { targetGroupDS->SMDSGroup().Add(aElement); + } } } } @@ -504,14 +520,15 @@ SMESH_Mesh* FemMesh::getSMesh() return myMesh; } -SMESH_Gen * FemMesh::getGenerator() +SMESH_Gen* FemMesh::getGenerator() { - if (!FemMesh::_mesh_gen) + if (!FemMesh::_mesh_gen) { FemMesh::_mesh_gen = new SMESH_Gen(); + } return FemMesh::_mesh_gen; } -void FemMesh::addHypothesis(const TopoDS_Shape & aSubShape, SMESH_HypothesisPtr hyp) +void FemMesh::addHypothesis(const TopoDS_Shape& aSubShape, SMESH_HypothesisPtr hyp) { myMesh->AddHypothesis(aSubShape, hyp->GetID()); SMESH_HypothesisPtr ptr(hyp); @@ -520,10 +537,11 @@ void FemMesh::addHypothesis(const TopoDS_Shape & aSubShape, SMESH_HypothesisPtr void FemMesh::setStandardHypotheses() { - if (!hypoth.empty()) + if (!hypoth.empty()) { return; + } #if SMESH_VERSION_MAJOR >= 9 - int hyp=0; + int hyp = 0; SMESH_HypothesisPtr len(new StdMeshers_MaxLength(hyp++, getGenerator())); static_cast(len.get())->SetLength(1.0); hypoth.push_back(len); @@ -547,17 +565,17 @@ void FemMesh::setStandardHypotheses() SMESH_HypothesisPtr reg(new StdMeshers_Regular_1D(hyp++, getGenerator())); hypoth.push_back(reg); - //SMESH_HypothesisPtr sel(new StdMeshers_StartEndLength(hyp++, getGenerator())); - //static_cast(sel.get())->SetLength(1.0, true); - //hypoth.push_back(sel); + // SMESH_HypothesisPtr sel(new StdMeshers_StartEndLength(hyp++, getGenerator())); + // static_cast(sel.get())->SetLength(1.0, true); + // hypoth.push_back(sel); - SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++,getGenerator())); + SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++, getGenerator())); hypoth.push_back(qdp); - SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++,getGenerator())); + SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++, getGenerator())); hypoth.push_back(q2d); #else - int hyp=0; + int hyp = 0; SMESH_HypothesisPtr len(new StdMeshers_MaxLength(hyp++, 1, getGenerator())); static_cast(len.get())->SetLength(1.0); hypoth.push_back(len); @@ -581,20 +599,21 @@ void FemMesh::setStandardHypotheses() SMESH_HypothesisPtr reg(new StdMeshers_Regular_1D(hyp++, 1, getGenerator())); hypoth.push_back(reg); - //SMESH_HypothesisPtr sel(new StdMeshers_StartEndLength(hyp++, 1, getGenerator())); - //static_cast(sel.get())->SetLength(1.0, true); - //hypoth.push_back(sel); + // SMESH_HypothesisPtr sel(new StdMeshers_StartEndLength(hyp++, 1, getGenerator())); + // static_cast(sel.get())->SetLength(1.0, true); + // hypoth.push_back(sel); - SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++,1,getGenerator())); + SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++, 1, getGenerator())); hypoth.push_back(qdp); - SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++,1,getGenerator())); + SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++, 1, getGenerator())); hypoth.push_back(q2d); #endif // Apply hypothesis - for (int i = 0; i < hyp; i++) + for (int i = 0; i < hyp; i++) { myMesh->AddHypothesis(myMesh->GetShapeToMesh(), i); + } } void FemMesh::compute() @@ -605,20 +624,20 @@ void FemMesh::compute() std::set FemMesh::getSurfaceNodes(long /*ElemId*/, short /*FaceId*/, float /*Angle*/) const { std::set result; - //const SMESHDS_Mesh* data = myMesh->GetMeshDS(); + // const SMESHDS_Mesh* data = myMesh->GetMeshDS(); - //const SMDS_MeshElement * element = data->FindElement(ElemId); - //int fNbr = element->NbFaces(); - //element-> + // const SMDS_MeshElement * element = data->FindElement(ElemId); + // int fNbr = element->NbFaces(); + // element-> return result; } /*! That function returns map containing volume ID and face ID. */ -std::list > FemMesh::getVolumesByFace(const TopoDS_Face &face) const +std::list> FemMesh::getVolumesByFace(const TopoDS_Face& face) const { - std::list > result; + std::list> result; std::set nodes_on_face = getNodesByFace(face); #if SMESH_VERSION_MAJOR >= 7 @@ -626,7 +645,7 @@ std::list > FemMesh::getVolumesByFace(const TopoDS_Face &fac // to iterate volume faces // In SMESH9 this function has been removed // - std::map< int, std::set > face_nodes; + std::map> face_nodes; // get faces that contribute to 'nodes_on_face' with all of its nodes SMDS_FaceIteratorPtr face_iter = myMesh->GetMeshDS()->facesIterator(); @@ -714,9 +733,9 @@ std::list > FemMesh::getVolumesByFace(const TopoDS_Face &fac /*! That function returns a list of face IDs. */ -std::list FemMesh::getFacesByFace(const TopoDS_Face &face) const +std::list FemMesh::getFacesByFace(const TopoDS_Face& face) const { - //TODO: This function is broken with SMESH7 as it is impossible to iterate volume faces + // TODO: This function is broken with SMESH7 as it is impossible to iterate volume faces std::list result; std::set nodes_on_face = getNodesByFace(face); @@ -747,7 +766,7 @@ std::list FemMesh::getFacesByFace(const TopoDS_Face &face) const return result; } -std::list FemMesh::getEdgesByEdge(const TopoDS_Edge &edge) const +std::list FemMesh::getEdgesByEdge(const TopoDS_Edge& edge) const { std::list result; std::set nodes_on_edge = getNodesByEdge(edge); @@ -782,14 +801,14 @@ std::list FemMesh::getEdgesByEdge(const TopoDS_Edge &edge) const * as per CalculiX definition for tetrahedral elements. See CalculiX * documentation for the details. */ -std::map FemMesh::getccxVolumesByFace(const TopoDS_Face &face) const +std::map FemMesh::getccxVolumesByFace(const TopoDS_Face& face) const { std::map result; std::set nodes_on_face = getNodesByFace(face); - static std::map > elem_order; + static std::map> elem_order; if (elem_order.empty()) { - std::vector c3d4 = boost::assign::list_of(1)(0)(2)(3); + std::vector c3d4 = boost::assign::list_of(1)(0)(2)(3); std::vector c3d10 = boost::assign::list_of(1)(0)(2)(3)(4)(6)(5)(8)(7)(9); elem_order.insert(std::make_pair(c3d4.size(), c3d4)); @@ -802,10 +821,10 @@ std::map FemMesh::getccxVolumesByFace(const TopoDS_Face &face) const while (vol_iter->more()) { const SMDS_MeshVolume* vol = vol_iter->next(); num_of_nodes = vol->NbNodes(); - std::pair > apair; + std::pair> apair; apair.first = vol->GetID(); - std::map >::iterator it = elem_order.find(num_of_nodes); + std::map>::iterator it = elem_order.find(num_of_nodes); if (it != elem_order.end()) { const std::vector& order = it->second; for (int jt : order) { @@ -842,21 +861,21 @@ std::map FemMesh::getccxVolumesByFace(const TopoDS_Face &face) const Face 4: 3-4-1, missing point 2 means it's face P4 */ int face_ccx = 0; switch (missing_node) { - case 1: - face_ccx = 3; - break; - case 2: - face_ccx = 4; - break; - case 3: - face_ccx = 2; - break; - case 4: - face_ccx = 1; - break; - default: - assert(false); // should never happen - break; + case 1: + face_ccx = 3; + break; + case 2: + face_ccx = 4; + break; + case 3: + face_ccx = 2; + break; + case 4: + face_ccx = 1; + break; + default: + assert(false); // should never happen + break; } result[apair.first] = face_ccx; } @@ -865,7 +884,7 @@ std::map FemMesh::getccxVolumesByFace(const TopoDS_Face &face) const return result; } -std::set FemMesh::getNodesBySolid(const TopoDS_Solid &solid) const +std::set FemMesh::getNodesBySolid(const TopoDS_Solid& solid) const { std::set result; @@ -876,8 +895,9 @@ std::set FemMesh::getNodesBySolid(const TopoDS_Solid &solid) const TopAbs_ShapeEnum shapetype = TopAbs_SHAPE; ShapeAnalysis_ShapeTolerance analysis; double limit = analysis.Tolerance(solid, 1, shapetype); - Base::Console().Log( - "The limit if a node is in or out: %.12lf in scientific: %.4e \n", limit, limit); + Base::Console().Log("The limit if a node is in or out: %.12lf in scientific: %.4e \n", + limit, + limit); // get the current transform of the FemMesh const Base::Matrix4D Mtrx(getTransform()); @@ -897,15 +917,16 @@ std::set FemMesh::getNodesBySolid(const TopoDS_Solid &solid) const // Apply the matrix to hold the BoundBox in absolute space. vec = Mtrx * vec; - if (!box.IsOut(gp_Pnt(vec.x,vec.y,vec.z))) { + if (!box.IsOut(gp_Pnt(vec.x, vec.y, vec.z))) { // create a vertex BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(vec.x, vec.y, vec.z)); TopoDS_Shape s = aBuilder.Vertex(); // measure distance BRepExtrema_DistShapeShape measure(solid, s); measure.Perform(); - if (!measure.IsDone() || measure.NbSolution() < 1) + if (!measure.IsDone() || measure.NbSolution() < 1) { continue; + } if (measure.Value() < limit) #pragma omp critical @@ -917,7 +938,7 @@ std::set FemMesh::getNodesBySolid(const TopoDS_Solid &solid) const return result; } -std::set FemMesh::getNodesByFace(const TopoDS_Face &face) const +std::set FemMesh::getNodesByFace(const TopoDS_Face& face) const { std::set result; @@ -925,7 +946,7 @@ std::set FemMesh::getNodesByFace(const TopoDS_Face &face) const BRepBndLib::Add( face, box, - Standard_False);// https://forum.freecad.org/viewtopic.php?f=18&t=21571&start=70#p221591 + Standard_False); // https://forum.freecad.org/viewtopic.php?f=18&t=21571&start=70#p221591 // limit where the mesh node belongs to the face: double limit = BRep_Tool::Tolerance(face); box.Enlarge(limit); @@ -948,15 +969,16 @@ std::set FemMesh::getNodesByFace(const TopoDS_Face &face) const // Apply the matrix to hold the BoundBox in absolute space. vec = Mtrx * vec; - if (!box.IsOut(gp_Pnt(vec.x,vec.y,vec.z))) { + if (!box.IsOut(gp_Pnt(vec.x, vec.y, vec.z))) { // create a vertex BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(vec.x, vec.y, vec.z)); TopoDS_Shape s = aBuilder.Vertex(); // measure distance BRepExtrema_DistShapeShape measure(face, s); measure.Perform(); - if (!measure.IsDone() || measure.NbSolution() < 1) + if (!measure.IsDone() || measure.NbSolution() < 1) { continue; + } if (measure.Value() < limit) #pragma omp critical @@ -969,7 +991,7 @@ std::set FemMesh::getNodesByFace(const TopoDS_Face &face) const return result; } -std::set FemMesh::getNodesByEdge(const TopoDS_Edge &edge) const +std::set FemMesh::getNodesByEdge(const TopoDS_Edge& edge) const { std::set result; @@ -997,15 +1019,16 @@ std::set FemMesh::getNodesByEdge(const TopoDS_Edge &edge) const // Apply the matrix to hold the BoundBox in absolute space. vec = Mtrx * vec; - if (!box.IsOut(gp_Pnt(vec.x,vec.y,vec.z))) { + if (!box.IsOut(gp_Pnt(vec.x, vec.y, vec.z))) { // create a vertex BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(vec.x, vec.y, vec.z)); TopoDS_Shape s = aBuilder.Vertex(); // measure distance BRepExtrema_DistShapeShape measure(edge, s); measure.Perform(); - if (!measure.IsDone() || measure.NbSolution() < 1) + if (!measure.IsDone() || measure.NbSolution() < 1) { continue; + } if (measure.Value() < limit) #pragma omp critical @@ -1018,12 +1041,12 @@ std::set FemMesh::getNodesByEdge(const TopoDS_Edge &edge) const return result; } -std::set FemMesh::getNodesByVertex(const TopoDS_Vertex &vertex) const +std::set FemMesh::getNodesByVertex(const TopoDS_Vertex& vertex) const { std::set result; double limit = BRep_Tool::Tolerance(vertex); - limit *= limit; // use square to improve speed + limit *= limit; // use square to improve speed gp_Pnt pnt = BRep_Tool::Pnt(vertex); Base::Vector3d node(pnt.X(), pnt.Y(), pnt.Z()); @@ -1059,8 +1082,9 @@ std::list FemMesh::getElementNodes(int id) const std::list result; const SMDS_MeshElement* elem = myMesh->GetMeshDS()->FindElement(id); if (elem) { - for (int i = 0; i < elem->NbNodes(); i++) + for (int i = 0; i < elem->NbNodes(); i++) { result.push_back(elem->GetNode(i)->GetID()); + } } return result; @@ -1102,17 +1126,21 @@ std::set FemMesh::getEdgesOnly() const // if aEdgeNodes is not a subset of any aFaceNodes --> aEdge does not belong to any Face std::vector inodes; - std::set_intersection(aFaceNodes.begin(), aFaceNodes.end(), - aEdgeNodes.begin(), aEdgeNodes.end(), + std::set_intersection(aFaceNodes.begin(), + aFaceNodes.end(), + aEdgeNodes.begin(), + aEdgeNodes.end(), std::back_inserter(inodes)); - std::set intersection_nodes(inodes.begin(), inodes.end()); // convert vector to set + std::set intersection_nodes(inodes.begin(), + inodes.end()); // convert vector to set if (aEdgeNodes == intersection_nodes) { edgeBelongsToAFace = true; break; } } - if (!edgeBelongsToAFace) + if (!edgeBelongsToAFace) { resultIDs.insert(aEdge->GetID()); + } } return resultIDs; @@ -1140,7 +1168,8 @@ std::set FemMesh::getFacesOnly() const // if not in volume faces // add it to the faces only // - // but the volume faces do not seem to know their global mesh ID, I could not find any method in SMESH + // but the volume faces do not seem to know their global mesh ID, I could not find any method in + // SMESH std::set resultIDs; @@ -1159,29 +1188,37 @@ std::set FemMesh::getFacesOnly() const std::list vnodes = getElementNodes(aVol->GetID()); std::set aVolNodes(vnodes.begin(), vnodes.end()); // convert list to set - // if aFaceNodes is not a subset of any aVolNodes --> aFace does not belong to any Volume + // if aFaceNodes is not a subset of any aVolNodes --> aFace does not belong to any + // Volume std::vector inodes; - std::set_intersection(aVolNodes.begin(), aVolNodes.end(), - aFaceNodes.begin(), aFaceNodes.end(), + std::set_intersection(aVolNodes.begin(), + aVolNodes.end(), + aFaceNodes.begin(), + aFaceNodes.end(), std::back_inserter(inodes)); - std::set intersection_nodes(inodes.begin(), inodes.end()); // convert vector to set + std::set intersection_nodes(inodes.begin(), + inodes.end()); // convert vector to set if (aFaceNodes == intersection_nodes) { faceBelongsToAVolume = true; break; } } - if (!faceBelongsToAVolume) + if (!faceBelongsToAVolume) { resultIDs.insert(aFace->GetID()); + } } return resultIDs; } -namespace { -class NastranElement { +namespace +{ +class NastranElement +{ public: virtual ~NastranElement() = default; - bool isValid() const { + bool isValid() const + { return element_id >= 0; } virtual void read(const std::string& str1, const std::string& str2) = 0; @@ -1194,8 +1231,10 @@ protected: using NastranElementPtr = std::shared_ptr; -class GRIDElement : public NastranElement { - void addToMesh(SMESHDS_Mesh* meshds) override { +class GRIDElement: public NastranElement +{ + void addToMesh(SMESHDS_Mesh* meshds) override + { meshds->AddNodeWithID(node.x, node.y, node.z, element_id); } @@ -1203,14 +1242,17 @@ protected: Base::Vector3d node; }; -class GRIDFreeFieldElement : public GRIDElement { - void read(const std::string& str, const std::string&) override { +class GRIDFreeFieldElement: public GRIDElement +{ + void read(const std::string& str, const std::string&) override + { char_separator sep(","); - tokenizer > tokens(str, sep); + tokenizer> tokens(str, sep); std::vector token_results; - token_results.assign(tokens.begin(),tokens.end()); - if (token_results.size() < 6) - return;//Line does not include Nodal coordinates + token_results.assign(tokens.begin(), tokens.end()); + if (token_results.size() < 6) { + return; // Line does not include Nodal coordinates + } element_id = atoi(token_results[1].c_str()); node.x = atof(token_results[3].c_str()); @@ -1219,32 +1261,33 @@ class GRIDFreeFieldElement : public GRIDElement { } }; -class GRIDLongFieldElement : public GRIDElement { - void read(const std::string& str1, const std::string& str2) override { - element_id = atoi(str1.substr(8,24).c_str()); - node.x = atof(str1.substr(40,56).c_str()); - node.y = atof(str1.substr(56,72).c_str()); - node.z = atof(str2.substr(8,24).c_str()); +class GRIDLongFieldElement: public GRIDElement +{ + void read(const std::string& str1, const std::string& str2) override + { + element_id = atoi(str1.substr(8, 24).c_str()); + node.x = atof(str1.substr(40, 56).c_str()); + node.y = atof(str1.substr(56, 72).c_str()); + node.z = atof(str2.substr(8, 24).c_str()); } }; -class GRIDSmallFieldElement : public GRIDElement { - void read(const std::string&, const std::string&) override { - } +class GRIDSmallFieldElement: public GRIDElement +{ + void read(const std::string&, const std::string&) override + {} }; -class CTRIA3Element : public NastranElement { +class CTRIA3Element: public NastranElement +{ public: - void addToMesh(SMESHDS_Mesh* meshds) override { + void addToMesh(SMESHDS_Mesh* meshds) override + { const SMDS_MeshNode* n0 = meshds->FindNode(elements[0]); const SMDS_MeshNode* n1 = meshds->FindNode(elements[1]); const SMDS_MeshNode* n2 = meshds->FindNode(elements[2]); if (n0 && n1 && n2) { - meshds->AddFaceWithID - ( - n0, n1, n2, - element_id - ); + meshds->AddFaceWithID(n0, n1, n2, element_id); } else { Base::Console().Warning("NASTRAN: Failed to add face %d from nodes: (%d, %d, %d,)\n", @@ -1256,15 +1299,18 @@ public: } }; -class CTRIA3FreeFieldElement : public CTRIA3Element { +class CTRIA3FreeFieldElement: public CTRIA3Element +{ public: - void read(const std::string& str, const std::string&) override { + void read(const std::string& str, const std::string&) override + { char_separator sep(","); - tokenizer > tokens(str, sep); + tokenizer> tokens(str, sep); std::vector token_results; - token_results.assign(tokens.begin(),tokens.end()); - if (token_results.size() < 6) - return;//Line does not include enough nodal IDs + token_results.assign(tokens.begin(), tokens.end()); + if (token_results.size() < 6) { + return; // Line does not include enough nodal IDs + } element_id = atoi(token_results[1].c_str()); elements.push_back(atoi(token_results[3].c_str())); @@ -1273,25 +1319,30 @@ public: } }; -class CTRIA3LongFieldElement : public CTRIA3Element { +class CTRIA3LongFieldElement: public CTRIA3Element +{ public: - void read(const std::string& str, const std::string&) override { - element_id = atoi(str.substr(8,16).c_str()); - elements.push_back(atoi(str.substr(24,32).c_str())); - elements.push_back(atoi(str.substr(32,40).c_str())); - elements.push_back(atoi(str.substr(40,48).c_str())); + void read(const std::string& str, const std::string&) override + { + element_id = atoi(str.substr(8, 16).c_str()); + elements.push_back(atoi(str.substr(24, 32).c_str())); + elements.push_back(atoi(str.substr(32, 40).c_str())); + elements.push_back(atoi(str.substr(40, 48).c_str())); } }; -class CTRIA3SmallFieldElement : public CTRIA3Element { +class CTRIA3SmallFieldElement: public CTRIA3Element +{ public: - void read(const std::string&, const std::string&) override { - } + void read(const std::string&, const std::string&) override + {} }; -class CTETRAElement : public NastranElement { +class CTETRAElement: public NastranElement +{ public: - void addToMesh(SMESHDS_Mesh* meshds) override { + void addToMesh(SMESHDS_Mesh* meshds) override + { const SMDS_MeshNode* n0 = meshds->FindNode(elements[1]); const SMDS_MeshNode* n1 = meshds->FindNode(elements[0]); const SMDS_MeshNode* n2 = meshds->FindNode(elements[2]); @@ -1303,14 +1354,11 @@ public: const SMDS_MeshNode* n8 = meshds->FindNode(elements[7]); const SMDS_MeshNode* n9 = meshds->FindNode(elements[9]); if (n0 && n1 && n2 && n3 && n4 && n5 && n6 && n7 && n8 && n9) { - meshds->AddVolumeWithID - ( - n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, - element_id - ); + meshds->AddVolumeWithID(n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, element_id); } else { - Base::Console().Warning("NASTRAN: Failed to add volume %d from nodes: (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d)\n", + Base::Console().Warning("NASTRAN: Failed to add volume %d from nodes: (%d, %d, %d, %d, " + "%d, %d, %d, %d, %d, %d)\n", element_id, elements[1], elements[0], @@ -1326,15 +1374,18 @@ public: } }; -class CTETRAFreeFieldElement : public CTETRAElement { +class CTETRAFreeFieldElement: public CTETRAElement +{ public: - void read(const std::string& str, const std::string&) override { + void read(const std::string& str, const std::string&) override + { char_separator sep(","); - tokenizer > tokens(str, sep); + tokenizer> tokens(str, sep); std::vector token_results; - token_results.assign(tokens.begin(),tokens.end()); - if (token_results.size() < 14) - return;//Line does not include enough nodal IDs + token_results.assign(tokens.begin(), tokens.end()); + if (token_results.size() < 14) { + return; // Line does not include enough nodal IDs + } element_id = atoi(token_results[1].c_str()); elements.push_back(atoi(token_results[3].c_str())); @@ -1350,45 +1401,53 @@ public: } }; -class CTETRALongFieldElement : public CTETRAElement { +class CTETRALongFieldElement: public CTETRAElement +{ public: - void read(const std::string& str1, const std::string& str2) override { - int id = atoi(str1.substr(8,16).c_str()); + void read(const std::string& str1, const std::string& str2) override + { + int id = atoi(str1.substr(8, 16).c_str()); int offset = 0; - if (id < 1000000) + if (id < 1000000) { offset = 0; - else if (id < 10000000) + } + else if (id < 10000000) { offset = 1; - else if (id < 100000000) + } + else if (id < 100000000) { offset = 2; + } element_id = id; - elements.push_back(atoi(str1.substr(24,32).c_str())); - elements.push_back(atoi(str1.substr(32,40).c_str())); - elements.push_back(atoi(str1.substr(40,48).c_str())); - elements.push_back(atoi(str1.substr(48,56).c_str())); - elements.push_back(atoi(str1.substr(56,64).c_str())); - elements.push_back(atoi(str1.substr(64,72).c_str())); - elements.push_back(atoi(str2.substr(8+offset,16+offset).c_str())); - elements.push_back(atoi(str2.substr(16+offset,24+offset).c_str())); - elements.push_back(atoi(str2.substr(24+offset,32+offset).c_str())); - elements.push_back(atoi(str2.substr(32+offset,40+offset).c_str())); + elements.push_back(atoi(str1.substr(24, 32).c_str())); + elements.push_back(atoi(str1.substr(32, 40).c_str())); + elements.push_back(atoi(str1.substr(40, 48).c_str())); + elements.push_back(atoi(str1.substr(48, 56).c_str())); + elements.push_back(atoi(str1.substr(56, 64).c_str())); + elements.push_back(atoi(str1.substr(64, 72).c_str())); + elements.push_back(atoi(str2.substr(8 + offset, 16 + offset).c_str())); + elements.push_back(atoi(str2.substr(16 + offset, 24 + offset).c_str())); + elements.push_back(atoi(str2.substr(24 + offset, 32 + offset).c_str())); + elements.push_back(atoi(str2.substr(32 + offset, 40 + offset).c_str())); } }; -class CTETRASmallFieldElement : public CTETRAElement { +class CTETRASmallFieldElement: public CTETRAElement +{ public: - void read(const std::string&, const std::string&) override { - } + void read(const std::string&, const std::string&) override + {} }; // NASTRAN-95 -class GRIDNastran95Element : public GRIDElement { - void read(const std::string& str, const std::string&) override { +class GRIDNastran95Element: public GRIDElement +{ + void read(const std::string& str, const std::string&) override + { element_id = atoi(str.substr(8, 16).c_str()); node.x = atof(str.substr(24, 32).c_str()); node.y = atof(str.substr(32, 40).c_str()); @@ -1396,175 +1455,167 @@ class GRIDNastran95Element : public GRIDElement { } }; -class CBARElement : public NastranElement { - void read(const std::string& str, const std::string&) override { - element_id = atoi(str.substr(8,16).c_str()); - elements.push_back(atoi(str.substr(24,32).c_str())); - elements.push_back(atoi(str.substr(32,40).c_str())); +class CBARElement: public NastranElement +{ + void read(const std::string& str, const std::string&) override + { + element_id = atoi(str.substr(8, 16).c_str()); + elements.push_back(atoi(str.substr(24, 32).c_str())); + elements.push_back(atoi(str.substr(32, 40).c_str())); } - void addToMesh(SMESHDS_Mesh* meshds) override { - meshds->AddEdgeWithID( - elements[0], - elements[1], - element_id - ); + void addToMesh(SMESHDS_Mesh* meshds) override + { + meshds->AddEdgeWithID(elements[0], elements[1], element_id); } }; -class CTRMEMElement : public NastranElement { - void read(const std::string& str, const std::string&) override { - element_id = atoi(str.substr(8,16).c_str()); - elements.push_back(atoi(str.substr(24,32).c_str())); - elements.push_back(atoi(str.substr(32,40).c_str())); - elements.push_back(atoi(str.substr(40,48).c_str())); - } - void addToMesh(SMESHDS_Mesh* meshds) override { - meshds->AddFaceWithID( - elements[0], - elements[1], - elements[2], - element_id - ); - } -}; - -class CTRIA1Element : public NastranElement { - void read(const std::string& str, const std::string&) override { - element_id = atoi(str.substr(8,16).c_str()); +class CTRMEMElement: public NastranElement +{ + void read(const std::string& str, const std::string&) override + { + element_id = atoi(str.substr(8, 16).c_str()); elements.push_back(atoi(str.substr(24, 32).c_str())); elements.push_back(atoi(str.substr(32, 40).c_str())); elements.push_back(atoi(str.substr(40, 48).c_str())); } - void addToMesh(SMESHDS_Mesh* meshds) override { - meshds->AddFaceWithID( - elements[0], - elements[1], - elements[2], - element_id - ); + void addToMesh(SMESHDS_Mesh* meshds) override + { + meshds->AddFaceWithID(elements[0], elements[1], elements[2], element_id); } }; -class CQUAD1Element : public NastranElement { - void read(const std::string& str, const std::string&) override { - element_id = atoi(str.substr(8,16).c_str()); +class CTRIA1Element: public NastranElement +{ + void read(const std::string& str, const std::string&) override + { + element_id = atoi(str.substr(8, 16).c_str()); + elements.push_back(atoi(str.substr(24, 32).c_str())); + elements.push_back(atoi(str.substr(32, 40).c_str())); + elements.push_back(atoi(str.substr(40, 48).c_str())); + } + void addToMesh(SMESHDS_Mesh* meshds) override + { + meshds->AddFaceWithID(elements[0], elements[1], elements[2], element_id); + } +}; + +class CQUAD1Element: public NastranElement +{ + void read(const std::string& str, const std::string&) override + { + element_id = atoi(str.substr(8, 16).c_str()); elements.push_back(atoi(str.substr(24, 32).c_str())); elements.push_back(atoi(str.substr(32, 40).c_str())); elements.push_back(atoi(str.substr(40, 48).c_str())); elements.push_back(atoi(str.substr(48, 56).c_str())); } - void addToMesh(SMESHDS_Mesh* meshds) override { - meshds->AddFaceWithID( - elements[0], - elements[1], - elements[2], - elements[3], - element_id - ); + void addToMesh(SMESHDS_Mesh* meshds) override + { + meshds->AddFaceWithID(elements[0], elements[1], elements[2], elements[3], element_id); } }; -class CTETRANastran95Element : public NastranElement { - void read(const std::string& str, const std::string&) override { - element_id = atoi(str.substr(8,16).c_str()); +class CTETRANastran95Element: public NastranElement +{ + void read(const std::string& str, const std::string&) override + { + element_id = atoi(str.substr(8, 16).c_str()); elements.push_back(atoi(str.substr(24, 32).c_str())); elements.push_back(atoi(str.substr(32, 40).c_str())); elements.push_back(atoi(str.substr(40, 48).c_str())); elements.push_back(atoi(str.substr(48, 56).c_str())); } - void addToMesh(SMESHDS_Mesh* meshds) override { - meshds->AddFaceWithID( - elements[0], - elements[1], - elements[2], - elements[3], - element_id - ); + void addToMesh(SMESHDS_Mesh* meshds) override + { + meshds->AddFaceWithID(elements[0], elements[1], elements[2], elements[3], element_id); } }; -class CWEDGEElement : public NastranElement { - void read(const std::string& str, const std::string&) override { - element_id = atoi(str.substr(8,16).c_str()); - elements.push_back(atoi(str.substr(24,32).c_str())); - elements.push_back(atoi(str.substr(32,40).c_str())); - elements.push_back(atoi(str.substr(40,48).c_str())); - elements.push_back(atoi(str.substr(48,56).c_str())); - elements.push_back(atoi(str.substr(56,64).c_str())); - elements.push_back(atoi(str.substr(64,72).c_str())); +class CWEDGEElement: public NastranElement +{ + void read(const std::string& str, const std::string&) override + { + element_id = atoi(str.substr(8, 16).c_str()); + elements.push_back(atoi(str.substr(24, 32).c_str())); + elements.push_back(atoi(str.substr(32, 40).c_str())); + elements.push_back(atoi(str.substr(40, 48).c_str())); + elements.push_back(atoi(str.substr(48, 56).c_str())); + elements.push_back(atoi(str.substr(56, 64).c_str())); + elements.push_back(atoi(str.substr(64, 72).c_str())); } - void addToMesh(SMESHDS_Mesh* meshds) override { - meshds->AddVolumeWithID( - elements[0], - elements[1], - elements[2], - elements[3], - elements[4], - elements[5], - element_id - ); + void addToMesh(SMESHDS_Mesh* meshds) override + { + meshds->AddVolumeWithID(elements[0], + elements[1], + elements[2], + elements[3], + elements[4], + elements[5], + element_id); } }; -class CHEXA1Element : public NastranElement { - void read(const std::string& str1, const std::string& str2) override { - element_id = atoi(str1.substr(8,16).c_str()); - elements.push_back(atoi(str1.substr(24,32).c_str())); - elements.push_back(atoi(str1.substr(32,40).c_str())); - elements.push_back(atoi(str1.substr(40,48).c_str())); - elements.push_back(atoi(str1.substr(48,56).c_str())); - elements.push_back(atoi(str1.substr(56,64).c_str())); - elements.push_back(atoi(str1.substr(64,72).c_str())); +class CHEXA1Element: public NastranElement +{ + void read(const std::string& str1, const std::string& str2) override + { + element_id = atoi(str1.substr(8, 16).c_str()); + elements.push_back(atoi(str1.substr(24, 32).c_str())); + elements.push_back(atoi(str1.substr(32, 40).c_str())); + elements.push_back(atoi(str1.substr(40, 48).c_str())); + elements.push_back(atoi(str1.substr(48, 56).c_str())); + elements.push_back(atoi(str1.substr(56, 64).c_str())); + elements.push_back(atoi(str1.substr(64, 72).c_str())); - elements.push_back(atoi(str2.substr(8,16).c_str())); - elements.push_back(atoi(str2.substr(16,24).c_str())); + elements.push_back(atoi(str2.substr(8, 16).c_str())); + elements.push_back(atoi(str2.substr(16, 24).c_str())); } - void addToMesh(SMESHDS_Mesh* meshds) override { - meshds->AddVolumeWithID( - elements[0], - elements[1], - elements[2], - elements[3], - elements[4], - elements[5], - elements[6], - elements[7], - element_id - ); + void addToMesh(SMESHDS_Mesh* meshds) override + { + meshds->AddVolumeWithID(elements[0], + elements[1], + elements[2], + elements[3], + elements[4], + elements[5], + elements[6], + elements[7], + element_id); } }; -class CHEXA2Element : public NastranElement { - void read(const std::string& str1, const std::string& str2) override { - element_id = atoi(str1.substr(8,16).c_str()); - elements.push_back(atoi(str1.substr(24,32).c_str())); - elements.push_back(atoi(str1.substr(32,40).c_str())); - elements.push_back(atoi(str1.substr(40,48).c_str())); - elements.push_back(atoi(str1.substr(48,56).c_str())); - elements.push_back(atoi(str1.substr(56,64).c_str())); - elements.push_back(atoi(str1.substr(64,72).c_str())); +class CHEXA2Element: public NastranElement +{ + void read(const std::string& str1, const std::string& str2) override + { + element_id = atoi(str1.substr(8, 16).c_str()); + elements.push_back(atoi(str1.substr(24, 32).c_str())); + elements.push_back(atoi(str1.substr(32, 40).c_str())); + elements.push_back(atoi(str1.substr(40, 48).c_str())); + elements.push_back(atoi(str1.substr(48, 56).c_str())); + elements.push_back(atoi(str1.substr(56, 64).c_str())); + elements.push_back(atoi(str1.substr(64, 72).c_str())); - elements.push_back(atoi(str2.substr(8,16).c_str())); - elements.push_back(atoi(str2.substr(16,24).c_str())); + elements.push_back(atoi(str2.substr(8, 16).c_str())); + elements.push_back(atoi(str2.substr(16, 24).c_str())); } - void addToMesh(SMESHDS_Mesh* meshds) override { - meshds->AddVolumeWithID( - elements[0], - elements[1], - elements[2], - elements[3], - elements[4], - elements[5], - elements[6], - elements[7], - element_id - ); + void addToMesh(SMESHDS_Mesh* meshds) override + { + meshds->AddVolumeWithID(elements[0], + elements[1], + elements[2], + elements[3], + elements[4], + elements[5], + elements[6], + elements[7], + element_id); } }; -} +} // namespace -void FemMesh::readNastran(const std::string &Filename) +void FemMesh::readNastran(const std::string& Filename) { Base::TimeInfo Start; Base::Console().Log("Start: FemMesh::readNastran() =================================\n"); @@ -1575,35 +1626,37 @@ void FemMesh::readNastran(const std::string &Filename) Base::ifstream inputfile; inputfile.open(fi); inputfile.seekg(std::ifstream::beg); - std::string line1,line2; + std::string line1, line2; std::vector mesh_elements; - enum Format { + enum Format + { FreeField, SmallField, LongField }; Format nastranFormat = Format::LongField; - do - { - std::getline(inputfile,line1); - if (line1.empty()) + do { + std::getline(inputfile, line1); + if (line1.empty()) { continue; - if (line1.find(',') != std::string::npos) + } + if (line1.find(',') != std::string::npos) { nastranFormat = Format::FreeField; + } NastranElementPtr ptr; - if (line1.find("GRID*") != std::string::npos) { //We found a Grid line - //Now lets extract the GRID Points = Nodes - //As each GRID Line consists of two subsequent lines we have to - //take care of that as well + if (line1.find("GRID*") != std::string::npos) { // We found a Grid line + // Now lets extract the GRID Points = Nodes + // As each GRID Line consists of two subsequent lines we have to + // take care of that as well if (nastranFormat == Format::LongField) { - std::getline(inputfile,line2); + std::getline(inputfile, line2); ptr = std::make_shared(); ptr->read(line1, line2); } } - else if (line1.find("GRID") != std::string::npos) { //We found a Grid line + else if (line1.find("GRID") != std::string::npos) { // We found a Grid line if (nastranFormat == Format::FreeField) { ptr = std::make_shared(); ptr->read(line1, ""); @@ -1620,11 +1673,11 @@ void FemMesh::readNastran(const std::string &Filename) } } else if (line1.find("CTETRA") != std::string::npos) { - //Lets extract the elements - //As each Element Line consists of two subsequent lines as well - //we have to take care of that - //At a first step we only extract Quadratic Tetrahedral Elements - std::getline(inputfile,line2); + // Lets extract the elements + // As each Element Line consists of two subsequent lines as well + // we have to take care of that + // At a first step we only extract Quadratic Tetrahedral Elements + std::getline(inputfile, line2); if (nastranFormat == Format::FreeField) { ptr = std::make_shared(); ptr->read(line1.append(line2), ""); @@ -1638,13 +1691,13 @@ void FemMesh::readNastran(const std::string &Filename) if (ptr && ptr->isValid()) { mesh_elements.push_back(ptr); } - } - while (inputfile.good()); + } while (inputfile.good()); inputfile.close(); - Base::Console().Log(" %f: File read, start building mesh\n",Base::TimeInfo::diffTimeF(Start,Base::TimeInfo())); + Base::Console().Log(" %f: File read, start building mesh\n", + Base::TimeInfo::diffTimeF(Start, Base::TimeInfo())); - //Now fill the SMESH datastructure + // Now fill the SMESH datastructure SMESHDS_Mesh* meshds = this->myMesh->GetMeshDS(); meshds->ClearMesh(); @@ -1652,11 +1705,10 @@ void FemMesh::readNastran(const std::string &Filename) it->addToMesh(meshds); } - Base::Console().Log(" %f: Done \n",Base::TimeInfo::diffTimeF(Start,Base::TimeInfo())); - + Base::Console().Log(" %f: Done \n", Base::TimeInfo::diffTimeF(Start, Base::TimeInfo())); } -void FemMesh::readNastran95(const std::string &Filename) +void FemMesh::readNastran95(const std::string& Filename) { Base::TimeInfo Start; Base::Console().Log("Start: FemMesh::readNastran95() =================================\n"); @@ -1667,101 +1719,93 @@ void FemMesh::readNastran95(const std::string &Filename) Base::ifstream inputfile; inputfile.open(fi); inputfile.seekg(std::ifstream::beg); - std::string line1,line2,tcard; + std::string line1, line2, tcard; std::vector mesh_nodes; std::vector mesh_elements; - do - { + do { NastranElementPtr node; NastranElementPtr elem; std::getline(inputfile, line1); - //cout << line1 << endl; - if (line1.empty()) + // cout << line1 << endl; + if (line1.empty()) { continue; + } tcard = line1.substr(0, 8).c_str(); - //boost::algorithm::trim(tcard); - if (line1.find("GRID*") != std::string::npos ) //We found a Grid line + // boost::algorithm::trim(tcard); + if (line1.find("GRID*") != std::string::npos) // We found a Grid line { - //Now lets extract the GRID Points = Nodes - //As each GRID Line consists of two subsequent lines we have to - //take care of that as well - std::getline(inputfile,line2); + // Now lets extract the GRID Points = Nodes + // As each GRID Line consists of two subsequent lines we have to + // take care of that as well + std::getline(inputfile, line2); node = std::make_shared(); node->read(line1, line2); } - else if (line1.find("GRID") != std::string::npos) //We found a Grid line + else if (line1.find("GRID") != std::string::npos) // We found a Grid line { - //Base::Console().Log("Found a GRID\n"); - //D06.inp - //GRID 109 .9 .7 - //Now lets extract the GRID Points = Nodes - //Get the Nodal ID + // Base::Console().Log("Found a GRID\n"); + // D06.inp + // GRID 109 .9 .7 + // Now lets extract the GRID Points = Nodes + // Get the Nodal ID node = std::make_shared(); node->read(line1, ""); } - //1D - else if (line1.substr(0, 6) == "CBAR") - { + // 1D + else if (line1.substr(0, 6) == "CBAR") { elem = std::make_shared(); elem->read(line1, ""); } - //2d - else if (line1.substr(0, 6) == "CTRMEM") - { - //D06 - //CTRMEM 322 1 179 180 185 + // 2d + else if (line1.substr(0, 6) == "CTRMEM") { + // D06 + // CTRMEM 322 1 179 180 185 elem = std::make_shared(); elem->read(line1, ""); } - else if (line1.substr(0, 6) == "CTRIA1") - { - //D06 - //CTRMEM 322 1 179 180 185 + else if (line1.substr(0, 6) == "CTRIA1") { + // D06 + // CTRMEM 322 1 179 180 185 elem = std::make_shared(); elem->read(line1, ""); } - else if (line1.substr(0, 6) == "CQUAD1") - { - //D06 - //CTRMEM 322 1 179 180 185 + else if (line1.substr(0, 6) == "CQUAD1") { + // D06 + // CTRMEM 322 1 179 180 185 elem = std::make_shared(); elem->read(line1, ""); } - //3d element - else if (line1.find("CTETRA")!= std::string::npos) - { - //d011121a.inp - //CTETRA 3 200 104 114 3 103 + // 3d element + else if (line1.find("CTETRA") != std::string::npos) { + // d011121a.inp + // CTETRA 3 200 104 114 3 103 elem = std::make_shared(); elem->read(line1, ""); } - else if (line1.find("CWEDGE")!= std::string::npos) - { - //d011121a.inp - //CWEDGE 11 200 6 17 16 106 117 116 + else if (line1.find("CWEDGE") != std::string::npos) { + // d011121a.inp + // CWEDGE 11 200 6 17 16 106 117 116 elem = std::make_shared(); elem->read(line1, ""); } - else if (line1.find("CHEXA1")!= std::string::npos) - { - //d011121a.inp - //CHEXA1 1 200 1 2 13 12 101 102 +SOL1 + else if (line1.find("CHEXA1") != std::string::npos) { + // d011121a.inp + // CHEXA1 1 200 1 2 13 12 101 102 +SOL1 //+SOL1 113 112 - std::getline(inputfile,line2); + std::getline(inputfile, line2); elem = std::make_shared(); elem->read(line1, line2); } - else if (line1.find("CHEXA2")!= std::string::npos) - { - //d011121a.inp - //CHEXA1 1 200 1 2 13 12 101 102 +SOL1 + else if (line1.find("CHEXA2") != std::string::npos) { + // d011121a.inp + // CHEXA1 1 200 1 2 13 12 101 102 +SOL1 //+SOL1 113 112 - std::getline(inputfile,line2); + std::getline(inputfile, line2); elem = std::make_shared(); elem->read(line1, line2); } @@ -1773,13 +1817,13 @@ void FemMesh::readNastran95(const std::string &Filename) if (elem && elem->isValid()) { mesh_elements.push_back(elem); } - } - while (inputfile.good()); + } while (inputfile.good()); inputfile.close(); - Base::Console().Log(" %f: File read, start building mesh\n",Base::TimeInfo::diffTimeF(Start,Base::TimeInfo())); + Base::Console().Log(" %f: File read, start building mesh\n", + Base::TimeInfo::diffTimeF(Start, Base::TimeInfo())); - //Now fill the SMESH datastructure + // Now fill the SMESH datastructure SMESHDS_Mesh* meshds = this->myMesh->GetMeshDS(); meshds->ClearMesh(); @@ -1791,10 +1835,10 @@ void FemMesh::readNastran95(const std::string &Filename) it->addToMesh(meshds); } - Base::Console().Log(" %f: Done \n",Base::TimeInfo::diffTimeF(Start,Base::TimeInfo())); + Base::Console().Log(" %f: Done \n", Base::TimeInfo::diffTimeF(Start, Base::TimeInfo())); } -void FemMesh::readAbaqus(const std::string &FileName) +void FemMesh::readAbaqus(const std::string& FileName) { Base::TimeInfo Start; Base::Console().Log("Start: FemMesh::readAbaqus() =================================\n"); @@ -1802,12 +1846,14 @@ void FemMesh::readAbaqus(const std::string &FileName) /* Python command to read Abaqus inp mesh file from test suite: from feminout.importInpMesh import read as read_inp - femmesh = read_inp(FreeCAD.ConfigGet("AppHomePath") + 'Mod/Fem/femtest/data/mesh/tetra10_mesh.inp') + femmesh = read_inp(FreeCAD.ConfigGet("AppHomePath") + + 'Mod/Fem/femtest/data/mesh/tetra10_mesh.inp') */ PyObject* module = PyImport_ImportModule("feminout.importInpMesh"); - if (!module) + if (!module) { return; + } try { Py::Module abaqusmod(module, true); Py::Callable method(abaqusmod.getAttr("read")); @@ -1817,8 +1863,9 @@ void FemMesh::readAbaqus(const std::string &FileName) if (PyObject_TypeCheck(mesh.ptr(), &FemMeshPy::Type)) { FemMeshPy* fempy = static_cast(mesh.ptr()); FemMesh* fem = fempy->getFemMeshPtr(); - *this = *fem; // the deep copy should be avoided, a pointer swap method could be implemented - // see https://forum.freecad.org/viewtopic.php?f=10&t=31999&start=10#p274241 + *this = *fem; // the deep copy should be avoided, a pointer swap method could be + // implemented see + // https://forum.freecad.org/viewtopic.php?f=10&t=31999&start=10#p274241 } else { throw Base::FileException("Problems reading file"); @@ -1827,10 +1874,10 @@ void FemMesh::readAbaqus(const std::string &FileName) catch (Py::Exception& e) { e.clear(); } - Base::Console().Log(" %f: Done \n",Base::TimeInfo::diffTimeF(Start,Base::TimeInfo())); + Base::Console().Log(" %f: Done \n", Base::TimeInfo::diffTimeF(Start, Base::TimeInfo())); } -void FemMesh::readZ88(const std::string &FileName) +void FemMesh::readZ88(const std::string& FileName) { Base::TimeInfo Start; Base::Console().Log("Start: FemMesh::readZ88() =================================\n"); @@ -1838,12 +1885,14 @@ void FemMesh::readZ88(const std::string &FileName) /* Python command to read Z88 mesh file from test suite: from feminout.importZ88Mesh import read as read_z88 - femmesh = read_z88(FreeCAD.ConfigGet("AppHomePath") + 'Mod/Fem/femtest/data/mesh/tetra10_mesh.z88') + femmesh = read_z88(FreeCAD.ConfigGet("AppHomePath") + + 'Mod/Fem/femtest/data/mesh/tetra10_mesh.z88') */ PyObject* module = PyImport_ImportModule("feminout.importZ88Mesh"); - if (!module) + if (!module) { return; + } try { Py::Module z88mod(module, true); Py::Callable method(z88mod.getAttr("read")); @@ -1853,8 +1902,9 @@ void FemMesh::readZ88(const std::string &FileName) if (PyObject_TypeCheck(mesh.ptr(), &FemMeshPy::Type)) { FemMeshPy* fempy = static_cast(mesh.ptr()); FemMesh* fem = fempy->getFemMeshPtr(); - *this = *fem; // the deep copy should be avoided, a pointer swap method could be implemented - // see https://forum.freecad.org/viewtopic.php?f=10&t=31999&start=10#p274241 + *this = *fem; // the deep copy should be avoided, a pointer swap method could be + // implemented see + // https://forum.freecad.org/viewtopic.php?f=10&t=31999&start=10#p274241 } else { throw Base::FileException("Problems reading file"); @@ -1863,46 +1913,48 @@ void FemMesh::readZ88(const std::string &FileName) catch (Py::Exception& e) { e.clear(); } - Base::Console().Log(" %f: Done \n",Base::TimeInfo::diffTimeF(Start,Base::TimeInfo())); + Base::Console().Log(" %f: Done \n", Base::TimeInfo::diffTimeF(Start, Base::TimeInfo())); } -void FemMesh::read(const char *FileName) +void FemMesh::read(const char* FileName) { Base::FileInfo File(FileName); _Mtrx = Base::Matrix4D(); // checking on the file - if (!File.isReadable()) + if (!File.isReadable()) { throw Base::FileException("File to load not existing or not readable", File); + } - if (File.hasExtension("unv") ) { + if (File.hasExtension("unv")) { // read UNV file myMesh->UNVToMesh(File.filePath().c_str()); } - else if (File.hasExtension("med") ) { - myMesh->MEDToMesh(File.filePath().c_str(),File.fileNamePure().c_str()); + else if (File.hasExtension("med")) { + myMesh->MEDToMesh(File.filePath().c_str(), File.fileNamePure().c_str()); } - else if (File.hasExtension("inp") ) { + else if (File.hasExtension("inp")) { // read Abaqus inp mesh file readAbaqus(File.filePath()); // if the file doesn't contain supported geometries try Nastran95 SMESHDS_Mesh* meshds = this->myMesh->GetMeshDS(); - if (meshds->NbNodes() == 0) + if (meshds->NbNodes() == 0) { readNastran95(File.filePath()); + } } - else if (File.hasExtension("stl") ) { + else if (File.hasExtension("stl")) { // read brep-file myMesh->STLToMesh(File.filePath().c_str()); } #if SMESH_VERSION_MAJOR < 7 - else if (File.hasExtension("dat") ) { + else if (File.hasExtension("dat")) { // read brep-file // vejmarie disable myMesh->DATToMesh(File.filePath().c_str()); } #endif - else if (File.hasExtension("bdf") ) { + else if (File.hasExtension("bdf")) { // read Nastran-file readNastran(File.filePath()); } @@ -1912,16 +1964,16 @@ void FemMesh::read(const char *FileName) FemVTKTools::readVTKMesh(File.filePath().c_str(), this); } #endif - else if (File.hasExtension("z88") ) { + else if (File.hasExtension("z88")) { // read Z88 mesh file readZ88(File.filePath()); } - else{ + else { throw Base::FileException("Unknown extension"); } } -void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool groupParam) const +void FemMesh::writeABAQUS(const std::string& Filename, int elemParam, bool groupParam) const { /* * elemParam: @@ -1934,7 +1986,7 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group * false = do not write group data */ - static std::map > elemOrderMap; + static std::map> elemOrderMap; static std::map edgeTypeMap; static std::map faceTypeMap; static std::map volTypeMap; @@ -1990,8 +2042,8 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group // master 0.14 release // changed to this in August 2013, committed by juergen (jriedel) // https://github.com/FreeCAD/FreeCAD/commit/af56b324b9566b20f3b6e7880c29354c1dbe7a99 - //std::vector c3d4 = boost::assign::list_of(0)(3)(1)(2); - //std::vector c3d10 = boost::assign::list_of(0)(2)(1)(3)(6)(5)(4)(7)(9)(8); + // std::vector c3d4 = boost::assign::list_of(0)(3)(1)(2); + // std::vector c3d10 = boost::assign::list_of(0)(2)(1)(3)(6)(5)(4)(7)(9)(8); // since master 0.15 // added by werner (wmayer) March 2015, @@ -2000,7 +2052,7 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group // https://github.com/FreeCAD/FreeCAD/commit/b007bd19e4e4608caa4cdad350a9f480287fac6b // tetra4 FreeCAD --> C3D4 CalculiX // N2, N1, N3, N4 - std::vector c3d4 = boost::assign::list_of(1)(0)(2)(3); + std::vector c3d4 = boost::assign::list_of(1)(0)(2)(3); // tetra10: FreeCAD --> C3D10 CalculiX // N2, N1, N3, N4, N5, N7, N6, N9, N8, N10 std::vector c3d10 = boost::assign::list_of(1)(0)(2)(3)(4)(6)(5)(8)(7)(9); @@ -2009,15 +2061,15 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group // be careful with activating because of method getccxVolumesByFace()) // tetra4 FreeCAD --> C3D4 CalculiX // N2, N3, N4, N1 - //std::vector c3d4 = boost::assign::list_of(1)(2)(3)(0); + // std::vector c3d4 = boost::assign::list_of(1)(2)(3)(0); // // tetra10: FreeCAD --> C3D10 CalculiX // N2, N3, N4, N1, N6, N10, N9, N5, N7, N8 - //std::vector c3d10 = boost::assign::list_of(1)(2)(3)(0)(5)(9)(8)(4)(6)(7); + // std::vector c3d10 = boost::assign::list_of(1)(2)(3)(0)(5)(9)(8)(4)(6)(7); // hexa8 FreeCAD --> C3D8 CalculiX // N6, N7, N8, N5, N2, N3, N4, N1 - std::vector c3d8 = boost::assign::list_of(5)(6)(7)(4)(1)(2)(3)(0) ; + std::vector c3d8 = boost::assign::list_of(5)(6)(7)(4)(1)(2)(3)(0); // // hexa20 FreeCAD --> C3D20 CalculiX // N6, N7, N8, N5, N2, N3, N4, N1, N14, N15, N16, N13, N10, N11, N12, N9, N18, N19, N20, N17 @@ -2026,11 +2078,12 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group // // penta6 FreeCAD --> C3D6 CalculiX // N5, N6, N4, N2, N3, N1 - std::vector c3d6 = boost::assign::list_of(4)(5)(3)(1)(2)(0) ; + std::vector c3d6 = boost::assign::list_of(4)(5)(3)(1)(2)(0); // // penta15 FreeCAD --> C3D15 CalculiX // N5, N6, N4, N2, N3, N1, N11, N12, N10, N8, N9, N7, N14, N15, N13 - std::vector c3d15 = boost::assign::list_of(4)(5)(3)(1)(2)(0)(10)(11)(9)(7)(8)(6)(13)(14)(12); + std::vector c3d15 = + boost::assign::list_of(4)(5)(3)(1)(2)(0)(10)(11)(9)(7)(8)(6)(13)(14)(12); elemOrderMap.insert(std::make_pair("C3D4", c3d4)); volTypeMap.insert(std::make_pair(elemOrderMap["C3D4"].size(), "C3D4")); @@ -2048,7 +2101,7 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group // get all data --> Extract Nodes and Elements of the current SMESH datastructure using VertexMap = std::map; - using NodesMap = std::map >; + using NodesMap = std::map>; using ElementsMap = std::map; // get nodes @@ -2057,7 +2110,7 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group Base::Vector3d current_node; while (aNodeIter->more()) { const SMDS_MeshNode* aNode = aNodeIter->next(); - current_node.Set(aNode->X(),aNode->Y(),aNode->Z()); + current_node.Set(aNode->X(), aNode->Y(), aNode->Z()); current_node = _Mtrx * current_node; vertexMap[aNode->GetID()] = current_node; } @@ -2067,19 +2120,20 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group SMDS_VolumeIteratorPtr aVolIter = myMesh->GetMeshDS()->volumesIterator(); while (aVolIter->more()) { const SMDS_MeshVolume* aVol = aVolIter->next(); - std::pair > apair; + std::pair> apair; apair.first = aVol->GetID(); int numNodes = aVol->NbNodes(); std::map::iterator it = volTypeMap.find(numNodes); if (it != volTypeMap.end()) { const std::vector& order = elemOrderMap[it->second]; - for (int jt : order) + for (int jt : order) { apair.second.push_back(aVol->GetNode(jt)->GetID()); + } elementsMapVol[it->second].insert(apair); } } - //get faces + // get faces ElementsMap elementsMapFac; // empty faces map used for elemParam = 1 // and elementsMapVol is not empty if ((elemParam == 0) || (elemParam == 1 && elementsMapVol.empty())) { @@ -2088,14 +2142,15 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group SMDS_FaceIteratorPtr aFaceIter = myMesh->GetMeshDS()->facesIterator(); while (aFaceIter->more()) { const SMDS_MeshFace* aFace = aFaceIter->next(); - std::pair > apair; + std::pair> apair; apair.first = aFace->GetID(); int numNodes = aFace->NbNodes(); std::map::iterator it = faceTypeMap.find(numNodes); if (it != faceTypeMap.end()) { const std::vector& order = elemOrderMap[it->second]; - for (int jt : order) + for (int jt : order) { apair.second.push_back(aFace->GetNode(jt)->GetID()); + } elementsMapFac[it->second].insert(apair); } } @@ -2104,15 +2159,16 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group // we're going to fill the elementsMapFac with the facesOnly std::set facesOnly = getFacesOnly(); for (int itfa : facesOnly) { - std::pair > apair; + std::pair> apair; apair.first = itfa; const SMDS_MeshElement* aFace = myMesh->GetMeshDS()->FindElement(itfa); int numNodes = aFace->NbNodes(); std::map::iterator it = faceTypeMap.find(numNodes); if (it != faceTypeMap.end()) { const std::vector& order = elemOrderMap[it->second]; - for (int jt : order) + for (int jt : order) { apair.second.push_back(aFace->GetNode(jt)->GetID()); + } elementsMapFac[it->second].insert(apair); } } @@ -2127,14 +2183,15 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group SMDS_EdgeIteratorPtr aEdgeIter = myMesh->GetMeshDS()->edgesIterator(); while (aEdgeIter->more()) { const SMDS_MeshEdge* aEdge = aEdgeIter->next(); - std::pair > apair; + std::pair> apair; apair.first = aEdge->GetID(); int numNodes = aEdge->NbNodes(); std::map::iterator it = edgeTypeMap.find(numNodes); if (it != edgeTypeMap.end()) { const std::vector& order = elemOrderMap[it->second]; - for (int jt : order) + for (int jt : order) { apair.second.push_back(aEdge->GetNode(jt)->GetID()); + } elementsMapEdg[it->second].insert(apair); } } @@ -2143,15 +2200,16 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group // we're going to fill the elementsMapEdg with the edgesOnly std::set edgesOnly = getEdgesOnly(); for (int ited : edgesOnly) { - std::pair > apair; + std::pair> apair; apair.first = ited; const SMDS_MeshElement* aEdge = myMesh->GetMeshDS()->FindElement(ited); int numNodes = aEdge->NbNodes(); std::map::iterator it = edgeTypeMap.find(numNodes); if (it != edgeTypeMap.end()) { const std::vector& order = elemOrderMap[it->second]; - for (int jt : order) + for (int jt : order) { apair.second.push_back(aEdge->GetNode(jt)->GetID()); + } elementsMapEdg[it->second].insert(apair); } } @@ -2167,8 +2225,8 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group // add some text and make sure one of the known elemParam values is used anABAQUS_Output << "** written by FreeCAD inp file writer for CalculiX,Abaqus meshes" - << std::endl; - switch(elemParam){ + << std::endl; + switch (elemParam) { case 0: anABAQUS_Output << "** all mesh elements." << std::endl << std::endl; break; @@ -2194,12 +2252,11 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group // This way we get sorted output. // See http://forum.freecad.org/viewtopic.php?f=18&t=12646&start=40#p103004 for (const auto& it : vertexMap) { - anABAQUS_Output << it.first << ", " - << it.second.x << ", " - << it.second.y << ", " - << it.second.z << std::endl; + anABAQUS_Output << it.first << ", " << it.second.x << ", " << it.second.y << ", " + << it.second.z << std::endl; } - anABAQUS_Output << std::endl << std::endl;; + anABAQUS_Output << std::endl << std::endl; + ; // write volumes to file @@ -2215,7 +2272,7 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group bool first_line = true; for (auto kt = jt.second.begin(); kt != jt.second.end(); ++kt, ++ct) { if (ct < 15) { - anABAQUS_Output << ", " << *kt; + anABAQUS_Output << ", " << *kt; } else { if (first_line) { @@ -2245,10 +2302,12 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group anABAQUS_Output << std::endl; } } - if (elsetname.empty()) + if (elsetname.empty()) { elsetname += "Efaces"; - else + } + else { elsetname += ", Efaces"; + } anABAQUS_Output << std::endl; } @@ -2265,10 +2324,12 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group anABAQUS_Output << std::endl; } } - if (elsetname.empty()) + if (elsetname.empty()) { elsetname += "Eedges"; - else + } + else { elsetname += ", Eedges"; + } anABAQUS_Output << std::endl; } @@ -2283,7 +2344,7 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group } else { // get and write group data - anABAQUS_Output << std::endl << "** Group data" << std::endl; + anABAQUS_Output << std::endl << "** Group data" << std::endl; std::list groupIDs = myMesh->GetGroupIds(); for (int it : groupIDs) { @@ -2293,15 +2354,31 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group // PyObject* FemMeshPy::getGroupElementType() SMDSAbs_ElementType aElementType = myMesh->GetGroup(it)->GetGroupDS()->GetType(); const char* groupElementType = ""; - switch(aElementType) { - case SMDSAbs_All : groupElementType = "All"; break; - case SMDSAbs_Node : groupElementType = "Node"; break; - case SMDSAbs_Edge : groupElementType = "Edge"; break; - case SMDSAbs_Face : groupElementType = "Face"; break; - case SMDSAbs_Volume : groupElementType = "Volume"; break; - case SMDSAbs_0DElement : groupElementType = "0DElement"; break; - case SMDSAbs_Ball : groupElementType = "Ball"; break; - default : groupElementType = "Unknown"; break; + switch (aElementType) { + case SMDSAbs_All: + groupElementType = "All"; + break; + case SMDSAbs_Node: + groupElementType = "Node"; + break; + case SMDSAbs_Edge: + groupElementType = "Edge"; + break; + case SMDSAbs_Face: + groupElementType = "Face"; + break; + case SMDSAbs_Volume: + groupElementType = "Volume"; + break; + case SMDSAbs_0DElement: + groupElementType = "0DElement"; + break; + case SMDSAbs_Ball: + groupElementType = "Ball"; + break; + default: + groupElementType = "Unknown"; + break; } const char* groupName = myMesh->GetGroup(it)->GetName(); anABAQUS_Output << "** GroupID: " << (it) << " --> GroupName: " << groupName @@ -2333,7 +2410,7 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group } -void FemMesh::writeZ88(const std::string &FileName) const +void FemMesh::writeZ88(const std::string& FileName) const { Base::TimeInfo Start; Base::Console().Log("Start: FemMesh::writeZ88() =================================\n"); @@ -2345,8 +2422,9 @@ void FemMesh::writeZ88(const std::string &FileName) const */ PyObject* module = PyImport_ImportModule("feminout.importZ88Mesh"); - if (!module) + if (!module) { return; + } try { Py::Module z88mod(module, true); Py::Object mesh = Py::asObject(new FemMeshPy(const_cast(this))); @@ -2362,11 +2440,11 @@ void FemMesh::writeZ88(const std::string &FileName) const } -void FemMesh::write(const char *FileName) const +void FemMesh::write(const char* FileName) const { Base::FileInfo File(FileName); - if (File.hasExtension("unv") ) { + if (File.hasExtension("unv")) { Base::Console().Log("FEM mesh object will be exported to unv format.\n"); // write UNV file myMesh->ExportUNV(File.filePath().c_str()); @@ -2376,19 +2454,19 @@ void FemMesh::write(const char *FileName) const myMesh->ExportMED(File.filePath().c_str(), File.fileNamePure().c_str(), false, - 2); // 2 means MED_V2_2 version! + 2); // 2 means MED_V2_2 version! } - else if (File.hasExtension("stl") ) { + else if (File.hasExtension("stl")) { Base::Console().Log("FEM mesh object will be exported to stl format.\n"); // export to stl file - myMesh->ExportSTL(File.filePath().c_str(),false); + myMesh->ExportSTL(File.filePath().c_str(), false); } - else if (File.hasExtension("dat") ) { + else if (File.hasExtension("dat")) { Base::Console().Log("FEM mesh object will be exported to dat format.\n"); // export to dat file myMesh->ExportDAT(File.filePath().c_str()); } - else if (File.hasExtension("inp") ) { + else if (File.hasExtension("inp")) { Base::Console().Log("FEM mesh object will be exported to inp format.\n"); // get Abaqus inp prefs ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( @@ -2405,27 +2483,27 @@ void FemMesh::write(const char *FileName) const FemVTKTools::writeVTKMesh(File.filePath().c_str(), this); } #endif - else if (File.hasExtension("z88") ) { + else if (File.hasExtension("z88")) { Base::Console().Log("FEM mesh object will be exported to z88 format.\n"); // write z88 file writeZ88(File.filePath()); } - else{ + else { throw Base::FileException("An unknown file extension was added!"); } } // ==== Base class implementer ============================================================== -unsigned int FemMesh::getMemSize () const +unsigned int FemMesh::getMemSize() const { return 0; } -void FemMesh::Save (Base::Writer &writer) const +void FemMesh::Save(Base::Writer& writer) const { if (!writer.isForceXML()) { - //See SaveDocFile(), RestoreDocFile() + // See SaveDocFile(), RestoreDocFile() writer.Stream() << writer.ind() << "ExportUNV(fi.filePath().c_str()); Base::ifstream file(fi, std::ios::in | std::ios::binary); - if (file){ + if (file) { std::streambuf* buf = file.rdbuf(); writer.Stream() << buf; } @@ -2502,15 +2580,16 @@ void FemMesh::SaveDocFile (Base::Writer &writer) const fi.deleteFile(); } -void FemMesh::RestoreDocFile(Base::Reader &reader) +void FemMesh::RestoreDocFile(Base::Reader& reader) { // create a temporary file and copy the content from the zip stream Base::FileInfo fi(App::Application::getTempFileName().c_str()); // read in the ASCII file and write back to the file stream Base::ofstream file(fi, std::ios::out | std::ios::binary); - if (reader) + if (reader) { reader >> file.rdbuf(); + } file.close(); // read the shape from the temp file @@ -2522,15 +2601,15 @@ void FemMesh::RestoreDocFile(Base::Reader &reader) void FemMesh::transformGeometry(const Base::Matrix4D& rclTrf) { - //We perform a translation and rotation of the current active Mesh object + // We perform a translation and rotation of the current active Mesh object Base::Matrix4D clMatrix(rclTrf); SMDS_NodeIteratorPtr aNodeIter = myMesh->GetMeshDS()->nodesIterator(); Base::Vector3d current_node; - for (;aNodeIter->more();) { + for (; aNodeIter->more();) { const SMDS_MeshNode* aNode = aNodeIter->next(); - current_node.Set(aNode->X(),aNode->Y(),aNode->Z()); + current_node.Set(aNode->X(), aNode->Y(), aNode->Z()); current_node = clMatrix * current_node; - myMesh->GetMeshDS()->MoveNode(aNode,current_node.x,current_node.y,current_node.z); + myMesh->GetMeshDS()->MoveNode(aNode, current_node.x, current_node.y, current_node.z); } } @@ -2552,9 +2631,9 @@ Base::BoundBox3d FemMesh::getBoundBox() const const SMESHDS_Mesh* data = getSMesh()->GetMeshDS(); SMDS_NodeIteratorPtr aNodeIter = data->nodesIterator(); - for (;aNodeIter->more();) { + for (; aNodeIter->more();) { const SMDS_MeshNode* aNode = aNodeIter->next(); - Base::Vector3d vec(aNode->X(),aNode->Y(),aNode->Z()); + Base::Vector3d vec(aNode->X(), aNode->Y(), aNode->Z()); // Apply the matrix to hold the BoundBox in absolute space. vec = _Mtrx * vec; box.Add(vec); @@ -2582,23 +2661,24 @@ unsigned long FemMesh::countSubElements(const char* /*Type*/) const Data::Segment* FemMesh::getSubElement(const char* /*Type*/, unsigned long /*n*/) const { // FIXME implement subelement interface - //std::stringstream str; - //str << Type << n; - //std::string temp = str.str(); - //return new ShapeSegment(getSubShape(temp.c_str())); + // std::stringstream str; + // str << Type << n; + // std::string temp = str.str(); + // return new ShapeSegment(getSubShape(temp.c_str())); return nullptr; } -void FemMesh::getPoints(std::vector &Points, - std::vector & /*Normals*/, - double /*Accuracy*/, uint16_t /*flags*/) const +void FemMesh::getPoints(std::vector& Points, + std::vector& /*Normals*/, + double /*Accuracy*/, + uint16_t /*flags*/) const { const SMESHDS_Mesh* data = getSMesh()->GetMeshDS(); std::vector nodes; nodes.reserve(data->NbNodes()); SMDS_NodeIteratorPtr aNodeIter = data->nodesIterator(); - for (;aNodeIter->more();) { + for (; aNodeIter->more();) { const SMDS_MeshNode* aNode = aNodeIter->next(); nodes.emplace_back(aNode->X(), aNode->Y(), aNode->Z()); } @@ -2606,11 +2686,12 @@ void FemMesh::getPoints(std::vector &Points, Points = transformPointsToOutside(nodes); } -struct Fem::FemMesh::FemMeshInfo FemMesh::getInfo() const{ +struct Fem::FemMesh::FemMeshInfo FemMesh::getInfo() const +{ struct FemMeshInfo rtrn; - const SMESHDS_Mesh* data = getSMesh()->GetMeshDS(); + const SMESHDS_Mesh* data = getSMesh()->GetMeshDS(); const SMDS_MeshInfo& info = data->GetMeshInfo(); rtrn.numFaces = data->NbFaces(); rtrn.numNode = info.NbNodes(); @@ -2625,7 +2706,6 @@ struct Fem::FemMesh::FemMeshInfo FemMesh::getInfo() const{ rtrn.numHedr = info.NbPolyhedrons(); return rtrn; - } // for (unsigned int i = 0; i < all_elements.size(); i++) // { @@ -2647,35 +2727,36 @@ struct Fem::FemMesh::FemMeshInfo FemMesh::getInfo() const{ // ); // } -Base::Quantity FemMesh::getVolume()const +Base::Quantity FemMesh::getVolume() const { SMDS_VolumeIteratorPtr aVolIter = myMesh->GetMeshDS()->volumesIterator(); - //Calculate Mesh Volume - //For an accurate Volume Calculation of a quadratic Tetrahedron - //we have to calculate the Volume of 8 Sub-Tetrahedrons - Base::Vector3d a,b,c,a_b_product; + // Calculate Mesh Volume + // For an accurate Volume Calculation of a quadratic Tetrahedron + // we have to calculate the Volume of 8 Sub-Tetrahedrons + Base::Vector3d a, b, c, a_b_product; double volume = 0.0; - for (;aVolIter->more();) - { + for (; aVolIter->more();) { const SMDS_MeshVolume* aVol = aVolIter->next(); - if ( aVol->NbNodes() != 10 ) continue; + if (aVol->NbNodes() != 10) { + continue; + } - Base::Vector3d v1(aVol->GetNode(1)->X(),aVol->GetNode(1)->Y(),aVol->GetNode(1)->Z()); - Base::Vector3d v0(aVol->GetNode(0)->X(),aVol->GetNode(0)->Y(),aVol->GetNode(0)->Z()); - Base::Vector3d v2(aVol->GetNode(2)->X(),aVol->GetNode(2)->Y(),aVol->GetNode(2)->Z()); - Base::Vector3d v3(aVol->GetNode(3)->X(),aVol->GetNode(3)->Y(),aVol->GetNode(3)->Z()); - Base::Vector3d v4(aVol->GetNode(4)->X(),aVol->GetNode(4)->Y(),aVol->GetNode(4)->Z()); - Base::Vector3d v6(aVol->GetNode(6)->X(),aVol->GetNode(6)->Y(),aVol->GetNode(6)->Z()); - Base::Vector3d v5(aVol->GetNode(5)->X(),aVol->GetNode(5)->Y(),aVol->GetNode(5)->Z()); - Base::Vector3d v8(aVol->GetNode(8)->X(),aVol->GetNode(8)->Y(),aVol->GetNode(8)->Z()); - Base::Vector3d v7(aVol->GetNode(7)->X(),aVol->GetNode(7)->Y(),aVol->GetNode(7)->Z()); - Base::Vector3d v9(aVol->GetNode(9)->X(),aVol->GetNode(9)->Y(),aVol->GetNode(9)->Z()); + Base::Vector3d v1(aVol->GetNode(1)->X(), aVol->GetNode(1)->Y(), aVol->GetNode(1)->Z()); + Base::Vector3d v0(aVol->GetNode(0)->X(), aVol->GetNode(0)->Y(), aVol->GetNode(0)->Z()); + Base::Vector3d v2(aVol->GetNode(2)->X(), aVol->GetNode(2)->Y(), aVol->GetNode(2)->Z()); + Base::Vector3d v3(aVol->GetNode(3)->X(), aVol->GetNode(3)->Y(), aVol->GetNode(3)->Z()); + Base::Vector3d v4(aVol->GetNode(4)->X(), aVol->GetNode(4)->Y(), aVol->GetNode(4)->Z()); + Base::Vector3d v6(aVol->GetNode(6)->X(), aVol->GetNode(6)->Y(), aVol->GetNode(6)->Z()); + Base::Vector3d v5(aVol->GetNode(5)->X(), aVol->GetNode(5)->Y(), aVol->GetNode(5)->Z()); + Base::Vector3d v8(aVol->GetNode(8)->X(), aVol->GetNode(8)->Y(), aVol->GetNode(8)->Z()); + Base::Vector3d v7(aVol->GetNode(7)->X(), aVol->GetNode(7)->Y(), aVol->GetNode(7)->Z()); + Base::Vector3d v9(aVol->GetNode(9)->X(), aVol->GetNode(9)->Y(), aVol->GetNode(9)->Z()); - //1,5,8,7 + // 1,5,8,7 a = v4 - v0; b = v7 - v0; c = v6 - v0; @@ -2684,7 +2765,7 @@ Base::Quantity FemMesh::getVolume()const a_b_product.z = a.x * b.y - b.x * a.y; volume += 1.0 / 6.0 * fabs((a_b_product.x * c.x) + (a_b_product.y * c.y) + (a_b_product.z * c.z)); - //5,9,8,7 + // 5,9,8,7 a = v8 - v4; b = v7 - v4; c = v6 - v4; @@ -2693,7 +2774,7 @@ Base::Quantity FemMesh::getVolume()const a_b_product.z = a.x * b.y - b.x * a.y; volume += 1.0 / 6.0 * fabs((a_b_product.x * c.x) + (a_b_product.y * c.y) + (a_b_product.z * c.z)); - //5,2,9,7 + // 5,2,9,7 a = v1 - v4; b = v8 - v4; c = v6 - v4; @@ -2702,7 +2783,7 @@ Base::Quantity FemMesh::getVolume()const a_b_product.z = a.x * b.y - b.x * a.y; volume += 1.0 / 6.0 * fabs((a_b_product.x * c.x) + (a_b_product.y * c.y) + (a_b_product.z * c.z)); - //2,6,9,7 + // 2,6,9,7 a = v5 - v1; b = v8 - v1; c = v6 - v1; @@ -2711,7 +2792,7 @@ Base::Quantity FemMesh::getVolume()const a_b_product.z = a.x * b.y - b.x * a.y; volume += 1.0 / 6.0 * fabs((a_b_product.x * c.x) + (a_b_product.y * c.y) + (a_b_product.z * c.z)); - //9,6,10,7 + // 9,6,10,7 a = v5 - v8; b = v9 - v8; c = v6 - v8; @@ -2720,7 +2801,7 @@ Base::Quantity FemMesh::getVolume()const a_b_product.z = a.x * b.y - b.x * a.y; volume += 1.0 / 6.0 * fabs((a_b_product.x * c.x) + (a_b_product.y * c.y) + (a_b_product.z * c.z)); - //6,3,10,7 + // 6,3,10,7 a = v2 - v5; b = v9 - v5; c = v6 - v5; @@ -2729,7 +2810,7 @@ Base::Quantity FemMesh::getVolume()const a_b_product.z = a.x * b.y - b.x * a.y; volume += 1.0 / 6.0 * fabs((a_b_product.x * c.x) + (a_b_product.y * c.y) + (a_b_product.z * c.z)); - //8,9,10,7 + // 8,9,10,7 a = v8 - v7; b = v9 - v7; c = v6 - v7; @@ -2738,7 +2819,7 @@ Base::Quantity FemMesh::getVolume()const a_b_product.z = a.x * b.y - b.x * a.y; volume += 1.0 / 6.0 * fabs((a_b_product.x * c.x) + (a_b_product.y * c.y) + (a_b_product.z * c.z)); - //8,9,10,4 + // 8,9,10,4 a = v8 - v7; b = v9 - v7; c = v3 - v7; @@ -2747,12 +2828,9 @@ Base::Quantity FemMesh::getVolume()const a_b_product.z = a.x * b.y - b.x * a.y; volume += 1.0 / 6.0 * fabs((a_b_product.x * c.x) + (a_b_product.y * c.y) + (a_b_product.z * c.z)); - } - return Base::Quantity(volume,Unit::Volume); - - + return Base::Quantity(volume, Unit::Volume); } int FemMesh::addGroup(const std::string TypeString, const std::string Name, const int theId) @@ -2773,19 +2851,21 @@ int FemMesh::addGroup(const std::string TypeString, const std::string Name, cons // check whether typestring is valid bool typeStringValid = false; - for (string_eltype_map::const_iterator it = mapping.begin(); it != mapping.end(); ++it) - { + for (string_eltype_map::const_iterator it = mapping.begin(); it != mapping.end(); ++it) { std::string key = it->first; - if (key == TypeString) + if (key == TypeString) { typeStringValid = true; + } } - if (!typeStringValid) + if (!typeStringValid) { throw std::runtime_error("AddGroup: Invalid type string! Allowed: All, Node, Edge, Face, " "Volume, 0DElement, Ball"); + } // add group to mesh SMESH_Group* group = this->getSMesh()->AddGroup(mapping[TypeString], Name.c_str(), aId); - if (!group) + if (!group) { throw std::runtime_error("AddGroup: Failed to create new group."); + } #if SMESH_VERSION_MAJOR >= 9 return group->GetID(); #else @@ -2813,11 +2893,11 @@ void FemMesh::addGroupElements(int GroupId, const std::set& ElementIds) const SMDS_MeshElement* aElem = aElemIter->next(); std::set::iterator it; it = ElementIds.find(aElem->GetID()); - if (it != ElementIds.end()) - { + if (it != ElementIds.end()) { // the element was in the list - if (!groupDS->Contains(aElem)) // check whether element is already in group - groupDS->Add(aElem); // if not, add it + if (!groupDS->Contains(aElem)) { // check whether element is already in group + groupDS->Add(aElem); // if not, add it + } } } } @@ -2826,4 +2906,3 @@ bool FemMesh::removeGroup(int GroupId) { return this->getSMesh()->RemoveGroup(GroupId); } - diff --git a/src/Mod/Fem/App/FemMesh.h b/src/Mod/Fem/App/FemMesh.h index 568a9af6c0..8c3431a869 100644 --- a/src/Mod/Fem/App/FemMesh.h +++ b/src/Mod/Fem/App/FemMesh.h @@ -27,8 +27,8 @@ #include #include -#include #include +#include #include #include @@ -51,7 +51,7 @@ using SMESH_HypothesisPtr = std::shared_ptr; /** The representation of a FemMesh */ -class FemExport FemMesh : public Data::ComplexGeoData +class FemExport FemMesh: public Data::ComplexGeoData { TYPESYSTEM_HEADER_WITH_OVERRIDE(); @@ -60,20 +60,20 @@ public: FemMesh(const FemMesh&); ~FemMesh() override; - FemMesh &operator=(const FemMesh&); + FemMesh& operator=(const FemMesh&); const SMESH_Mesh* getSMesh() const; SMESH_Mesh* getSMesh(); - static SMESH_Gen * getGenerator(); - void addHypothesis(const TopoDS_Shape & aSubShape, SMESH_HypothesisPtr hyp); + static SMESH_Gen* getGenerator(); + void addHypothesis(const TopoDS_Shape& aSubShape, SMESH_HypothesisPtr hyp); void setStandardHypotheses(); void compute(); // from base class - unsigned int getMemSize () const override; - void Save (Base::Writer &/*writer*/) const override; - void Restore(Base::XMLReader &/*reader*/) override; - void SaveDocFile (Base::Writer &writer) const override; - void RestoreDocFile(Base::Reader &reader) override; + unsigned int getMemSize() const override; + void Save(Base::Writer& /*writer*/) const override; + void Restore(Base::XMLReader& /*reader*/) override; + void SaveDocFile(Base::Writer& writer) const override; + void RestoreDocFile(Base::Reader& reader) override; /** @name Subelement management */ //@{ @@ -86,40 +86,41 @@ public: /// get the subelement by type and number Data::Segment* getSubElement(const char* Type, unsigned long) const override; /** Get points from object with given accuracy */ - void getPoints(std::vector &Points, - std::vector &Normals, - double Accuracy, uint16_t flags=0) const override; + void getPoints(std::vector& Points, + std::vector& Normals, + double Accuracy, + uint16_t flags = 0) const override; //@} /** @name search and retrieval */ //@{ /// retrieving by region growing - std::set getSurfaceNodes(long ElemId, short FaceId, float Angle=360)const; + std::set getSurfaceNodes(long ElemId, short FaceId, float Angle = 360) const; /// retrieving by solid - std::set getNodesBySolid(const TopoDS_Solid &solid) const; + std::set getNodesBySolid(const TopoDS_Solid& solid) const; /// retrieving by face - std::set getNodesByFace(const TopoDS_Face &face) const; + std::set getNodesByFace(const TopoDS_Face& face) const; /// retrieving by edge - std::set getNodesByEdge(const TopoDS_Edge &edge) const; + std::set getNodesByEdge(const TopoDS_Edge& edge) const; /// retrieving by vertex - std::set getNodesByVertex(const TopoDS_Vertex &vertex) const; + std::set getNodesByVertex(const TopoDS_Vertex& vertex) const; /// retrieving node IDs by element ID std::list getElementNodes(int id) const; /// retrieving elements IDs by node ID - std::list getNodeElements(int id, SMDSAbs_ElementType type=SMDSAbs_All) const; + std::list getNodeElements(int id, SMDSAbs_ElementType type = SMDSAbs_All) const; /// retrieving face IDs number by face - std::list getFacesByFace(const TopoDS_Face &face) const; + std::list getFacesByFace(const TopoDS_Face& face) const; /// retrieving edge IDs number by edge - std::list getEdgesByEdge(const TopoDS_Edge &edge) const; + std::list getEdgesByEdge(const TopoDS_Edge& edge) const; /// retrieving volume IDs and face IDs number by face - std::list > getVolumesByFace(const TopoDS_Face &face) const; + std::list> getVolumesByFace(const TopoDS_Face& face) const; /// retrieving volume IDs and CalculiX face number by face - std::map getccxVolumesByFace(const TopoDS_Face &face) const; + std::map getccxVolumesByFace(const TopoDS_Face& face) const; /// retrieving IDs of edges not belonging to any face (and thus not belonging to any volume too) std::set getEdgesOnly() const; /// retrieving IDs of faces not belonging to any volume std::set getFacesOnly() const; - //@} + //@} /** @name Placement control */ //@{ @@ -128,21 +129,21 @@ public: /// get the transformation Base::Matrix4D getTransform() const override; /// Bound box from the shape - Base::BoundBox3d getBoundBox()const override; + Base::BoundBox3d getBoundBox() const override; /// get the volume (when there are volume elements) - Base::Quantity getVolume()const; + Base::Quantity getVolume() const; //@} /** @name Modification */ //@{ /// Applies a transformation on the real geometric data type - void transformGeometry(const Base::Matrix4D &rclMat) override; + void transformGeometry(const Base::Matrix4D& rclMat) override; //@} /** @name Group management */ //@{ /// Adds group to mesh - int addGroup(const std::string, const std::string, const int=-1); + int addGroup(const std::string, const std::string, const int = -1); /// Adds elements to group (int due to int used by raw SMESH functions) void addGroupElements(int, const std::set&); /// Remove group (Name due to similarity to SMESH basis functions) @@ -150,7 +151,8 @@ public: //@} - struct FemMeshInfo { + struct FemMeshInfo + { int numFaces; int numNode; int numTria; @@ -168,28 +170,28 @@ public: struct FemMeshInfo getInfo() const; /// import from files - void read(const char *FileName); - void write(const char *FileName) const; - void writeABAQUS(const std::string &Filename, int elemParam, bool groupParam) const; - void writeZ88(const std::string &FileName) const; + void read(const char* FileName); + void write(const char* FileName) const; + void writeABAQUS(const std::string& Filename, int elemParam, bool groupParam) const; + void writeZ88(const std::string& FileName) const; private: void copyMeshData(const FemMesh&); - void readNastran(const std::string &Filename); - void readNastran95(const std::string &Filename); - void readZ88(const std::string &Filename); - void readAbaqus(const std::string &Filename); + void readNastran(const std::string& Filename); + void readNastran95(const std::string& Filename); + void readZ88(const std::string& Filename); + void readAbaqus(const std::string& Filename); private: /// positioning matrix Base::Matrix4D _Mtrx; - SMESH_Mesh *myMesh; + SMESH_Mesh* myMesh; std::list hypoth; - static SMESH_Gen *_mesh_gen; + static SMESH_Gen* _mesh_gen; }; -} //namespace Part +} // namespace Fem -#endif // FEM_FEMMESH_H +#endif // FEM_FEMMESH_H diff --git a/src/Mod/Fem/App/FemMeshObject.cpp b/src/Mod/Fem/App/FemMeshObject.cpp index c106061a03..43b31db040 100644 --- a/src/Mod/Fem/App/FemMeshObject.cpp +++ b/src/Mod/Fem/App/FemMeshObject.cpp @@ -22,12 +22,12 @@ #include "PreCompiled.h" -#include #include +#include #include -#include "FemMeshObject.h" #include "FemMesh.h" +#include "FemMeshObject.h" using namespace Fem; @@ -38,7 +38,7 @@ PROPERTY_SOURCE(Fem::FemMeshObject, App::GeoFeature) FemMeshObject::FemMeshObject() { - ADD_PROPERTY_TYPE(FemMesh,(), "FEM Mesh",Prop_NoRecompute,"FEM Mesh object"); + ADD_PROPERTY_TYPE(FemMesh, (), "FEM Mesh", Prop_NoRecompute, "FEM Mesh object"); // in the regard of recomputes see: // https://forum.freecad.org/viewtopic.php?f=18&t=33329#p279203 } @@ -50,9 +50,9 @@ short FemMeshObject::mustExecute() const return 0; } -PyObject *FemMeshObject::getPyObject() +PyObject* FemMeshObject::getPyObject() { - if (PythonObject.is(Py::_None())){ + if (PythonObject.is(Py::_None())) { // ref counter is set to 1 PythonObject = Py::asObject(new GeoFeaturePy(this)); } @@ -67,19 +67,23 @@ void FemMeshObject::onChanged(const Property* prop) if (prop == &this->Placement) { this->FemMesh.setTransform(this->Placement.getValue().toMatrix()); } - } // Python feature --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Fem::FemMeshObjectPython, Fem::FemMeshObject) -template<> const char* Fem::FemMeshObjectPython::getViewProviderName() const { +template<> +const char* Fem::FemMeshObjectPython::getViewProviderName() const +{ return "FemGui::ViewProviderFemMeshPython"; } -template<> PyObject* Fem::FemMeshObjectPython::getPyObject() { +template<> +PyObject* Fem::FemMeshObjectPython::getPyObject() +{ if (PythonObject.is(Py::_None())) { // ref counter is set to 1 PythonObject = Py::asObject(new App::FeaturePythonPyT(this)); @@ -92,4 +96,4 @@ template class FemExport FeaturePythonT; /// @endcond -} +} // namespace App diff --git a/src/Mod/Fem/App/FemMeshObject.h b/src/Mod/Fem/App/FemMeshObject.h index 5360686d31..97d51b44db 100644 --- a/src/Mod/Fem/App/FemMeshObject.h +++ b/src/Mod/Fem/App/FemMeshObject.h @@ -33,7 +33,7 @@ namespace Fem { -class FemExport FemMeshObject : public App::GeoFeature +class FemExport FemMeshObject: public App::GeoFeature { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemMeshObject); @@ -43,15 +43,18 @@ public: ~FemMeshObject() override; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemMesh"; } - App::DocumentObjectExecReturn *execute() override { + App::DocumentObjectExecReturn* execute() override + { return App::DocumentObject::StdReturn; } short mustExecute() const override; - PyObject *getPyObject() override; - const App::PropertyComplexGeoData* getPropertyOfGeometry() const override { + PyObject* getPyObject() override; + const App::PropertyComplexGeoData* getPropertyOfGeometry() const override + { return &FemMesh; } @@ -59,13 +62,13 @@ public: protected: /// get called by the container when a property has changed - void onChanged (const App::Property* prop) override; + void onChanged(const App::Property* prop) override; }; using FemMeshObjectPython = App::FeaturePythonT; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemMeshObject_H +#endif // Fem_FemMeshObject_H diff --git a/src/Mod/Fem/App/FemMeshProperty.cpp b/src/Mod/Fem/App/FemMeshProperty.cpp index 84b1f41dff..d4721bc7c3 100644 --- a/src/Mod/Fem/App/FemMeshProperty.cpp +++ b/src/Mod/Fem/App/FemMeshProperty.cpp @@ -23,7 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -36,11 +36,11 @@ using namespace Fem; -TYPESYSTEM_SOURCE(Fem::PropertyFemMesh , App::PropertyComplexGeoData) +TYPESYSTEM_SOURCE(Fem::PropertyFemMesh, App::PropertyComplexGeoData) -PropertyFemMesh::PropertyFemMesh() : _FemMesh(new FemMesh) -{ -} +PropertyFemMesh::PropertyFemMesh() + : _FemMesh(new FemMesh) +{} PropertyFemMesh::~PropertyFemMesh() = default; @@ -61,7 +61,7 @@ void PropertyFemMesh::setValue(const FemMesh& sh) hasSetValue(); } -const FemMesh &PropertyFemMesh::getValue()const +const FemMesh& PropertyFemMesh::getValue() const { return *_FemMesh; } @@ -76,7 +76,7 @@ Base::BoundBox3d PropertyFemMesh::getBoundingBox() const return _FemMesh->getBoundBox(); } -void PropertyFemMesh::setTransform(const Base::Matrix4D &rclTrf) +void PropertyFemMesh::setTransform(const Base::Matrix4D& rclTrf) { _FemMesh->setTransform(rclTrf); } @@ -86,28 +86,28 @@ Base::Matrix4D PropertyFemMesh::getTransform() const return _FemMesh->getTransform(); } -void PropertyFemMesh::transformGeometry(const Base::Matrix4D &rclMat) +void PropertyFemMesh::transformGeometry(const Base::Matrix4D& rclMat) { aboutToSetValue(); _FemMesh->transformGeometry(rclMat); hasSetValue(); } -PyObject *PropertyFemMesh::getPyObject() +PyObject* PropertyFemMesh::getPyObject() { FemMeshPy* mesh = new FemMeshPy(&*_FemMesh); mesh->setConst(); return mesh; } -void PropertyFemMesh::setPyObject(PyObject *value) +void PropertyFemMesh::setPyObject(PyObject* value) { if (PyObject_TypeCheck(value, &(FemMeshPy::Type))) { - FemMeshPy *pcObject = static_cast(value); + FemMeshPy* pcObject = static_cast(value); setValue(*pcObject->getFemMeshPtr()); } else if (PyObject_TypeCheck(value, &(Base::PlacementPy::Type))) { - Base::PlacementPy *pcObject = static_cast(value); + Base::PlacementPy* pcObject = static_cast(value); transformGeometry(pcObject->getPlacementPtr()->toMatrix()); } else { @@ -117,41 +117,41 @@ void PropertyFemMesh::setPyObject(PyObject *value) } } -App::Property *PropertyFemMesh::Copy() const +App::Property* PropertyFemMesh::Copy() const { - PropertyFemMesh *prop = new PropertyFemMesh(); + PropertyFemMesh* prop = new PropertyFemMesh(); prop->_FemMesh = this->_FemMesh; return prop; } -void PropertyFemMesh::Paste(const App::Property &from) +void PropertyFemMesh::Paste(const App::Property& from) { aboutToSetValue(); _FemMesh = dynamic_cast(from)._FemMesh; hasSetValue(); } -unsigned int PropertyFemMesh::getMemSize () const +unsigned int PropertyFemMesh::getMemSize() const { return _FemMesh->getMemSize(); } -void PropertyFemMesh::Save (Base::Writer &writer) const +void PropertyFemMesh::Save(Base::Writer& writer) const { _FemMesh->Save(writer); } -void PropertyFemMesh::Restore(Base::XMLReader &reader) +void PropertyFemMesh::Restore(Base::XMLReader& reader) { _FemMesh->Restore(reader); } -void PropertyFemMesh::SaveDocFile (Base::Writer &writer) const +void PropertyFemMesh::SaveDocFile(Base::Writer& writer) const { _FemMesh->SaveDocFile(writer); } -void PropertyFemMesh::RestoreDocFile(Base::Reader &reader ) +void PropertyFemMesh::RestoreDocFile(Base::Reader& reader) { aboutToSetValue(); _FemMesh->RestoreDocFile(reader); diff --git a/src/Mod/Fem/App/FemMeshProperty.h b/src/Mod/Fem/App/FemMeshProperty.h index a6d1af5138..84bdb8ff80 100644 --- a/src/Mod/Fem/App/FemMeshProperty.h +++ b/src/Mod/Fem/App/FemMeshProperty.h @@ -35,7 +35,7 @@ namespace Fem /** The part shape property class. * @author Werner Mayer */ -class FemExport PropertyFemMesh : public App::PropertyComplexGeoData +class FemExport PropertyFemMesh: public App::PropertyComplexGeoData { TYPESYSTEM_HEADER_WITH_OVERRIDE(); @@ -49,9 +49,10 @@ public: /// set the FemMesh shape void setValue(const FemMesh&); /// does nothing, for add property macro - void setValue(){} + void setValue() + {} /// get the FemMesh shape - const FemMesh &getValue() const; + const FemMesh& getValue() const; const Data::ComplexGeoData* getComplexData() const override; //@} @@ -64,26 +65,29 @@ public: void setTransform(const Base::Matrix4D& rclTrf) override; /// Get the placement of the geometry Base::Matrix4D getTransform() const override; - void transformGeometry(const Base::Matrix4D &rclMat) override; + void transformGeometry(const Base::Matrix4D& rclMat) override; //@} /** @name Python interface */ //@{ PyObject* getPyObject() override; - void setPyObject(PyObject *value) override; + void setPyObject(PyObject* value) override; //@} /** @name Save/restore */ //@{ - void Save (Base::Writer &writer) const override; - void Restore(Base::XMLReader &reader) override; - void SaveDocFile (Base::Writer &writer) const override; - void RestoreDocFile(Base::Reader &reader) override; + void Save(Base::Writer& writer) const override; + void Restore(Base::XMLReader& reader) override; + void SaveDocFile(Base::Writer& writer) const override; + void RestoreDocFile(Base::Reader& reader) override; - App::Property *Copy() const override; - void Paste(const App::Property &from) override; - unsigned int getMemSize () const override; - const char* getEditorName() const override { return "FemGui::PropertyFemMeshItem"; } + App::Property* Copy() const override; + void Paste(const App::Property& from) override; + unsigned int getMemSize() const override; + const char* getEditorName() const override + { + return "FemGui::PropertyFemMeshItem"; + } //@} private: @@ -91,7 +95,7 @@ private: }; -} //namespace Fem +} // namespace Fem -#endif // PROPERTYTOPOSHAPE_H +#endif // PROPERTYTOPOSHAPE_H diff --git a/src/Mod/Fem/App/FemMeshPyImp.cpp b/src/Mod/Fem/App/FemMeshPyImp.cpp index 38f7899491..0a0d764135 100644 --- a/src/Mod/Fem/App/FemMeshPyImp.cpp +++ b/src/Mod/Fem/App/FemMeshPyImp.cpp @@ -23,35 +23,37 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif +#include "Mod/Fem/App/FemMesh.h" #include #include #include #include -#include #include #include +#include #include #include -#include "Mod/Fem/App/FemMesh.h" +// clang-format off // inclusion of the generated files (generated out of FemMeshPy.xml) #include "FemMeshPy.h" #include "FemMeshPy.cpp" #include "HypothesisPy.h" +// clang-format on using namespace Fem; @@ -64,7 +66,7 @@ std::string FemMeshPy::representation() const return str.str(); } -PyObject *FemMeshPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +PyObject* FemMeshPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper { // create a new instance of FemMeshPy and the Twin object return new FemMeshPy(new FemMesh); @@ -73,29 +75,32 @@ PyObject *FemMeshPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Py // constructor method int FemMeshPy::PyInit(PyObject* args, PyObject* /*kwd*/) { - PyObject *pcObj=nullptr; - if (!PyArg_ParseTuple(args, "|O", &pcObj)) + PyObject* pcObj = nullptr; + if (!PyArg_ParseTuple(args, "|O", &pcObj)) { return -1; + } try { // if no mesh is given - if (!pcObj) + if (!pcObj) { return 0; + } if (PyObject_TypeCheck(pcObj, &(FemMeshPy::Type))) { - getFemMeshPtr()->operator= (*static_cast(pcObj)->getFemMeshPtr()); + getFemMeshPtr()->operator=(*static_cast(pcObj)->getFemMeshPtr()); } else { - PyErr_Format(PyExc_TypeError, "Cannot create a FemMesh out of a '%s'", - pcObj->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, + "Cannot create a FemMesh out of a '%s'", + pcObj->ob_type->tp_name); return -1; } } - catch (const Base::Exception &e) { + catch (const Base::Exception& e) { e.setPyException(); return -1; } - catch (const std::exception &e) { - PyErr_SetString(Base::PyExc_FC_GeneralError,e.what()); + catch (const std::exception& e) { + PyErr_SetString(Base::PyExc_FC_GeneralError, e.what()); return -1; } catch (const Py::Exception&) { @@ -108,11 +113,12 @@ int FemMeshPy::PyInit(PyObject* args, PyObject* /*kwd*/) // ===== Methods ============================================================ -PyObject* FemMeshPy::setShape(PyObject *args) +PyObject* FemMeshPy::setShape(PyObject* args) { - PyObject *pcObj; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapePy::Type), &pcObj)) + PyObject* pcObj; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapePy::Type), &pcObj)) { return nullptr; + } try { TopoDS_Shape shape = static_cast(pcObj)->getTopoShapePtr()->getShape(); @@ -125,20 +131,23 @@ PyObject* FemMeshPy::setShape(PyObject *args) Py_Return; } -PyObject* FemMeshPy::addHypothesis(PyObject *args) +PyObject* FemMeshPy::addHypothesis(PyObject* args) { PyObject* hyp; PyObject* shp = nullptr; // Since we have not a common base class for the Python binding of the // hypotheses classes we cannot pass a certain Python type - if (!PyArg_ParseTuple(args, "O|O!",&hyp, &(Part::TopoShapePy::Type), &shp)) + if (!PyArg_ParseTuple(args, "O|O!", &hyp, &(Part::TopoShapePy::Type), &shp)) { return nullptr; + } TopoDS_Shape shape; - if (!shp) + if (!shp) { shape = getFemMeshPtr()->getSMesh()->GetShapeToMesh(); - else + } + else { shape = static_cast(shp)->getTopoShapePtr()->getShape(); + } try { Py::Object obj(hyp); @@ -156,10 +165,11 @@ PyObject* FemMeshPy::addHypothesis(PyObject *args) Py_Return; } -PyObject* FemMeshPy::setStandardHypotheses(PyObject *args) +PyObject* FemMeshPy::setStandardHypotheses(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } try { getFemMeshPtr()->setStandardHypotheses(); @@ -171,10 +181,11 @@ PyObject* FemMeshPy::setStandardHypotheses(PyObject *args) Py_Return; } -PyObject* FemMeshPy::compute(PyObject *args) +PyObject* FemMeshPy::compute(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } try { getFemMeshPtr()->compute(); @@ -186,17 +197,18 @@ PyObject* FemMeshPy::compute(PyObject *args) Py_Return; } -PyObject* FemMeshPy::addNode(PyObject *args) +PyObject* FemMeshPy::addNode(PyObject* args) { - double x,y,z; + double x, y, z; int i = -1; - if (PyArg_ParseTuple(args, "ddd",&x,&y,&z)){ + if (PyArg_ParseTuple(args, "ddd", &x, &y, &z)) { try { SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh(); SMESHDS_Mesh* meshDS = mesh->GetMeshDS(); - SMDS_MeshNode* node = meshDS->AddNode(x,y,z); - if (!node) + SMDS_MeshNode* node = meshDS->AddNode(x, y, z); + if (!node) { throw std::runtime_error("Failed to add node"); + } return Py::new_reference_to(Py::Long(node->GetID())); } catch (const std::exception& e) { @@ -206,13 +218,14 @@ PyObject* FemMeshPy::addNode(PyObject *args) } PyErr_Clear(); - if (PyArg_ParseTuple(args, "dddi",&x,&y,&z,&i)){ + if (PyArg_ParseTuple(args, "dddi", &x, &y, &z, &i)) { try { SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh(); SMESHDS_Mesh* meshDS = mesh->GetMeshDS(); - SMDS_MeshNode* node = meshDS->AddNodeWithID(x,y,z,i); - if (!node) + SMDS_MeshNode* node = meshDS->AddNodeWithID(x, y, z, i); + if (!node) { throw std::runtime_error("Failed to add node"); + } return Py::new_reference_to(Py::Long(node->GetID())); } catch (const std::exception& e) { @@ -220,27 +233,30 @@ PyObject* FemMeshPy::addNode(PyObject *args) return nullptr; } } - PyErr_SetString(PyExc_TypeError, "addNode() accepts:\n" - "-- addNode(x,y,z)\n" - "-- addNode(x,y,z,ElemId)\n"); + PyErr_SetString(PyExc_TypeError, + "addNode() accepts:\n" + "-- addNode(x,y,z)\n" + "-- addNode(x,y,z,ElemId)\n"); return nullptr; } -PyObject* FemMeshPy::addEdge(PyObject *args) +PyObject* FemMeshPy::addEdge(PyObject* args) { SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh(); SMESHDS_Mesh* meshDS = mesh->GetMeshDS(); - int n1,n2; - if (PyArg_ParseTuple(args, "ii",&n1,&n2)) { + int n1, n2; + if (PyArg_ParseTuple(args, "ii", &n1, &n2)) { try { const SMDS_MeshNode* node1 = meshDS->FindNode(n1); const SMDS_MeshNode* node2 = meshDS->FindNode(n2); - if (!node1 || !node2) + if (!node1 || !node2) { throw std::runtime_error("Failed to get node of the given indices"); + } SMDS_MeshEdge* edge = meshDS->AddEdge(node1, node2); - if (!edge) + if (!edge) { throw std::runtime_error("Failed to add edge"); + } return Py::new_reference_to(Py::Long(edge->GetID())); } catch (const std::exception& e) { @@ -250,79 +266,87 @@ PyObject* FemMeshPy::addEdge(PyObject *args) } PyErr_Clear(); - PyObject *obj; - int ElementId=-1; - if (PyArg_ParseTuple(args, "O!|i", &PyList_Type, &obj, &ElementId)) - { + PyObject* obj; + int ElementId = -1; + if (PyArg_ParseTuple(args, "O!|i", &PyList_Type, &obj, &ElementId)) { Py::List list(obj); std::vector Nodes; for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { Py::Long NoNr(*it); const SMDS_MeshNode* node = meshDS->FindNode(NoNr); - if (!node) + if (!node) { throw std::runtime_error("Failed to get node of the given indices"); + } Nodes.push_back(node); } - SMDS_MeshEdge* edge=nullptr; - if(ElementId != -1) { - switch(Nodes.size()){ + SMDS_MeshEdge* edge = nullptr; + if (ElementId != -1) { + switch (Nodes.size()) { case 2: - edge = meshDS->AddEdgeWithID(Nodes[0],Nodes[1],ElementId); - if (!edge) + edge = meshDS->AddEdgeWithID(Nodes[0], Nodes[1], ElementId); + if (!edge) { throw std::runtime_error("Failed to add edge with given ElementId"); + } break; case 3: - edge = meshDS->AddEdgeWithID(Nodes[0],Nodes[1],Nodes[2],ElementId); - if (!edge) + edge = meshDS->AddEdgeWithID(Nodes[0], Nodes[1], Nodes[2], ElementId); + if (!edge) { throw std::runtime_error("Failed to add edge with given ElementId"); + } break; default: - throw std::runtime_error("Unknown node count, [2|3] are allowed"); //unknown edge type + throw std::runtime_error( + "Unknown node count, [2|3] are allowed"); // unknown edge type } } else { - switch(Nodes.size()){ - case 2: - edge = meshDS->AddEdge(Nodes[0],Nodes[1]); - if (!edge) - throw std::runtime_error("Failed to add edge"); - break; - case 3: - edge = meshDS->AddEdge(Nodes[0],Nodes[1],Nodes[2]); - if (!edge) - throw std::runtime_error("Failed to add edge"); - break; - default: - throw std::runtime_error("Unknown node count, [2|3] are allowed"); //unknown edge type + switch (Nodes.size()) { + case 2: + edge = meshDS->AddEdge(Nodes[0], Nodes[1]); + if (!edge) { + throw std::runtime_error("Failed to add edge"); + } + break; + case 3: + edge = meshDS->AddEdge(Nodes[0], Nodes[1], Nodes[2]); + if (!edge) { + throw std::runtime_error("Failed to add edge"); + } + break; + default: + throw std::runtime_error( + "Unknown node count, [2|3] are allowed"); // unknown edge type } } return Py::new_reference_to(Py::Long(edge->GetID())); } - PyErr_SetString(PyExc_TypeError, "addEdge accepts:\n" - "-- int,int\n" - "-- [2|3],[int]\n"); + PyErr_SetString(PyExc_TypeError, + "addEdge accepts:\n" + "-- int,int\n" + "-- [2|3],[int]\n"); return nullptr; } -PyObject* FemMeshPy::addFace(PyObject *args) +PyObject* FemMeshPy::addFace(PyObject* args) { SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh(); SMESHDS_Mesh* meshDS = mesh->GetMeshDS(); - int n1,n2,n3; - if (PyArg_ParseTuple(args, "iii",&n1,&n2,&n3)) - { + int n1, n2, n3; + if (PyArg_ParseTuple(args, "iii", &n1, &n2, &n3)) { // old form, deprecated try { const SMDS_MeshNode* node1 = meshDS->FindNode(n1); const SMDS_MeshNode* node2 = meshDS->FindNode(n2); const SMDS_MeshNode* node3 = meshDS->FindNode(n3); - if (!node1 || !node2 || !node3) + if (!node1 || !node2 || !node3) { throw std::runtime_error("Failed to get node of the given indices"); + } SMDS_MeshFace* face = meshDS->AddFace(node1, node2, node3); - if (!face) + if (!face) { throw std::runtime_error("Failed to add face"); + } return Py::new_reference_to(Py::Long(face->GetID())); } catch (const std::exception& e) { @@ -332,87 +356,122 @@ PyObject* FemMeshPy::addFace(PyObject *args) } PyErr_Clear(); - PyObject *obj; - int ElementId=-1; - if (PyArg_ParseTuple(args, "O!|i", &PyList_Type, &obj, &ElementId)) - { + PyObject* obj; + int ElementId = -1; + if (PyArg_ParseTuple(args, "O!|i", &PyList_Type, &obj, &ElementId)) { Py::List list(obj); std::vector Nodes; for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { Py::Long NoNr(*it); const SMDS_MeshNode* node = meshDS->FindNode(NoNr); - if (!node) + if (!node) { throw std::runtime_error("Failed to get node of the given indices"); + } Nodes.push_back(node); } - SMDS_MeshFace* face=nullptr; - if(ElementId != -1) { - switch(Nodes.size()){ + SMDS_MeshFace* face = nullptr; + if (ElementId != -1) { + switch (Nodes.size()) { case 3: - face = meshDS->AddFaceWithID(Nodes[0],Nodes[1],Nodes[2],ElementId); - if (!face) - throw std::runtime_error("Failed to add triangular face with given ElementId"); + face = meshDS->AddFaceWithID(Nodes[0], Nodes[1], Nodes[2], ElementId); + if (!face) { + throw std::runtime_error( + "Failed to add triangular face with given ElementId"); + } break; case 4: - face = meshDS->AddFaceWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],ElementId); - if (!face) + face = meshDS->AddFaceWithID(Nodes[0], Nodes[1], Nodes[2], Nodes[3], ElementId); + if (!face) { throw std::runtime_error("Failed to add face with given ElementId"); + } break; case 6: - face = meshDS->AddFaceWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],ElementId); - if (!face) + face = meshDS->AddFaceWithID(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + ElementId); + if (!face) { throw std::runtime_error("Failed to add face with given ElementId"); + } break; case 8: - face = meshDS->AddFaceWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],ElementId); - if (!face) + face = meshDS->AddFaceWithID(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7], + ElementId); + if (!face) { throw std::runtime_error("Failed to add face with given ElementId"); + } break; default: - throw std::runtime_error("Unknown node count, [3|4|6|8] are allowed"); //unknown face type + throw std::runtime_error( + "Unknown node count, [3|4|6|8] are allowed"); // unknown face type } - }else{ - switch(Nodes.size()){ + } + else { + switch (Nodes.size()) { case 3: - face = meshDS->AddFace(Nodes[0],Nodes[1],Nodes[2]); - if (!face) + face = meshDS->AddFace(Nodes[0], Nodes[1], Nodes[2]); + if (!face) { throw std::runtime_error("Failed to add triangular face"); + } break; case 4: - face = meshDS->AddFace(Nodes[0],Nodes[1],Nodes[2],Nodes[3]); - if (!face) + face = meshDS->AddFace(Nodes[0], Nodes[1], Nodes[2], Nodes[3]); + if (!face) { throw std::runtime_error("Failed to add face"); + } break; case 6: - face = meshDS->AddFace(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5]); - if (!face) + face = + meshDS->AddFace(Nodes[0], Nodes[1], Nodes[2], Nodes[3], Nodes[4], Nodes[5]); + if (!face) { throw std::runtime_error("Failed to add face"); + } break; case 8: - face = meshDS->AddFace(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7]); - if (!face) + face = meshDS->AddFace(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7]); + if (!face) { throw std::runtime_error("Failed to add face"); + } break; default: - throw std::runtime_error("Unknown node count, [4|5|6|8] are allowed"); //unknown face type + throw std::runtime_error( + "Unknown node count, [4|5|6|8] are allowed"); // unknown face type } } return Py::new_reference_to(Py::Long(face->GetID())); - } - PyErr_SetString(PyExc_TypeError, "addFace accepts:\n" - "-- int,int,int\n" - "-- [3|4|6|8 int],[int]\n"); + PyErr_SetString(PyExc_TypeError, + "addFace accepts:\n" + "-- int,int,int\n" + "-- [3|4|6|8 int],[int]\n"); return nullptr; } -PyObject* FemMeshPy::addQuad(PyObject *args) +PyObject* FemMeshPy::addQuad(PyObject* args) { - int n1,n2,n3,n4; - if (!PyArg_ParseTuple(args, "iiii",&n1,&n2,&n3,&n4)) + int n1, n2, n3, n4; + if (!PyArg_ParseTuple(args, "iiii", &n1, &n2, &n3, &n4)) { return nullptr; + } try { SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh(); @@ -421,11 +480,13 @@ PyObject* FemMeshPy::addQuad(PyObject *args) const SMDS_MeshNode* node2 = meshDS->FindNode(n2); const SMDS_MeshNode* node3 = meshDS->FindNode(n3); const SMDS_MeshNode* node4 = meshDS->FindNode(n4); - if (!node1 || !node2 || !node3 || !node4) + if (!node1 || !node2 || !node3 || !node4) { throw std::runtime_error("Failed to get node of the given indices"); + } SMDS_MeshFace* face = meshDS->AddFace(node1, node2, node3, node4); - if (!face) + if (!face) { throw std::runtime_error("Failed to add quad"); + } return Py::new_reference_to(Py::Long(face->GetID())); } catch (const std::exception& e) { @@ -434,24 +495,25 @@ PyObject* FemMeshPy::addQuad(PyObject *args) } } -PyObject* FemMeshPy::addVolume(PyObject *args) +PyObject* FemMeshPy::addVolume(PyObject* args) { SMESH_Mesh* mesh = getFemMeshPtr()->getSMesh(); SMESHDS_Mesh* meshDS = mesh->GetMeshDS(); - int n1,n2,n3,n4; - if (PyArg_ParseTuple(args, "iiii",&n1,&n2,&n3,&n4)) - { + int n1, n2, n3, n4; + if (PyArg_ParseTuple(args, "iiii", &n1, &n2, &n3, &n4)) { try { const SMDS_MeshNode* node1 = meshDS->FindNode(n1); const SMDS_MeshNode* node2 = meshDS->FindNode(n2); const SMDS_MeshNode* node3 = meshDS->FindNode(n3); const SMDS_MeshNode* node4 = meshDS->FindNode(n4); - if (!node1 || !node2 || !node3 || !node4) + if (!node1 || !node2 || !node3 || !node4) { throw std::runtime_error("Failed to get node of the given indices"); + } SMDS_MeshVolume* vol = meshDS->AddVolume(node1, node2, node3, node4); - if (!vol) + if (!vol) { throw std::runtime_error("Failed to add volume"); + } return Py::new_reference_to(Py::Long(vol->GetID())); } catch (const std::exception& e) { @@ -461,134 +523,307 @@ PyObject* FemMeshPy::addVolume(PyObject *args) } PyErr_Clear(); - PyObject *obj; - int ElementId=-1; - if (PyArg_ParseTuple(args, "O!|i", &PyList_Type, &obj, &ElementId)) - { + PyObject* obj; + int ElementId = -1; + if (PyArg_ParseTuple(args, "O!|i", &PyList_Type, &obj, &ElementId)) { Py::List list(obj); std::vector Nodes; for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { Py::Long NoNr(*it); const SMDS_MeshNode* node = meshDS->FindNode(NoNr); - if (!node) + if (!node) { throw std::runtime_error("Failed to get node of the given indices"); + } Nodes.push_back(node); } - SMDS_MeshVolume* vol=nullptr; - if(ElementId != -1) { - switch(Nodes.size()){ + SMDS_MeshVolume* vol = nullptr; + if (ElementId != -1) { + switch (Nodes.size()) { case 4: - vol = meshDS->AddVolumeWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],ElementId); - if (!vol) + vol = + meshDS->AddVolumeWithID(Nodes[0], Nodes[1], Nodes[2], Nodes[3], ElementId); + if (!vol) { throw std::runtime_error("Failed to add Tet4 volume with given ElementId"); + } break; case 5: - vol = meshDS->AddVolumeWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],ElementId); - if (!vol) + vol = meshDS->AddVolumeWithID(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + ElementId); + if (!vol) { throw std::runtime_error("Failed to add Pyra5 volume with given ElementId"); + } break; case 6: - vol = meshDS->AddVolumeWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],ElementId); - if (!vol) - throw std::runtime_error("Failed to add Penta6 volume with given ElementId"); + vol = meshDS->AddVolumeWithID(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + ElementId); + if (!vol) { + throw std::runtime_error( + "Failed to add Penta6 volume with given ElementId"); + } break; case 8: - vol = meshDS->AddVolumeWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],ElementId); - if (!vol) + vol = meshDS->AddVolumeWithID(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7], + ElementId); + if (!vol) { throw std::runtime_error("Failed to add Hexa8 volume with given ElementId"); + } break; case 10: - vol = meshDS->AddVolumeWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],Nodes[8],Nodes[9],ElementId); - if (!vol) + vol = meshDS->AddVolumeWithID(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7], + Nodes[8], + Nodes[9], + ElementId); + if (!vol) { throw std::runtime_error("Failed to add Tet10 volume with given ElementId"); + } break; case 13: - vol = meshDS->AddVolumeWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],Nodes[8],Nodes[9],Nodes[10],Nodes[11],Nodes[12],ElementId); - if (!vol) - throw std::runtime_error("Failed to add Pyra13 volume with given ElementId"); + vol = meshDS->AddVolumeWithID(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7], + Nodes[8], + Nodes[9], + Nodes[10], + Nodes[11], + Nodes[12], + ElementId); + if (!vol) { + throw std::runtime_error( + "Failed to add Pyra13 volume with given ElementId"); + } break; case 15: - vol = meshDS->AddVolumeWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],Nodes[8],Nodes[9],Nodes[10],Nodes[11],Nodes[12],Nodes[13],Nodes[14],ElementId); - if (!vol) - throw std::runtime_error("Failed to add Penta15 volume with given ElementId"); + vol = meshDS->AddVolumeWithID(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7], + Nodes[8], + Nodes[9], + Nodes[10], + Nodes[11], + Nodes[12], + Nodes[13], + Nodes[14], + ElementId); + if (!vol) { + throw std::runtime_error( + "Failed to add Penta15 volume with given ElementId"); + } break; case 20: - vol = meshDS->AddVolumeWithID(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],Nodes[8],Nodes[9],Nodes[10],Nodes[11],Nodes[12],Nodes[13],Nodes[14],Nodes[15],Nodes[16],Nodes[17],Nodes[18],Nodes[19],ElementId); - if (!vol) - throw std::runtime_error("Failed to add Hexa20 volume with given ElementId"); + vol = meshDS->AddVolumeWithID(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7], + Nodes[8], + Nodes[9], + Nodes[10], + Nodes[11], + Nodes[12], + Nodes[13], + Nodes[14], + Nodes[15], + Nodes[16], + Nodes[17], + Nodes[18], + Nodes[19], + ElementId); + if (!vol) { + throw std::runtime_error( + "Failed to add Hexa20 volume with given ElementId"); + } break; - default: throw std::runtime_error("Unknown node count, [4|5|6|8|10|13|15|20] are allowed"); //unknown volume type + default: + throw std::runtime_error( + "Unknown node count, [4|5|6|8|10|13|15|20] are allowed"); // unknown volume + // type } - }else{ - switch(Nodes.size()){ + } + else { + switch (Nodes.size()) { case 4: - vol = meshDS->AddVolume(Nodes[0],Nodes[1],Nodes[2],Nodes[3]); - if (!vol) + vol = meshDS->AddVolume(Nodes[0], Nodes[1], Nodes[2], Nodes[3]); + if (!vol) { throw std::runtime_error("Failed to add Tet4 volume"); + } break; case 5: - vol = meshDS->AddVolume(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4]); - if (!vol) + vol = meshDS->AddVolume(Nodes[0], Nodes[1], Nodes[2], Nodes[3], Nodes[4]); + if (!vol) { throw std::runtime_error("Failed to add Pyra5 volume"); + } break; case 6: - vol = meshDS->AddVolume(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5]); - if (!vol) + vol = meshDS->AddVolume(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5]); + if (!vol) { throw std::runtime_error("Failed to add Penta6 volume"); + } break; case 8: - vol = meshDS->AddVolume(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7]); - if (!vol) + vol = meshDS->AddVolume(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7]); + if (!vol) { throw std::runtime_error("Failed to add Hexa8 volume"); + } break; case 10: - vol = meshDS->AddVolume(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],Nodes[8],Nodes[9]); - if (!vol) + vol = meshDS->AddVolume(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7], + Nodes[8], + Nodes[9]); + if (!vol) { throw std::runtime_error("Failed to add Tet10 volume"); + } break; case 13: - vol = meshDS->AddVolume(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],Nodes[8],Nodes[9],Nodes[10],Nodes[11],Nodes[12]); - if (!vol) + vol = meshDS->AddVolume(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7], + Nodes[8], + Nodes[9], + Nodes[10], + Nodes[11], + Nodes[12]); + if (!vol) { throw std::runtime_error("Failed to add Pyra13 volume"); + } break; case 15: - vol = meshDS->AddVolume(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],Nodes[8],Nodes[9],Nodes[10],Nodes[11],Nodes[12],Nodes[13],Nodes[14]); - if (!vol) + vol = meshDS->AddVolume(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7], + Nodes[8], + Nodes[9], + Nodes[10], + Nodes[11], + Nodes[12], + Nodes[13], + Nodes[14]); + if (!vol) { throw std::runtime_error("Failed to add Penta15 volume"); + } break; case 20: - vol = meshDS->AddVolume(Nodes[0],Nodes[1],Nodes[2],Nodes[3],Nodes[4],Nodes[5],Nodes[6],Nodes[7],Nodes[8],Nodes[9],Nodes[10],Nodes[11],Nodes[12],Nodes[13],Nodes[14],Nodes[15],Nodes[16],Nodes[17],Nodes[18],Nodes[19]); - if (!vol) + vol = meshDS->AddVolume(Nodes[0], + Nodes[1], + Nodes[2], + Nodes[3], + Nodes[4], + Nodes[5], + Nodes[6], + Nodes[7], + Nodes[8], + Nodes[9], + Nodes[10], + Nodes[11], + Nodes[12], + Nodes[13], + Nodes[14], + Nodes[15], + Nodes[16], + Nodes[17], + Nodes[18], + Nodes[19]); + if (!vol) { throw std::runtime_error("Failed to add Hexa20 volume"); + } break; - default: throw std::runtime_error("Unknown node count, [4|5|6|8|10|13|15|20] are allowed"); //unknown volume type + default: + throw std::runtime_error( + "Unknown node count, [4|5|6|8|10|13|15|20] are allowed"); // unknown volume + // type } } return Py::new_reference_to(Py::Long(vol->GetID())); - } - PyErr_SetString(PyExc_TypeError, "addVolume accepts:\n" - "-- int,int,int,int\n" - "-- [4|5|6|8|10|13|15|20 int],[int]\n"); + PyErr_SetString(PyExc_TypeError, + "addVolume accepts:\n" + "-- int,int,int,int\n" + "-- [4|5|6|8|10|13|15|20 int],[int]\n"); return nullptr; } -PyObject* FemMeshPy::copy(PyObject *args) +PyObject* FemMeshPy::copy(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } const FemMesh& mesh = *getFemMeshPtr(); return new FemMeshPy(new FemMesh(mesh)); } -PyObject* FemMeshPy::read(PyObject *args) +PyObject* FemMeshPy::read(PyObject* args) { char* Name; - if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) + if (!PyArg_ParseTuple(args, "et", "utf-8", &Name)) { return nullptr; + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -602,11 +837,12 @@ PyObject* FemMeshPy::read(PyObject *args) Py_Return; } -PyObject* FemMeshPy::write(PyObject *args) +PyObject* FemMeshPy::write(PyObject* args) { char* Name; - if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) + if (!PyArg_ParseTuple(args, "et", "utf-8", &Name)) { return nullptr; + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -620,13 +856,14 @@ PyObject* FemMeshPy::write(PyObject *args) Py_Return; } -PyObject* FemMeshPy::writeABAQUS(PyObject *args) +PyObject* FemMeshPy::writeABAQUS(PyObject* args) { char* Name; int elemParam; PyObject* groupParam; - if (!PyArg_ParseTuple(args, "etiO!","utf-8",&Name,&elemParam,&PyBool_Type,&groupParam)) + if (!PyArg_ParseTuple(args, "etiO!", "utf-8", &Name, &elemParam, &PyBool_Type, &groupParam)) { return nullptr; + } std::string EncodedName = std::string(Name); PyMem_Free(Name); bool grpParam = Base::asBoolean(groupParam); @@ -641,11 +878,12 @@ PyObject* FemMeshPy::writeABAQUS(PyObject *args) Py_Return; } -PyObject* FemMeshPy::setTransform(PyObject *args) +PyObject* FemMeshPy::setTransform(PyObject* args) { PyObject* ptr; - if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &ptr)) + if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &ptr)) { return nullptr; + } Base::Placement* placement = static_cast(ptr)->getPlacementPtr(); Base::Matrix4D mat = placement->toMatrix(); @@ -654,14 +892,16 @@ PyObject* FemMeshPy::setTransform(PyObject *args) } -PyObject* FemMeshPy::getFacesByFace(PyObject *args) +PyObject* FemMeshPy::getFacesByFace(PyObject* args) { - PyObject *pW; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &pW)) - return nullptr; + PyObject* pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &pW)) { + return nullptr; + } try { - const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->getShape(); + const TopoDS_Shape& sh = + static_cast(pW)->getTopoShapePtr()->getShape(); if (sh.IsNull()) { PyErr_SetString(PyExc_ValueError, "Face is empty"); return nullptr; @@ -671,7 +911,7 @@ PyObject* FemMeshPy::getFacesByFace(PyObject *args) Py::List ret; std::list resultSet = getFemMeshPtr()->getFacesByFace(fc); - for (std::list::const_iterator it = resultSet.begin();it!=resultSet.end();++it) { + for (std::list::const_iterator it = resultSet.begin(); it != resultSet.end(); ++it) { ret.append(Py::Long(*it)); } @@ -684,14 +924,16 @@ PyObject* FemMeshPy::getFacesByFace(PyObject *args) } -PyObject* FemMeshPy::getEdgesByEdge(PyObject *args) +PyObject* FemMeshPy::getEdgesByEdge(PyObject* args) { - PyObject *pW; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeEdgePy::Type), &pW)) - return nullptr; + PyObject* pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeEdgePy::Type), &pW)) { + return nullptr; + } try { - const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->getShape(); + const TopoDS_Shape& sh = + static_cast(pW)->getTopoShapePtr()->getShape(); if (sh.IsNull()) { PyErr_SetString(PyExc_ValueError, "Edge is empty"); return nullptr; @@ -701,7 +943,7 @@ PyObject* FemMeshPy::getEdgesByEdge(PyObject *args) Py::List ret; std::list resultSet = getFemMeshPtr()->getEdgesByEdge(fc); - for (std::list::const_iterator it = resultSet.begin();it!=resultSet.end();++it) { + for (std::list::const_iterator it = resultSet.begin(); it != resultSet.end(); ++it) { ret.append(Py::Long(*it)); } @@ -713,14 +955,16 @@ PyObject* FemMeshPy::getEdgesByEdge(PyObject *args) } } -PyObject* FemMeshPy::getVolumesByFace(PyObject *args) +PyObject* FemMeshPy::getVolumesByFace(PyObject* args) { - PyObject *pW; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &pW)) - return nullptr; + PyObject* pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &pW)) { + return nullptr; + } try { - const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->getShape(); + const TopoDS_Shape& sh = + static_cast(pW)->getTopoShapePtr()->getShape(); if (sh.IsNull()) { PyErr_SetString(PyExc_ValueError, "Face is empty"); return nullptr; @@ -729,8 +973,10 @@ PyObject* FemMeshPy::getVolumesByFace(PyObject *args) const TopoDS_Face& fc = TopoDS::Face(sh); Py::List ret; - std::list > resultSet = getFemMeshPtr()->getVolumesByFace(fc); - for (std::list >::const_iterator it = resultSet.begin();it!=resultSet.end();++it) { + std::list> resultSet = getFemMeshPtr()->getVolumesByFace(fc); + for (std::list>::const_iterator it = resultSet.begin(); + it != resultSet.end(); + ++it) { Py::Tuple vol_face(2); vol_face.setItem(0, Py::Long(it->first)); vol_face.setItem(1, Py::Long(it->second)); @@ -745,14 +991,16 @@ PyObject* FemMeshPy::getVolumesByFace(PyObject *args) } } -PyObject* FemMeshPy::getccxVolumesByFace(PyObject *args) +PyObject* FemMeshPy::getccxVolumesByFace(PyObject* args) { - PyObject *pW; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &pW)) - return nullptr; + PyObject* pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &pW)) { + return nullptr; + } try { - const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->getShape(); + const TopoDS_Shape& sh = + static_cast(pW)->getTopoShapePtr()->getShape(); if (sh.IsNull()) { PyErr_SetString(PyExc_ValueError, "Face is empty"); return nullptr; @@ -762,7 +1010,8 @@ PyObject* FemMeshPy::getccxVolumesByFace(PyObject *args) Py::List ret; std::map resultSet = getFemMeshPtr()->getccxVolumesByFace(fc); - for (std::map::const_iterator it = resultSet.begin();it!=resultSet.end();++it) { + for (std::map::const_iterator it = resultSet.begin(); it != resultSet.end(); + ++it) { Py::Tuple vol_face(2); vol_face.setItem(0, Py::Long(it->first)); vol_face.setItem(1, Py::Long(it->second)); @@ -777,33 +1026,37 @@ PyObject* FemMeshPy::getccxVolumesByFace(PyObject *args) } } -PyObject* FemMeshPy::getNodeById(PyObject *args) +PyObject* FemMeshPy::getNodeById(PyObject* args) { int id; - if (!PyArg_ParseTuple(args, "i", &id)) + if (!PyArg_ParseTuple(args, "i", &id)) { return nullptr; + } Base::Matrix4D Mtrx = getFemMeshPtr()->getTransform(); const SMDS_MeshNode* aNode = getFemMeshPtr()->getSMesh()->GetMeshDS()->FindNode(id); - if(aNode){ - Base::Vector3d vec(aNode->X(),aNode->Y(),aNode->Z()); + if (aNode) { + Base::Vector3d vec(aNode->X(), aNode->Y(), aNode->Z()); vec = Mtrx * vec; - return new Base::VectorPy( vec ); - }else{ + return new Base::VectorPy(vec); + } + else { PyErr_SetString(PyExc_ValueError, "No valid node ID"); return nullptr; } } -PyObject* FemMeshPy::getNodesBySolid(PyObject *args) +PyObject* FemMeshPy::getNodesBySolid(PyObject* args) { - PyObject *pW; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeSolidPy::Type), &pW)) - return nullptr; + PyObject* pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeSolidPy::Type), &pW)) { + return nullptr; + } try { - const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->getShape(); + const TopoDS_Shape& sh = + static_cast(pW)->getTopoShapePtr()->getShape(); const TopoDS_Solid& fc = TopoDS::Solid(sh); if (sh.IsNull()) { PyErr_SetString(PyExc_ValueError, "Solid is empty"); @@ -811,11 +1064,11 @@ PyObject* FemMeshPy::getNodesBySolid(PyObject *args) } Py::List ret; std::set resultSet = getFemMeshPtr()->getNodesBySolid(fc); - for (int it : resultSet) + for (int it : resultSet) { ret.append(Py::Long(it)); + } return Py::new_reference_to(ret); - } catch (Standard_Failure& e) { PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString()); @@ -823,14 +1076,16 @@ PyObject* FemMeshPy::getNodesBySolid(PyObject *args) } } -PyObject* FemMeshPy::getNodesByFace(PyObject *args) +PyObject* FemMeshPy::getNodesByFace(PyObject* args) { - PyObject *pW; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &pW)) - return nullptr; + PyObject* pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &pW)) { + return nullptr; + } try { - const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->getShape(); + const TopoDS_Shape& sh = + static_cast(pW)->getTopoShapePtr()->getShape(); const TopoDS_Face& fc = TopoDS::Face(sh); if (sh.IsNull()) { PyErr_SetString(PyExc_ValueError, "Face is empty"); @@ -838,11 +1093,11 @@ PyObject* FemMeshPy::getNodesByFace(PyObject *args) } Py::List ret; std::set resultSet = getFemMeshPtr()->getNodesByFace(fc); - for (int it : resultSet) + for (int it : resultSet) { ret.append(Py::Long(it)); + } return Py::new_reference_to(ret); - } catch (Standard_Failure& e) { PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString()); @@ -850,14 +1105,16 @@ PyObject* FemMeshPy::getNodesByFace(PyObject *args) } } -PyObject* FemMeshPy::getNodesByEdge(PyObject *args) +PyObject* FemMeshPy::getNodesByEdge(PyObject* args) { - PyObject *pW; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeEdgePy::Type), &pW)) - return nullptr; + PyObject* pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeEdgePy::Type), &pW)) { + return nullptr; + } try { - const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->getShape(); + const TopoDS_Shape& sh = + static_cast(pW)->getTopoShapePtr()->getShape(); const TopoDS_Edge& fc = TopoDS::Edge(sh); if (sh.IsNull()) { PyErr_SetString(PyExc_ValueError, "Edge is empty"); @@ -865,11 +1122,11 @@ PyObject* FemMeshPy::getNodesByEdge(PyObject *args) } Py::List ret; std::set resultSet = getFemMeshPtr()->getNodesByEdge(fc); - for (int it : resultSet) + for (int it : resultSet) { ret.append(Py::Long(it)); + } return Py::new_reference_to(ret); - } catch (Standard_Failure& e) { PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString()); @@ -877,14 +1134,16 @@ PyObject* FemMeshPy::getNodesByEdge(PyObject *args) } } -PyObject* FemMeshPy::getNodesByVertex(PyObject *args) +PyObject* FemMeshPy::getNodesByVertex(PyObject* args) { - PyObject *pW; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeVertexPy::Type), &pW)) - return nullptr; + PyObject* pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeVertexPy::Type), &pW)) { + return nullptr; + } try { - const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->getShape(); + const TopoDS_Shape& sh = + static_cast(pW)->getTopoShapePtr()->getShape(); const TopoDS_Vertex& fc = TopoDS::Vertex(sh); if (sh.IsNull()) { PyErr_SetString(PyExc_ValueError, "Vertex is empty"); @@ -892,11 +1151,11 @@ PyObject* FemMeshPy::getNodesByVertex(PyObject *args) } Py::List ret; std::set resultSet = getFemMeshPtr()->getNodesByVertex(fc); - for (int it : resultSet) + for (int it : resultSet) { ret.append(Py::Long(it)); + } return Py::new_reference_to(ret); - } catch (Standard_Failure& e) { PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString()); @@ -904,18 +1163,20 @@ PyObject* FemMeshPy::getNodesByVertex(PyObject *args) } } -PyObject* FemMeshPy::getElementNodes(PyObject *args) +PyObject* FemMeshPy::getElementNodes(PyObject* args) { int id; - if (!PyArg_ParseTuple(args, "i", &id)) - return nullptr; + if (!PyArg_ParseTuple(args, "i", &id)) { + return nullptr; + } try { std::list resultSet = getFemMeshPtr()->getElementNodes(id); Py::Tuple ret(resultSet.size()); int index = 0; - for (std::list::const_iterator it = resultSet.begin();it!=resultSet.end();++it) + for (std::list::const_iterator it = resultSet.begin(); it != resultSet.end(); ++it) { ret.setItem(index++, Py::Long(*it)); + } return Py::new_reference_to(ret); } @@ -941,8 +1202,9 @@ PyObject* FemMeshPy::getNodeElements(PyObject* args) { int id; const char* typeStr = "All"; - if (!PyArg_ParseTuple(args, "i|s", &id, &typeStr)) + if (!PyArg_ParseTuple(args, "i|s", &id, &typeStr)) { return nullptr; + } auto it = std::find_if(vecTypeName.begin(), vecTypeName.end(), [=](const pairStrElemType& x) { return x.first == typeStr; @@ -964,11 +1226,12 @@ PyObject* FemMeshPy::getNodeElements(PyObject* args) return Py::new_reference_to(result); } -PyObject* FemMeshPy::getGroupName(PyObject *args) +PyObject* FemMeshPy::getGroupName(PyObject* args) { int id; - if (!PyArg_ParseTuple(args, "i", &id)) - return nullptr; + if (!PyArg_ParseTuple(args, "i", &id)) { + return nullptr; + } SMESH_Group* group = getFemMeshPtr()->getSMesh()->GetGroup(id); if (!group) { @@ -978,11 +1241,12 @@ PyObject* FemMeshPy::getGroupName(PyObject *args) return PyUnicode_FromString(group->GetName()); } -PyObject* FemMeshPy::getGroupElementType(PyObject *args) +PyObject* FemMeshPy::getGroupElementType(PyObject* args) { int id; - if (!PyArg_ParseTuple(args, "i", &id)) - return nullptr; + if (!PyArg_ParseTuple(args, "i", &id)) { + return nullptr; + } SMESH_Group* group = getFemMeshPtr()->getSMesh()->GetGroup(id); if (!group) { @@ -1000,11 +1264,12 @@ PyObject* FemMeshPy::getGroupElementType(PyObject *args) return PyUnicode_FromString(typeStr); } -PyObject* FemMeshPy::getGroupElements(PyObject *args) +PyObject* FemMeshPy::getGroupElements(PyObject* args) { int id; - if (!PyArg_ParseTuple(args, "i", &id)) - return nullptr; + if (!PyArg_ParseTuple(args, "i", &id)) { + return nullptr; + } SMESH_Group* group = getFemMeshPtr()->getSMesh()->GetGroup(id); if (!group) { @@ -1032,14 +1297,15 @@ PyObject* FemMeshPy::getGroupElements(PyObject *args) Add Groups and elements to these. */ -PyObject* FemMeshPy::addGroup(PyObject *args) +PyObject* FemMeshPy::addGroup(PyObject* args) { // get name and typestring from arguments char* Name; char* typeString; int theId = -1; - if (!PyArg_ParseTuple(args, "etet|i","utf-8", &Name, "utf-8", &typeString, &theId)) + if (!PyArg_ParseTuple(args, "etet|i", "utf-8", &Name, "utf-8", &typeString, &theId)) { return nullptr; + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -1048,30 +1314,30 @@ PyObject* FemMeshPy::addGroup(PyObject *args) int retId = -1; - try - { + try { retId = getFemMeshPtr()->addGroup(EncodedTypeString, EncodedName, theId); } catch (Standard_Failure& e) { PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString()); return nullptr; } - std::cout << "Added Group: Name: \'" << EncodedName << "\' Type: \'" << EncodedTypeString << "\' id: " << retId << std::endl; + std::cout << "Added Group: Name: \'" << EncodedName << "\' Type: \'" << EncodedTypeString + << "\' id: " << retId << std::endl; return PyLong_FromLong(retId); } -PyObject* FemMeshPy::addGroupElements(PyObject *args) +PyObject* FemMeshPy::addGroupElements(PyObject* args) { int id; // the second object should be a list - // see https://stackoverflow.com/questions/22458298/extending-python-with-c-pass-a-list-to-pyarg-parsetuple - PyObject *pList; - PyObject *pItem; + // see + // https://stackoverflow.com/questions/22458298/extending-python-with-c-pass-a-list-to-pyarg-parsetuple + PyObject* pList; + PyObject* pItem; Py_ssize_t n; - if (!PyArg_ParseTuple(args, "iO!", &id, &PyList_Type, &pList)) - { + if (!PyArg_ParseTuple(args, "iO!", &id, &PyList_Type, &pList)) { PyErr_SetString(PyExc_TypeError, "AddGroupElements: 2nd Parameter must be a list."); return nullptr; } @@ -1081,7 +1347,7 @@ PyObject* FemMeshPy::addGroupElements(PyObject *args) std::cout << "AddGroupElements: num elements: " << n << " sizeof: " << sizeof(n) << std::endl; for (Py_ssize_t i = 0; i < n; i++) { pItem = PyList_GetItem(pList, i); - if(!PyLong_Check(pItem)) { + if (!PyLong_Check(pItem)) { PyErr_SetString(PyExc_TypeError, "AddGroupElements: List items must be integers."); return nullptr; } @@ -1092,11 +1358,11 @@ PyObject* FemMeshPy::addGroupElements(PyObject *args) // Downcast Py_ssize_t to int to be compatible with SMESH functions std::set int_ids; - for (Py_ssize_t it : ids) + for (Py_ssize_t it : ids) { int_ids.insert(Py_SAFE_DOWNCAST(it, Py_ssize_t, int)); + } - try - { + try { getFemMeshPtr()->addGroupElements(id, int_ids); } catch (Standard_Failure& e) { @@ -1107,30 +1373,34 @@ PyObject* FemMeshPy::addGroupElements(PyObject *args) Py_Return; } -PyObject* FemMeshPy::removeGroup(PyObject *args) +PyObject* FemMeshPy::removeGroup(PyObject* args) { int theId; - if (!PyArg_ParseTuple(args, "i", &theId)) + if (!PyArg_ParseTuple(args, "i", &theId)) { return nullptr; + } return PyBool_FromLong((long)(getFemMeshPtr()->removeGroup(theId))); } -PyObject* FemMeshPy::getElementType(PyObject *args) +PyObject* FemMeshPy::getElementType(PyObject* args) { int id; - if (!PyArg_ParseTuple(args, "i", &id)) + if (!PyArg_ParseTuple(args, "i", &id)) { return nullptr; + } // An element ... SMDSAbs_ElementType elemType = getFemMeshPtr()->getSMesh()->GetElementType(id, true); // ... or a node - if (elemType == SMDSAbs_All) + if (elemType == SMDSAbs_All) { elemType = getFemMeshPtr()->getSMesh()->GetElementType(id, false); + } - auto it = std::find_if(vecTypeName.begin()+1, vecTypeName.end(), [=](const pairStrElemType& x) { - return x.second == elemType; - }); + auto it = + std::find_if(vecTypeName.begin() + 1, vecTypeName.end(), [=](const pairStrElemType& x) { + return x.second == elemType; + }); const char* typeStr = it != vecTypeName.end() ? it->first.c_str() : nullptr; if (!typeStr) { @@ -1141,11 +1411,12 @@ PyObject* FemMeshPy::getElementType(PyObject *args) return PyUnicode_FromString(typeStr); } -PyObject* FemMeshPy::getIdByElementType(PyObject *args) +PyObject* FemMeshPy::getIdByElementType(PyObject* args) { const char* typeStr; - if (!PyArg_ParseTuple(args, "s", &typeStr)) + if (!PyArg_ParseTuple(args, "s", &typeStr)) { return nullptr; + } auto it = std::find_if(vecTypeName.begin(), vecTypeName.end(), [=](const pairStrElemType& x) { return x.first == typeStr; @@ -1158,7 +1429,8 @@ PyObject* FemMeshPy::getIdByElementType(PyObject *args) SMDSAbs_ElementType elemType = it->second; std::set ids; - SMDS_ElemIteratorPtr aElemIter = getFemMeshPtr()->getSMesh()->GetMeshDS()->elementsIterator(elemType); + SMDS_ElemIteratorPtr aElemIter = + getFemMeshPtr()->getSMesh()->GetMeshDS()->elementsIterator(elemType); while (aElemIter->more()) { const SMDS_MeshElement* aElem = aElemIter->next(); ids.insert(aElem->GetID()); @@ -1177,22 +1449,22 @@ PyObject* FemMeshPy::getIdByElementType(PyObject *args) Py::Dict FemMeshPy::getNodes() const { - //int count = getFemMeshPtr()->getSMesh()->GetMeshDS()->NbNodes(); - //Py::Tuple tup(count); + // int count = getFemMeshPtr()->getSMesh()->GetMeshDS()->NbNodes(); + // Py::Tuple tup(count); Py::Dict dict; // get the actual transform of the FemMesh Base::Matrix4D Mtrx = getFemMeshPtr()->getTransform(); SMDS_NodeIteratorPtr aNodeIter = getFemMeshPtr()->getSMesh()->GetMeshDS()->nodesIterator(); - for (int i=0;aNodeIter->more();i++) { + for (int i = 0; aNodeIter->more(); i++) { const SMDS_MeshNode* aNode = aNodeIter->next(); - Base::Vector3d vec(aNode->X(),aNode->Y(),aNode->Z()); + Base::Vector3d vec(aNode->X(), aNode->Y(), aNode->Z()); // Apply the matrix to hold the BoundBox in absolute space. vec = Mtrx * vec; int id = aNode->GetID(); - dict[Py::Long(id)] = Py::asObject(new Base::VectorPy( vec )); + dict[Py::Long(id)] = Py::asObject(new Base::VectorPy(vec)); } return dict; @@ -1362,12 +1634,11 @@ Py::Tuple FemMeshPy::getGroups() const Py::Object FemMeshPy::getVolume() const { return Py::asObject(new Base::QuantityPy(new Base::Quantity(getFemMeshPtr()->getVolume()))); - } // ===== custom attributes ============================================================ -PyObject *FemMeshPy::getCustomAttributes(const char* /*attr*/) const +PyObject* FemMeshPy::getCustomAttributes(const char* /*attr*/) const { return nullptr; } diff --git a/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp b/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp index 73a7631c85..cc11e8f6d5 100644 --- a/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp +++ b/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp @@ -24,22 +24,22 @@ #include #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include -# ifdef FCWithNetgen -# include -# include -# endif +#ifdef FCWithNetgen +#include +#include +#endif #endif #include #include #include -#include "FemMeshShapeNetgenObject.h" #include "FemMesh.h" +#include "FemMeshShapeNetgenObject.h" using namespace Fem; @@ -47,49 +47,64 @@ using namespace App; PROPERTY_SOURCE(Fem::FemMeshShapeNetgenObject, Fem::FemMeshShapeObject) -const char* FinenessEnums[]= {"VeryCoarse","Coarse","Moderate","Fine","VeryFine","UserDefined",nullptr}; +const char* FinenessEnums[] = + {"VeryCoarse", "Coarse", "Moderate", "Fine", "VeryFine", "UserDefined", nullptr}; FemMeshShapeNetgenObject::FemMeshShapeNetgenObject() { - ADD_PROPERTY_TYPE(MaxSize,(1000), "MeshParams",Prop_None,"Maximum element size"); - ADD_PROPERTY_TYPE(SecondOrder,(true), "MeshParams",Prop_None,"Create quadric elements"); - ADD_PROPERTY_TYPE(Fineness,(2), "MeshParams",Prop_None,"Fineness level of the mesh"); + ADD_PROPERTY_TYPE(MaxSize, (1000), "MeshParams", Prop_None, "Maximum element size"); + ADD_PROPERTY_TYPE(SecondOrder, (true), "MeshParams", Prop_None, "Create quadric elements"); + ADD_PROPERTY_TYPE(Fineness, (2), "MeshParams", Prop_None, "Fineness level of the mesh"); Fineness.setEnums(FinenessEnums); - ADD_PROPERTY_TYPE(GrowthRate,(0.3), "MeshParams",Prop_None," allows to define how much the linear dimensions of two adjacent cells can differ"); - ADD_PROPERTY_TYPE(NbSegsPerEdge,(1), "MeshParams",Prop_None,"allows to define the minimum number of mesh segments in which edges will be split"); - ADD_PROPERTY_TYPE(NbSegsPerRadius,(2), "MeshParams",Prop_None,"allows to define the minimum number of mesh segments in which radiuses will be split"); - ADD_PROPERTY_TYPE(Optimize,(true), "MeshParams",Prop_None,"Optimize the resulting mesh"); - + ADD_PROPERTY_TYPE( + GrowthRate, + (0.3), + "MeshParams", + Prop_None, + " allows to define how much the linear dimensions of two adjacent cells can differ"); + ADD_PROPERTY_TYPE( + NbSegsPerEdge, + (1), + "MeshParams", + Prop_None, + "allows to define the minimum number of mesh segments in which edges will be split"); + ADD_PROPERTY_TYPE( + NbSegsPerRadius, + (2), + "MeshParams", + Prop_None, + "allows to define the minimum number of mesh segments in which radiuses will be split"); + ADD_PROPERTY_TYPE(Optimize, (true), "MeshParams", Prop_None, "Optimize the resulting mesh"); } FemMeshShapeNetgenObject::~FemMeshShapeNetgenObject() = default; -App::DocumentObjectExecReturn *FemMeshShapeNetgenObject::execute() +App::DocumentObjectExecReturn* FemMeshShapeNetgenObject::execute() { #ifdef FCWithNetgen Fem::FemMesh newMesh; - Part::Feature *feat = Shape.getValue(); + Part::Feature* feat = Shape.getValue(); TopoDS_Shape shape = feat->Shape.getValue(); - NETGENPlugin_Mesher myNetGenMesher(newMesh.getSMesh(),shape,true); + NETGENPlugin_Mesher myNetGenMesher(newMesh.getSMesh(), shape, true); #if SMESH_VERSION_MAJOR >= 9 - NETGENPlugin_Hypothesis* tet= new NETGENPlugin_Hypothesis(0,newMesh.getGenerator()); + NETGENPlugin_Hypothesis* tet = new NETGENPlugin_Hypothesis(0, newMesh.getGenerator()); #else - NETGENPlugin_Hypothesis* tet= new NETGENPlugin_Hypothesis(0,1,newMesh.getGenerator()); + NETGENPlugin_Hypothesis* tet = new NETGENPlugin_Hypothesis(0, 1, newMesh.getGenerator()); #endif tet->SetMaxSize(MaxSize.getValue()); tet->SetSecondOrder(SecondOrder.getValue()); tet->SetOptimize(Optimize.getValue()); int iFineness = Fineness.getValue(); tet->SetFineness((NETGENPlugin_Hypothesis::Fineness)iFineness); - if(iFineness == 5){ + if (iFineness == 5) { tet->SetGrowthRate(GrowthRate.getValue()); tet->SetNbSegPerEdge(NbSegsPerEdge.getValue()); tet->SetNbSegPerRadius(NbSegsPerRadius.getValue()); } - myNetGenMesher.SetParameters( tet); + myNetGenMesher.SetParameters(tet); newMesh.getSMesh()->ShapeToMesh(shape); myNetGenMesher.Compute(); @@ -100,40 +115,42 @@ App::DocumentObjectExecReturn *FemMeshShapeNetgenObject::execute() const SMDS_MeshInfo& info = data->GetMeshInfo(); int numFaces = data->NbFaces(); int numNode = info.NbNodes(); - //int numTria = info.NbTriangles(); - //int numQuad = info.NbQuadrangles(); - //int numPoly = info.NbPolygons(); + // int numTria = info.NbTriangles(); + // int numQuad = info.NbQuadrangles(); + // int numPoly = info.NbPolygons(); int numVolu = info.NbVolumes(); - //int numTetr = info.NbTetras(); - //int numHexa = info.NbHexas(); - //int numPyrd = info.NbPyramids(); - //int numPris = info.NbPrisms(); - //int numHedr = info.NbPolyhedrons(); + // int numTetr = info.NbTetras(); + // int numHexa = info.NbHexas(); + // int numPyrd = info.NbPyramids(); + // int numPris = info.NbPrisms(); + // int numHedr = info.NbPolyhedrons(); - Base::Console().Log("NetgenMesh: %i Nodes, %i Volumes, %i Faces\n",numNode,numVolu,numFaces); + Base::Console().Log("NetgenMesh: %i Nodes, %i Volumes, %i Faces\n", numNode, numVolu, numFaces); - FemMesh.setValue(newMesh); + FemMesh.setValue(newMesh); return App::DocumentObject::StdReturn; #else - return new App::DocumentObjectExecReturn("The FEM module is built without NETGEN support. Meshing will not work!!!", this); + return new App::DocumentObjectExecReturn( + "The FEM module is built without NETGEN support. Meshing will not work!!!", + this); #endif } -//short FemMeshShapeNetgenObject::mustExecute(void) const +// short FemMeshShapeNetgenObject::mustExecute(void) const //{ -// return 0; -//} +// return 0; +// } -//PyObject *FemMeshShapeNetgenObject::getPyObject() +// PyObject *FemMeshShapeNetgenObject::getPyObject() //{ -// if (PythonObject.is(Py::_None())){ -// // ref counter is set to 1 -// PythonObject = Py::Object(new DocumentObjectPy(this),true); -// } -// return Py::new_reference_to(PythonObject); -//} +// if (PythonObject.is(Py::_None())){ +// // ref counter is set to 1 +// PythonObject = Py::Object(new DocumentObjectPy(this),true); +// } +// return Py::new_reference_to(PythonObject); +// } -//void FemMeshShapeNetgenObject::onChanged(const Property* prop) +// void FemMeshShapeNetgenObject::onChanged(const Property* prop) //{ -// Fem::FemMeshShapeObject::onChanged(prop); -//} +// Fem::FemMeshShapeObject::onChanged(prop); +// } diff --git a/src/Mod/Fem/App/FemMeshShapeNetgenObject.h b/src/Mod/Fem/App/FemMeshShapeNetgenObject.h index 14666927d3..748cc868b1 100644 --- a/src/Mod/Fem/App/FemMeshShapeNetgenObject.h +++ b/src/Mod/Fem/App/FemMeshShapeNetgenObject.h @@ -23,13 +23,13 @@ #ifndef Fem_FemMeshShapeNetgenObject_H #define Fem_FemMeshShapeNetgenObject_H -#include #include "FemMeshShapeObject.h" +#include namespace Fem { -class FemExport FemMeshShapeNetgenObject : public FemMeshShapeObject +class FemExport FemMeshShapeNetgenObject: public FemMeshShapeObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemMeshShapeNetgenObject); @@ -38,31 +38,32 @@ public: FemMeshShapeNetgenObject(); ~FemMeshShapeNetgenObject() override; - App::PropertyFloat MaxSize; - App::PropertyBool SecondOrder; - App::PropertyEnumeration Fineness; - App::PropertyFloat GrowthRate; - App::PropertyInteger NbSegsPerEdge; - App::PropertyInteger NbSegsPerRadius; - App::PropertyBool Optimize; + App::PropertyFloat MaxSize; + App::PropertyBool SecondOrder; + App::PropertyEnumeration Fineness; + App::PropertyFloat GrowthRate; + App::PropertyInteger NbSegsPerEdge; + App::PropertyInteger NbSegsPerRadius; + App::PropertyBool Optimize; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemMeshShapeNetgen"; } - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; - //virtual short mustExecute(void) const; - //virtual PyObject *getPyObject(void); + // virtual short mustExecute(void) const; + // virtual PyObject *getPyObject(void); - //App::PropertyLink Shape; + // App::PropertyLink Shape; protected: /// get called by the container when a property has changed - //virtual void onChanged (const App::Property* prop); + // virtual void onChanged (const App::Property* prop); }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemMeshShapeNetgenObject_H +#endif // Fem_FemMeshShapeNetgenObject_H diff --git a/src/Mod/Fem/App/FemMeshShapeObject.cpp b/src/Mod/Fem/App/FemMeshShapeObject.cpp index 6d8f98c8a8..04d9f1e9d4 100644 --- a/src/Mod/Fem/App/FemMeshShapeObject.cpp +++ b/src/Mod/Fem/App/FemMeshShapeObject.cpp @@ -24,33 +24,33 @@ #include #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include #include -#include "FemMeshShapeObject.h" #include "FemMesh.h" +#include "FemMeshShapeObject.h" using namespace Fem; @@ -62,17 +62,20 @@ PROPERTY_SOURCE(Fem::FemMeshShapeObject, Fem::FemMeshObject) FemMeshShapeObject::FemMeshShapeObject() { ADD_PROPERTY_TYPE( - Shape, (nullptr), "FEM Mesh", Prop_None, + Shape, + (nullptr), + "FEM Mesh", + Prop_None, "Geometry object, the mesh is made from. The geometry object has to have a Shape."); } FemMeshShapeObject::~FemMeshShapeObject() = default; -App::DocumentObjectExecReturn *FemMeshShapeObject::execute() +App::DocumentObjectExecReturn* FemMeshShapeObject::execute() { Fem::FemMesh newMesh; - Part::Feature *feat = Shape.getValue(); + Part::Feature* feat = Shape.getValue(); #if 0 TopoDS_Shape oshape = feat->Shape.getValue(); @@ -84,9 +87,9 @@ App::DocumentObjectExecReturn *FemMeshShapeObject::execute() #endif newMesh.getSMesh()->ShapeToMesh(shape); - SMESH_Gen *myGen = newMesh.getGenerator(); + SMESH_Gen* myGen = newMesh.getGenerator(); - int hyp=0; + int hyp = 0; #if 0 SMESH_HypothesisPtr len(new StdMeshers_MaxLength(hyp++, 1, myGen)); static_cast(len.get())->SetLength(1.0); @@ -152,10 +155,10 @@ App::DocumentObjectExecReturn *FemMeshShapeObject::execute() SMESH_HypothesisPtr reg(new StdMeshers_Regular_1D(hyp++, myGen)); newMesh.addHypothesis(shape, reg); - SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++,myGen)); + SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++, myGen)); newMesh.addHypothesis(shape, qdp); - SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++,myGen)); + SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++, myGen)); newMesh.addHypothesis(shape, q2d); #else SMESH_HypothesisPtr len(new StdMeshers_MaxLength(hyp++, 1, myGen)); @@ -181,21 +184,21 @@ App::DocumentObjectExecReturn *FemMeshShapeObject::execute() SMESH_HypothesisPtr reg(new StdMeshers_Regular_1D(hyp++, 1, myGen)); newMesh.addHypothesis(shape, reg); - //SMESH_HypothesisPtr sel(new StdMeshers_StartEndLength(hyp++, 1, myGen)); - //static_cast(sel.get())->SetLength(1.0, true); - //newMesh.addHypothesis(shape, sel; + // SMESH_HypothesisPtr sel(new StdMeshers_StartEndLength(hyp++, 1, myGen)); + // static_cast(sel.get())->SetLength(1.0, true); + // newMesh.addHypothesis(shape, sel; - SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++,1,myGen)); + SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++, 1, myGen)); newMesh.addHypothesis(shape, qdp); - SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++,1,myGen)); + SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++, 1, myGen)); newMesh.addHypothesis(shape, q2d); #endif // create mesh newMesh.compute(); #endif -#if 0 // NETGEN test +#if 0 // NETGEN test NETGENPlugin_Mesher myNetGenMesher(newMesh.getSMesh(),shape,true); //NETGENPlugin_SimpleHypothesis_2D * tet2 = new NETGENPlugin_SimpleHypothesis_2D(hyp++,1,myGen); @@ -219,21 +222,21 @@ App::DocumentObjectExecReturn *FemMeshShapeObject::execute() return App::DocumentObject::StdReturn; } -//short FemMeshShapeObject::mustExecute(void) const +// short FemMeshShapeObject::mustExecute(void) const //{ -// return 0; -//} +// return 0; +// } -//PyObject *FemMeshShapeObject::getPyObject() +// PyObject *FemMeshShapeObject::getPyObject() //{ -// if (PythonObject.is(Py::_None())){ -// // ref counter is set to 1 -// PythonObject = Py::Object(new DocumentObjectPy(this),true); -// } -// return Py::new_reference_to(PythonObject); -//} +// if (PythonObject.is(Py::_None())){ +// // ref counter is set to 1 +// PythonObject = Py::Object(new DocumentObjectPy(this),true); +// } +// return Py::new_reference_to(PythonObject); +// } -//void FemMeshShapeObject::onChanged(const Property* prop) +// void FemMeshShapeObject::onChanged(const Property* prop) //{ -// App::GeoFeature::onChanged(prop); -//} +// App::GeoFeature::onChanged(prop); +// } diff --git a/src/Mod/Fem/App/FemMeshShapeObject.h b/src/Mod/Fem/App/FemMeshShapeObject.h index 7bd2c09f7d..13d20af526 100644 --- a/src/Mod/Fem/App/FemMeshShapeObject.h +++ b/src/Mod/Fem/App/FemMeshShapeObject.h @@ -29,7 +29,7 @@ namespace Fem { -class FemExport FemMeshShapeObject : public FemMeshObject +class FemExport FemMeshShapeObject: public FemMeshObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemMeshShapeObject); @@ -39,22 +39,23 @@ public: ~FemMeshShapeObject() override; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemMeshShape"; } - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; - //virtual short mustExecute(void) const; - //virtual PyObject *getPyObject(void); + // virtual short mustExecute(void) const; + // virtual PyObject *getPyObject(void); App::PropertyLink Shape; protected: /// get called by the container when a property has changed - //virtual void onChanged (const App::Property* prop); + // virtual void onChanged (const App::Property* prop); }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemMeshShapeObject_H +#endif // Fem_FemMeshShapeObject_H diff --git a/src/Mod/Fem/App/FemPostFilter.cpp b/src/Mod/Fem/App/FemPostFilter.cpp index aad66d32e0..ad3ea6a880 100644 --- a/src/Mod/Fem/App/FemPostFilter.cpp +++ b/src/Mod/Fem/App/FemPostFilter.cpp @@ -23,9 +23,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include #endif #include @@ -42,7 +42,7 @@ PROPERTY_SOURCE(Fem::FemPostFilter, Fem::FemPostObject) FemPostFilter::FemPostFilter() { - ADD_PROPERTY(Input,(nullptr)); + ADD_PROPERTY(Input, (nullptr)); } FemPostFilter::~FemPostFilter() = default; @@ -69,13 +69,14 @@ DocumentObjectExecReturn* FemPostFilter::execute() if (!m_pipelines.empty() && !m_activePipeline.empty()) { FemPostFilter::FilterPipeline& pipe = m_pipelines[m_activePipeline]; vtkSmartPointer data = getInputData(); - if (!data || !data->IsA("vtkDataSet")) + if (!data || !data->IsA("vtkDataSet")) { return StdReturn; + } if ((m_activePipeline == "DataAlongLine") || (m_activePipeline == "DataAtPoint")) { - pipe.filterSource->SetSourceData(getInputData()); - pipe.filterTarget->Update(); - Data.setValue(pipe.filterTarget->GetOutputDataObject(0)); + pipe.filterSource->SetSourceData(getInputData()); + pipe.filterTarget->Update(); + Data.setValue(pipe.filterTarget->GetOutputDataObject(0)); } else { pipe.source->SetInputDataObject(data); @@ -90,19 +91,23 @@ DocumentObjectExecReturn* FemPostFilter::execute() vtkDataObject* FemPostFilter::getInputData() { if (Input.getValue()) { - if (Input.getValue()->getTypeId().isDerivedFrom(Base::Type::fromName("Fem::FemPostObject"))) + if (Input.getValue()->getTypeId().isDerivedFrom( + Base::Type::fromName("Fem::FemPostObject"))) { return Input.getValue()->Data.getValue(); - else + } + else { throw std::runtime_error( "The filter's Input object is not a 'Fem::FemPostObject' object!"); + } } else { - //get the pipeline and use the pipelinedata + // get the pipeline and use the pipelinedata std::vector objs = getDocument()->getObjectsOfType(FemPostPipeline::getClassTypeId()); for (auto it : objs) { - if (static_cast(it)->holdsPostObject(this)) + if (static_cast(it)->holdsPostObject(this)) { return static_cast(it)->Data.getValue(); + } } } @@ -136,10 +141,16 @@ FemPostDataAlongLineFilter::FemPostDataAlongLineFilter() "DataAlongLine", App::Prop_None, "The number of intervals between the 2 end points of line"); - ADD_PROPERTY_TYPE( - XAxisData, (0), "DataAlongLine", App::Prop_None, "X axis data values used for plotting"); - ADD_PROPERTY_TYPE( - YAxisData, (0), "DataAlongLine", App::Prop_None, "Y axis data values used for plotting"); + ADD_PROPERTY_TYPE(XAxisData, + (0), + "DataAlongLine", + App::Prop_None, + "X axis data values used for plotting"); + ADD_PROPERTY_TYPE(YAxisData, + (0), + "DataAlongLine", + App::Prop_None, + "Y axis data values used for plotting"); ADD_PROPERTY_TYPE(PlotData, (""), "DataAlongLine", App::Prop_None, "Field used for plotting"); PlotData.setStatus(App::Property::ReadOnly, true); @@ -178,7 +189,7 @@ FemPostDataAlongLineFilter::~FemPostDataAlongLineFilter() = default; DocumentObjectExecReturn* FemPostDataAlongLineFilter::execute() { - //recalculate the filter + // recalculate the filter return Fem::FemPostFilter::execute(); } @@ -223,10 +234,12 @@ void FemPostDataAlongLineFilter::onChanged(const Property* prop) short int FemPostDataAlongLineFilter::mustExecute() const { - if (Point1.isTouched() || Point2.isTouched() || Resolution.isTouched()) + if (Point1.isTouched() || Point2.isTouched() || Resolution.isTouched()) { return 1; - else + } + else { return App::DocumentObject::mustExecute(); + } } void FemPostDataAlongLineFilter::GetAxisData() @@ -236,13 +249,15 @@ void FemPostDataAlongLineFilter::GetAxisData() vtkSmartPointer data = m_probe->GetOutputDataObject(0); vtkDataSet* dset = vtkDataSet::SafeDownCast(data); - if (!dset) + if (!dset) { return; + } vtkDataArray* pdata = dset->GetPointData()->GetArray(PlotData.getValue()); // VTK cannot deliver data when the filer relies e.g. on a scalar clip filter // whose value is set so that all data are clipped - if (!pdata) + if (!pdata) { return; + } vtkDataArray* tcoords = dset->GetPointData()->GetTCoords("Texture Coordinates"); vtkIdType component = 0; @@ -260,8 +275,9 @@ void FemPostDataAlongLineFilter::GetAxisData() value = pdata->GetComponent(i, component); } else { - for (vtkIdType j = 0; j < pdata->GetNumberOfComponents(); ++j) + for (vtkIdType j = 0; j < pdata->GetNumberOfComponents(); ++j) { value += std::pow(pdata->GetComponent(i, j), 2); + } value = std::sqrt(value); } @@ -288,8 +304,11 @@ FemPostDataAtPointFilter::FemPostDataAtPointFilter() "DataAtPoint", App::Prop_None, "Center of the point"); - ADD_PROPERTY_TYPE( - Radius, (0), "DataAtPoint", App::Prop_None, "Radius around the point (unused)"); + ADD_PROPERTY_TYPE(Radius, + (0), + "DataAtPoint", + App::Prop_None, + "Radius around the point (unused)"); ADD_PROPERTY_TYPE(PointData, (0), "DataAtPoint", App::Prop_None, "Point data values"); ADD_PROPERTY_TYPE(FieldName, (""), "DataAtPoint", App::Prop_None, "Field used for plotting"); ADD_PROPERTY_TYPE(Unit, (""), "DataAtPoint", App::Prop_None, "Unit used for the field"); @@ -327,7 +346,7 @@ FemPostDataAtPointFilter::~FemPostDataAtPointFilter() = default; DocumentObjectExecReturn* FemPostDataAtPointFilter::execute() { - //recalculate the filter + // recalculate the filter return Fem::FemPostFilter::execute(); } @@ -343,10 +362,12 @@ void FemPostDataAtPointFilter::onChanged(const Property* prop) short int FemPostDataAtPointFilter::mustExecute() const { - if (Center.isTouched()) + if (Center.isTouched()) { return 1; - else + } + else { return App::DocumentObject::mustExecute(); + } } void FemPostDataAtPointFilter::GetPointData() @@ -355,24 +376,28 @@ void FemPostDataAtPointFilter::GetPointData() vtkSmartPointer data = m_probe->GetOutputDataObject(0); vtkDataSet* dset = vtkDataSet::SafeDownCast(data); - if (!dset) + if (!dset) { return; + } vtkDataArray* pdata = dset->GetPointData()->GetArray(FieldName.getValue()); // VTK cannot deliver data when the filer relies e.g. on a scalar clip filter // whose value is set so that all data are clipped - if (!pdata) + if (!pdata) { return; + } int component = 0; for (int i = 0; i < dset->GetNumberOfPoints(); ++i) { double value = 0; - if (pdata->GetNumberOfComponents() == 1) + if (pdata->GetNumberOfComponents() == 1) { value = pdata->GetComponent(i, component); + } else { - for (int j = 0; j < pdata->GetNumberOfComponents(); ++j) + for (int j = 0; j < pdata->GetNumberOfComponents(); ++j) { value += std::pow(pdata->GetComponent(i, j), 2); + } value = std::sqrt(value); } @@ -439,10 +464,12 @@ void FemPostClipFilter::onChanged(const Property* prop) } else if (prop == &CutCells) { - if (!CutCells.getValue()) + if (!CutCells.getValue()) { setActiveFilterPipeline("extract"); - else + } + else { setActiveFilterPipeline("clip"); + } }; Fem::FemPostFilter::onChanged(prop); @@ -450,17 +477,20 @@ void FemPostClipFilter::onChanged(const Property* prop) short int FemPostClipFilter::mustExecute() const { - if (Function.isTouched() || InsideOut.isTouched() || CutCells.isTouched()) + if (Function.isTouched() || InsideOut.isTouched() || CutCells.isTouched()) { return 1; - else + } + else { return App::DocumentObject::mustExecute(); + } } DocumentObjectExecReturn* FemPostClipFilter::execute() { - if (!m_extractor->GetImplicitFunction()) + if (!m_extractor->GetImplicitFunction()) { return StdReturn; + } return Fem::FemPostFilter::execute(); } @@ -474,10 +504,16 @@ FemPostContoursFilter::FemPostContoursFilter() { ADD_PROPERTY_TYPE(NumberOfContours, (10), "Contours", App::Prop_None, "The number of contours"); ADD_PROPERTY_TYPE(Field, (long(0)), "Clip", App::Prop_None, "The field used to clip"); - ADD_PROPERTY_TYPE( - VectorMode, ((long)0), "Contours", App::Prop_None, "Select what vector field"); - ADD_PROPERTY_TYPE(NoColor, (false), "Contours", - PropertyType(Prop_Hidden), "Don't color the contours"); + ADD_PROPERTY_TYPE(VectorMode, + ((long)0), + "Contours", + App::Prop_None, + "Select what vector field"); + ADD_PROPERTY_TYPE(NoColor, + (false), + "Contours", + PropertyType(Prop_Hidden), + "Don't color the contours"); m_contourConstraints.LowerBound = 1; m_contourConstraints.UpperBound = 1000; @@ -509,23 +545,27 @@ DocumentObjectExecReturn* FemPostContoursFilter::execute() // delete contour field vtkSmartPointer data = getInputData(); vtkDataSet* dset = vtkDataSet::SafeDownCast(data); - if (!dset) + if (!dset) { return returnObject; + } dset->GetPointData()->RemoveArray(contourFieldName.c_str()); // refresh fields to reflect the deletion - if (!m_blockPropertyChanges) + if (!m_blockPropertyChanges) { refreshFields(); + } return returnObject; } void FemPostContoursFilter::onChanged(const Property* prop) { - if (m_blockPropertyChanges) + if (m_blockPropertyChanges) { return; + } - if (prop == &Field && (Field.getValue() >= 0)) + if (prop == &Field && (Field.getValue() >= 0)) { refreshVectors(); + } // note that we need to calculate also in case of a Data change // otherwise the contours output would be empty and the ViewProviderFemPostObject @@ -537,15 +577,20 @@ void FemPostContoursFilter::onChanged(const Property* prop) // get the field and its data vtkSmartPointer data = getInputData(); vtkDataSet* dset = vtkDataSet::SafeDownCast(data); - if (!dset) + if (!dset) { return; + } vtkDataArray* pdata = dset->GetPointData()->GetArray(Field.getValueAsString()); - if (!pdata) + if (!pdata) { return; + } if (pdata->GetNumberOfComponents() == 1) { // if we have a scalar, we can directly use the array - m_contours->SetInputArrayToProcess( - 0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, Field.getValueAsString()); + m_contours->SetInputArrayToProcess(0, + 0, + 0, + vtkDataObject::FIELD_ASSOCIATION_POINTS, + Field.getValueAsString()); pdata->GetRange(p); recalculateContours(p[0], p[1]); } @@ -555,12 +600,15 @@ void FemPostContoursFilter::onChanged(const Property* prop) // scalar array and append this temporarily to the data. (vtkExtractVectorComponents // does not work because our data is an unstructured data set.) int component = -1; - if (VectorMode.getValue() == 1) + if (VectorMode.getValue() == 1) { component = 0; - else if (VectorMode.getValue() == 2) + } + else if (VectorMode.getValue() == 2) { component = 1; - else if (VectorMode.getValue() == 3) + } + else if (VectorMode.getValue() == 3) { component = 2; + } // extract the component to a new array vtkSmartPointer componentArray = vtkSmartPointer::New(); componentArray->SetNumberOfComponents(1); @@ -569,8 +617,9 @@ void FemPostContoursFilter::onChanged(const Property* prop) if (component >= 0) { for (vtkIdType tupleIdx = 0; tupleIdx < numTuples; ++tupleIdx) { - componentArray->SetComponent( - tupleIdx, 0, pdata->GetComponent(tupleIdx, component)); + componentArray->SetComponent(tupleIdx, + 0, + pdata->GetComponent(tupleIdx, component)); } } else { @@ -590,8 +639,11 @@ void FemPostContoursFilter::onChanged(const Property* prop) // add the array as new field and use it for the contour filter dset->GetPointData()->AddArray(componentArray); - m_contours->SetInputArrayToProcess( - 0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, contourFieldName.c_str()); + m_contours->SetInputArrayToProcess(0, + 0, + 0, + vtkDataObject::FIELD_ASSOCIATION_POINTS, + contourFieldName.c_str()); componentArray->GetRange(p); recalculateContours(p[0], p[1]); if (prop == &Data) { @@ -610,10 +662,12 @@ void FemPostContoursFilter::onChanged(const Property* prop) short int FemPostContoursFilter::mustExecute() const { if (Field.isTouched() || VectorMode.isTouched() || NumberOfContours.isTouched() - || Data.isTouched()) + || Data.isTouched()) { return 1; - else + } + else { return App::DocumentObject::mustExecute(); + } } void FemPostContoursFilter::recalculateContours(double min, double max) @@ -630,8 +684,9 @@ void FemPostContoursFilter::refreshFields() m_blockPropertyChanges = true; std::string fieldName; - if (Field.getValue() >= 0) + if (Field.getValue() >= 0) { fieldName = Field.getValueAsString(); + } std::vector FieldsArray; @@ -688,12 +743,14 @@ void FemPostContoursFilter::refreshVectors() // store name if already set std::string vectorName; - if (VectorMode.hasEnums() && VectorMode.getValue() >= 0) + if (VectorMode.hasEnums() && VectorMode.getValue() >= 0) { vectorName = VectorMode.getValueAsString(); + } std::vector vectorArray; - if (fieldArray->GetNumberOfComponents() == 1) + if (fieldArray->GetNumberOfComponents() == 1) { vectorArray.emplace_back("Not a vector"); + } else { vectorArray.emplace_back("Magnitude"); if (fieldArray->GetNumberOfComponents() >= 2) { @@ -711,8 +768,9 @@ void FemPostContoursFilter::refreshVectors() // apply stored name auto it = std::find(vectorArray.begin(), vectorArray.end(), vectorName); - if (!vectorName.empty() && it != vectorArray.end()) + if (!vectorName.empty() && it != vectorArray.end()) { VectorMode.setValue(vectorName.c_str()); + } m_blockPropertyChanges = false; } @@ -756,16 +814,19 @@ void FemPostCutFilter::onChanged(const Property* prop) short int FemPostCutFilter::mustExecute() const { - if (Function.isTouched()) + if (Function.isTouched()) { return 1; - else + } + else { return App::DocumentObject::mustExecute(); + } } DocumentObjectExecReturn* FemPostCutFilter::execute() { - if (!m_cutter->GetCutFunction()) + if (!m_cutter->GetCutFunction()) { return StdReturn; + } return Fem::FemPostFilter::execute(); } @@ -775,17 +836,22 @@ DocumentObjectExecReturn* FemPostCutFilter::execute() // scalar clip filter PROPERTY_SOURCE(Fem::FemPostScalarClipFilter, Fem::FemPostFilter) -FemPostScalarClipFilter::FemPostScalarClipFilter() : FemPostFilter() { +FemPostScalarClipFilter::FemPostScalarClipFilter() + : FemPostFilter() +{ - ADD_PROPERTY_TYPE( - Value, (0), "Clip", App::Prop_None, "The scalar value used to clip the selected field"); + ADD_PROPERTY_TYPE(Value, + (0), + "Clip", + App::Prop_None, + "The scalar value used to clip the selected field"); ADD_PROPERTY_TYPE(Scalars, (long(0)), "Clip", App::Prop_None, "The field used to clip"); ADD_PROPERTY_TYPE(InsideOut, (false), "Clip", App::Prop_None, "Invert the clip direction"); Value.setConstraints(&m_constraints); FilterPipeline clip; - m_clipper = vtkSmartPointer::New(); + m_clipper = vtkSmartPointer::New(); clip.source = m_clipper; clip.target = m_clipper; addFilterPipeline(clip, "clip"); @@ -797,21 +863,24 @@ FemPostScalarClipFilter::~FemPostScalarClipFilter() = default; DocumentObjectExecReturn* FemPostScalarClipFilter::execute() { std::string val; - if (Scalars.getValue() >= 0) + if (Scalars.getValue() >= 0) { val = Scalars.getValueAsString(); + } std::vector ScalarsArray; vtkSmartPointer data = getInputData(); vtkDataSet* dset = vtkDataSet::SafeDownCast(data); - if (!dset) + if (!dset) { return StdReturn; + } vtkPointData* pd = dset->GetPointData(); // get all scalar fields for (int i = 0; i < pd->GetNumberOfArrays(); ++i) { - if (pd->GetArray(i)->GetNumberOfComponents() == 1) + if (pd->GetArray(i)->GetNumberOfComponents() == 1) { ScalarsArray.emplace_back(pd->GetArrayName(i)); + } } App::Enumeration empty; @@ -822,10 +891,11 @@ DocumentObjectExecReturn* FemPostScalarClipFilter::execute() // search if the current field is in the available ones and set it std::vector::iterator it = std::find(ScalarsArray.begin(), ScalarsArray.end(), val); - if (!val.empty() && it != ScalarsArray.end()) + if (!val.empty() && it != ScalarsArray.end()) { Scalars.setValue(val.c_str()); + } - //recalculate the filter + // recalculate the filter return Fem::FemPostFilter::execute(); } @@ -838,8 +908,11 @@ void FemPostScalarClipFilter::onChanged(const Property* prop) m_clipper->SetInsideOut(InsideOut.getValue()); } else if (prop == &Scalars && (Scalars.getValue() >= 0)) { - m_clipper->SetInputArrayToProcess(0, 0, 0, - vtkDataObject::FIELD_ASSOCIATION_POINTS, Scalars.getValueAsString()); + m_clipper->SetInputArrayToProcess(0, + 0, + 0, + vtkDataObject::FIELD_ASSOCIATION_POINTS, + Scalars.getValueAsString()); setConstraintForField(); } @@ -848,26 +921,28 @@ void FemPostScalarClipFilter::onChanged(const Property* prop) short int FemPostScalarClipFilter::mustExecute() const { - if (Value.isTouched() || - InsideOut.isTouched() || - Scalars.isTouched()) + if (Value.isTouched() || InsideOut.isTouched() || Scalars.isTouched()) { return 1; - else + } + else { return App::DocumentObject::mustExecute(); + } } void FemPostScalarClipFilter::setConstraintForField() { vtkSmartPointer data = getInputData(); vtkDataSet* dset = vtkDataSet::SafeDownCast(data); - if (!dset) + if (!dset) { return; + } vtkDataArray* pdata = dset->GetPointData()->GetArray(Scalars.getValueAsString()); // VTK cannot deliver data when the filer relies e.g. on a cut clip filter // whose value is set so that all data are cut - if (!pdata) + if (!pdata) { return; + } double p[2]; pdata->GetRange(p); m_constraints.LowerBound = p[0]; @@ -880,18 +955,22 @@ void FemPostScalarClipFilter::setConstraintForField() // warp vector filter PROPERTY_SOURCE(Fem::FemPostWarpVectorFilter, Fem::FemPostFilter) -FemPostWarpVectorFilter::FemPostWarpVectorFilter() : FemPostFilter() +FemPostWarpVectorFilter::FemPostWarpVectorFilter() + : FemPostFilter() { ADD_PROPERTY_TYPE(Factor, (0), "Warp", App::Prop_None, "The factor by which the vector is added to the node positions"); - ADD_PROPERTY_TYPE( - Vector, (long(0)), "Warp", App::Prop_None, "The field added to the node position"); + ADD_PROPERTY_TYPE(Vector, + (long(0)), + "Warp", + App::Prop_None, + "The field added to the node position"); FilterPipeline warp; - m_warp = vtkSmartPointer::New(); + m_warp = vtkSmartPointer::New(); warp.source = m_warp; warp.target = m_warp; addFilterPipeline(warp, "warp"); @@ -903,21 +982,24 @@ FemPostWarpVectorFilter::~FemPostWarpVectorFilter() = default; DocumentObjectExecReturn* FemPostWarpVectorFilter::execute() { std::string val; - if (Vector.getValue() >= 0) + if (Vector.getValue() >= 0) { val = Vector.getValueAsString(); + } std::vector VectorArray; vtkSmartPointer data = getInputData(); vtkDataSet* dset = vtkDataSet::SafeDownCast(data); - if (!dset) + if (!dset) { return StdReturn; + } vtkPointData* pd = dset->GetPointData(); // get all vector fields for (int i = 0; i < pd->GetNumberOfArrays(); ++i) { - if (pd->GetArray(i)->GetNumberOfComponents() == 3) + if (pd->GetArray(i)->GetNumberOfComponents() == 3) { VectorArray.emplace_back(pd->GetArrayName(i)); + } } App::Enumeration empty; @@ -926,31 +1008,38 @@ DocumentObjectExecReturn* FemPostWarpVectorFilter::execute() Vector.setValue(m_vectorFields); // search if the current field is in the available ones and set it - std::vector::iterator it = - std::find(VectorArray.begin(), VectorArray.end(), val); - if (!val.empty() && it != VectorArray.end()) + std::vector::iterator it = std::find(VectorArray.begin(), VectorArray.end(), val); + if (!val.empty() && it != VectorArray.end()) { Vector.setValue(val.c_str()); + } - //recalculate the filter + // recalculate the filter return Fem::FemPostFilter::execute(); } void FemPostWarpVectorFilter::onChanged(const Property* prop) { - if (prop == &Factor) + if (prop == &Factor) { // since our mesh is in mm, we must scale the factor m_warp->SetScaleFactor(1000 * Factor.getValue()); - else if (prop == &Vector && (Vector.getValue() >= 0)) - m_warp->SetInputArrayToProcess(0, 0, 0, - vtkDataObject::FIELD_ASSOCIATION_POINTS, Vector.getValueAsString()); + } + else if (prop == &Vector && (Vector.getValue() >= 0)) { + m_warp->SetInputArrayToProcess(0, + 0, + 0, + vtkDataObject::FIELD_ASSOCIATION_POINTS, + Vector.getValueAsString()); + } Fem::FemPostFilter::onChanged(prop); } short int FemPostWarpVectorFilter::mustExecute() const { - if (Factor.isTouched() || Vector.isTouched()) + if (Factor.isTouched() || Vector.isTouched()) { return 1; - else + } + else { return App::DocumentObject::mustExecute(); + } } diff --git a/src/Mod/Fem/App/FemPostFilter.h b/src/Mod/Fem/App/FemPostFilter.h index a00edb7d9b..b4a292bf31 100644 --- a/src/Mod/Fem/App/FemPostFilter.h +++ b/src/Mod/Fem/App/FemPostFilter.h @@ -28,11 +28,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include @@ -43,7 +43,7 @@ namespace Fem { -class FemExport FemPostFilter : public Fem::FemPostObject +class FemExport FemPostFilter: public Fem::FemPostObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostFilter); @@ -59,18 +59,20 @@ public: protected: vtkDataObject* getInputData(); - //pipeline handling for derived filter - struct FilterPipeline { - vtkSmartPointer source, target; - vtkSmartPointer filterSource, filterTarget; - std::vector > algorithmStorage; + // pipeline handling for derived filter + struct FilterPipeline + { + vtkSmartPointer source, target; + vtkSmartPointer filterSource, filterTarget; + std::vector> algorithmStorage; }; void addFilterPipeline(const FilterPipeline& p, std::string name); void setActiveFilterPipeline(std::string name); FilterPipeline& getFilterPipeline(std::string name); + private: - //handling of multiple pipelines which can be the filter + // handling of multiple pipelines which can be the filter std::map m_pipelines; std::string m_activePipeline; }; @@ -93,14 +95,14 @@ public: App::PropertyVectorDistance Point1; App::PropertyVectorDistance Point2; - App::PropertyInteger Resolution; - App::PropertyFloatList XAxisData; - App::PropertyFloatList YAxisData; - App::PropertyString PlotData; + App::PropertyInteger Resolution; + App::PropertyFloatList XAxisData; + App::PropertyFloatList YAxisData; + App::PropertyString PlotData; const char* getViewProviderName() const override { - return "FemGui::ViewProviderFemPostDataAlongLine"; + return "FemGui::ViewProviderFemPostDataAlongLine"; } short int mustExecute() const override; void GetAxisData(); @@ -108,7 +110,8 @@ public: protected: App::DocumentObjectExecReturn* execute() override; void onChanged(const App::Property* prop) override; - void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, + void handleChangedPropertyType(Base::XMLReader& reader, + const char* TypeName, App::Property* prop) override; private: @@ -128,15 +131,15 @@ public: FemPostDataAtPointFilter(); ~FemPostDataAtPointFilter() override; - App::PropertyVectorDistance Center; - App::PropertyDistance Radius; - App::PropertyString FieldName; - App::PropertyFloatList PointData; - App::PropertyString Unit; + App::PropertyVectorDistance Center; + App::PropertyDistance Radius; + App::PropertyString FieldName; + App::PropertyFloatList PointData; + App::PropertyString Unit; const char* getViewProviderName() const override { - return "FemGui::ViewProviderFemPostDataAtPoint"; + return "FemGui::ViewProviderFemPostDataAtPoint"; } short int mustExecute() const override; @@ -168,7 +171,7 @@ public: const char* getViewProviderName() const override { - return "FemGui::ViewProviderFemPostClip"; + return "FemGui::ViewProviderFemPostClip"; } short int mustExecute() const override; App::DocumentObjectExecReturn* execute() override; @@ -286,7 +289,8 @@ private: // *************************************************************************** // warp vector filter -class FemExport FemPostWarpVectorFilter : public FemPostFilter { +class FemExport FemPostWarpVectorFilter: public FemPostFilter +{ PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostWarpVectorFilter); @@ -294,10 +298,11 @@ public: FemPostWarpVectorFilter(); ~FemPostWarpVectorFilter() override; - App::PropertyFloat Factor; - App::PropertyEnumeration Vector; + App::PropertyFloat Factor; + App::PropertyEnumeration Vector; - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemPostWarpVector"; } short int mustExecute() const override; @@ -307,11 +312,11 @@ protected: void onChanged(const App::Property* prop) override; private: - vtkSmartPointer m_warp; - App::Enumeration m_vectorFields; + vtkSmartPointer m_warp; + App::Enumeration m_vectorFields; }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemPostFilter_H +#endif // Fem_FemPostFilter_H diff --git a/src/Mod/Fem/App/FemPostFunction.cpp b/src/Mod/Fem/App/FemPostFunction.cpp index 5330c738c2..0b41eb95d8 100644 --- a/src/Mod/Fem/App/FemPostFunction.cpp +++ b/src/Mod/Fem/App/FemPostFunction.cpp @@ -30,14 +30,17 @@ using namespace App; PROPERTY_SOURCE(Fem::FemPostFunctionProvider, App::DocumentObject) -FemPostFunctionProvider::FemPostFunctionProvider() : DocumentObject() { +FemPostFunctionProvider::FemPostFunctionProvider() + : DocumentObject() +{ ADD_PROPERTY(Functions, (nullptr)); } FemPostFunctionProvider::~FemPostFunctionProvider() = default; -void FemPostFunctionProvider::onChanged(const Property* prop) { +void FemPostFunctionProvider::onChanged(const Property* prop) +{ App::DocumentObject::onChanged(prop); } @@ -48,7 +51,8 @@ FemPostFunction::FemPostFunction() = default; FemPostFunction::~FemPostFunction() = default; -DocumentObjectExecReturn* FemPostFunction::execute() { +DocumentObjectExecReturn* FemPostFunction::execute() +{ return DocumentObject::StdReturn; } @@ -80,10 +84,12 @@ void FemPostBoxFunction::onChanged(const Property* prop) float l = Length.getValue(); float w = Width.getValue(); float h = Height.getValue(); - m_box->SetBounds( - vec[0] - l/2, vec[0] + l/2, - vec[1] - w/2, vec[1] + w/2, - vec[2] - h/2, vec[2] + h/2); + m_box->SetBounds(vec[0] - l / 2, + vec[0] + l / 2, + vec[1] - w / 2, + vec[1] + w / 2, + vec[2] - h / 2, + vec[2] + h / 2); } Fem::FemPostFunction::onChanged(prop); @@ -145,7 +151,9 @@ void FemPostCylinderFunction::onDocumentRestored() // plane function PROPERTY_SOURCE(Fem::FemPostPlaneFunction, Fem::FemPostFunction) -FemPostPlaneFunction::FemPostPlaneFunction() : FemPostFunction() { +FemPostPlaneFunction::FemPostPlaneFunction() + : FemPostFunction() +{ ADD_PROPERTY(Origin, (Base::Vector3d(0.0, 0.0, 0.0))); ADD_PROPERTY(Normal, (Base::Vector3d(0.0, 0.0, 1.0))); @@ -159,7 +167,8 @@ FemPostPlaneFunction::FemPostPlaneFunction() : FemPostFunction() { FemPostPlaneFunction::~FemPostPlaneFunction() = default; -void FemPostPlaneFunction::onChanged(const Property* prop) { +void FemPostPlaneFunction::onChanged(const Property* prop) +{ if (prop == &Origin) { const Base::Vector3d& vec = Origin.getValue(); @@ -173,7 +182,8 @@ void FemPostPlaneFunction::onChanged(const Property* prop) { Fem::FemPostFunction::onChanged(prop); } -void FemPostPlaneFunction::onDocumentRestored() { +void FemPostPlaneFunction::onDocumentRestored() +{ // This is to notify the view provider that the document has been fully restored Normal.touch(); } @@ -183,7 +193,9 @@ void FemPostPlaneFunction::onDocumentRestored() { // sphere function PROPERTY_SOURCE(Fem::FemPostSphereFunction, Fem::FemPostFunction) -FemPostSphereFunction::FemPostSphereFunction() : FemPostFunction() { +FemPostSphereFunction::FemPostSphereFunction() + : FemPostFunction() +{ ADD_PROPERTY(Radius, (5.0)); ADD_PROPERTY(Center, (Base::Vector3d(1.0, 0.0, 0.0))); @@ -197,7 +209,8 @@ FemPostSphereFunction::FemPostSphereFunction() : FemPostFunction() { FemPostSphereFunction::~FemPostSphereFunction() = default; -void FemPostSphereFunction::onChanged(const Property* prop) { +void FemPostSphereFunction::onChanged(const Property* prop) +{ if (prop == &Center) { const Base::Vector3d& vec = Center.getValue(); diff --git a/src/Mod/Fem/App/FemPostFunction.h b/src/Mod/Fem/App/FemPostFunction.h index f5d12cea01..e8885d9369 100644 --- a/src/Mod/Fem/App/FemPostFunction.h +++ b/src/Mod/Fem/App/FemPostFunction.h @@ -39,7 +39,7 @@ namespace Fem { -class FemExport FemPostFunction : public App::DocumentObject +class FemExport FemPostFunction: public App::DocumentObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostFunction); @@ -48,24 +48,32 @@ public: FemPostFunction(); ~FemPostFunction() override; - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemPostFunction"; } App::DocumentObjectExecReturn* execute() override; - //bound box handling - void setBoundingBox(vtkBoundingBox b) {m_boundingBox = b;}; + // bound box handling + void setBoundingBox(vtkBoundingBox b) + { + m_boundingBox = b; + }; - //get the algorithm or the data - vtkSmartPointer getImplicitFunction() {return m_implicit;}; + // get the algorithm or the data + vtkSmartPointer getImplicitFunction() + { + return m_implicit; + }; protected: - vtkSmartPointer m_implicit; - vtkBoundingBox m_boundingBox; + vtkSmartPointer m_implicit; + vtkBoundingBox m_boundingBox; }; -class FemExport FemPostFunctionProvider : public App::DocumentObject { +class FemExport FemPostFunctionProvider: public App::DocumentObject +{ PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostFunctionProvider); @@ -73,7 +81,8 @@ public: FemPostFunctionProvider(); ~FemPostFunctionProvider() override; - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemPostFunctionProvider"; } @@ -85,21 +94,21 @@ protected: // --------------------------------------------------------------------------- -class FemExport FemPostBoxFunction : public FemPostFunction +class FemExport FemPostBoxFunction: public FemPostFunction { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostBoxFunction); public: - FemPostBoxFunction(); ~FemPostBoxFunction() override; - App::PropertyVectorDistance Center; - App::PropertyDistance Length; - App::PropertyDistance Width; - App::PropertyDistance Height; + App::PropertyVectorDistance Center; + App::PropertyDistance Length; + App::PropertyDistance Width; + App::PropertyDistance Height; - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemPostBoxFunction"; } @@ -113,20 +122,20 @@ protected: // --------------------------------------------------------------------------- -class FemExport FemPostCylinderFunction : public FemPostFunction +class FemExport FemPostCylinderFunction: public FemPostFunction { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostCylinderFunction); public: - FemPostCylinderFunction(); ~FemPostCylinderFunction() override; - App::PropertyVector Axis; - App::PropertyVectorDistance Center; - App::PropertyDistance Radius; + App::PropertyVector Axis; + App::PropertyVectorDistance Center; + App::PropertyDistance Radius; - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemPostCylinderFunction"; } @@ -140,19 +149,19 @@ protected: // --------------------------------------------------------------------------- -class FemExport FemPostPlaneFunction : public FemPostFunction +class FemExport FemPostPlaneFunction: public FemPostFunction { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostPlaneFunction); public: - FemPostPlaneFunction(); ~FemPostPlaneFunction() override; - App::PropertyVector Normal; - App::PropertyVectorDistance Origin; + App::PropertyVector Normal; + App::PropertyVectorDistance Origin; - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemPostPlaneFunction"; } @@ -166,19 +175,19 @@ protected: // --------------------------------------------------------------------------- -class FemExport FemPostSphereFunction : public FemPostFunction +class FemExport FemPostSphereFunction: public FemPostFunction { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostSphereFunction); public: - FemPostSphereFunction(); ~FemPostSphereFunction() override; - App::PropertyDistance Radius; - App::PropertyVectorDistance Center; + App::PropertyDistance Radius; + App::PropertyVectorDistance Center; - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemPostSphereFunction"; } @@ -188,7 +197,7 @@ protected: vtkSmartPointer m_sphere; }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemPostFunction_H +#endif // Fem_FemPostFunction_H diff --git a/src/Mod/Fem/App/FemPostObject.cpp b/src/Mod/Fem/App/FemPostObject.cpp index 3be1a3f154..afb7ff4953 100644 --- a/src/Mod/Fem/App/FemPostObject.cpp +++ b/src/Mod/Fem/App/FemPostObject.cpp @@ -23,7 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include "FemPostObject.h" @@ -42,13 +42,15 @@ FemPostObject::FemPostObject() FemPostObject::~FemPostObject() = default; -vtkBoundingBox FemPostObject::getBoundingBox() { +vtkBoundingBox FemPostObject::getBoundingBox() +{ vtkBoundingBox box; vtkDataSet* dset = vtkDataSet::SafeDownCast(Data.getValue()); - if (dset) + if (dset) { box.AddBounds(dset->GetBounds()); + } // TODO: add calculation of multiblock and Multipiece datasets diff --git a/src/Mod/Fem/App/FemPostObject.h b/src/Mod/Fem/App/FemPostObject.h index f7c00c4a83..4f0c840436 100644 --- a/src/Mod/Fem/App/FemPostObject.h +++ b/src/Mod/Fem/App/FemPostObject.h @@ -24,8 +24,8 @@ #ifndef Fem_FemPostObject_H #define Fem_FemPostObject_H -#include #include "PropertyPostDataObject.h" +#include #include @@ -34,7 +34,7 @@ namespace Fem // poly data is the only data we can visualize, hence every post // processing object needs to expose it -class FemExport FemPostObject : public App::GeoFeature +class FemExport FemPostObject: public App::GeoFeature { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostObject); @@ -48,7 +48,7 @@ public: vtkBoundingBox getBoundingBox(); }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemPostObject_H +#endif // Fem_FemPostObject_H diff --git a/src/Mod/Fem/App/FemPostPipeline.cpp b/src/Mod/Fem/App/FemPostPipeline.cpp index 16e1d43423..53ac2721ae 100644 --- a/src/Mod/Fem/App/FemPostPipeline.cpp +++ b/src/Mod/Fem/App/FemPostPipeline.cpp @@ -23,27 +23,27 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include -#include "FemPostPipeline.h" -#include "FemPostPipelinePy.h" #include "FemMesh.h" #include "FemMeshObject.h" +#include "FemPostPipeline.h" +#include "FemPostPipelinePy.h" #include "FemVTKTools.h" @@ -51,12 +51,15 @@ using namespace Fem; using namespace App; PROPERTY_SOURCE(Fem::FemPostPipeline, Fem::FemPostObject) -const char* FemPostPipeline::ModeEnums[] = { "Serial", "Parallel", "Custom", nullptr }; +const char* FemPostPipeline::ModeEnums[] = {"Serial", "Parallel", "Custom", nullptr}; FemPostPipeline::FemPostPipeline() { - ADD_PROPERTY_TYPE( - Filter, (nullptr), "Pipeline", App::Prop_None, "The filter used in this pipeline"); + ADD_PROPERTY_TYPE(Filter, + (nullptr), + "Pipeline", + App::Prop_None, + "The filter used in this pipeline"); ADD_PROPERTY_TYPE(Functions, (nullptr), "Pipeline", @@ -77,25 +80,28 @@ FemPostPipeline::~FemPostPipeline() = default; short FemPostPipeline::mustExecute() const { - if (Mode.isTouched()) + if (Mode.isTouched()) { return 1; + } return FemPostFilter::mustExecute(); } -DocumentObjectExecReturn* FemPostPipeline::execute() { +DocumentObjectExecReturn* FemPostPipeline::execute() +{ // if we are the toplevel pipeline our data object is not created by filters, // we are the main source - if (!Input.getValue()) + if (!Input.getValue()) { return StdReturn; + } // now if we are a filter than our data object is created by the filter we hold // if we are in serial mode we just copy over the data of the last filter, // but if we are in parallel we need to combine all filter results if (Mode.getValue() == 0) { - //serial + // serial Data.setValue(getLastPostObject()->Data.getValue()); } else if (Mode.getValue() == 1) { @@ -117,34 +123,45 @@ DocumentObjectExecReturn* FemPostPipeline::execute() { } -bool FemPostPipeline::canRead(Base::FileInfo File) { +bool FemPostPipeline::canRead(Base::FileInfo File) +{ // from FemResult only unstructural mesh is supported in femvtktoools.cpp return File.hasExtension({"vtk", "vtp", "vts", "vtr", "vti", "vtu", "pvtu"}); } -void FemPostPipeline::read(Base::FileInfo File) { +void FemPostPipeline::read(Base::FileInfo File) +{ // checking on the file - if (!File.isReadable()) + if (!File.isReadable()) { throw Base::FileException("File to load not existing or not readable", File); + } - if (File.hasExtension("vtu")) + if (File.hasExtension("vtu")) { readXMLFile(File.filePath()); - else if (File.hasExtension("pvtu")) + } + else if (File.hasExtension("pvtu")) { readXMLFile(File.filePath()); - else if (File.hasExtension("vtp")) + } + else if (File.hasExtension("vtp")) { readXMLFile(File.filePath()); - else if (File.hasExtension("vts")) + } + else if (File.hasExtension("vts")) { readXMLFile(File.filePath()); - else if (File.hasExtension("vtr")) + } + else if (File.hasExtension("vtr")) { readXMLFile(File.filePath()); - else if (File.hasExtension("vti")) + } + else if (File.hasExtension("vti")) { readXMLFile(File.filePath()); - else if (File.hasExtension("vtk")) + } + else if (File.hasExtension("vtk")) { readXMLFile(File.filePath()); - else + } + else { throw Base::FileException("Unknown extension"); + } } void FemPostPipeline::scale(double s) @@ -158,14 +175,16 @@ void FemPostPipeline::onChanged(const Property* prop) // if we are in custom mode the user is free to set the input // thus nothing needs to be done here - if (Mode.getValue() == 2) // custom + if (Mode.getValue() == 2) { // custom return; + } // we check if all connections are right and add new ones if needed std::vector objs = Filter.getValues(); - if (objs.empty()) + if (objs.empty()) { return; + } std::vector::iterator it = objs.begin(); FemPostFilter* filter = static_cast(*it); @@ -174,8 +193,9 @@ void FemPostPipeline::onChanged(const Property* prop) if (Input.getValue()) { // the first filter is always connected to the input - if (filter->Input.getValue() != Input.getValue()) + if (filter->Input.getValue() != Input.getValue()) { filter->Input.setValue(Input.getValue()); + } // all the others need to be connected to the previous filter or the source, // dependent on the mode @@ -183,13 +203,15 @@ void FemPostPipeline::onChanged(const Property* prop) for (; it != objs.end(); ++it) { FemPostFilter* nextFilter = static_cast(*it); - if (Mode.getValue() == 0) { //serial mode - if (nextFilter->Input.getValue() != filter) + if (Mode.getValue() == 0) { // serial mode + if (nextFilter->Input.getValue() != filter) { nextFilter->Input.setValue(filter); + } } - else { //Parallel mode - if (nextFilter->Input.getValue() != Input.getValue()) + else { // Parallel mode + if (nextFilter->Input.getValue() != Input.getValue()) { nextFilter->Input.setValue(Input.getValue()); + } } filter = nextFilter; @@ -198,8 +220,9 @@ void FemPostPipeline::onChanged(const Property* prop) // if we have no input the filters are responsible of grabbing the pipeline data themself else { // the first filter must always grab the data - if (filter->Input.getValue()) + if (filter->Input.getValue()) { filter->Input.setValue(nullptr); + } // all the others need to be connected to the previous filter or grab the data, // dependent on mode @@ -207,13 +230,15 @@ void FemPostPipeline::onChanged(const Property* prop) for (; it != objs.end(); ++it) { FemPostFilter* nextFilter = static_cast(*it); - if (Mode.getValue() == 0) { //serial mode - if (nextFilter->Input.getValue() != filter) + if (Mode.getValue() == 0) { // serial mode + if (nextFilter->Input.getValue() != filter) { nextFilter->Input.setValue(filter); + } } - else { //Parallel mode - if (nextFilter->Input.getValue()) + else { // Parallel mode + if (nextFilter->Input.getValue()) { nextFilter->Input.setValue(nullptr); + } } filter = nextFilter; @@ -222,35 +247,40 @@ void FemPostPipeline::onChanged(const Property* prop) } App::GeoFeature::onChanged(prop); - } void FemPostPipeline::recomputeChildren() { - for (const auto &obj : Filter.getValues()) + for (const auto& obj : Filter.getValues()) { obj->touch(); + } } -FemPostObject* FemPostPipeline::getLastPostObject() { +FemPostObject* FemPostPipeline::getLastPostObject() +{ - if (Filter.getValues().empty()) + if (Filter.getValues().empty()) { return this; + } return static_cast(Filter.getValues().back()); } -bool FemPostPipeline::holdsPostObject(FemPostObject* obj) { +bool FemPostPipeline::holdsPostObject(FemPostObject* obj) +{ std::vector::const_iterator it = Filter.getValues().begin(); for (; it != Filter.getValues().end(); ++it) { - if (*it == obj) + if (*it == obj) { return true; + } } return false; } -void FemPostPipeline::load(FemResultObject* res) { +void FemPostPipeline::load(FemResultObject* res) +{ if (!res->Mesh.getValue()) { Base::Console().Log("Result mesh object is empty.\n"); return; diff --git a/src/Mod/Fem/App/FemPostPipeline.h b/src/Mod/Fem/App/FemPostPipeline.h index 0022a6f7c7..475b0e6f99 100644 --- a/src/Mod/Fem/App/FemPostPipeline.h +++ b/src/Mod/Fem/App/FemPostPipeline.h @@ -34,7 +34,7 @@ namespace Fem { -class FemExport FemPostPipeline : public Fem::FemPostFilter +class FemExport FemPostPipeline: public Fem::FemPostFilter { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostPipeline); @@ -43,38 +43,41 @@ public: FemPostPipeline(); ~FemPostPipeline() override; - App::PropertyLinkList Filter; - App::PropertyLink Functions; - App::PropertyEnumeration Mode; + App::PropertyLinkList Filter; + App::PropertyLink Functions; + App::PropertyEnumeration Mode; short mustExecute() const override; App::DocumentObjectExecReturn* execute() override; PyObject* getPyObject() override; - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderFemPostPipeline"; } - //load data from files + // load data from files static bool canRead(Base::FileInfo file); void read(Base::FileInfo file); void scale(double s); - //load from results + // load from results void load(FemResultObject* res); - //Pipeline handling + // Pipeline handling void recomputeChildren(); - FemPostObject *getLastPostObject(); - bool holdsPostObject(FemPostObject *obj); + FemPostObject* getLastPostObject(); + bool holdsPostObject(FemPostObject* obj); protected: - void onChanged(const App::Property *prop) override; + void onChanged(const App::Property* prop) override; private: static const char* ModeEnums[]; - template void readXMLFile(std::string file) { + template + void readXMLFile(std::string file) + { vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName(file.c_str()); @@ -83,7 +86,7 @@ private: } }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemPostPipeline_H +#endif // Fem_FemPostPipeline_H diff --git a/src/Mod/Fem/App/FemPostPipelinePyImp.cpp b/src/Mod/Fem/App/FemPostPipelinePyImp.cpp index 484df01a5a..485ee6e6ce 100644 --- a/src/Mod/Fem/App/FemPostPipelinePyImp.cpp +++ b/src/Mod/Fem/App/FemPostPipelinePyImp.cpp @@ -22,14 +22,16 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include +// clang-format off #include "FemPostPipeline.h" #include "FemPostPipelinePy.h" #include "FemPostPipelinePy.cpp" +// clang-format on using namespace Fem; @@ -40,7 +42,7 @@ std::string FemPostPipelinePy::representation() const return {""}; } -PyObject* FemPostPipelinePy::read(PyObject *args) +PyObject* FemPostPipelinePy::read(PyObject* args) { char* Name; if (PyArg_ParseTuple(args, "et", "utf-8", &Name)) { @@ -51,7 +53,7 @@ PyObject* FemPostPipelinePy::read(PyObject *args) return nullptr; } -PyObject* FemPostPipelinePy::scale(PyObject *args) +PyObject* FemPostPipelinePy::scale(PyObject* args) { double scale; if (PyArg_ParseTuple(args, "d", &scale)) { @@ -61,11 +63,12 @@ PyObject* FemPostPipelinePy::scale(PyObject *args) return nullptr; } -PyObject* FemPostPipelinePy::load(PyObject *args) +PyObject* FemPostPipelinePy::load(PyObject* args) { PyObject* py; - if (!PyArg_ParseTuple(args, "O!", &(App::DocumentObjectPy::Type), &py)) + if (!PyArg_ParseTuple(args, "O!", &(App::DocumentObjectPy::Type), &py)) { return nullptr; + } App::DocumentObject* obj = static_cast(py)->getDocumentObjectPtr(); if (!obj->getTypeId().isDerivedFrom(FemResultObject::getClassTypeId())) { @@ -77,31 +80,35 @@ PyObject* FemPostPipelinePy::load(PyObject *args) Py_Return; } -PyObject *FemPostPipelinePy::recomputeChildren(PyObject *args) +PyObject* FemPostPipelinePy::recomputeChildren(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } getFemPostPipelinePtr()->recomputeChildren(); Py_Return; } -PyObject* FemPostPipelinePy::getLastPostObject(PyObject *args) +PyObject* FemPostPipelinePy::getLastPostObject(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } App::DocumentObject* obj = getFemPostPipelinePtr()->getLastPostObject(); - if (obj) + if (obj) { return obj->getPyObject(); + } Py_Return; } -PyObject* FemPostPipelinePy::holdsPostObject(PyObject *args) +PyObject* FemPostPipelinePy::holdsPostObject(PyObject* args) { PyObject* py; - if (!PyArg_ParseTuple(args, "O!", &(App::DocumentObjectPy::Type), &py)) + if (!PyArg_ParseTuple(args, "O!", &(App::DocumentObjectPy::Type), &py)) { return nullptr; + } App::DocumentObject* obj = static_cast(py)->getDocumentObjectPtr(); if (!obj->getTypeId().isDerivedFrom(FemPostObject::getClassTypeId())) { @@ -113,7 +120,7 @@ PyObject* FemPostPipelinePy::holdsPostObject(PyObject *args) return Py_BuildValue("O", (ok ? Py_True : Py_False)); } -PyObject *FemPostPipelinePy::getCustomAttributes(const char* /*attr*/) const +PyObject* FemPostPipelinePy::getCustomAttributes(const char* /*attr*/) const { return nullptr; } diff --git a/src/Mod/Fem/App/FemResultObject.cpp b/src/Mod/Fem/App/FemResultObject.cpp index d7e8fc676f..f14d561252 100644 --- a/src/Mod/Fem/App/FemResultObject.cpp +++ b/src/Mod/Fem/App/FemResultObject.cpp @@ -54,29 +54,34 @@ short FemResultObject::mustExecute() const return 0; } -PyObject *FemResultObject::getPyObject() +PyObject* FemResultObject::getPyObject() { - if (PythonObject.is(Py::_None())){ + if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new DocumentObjectPy(this),true); + PythonObject = Py::Object(new DocumentObjectPy(this), true); } return Py::new_reference_to(PythonObject); } // Python feature --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Fem::FemResultObjectPython, Fem::FemResultObject) -template<> const char* Fem::FemResultObjectPython::getViewProviderName() const { +template<> +const char* Fem::FemResultObjectPython::getViewProviderName() const +{ return "FemGui::ViewProviderResultPython"; } /// @endcond -template<> PyObject* Fem::FemResultObjectPython::getPyObject() { +template<> +PyObject* Fem::FemResultObjectPython::getPyObject() +{ if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new App::FeaturePythonPyT(this),true); + PythonObject = Py::Object(new App::FeaturePythonPyT(this), true); } return Py::new_reference_to(PythonObject); } @@ -84,4 +89,4 @@ template<> PyObject* Fem::FemResultObjectPython::getPyObject() { // explicit template instantiation template class FemExport FeaturePythonT; -} +} // namespace App diff --git a/src/Mod/Fem/App/FemResultObject.h b/src/Mod/Fem/App/FemResultObject.h index 97de965e4a..5104d0a752 100644 --- a/src/Mod/Fem/App/FemResultObject.h +++ b/src/Mod/Fem/App/FemResultObject.h @@ -31,7 +31,7 @@ namespace Fem { /// Father of all result data in a Fem Analysis -class FemExport FemResultObject : public App::DocumentObject +class FemExport FemResultObject: public App::DocumentObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemResultObject); @@ -50,20 +50,22 @@ public: /// Displacement vectors of analysis /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderResult"; } - App::DocumentObjectExecReturn *execute() override { + App::DocumentObjectExecReturn* execute() override + { return App::DocumentObject::StdReturn; } short mustExecute() const override; - PyObject *getPyObject() override; + PyObject* getPyObject() override; }; using FemResultObjectPython = App::FeaturePythonT; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemResultObject_H +#endif // Fem_FemResultObject_H diff --git a/src/Mod/Fem/App/FemSetElementsObject.cpp b/src/Mod/Fem/App/FemSetElementsObject.cpp index 08bf489f28..ed2c321138 100644 --- a/src/Mod/Fem/App/FemSetElementsObject.cpp +++ b/src/Mod/Fem/App/FemSetElementsObject.cpp @@ -42,12 +42,11 @@ short FemSetElementsObject::mustExecute() const return 0; } -PyObject *FemSetElementsObject::getPyObject() +PyObject* FemSetElementsObject::getPyObject() { - if (PythonObject.is(Py::_None())){ + if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new DocumentObjectPy(this),true); + PythonObject = Py::Object(new DocumentObjectPy(this), true); } return Py::new_reference_to(PythonObject); } - diff --git a/src/Mod/Fem/App/FemSetElementsObject.h b/src/Mod/Fem/App/FemSetElementsObject.h index 4889a892df..4a021166d4 100644 --- a/src/Mod/Fem/App/FemSetElementsObject.h +++ b/src/Mod/Fem/App/FemSetElementsObject.h @@ -23,14 +23,14 @@ #ifndef Fem_FemSetElementsObjec_H #define Fem_FemSetElementsObjec_H -#include #include "FemSetObject.h" +#include namespace Fem { -class FemExport FemSetElementsObject : public FemSetObject +class FemExport FemSetElementsObject: public FemSetObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemSetElementsObject); @@ -40,19 +40,19 @@ public: ~FemSetElementsObject() override; // returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderSetElements"; } - App::DocumentObjectExecReturn *execute() override { + App::DocumentObjectExecReturn* execute() override + { return App::DocumentObject::StdReturn; } short mustExecute() const override; - PyObject *getPyObject() override; - - + PyObject* getPyObject() override; }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemSetElementsObjec_H +#endif // Fem_FemSetElementsObjec_H diff --git a/src/Mod/Fem/App/FemSetFacesObject.cpp b/src/Mod/Fem/App/FemSetFacesObject.cpp index 4aca555e60..c8d6816150 100644 --- a/src/Mod/Fem/App/FemSetFacesObject.cpp +++ b/src/Mod/Fem/App/FemSetFacesObject.cpp @@ -42,12 +42,11 @@ short FemSetFacesObject::mustExecute() const return 0; } -PyObject *FemSetFacesObject::getPyObject() +PyObject* FemSetFacesObject::getPyObject() { - if (PythonObject.is(Py::_None())){ + if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new DocumentObjectPy(this),true); + PythonObject = Py::Object(new DocumentObjectPy(this), true); } return Py::new_reference_to(PythonObject); } - diff --git a/src/Mod/Fem/App/FemSetFacesObject.h b/src/Mod/Fem/App/FemSetFacesObject.h index 834e8fa310..8d921e4e32 100644 --- a/src/Mod/Fem/App/FemSetFacesObject.h +++ b/src/Mod/Fem/App/FemSetFacesObject.h @@ -23,14 +23,14 @@ #ifndef Fem_FemSetFacesObject_H #define Fem_FemSetFacesObject_H -#include #include "FemSetObject.h" +#include namespace Fem { -class FemExport FemSetFacesObject : public FemSetObject +class FemExport FemSetFacesObject: public FemSetObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemSetFacesObject); @@ -40,17 +40,19 @@ public: ~FemSetFacesObject() override; // returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderSetFaces"; } - App::DocumentObjectExecReturn *execute() override { + App::DocumentObjectExecReturn* execute() override + { return App::DocumentObject::StdReturn; } short mustExecute() const override; - PyObject *getPyObject() override; + PyObject* getPyObject() override; }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemSetFacesObject_H +#endif // Fem_FemSetFacesObject_H diff --git a/src/Mod/Fem/App/FemSetGeometryObject.cpp b/src/Mod/Fem/App/FemSetGeometryObject.cpp index 57044225c7..55025bf087 100644 --- a/src/Mod/Fem/App/FemSetGeometryObject.cpp +++ b/src/Mod/Fem/App/FemSetGeometryObject.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" -#include #include "FemSetGeometryObject.h" +#include using namespace Fem; @@ -41,12 +41,11 @@ short FemSetGeometryObject::mustExecute() const return 0; } -PyObject *FemSetGeometryObject::getPyObject() +PyObject* FemSetGeometryObject::getPyObject() { - if (PythonObject.is(Py::_None())){ + if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new DocumentObjectPy(this),true); + PythonObject = Py::Object(new DocumentObjectPy(this), true); } return Py::new_reference_to(PythonObject); } - diff --git a/src/Mod/Fem/App/FemSetGeometryObject.h b/src/Mod/Fem/App/FemSetGeometryObject.h index 4135786826..a9de42bba6 100644 --- a/src/Mod/Fem/App/FemSetGeometryObject.h +++ b/src/Mod/Fem/App/FemSetGeometryObject.h @@ -23,14 +23,14 @@ #ifndef Fem_FemSetGeometryObject_H #define Fem_FemSetGeometryObject_H -#include #include "FemSetObject.h" +#include namespace Fem { -class FemExport FemSetGeometryObject : public FemSetObject +class FemExport FemSetGeometryObject: public FemSetObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemSetGeometryObject); @@ -40,19 +40,19 @@ public: ~FemSetGeometryObject() override; // returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderSetGeometry"; } - App::DocumentObjectExecReturn *execute() override { + App::DocumentObjectExecReturn* execute() override + { return App::DocumentObject::StdReturn; } short mustExecute() const override; - PyObject *getPyObject() override; - - + PyObject* getPyObject() override; }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemSetGeometryObject_H +#endif // Fem_FemSetGeometryObject_H diff --git a/src/Mod/Fem/App/FemSetNodesObject.cpp b/src/Mod/Fem/App/FemSetNodesObject.cpp index 0554831fa4..467acf402d 100644 --- a/src/Mod/Fem/App/FemSetNodesObject.cpp +++ b/src/Mod/Fem/App/FemSetNodesObject.cpp @@ -35,7 +35,7 @@ PROPERTY_SOURCE(Fem::FemSetNodesObject, Fem::FemSetObject) FemSetNodesObject::FemSetNodesObject() { - ADD_PROPERTY_TYPE(Nodes,(), "Node indexes",Prop_None,"Nodes belonging to the NodesSet"); + ADD_PROPERTY_TYPE(Nodes, (), "Node indexes", Prop_None, "Nodes belonging to the NodesSet"); } FemSetNodesObject::~FemSetNodesObject() = default; @@ -45,12 +45,11 @@ short FemSetNodesObject::mustExecute() const return 0; } -PyObject *FemSetNodesObject::getPyObject() +PyObject* FemSetNodesObject::getPyObject() { - if (PythonObject.is(Py::_None())){ + if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new DocumentObjectPy(this),true); + PythonObject = Py::Object(new DocumentObjectPy(this), true); } return Py::new_reference_to(PythonObject); } - diff --git a/src/Mod/Fem/App/FemSetNodesObject.h b/src/Mod/Fem/App/FemSetNodesObject.h index f33f780675..d9b292f7aa 100644 --- a/src/Mod/Fem/App/FemSetNodesObject.h +++ b/src/Mod/Fem/App/FemSetNodesObject.h @@ -24,14 +24,14 @@ #ifndef Fem_FemSetNodesObject_H #define Fem_FemSetNodesObject_H +#include "FemSetObject.h" #include #include -#include "FemSetObject.h" namespace Fem { -class FemExport FemSetNodesObject : public FemSetObject +class FemExport FemSetNodesObject: public FemSetObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemSetNodesObject); @@ -43,19 +43,19 @@ public: App::PropertyIntegerSet Nodes; // returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderSetNodes"; } - App::DocumentObjectExecReturn *execute() override { + App::DocumentObjectExecReturn* execute() override + { return App::DocumentObject::StdReturn; } short mustExecute() const override; - PyObject *getPyObject() override; - - + PyObject* getPyObject() override; }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemSetNodesObject_H +#endif // Fem_FemSetNodesObject_H diff --git a/src/Mod/Fem/App/FemSetObject.cpp b/src/Mod/Fem/App/FemSetObject.cpp index 3cdcb59f7b..05ee5f2648 100644 --- a/src/Mod/Fem/App/FemSetObject.cpp +++ b/src/Mod/Fem/App/FemSetObject.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" -#include #include "FemSetObject.h" +#include using namespace Fem; @@ -34,7 +34,7 @@ PROPERTY_SOURCE(Fem::FemSetObject, App::DocumentObject) FemSetObject::FemSetObject() { - ADD_PROPERTY_TYPE(FemMesh,(nullptr), "MeshSet link",Prop_None,"MeshSet the set belongs to"); + ADD_PROPERTY_TYPE(FemMesh, (nullptr), "MeshSet link", Prop_None, "MeshSet the set belongs to"); } FemSetObject::~FemSetObject() = default; @@ -44,12 +44,11 @@ short FemSetObject::mustExecute() const return 0; } -PyObject *FemSetObject::getPyObject() +PyObject* FemSetObject::getPyObject() { - if (PythonObject.is(Py::_None())){ + if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new DocumentObjectPy(this),true); + PythonObject = Py::Object(new DocumentObjectPy(this), true); } return Py::new_reference_to(PythonObject); } - diff --git a/src/Mod/Fem/App/FemSetObject.h b/src/Mod/Fem/App/FemSetObject.h index 2d25a059bf..9f121fdad8 100644 --- a/src/Mod/Fem/App/FemSetObject.h +++ b/src/Mod/Fem/App/FemSetObject.h @@ -31,7 +31,7 @@ namespace Fem { -class FemExport FemSetObject : public App::DocumentObject +class FemExport FemSetObject: public App::DocumentObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemSetObject); @@ -43,19 +43,18 @@ public: App::PropertyLink FemMesh; /// returns the type name of the ViewProvider - //virtual const char* getViewProviderName(void) const { - // return "FemGui::ViewProviderFemSet"; - //} - App::DocumentObjectExecReturn *execute() override { + // virtual const char* getViewProviderName(void) const { + // return "FemGui::ViewProviderFemSet"; + // } + App::DocumentObjectExecReturn* execute() override + { return App::DocumentObject::StdReturn; } short mustExecute() const override; - PyObject *getPyObject() override; - - + PyObject* getPyObject() override; }; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemSetObject_H +#endif // Fem_FemSetObject_H diff --git a/src/Mod/Fem/App/FemSolverObject.cpp b/src/Mod/Fem/App/FemSolverObject.cpp index 7ca43ff8f1..8809c216aa 100644 --- a/src/Mod/Fem/App/FemSolverObject.cpp +++ b/src/Mod/Fem/App/FemSolverObject.cpp @@ -44,28 +44,33 @@ short FemSolverObject::mustExecute() const return 0; } -PyObject *FemSolverObject::getPyObject() +PyObject* FemSolverObject::getPyObject() { - if (PythonObject.is(Py::_None())){ + if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new DocumentObjectPy(this),true); + PythonObject = Py::Object(new DocumentObjectPy(this), true); } return Py::new_reference_to(PythonObject); } // Python feature --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Fem::FemSolverObjectPython, Fem::FemSolverObject) -template<> const char* Fem::FemSolverObjectPython::getViewProviderName() const { +template<> +const char* Fem::FemSolverObjectPython::getViewProviderName() const +{ return "FemGui::ViewProviderSolverPython"; } -template<> PyObject* Fem::FemSolverObjectPython::getPyObject() { +template<> +PyObject* Fem::FemSolverObjectPython::getPyObject() +{ if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new App::FeaturePythonPyT(this),true); + PythonObject = Py::Object(new App::FeaturePythonPyT(this), true); } return Py::new_reference_to(PythonObject); } @@ -73,4 +78,4 @@ template<> PyObject* Fem::FemSolverObjectPython::getPyObject() { // explicit template instantiation template class FemExport FeaturePythonT; -} +} // namespace App diff --git a/src/Mod/Fem/App/FemSolverObject.h b/src/Mod/Fem/App/FemSolverObject.h index ab5a7b0e13..629f7cbc7d 100644 --- a/src/Mod/Fem/App/FemSolverObject.h +++ b/src/Mod/Fem/App/FemSolverObject.h @@ -31,7 +31,7 @@ namespace Fem { /// Father of all result data in a Fem Analysis -class FemExport FemSolverObject : public App::DocumentObject +class FemExport FemSolverObject: public App::DocumentObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemSolverObject); @@ -43,20 +43,21 @@ public: // Attributes are implemented in the FemSolverObjectPython /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { + const char* getViewProviderName() const override + { return "FemGui::ViewProviderSolver"; } - App::DocumentObjectExecReturn *execute() override { + App::DocumentObjectExecReturn* execute() override + { return App::DocumentObject::StdReturn; } short mustExecute() const override; - PyObject *getPyObject() override; - + PyObject* getPyObject() override; }; using FemSolverObjectPython = App::FeaturePythonT; -} //namespace Fem +} // namespace Fem -#endif // Fem_FemSolverObject_H +#endif // Fem_FemSolverObject_H diff --git a/src/Mod/Fem/App/FemTools.cpp b/src/Mod/Fem/App/FemTools.cpp index d622862fcf..585e62c559 100644 --- a/src/Mod/Fem/App/FemTools.cpp +++ b/src/Mod/Fem/App/FemTools.cpp @@ -23,24 +23,24 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -78,22 +78,22 @@ bool Fem::Tools::isPlanar(const TopoDS_Face& face) else if (surface.GetType() == GeomAbs_BSplineSurface) { Handle(Geom_BSplineSurface) spline = surface.BSpline(); try { - TColgp_Array2OfPnt poles(1,spline->NbUPoles(),1,spline->NbVPoles()); + TColgp_Array2OfPnt poles(1, spline->NbUPoles(), 1, spline->NbVPoles()); spline->Poles(poles); // get the plane from three control points - gp_Pnt p1 = poles(poles.LowerRow(),poles.LowerCol()); - gp_Pnt p2 = poles(poles.UpperRow(),poles.LowerCol()); - gp_Pnt p3 = poles(poles.LowerRow(),poles.UpperCol()); + gp_Pnt p1 = poles(poles.LowerRow(), poles.LowerCol()); + gp_Pnt p2 = poles(poles.UpperRow(), poles.LowerCol()); + gp_Pnt p3 = poles(poles.LowerRow(), poles.UpperCol()); gp_Vec vec1(p1, p2); gp_Vec vec2(p1, p3); gp_Vec vec3 = vec1.Crossed(vec2); gp_Pln plane(p1, gp_Dir(vec3)); - for (int i=poles.LowerRow(); i<=poles.UpperRow(); i++) { - for (int j=poles.LowerCol(); j Precision::Confusion()) { return false; @@ -110,22 +110,22 @@ bool Fem::Tools::isPlanar(const TopoDS_Face& face) else if (surface.GetType() == GeomAbs_BezierSurface) { Handle(Geom_BezierSurface) bezier = surface.Bezier(); try { - TColgp_Array2OfPnt poles(1,bezier->NbUPoles(),1,bezier->NbVPoles()); + TColgp_Array2OfPnt poles(1, bezier->NbUPoles(), 1, bezier->NbVPoles()); bezier->Poles(poles); // get the plane from three control points - gp_Pnt p1 = poles(poles.LowerRow(),poles.LowerCol()); - gp_Pnt p2 = poles(poles.UpperRow(),poles.LowerCol()); - gp_Pnt p3 = poles(poles.LowerRow(),poles.UpperCol()); + gp_Pnt p1 = poles(poles.LowerRow(), poles.LowerCol()); + gp_Pnt p2 = poles(poles.UpperRow(), poles.LowerCol()); + gp_Pnt p3 = poles(poles.LowerRow(), poles.UpperCol()); gp_Vec vec1(p1, p2); gp_Vec vec2(p1, p3); gp_Vec vec3 = vec1.Crossed(vec2); gp_Pln plane(p1, gp_Dir(vec3)); - for (int i=poles.LowerRow(); i<=poles.UpperRow(); i++) { - for (int j=poles.LowerCol(); j Precision::Confusion()) { return false; @@ -154,13 +154,13 @@ gp_XYZ Fem::Tools::getDirection(const TopoDS_Face& face) else if (surface.GetType() == GeomAbs_BSplineSurface) { Handle(Geom_BSplineSurface) spline = surface.BSpline(); try { - TColgp_Array2OfPnt poles(1,spline->NbUPoles(),1,spline->NbVPoles()); + TColgp_Array2OfPnt poles(1, spline->NbUPoles(), 1, spline->NbVPoles()); spline->Poles(poles); // get the plane from three control points - gp_Pnt p1 = poles(poles.LowerRow(),poles.LowerCol()); - gp_Pnt p2 = poles(poles.UpperRow(),poles.LowerCol()); - gp_Pnt p3 = poles(poles.LowerRow(),poles.UpperCol()); + gp_Pnt p1 = poles(poles.LowerRow(), poles.LowerCol()); + gp_Pnt p2 = poles(poles.UpperRow(), poles.LowerCol()); + gp_Pnt p3 = poles(poles.LowerRow(), poles.UpperCol()); gp_Vec vec1(p1, p2); gp_Vec vec2(p1, p3); gp_Vec vec3 = vec1.Crossed(vec2); @@ -173,13 +173,13 @@ gp_XYZ Fem::Tools::getDirection(const TopoDS_Face& face) else if (surface.GetType() == GeomAbs_BezierSurface) { Handle(Geom_BezierSurface) bezier = surface.Bezier(); try { - TColgp_Array2OfPnt poles(1,bezier->NbUPoles(),1,bezier->NbVPoles()); + TColgp_Array2OfPnt poles(1, bezier->NbUPoles(), 1, bezier->NbVPoles()); bezier->Poles(poles); // get the plane from three control points - gp_Pnt p1 = poles(poles.LowerRow(),poles.LowerCol()); - gp_Pnt p2 = poles(poles.UpperRow(),poles.LowerCol()); - gp_Pnt p3 = poles(poles.LowerRow(),poles.UpperCol()); + gp_Pnt p1 = poles(poles.LowerRow(), poles.LowerCol()); + gp_Pnt p2 = poles(poles.UpperRow(), poles.LowerCol()); + gp_Pnt p3 = poles(poles.LowerRow(), poles.UpperCol()); gp_Vec vec1(p1, p2); gp_Vec vec2(p1, p3); gp_Vec vec3 = vec1.Crossed(vec2); @@ -207,7 +207,7 @@ bool Fem::Tools::isLinear(const TopoDS_Edge& edge) gp_Vec vec(s1, sn); gp_Lin line(s1, gp_Dir(vec)); - for (int i=2; iNbPoles(); i++) { + for (int i = 2; i < spline->NbPoles(); i++) { // are control points collinear? Standard_Real dist = line.Distance(spline->Pole(i)); if (dist > Precision::Confusion()) { @@ -229,7 +229,7 @@ bool Fem::Tools::isLinear(const TopoDS_Edge& edge) gp_Vec vec(s1, sn); gp_Lin line(s1, gp_Dir(vec)); - for (int i=2; iNbPoles(); i++) { + for (int i = 2; i < bezier->NbPoles(); i++) { // are control points collinear? Standard_Real dist = line.Distance(bezier->Pole(i)); if (dist > Precision::Confusion()) { @@ -285,8 +285,8 @@ gp_XYZ Fem::Tools::getDirection(const TopoDS_Edge& edge) // function to determine 3rd-party binaries used by the FEM WB std::string Fem::Tools::checkIfBinaryExists(std::string prefSection, - std::string prefBinaryName, - std::string binaryName) + std::string prefBinaryName, + std::string binaryName) { // if "Search in known binary directories" is set in the preferences, we ignore custom path auto paramPath = "User parameter:BaseApp/Preferences/Mod/Fem/" + prefSection; @@ -305,8 +305,9 @@ std::string Fem::Tools::checkIfBinaryExists(std::string prefSection, // check the folder of the FreeCAD binary else { auto homePathBinary = App::Application::getHomePath() + "bin/" + binaryName; - if (QFileInfo::exists(QString::fromLatin1(homePathBinary.c_str()))) + if (QFileInfo::exists(QString::fromLatin1(homePathBinary.c_str()))) { return binaryName; + } } } else { @@ -315,8 +316,9 @@ std::string Fem::Tools::checkIfBinaryExists(std::string prefSection, App::GetApplication().GetParameterGroupByPath(paramPath.c_str()); auto binaryPath = hGrp->GetASCII(binaryPathString.c_str(), ""); QFileInfo::exists(QString::fromLatin1(binaryPath.c_str())); - if (QFileInfo::exists(QString::fromLatin1(binaryPath.c_str()))) + if (QFileInfo::exists(QString::fromLatin1(binaryPath.c_str()))) { return binaryPath; + } } return ""; } diff --git a/src/Mod/Fem/App/FemTools.h b/src/Mod/Fem/App/FemTools.h index 628923570b..d5397df0df 100644 --- a/src/Mod/Fem/App/FemTools.h +++ b/src/Mod/Fem/App/FemTools.h @@ -25,8 +25,8 @@ #define FEM_TOOLS_H #include -#include #include +#include class TopoDS_Shape; class TopoDS_Edge; @@ -72,11 +72,12 @@ public: The result is either the full path if available or just the binary name if it was found in a system path */ - static std::string checkIfBinaryExists(std::string prefSection, std::string prefBinaryPath, + static std::string checkIfBinaryExists(std::string prefSection, + std::string prefBinaryPath, std::string prefBinaryName); }; -} //namespace Fem +} // namespace Fem -#endif // FEM_TOOLS_H +#endif // FEM_TOOLS_H diff --git a/src/Mod/Fem/App/FemVTKTools.cpp b/src/Mod/Fem/App/FemVTKTools.cpp index 1b572bba94..49ff9f0d39 100644 --- a/src/Mod/Fem/App/FemVTKTools.cpp +++ b/src/Mod/Fem/App/FemVTKTools.cpp @@ -24,38 +24,38 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include -# include -# include +#include +#include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -66,31 +66,31 @@ #include #include -#include "FemVTKTools.h" #include "FemAnalysis.h" #include "FemResultObject.h" +#include "FemVTKTools.h" namespace Fem { -template vtkDataSet* readVTKFile(const char*fileName) +template +vtkDataSet* readVTKFile(const char* fileName) { - vtkSmartPointer reader = - vtkSmartPointer::New(); + vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName(fileName); reader->Update(); auto output = reader->GetOutput(); - if (output) + if (output) { output->Register(reader); + } return vtkDataSet::SafeDownCast(output); } template void writeVTKFile(const char* filename, vtkSmartPointer dataset) { - vtkSmartPointer writer = - vtkSmartPointer::New(); + vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename); writer->SetInputData(dataset); writer->Write(); @@ -104,11 +104,11 @@ void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* me Base::Console().Log("%d nodes/points and %d cells/elements found!\n", nPoints, nCells); Base::Console().Log("Build SMESH mesh out of the vtk mesh data.\n", nPoints, nCells); - //vtkSmartPointer cells = dataset->GetCells(); - // works only for vtkUnstructuredGrid - vtkSmartPointer idlist= vtkSmartPointer::New(); + // vtkSmartPointer cells = dataset->GetCells(); + // works only for vtkUnstructuredGrid + vtkSmartPointer idlist = vtkSmartPointer::New(); - //Now fill the SMESH datastructure + // Now fill the SMESH datastructure SMESH_Mesh* smesh = mesh->getSMesh(); SMESHDS_Mesh* meshds = smesh->GetMeshDS(); meshds->ClearMesh(); @@ -124,10 +124,10 @@ void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* me vtkIdType* ids = idlist->GetPointer(0); switch (dataset->GetCellType(iCell)) { // 2D faces - case VTK_TRIANGLE:// tria3 + case VTK_TRIANGLE: // tria3 meshds->AddFaceWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, iCell + 1); break; - case VTK_QUADRATIC_TRIANGLE:// tria6 + case VTK_QUADRATIC_TRIANGLE: // tria6 meshds->AddFaceWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, @@ -136,10 +136,10 @@ void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* me ids[5] + 1, iCell + 1); break; - case VTK_QUAD:// quad4 + case VTK_QUAD: // quad4 meshds->AddFaceWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, ids[3] + 1, iCell + 1); break; - case VTK_QUADRATIC_QUAD:// quad8 + case VTK_QUADRATIC_QUAD: // quad8 meshds->AddFaceWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, @@ -152,10 +152,10 @@ void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* me break; // 3D volumes - case VTK_TETRA:// tetra4 + case VTK_TETRA: // tetra4 meshds->AddVolumeWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, ids[3] + 1, iCell + 1); break; - case VTK_QUADRATIC_TETRA:// tetra10 + case VTK_QUADRATIC_TETRA: // tetra10 meshds->AddVolumeWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, @@ -168,7 +168,7 @@ void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* me ids[9] + 1, iCell + 1); break; - case VTK_HEXAHEDRON:// hexa8 + case VTK_HEXAHEDRON: // hexa8 meshds->AddVolumeWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, @@ -179,7 +179,7 @@ void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* me ids[7] + 1, iCell + 1); break; - case VTK_QUADRATIC_HEXAHEDRON:// hexa20 + case VTK_QUADRATIC_HEXAHEDRON: // hexa20 meshds->AddVolumeWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, @@ -202,7 +202,7 @@ void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* me ids[19] + 1, iCell + 1); break; - case VTK_WEDGE:// penta6 + case VTK_WEDGE: // penta6 meshds->AddVolumeWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, @@ -211,7 +211,7 @@ void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* me ids[5] + 1, iCell + 1); break; - case VTK_QUADRATIC_WEDGE:// penta15 + case VTK_QUADRATIC_WEDGE: // penta15 meshds->AddVolumeWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, @@ -229,11 +229,15 @@ void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* me ids[14] + 1, iCell + 1); break; - case VTK_PYRAMID:// pyra5 - meshds->AddVolumeWithID( - ids[0] + 1, ids[1] + 1, ids[2] + 1, ids[3] + 1, ids[4] + 1, iCell + 1); + case VTK_PYRAMID: // pyra5 + meshds->AddVolumeWithID(ids[0] + 1, + ids[1] + 1, + ids[2] + 1, + ids[3] + 1, + ids[4] + 1, + iCell + 1); break; - case VTK_QUADRATIC_PYRAMID:// pyra13 + case VTK_QUADRATIC_PYRAMID: // pyra13 meshds->AddVolumeWithID(ids[0] + 1, ids[1] + 1, ids[2] + 1, @@ -294,7 +298,7 @@ FemMesh* FemVTKTools::readVTKMesh(const char* filename, FemMesh* mesh) Base::Console().Error("file name extension is not supported\n"); return nullptr; } - //Mesh should link to the part feature, in order to set up FemConstraint + // Mesh should link to the part feature, in order to set up FemConstraint Base::Console().Log(" %f: Done \n", Base::TimeInfo::diffTimeF(Start, Base::TimeInfo())); return mesh; @@ -310,11 +314,10 @@ void exportFemMeshFaces(vtkSmartPointer grid, vtkSmartPointer quadArray = vtkSmartPointer::New(); vtkSmartPointer quadQuadArray = vtkSmartPointer::New(); - for (;aFaceIter->more();) - { + for (; aFaceIter->more();) { const SMDS_MeshFace* aFace = aFaceIter->next(); - //triangle + // triangle if (aFace->NbNodes() == 3) { vtkSmartPointer tria = vtkSmartPointer::New(); tria->GetPointIds()->SetId(0, aFace->GetNode(0)->GetID() - 1); @@ -323,7 +326,7 @@ void exportFemMeshFaces(vtkSmartPointer grid, triangleArray->InsertNextCell(tria); } - //quad + // quad else if (aFace->NbNodes() == 4) { vtkSmartPointer quad = vtkSmartPointer::New(); quad->GetPointIds()->SetId(0, aFace->GetNode(0)->GetID() - 1); @@ -333,7 +336,7 @@ void exportFemMeshFaces(vtkSmartPointer grid, quadArray->InsertNextCell(quad); } - //quadratic triangle + // quadratic triangle else if (aFace->NbNodes() == 6) { vtkSmartPointer tria = vtkSmartPointer::New(); @@ -345,7 +348,7 @@ void exportFemMeshFaces(vtkSmartPointer grid, tria->GetPointIds()->SetId(5, aFace->GetNode(5)->GetID() - 1); quadTriangleArray->InsertNextCell(tria); } - //quadratic quad + // quadratic quad else if (aFace->NbNodes() == 8) { vtkSmartPointer quad = vtkSmartPointer::New(); quad->GetPointIds()->SetId(0, aFace->GetNode(0)->GetID() - 1); @@ -363,17 +366,21 @@ void exportFemMeshFaces(vtkSmartPointer grid, throw std::runtime_error("Face not yet supported by FreeCAD's VTK mesh builder\n"); } } - if (triangleArray->GetNumberOfCells() > 0) + if (triangleArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_TRIANGLE, triangleArray); + } - if (quadArray->GetNumberOfCells() > 0) + if (quadArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_QUAD, quadArray); + } - if (quadTriangleArray->GetNumberOfCells() > 0) + if (quadTriangleArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_QUADRATIC_TRIANGLE, quadTriangleArray); + } - if (quadQuadArray->GetNumberOfCells() > 0) + if (quadQuadArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_QUADRATIC_QUAD, quadQuadArray); + } Base::Console().Log(" End: VTK mesh builder faces.\n"); } @@ -392,11 +399,10 @@ void exportFemMeshCells(vtkSmartPointer grid, vtkSmartPointer quadWedgeArray = vtkSmartPointer::New(); vtkSmartPointer quadHexaArray = vtkSmartPointer::New(); - for (;aVolIter->more();) - { + for (; aVolIter->more();) { const SMDS_MeshVolume* aVol = aVolIter->next(); - if (aVol->NbNodes() == 4) {// tetra4 + if (aVol->NbNodes() == 4) { // tetra4 Base::Console().Log(" Volume tetra4\n"); vtkSmartPointer cell = vtkSmartPointer::New(); cell->GetPointIds()->SetId(0, aVol->GetNode(0)->GetID() - 1); @@ -405,7 +411,7 @@ void exportFemMeshCells(vtkSmartPointer grid, cell->GetPointIds()->SetId(3, aVol->GetNode(3)->GetID() - 1); tetraArray->InsertNextCell(cell); } - else if (aVol->NbNodes() == 5) {// pyra5 + else if (aVol->NbNodes() == 5) { // pyra5 Base::Console().Log(" Volume pyra5\n"); vtkSmartPointer cell = vtkSmartPointer::New(); cell->GetPointIds()->SetId(0, aVol->GetNode(0)->GetID() - 1); @@ -415,7 +421,7 @@ void exportFemMeshCells(vtkSmartPointer grid, cell->GetPointIds()->SetId(4, aVol->GetNode(4)->GetID() - 1); pyramidArray->InsertNextCell(cell); } - else if (aVol->NbNodes() == 6) {// penta6 + else if (aVol->NbNodes() == 6) { // penta6 Base::Console().Log(" Volume penta6\n"); vtkSmartPointer cell = vtkSmartPointer::New(); cell->GetPointIds()->SetId(0, aVol->GetNode(0)->GetID() - 1); @@ -426,7 +432,7 @@ void exportFemMeshCells(vtkSmartPointer grid, cell->GetPointIds()->SetId(5, aVol->GetNode(5)->GetID() - 1); wedgeArray->InsertNextCell(cell); } - else if (aVol->NbNodes() == 8) {// hexa8 + else if (aVol->NbNodes() == 8) { // hexa8 Base::Console().Log(" Volume hexa8\n"); vtkSmartPointer cell = vtkSmartPointer::New(); cell->GetPointIds()->SetId(0, aVol->GetNode(0)->GetID() - 1); @@ -439,7 +445,7 @@ void exportFemMeshCells(vtkSmartPointer grid, cell->GetPointIds()->SetId(7, aVol->GetNode(7)->GetID() - 1); hexaArray->InsertNextCell(cell); } - else if (aVol->NbNodes() == 10) {// tetra10 + else if (aVol->NbNodes() == 10) { // tetra10 Base::Console().Log(" Volume tetra10\n"); vtkSmartPointer tetra = vtkSmartPointer::New(); for (int i = 0; i < 10; i++) { @@ -448,7 +454,7 @@ void exportFemMeshCells(vtkSmartPointer grid, quadTetraArray->InsertNextCell(tetra); } - else if (aVol->NbNodes() == 13) {// pyra13 + else if (aVol->NbNodes() == 13) { // pyra13 Base::Console().Log(" Volume pyra13\n"); vtkSmartPointer cell = vtkSmartPointer::New(); for (int i = 0; i < 13; i++) { @@ -457,7 +463,7 @@ void exportFemMeshCells(vtkSmartPointer grid, } quadPyramidArray->InsertNextCell(cell); } - else if (aVol->NbNodes() == 15) {// penta15 + else if (aVol->NbNodes() == 15) { // penta15 Base::Console().Log(" Volume penta15\n"); vtkSmartPointer cell = vtkSmartPointer::New(); for (int i = 0; i < 15; i++) { @@ -465,7 +471,7 @@ void exportFemMeshCells(vtkSmartPointer grid, } quadWedgeArray->InsertNextCell(cell); } - else if (aVol->NbNodes() == 20) {// hexa20 + else if (aVol->NbNodes() == 20) { // hexa20 Base::Console().Log(" Volume hexa20\n"); vtkSmartPointer cell = vtkSmartPointer::New(); @@ -479,34 +485,43 @@ void exportFemMeshCells(vtkSmartPointer grid, } } - if (tetraArray->GetNumberOfCells() > 0) + if (tetraArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_TETRA, tetraArray); + } - if (pyramidArray->GetNumberOfCells() > 0) + if (pyramidArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_PYRAMID, pyramidArray); + } - if (wedgeArray->GetNumberOfCells() > 0) + if (wedgeArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_WEDGE, wedgeArray); + } - if (hexaArray->GetNumberOfCells() > 0) + if (hexaArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_HEXAHEDRON, hexaArray); + } - if (quadTetraArray->GetNumberOfCells() > 0) + if (quadTetraArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_QUADRATIC_TETRA, quadTetraArray); + } - if (quadPyramidArray->GetNumberOfCells() > 0) + if (quadPyramidArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_QUADRATIC_PYRAMID, quadPyramidArray); + } - if (quadWedgeArray->GetNumberOfCells() > 0) + if (quadWedgeArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_QUADRATIC_WEDGE, quadWedgeArray); + } - if (quadHexaArray->GetNumberOfCells() > 0) + if (quadHexaArray->GetNumberOfCells() > 0) { grid->SetCells(VTK_QUADRATIC_HEXAHEDRON, quadHexaArray); + } Base::Console().Log(" End: VTK mesh builder volumes.\n"); } -void FemVTKTools::exportVTKMesh(const FemMesh* mesh, vtkSmartPointer grid, +void FemVTKTools::exportVTKMesh(const FemMesh* mesh, + vtkSmartPointer grid, float scale) { @@ -521,9 +536,10 @@ void FemVTKTools::exportVTKMesh(const FemMesh* mesh, vtkSmartPointernodesIterator(); while (aNodeIter->more()) { - const SMDS_MeshNode* node = aNodeIter->next();// why float, not double? - double coords[3] = { - double(node->X() * scale), double(node->Y() * scale), double(node->Z() * scale)}; + const SMDS_MeshNode* node = aNodeIter->next(); // why float, not double? + double coords[3] = {double(node->X() * scale), + double(node->Y() * scale), + double(node->Z() * scale)}; points->InsertPoint(node->GetID() - 1, coords); // memory is allocated by VTK points size for max node id, not for point count // if the SMESH mesh has gaps in node numbering, points without any element @@ -559,7 +575,7 @@ void FemVTKTools::writeVTKMesh(const char* filename, const FemMesh* mesh) vtkSmartPointer grid = vtkSmartPointer::New(); exportVTKMesh(mesh, grid); - //vtkSmartPointer dataset = vtkDataSet::SafeDownCast(grid); + // vtkSmartPointer dataset = vtkDataSet::SafeDownCast(grid); Base::Console().Log("Start: writing mesh data ======================\n"); if (f.hasExtension("vtu")) { writeVTKFile(filename, grid); @@ -571,7 +587,7 @@ void FemVTKTools::writeVTKMesh(const char* filename, const FemMesh* mesh) Base::Console().Error("file name extension is not supported to write VTK\n"); } - Base::Console().Log(" %f: Done \n",Base::TimeInfo::diffTimeF(Start, Base::TimeInfo())); + Base::Console().Log(" %f: Done \n", Base::TimeInfo::diffTimeF(Start, Base::TimeInfo())); } @@ -589,9 +605,10 @@ App::DocumentObject* getObjectByType(const Base::Type type) } if (obj->getTypeId() == FemAnalysis::getClassTypeId()) { std::vector fem = (static_cast(obj))->Group.getValues(); - for (const auto & it : fem) { - if (it->getTypeId().isDerivedFrom(type)) - return static_cast(it);// return the first of that type + for (const auto& it : fem) { + if (it->getTypeId().isDerivedFrom(type)) { + return static_cast(it); // return the first of that type + } } } return nullptr; @@ -613,7 +630,7 @@ App::DocumentObject* createObjectByType(const Base::Type type) return newobj; } else { - return pcDoc->addObject(type.getName());// create in the active document + return pcDoc->addObject(type.getName()); // create in the active document } } @@ -621,7 +638,8 @@ App::DocumentObject* createObjectByType(const Base::Type type) App::DocumentObject* FemVTKTools::readResult(const char* filename, App::DocumentObject* res) { Base::TimeInfo Start; - Base::Console().Log("Start: read FemResult with FemMesh from VTK file ======================\n"); + Base::Console().Log( + "Start: read FemResult with FemMesh from VTK file ======================\n"); Base::FileInfo f(filename); vtkSmartPointer ds; @@ -666,10 +684,11 @@ App::DocumentObject* FemVTKTools::readResult(const char* filename, App::Document // PropertyLink is the property type to store DocumentObject pointer App::PropertyLink* link = dynamic_cast(result->getPropertyByName("Mesh")); - if (link) + if (link) { link->setValue(mesh); + } - //vtkSmartPointer pd = dataset->GetPointData(); + // vtkSmartPointer pd = dataset->GetPointData(); importFreeCADResult(dataset, result); } @@ -681,14 +700,15 @@ App::DocumentObject* FemVTKTools::readResult(const char* filename, App::Document } -void FemVTKTools::writeResult(const char* filename, const App::DocumentObject* res) { +void FemVTKTools::writeResult(const char* filename, const App::DocumentObject* res) +{ if (!res) { App::Document* pcDoc = App::GetApplication().getActiveDocument(); if (!pcDoc) { Base::Console().Message("No active document is found thus do nothing and return\n"); return; } - res = pcDoc->getActiveObject();//type checking is done by caller + res = pcDoc->getActiveObject(); // type checking is done by caller } if (!res) { Base::Console().Error("Result object pointer is invalid and it is not active object"); @@ -713,7 +733,7 @@ void FemVTKTools::writeResult(const char* filename, const App::DocumentObject* r // result FemVTKTools::exportFreeCADResult(res, grid); - //vtkSmartPointer dataset = vtkDataSet::SafeDownCast(grid); + // vtkSmartPointer dataset = vtkDataSet::SafeDownCast(grid); if (f.hasExtension("vtu")) { writeVTKFile(filename, grid); } @@ -730,7 +750,8 @@ void FemVTKTools::writeResult(const char* filename, const App::DocumentObject* r } -std::map _getFreeCADMechResultVectorProperties() { +std::map _getFreeCADMechResultVectorProperties() +{ // see src/Mod/Fem/femobjects/_FemResultMechanical // App::PropertyVectorList will be a list of vectors in vtk std::map resFCVecProp; @@ -750,12 +771,13 @@ std::map _getFreeCADMechResultVectorProperties() { // some scalar list are not needed on VTK file export but they are needed for internal VTK pipeline // TODO some filter to only export the needed values to VTK file but have all // in FreeCAD VTK pipeline -std::map _getFreeCADMechResultScalarProperties() { +std::map _getFreeCADMechResultScalarProperties() +{ // see src/Mod/Fem/femobjects/result_mechanical.py // App::PropertyFloatList will be a list of scalars in vtk std::map resFCScalProp; resFCScalProp["DisplacementLengths"] = - "Displacement Magnitude";// can be plotted in Paraview as THE DISPLACEMENT MAGNITUDE + "Displacement Magnitude"; // can be plotted in Paraview as THE DISPLACEMENT MAGNITUDE resFCScalProp["MaxShear"] = "Tresca Stress"; resFCScalProp["NodeStressXX"] = "Stress xx component"; resFCScalProp["NodeStressYY"] = "Stress yy component"; @@ -782,12 +804,13 @@ std::map _getFreeCADMechResultScalarProperties() { // how to generate them in paraview) // but there are needed anyway because the pipeline in FreeCAD needs the principal stress values // https://forum.freecad.org/viewtopic.php?f=18&t=33106&p=416006#p412800 - resFCScalProp["PrincipalMax"] = - "Major Principal Stress";// can be plotted in Paraview as THE MAJOR PRINCIPAL STRESS MAGNITUDE + resFCScalProp["PrincipalMax"] = "Major Principal Stress"; // can be plotted in Paraview as THE + // MAJOR PRINCIPAL STRESS MAGNITUDE resFCScalProp["PrincipalMed"] = - "Intermediate Principal Stress";// can be plotted in Paraview as THE INTERMEDIATE PRINCIPAL STRESS MAGNITUDE - resFCScalProp["PrincipalMin"] = - "Minor Principal Stress";// can be plotted in Paraview as THE MINOR PRINCIPAL STRESS MAGNITUDE + "Intermediate Principal Stress"; // can be plotted in Paraview as THE INTERMEDIATE + // PRINCIPAL STRESS MAGNITUDE + resFCScalProp["PrincipalMin"] = "Minor Principal Stress"; // can be plotted in Paraview as THE + // MINOR PRINCIPAL STRESS MAGNITUDE resFCScalProp["vonMises"] = "von Mises Stress"; resFCScalProp["Temperature"] = "Temperature"; resFCScalProp["MohrCoulomb"] = "MohrCoulomb"; @@ -811,7 +834,7 @@ void FemVTKTools::importFreeCADResult(vtkSmartPointer dataset, std::map vectors = _getFreeCADMechResultVectorProperties(); std::map scalars = _getFreeCADMechResultScalarProperties(); - double ts = 0.0;// t=0.0 for static simulation + double ts = 0.0; // t=0.0 for static simulation static_cast(result->getPropertyByName("Time"))->setValue(ts); vtkSmartPointer pd = dataset->GetPointData(); @@ -833,9 +856,9 @@ void FemVTKTools::importFreeCADResult(vtkSmartPointer dataset, Base::Console().Log(" NodeNumbers have been filled with values.\n"); // vectors - for (const auto & it : vectors) { - int dim = 3;// Fixme: currently 3D only, here we could run into trouble, - // FreeCAD only supports dim 3D, I do not know about VTK + for (const auto& it : vectors) { + int dim = 3; // Fixme: currently 3D only, here we could run into trouble, + // FreeCAD only supports dim 3D, I do not know about VTK vtkDataArray* vector_field = vtkDataArray::SafeDownCast(pd->GetArray(it.second.c_str())); if (vector_field && vector_field->GetNumberOfComponents() == dim) { App::PropertyVectorList* vector_list = @@ -844,7 +867,7 @@ void FemVTKTools::importFreeCADResult(vtkSmartPointer dataset, std::vector vec(nPoints); for (vtkIdType i = 0; i < nPoints; ++i) { double* p = vector_field->GetTuple( - i);// both vtkFloatArray and vtkDoubleArray return double* for GetTuple(i) + i); // both vtkFloatArray and vtkDoubleArray return double* for GetTuple(i) vec[i] = (Base::Vector3d(p[0], p[1], p[2])); } // PropertyVectorList will not show up in PropertyEditor @@ -859,17 +882,18 @@ void FemVTKTools::importFreeCADResult(vtkSmartPointer dataset, continue; } } - else + else { Base::Console().Message(" PropertyVectorList NOT found in vkt file data: %s\n", it.first.c_str()); + } } // scalars - for (const auto & scalar : scalars) { + for (const auto& scalar : scalars) { vtkDataArray* vec = vtkDataArray::SafeDownCast(pd->GetArray(scalar.second.c_str())); if (nPoints && vec && vec->GetNumberOfComponents() == 1) { - App::PropertyFloatList* field = - static_cast(result->getPropertyByName(scalar.first.c_str())); + App::PropertyFloatList* field = static_cast( + result->getPropertyByName(scalar.first.c_str())); if (!field) { Base::Console().Error("static_cast((result->" "getPropertyByName(\"%s\")) failed.\n", @@ -882,18 +906,21 @@ void FemVTKTools::importFreeCADResult(vtkSmartPointer dataset, for (vtkIdType i = 0; i < vec->GetNumberOfTuples(); i++) { double v = *(vec->GetTuple(i)); values[i] = v; - if (v > vmax) + if (v > vmax) { vmax = v; - if (v < vmin) + } + if (v < vmin) { vmin = v; + } } field->setValues(values); Base::Console().Log(" A PropertyFloatList has been filled with vales: %s\n", scalar.first.c_str()); } - else + else { Base::Console().Message(" PropertyFloatList NOT found in vkt file data %s\n", scalar.first.c_str()); + } } // stats @@ -931,19 +958,21 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, double factor = 1.0; // vectors - for (const auto & it : vectors) { - const int dim = 3;//Fixme, detect dim, but FreeCAD PropertyVectorList ATM only has DIM of 3 + for (const auto& it : vectors) { + const int dim = + 3; // Fixme, detect dim, but FreeCAD PropertyVectorList ATM only has DIM of 3 App::PropertyVectorList* field = nullptr; - if (res->getPropertyByName(it.first.c_str())) - field = - static_cast(res->getPropertyByName(it.first.c_str())); - else + if (res->getPropertyByName(it.first.c_str())) { + field = static_cast(res->getPropertyByName(it.first.c_str())); + } + else { Base::Console().Error(" PropertyVectorList not found: %s\n", it.first.c_str()); + } if (field && field->getSize() > 0) { - //if (nPoints != field->getSize()) - // Base::Console().Error("Size of PropertyVectorList = %d, not equal - // to vtk mesh node count %d \n", field->getSize(), nPoints); + // if (nPoints != field->getSize()) + // Base::Console().Error("Size of PropertyVectorList = %d, not equal + // to vtk mesh node count %d \n", field->getSize(), nPoints); const std::vector& vel = field->getValues(); vtkSmartPointer data = vtkSmartPointer::New(); data->SetNumberOfComponents(dim); @@ -960,13 +989,15 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, } } - if (it.first.compare("DisplacementVectors") == 0) - factor = 0.001;// to get meter - else + if (it.first.compare("DisplacementVectors") == 0) { + factor = 0.001; // to get meter + } + else { factor = 1.0; + } SMDS_NodeIteratorPtr aNodeIter = meshDS->nodesIterator(); - for (const auto & jt : vel) { + for (const auto& jt : vel) { const SMDS_MeshNode* node = aNodeIter->next(); double tuple[] = {jt.x * factor, jt.y * factor, jt.z * factor}; data->SetTuple(node->GetID() - 1, tuple); @@ -985,17 +1016,20 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, } // scalars - for (const auto & scalar : scalars) { + for (const auto& scalar : scalars) { App::PropertyFloatList* field = nullptr; - if (res->getPropertyByName(scalar.first.c_str())) - field = static_cast(res->getPropertyByName(scalar.first.c_str())); - else + if (res->getPropertyByName(scalar.first.c_str())) { + field = + static_cast(res->getPropertyByName(scalar.first.c_str())); + } + else { Base::Console().Error("PropertyFloatList %s not found \n", scalar.first.c_str()); + } if (field && field->getSize() > 0) { - //if (nPoints != field->getSize()) - // Base::Console().Error("Size of PropertyFloatList = %d, not equal to vtk mesh - // node count %d \n", field->getSize(), nPoints); + // if (nPoints != field->getSize()) + // Base::Console().Error("Size of PropertyFloatList = %d, not equal to vtk mesh + // node count %d \n", field->getSize(), nPoints); const std::vector& vec = field->getValues(); vtkSmartPointer data = vtkSmartPointer::New(); data->SetNumberOfValues(nPoints); @@ -1021,19 +1055,23 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, || (scalar.first.compare("PrincipalMed") == 0) || (scalar.first.compare("PrincipalMin") == 0) || (scalar.first.compare("vonMises") == 0) - || (scalar.first.compare("NetworkPressure") == 0) ) - factor = 1e6; // to get Pascal - else if (scalar.first.compare("DisplacementLengths") == 0) - factor = 0.001; // to get meter - else + || (scalar.first.compare("NetworkPressure") == 0)) { + factor = 1e6; // to get Pascal + } + else if (scalar.first.compare("DisplacementLengths") == 0) { + factor = 0.001; // to get meter + } + else { factor = 1.0; + } SMDS_NodeIteratorPtr aNodeIter = meshDS->nodesIterator(); for (double i : vec) { const SMDS_MeshNode* node = aNodeIter->next(); // for the MassFlowRate the last vec entries can be a nullptr, thus check this - if (node) + if (node) { data->SetValue(node->GetID() - 1, i * factor); + } } grid->GetPointData()->AddArray(data); @@ -1052,4 +1090,4 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, Base::Console().Log("End: Create VTK result data from FreeCAD result data.\n"); } -} // namespace +} // namespace Fem diff --git a/src/Mod/Fem/App/FemVTKTools.h b/src/Mod/Fem/App/FemVTKTools.h index 87f5bb1491..19fb2d32b0 100644 --- a/src/Mod/Fem/App/FemVTKTools.h +++ b/src/Mod/Fem/App/FemVTKTools.h @@ -34,34 +34,42 @@ namespace Fem { - // utility class to import/export read/write vtk mesh and result - class FemExport FemVTKTools - { - public: - // extract data from vtkUnstructuredGrid instance and fill a FreeCAD FEM mesh object with that data - static void importVTKMesh(vtkSmartPointer grid, FemMesh* mesh, float scale = 1.0); +// utility class to import/export read/write vtk mesh and result +class FemExport FemVTKTools +{ +public: + // extract data from vtkUnstructuredGrid instance and fill a FreeCAD FEM mesh object with that + // data + static void importVTKMesh(vtkSmartPointer grid, FemMesh* mesh, float scale = 1.0); - // extract data from FreCAD FEM mesh and fill a vtkUnstructuredGrid instance with that data - static void exportVTKMesh(const FemMesh* mesh, vtkSmartPointer grid, float scale = 1.0); + // extract data from FreCAD FEM mesh and fill a vtkUnstructuredGrid instance with that data + static void exportVTKMesh(const FemMesh* mesh, + vtkSmartPointer grid, + float scale = 1.0); - // extract data from vtkUnstructuredGrid object and fill a FreeCAD FEM result object with that data (needed by readResult) - static void importFreeCADResult(vtkSmartPointer dataset, App::DocumentObject* result); + // extract data from vtkUnstructuredGrid object and fill a FreeCAD FEM result object with that + // data (needed by readResult) + static void importFreeCADResult(vtkSmartPointer dataset, + App::DocumentObject* result); - // extract data from a FreeCAD FEM result object and fill a vtkUnstructuredGrid object with that data (needed by writeResult) - static void exportFreeCADResult(const App::DocumentObject* result, vtkSmartPointer grid); + // extract data from a FreeCAD FEM result object and fill a vtkUnstructuredGrid object with that + // data (needed by writeResult) + static void exportFreeCADResult(const App::DocumentObject* result, + vtkSmartPointer grid); - // FemMesh read from vtkUnstructuredGrid data file - static FemMesh* readVTKMesh(const char* filename, FemMesh* mesh); + // FemMesh read from vtkUnstructuredGrid data file + static FemMesh* readVTKMesh(const char* filename, FemMesh* mesh); - // FemMesh write to vtkUnstructuredGrid data file - static void writeVTKMesh(const char* Filename, const FemMesh* mesh); + // FemMesh write to vtkUnstructuredGrid data file + static void writeVTKMesh(const char* Filename, const FemMesh* mesh); - // FemResult (activeObject or created if res= NULL) read from vtkUnstructuredGrid dataset file - static App::DocumentObject* readResult(const char* Filename, App::DocumentObject* res = nullptr); + // FemResult (activeObject or created if res= NULL) read from vtkUnstructuredGrid dataset file + static App::DocumentObject* readResult(const char* Filename, + App::DocumentObject* res = nullptr); - // write FemResult (activeObject if res= NULL) to vtkUnstructuredGrid dataset file - static void writeResult(const char* filename, const App::DocumentObject* res = nullptr); - }; -} + // write FemResult (activeObject if res= NULL) to vtkUnstructuredGrid dataset file + static void writeResult(const char* filename, const App::DocumentObject* res = nullptr); +}; +} // namespace Fem -#endif //FEM_VTK_TOOLS_H +#endif // FEM_VTK_TOOLS_H diff --git a/src/Mod/Fem/App/HypothesisPy.cpp b/src/Mod/Fem/App/HypothesisPy.cpp old mode 100755 new mode 100644 index 45d54f2b9c..1c9c8f646b --- a/src/Mod/Fem/App/HypothesisPy.cpp +++ b/src/Mod/Fem/App/HypothesisPy.cpp @@ -27,42 +27,42 @@ #include "HypothesisPy.h" #ifndef _PreComp_ -# include -# include // needed for SMESH_VERSION_MAJOR -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# if SMESH_VERSION_MAJOR < 7 -# include -# endif +#include // needed for SMESH_VERSION_MAJOR +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if SMESH_VERSION_MAJOR < 7 +#include +#endif #endif #include @@ -74,9 +74,8 @@ using namespace Fem; HypothesisPy::HypothesisPy(std::shared_ptr h) - : hyp(h) -{ -} + : hyp(h) +{} HypothesisPy::~HypothesisPy() = default; @@ -91,34 +90,54 @@ void SMESH_HypothesisPy::init_type(PyObject* module) SMESH_HypothesisPy::behaviors().supportSetattr(); SMESH_HypothesisPy::behaviors().set_tp_new(PyMake); - SMESH_HypothesisPy::add_varargs_method("setLibName", &SMESH_HypothesisPy::setLibName, "setLibName(String)"); - SMESH_HypothesisPy::add_varargs_method("getLibName", &SMESH_HypothesisPy::getLibName, "String getLibName()"); + SMESH_HypothesisPy::add_varargs_method("setLibName", + &SMESH_HypothesisPy::setLibName, + "setLibName(String)"); + SMESH_HypothesisPy::add_varargs_method("getLibName", + &SMESH_HypothesisPy::getLibName, + "String getLibName()"); #if SMESH_VERSION_MAJOR < 7 - SMESH_HypothesisPy::add_varargs_method("setParameters", &SMESH_HypothesisPy::setParameters, "setParameters(String)"); - SMESH_HypothesisPy::add_varargs_method("getParameters", &SMESH_HypothesisPy::getParameters, "String getParameters()"); - SMESH_HypothesisPy::add_varargs_method("setLastParameters", &SMESH_HypothesisPy::setLastParameters, "setLastParameters(String)"); - SMESH_HypothesisPy::add_varargs_method("getLastParameters", &SMESH_HypothesisPy::getLastParameters, "String getLastParameters()"); - SMESH_HypothesisPy::add_varargs_method("clearParameters", &SMESH_HypothesisPy::clearParameters, "clearParameters()"); + SMESH_HypothesisPy::add_varargs_method("setParameters", + &SMESH_HypothesisPy::setParameters, + "setParameters(String)"); + SMESH_HypothesisPy::add_varargs_method("getParameters", + &SMESH_HypothesisPy::getParameters, + "String getParameters()"); + SMESH_HypothesisPy::add_varargs_method("setLastParameters", + &SMESH_HypothesisPy::setLastParameters, + "setLastParameters(String)"); + SMESH_HypothesisPy::add_varargs_method("getLastParameters", + &SMESH_HypothesisPy::getLastParameters, + "String getLastParameters()"); + SMESH_HypothesisPy::add_varargs_method("clearParameters", + &SMESH_HypothesisPy::clearParameters, + "clearParameters()"); #endif - SMESH_HypothesisPy::add_varargs_method("isAuxiliary", &SMESH_HypothesisPy::isAuxiliary, "Bool isAuxiliary()"); - SMESH_HypothesisPy::add_varargs_method("setParametersByMesh", &SMESH_HypothesisPy::setParametersByMesh, "setParametersByMesh(Mesh,Shape)"); + SMESH_HypothesisPy::add_varargs_method("isAuxiliary", + &SMESH_HypothesisPy::isAuxiliary, + "Bool isAuxiliary()"); + SMESH_HypothesisPy::add_varargs_method("setParametersByMesh", + &SMESH_HypothesisPy::setParametersByMesh, + "setParametersByMesh(Mesh,Shape)"); Base::Interpreter().addType(SMESH_HypothesisPy::behaviors().type_object(), - module,SMESH_HypothesisPy::behaviors().getName()); + module, + SMESH_HypothesisPy::behaviors().getName()); } template -SMESH_HypothesisPy::SMESH_HypothesisPy(SMESH_Hypothesis* h) : hyp(h) -{ -} +SMESH_HypothesisPy::SMESH_HypothesisPy(SMESH_Hypothesis* h) + : hyp(h) +{} template SMESH_HypothesisPy::~SMESH_HypothesisPy() = default; template -Py::Object SMESH_HypothesisPy::getattr(const char *name) +Py::Object SMESH_HypothesisPy::getattr(const char* name) { - if (strcmp(name,"this") == 0) + if (strcmp(name, "this") == 0) { return Hypothesis(Py::asObject(new HypothesisPy(this->getHypothesis()))); + } return Py::PythonExtension::getattr(name); } @@ -141,13 +160,14 @@ Py::Object SMESH_HypothesisPy::setLibName(const Py::Tuple& args) template Py::Object SMESH_HypothesisPy::getLibName(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::String(hypothesis()->GetLibName()); } -#if SMESH_VERSION_MAJOR < 7 // ----------------------------------------------- +#if SMESH_VERSION_MAJOR < 7 // ----------------------------------------------- template Py::Object SMESH_HypothesisPy::setParameters(const Py::Tuple& args) { @@ -159,16 +179,18 @@ Py::Object SMESH_HypothesisPy::setParameters(const Py::Tuple& args) template Py::Object SMESH_HypothesisPy::getParameters(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::String(hypothesis()->GetParameters()); } template Py::Object SMESH_HypothesisPy::setLastParameters(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } std::string paramName = static_cast(Py::String(args[0])); hypothesis()->SetLastParameters(paramName.c_str()); return Py::None(); @@ -177,29 +199,35 @@ Py::Object SMESH_HypothesisPy::setLastParameters(const Py::Tuple& args) template Py::Object SMESH_HypothesisPy::getLastParameters(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::String(hypothesis()->GetLastParameters()); } template Py::Object SMESH_HypothesisPy::clearParameters(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } hypothesis()->ClearParameters(); return Py::None(); } -#endif // -------------------------------------------------------------------- +#endif // -------------------------------------------------------------------- template Py::Object SMESH_HypothesisPy::setParametersByMesh(const Py::Tuple& args) { PyObject *mesh, *shape; - if (!PyArg_ParseTuple(args.ptr(), "O!O!", - &(Fem::FemMeshPy::Type), &mesh, - &(Part::TopoShapePy::Type), &shape)) + if (!PyArg_ParseTuple(args.ptr(), + "O!O!", + &(Fem::FemMeshPy::Type), + &mesh, + &(Part::TopoShapePy::Type), + &shape)) { throw Py::Exception(); + } Fem::FemMesh* m = static_cast(mesh)->getFemMeshPtr(); const TopoDS_Shape& s = static_cast(shape)->getTopoShapePtr()->getShape(); return Py::Boolean(hypothesis()->SetParametersByMesh(m->getSMesh(), s)); @@ -208,18 +236,21 @@ Py::Object SMESH_HypothesisPy::setParametersByMesh(const Py::Tuple& args) template Py::Object SMESH_HypothesisPy::isAuxiliary(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Boolean(hypothesis()->IsAuxiliary()); } template -PyObject *SMESH_HypothesisPy::PyMake(struct _typeobject * /*type*/, PyObject * args, PyObject * /*kwds*/) +PyObject* +SMESH_HypothesisPy::PyMake(struct _typeobject* /*type*/, PyObject* args, PyObject* /*kwds*/) { int hypId; PyObject* obj; - if (!PyArg_ParseTuple(args, "iO!",&hypId,&(FemMeshPy::Type),&obj)) + if (!PyArg_ParseTuple(args, "iO!", &hypId, &(FemMeshPy::Type), &obj)) { return nullptr; + } FemMesh* mesh = static_cast(obj)->getFemMeshPtr(); #if SMESH_VERSION_MAJOR >= 9 return new T(hypId, mesh->getGenerator()); @@ -242,32 +273,30 @@ void StdMeshers_Arithmetic1DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_Arithmetic1DPy::StdMeshers_Arithmetic1DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Arithmetic1D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Arithmetic1D(hypId, gen)) +{} #else StdMeshers_Arithmetic1DPy::StdMeshers_Arithmetic1DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Arithmetic1D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Arithmetic1D(hypId, studyId, gen)) +{} #endif StdMeshers_Arithmetic1DPy::~StdMeshers_Arithmetic1DPy() = default; Py::Object StdMeshers_Arithmetic1DPy::setLength(const Py::Tuple& args) { - hypothesis()-> - SetLength((double)Py::Float(args[0]), (bool)Py::Boolean(args[1])); + hypothesis()->SetLength((double)Py::Float(args[0]), + (bool)Py::Boolean(args[1])); return Py::None(); } Py::Object StdMeshers_Arithmetic1DPy::getLength(const Py::Tuple& args) { int start; - if (!PyArg_ParseTuple(args.ptr(), "i",&start)) + if (!PyArg_ParseTuple(args.ptr(), "i", &start)) { throw Py::Exception(); - return Py::Float(hypothesis()-> - GetLength(start ? true : false)); + } + return Py::Float(hypothesis()->GetLength(start ? true : false)); } // --------------------------------------------------------------------------- @@ -285,14 +314,14 @@ void StdMeshers_AutomaticLengthPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_AutomaticLengthPy::StdMeshers_AutomaticLengthPy(int /*hypId*/, SMESH_Gen* /*gen*/) - : SMESH_HypothesisPyBase(0) -{ -} + : SMESH_HypothesisPyBase(0) +{} #else -StdMeshers_AutomaticLengthPy::StdMeshers_AutomaticLengthPy(int /*hypId*/, int /*studyId*/, SMESH_Gen* /*gen*/) - : SMESH_HypothesisPyBase(nullptr) -{ -} +StdMeshers_AutomaticLengthPy::StdMeshers_AutomaticLengthPy(int /*hypId*/, + int /*studyId*/, + SMESH_Gen* /*gen*/) + : SMESH_HypothesisPyBase(nullptr) +{} #endif StdMeshers_AutomaticLengthPy::~StdMeshers_AutomaticLengthPy() = default; @@ -306,23 +335,27 @@ Py::Object StdMeshers_AutomaticLengthPy::setFineness(const Py::Tuple& args) Py::Object StdMeshers_AutomaticLengthPy::getFineness(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Float(hypothesis()->GetFineness()); } -namespace Py { - using FemMesh = ExtensionObject; - using TopoShape = ExtensionObject; - template<> bool FemMesh::accepts (PyObject *pyob) const - { - return (pyob && PyObject_TypeCheck(pyob, &(Fem::FemMeshPy::Type))); - } - template<> bool TopoShape::accepts (PyObject *pyob) const - { - return (pyob && PyObject_TypeCheck(pyob, &(Part::TopoShapePy::Type))); - } +namespace Py +{ +using FemMesh = ExtensionObject; +using TopoShape = ExtensionObject; +template<> +bool FemMesh::accepts(PyObject* pyob) const +{ + return (pyob && PyObject_TypeCheck(pyob, &(Fem::FemMeshPy::Type))); } +template<> +bool TopoShape::accepts(PyObject* pyob) const +{ + return (pyob && PyObject_TypeCheck(pyob, &(Part::TopoShapePy::Type))); +} +} // namespace Py Py::Object StdMeshers_AutomaticLengthPy::getLength(const Py::Tuple& args) { @@ -332,12 +365,12 @@ Py::Object StdMeshers_AutomaticLengthPy::getLength(const Py::Tuple& args) Fem::FemMesh* m = mesh.extensionObject()->getFemMeshPtr(); if (shape_or_double.type() == Py::Float().type()) { double len = (double)Py::Float(shape_or_double); - return Py::Float(hypothesis()->GetLength(m->getSMesh(),len)); + return Py::Float(hypothesis()->GetLength(m->getSMesh(), len)); } else { Py::TopoShape shape(shape_or_double); const TopoDS_Shape& s = shape.extensionObject()->getTopoShapePtr()->getShape(); - return Py::Float(hypothesis()->GetLength(m->getSMesh(),s)); + return Py::Float(hypothesis()->GetLength(m->getSMesh(), s)); } } @@ -352,14 +385,14 @@ void StdMeshers_NotConformAllowedPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_NotConformAllowedPy::StdMeshers_NotConformAllowedPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_NotConformAllowed(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_NotConformAllowed(hypId, gen)) +{} #else -StdMeshers_NotConformAllowedPy::StdMeshers_NotConformAllowedPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_NotConformAllowed(hypId, studyId, gen)) -{ -} +StdMeshers_NotConformAllowedPy::StdMeshers_NotConformAllowedPy(int hypId, + int studyId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_NotConformAllowed(hypId, studyId, gen)) +{} #endif StdMeshers_NotConformAllowedPy::~StdMeshers_NotConformAllowedPy() = default; @@ -373,24 +406,32 @@ void StdMeshers_MaxLengthPy::init_type(PyObject* module) add_varargs_method("setLength", &StdMeshers_MaxLengthPy::setLength, "setLength()"); add_varargs_method("getLength", &StdMeshers_MaxLengthPy::getLength, "getLength()"); - add_varargs_method("havePreestimatedLength", &StdMeshers_MaxLengthPy::havePreestimatedLength, "havePreestimatedLength()"); - add_varargs_method("getPreestimatedLength", &StdMeshers_MaxLengthPy::getPreestimatedLength, "getPreestimatedLength()"); - add_varargs_method("setPreestimatedLength", &StdMeshers_MaxLengthPy::setPreestimatedLength, "setPreestimatedLength()"); - add_varargs_method("setUsePreestimatedLength", &StdMeshers_MaxLengthPy::setUsePreestimatedLength, "setUsePreestimatedLength()"); - add_varargs_method("getUsePreestimatedLength", &StdMeshers_MaxLengthPy::getUsePreestimatedLength, "getUsePreestimatedLength()"); + add_varargs_method("havePreestimatedLength", + &StdMeshers_MaxLengthPy::havePreestimatedLength, + "havePreestimatedLength()"); + add_varargs_method("getPreestimatedLength", + &StdMeshers_MaxLengthPy::getPreestimatedLength, + "getPreestimatedLength()"); + add_varargs_method("setPreestimatedLength", + &StdMeshers_MaxLengthPy::setPreestimatedLength, + "setPreestimatedLength()"); + add_varargs_method("setUsePreestimatedLength", + &StdMeshers_MaxLengthPy::setUsePreestimatedLength, + "setUsePreestimatedLength()"); + add_varargs_method("getUsePreestimatedLength", + &StdMeshers_MaxLengthPy::getUsePreestimatedLength, + "getUsePreestimatedLength()"); SMESH_HypothesisPyBase::init_type(module); } #if SMESH_VERSION_MAJOR >= 9 StdMeshers_MaxLengthPy::StdMeshers_MaxLengthPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_MaxLength(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_MaxLength(hypId, gen)) +{} #else StdMeshers_MaxLengthPy::StdMeshers_MaxLengthPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_MaxLength(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_MaxLength(hypId, studyId, gen)) +{} #endif StdMeshers_MaxLengthPy::~StdMeshers_MaxLengthPy() = default; @@ -403,22 +444,25 @@ Py::Object StdMeshers_MaxLengthPy::setLength(const Py::Tuple& args) Py::Object StdMeshers_MaxLengthPy::getLength(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Float(hypothesis()->GetLength()); } Py::Object StdMeshers_MaxLengthPy::havePreestimatedLength(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Boolean(hypothesis()->HavePreestimatedLength()); } Py::Object StdMeshers_MaxLengthPy::getPreestimatedLength(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Float(hypothesis()->GetPreestimatedLength()); } @@ -436,8 +480,9 @@ Py::Object StdMeshers_MaxLengthPy::setUsePreestimatedLength(const Py::Tuple& arg Py::Object StdMeshers_MaxLengthPy::getUsePreestimatedLength(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Boolean(hypothesis()->GetUsePreestimatedLength()); } @@ -457,14 +502,12 @@ void StdMeshers_LocalLengthPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_LocalLengthPy::StdMeshers_LocalLengthPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_LocalLength(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_LocalLength(hypId, gen)) +{} #else StdMeshers_LocalLengthPy::StdMeshers_LocalLengthPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_LocalLength(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_LocalLength(hypId, studyId, gen)) +{} #endif StdMeshers_LocalLengthPy::~StdMeshers_LocalLengthPy() = default; @@ -477,8 +520,9 @@ Py::Object StdMeshers_LocalLengthPy::setLength(const Py::Tuple& args) Py::Object StdMeshers_LocalLengthPy::getLength(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Float(hypothesis()->GetLength()); } @@ -490,8 +534,9 @@ Py::Object StdMeshers_LocalLengthPy::setPrecision(const Py::Tuple& args) Py::Object StdMeshers_LocalLengthPy::getPrecision(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Float(hypothesis()->GetPrecision()); } @@ -509,14 +554,12 @@ void StdMeshers_MaxElementAreaPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_MaxElementAreaPy::StdMeshers_MaxElementAreaPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_MaxElementArea(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_MaxElementArea(hypId, gen)) +{} #else StdMeshers_MaxElementAreaPy::StdMeshers_MaxElementAreaPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_MaxElementArea(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_MaxElementArea(hypId, studyId, gen)) +{} #endif StdMeshers_MaxElementAreaPy::~StdMeshers_MaxElementAreaPy() = default; @@ -529,8 +572,9 @@ Py::Object StdMeshers_MaxElementAreaPy::setMaxArea(const Py::Tuple& args) Py::Object StdMeshers_MaxElementAreaPy::getMaxArea(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Float(hypothesis()->GetMaxArea()); } @@ -545,14 +589,14 @@ void StdMeshers_QuadranglePreferencePy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_QuadranglePreferencePy::StdMeshers_QuadranglePreferencePy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_QuadranglePreference(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_QuadranglePreference(hypId, gen)) +{} #else -StdMeshers_QuadranglePreferencePy::StdMeshers_QuadranglePreferencePy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_QuadranglePreference(hypId, studyId, gen)) -{ -} +StdMeshers_QuadranglePreferencePy::StdMeshers_QuadranglePreferencePy(int hypId, + int studyId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_QuadranglePreference(hypId, studyId, gen)) +{} #endif StdMeshers_QuadranglePreferencePy::~StdMeshers_QuadranglePreferencePy() = default; @@ -568,14 +612,12 @@ void StdMeshers_Quadrangle_2DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_Quadrangle_2DPy::StdMeshers_Quadrangle_2DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Quadrangle_2D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Quadrangle_2D(hypId, gen)) +{} #else StdMeshers_Quadrangle_2DPy::StdMeshers_Quadrangle_2DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Quadrangle_2D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Quadrangle_2D(hypId, studyId, gen)) +{} #endif StdMeshers_Quadrangle_2DPy::~StdMeshers_Quadrangle_2DPy() = default; @@ -591,14 +633,12 @@ void StdMeshers_Regular_1DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_Regular_1DPy::StdMeshers_Regular_1DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Regular_1D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Regular_1D(hypId, gen)) +{} #else StdMeshers_Regular_1DPy::StdMeshers_Regular_1DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Regular_1D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Regular_1D(hypId, studyId, gen)) +{} #endif StdMeshers_Regular_1DPy::~StdMeshers_Regular_1DPy() = default; @@ -614,14 +654,12 @@ void StdMeshers_UseExisting_1DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_UseExisting_1DPy::StdMeshers_UseExisting_1DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_UseExisting_1D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_UseExisting_1D(hypId, gen)) +{} #else StdMeshers_UseExisting_1DPy::StdMeshers_UseExisting_1DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_UseExisting_1D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_UseExisting_1D(hypId, studyId, gen)) +{} #endif StdMeshers_UseExisting_1DPy::~StdMeshers_UseExisting_1DPy() = default; @@ -637,14 +675,12 @@ void StdMeshers_UseExisting_2DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_UseExisting_2DPy::StdMeshers_UseExisting_2DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_UseExisting_2D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_UseExisting_2D(hypId, gen)) +{} #else StdMeshers_UseExisting_2DPy::StdMeshers_UseExisting_2DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_UseExisting_2D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_UseExisting_2D(hypId, studyId, gen)) +{} #endif StdMeshers_UseExisting_2DPy::~StdMeshers_UseExisting_2DPy() = default; @@ -660,14 +696,14 @@ void StdMeshers_CompositeSegment_1DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_CompositeSegment_1DPy::StdMeshers_CompositeSegment_1DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_CompositeSegment_1D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_CompositeSegment_1D(hypId, gen)) +{} #else -StdMeshers_CompositeSegment_1DPy::StdMeshers_CompositeSegment_1DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_CompositeSegment_1D(hypId, studyId, gen)) -{ -} +StdMeshers_CompositeSegment_1DPy::StdMeshers_CompositeSegment_1DPy(int hypId, + int studyId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_CompositeSegment_1D(hypId, studyId, gen)) +{} #endif StdMeshers_CompositeSegment_1DPy::~StdMeshers_CompositeSegment_1DPy() = default; @@ -679,20 +715,20 @@ void StdMeshers_Deflection1DPy::init_type(PyObject* module) behaviors().name("StdMeshers_Deflection1D"); behaviors().doc("StdMeshers_Deflection1D"); - add_varargs_method("setDeflection", &StdMeshers_Deflection1DPy::setDeflection, "setDeflection()"); + add_varargs_method("setDeflection", + &StdMeshers_Deflection1DPy::setDeflection, + "setDeflection()"); SMESH_HypothesisPyBase::init_type(module); } #if SMESH_VERSION_MAJOR >= 9 StdMeshers_Deflection1DPy::StdMeshers_Deflection1DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Deflection1D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Deflection1D(hypId, gen)) +{} #else StdMeshers_Deflection1DPy::StdMeshers_Deflection1DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Deflection1D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Deflection1D(hypId, studyId, gen)) +{} #endif StdMeshers_Deflection1DPy::~StdMeshers_Deflection1DPy() = default; @@ -715,21 +751,19 @@ void StdMeshers_Hexa_3DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_Hexa_3DPy::StdMeshers_Hexa_3DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Hexa_3D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Hexa_3D(hypId, gen)) +{} #else StdMeshers_Hexa_3DPy::StdMeshers_Hexa_3DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Hexa_3D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Hexa_3D(hypId, studyId, gen)) +{} #endif StdMeshers_Hexa_3DPy::~StdMeshers_Hexa_3DPy() = default; // --------------------------------------------------------------------------- -#if SMESH_VERSION_MAJOR < 7 // ----------------------------------------------- +#if SMESH_VERSION_MAJOR < 7 // ----------------------------------------------- void StdMeshers_TrianglePreferencePy::init_type(PyObject* module) { behaviors().name("StdMeshers_TrianglePreference"); @@ -737,13 +771,14 @@ void StdMeshers_TrianglePreferencePy::init_type(PyObject* module) SMESH_HypothesisPyBase::init_type(module); } -StdMeshers_TrianglePreferencePy::StdMeshers_TrianglePreferencePy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_TrianglePreference(hypId, studyId, gen)) -{ -} +StdMeshers_TrianglePreferencePy::StdMeshers_TrianglePreferencePy(int hypId, + int studyId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_TrianglePreference(hypId, studyId, gen)) +{} StdMeshers_TrianglePreferencePy::~StdMeshers_TrianglePreferencePy() = default; -#endif // -------------------------------------------------------------------- +#endif // -------------------------------------------------------------------- // --------------------------------------------------------------------------- @@ -758,27 +793,27 @@ void StdMeshers_StartEndLengthPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_StartEndLengthPy::StdMeshers_StartEndLengthPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_StartEndLength(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_StartEndLength(hypId, gen)) +{} #else StdMeshers_StartEndLengthPy::StdMeshers_StartEndLengthPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_StartEndLength(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_StartEndLength(hypId, studyId, gen)) +{} #endif StdMeshers_StartEndLengthPy::~StdMeshers_StartEndLengthPy() = default; Py::Object StdMeshers_StartEndLengthPy::setLength(const Py::Tuple& args) { - hypothesis()->SetLength((double)Py::Float(args[0]),(bool)Py::Boolean(args[1])); + hypothesis()->SetLength((double)Py::Float(args[0]), + (bool)Py::Boolean(args[1])); return Py::None(); } Py::Object StdMeshers_StartEndLengthPy::getLength(const Py::Tuple& args) { - return Py::Float(hypothesis()->GetLength((bool)Py::Boolean(args[0]))); + return Py::Float( + hypothesis()->GetLength((bool)Py::Boolean(args[0]))); } // --------------------------------------------------------------------------- @@ -787,21 +822,26 @@ void StdMeshers_SegmentLengthAroundVertexPy::init_type(PyObject* module) { behaviors().name("StdMeshers_SegmentLengthAroundVertex"); behaviors().doc("StdMeshers_SegmentLengthAroundVertex"); - add_varargs_method("setLength", &StdMeshers_SegmentLengthAroundVertexPy::setLength, "setLength()"); - add_varargs_method("getLength", &StdMeshers_SegmentLengthAroundVertexPy::getLength, "getLength()"); + add_varargs_method("setLength", + &StdMeshers_SegmentLengthAroundVertexPy::setLength, + "setLength()"); + add_varargs_method("getLength", + &StdMeshers_SegmentLengthAroundVertexPy::getLength, + "getLength()"); SMESH_HypothesisPyBase::init_type(module); } #if SMESH_VERSION_MAJOR >= 9 -StdMeshers_SegmentLengthAroundVertexPy::StdMeshers_SegmentLengthAroundVertexPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_SegmentLengthAroundVertex(hypId, gen)) -{ -} +StdMeshers_SegmentLengthAroundVertexPy::StdMeshers_SegmentLengthAroundVertexPy(int hypId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_SegmentLengthAroundVertex(hypId, gen)) +{} #else -StdMeshers_SegmentLengthAroundVertexPy::StdMeshers_SegmentLengthAroundVertexPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_SegmentLengthAroundVertex(hypId, studyId, gen)) -{ -} +StdMeshers_SegmentLengthAroundVertexPy::StdMeshers_SegmentLengthAroundVertexPy(int hypId, + int studyId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_SegmentLengthAroundVertex(hypId, studyId, gen)) +{} #endif StdMeshers_SegmentLengthAroundVertexPy::~StdMeshers_SegmentLengthAroundVertexPy() = default; @@ -814,8 +854,9 @@ Py::Object StdMeshers_SegmentLengthAroundVertexPy::setLength(const Py::Tuple& ar Py::Object StdMeshers_SegmentLengthAroundVertexPy::getLength(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Float(hypothesis()->GetLength()); } @@ -830,14 +871,14 @@ void StdMeshers_SegmentAroundVertex_0DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_SegmentAroundVertex_0DPy::StdMeshers_SegmentAroundVertex_0DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_SegmentAroundVertex_0D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_SegmentAroundVertex_0D(hypId, gen)) +{} #else -StdMeshers_SegmentAroundVertex_0DPy::StdMeshers_SegmentAroundVertex_0DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_SegmentAroundVertex_0D(hypId, studyId, gen)) -{ -} +StdMeshers_SegmentAroundVertex_0DPy::StdMeshers_SegmentAroundVertex_0DPy(int hypId, + int studyId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_SegmentAroundVertex_0D(hypId, studyId, gen)) +{} #endif StdMeshers_SegmentAroundVertex_0DPy::~StdMeshers_SegmentAroundVertex_0DPy() = default; @@ -853,14 +894,12 @@ void StdMeshers_RadialPrism_3DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_RadialPrism_3DPy::StdMeshers_RadialPrism_3DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_RadialPrism_3D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_RadialPrism_3D(hypId, gen)) +{} #else StdMeshers_RadialPrism_3DPy::StdMeshers_RadialPrism_3DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_RadialPrism_3D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_RadialPrism_3D(hypId, studyId, gen)) +{} #endif StdMeshers_RadialPrism_3DPy::~StdMeshers_RadialPrism_3DPy() = default; @@ -876,14 +915,12 @@ void StdMeshers_QuadraticMeshPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_QuadraticMeshPy::StdMeshers_QuadraticMeshPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_QuadraticMesh(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_QuadraticMesh(hypId, gen)) +{} #else StdMeshers_QuadraticMeshPy::StdMeshers_QuadraticMeshPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_QuadraticMesh(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_QuadraticMesh(hypId, studyId, gen)) +{} #endif StdMeshers_QuadraticMeshPy::~StdMeshers_QuadraticMeshPy() = default; @@ -899,14 +936,14 @@ void StdMeshers_ProjectionSource3DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_ProjectionSource3DPy::StdMeshers_ProjectionSource3DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource3D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource3D(hypId, gen)) +{} #else -StdMeshers_ProjectionSource3DPy::StdMeshers_ProjectionSource3DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource3D(hypId, studyId, gen)) -{ -} +StdMeshers_ProjectionSource3DPy::StdMeshers_ProjectionSource3DPy(int hypId, + int studyId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource3D(hypId, studyId, gen)) +{} #endif StdMeshers_ProjectionSource3DPy::~StdMeshers_ProjectionSource3DPy() = default; @@ -922,14 +959,14 @@ void StdMeshers_ProjectionSource2DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_ProjectionSource2DPy::StdMeshers_ProjectionSource2DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource2D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource2D(hypId, gen)) +{} #else -StdMeshers_ProjectionSource2DPy::StdMeshers_ProjectionSource2DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource2D(hypId, studyId, gen)) -{ -} +StdMeshers_ProjectionSource2DPy::StdMeshers_ProjectionSource2DPy(int hypId, + int studyId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource2D(hypId, studyId, gen)) +{} #endif StdMeshers_ProjectionSource2DPy::~StdMeshers_ProjectionSource2DPy() = default; @@ -945,14 +982,14 @@ void StdMeshers_ProjectionSource1DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_ProjectionSource1DPy::StdMeshers_ProjectionSource1DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource1D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource1D(hypId, gen)) +{} #else -StdMeshers_ProjectionSource1DPy::StdMeshers_ProjectionSource1DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource1D(hypId, studyId, gen)) -{ -} +StdMeshers_ProjectionSource1DPy::StdMeshers_ProjectionSource1DPy(int hypId, + int studyId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_ProjectionSource1D(hypId, studyId, gen)) +{} #endif StdMeshers_ProjectionSource1DPy::~StdMeshers_ProjectionSource1DPy() = default; @@ -968,14 +1005,12 @@ void StdMeshers_Projection_3DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_Projection_3DPy::StdMeshers_Projection_3DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Projection_3D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Projection_3D(hypId, gen)) +{} #else StdMeshers_Projection_3DPy::StdMeshers_Projection_3DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Projection_3D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Projection_3D(hypId, studyId, gen)) +{} #endif StdMeshers_Projection_3DPy::~StdMeshers_Projection_3DPy() = default; @@ -991,14 +1026,12 @@ void StdMeshers_Projection_2DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_Projection_2DPy::StdMeshers_Projection_2DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Projection_2D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Projection_2D(hypId, gen)) +{} #else StdMeshers_Projection_2DPy::StdMeshers_Projection_2DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Projection_2D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Projection_2D(hypId, studyId, gen)) +{} #endif StdMeshers_Projection_2DPy::~StdMeshers_Projection_2DPy() = default; @@ -1014,14 +1047,12 @@ void StdMeshers_Projection_1DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_Projection_1DPy::StdMeshers_Projection_1DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Projection_1D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Projection_1D(hypId, gen)) +{} #else StdMeshers_Projection_1DPy::StdMeshers_Projection_1DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Projection_1D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Projection_1D(hypId, studyId, gen)) +{} #endif StdMeshers_Projection_1DPy::~StdMeshers_Projection_1DPy() = default; @@ -1037,14 +1068,12 @@ void StdMeshers_Prism_3DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_Prism_3DPy::StdMeshers_Prism_3DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Prism_3D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Prism_3D(hypId, gen)) +{} #else StdMeshers_Prism_3DPy::StdMeshers_Prism_3DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_Prism_3D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_Prism_3D(hypId, studyId, gen)) +{} #endif StdMeshers_Prism_3DPy::~StdMeshers_Prism_3DPy() = default; @@ -1055,21 +1084,23 @@ void StdMeshers_NumberOfSegmentsPy::init_type(PyObject* module) { behaviors().name("StdMeshers_NumberOfSegments"); behaviors().doc("StdMeshers_NumberOfSegments"); - add_varargs_method("setNumberOfSegments",&StdMeshers_NumberOfSegmentsPy::setNumSegm,"setNumberOfSegments()"); - add_varargs_method("getNumberOfSegments",&StdMeshers_NumberOfSegmentsPy::getNumSegm,"getNumberOfSegments()"); + add_varargs_method("setNumberOfSegments", + &StdMeshers_NumberOfSegmentsPy::setNumSegm, + "setNumberOfSegments()"); + add_varargs_method("getNumberOfSegments", + &StdMeshers_NumberOfSegmentsPy::getNumSegm, + "getNumberOfSegments()"); SMESH_HypothesisPyBase::init_type(module); } #if SMESH_VERSION_MAJOR >= 9 StdMeshers_NumberOfSegmentsPy::StdMeshers_NumberOfSegmentsPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_NumberOfSegments(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_NumberOfSegments(hypId, gen)) +{} #else StdMeshers_NumberOfSegmentsPy::StdMeshers_NumberOfSegmentsPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_NumberOfSegments(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_NumberOfSegments(hypId, studyId, gen)) +{} #endif StdMeshers_NumberOfSegmentsPy::~StdMeshers_NumberOfSegmentsPy() = default; @@ -1082,8 +1113,9 @@ Py::Object StdMeshers_NumberOfSegmentsPy::setNumSegm(const Py::Tuple& args) Py::Object StdMeshers_NumberOfSegmentsPy::getNumSegm(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Long(hypothesis()->GetNumberOfSegments()); } @@ -1093,21 +1125,23 @@ void StdMeshers_NumberOfLayersPy::init_type(PyObject* module) { behaviors().name("StdMeshers_NumberOfLayers"); behaviors().doc("StdMeshers_NumberOfLayers"); - add_varargs_method("setNumberOfLayers",&StdMeshers_NumberOfLayersPy::setNumLayers,"setNumberOfLayers()"); - add_varargs_method("getNumberOfLayers",&StdMeshers_NumberOfLayersPy::getNumLayers,"getNumberOfLayers()"); + add_varargs_method("setNumberOfLayers", + &StdMeshers_NumberOfLayersPy::setNumLayers, + "setNumberOfLayers()"); + add_varargs_method("getNumberOfLayers", + &StdMeshers_NumberOfLayersPy::getNumLayers, + "getNumberOfLayers()"); SMESH_HypothesisPyBase::init_type(module); } #if SMESH_VERSION_MAJOR >= 9 StdMeshers_NumberOfLayersPy::StdMeshers_NumberOfLayersPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_NumberOfLayers(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_NumberOfLayers(hypId, gen)) +{} #else StdMeshers_NumberOfLayersPy::StdMeshers_NumberOfLayersPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_NumberOfLayers(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_NumberOfLayers(hypId, studyId, gen)) +{} #endif StdMeshers_NumberOfLayersPy::~StdMeshers_NumberOfLayersPy() = default; @@ -1120,8 +1154,9 @@ Py::Object StdMeshers_NumberOfLayersPy::setNumLayers(const Py::Tuple& args) Py::Object StdMeshers_NumberOfLayersPy::getNumLayers(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Long(hypothesis()->GetNumberOfLayers()); } @@ -1136,14 +1171,12 @@ void StdMeshers_MEFISTO_2DPy::init_type(PyObject* module) #if SMESH_VERSION_MAJOR >= 9 StdMeshers_MEFISTO_2DPy::StdMeshers_MEFISTO_2DPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_MEFISTO_2D(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_MEFISTO_2D(hypId, gen)) +{} #else StdMeshers_MEFISTO_2DPy::StdMeshers_MEFISTO_2DPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_MEFISTO_2D(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_MEFISTO_2D(hypId, studyId, gen)) +{} #endif StdMeshers_MEFISTO_2DPy::~StdMeshers_MEFISTO_2DPy() = default; @@ -1154,21 +1187,23 @@ void StdMeshers_MaxElementVolumePy::init_type(PyObject* module) { behaviors().name("StdMeshers_MaxElementVolume"); behaviors().doc("StdMeshers_MaxElementVolume"); - add_varargs_method("setMaxVolume",&StdMeshers_MaxElementVolumePy::setMaxVolume,"setMaxVolume()"); - add_varargs_method("getMaxVolume",&StdMeshers_MaxElementVolumePy::getMaxVolume,"getMaxVolume()"); + add_varargs_method("setMaxVolume", + &StdMeshers_MaxElementVolumePy::setMaxVolume, + "setMaxVolume()"); + add_varargs_method("getMaxVolume", + &StdMeshers_MaxElementVolumePy::getMaxVolume, + "getMaxVolume()"); SMESH_HypothesisPyBase::init_type(module); } #if SMESH_VERSION_MAJOR >= 9 StdMeshers_MaxElementVolumePy::StdMeshers_MaxElementVolumePy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_MaxElementVolume(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_MaxElementVolume(hypId, gen)) +{} #else StdMeshers_MaxElementVolumePy::StdMeshers_MaxElementVolumePy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_MaxElementVolume(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_MaxElementVolume(hypId, studyId, gen)) +{} #endif StdMeshers_MaxElementVolumePy::~StdMeshers_MaxElementVolumePy() = default; @@ -1181,8 +1216,9 @@ Py::Object StdMeshers_MaxElementVolumePy::setMaxVolume(const Py::Tuple& args) Py::Object StdMeshers_MaxElementVolumePy::getMaxVolume(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Float(hypothesis()->GetMaxVolume()); } @@ -1192,21 +1228,19 @@ void StdMeshers_LengthFromEdgesPy::init_type(PyObject* module) { behaviors().name("StdMeshers_LengthFromEdges"); behaviors().doc("StdMeshers_LengthFromEdges"); - add_varargs_method("setMode",&StdMeshers_LengthFromEdgesPy::setMode,"setMode()"); - add_varargs_method("getMode",&StdMeshers_LengthFromEdgesPy::getMode,"getMode()"); + add_varargs_method("setMode", &StdMeshers_LengthFromEdgesPy::setMode, "setMode()"); + add_varargs_method("getMode", &StdMeshers_LengthFromEdgesPy::getMode, "getMode()"); SMESH_HypothesisPyBase::init_type(module); } #if SMESH_VERSION_MAJOR >= 9 StdMeshers_LengthFromEdgesPy::StdMeshers_LengthFromEdgesPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_LengthFromEdges(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_LengthFromEdges(hypId, gen)) +{} #else StdMeshers_LengthFromEdgesPy::StdMeshers_LengthFromEdgesPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_LengthFromEdges(hypId, studyId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_LengthFromEdges(hypId, studyId, gen)) +{} #endif StdMeshers_LengthFromEdgesPy::~StdMeshers_LengthFromEdgesPy() = default; @@ -1219,8 +1253,9 @@ Py::Object StdMeshers_LengthFromEdgesPy::setMode(const Py::Tuple& args) Py::Object StdMeshers_LengthFromEdgesPy::getMode(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::Long(hypothesis()->GetMode()); } @@ -1231,39 +1266,41 @@ void StdMeshers_LayerDistributionPy::init_type(PyObject* module) behaviors().name("StdMeshers_LayerDistribution"); behaviors().doc("StdMeshers_LayerDistribution"); add_varargs_method("setLayerDistribution", - &StdMeshers_LayerDistributionPy::setLayerDistribution, - "setLayerDistribution()"); + &StdMeshers_LayerDistributionPy::setLayerDistribution, + "setLayerDistribution()"); add_varargs_method("getLayerDistribution", - &StdMeshers_LayerDistributionPy::getLayerDistribution, - "getLayerDistribution()"); + &StdMeshers_LayerDistributionPy::getLayerDistribution, + "getLayerDistribution()"); SMESH_HypothesisPyBase::init_type(module); } #if SMESH_VERSION_MAJOR >= 9 StdMeshers_LayerDistributionPy::StdMeshers_LayerDistributionPy(int hypId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_LayerDistribution(hypId, gen)) -{ -} + : SMESH_HypothesisPyBase(new StdMeshers_LayerDistribution(hypId, gen)) +{} #else -StdMeshers_LayerDistributionPy::StdMeshers_LayerDistributionPy(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_HypothesisPyBase(new StdMeshers_LayerDistribution(hypId, studyId, gen)) -{ -} +StdMeshers_LayerDistributionPy::StdMeshers_LayerDistributionPy(int hypId, + int studyId, + SMESH_Gen* gen) + : SMESH_HypothesisPyBase(new StdMeshers_LayerDistribution(hypId, studyId, gen)) +{} #endif StdMeshers_LayerDistributionPy::~StdMeshers_LayerDistributionPy() = default; Py::Object StdMeshers_LayerDistributionPy::setLayerDistribution(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); + } return Py::None(); } Py::Object StdMeshers_LayerDistributionPy::getLayerDistribution(const Py::Tuple& args) { - if (!PyArg_ParseTuple(args.ptr(), "")) + if (!PyArg_ParseTuple(args.ptr(), "")) { throw Py::Exception(); - //return hypothesis()->GetLayerDistribution(); + } + // return hypothesis()->GetLayerDistribution(); return Py::None(); } diff --git a/src/Mod/Fem/App/HypothesisPy.h b/src/Mod/Fem/App/HypothesisPy.h old mode 100755 new mode 100644 index 5b321ac7d4..0526a0398f --- a/src/Mod/Fem/App/HypothesisPy.h +++ b/src/Mod/Fem/App/HypothesisPy.h @@ -24,22 +24,25 @@ #define FEM_HYPOTHESISPY_H #include +#include // needed for SMESH_VERSION_MAJOR #include -#include // needed for SMESH_VERSION_MAJOR class SMESH_Hypothesis; class SMESH_Gen; -namespace Fem { +namespace Fem +{ -class HypothesisPy : public Py::PythonExtension +class HypothesisPy: public Py::PythonExtension { public: using HypothesisPyBase = Py::PythonExtension; explicit HypothesisPy(std::shared_ptr); ~HypothesisPy() override; std::shared_ptr getHypothesis() const - { return hyp; } + { + return hyp; + } private: std::shared_ptr hyp; @@ -47,17 +50,17 @@ private: using Hypothesis = Py::ExtensionObject; -template -class SMESH_HypothesisPy : public Py::PythonExtension +template +class SMESH_HypothesisPy: public Py::PythonExtension { public: using SMESH_HypothesisPyBase = SMESH_HypothesisPy; - static void init_type(PyObject*); // announce properties and methods + static void init_type(PyObject*); // announce properties and methods explicit SMESH_HypothesisPy(SMESH_Hypothesis*); ~SMESH_HypothesisPy() override; - Py::Object getattr(const char *name) override; + Py::Object getattr(const char* name) override; Py::Object repr() override; Py::Object getLibName(const Py::Tuple& args); Py::Object setLibName(const Py::Tuple& args); @@ -72,22 +75,26 @@ public: Py::Object setParametersByMesh(const Py::Tuple& args); std::shared_ptr getHypothesis() const - { return hyp; } + { + return hyp; + } protected: template type* hypothesis() const - { return static_cast(hyp.get()); } + { + return static_cast(hyp.get()); + } private: - static PyObject *PyMake(struct _typeobject *, PyObject *, PyObject *); + static PyObject* PyMake(struct _typeobject*, PyObject*, PyObject*); private: std::shared_ptr hyp; }; #if SMESH_VERSION_MAJOR >= 9 -class StdMeshers_Arithmetic1DPy : public SMESH_HypothesisPy +class StdMeshers_Arithmetic1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -98,7 +105,7 @@ public: Py::Object getLength(const Py::Tuple& args); }; -class StdMeshers_AutomaticLengthPy : public SMESH_HypothesisPy +class StdMeshers_AutomaticLengthPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -110,7 +117,7 @@ public: Py::Object getLength(const Py::Tuple& args); }; -class StdMeshers_NotConformAllowedPy : public SMESH_HypothesisPy +class StdMeshers_NotConformAllowedPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -118,7 +125,7 @@ public: ~StdMeshers_NotConformAllowedPy(); }; -class StdMeshers_MaxLengthPy : public SMESH_HypothesisPy +class StdMeshers_MaxLengthPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -134,7 +141,7 @@ public: Py::Object getUsePreestimatedLength(const Py::Tuple& args); }; -class StdMeshers_LocalLengthPy : public SMESH_HypothesisPy +class StdMeshers_LocalLengthPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -147,7 +154,7 @@ public: Py::Object getPrecision(const Py::Tuple& args); }; -class StdMeshers_MaxElementAreaPy : public SMESH_HypothesisPy +class StdMeshers_MaxElementAreaPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -158,7 +165,8 @@ public: Py::Object getMaxArea(const Py::Tuple& args); }; -class StdMeshers_QuadranglePreferencePy : public SMESH_HypothesisPy +class StdMeshers_QuadranglePreferencePy + : public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -166,7 +174,7 @@ public: ~StdMeshers_QuadranglePreferencePy(); }; -class StdMeshers_Quadrangle_2DPy : public SMESH_HypothesisPy +class StdMeshers_Quadrangle_2DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -174,7 +182,7 @@ public: ~StdMeshers_Quadrangle_2DPy(); }; -class StdMeshers_Regular_1DPy : public SMESH_HypothesisPy +class StdMeshers_Regular_1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -182,7 +190,7 @@ public: ~StdMeshers_Regular_1DPy(); }; -class StdMeshers_UseExisting_1DPy : public SMESH_HypothesisPy +class StdMeshers_UseExisting_1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -190,7 +198,7 @@ public: ~StdMeshers_UseExisting_1DPy(); }; -class StdMeshers_UseExisting_2DPy : public SMESH_HypothesisPy +class StdMeshers_UseExisting_2DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -198,7 +206,7 @@ public: ~StdMeshers_UseExisting_2DPy(); }; -class StdMeshers_CompositeSegment_1DPy : public SMESH_HypothesisPy +class StdMeshers_CompositeSegment_1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -206,7 +214,7 @@ public: ~StdMeshers_CompositeSegment_1DPy(); }; -class StdMeshers_Deflection1DPy : public SMESH_HypothesisPy +class StdMeshers_Deflection1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -216,7 +224,7 @@ public: Py::Object setDeflection(const Py::Tuple& args); }; -class StdMeshers_Hexa_3DPy : public SMESH_HypothesisPy +class StdMeshers_Hexa_3DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -224,7 +232,7 @@ public: ~StdMeshers_Hexa_3DPy(); }; -class StdMeshers_StartEndLengthPy : public SMESH_HypothesisPy +class StdMeshers_StartEndLengthPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -234,7 +242,8 @@ public: Py::Object getLength(const Py::Tuple& args); }; -class StdMeshers_SegmentLengthAroundVertexPy : public SMESH_HypothesisPy +class StdMeshers_SegmentLengthAroundVertexPy + : public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -244,7 +253,8 @@ public: Py::Object getLength(const Py::Tuple& args); }; -class StdMeshers_SegmentAroundVertex_0DPy : public SMESH_HypothesisPy +class StdMeshers_SegmentAroundVertex_0DPy + : public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -252,7 +262,7 @@ public: ~StdMeshers_SegmentAroundVertex_0DPy(); }; -class StdMeshers_RadialPrism_3DPy : public SMESH_HypothesisPy +class StdMeshers_RadialPrism_3DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -260,7 +270,7 @@ public: ~StdMeshers_RadialPrism_3DPy(); }; -class StdMeshers_QuadraticMeshPy : public SMESH_HypothesisPy +class StdMeshers_QuadraticMeshPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -268,7 +278,7 @@ public: ~StdMeshers_QuadraticMeshPy(); }; -class StdMeshers_ProjectionSource3DPy : public SMESH_HypothesisPy +class StdMeshers_ProjectionSource3DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -276,7 +286,7 @@ public: ~StdMeshers_ProjectionSource3DPy(); }; -class StdMeshers_ProjectionSource2DPy : public SMESH_HypothesisPy +class StdMeshers_ProjectionSource2DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -284,7 +294,7 @@ public: ~StdMeshers_ProjectionSource2DPy(); }; -class StdMeshers_ProjectionSource1DPy : public SMESH_HypothesisPy +class StdMeshers_ProjectionSource1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -292,7 +302,7 @@ public: ~StdMeshers_ProjectionSource1DPy(); }; -class StdMeshers_Projection_3DPy : public SMESH_HypothesisPy +class StdMeshers_Projection_3DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -300,7 +310,7 @@ public: ~StdMeshers_Projection_3DPy(); }; -class StdMeshers_Projection_2DPy : public SMESH_HypothesisPy +class StdMeshers_Projection_2DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -308,7 +318,7 @@ public: ~StdMeshers_Projection_2DPy(); }; -class StdMeshers_Projection_1DPy : public SMESH_HypothesisPy +class StdMeshers_Projection_1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -316,7 +326,7 @@ public: ~StdMeshers_Projection_1DPy(); }; -class StdMeshers_Prism_3DPy : public SMESH_HypothesisPy +class StdMeshers_Prism_3DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -324,7 +334,7 @@ public: ~StdMeshers_Prism_3DPy(); }; -class StdMeshers_NumberOfSegmentsPy : public SMESH_HypothesisPy +class StdMeshers_NumberOfSegmentsPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -334,7 +344,7 @@ public: Py::Object getNumSegm(const Py::Tuple& args); }; -class StdMeshers_NumberOfLayersPy : public SMESH_HypothesisPy +class StdMeshers_NumberOfLayersPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -344,7 +354,7 @@ public: Py::Object getNumLayers(const Py::Tuple& args); }; -class StdMeshers_MEFISTO_2DPy : public SMESH_HypothesisPy +class StdMeshers_MEFISTO_2DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -352,7 +362,7 @@ public: ~StdMeshers_MEFISTO_2DPy(); }; -class StdMeshers_MaxElementVolumePy : public SMESH_HypothesisPy +class StdMeshers_MaxElementVolumePy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -362,7 +372,7 @@ public: Py::Object getMaxVolume(const Py::Tuple& args); }; -class StdMeshers_LengthFromEdgesPy : public SMESH_HypothesisPy +class StdMeshers_LengthFromEdgesPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -372,7 +382,7 @@ public: Py::Object getMode(const Py::Tuple& args); }; -class StdMeshers_LayerDistributionPy : public SMESH_HypothesisPy +class StdMeshers_LayerDistributionPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -382,7 +392,7 @@ public: Py::Object getLayerDistribution(const Py::Tuple& args); }; #else -class StdMeshers_Arithmetic1DPy : public SMESH_HypothesisPy +class StdMeshers_Arithmetic1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -393,7 +403,7 @@ public: Py::Object getLength(const Py::Tuple& args); }; -class StdMeshers_AutomaticLengthPy : public SMESH_HypothesisPy +class StdMeshers_AutomaticLengthPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -405,7 +415,7 @@ public: Py::Object getLength(const Py::Tuple& args); }; -class StdMeshers_NotConformAllowedPy : public SMESH_HypothesisPy +class StdMeshers_NotConformAllowedPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -413,7 +423,7 @@ public: ~StdMeshers_NotConformAllowedPy() override; }; -class StdMeshers_MaxLengthPy : public SMESH_HypothesisPy +class StdMeshers_MaxLengthPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -429,7 +439,7 @@ public: Py::Object getUsePreestimatedLength(const Py::Tuple& args); }; -class StdMeshers_LocalLengthPy : public SMESH_HypothesisPy +class StdMeshers_LocalLengthPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -442,7 +452,7 @@ public: Py::Object getPrecision(const Py::Tuple& args); }; -class StdMeshers_MaxElementAreaPy : public SMESH_HypothesisPy +class StdMeshers_MaxElementAreaPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -453,7 +463,8 @@ public: Py::Object getMaxArea(const Py::Tuple& args); }; -class StdMeshers_QuadranglePreferencePy : public SMESH_HypothesisPy +class StdMeshers_QuadranglePreferencePy + : public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -461,7 +472,7 @@ public: ~StdMeshers_QuadranglePreferencePy() override; }; -class StdMeshers_Quadrangle_2DPy : public SMESH_HypothesisPy +class StdMeshers_Quadrangle_2DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -469,7 +480,7 @@ public: ~StdMeshers_Quadrangle_2DPy() override; }; -class StdMeshers_Regular_1DPy : public SMESH_HypothesisPy +class StdMeshers_Regular_1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -477,7 +488,7 @@ public: ~StdMeshers_Regular_1DPy() override; }; -class StdMeshers_UseExisting_1DPy : public SMESH_HypothesisPy +class StdMeshers_UseExisting_1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -485,7 +496,7 @@ public: ~StdMeshers_UseExisting_1DPy() override; }; -class StdMeshers_UseExisting_2DPy : public SMESH_HypothesisPy +class StdMeshers_UseExisting_2DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -493,7 +504,7 @@ public: ~StdMeshers_UseExisting_2DPy() override; }; -class StdMeshers_CompositeSegment_1DPy : public SMESH_HypothesisPy +class StdMeshers_CompositeSegment_1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -501,7 +512,7 @@ public: ~StdMeshers_CompositeSegment_1DPy() override; }; -class StdMeshers_Deflection1DPy : public SMESH_HypothesisPy +class StdMeshers_Deflection1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -511,24 +522,24 @@ public: Py::Object setDeflection(const Py::Tuple& args); }; -class StdMeshers_Hexa_3DPy : public SMESH_HypothesisPy +class StdMeshers_Hexa_3DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); StdMeshers_Hexa_3DPy(int hypId, int studyId, SMESH_Gen* gen); ~StdMeshers_Hexa_3DPy() override; }; -#if SMESH_VERSION_MAJOR < 7 // ----------------------------------------------- -class StdMeshers_TrianglePreferencePy : public SMESH_HypothesisPy +#if SMESH_VERSION_MAJOR < 7 // ----------------------------------------------- +class StdMeshers_TrianglePreferencePy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); StdMeshers_TrianglePreferencePy(int hypId, int studyId, SMESH_Gen* gen); ~StdMeshers_TrianglePreferencePy(); }; -#endif // -------------------------------------------------------------------- +#endif // -------------------------------------------------------------------- -class StdMeshers_StartEndLengthPy : public SMESH_HypothesisPy +class StdMeshers_StartEndLengthPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -538,7 +549,8 @@ public: Py::Object getLength(const Py::Tuple& args); }; -class StdMeshers_SegmentLengthAroundVertexPy : public SMESH_HypothesisPy +class StdMeshers_SegmentLengthAroundVertexPy + : public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -548,7 +560,8 @@ public: Py::Object getLength(const Py::Tuple& args); }; -class StdMeshers_SegmentAroundVertex_0DPy : public SMESH_HypothesisPy +class StdMeshers_SegmentAroundVertex_0DPy + : public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -556,7 +569,7 @@ public: ~StdMeshers_SegmentAroundVertex_0DPy() override; }; -class StdMeshers_RadialPrism_3DPy : public SMESH_HypothesisPy +class StdMeshers_RadialPrism_3DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -564,7 +577,7 @@ public: ~StdMeshers_RadialPrism_3DPy() override; }; -class StdMeshers_QuadraticMeshPy : public SMESH_HypothesisPy +class StdMeshers_QuadraticMeshPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -572,63 +585,63 @@ public: ~StdMeshers_QuadraticMeshPy() override; }; -class StdMeshers_ProjectionSource3DPy : public SMESH_HypothesisPy +class StdMeshers_ProjectionSource3DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); StdMeshers_ProjectionSource3DPy(int hypId, int studyId, SMESH_Gen* gen); ~StdMeshers_ProjectionSource3DPy() override; - //Py::Object setSource3DShape(const Py::Tuple& args); - //Py::Object getSource3DShape(const Py::Tuple& args); - //Py::Object setSourceMesh(const Py::Tuple& args); - //Py::Object getSourceMesh(const Py::Tuple& args); - //Py::Object setVertexAssociation(const Py::Tuple& args); - //Py::Object getSourceVertex(const Py::Tuple& args); - //Py::Object getTargetVertex(const Py::Tuple& args); - //Py::Object hasVertexAssociation(const Py::Tuple& args); - //Py::Object getStoreParams(const Py::Tuple& args); - //Py::Object restoreParams(const Py::Tuple& args); + // Py::Object setSource3DShape(const Py::Tuple& args); + // Py::Object getSource3DShape(const Py::Tuple& args); + // Py::Object setSourceMesh(const Py::Tuple& args); + // Py::Object getSourceMesh(const Py::Tuple& args); + // Py::Object setVertexAssociation(const Py::Tuple& args); + // Py::Object getSourceVertex(const Py::Tuple& args); + // Py::Object getTargetVertex(const Py::Tuple& args); + // Py::Object hasVertexAssociation(const Py::Tuple& args); + // Py::Object getStoreParams(const Py::Tuple& args); + // Py::Object restoreParams(const Py::Tuple& args); }; -class StdMeshers_ProjectionSource2DPy : public SMESH_HypothesisPy +class StdMeshers_ProjectionSource2DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); StdMeshers_ProjectionSource2DPy(int hypId, int studyId, SMESH_Gen* gen); ~StdMeshers_ProjectionSource2DPy() override; - //Py::Object setSourceFace(const Py::Tuple& args); - //Py::Object getSourceFace(const Py::Tuple& args); - //Py::Object isCompoundSource(const Py::Tuple& args); - //Py::Object setSourceMesh(const Py::Tuple& args); - //Py::Object getSourceMesh(const Py::Tuple& args); - //Py::Object setVertexAssociation(const Py::Tuple& args); - //Py::Object getSourceVertex(const Py::Tuple& args); - //Py::Object getTargetVertex(const Py::Tuple& args); - //Py::Object hasVertexAssociation(const Py::Tuple& args); - //Py::Object getStoreParams(const Py::Tuple& args); - //Py::Object restoreParams(const Py::Tuple& args); + // Py::Object setSourceFace(const Py::Tuple& args); + // Py::Object getSourceFace(const Py::Tuple& args); + // Py::Object isCompoundSource(const Py::Tuple& args); + // Py::Object setSourceMesh(const Py::Tuple& args); + // Py::Object getSourceMesh(const Py::Tuple& args); + // Py::Object setVertexAssociation(const Py::Tuple& args); + // Py::Object getSourceVertex(const Py::Tuple& args); + // Py::Object getTargetVertex(const Py::Tuple& args); + // Py::Object hasVertexAssociation(const Py::Tuple& args); + // Py::Object getStoreParams(const Py::Tuple& args); + // Py::Object restoreParams(const Py::Tuple& args); }; -class StdMeshers_ProjectionSource1DPy : public SMESH_HypothesisPy +class StdMeshers_ProjectionSource1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); StdMeshers_ProjectionSource1DPy(int hypId, int studyId, SMESH_Gen* gen); ~StdMeshers_ProjectionSource1DPy() override; - //Py::Object setSourceEdge(const Py::Tuple& args); - //Py::Object getSourceEdge(const Py::Tuple& args); - //Py::Object isCompoundSource(const Py::Tuple& args); - //Py::Object setSourceMesh(const Py::Tuple& args); - //Py::Object getSourceMesh(const Py::Tuple& args); - //Py::Object setVertexAssociation(const Py::Tuple& args); - //Py::Object getSourceVertex(const Py::Tuple& args); - //Py::Object getTargetVertex(const Py::Tuple& args); - //Py::Object hasVertexAssociation(const Py::Tuple& args); - //Py::Object getStoreParams(const Py::Tuple& args); - //Py::Object restoreParams(const Py::Tuple& args); + // Py::Object setSourceEdge(const Py::Tuple& args); + // Py::Object getSourceEdge(const Py::Tuple& args); + // Py::Object isCompoundSource(const Py::Tuple& args); + // Py::Object setSourceMesh(const Py::Tuple& args); + // Py::Object getSourceMesh(const Py::Tuple& args); + // Py::Object setVertexAssociation(const Py::Tuple& args); + // Py::Object getSourceVertex(const Py::Tuple& args); + // Py::Object getTargetVertex(const Py::Tuple& args); + // Py::Object hasVertexAssociation(const Py::Tuple& args); + // Py::Object getStoreParams(const Py::Tuple& args); + // Py::Object restoreParams(const Py::Tuple& args); }; -class StdMeshers_Projection_3DPy : public SMESH_HypothesisPy +class StdMeshers_Projection_3DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -636,7 +649,7 @@ public: ~StdMeshers_Projection_3DPy() override; }; -class StdMeshers_Projection_2DPy : public SMESH_HypothesisPy +class StdMeshers_Projection_2DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -644,7 +657,7 @@ public: ~StdMeshers_Projection_2DPy() override; }; -class StdMeshers_Projection_1DPy : public SMESH_HypothesisPy +class StdMeshers_Projection_1DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -652,7 +665,7 @@ public: ~StdMeshers_Projection_1DPy() override; }; -class StdMeshers_Prism_3DPy : public SMESH_HypothesisPy +class StdMeshers_Prism_3DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -660,7 +673,7 @@ public: ~StdMeshers_Prism_3DPy() override; }; -class StdMeshers_NumberOfSegmentsPy : public SMESH_HypothesisPy +class StdMeshers_NumberOfSegmentsPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -670,7 +683,7 @@ public: Py::Object getNumSegm(const Py::Tuple& args); }; -class StdMeshers_NumberOfLayersPy : public SMESH_HypothesisPy +class StdMeshers_NumberOfLayersPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -680,7 +693,7 @@ public: Py::Object getNumLayers(const Py::Tuple& args); }; -class StdMeshers_MEFISTO_2DPy : public SMESH_HypothesisPy +class StdMeshers_MEFISTO_2DPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -688,7 +701,7 @@ public: ~StdMeshers_MEFISTO_2DPy() override; }; -class StdMeshers_MaxElementVolumePy : public SMESH_HypothesisPy +class StdMeshers_MaxElementVolumePy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -698,7 +711,7 @@ public: Py::Object getMaxVolume(const Py::Tuple& args); }; -class StdMeshers_LengthFromEdgesPy : public SMESH_HypothesisPy +class StdMeshers_LengthFromEdgesPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -708,7 +721,7 @@ public: Py::Object getMode(const Py::Tuple& args); }; -class StdMeshers_LayerDistributionPy : public SMESH_HypothesisPy +class StdMeshers_LayerDistributionPy: public SMESH_HypothesisPy { public: static void init_type(PyObject*); @@ -719,6 +732,6 @@ public: }; #endif -} // namespace Fem +} // namespace Fem -#endif // FEM_HYPOTHESISPY_H +#endif // FEM_HYPOTHESISPY_H diff --git a/src/Mod/Fem/App/PreCompiled.h b/src/Mod/Fem/App/PreCompiled.h index 17c6982089..a23b894be9 100644 --- a/src/Mod/Fem/App/PreCompiled.h +++ b/src/Mod/Fem/App/PreCompiled.h @@ -26,8 +26,8 @@ #include #ifdef _MSC_VER -# pragma warning(disable : 4290) -# pragma warning(disable : 4275) +#pragma warning(disable : 4290) +#pragma warning(disable : 4275) #endif #ifdef _PreComp_ @@ -56,19 +56,19 @@ #include // Salomesh +#include #include #include #include #include -#include +#include +#include +#include #include #include #include #include #include -#include -#include -#include #include #include @@ -78,40 +78,40 @@ #include #include #include +#include #include #include #include -#include #include #include #include #include -#include -#include -#include #include #include #include +#include +#include +#include +#include #include #include -#include #include #include #include #include #include #if SMESH_VERSION_MAJOR < 7 -# include +#include #endif #include // Opencascade #include -#include -#include #include +#include +#include #if OCC_VERSION_HEX < 0x070600 -# include +#include #endif #include #include @@ -123,20 +123,15 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -148,6 +143,11 @@ #include #include #include +#include +#include +#include +#include +#include // VTK #include @@ -190,10 +190,10 @@ // Netgen #ifdef FCWithNetgen -# include -# include -# include +#include +#include +#include #endif -#endif // _PreComp_ +#endif // _PreComp_ #endif diff --git a/src/Mod/Fem/App/PropertyPostDataObject.cpp b/src/Mod/Fem/App/PropertyPostDataObject.cpp index 42ea5b06a2..f416dd7aa2 100644 --- a/src/Mod/Fem/App/PropertyPostDataObject.cpp +++ b/src/Mod/Fem/App/PropertyPostDataObject.cpp @@ -23,21 +23,21 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -54,45 +54,48 @@ using namespace Fem; -TYPESYSTEM_SOURCE(Fem::PropertyPostDataObject , App::Property) +TYPESYSTEM_SOURCE(Fem::PropertyPostDataObject, App::Property) PropertyPostDataObject::PropertyPostDataObject() = default; PropertyPostDataObject::~PropertyPostDataObject() = default; -void PropertyPostDataObject::scaleDataObject(vtkDataObject *dataObject, double s) +void PropertyPostDataObject::scaleDataObject(vtkDataObject* dataObject, double s) { - auto scalePoints = [](vtkPoints *points, double s) { + auto scalePoints = [](vtkPoints* points, double s) { for (vtkIdType i = 0; i < points->GetNumberOfPoints(); i++) { double xyz[3]; points->GetPoint(i, xyz); - for (double & j : xyz) + for (double& j : xyz) { j *= s; + } points->SetPoint(i, xyz); } }; if (dataObject->GetDataObjectType() == VTK_POLY_DATA) { - vtkPolyData *dataSet = vtkPolyData::SafeDownCast(dataObject); + vtkPolyData* dataSet = vtkPolyData::SafeDownCast(dataObject); scalePoints(dataSet->GetPoints(), s); } else if (dataObject->GetDataObjectType() == VTK_STRUCTURED_GRID) { - vtkStructuredGrid *dataSet = vtkStructuredGrid::SafeDownCast(dataObject); + vtkStructuredGrid* dataSet = vtkStructuredGrid::SafeDownCast(dataObject); scalePoints(dataSet->GetPoints(), s); } else if (dataObject->GetDataObjectType() == VTK_UNSTRUCTURED_GRID) { - vtkUnstructuredGrid *dataSet = vtkUnstructuredGrid::SafeDownCast(dataObject); + vtkUnstructuredGrid* dataSet = vtkUnstructuredGrid::SafeDownCast(dataObject); scalePoints(dataSet->GetPoints(), s); } else if (dataObject->GetDataObjectType() == VTK_MULTIBLOCK_DATA_SET) { - vtkMultiBlockDataSet *dataSet = vtkMultiBlockDataSet::SafeDownCast(dataObject); - for (unsigned int i = 0; i < dataSet->GetNumberOfBlocks(); i++) + vtkMultiBlockDataSet* dataSet = vtkMultiBlockDataSet::SafeDownCast(dataObject); + for (unsigned int i = 0; i < dataSet->GetNumberOfBlocks(); i++) { scaleDataObject(dataSet->GetBlock(i), s); + } } else if (dataObject->GetDataObjectType() == VTK_MULTIPIECE_DATA_SET) { - vtkMultiPieceDataSet *dataSet = vtkMultiPieceDataSet::SafeDownCast(dataObject); - for (unsigned int i = 0; i < dataSet->GetNumberOfPieces(); i++) + vtkMultiPieceDataSet* dataSet = vtkMultiPieceDataSet::SafeDownCast(dataObject); + for (unsigned int i = 0; i < dataSet->GetNumberOfPieces(); i++) { scaleDataObject(dataSet->GetPiece(i), s); + } } } @@ -105,7 +108,7 @@ void PropertyPostDataObject::scale(double s) } } -void PropertyPostDataObject::setValue(const vtkSmartPointer &ds) +void PropertyPostDataObject::setValue(const vtkSmartPointer& ds) { aboutToSetValue(); @@ -120,7 +123,7 @@ void PropertyPostDataObject::setValue(const vtkSmartPointer &ds) hasSetValue(); } -const vtkSmartPointer &PropertyPostDataObject::getValue() const +const vtkSmartPointer& PropertyPostDataObject::getValue() const { return m_dataObject; } @@ -140,26 +143,26 @@ bool PropertyPostDataObject::isDataSet() int PropertyPostDataObject::getDataType() { - if (!m_dataObject) + if (!m_dataObject) { return -1; + } return m_dataObject->GetDataObjectType(); } -PyObject *PropertyPostDataObject::getPyObject() +PyObject* PropertyPostDataObject::getPyObject() { - //TODO: fetch the vtk python object from the data set and return it + // TODO: fetch the vtk python object from the data set and return it return Py::new_reference_to(Py::None()); } -void PropertyPostDataObject::setPyObject(PyObject * /*value*/) -{ -} +void PropertyPostDataObject::setPyObject(PyObject* /*value*/) +{} -App::Property *PropertyPostDataObject::Copy() const +App::Property* PropertyPostDataObject::Copy() const { - PropertyPostDataObject *prop = new PropertyPostDataObject(); + PropertyPostDataObject* prop = new PropertyPostDataObject(); if (m_dataObject) { prop->createDataObjectByExternalType(m_dataObject); @@ -204,10 +207,10 @@ void PropertyPostDataObject::createDataObjectByExternalType(vtkSmartPointer(from).m_dataObject; + m_dataObject = dynamic_cast(from).m_dataObject; hasSetValue(); } @@ -218,34 +221,35 @@ unsigned int PropertyPostDataObject::getMemSize() const void PropertyPostDataObject::getPaths(std::vector& /*paths*/) const { - /* paths.push_back(App::ObjectIdentifier(getContainer()) - << App::ObjectIdentifier::Component::SimpleComponent(getName()) - << App::ObjectIdentifier::Component::SimpleComponent( - App::ObjectIdentifier::String("ShapeType"))); - paths.push_back(App::ObjectIdentifier(getContainer()) - << App::ObjectIdentifier::Component::SimpleComponent(getName()) - << App::ObjectIdentifier::Component::SimpleComponent( - App::ObjectIdentifier::String("Orientation"))); - paths.push_back(App::ObjectIdentifier(getContainer()) - << App::ObjectIdentifier::Component::SimpleComponent(getName()) - << App::ObjectIdentifier::Component::SimpleComponent( - App::ObjectIdentifier::String("Length"))); - paths.push_back(App::ObjectIdentifier(getContainer()) - << App::ObjectIdentifier::Component::SimpleComponent(getName()) - << App::ObjectIdentifier::Component::SimpleComponent( - App::ObjectIdentifier::String("Area"))); - paths.push_back(App::ObjectIdentifier(getContainer()) - << App::ObjectIdentifier::Component::SimpleComponent(getName()) - << App::ObjectIdentifier::Component::SimpleComponent( - App::ObjectIdentifier::String("Volume"))); - */ + /* paths.push_back(App::ObjectIdentifier(getContainer()) + << App::ObjectIdentifier::Component::SimpleComponent(getName()) + << App::ObjectIdentifier::Component::SimpleComponent( + App::ObjectIdentifier::String("ShapeType"))); + paths.push_back(App::ObjectIdentifier(getContainer()) + << App::ObjectIdentifier::Component::SimpleComponent(getName()) + << App::ObjectIdentifier::Component::SimpleComponent( + App::ObjectIdentifier::String("Orientation"))); + paths.push_back(App::ObjectIdentifier(getContainer()) + << App::ObjectIdentifier::Component::SimpleComponent(getName()) + << App::ObjectIdentifier::Component::SimpleComponent( + App::ObjectIdentifier::String("Length"))); + paths.push_back(App::ObjectIdentifier(getContainer()) + << App::ObjectIdentifier::Component::SimpleComponent(getName()) + << App::ObjectIdentifier::Component::SimpleComponent( + App::ObjectIdentifier::String("Area"))); + paths.push_back(App::ObjectIdentifier(getContainer()) + << App::ObjectIdentifier::Component::SimpleComponent(getName()) + << App::ObjectIdentifier::Component::SimpleComponent( + App::ObjectIdentifier::String("Volume"))); + */ } -void PropertyPostDataObject::Save(Base::Writer &writer) const +void PropertyPostDataObject::Save(Base::Writer& writer) const { std::string extension; - if (!m_dataObject) + if (!m_dataObject) { return; + } switch (m_dataObject->GetDataObjectType()) { @@ -262,35 +266,35 @@ void PropertyPostDataObject::Save(Base::Writer &writer) const extension = "vtu"; break; case VTK_UNIFORM_GRID: - extension = "vti";//image data + extension = "vti"; // image data break; - //TODO:multi-datasets use multiple files, this needs to be implemented specially -// case VTK_COMPOSITE_DATA_SET: -// prop->m_dataObject = vtkCompositeDataSet::New(); -// break; -// case VTK_MULTIBLOCK_DATA_SET: -// prop->m_dataObject = vtkMultiBlockDataSet::New(); -// break; -// case VTK_MULTIPIECE_DATA_SET: -// prop->m_dataObject = vtkMultiPieceDataSet::New(); -// break; + // TODO:multi-datasets use multiple files, this needs to be implemented specially + // case VTK_COMPOSITE_DATA_SET: + // prop->m_dataObject = vtkCompositeDataSet::New(); + // break; + // case VTK_MULTIBLOCK_DATA_SET: + // prop->m_dataObject = vtkMultiBlockDataSet::New(); + // break; + // case VTK_MULTIPIECE_DATA_SET: + // prop->m_dataObject = vtkMultiPieceDataSet::New(); + // break; default: break; }; if (!writer.isForceXML()) { std::string file = "Data." + extension; - writer.Stream() << writer.ind() << "" << std::endl; } } -void PropertyPostDataObject::Restore(Base::XMLReader &reader) +void PropertyPostDataObject::Restore(Base::XMLReader& reader) { reader.readElement("Data"); - if (!reader.hasAttribute("file")) + if (!reader.hasAttribute("file")) { return; + } std::string file(reader.getAttribute("file")); @@ -300,12 +304,13 @@ void PropertyPostDataObject::Restore(Base::XMLReader &reader) } } -void PropertyPostDataObject::SaveDocFile(Base::Writer &writer) const +void PropertyPostDataObject::SaveDocFile(Base::Writer& writer) const { // If the shape is empty we simply store nothing. The file size will be 0 which // can be checked when reading in the data. - if (!m_dataObject) + if (!m_dataObject) { return; + } // create a temporary file and copy the content to the zip stream // once the tmp. filename is known use always the same because otherwise @@ -319,7 +324,7 @@ void PropertyPostDataObject::SaveDocFile(Base::Writer &writer) const #ifdef VTK_CELL_ARRAY_V2 // Looks like an invalid data object that causes a crash with vtk9 - vtkUnstructuredGrid *dataGrid = vtkUnstructuredGrid::SafeDownCast(m_dataObject); + vtkUnstructuredGrid* dataGrid = vtkUnstructuredGrid::SafeDownCast(m_dataObject); if (dataGrid && (dataGrid->GetPiece() < 0 || dataGrid->GetNumberOfPoints() <= 0)) { std::cerr << "PropertyPostDataObject::SaveDocFile: ignore empty vtkUnstructuredGrid\n"; return; @@ -331,11 +336,12 @@ void PropertyPostDataObject::SaveDocFile(Base::Writer &writer) const // not be created we should not abort. // We only print an error message but continue writing the next files to the // stream... - App::PropertyContainer *father = this->getContainer(); + App::PropertyContainer* father = this->getContainer(); if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) { - App::DocumentObject *obj = static_cast(father); + App::DocumentObject* obj = static_cast(father); Base::Console().Error("Dataset of '%s' cannot be written to vtk file '%s'\n", - obj->Label.getValue(), fi.filePath().c_str()); + obj->Label.getValue(), + fi.filePath().c_str()); } else { Base::Console().Error("Cannot save vtk file '%s'\n", fi.filePath().c_str()); @@ -348,7 +354,7 @@ void PropertyPostDataObject::SaveDocFile(Base::Writer &writer) const Base::ifstream file(fi, std::ios::in | std::ios::binary); if (file) { - std::streambuf *buf = file.rdbuf(); + std::streambuf* buf = file.rdbuf(); writer.Stream() << buf; } @@ -357,7 +363,7 @@ void PropertyPostDataObject::SaveDocFile(Base::Writer &writer) const fi.deleteFile(); } -void PropertyPostDataObject::RestoreDocFile(Base::Reader &reader) +void PropertyPostDataObject::RestoreDocFile(Base::Reader& reader) { Base::FileInfo xml(reader.getFileName()); // create a temporary file and copy the content from the zip stream @@ -367,7 +373,7 @@ void PropertyPostDataObject::RestoreDocFile(Base::Reader &reader) Base::ofstream file(fi, std::ios::out | std::ios::binary); unsigned long ulSize = 0; if (reader) { - std::streambuf *buf = file.rdbuf(); + std::streambuf* buf = file.rdbuf(); reader >> buf; file.flush(); ulSize = buf->pubseekoff(0, std::ios::cur, std::ios::in); @@ -381,16 +387,21 @@ void PropertyPostDataObject::RestoreDocFile(Base::Reader &reader) // TODO: read in of composite data structures need to be coded, // including replace of "GetOutputAsDataSet()" vtkSmartPointer xmlReader; - if (extension == "vtp") + if (extension == "vtp") { xmlReader = vtkSmartPointer::New(); - else if (extension == "vts") + } + else if (extension == "vts") { xmlReader = vtkSmartPointer::New(); - else if (extension == "vtr") + } + else if (extension == "vtr") { xmlReader = vtkSmartPointer::New(); - else if (extension == "vtu") + } + else if (extension == "vtu") { xmlReader = vtkSmartPointer::New(); - else if (extension == "vti") + } + else if (extension == "vti") { xmlReader = vtkSmartPointer::New(); + } xmlReader->SetFileName(fi.filePath().c_str()); xmlReader->Update(); @@ -400,11 +411,12 @@ void PropertyPostDataObject::RestoreDocFile(Base::Reader &reader) // not be read it's NOT an indication for an invalid input stream 'reader'. // We only print an error message but continue reading the next files from the // stream... - App::PropertyContainer *father = this->getContainer(); + App::PropertyContainer* father = this->getContainer(); if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) { - App::DocumentObject *obj = static_cast(father); + App::DocumentObject* obj = static_cast(father); Base::Console().Error("Dataset file '%s' with data of '%s' seems to be empty\n", - fi.filePath().c_str(), obj->Label.getValue()); + fi.filePath().c_str(), + obj->Label.getValue()); } else { Base::Console().Warning("Loaded Dataset file '%s' seems to be empty\n", diff --git a/src/Mod/Fem/App/PropertyPostDataObject.h b/src/Mod/Fem/App/PropertyPostDataObject.h index c950177647..afd8b0b8fb 100644 --- a/src/Mod/Fem/App/PropertyPostDataObject.h +++ b/src/Mod/Fem/App/PropertyPostDataObject.h @@ -36,7 +36,7 @@ namespace Fem /** The vtk data set property class. * @author Stefan Tröger */ -class FemExport PropertyPostDataObject : public App::Property +class FemExport PropertyPostDataObject: public App::Property { TYPESYSTEM_HEADER_WITH_OVERRIDE(); @@ -55,30 +55,30 @@ public: /// check if we hold a dataset or a dataobject (which would mean a composite data structure) bool isDataSet(); bool isComposite(); - int getDataType(); + int getDataType(); //@} /** @name Python interface */ //@{ PyObject* getPyObject() override; - void setPyObject(PyObject *value) override; + void setPyObject(PyObject* value) override; //@} /** @name Save/restore */ //@{ - void Save (Base::Writer &writer) const override; - void Restore(Base::XMLReader &reader) override; + void Save(Base::Writer& writer) const override; + void Restore(Base::XMLReader& reader) override; - void SaveDocFile (Base::Writer &writer) const override; - void RestoreDocFile(Base::Reader &reader) override; + void SaveDocFile(Base::Writer& writer) const override; + void RestoreDocFile(Base::Reader& reader) override; - App::Property *Copy() const override; - void Paste(const App::Property &from) override; - unsigned int getMemSize () const override; + App::Property* Copy() const override; + void Paste(const App::Property& from) override; + unsigned int getMemSize() const override; //@} /// Get valid paths for this property; used by auto completer - void getPaths(std::vector & paths) const override; + void getPaths(std::vector& paths) const override; private: static void scaleDataObject(vtkDataObject*, double s); @@ -88,7 +88,7 @@ protected: vtkSmartPointer m_dataObject; }; -} //namespace FEM +} // namespace Fem -#endif // FEM_PROPERTYPOSTDATASET_H +#endif // FEM_PROPERTYPOSTDATASET_H