diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index 002ef0c635..0df7f589db 100644 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -130,7 +130,7 @@ SET(FemSet_SRCS FemSetObject.h FemSetNodesObject.cpp FemSetNodesObject.h - FemSetElementNodesObject.cpp + FemSetElementNodesObject.cpp FemSetElementNodesObject.h FemSetElementsObject.cpp FemSetElementsObject.h diff --git a/src/Mod/Fem/App/FemSetElementNodesObject.cpp b/src/Mod/Fem/App/FemSetElementNodesObject.cpp index 63cd33847d..52f2925172 100644 --- a/src/Mod/Fem/App/FemSetElementNodesObject.cpp +++ b/src/Mod/Fem/App/FemSetElementNodesObject.cpp @@ -38,7 +38,11 @@ PROPERTY_SOURCE(Fem::FemSetElementNodesObject, Fem::FemSetObject) FemSetElementNodesObject::FemSetElementNodesObject() { - ADD_PROPERTY_TYPE(Elements, (), "Element indexes", Prop_None, "Elements belonging to the ElementSet"); + ADD_PROPERTY_TYPE(Elements, + (), + "Element indexes", + Prop_None, + "Elements belonging to the ElementSet"); } FemSetElementNodesObject::~FemSetElementNodesObject() = default; @@ -56,4 +60,3 @@ PyObject* FemSetElementNodesObject::getPyObject() } return Py::new_reference_to(PythonObject); } - diff --git a/src/Mod/Fem/App/FemSetElementNodesObject.h b/src/Mod/Fem/App/FemSetElementNodesObject.h index 7a0de630dd..ed79ccbb99 100644 --- a/src/Mod/Fem/App/FemSetElementNodesObject.h +++ b/src/Mod/Fem/App/FemSetElementNodesObject.h @@ -34,7 +34,7 @@ namespace Fem { -class FemExport FemSetElementNodesObject : public FemSetObject +class FemExport FemSetElementNodesObject: public FemSetObject { PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemSetElementNodesObject); @@ -56,10 +56,8 @@ public: } short mustExecute() const override; PyObject* getPyObject() override; - static std::string elementsName; // = "ElementsSet"; - static std::string uniqueElementsName; // "ElementsSet" latest name - - + static std::string elementsName; // = "ElementsSet"; + static std::string uniqueElementsName; // "ElementsSet" latest name }; } // namespace Fem diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index 0b18a4f285..7fe63998dc 100644 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (c) 2023 Peter McB * - * additional statement(s) for element sets * + * additional statement(s) for element sets * * * * added to: AppFemGui.cpp * * Copyright (c) 2008 Jürgen Riegel * @@ -46,7 +46,7 @@ #include "ViewProviderFemMeshShape.h" #include "ViewProviderFemMeshShapeNetgen.h" #include "ViewProviderSetElements.h" -#include "ViewProviderSetElementNodes.h" +#include "ViewProviderSetElementNodes.h" #include "ViewProviderSetFaces.h" #include "ViewProviderSetGeometry.h" #include "ViewProviderSetNodes.h" diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index fff0c46727..f57d546a87 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -248,7 +248,7 @@ SET(FemGui_SRCS_TaskBoxes TaskObjectName.h TaskCreateElementSet.ui TaskCreateElementSet.cpp - TaskCreateElementSet.h + TaskCreateElementSet.h TaskCreateNodeSet.ui TaskCreateNodeSet.cpp TaskCreateNodeSet.h diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index f2ed1116c0..094d1be668 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -1187,7 +1187,7 @@ bool CmdFemCreateNodesSet::isActive() } //=========================================================================== -// start of Erase Elements code +// start of Erase Elements code //=========================================================================== std::string Fem::FemSetElementNodesObject::elementsName; std::string Fem::FemSetElementNodesObject::uniqueElementsName; @@ -1195,12 +1195,13 @@ std::string Fem::FemSetElementNodesObject::uniqueElementsName; DEF_STD_CMD_A(CmdFemDefineElementsSet); -void DefineElementsCallback(void *ud, SoEventCallback *n) +void DefineElementsCallback(void* ud, SoEventCallback* n) { Fem::FemAnalysis* Analysis; - if (getConstraintPrerequisits(&Analysis)) + if (getConstraintPrerequisits(&Analysis)) { return; + } // show the wait cursor because this could take quite some time Gui::WaitCursor wc; @@ -1213,23 +1214,29 @@ void DefineElementsCallback(void *ud, SoEventCallback *n) Gui::SelectionRole role; std::vector clPoly = view->getGLPolygon(&role); - if (clPoly.size() < 3) + if (clPoly.size() < 3) { return; - if (clPoly.front() != clPoly.back()) + } + if (clPoly.front() != clPoly.back()) { clPoly.push_back(clPoly.front()); + } SoCamera* cam = view->getSoRenderManager()->getCamera(); SbViewVolume vv = cam->getViewVolume(); Gui::ViewVolumeProjection proj(vv); Base::Polygon2d polygon; - for (std::vector::const_iterator it = clPoly.begin(); it != clPoly.end(); ++it) + for (std::vector::const_iterator it = clPoly.begin(); it != clPoly.end(); ++it) { polygon.Add(Base::Vector2d((*it)[0], (*it)[1])); + } - std::vector docObj = Gui::Selection().getObjectsOfType(Fem::FemMeshObject::getClassTypeId()); - if (docObj.size() != 1) + std::vector docObj = + Gui::Selection().getObjectsOfType(Fem::FemMeshObject::getClassTypeId()); + if (docObj.size() != 1) { return; + } - const SMESHDS_Mesh* data = static_cast(docObj[0])->FemMesh.getValue().getSMesh()->GetMeshDS(); + const SMESHDS_Mesh* data = + static_cast(docObj[0])->FemMesh.getValue().getSMesh()->GetMeshDS(); SMDS_NodeIteratorPtr aNodeIter = data->nodesIterator(); Base::Vector3f pt2d; @@ -1239,27 +1246,36 @@ void DefineElementsCallback(void *ud, SoEventCallback *n) const SMDS_MeshNode* aNode = aNodeIter->next(); Base::Vector3f vec(aNode->X(), aNode->Y(), aNode->Z()); pt2d = proj(vec); - if (polygon.Contains(Base::Vector2d(pt2d.x, pt2d.y))) + if (polygon.Contains(Base::Vector2d(pt2d.x, pt2d.y))) { IntSet.insert(aNode->GetID()); + } } - std::stringstream set; + std::stringstream set; set << "["; - for (std::set::const_iterator it = IntSet.begin(); it != IntSet.end(); ++it) - if (it == IntSet.begin()) + for (std::set::const_iterator it = IntSet.begin(); it != IntSet.end(); ++it) { + if (it == IntSet.begin()) { set << *it; - else + } + else { set << "," << *it; + } + } set << "]"; Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Place robot")); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.addObject('Fem::FemSetElementNodesObject','ElementSet')"); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.ActiveObject.Nodes = %s", set.str().c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.addObject(App.activeDocument().ElementSet)", Analysis->getNameInDocument()); + Gui::Command::doCommand( + Gui::Command::Doc, + "App.ActiveDocument.addObject('Fem::FemSetElementNodesObject','ElementSet')"); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.ActiveObject.Nodes = %s", + set.str().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.activeDocument().%s.addObject(App.activeDocument().ElementSet)", + Analysis->getNameInDocument()); Gui::Command::commitCommand(); - } CmdFemDefineElementsSet::CmdFemDefineElementsSet() @@ -1276,9 +1292,11 @@ CmdFemDefineElementsSet::CmdFemDefineElementsSet() void CmdFemDefineElementsSet::activated(int) { - std::vector docObj = Gui::Selection().getObjectsOfType(Fem::FemMeshObject::getClassTypeId()); + std::vector docObj = + Gui::Selection().getObjectsOfType(Fem::FemMeshObject::getClassTypeId()); - for (std::vector::iterator it = docObj.begin(); it != docObj.end(); ++it) { + for (std::vector::iterator it = docObj.begin(); it != docObj.end(); + ++it) { if (it == docObj.begin()) { Gui::Document* doc = getActiveGuiDocument(); Gui::MDIView* view = doc->getActiveView(); @@ -1286,21 +1304,22 @@ void CmdFemDefineElementsSet::activated(int) Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer(); viewer->setEditing(true); viewer->startSelection(Gui::View3DInventorViewer::Clip); - viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), DefineElementsCallback); + viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), + DefineElementsCallback); } else { return; } } - } } bool CmdFemDefineElementsSet::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Fem::FemMeshObject::getClassTypeId()) != 1) + if (getSelection().countObjectsOfType(Fem::FemMeshObject::getClassTypeId()) != 1) { return false; + } Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { @@ -1332,26 +1351,36 @@ void CmdFemCreateElementsSet::activated(int) Gui::SelectionFilter FemMeshFilter("SELECT Fem::FemMeshObject COUNT 1"); if (ObjectFilter.match()) { - Fem::FemSetElementNodesObject* NodesObj = static_cast(ObjectFilter.Result[0][0].getObject()); + Fem::FemSetElementNodesObject* NodesObj = + static_cast(ObjectFilter.Result[0][0].getObject()); openCommand(QT_TRANSLATE_NOOP("Command", "Edit Elements set")); doCommand(Gui, "Gui.activeDocument().setEdit('%s')", NodesObj->getNameInDocument()); } // start else if (FemMeshFilter.match()) { - Fem::FemMeshObject* MeshObj = static_cast(FemMeshFilter.Result[0][0].getObject()); + Fem::FemMeshObject* MeshObj = + static_cast(FemMeshFilter.Result[0][0].getObject()); Fem::FemSetElementNodesObject::elementsName = "ElementsSet"; - Fem::FemSetElementNodesObject::uniqueElementsName = Command::getUniqueObjectName(Fem::FemSetElementNodesObject::elementsName.c_str()); + Fem::FemSetElementNodesObject::uniqueElementsName = + Command::getUniqueObjectName(Fem::FemSetElementNodesObject::elementsName.c_str()); openCommand(QT_TRANSLATE_NOOP("Command", "Create Elements set")); - doCommand(Doc, "App.activeDocument().addObject('Fem::FemSetElementNodesObject','%s')", Fem::FemSetElementNodesObject::uniqueElementsName.c_str()); - doCommand(Gui, "App.activeDocument().%s.FemMesh = App.activeDocument().%s", Fem::FemSetElementNodesObject::uniqueElementsName.c_str(), MeshObj->getNameInDocument()); - doCommand(Gui, "Gui.activeDocument().setEdit('%s')", Fem::FemSetElementNodesObject::uniqueElementsName.c_str()); - + doCommand(Doc, + "App.activeDocument().addObject('Fem::FemSetElementNodesObject','%s')", + Fem::FemSetElementNodesObject::uniqueElementsName.c_str()); + doCommand(Gui, + "App.activeDocument().%s.FemMesh = App.activeDocument().%s", + Fem::FemSetElementNodesObject::uniqueElementsName.c_str(), + MeshObj->getNameInDocument()); + doCommand(Gui, + "Gui.activeDocument().setEdit('%s')", + Fem::FemSetElementNodesObject::uniqueElementsName.c_str()); } else { - QMessageBox::warning(Gui::getMainWindow(), + QMessageBox::warning( + Gui::getMainWindow(), qApp->translate("CmdFemCreateElementsSet", "Wrong selection"), qApp->translate("CmdFemCreateNodesSet", "Select a single FEM Mesh, please.")); } @@ -1362,7 +1391,7 @@ bool CmdFemCreateElementsSet::isActive() return hasActiveDocument(); } //=========================================================================== -// end of Erase Elements code +// end of Erase Elements code //=========================================================================== //=========================================================================== @@ -2794,8 +2823,8 @@ void CreateFemCommands() // mesh rcCmdMgr.addCommand(new CmdFemCreateNodesSet()); rcCmdMgr.addCommand(new CmdFemDefineNodesSet()); - rcCmdMgr.addCommand(new CmdFemCreateElementsSet()); - rcCmdMgr.addCommand(new CmdFemDefineElementsSet()); + rcCmdMgr.addCommand(new CmdFemCreateElementsSet()); + rcCmdMgr.addCommand(new CmdFemDefineElementsSet()); // equations rcCmdMgr.addCommand(new CmdFemCompEmEquations()); diff --git a/src/Mod/Fem/Gui/Resources/icons/FEM_CreateElementsSet.svg b/src/Mod/Fem/Gui/Resources/icons/FEM_CreateElementsSet.svg index 244b814ef4..a8ef7c05c6 100644 --- a/src/Mod/Fem/Gui/Resources/icons/FEM_CreateElementsSet.svg +++ b/src/Mod/Fem/Gui/Resources/icons/FEM_CreateElementsSet.svg @@ -1,3 +1,3 @@ - \ No newline at end of file + diff --git a/src/Mod/Fem/Gui/TaskCreateElementSet.cpp b/src/Mod/Fem/Gui/TaskCreateElementSet.cpp index 21e2dd6215..9529efb17a 100644 --- a/src/Mod/Fem/Gui/TaskCreateElementSet.cpp +++ b/src/Mod/Fem/Gui/TaskCreateElementSet.cpp @@ -31,9 +31,9 @@ #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -63,17 +63,15 @@ #include - - using namespace Gui; -//using namespace Fem; +// using namespace Fem; using namespace FemGui; using namespace std; std::string inp_file = "abaqusOutputFileEraseElements.inp"; std::string createdMesh = "cDUMMY"; -std::string startResultMesh = "StartResultMesh"; // StartResultMesh"; +std::string startResultMesh = "StartResultMesh"; // StartResultMesh"; std::string newResultMesh = "NewResultMesh"; std::string newFemMesh = "NewFemMesh"; @@ -84,182 +82,223 @@ std::string newProject = ""; std::string resultMesh = "Result"; std::string actualResultMesh = "XXXXXX"; std::string lastName = ""; -std::string highLightMesh; // name of highlighted mesh -std::string meshType; // type of - either 'result' or 'femmesh' +std::string highLightMesh; // name of highlighted mesh +std::string meshType; // type of - either 'result' or 'femmesh' int passResult = 0; int passFemMesh = 0; int maxProject = 10; -double **nodeCoords; // these are node coords -int *nodeNumbers; // these are node numbers - probably not required[100]; +double** nodeCoords; // these are node coords +int* nodeNumbers; // these are node numbers - probably not required[100]; - -string myToUpper(std::string str) { - for(int i = 0; i < str.length(); i++) { - str[i] = toupper(str[i]); - } - return str; -} -void addFaceToMesh(const std::vector nodes, SMESHDS_Mesh *MeshDS, int EID) +string myToUpper(std::string str) { - int nbNodes = nodes.size(); - switch (nbNodes) - { - case 3: // 3 node triangle - MeshDS->AddFaceWithID( - nodes[0], nodes[1], nodes[2], - EID); - break; - case 4: // 4 node quadrilateral - MeshDS->AddFaceWithID( - nodes[0], nodes[1], nodes[2], nodes[3], - EID); - break; - case 6: // 6 node triangle - MeshDS->AddFaceWithID( - nodes[0], nodes[1], nodes[2], nodes[3], - nodes[4], nodes[5], - EID); - break; - case 8: // 8 node quadrilateral - MeshDS->AddFaceWithID( - nodes[0], nodes[1], nodes[2], nodes[3], - nodes[4], nodes[5], nodes[6], nodes[7], - EID); - break; + for (int i = 0; i < str.length(); i++) { + str[i] = toupper(str[i]); } -} // addFaceToMesh + return str; +} -void addVolumeToMesh(const std::vector nodes, SMESHDS_Mesh *MeshDS, int EID) +void addFaceToMesh(const std::vector nodes, SMESHDS_Mesh* MeshDS, int EID) +{ + int nbNodes = nodes.size(); + switch (nbNodes) { + case 3: // 3 node triangle + MeshDS->AddFaceWithID(nodes[0], nodes[1], nodes[2], EID); + break; + case 4: // 4 node quadrilateral + MeshDS->AddFaceWithID(nodes[0], nodes[1], nodes[2], nodes[3], EID); + break; + case 6: // 6 node triangle + MeshDS->AddFaceWithID(nodes[0], nodes[1], nodes[2], nodes[3], nodes[4], nodes[5], EID); + break; + case 8: // 8 node quadrilateral + MeshDS->AddFaceWithID(nodes[0], + nodes[1], + nodes[2], + nodes[3], + nodes[4], + nodes[5], + nodes[6], + nodes[7], + EID); + break; + } +} // addFaceToMesh + +void addVolumeToMesh(const std::vector nodes, SMESHDS_Mesh* MeshDS, int EID) { int nbNodes = nodes.size(); - switch (nbNodes) - { - case 4: // 4 node tetrahedron - MeshDS->AddVolumeWithID( - nodes[0], nodes[1], nodes[2], nodes[3], - EID); - break; - case 5: // 5 node pyramid - MeshDS->AddVolumeWithID( - nodes[0], nodes[1], nodes[2], nodes[3], - nodes[4], - EID); - break; - case 6: // 6 node pentahedron - MeshDS->AddVolumeWithID( - nodes[0], nodes[1], nodes[2], nodes[3], - nodes[4], nodes[5], - EID); - break; - case 8: // 8 node hexahedron - MeshDS->AddVolumeWithID( - nodes[0], nodes[1], nodes[2], nodes[3], - nodes[4], nodes[5], nodes[6], nodes[7], - EID); - break; - case 10: // 10 node tetrahedron - MeshDS->AddVolumeWithID( - nodes[0], nodes[1], nodes[2], nodes[3], - nodes[4], nodes[5], nodes[6], nodes[7], - nodes[8], nodes[9], - EID); - break; - case 13: // 13 node pyramid - 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], - EID); - break; - case 15: // 15 node pentahedron - 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], - EID); - break; - case 20: // 20 node hexahedron - 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], - EID); - break; - } // default: {} + switch (nbNodes) { + case 4: // 4 node tetrahedron + MeshDS->AddVolumeWithID(nodes[0], nodes[1], nodes[2], nodes[3], EID); + break; + case 5: // 5 node pyramid + MeshDS->AddVolumeWithID(nodes[0], nodes[1], nodes[2], nodes[3], nodes[4], EID); + break; + case 6: // 6 node pentahedron + MeshDS + ->AddVolumeWithID(nodes[0], nodes[1], nodes[2], nodes[3], nodes[4], nodes[5], EID); + break; + case 8: // 8 node hexahedron + MeshDS->AddVolumeWithID(nodes[0], + nodes[1], + nodes[2], + nodes[3], + nodes[4], + nodes[5], + nodes[6], + nodes[7], + EID); + break; + case 10: // 10 node tetrahedron + MeshDS->AddVolumeWithID(nodes[0], + nodes[1], + nodes[2], + nodes[3], + nodes[4], + nodes[5], + nodes[6], + nodes[7], + nodes[8], + nodes[9], + EID); + break; + case 13: // 13 node pyramid + 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], + EID); + break; + case 15: // 15 node pentahedron + 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], + EID); + break; + case 20: // 20 node hexahedron + 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], + EID); + break; + } // default: {} -} // addVolumeToMesh +} // addVolumeToMesh void myCopyResultsMesh(std::string oldName, std::string newName) { int error = 0; Base::Console().Warning("copy: %s and %s\n", oldName.c_str(), newName.c_str()); - if (oldName.compare(newName) == 0 && error == 0) - { + if (oldName.compare(newName) == 0 && error == 0) { error = 1; - Base::Console().Warning("Can't copy ResultMesh to ResultMesh: %s and %s\n", oldName.c_str(), newName.c_str()); - QMessageBox::warning(Gui::getMainWindow(), -// QMessageBox::warning(Gui::MainWindow(), - qApp->translate("CmdFemCreateElementsSet", "Wrong selection"), - qApp->translate("CmdFemCreateElementsSet", "Can't copy ResultMesh to ResultMesh")); + Base::Console().Warning("Can't copy ResultMesh to ResultMesh: %s and %s\n", + oldName.c_str(), + newName.c_str()); + QMessageBox::warning( + Gui::getMainWindow(), + // QMessageBox::warning(Gui::MainWindow(), + qApp->translate("CmdFemCreateElementsSet", "Wrong selection"), + qApp->translate("CmdFemCreateElementsSet", "Can't copy ResultMesh to ResultMesh")); } - if ((oldName.find("Result") == std::string::npos || newName.find("Result") == std::string::npos) && error == 0) - { + if ((oldName.find("Result") == std::string::npos || newName.find("Result") == std::string::npos) + && error == 0) { error = 1; Base::Console().Warning("Mesh must be results: %s\n", oldName.c_str()); - QMessageBox::warning(Gui::getMainWindow(), -// QMessageBox::warning(Gui::MainWindow(), - qApp->translate("CmdFemCreateElementsSet", "Wrong selection"), - qApp->translate("CmdFemCreateElementsSet", "Mesh must be a Results mesh")); + QMessageBox::warning( + Gui::getMainWindow(), + // QMessageBox::warning(Gui::MainWindow(), + qApp->translate("CmdFemCreateElementsSet", "Wrong selection"), + qApp->translate("CmdFemCreateElementsSet", "Mesh must be a Results mesh")); } - if (error == 0) - { - Gui::Command::doCommand(Gui::Command::Doc, "c = FreeCADGui.ActiveDocument.getObject(\'%s\')", oldName.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "FreeCAD.ActiveDocument.%s.FemMesh = c.Object.FemMesh", newName.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "Gui.ActiveDocument.getObject(\'%s\').BackfaceCulling = False", newName.c_str()); + if (error == 0) { + Gui::Command::doCommand(Gui::Command::Doc, + "c = FreeCADGui.ActiveDocument.getObject(\'%s\')", + oldName.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "FreeCAD.ActiveDocument.%s.FemMesh = c.Object.FemMesh", + newName.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "Gui.ActiveDocument.getObject(\'%s\').BackfaceCulling = False", + newName.c_str()); } -} // copyresultsmesh +} // copyresultsmesh void generateMesh(std::string meshType) { - if (passResult + passFemMesh == 0) - { + if (passResult + passFemMesh == 0) { Gui::Command::doCommand(Gui::Command::Doc, "import Fem,os"); } - if (strcmp(meshType.c_str(), "result") == 0) - { - if (passResult == 0) - { + if (strcmp(meshType.c_str(), "result") == 0) { + if (passResult == 0) { string xstr(startResultMesh.c_str()); createdMesh = newResultMesh.c_str(); - Gui::Command::doCommand(Gui::Command::Doc, "obj1 = App.ActiveDocument.addObject('Fem::FemMeshObject', \'%s\')", startResultMesh.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "Gui.ActiveDocument.getObject(\'%s\').Visibility = False", startResultMesh.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "ne = Gui.ActiveDocument.getObject(\'%s\')", actualResultMesh.c_str()); + Gui::Command::doCommand( + Gui::Command::Doc, + "obj1 = App.ActiveDocument.addObject('Fem::FemMeshObject', \'%s\')", + startResultMesh.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "Gui.ActiveDocument.getObject(\'%s\').Visibility = False", + startResultMesh.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "ne = Gui.ActiveDocument.getObject(\'%s\')", + actualResultMesh.c_str()); Gui::Command::doCommand(Gui::Command::Doc, "obj1.FemMesh = ne.Object.FemMesh"); } - else if (passResult > 0) - { + else if (passResult > 0) { createdMesh = newResultMesh.c_str(); } passResult += 1; } - else if (strcmp(meshType.c_str(), "femmesh") == 0) - { - if (passFemMesh == 0) - { + else if (strcmp(meshType.c_str(), "femmesh") == 0) { + if (passFemMesh == 0) { string xstr("no rename required"); createdMesh = newFemMesh.c_str(); } - else if (passFemMesh > 0) - { + else if (passFemMesh > 0) { createdMesh = newFemMesh.c_str(); } passFemMesh += 1; @@ -267,45 +306,65 @@ void generateMesh(std::string meshType) App::Document* doc = App::GetApplication().getActiveDocument(); uniqueMesh = doc->getUniqueObjectName(createdMesh.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "Gui.ActiveDocument.getObject(\'%s\').Visibility = False", highLightMesh.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "Gui.ActiveDocument.getObject(\'%s\').Visibility = False", + highLightMesh.c_str()); Gui::Command::doCommand(Gui::Command::Doc, "newermesh = Fem.read(\'%s\')", inp_file.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "obj = App.ActiveDocument.addObject('Fem::FemMeshObject', \'%s\')", uniqueMesh.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "obj = App.ActiveDocument.addObject('Fem::FemMeshObject', \'%s\')", + uniqueMesh.c_str()); Gui::Command::doCommand(Gui::Command::Doc, "obj.FemMesh = newermesh"); - Gui::Command::doCommand(Gui::Command::Doc, "Gui.ActiveDocument.getObject(\'%s\').BackfaceCulling = False", uniqueMesh.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "Gui.ActiveDocument.getObject(\'%s\').Visibility = True", uniqueMesh.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "Gui.ActiveDocument.getObject(\'%s\').BackfaceCulling = False", + uniqueMesh.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "Gui.ActiveDocument.getObject(\'%s\').Visibility = True", + uniqueMesh.c_str()); Gui::Command::doCommand(Gui::Command::Doc, "os.remove(\'%s\')", inp_file.c_str()); - if (strcmp(meshType.c_str(), "result") == 0) - { - Gui::Command::doCommand(Gui::Command::Doc, "c = FreeCADGui.ActiveDocument.getObject(\'%s\')", uniqueMesh.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "FreeCAD.ActiveDocument.%s.FemMesh = c.Object.FemMesh", actualResultMesh.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "Gui.ActiveDocument.getObject(\'%s\').BackfaceCulling = False", actualResultMesh.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "Gui.ActiveDocument.getObject(\'%s\').Visibility = True", actualResultMesh.c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "Gui.ActiveDocument.getObject(\'%s\').Visibility = False", uniqueMesh.c_str()); + if (strcmp(meshType.c_str(), "result") == 0) { + Gui::Command::doCommand(Gui::Command::Doc, + "c = FreeCADGui.ActiveDocument.getObject(\'%s\')", + uniqueMesh.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "FreeCAD.ActiveDocument.%s.FemMesh = c.Object.FemMesh", + actualResultMesh.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "Gui.ActiveDocument.getObject(\'%s\').BackfaceCulling = False", + actualResultMesh.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "Gui.ActiveDocument.getObject(\'%s\').Visibility = True", + actualResultMesh.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "Gui.ActiveDocument.getObject(\'%s\').Visibility = False", + uniqueMesh.c_str()); } -} // generate mesh +} // generate mesh -void writeToFile(std::string fileName, SMESHDS_Mesh *newMesh, int *nodeNumbers, - double **nodeCoords, int rows, int requiredType) +void writeToFile(std::string fileName, + SMESHDS_Mesh* newMesh, + int* nodeNumbers, + double** nodeCoords, + int rows, + int requiredType) { std::map elType2D; std::map elType3D; - elType2D[3] = "S3"; // 3 node triangle - elType2D[6] = "S6"; // 4 node quadrilateral - elType2D[4] = "S4"; // 6 node triangle - elType2D[8] = "S8"; // 8 node quadrilateral + elType2D[3] = "S3"; // 3 node triangle + elType2D[6] = "S6"; // 4 node quadrilateral + elType2D[4] = "S4"; // 6 node triangle + elType2D[8] = "S8"; // 8 node quadrilateral - elType3D[4] = "C3D4"; // 4 node tetrahedron - elType3D[6] = "C3D6"; // 6 node pentahedron - elType3D[8] = "C3D8"; // 8 node hexahedron - elType3D[10] = "C3D10"; // 10 node tetrahedron - elType3D[15] = "C3D15"; // 15 node pentahedron - elType3D[20] = "C3D20"; // 20 node hexahedron -// no pyramid elements - FILE *fptr = fopen(fileName.c_str(), "w"); - if (fptr == NULL) - { + elType3D[4] = "C3D4"; // 4 node tetrahedron + elType3D[6] = "C3D6"; // 6 node pentahedron + elType3D[8] = "C3D8"; // 8 node hexahedron + elType3D[10] = "C3D10"; // 10 node tetrahedron + elType3D[15] = "C3D15"; // 15 node pentahedron + elType3D[20] = "C3D20"; // 20 node hexahedron + // no pyramid elements + FILE* fptr = fopen(fileName.c_str(), "w"); + if (fptr == NULL) { return; } fprintf(fptr, "** written by Erase Elements inp file writer for CalculiX,Abaqus meshes\n"); @@ -316,12 +375,14 @@ void writeToFile(std::string fileName, SMESHDS_Mesh *newMesh, int *nodeNumbers, fprintf(fptr, "** Nodes\n"); fprintf(fptr, "*Node, NSET=Nall\n"); - for (int i = 1; i < rows + 1; i++) - { - if (nodeNumbers[i] > 0) - { - fprintf(fptr, "%d, %e, %e, %e\n", - nodeNumbers[i], nodeCoords[i][0], nodeCoords[i][1], nodeCoords[i][2]); + for (int i = 1; i < rows + 1; i++) { + if (nodeNumbers[i] > 0) { + fprintf(fptr, + "%d, %e, %e, %e\n", + nodeNumbers[i], + nodeCoords[i][0], + nodeCoords[i][1], + nodeCoords[i][2]); } } @@ -329,59 +390,54 @@ void writeToFile(std::string fileName, SMESHDS_Mesh *newMesh, int *nodeNumbers, SMDS_NodeIteratorPtr srcNodeIt; srcElemIt = newMesh->elementsIterator(); srcNodeIt = newMesh->nodesIterator(); - const SMDS_MeshNode *nSrc; + const SMDS_MeshNode* nSrc; int NID, EID; - while (srcNodeIt->more()) - { - const SMDS_MeshNode *node = srcNodeIt->next(); + while (srcNodeIt->more()) { + const SMDS_MeshNode* node = srcNodeIt->next(); NID = node->GetID(); } int numberNodes = -1; - while (srcElemIt->more()) - { - const SMDS_MeshElement *elem = srcElemIt->next(); + while (srcElemIt->more()) { + const SMDS_MeshElement* elem = srcElemIt->next(); EID = elem->GetID(); - if (elem->GetType() != requiredType) - { + if (elem->GetType() != requiredType) { continue; } - if (numberNodes != elem->NbNodes()) - { - if (requiredType == 4) - { + if (numberNodes != elem->NbNodes()) { + if (requiredType == 4) { fprintf(fptr, "\n"); fprintf(fptr, "\n"); fprintf(fptr, "%s", "** Volume elements\n"); - fprintf(fptr, "*Element, TYPE=%s, ELSET=Evolumes\n", elType3D[elem->NbNodes()].c_str()); + fprintf(fptr, + "*Element, TYPE=%s, ELSET=Evolumes\n", + elType3D[elem->NbNodes()].c_str()); } - else if (requiredType == 3) - { + else if (requiredType == 3) { fprintf(fptr, "%s", "** Face elements\n"); - fprintf(fptr, "*Element, TYPE=%s, ELSET=Efaces\n", elType2D[elem->NbNodes()].c_str()); + fprintf(fptr, + "*Element, TYPE=%s, ELSET=Efaces\n", + elType2D[elem->NbNodes()].c_str()); } numberNodes = elem->NbNodes(); } SMDS_ElemIteratorPtr nIt = elem->nodesIterator(); fprintf(fptr, "%d", EID); - for (int iN = 0; nIt->more(); ++iN) - { - nSrc = static_cast(nIt->next()); + for (int iN = 0; nIt->more(); ++iN) { + nSrc = static_cast(nIt->next()); NID = nSrc->GetID(); fprintf(fptr, ", %d", NID); - } // for iN + } // for iN fprintf(fptr, "\n"); - } // while print - if (requiredType == 4) - { + } // while print + if (requiredType == 4) { fprintf(fptr, "\n"); fprintf(fptr, "\n"); fprintf(fptr, "%s", "** Define element set Eall\n"); fprintf(fptr, "%s", "*ELSET, ELSET=Eall\n"); fprintf(fptr, "%s", "Evolumes\n"); } - else if (requiredType == 3) - { + else if (requiredType == 3) { fprintf(fptr, "%s", "** Define element set Eall\n"); fprintf(fptr, "%s", "*ELSET, ELSET=Eall\n"); fprintf(fptr, "%s", "Efaces\n"); @@ -395,9 +451,9 @@ TaskCreateElementSet::TaskCreateElementSet(Fem::FemSetElementNodesObject* pcObje : TaskBox(Gui::BitmapFactory().pixmap("FEM_CreateElementsSet"), tr("Elements set"), true, - parent), - pcObject(pcObject), - selectionMode(none) + parent) + , pcObject(pcObject) + , selectionMode(none) { proxy = new QWidget(this); ui = new Ui_TaskCreateElementSet(); @@ -409,7 +465,9 @@ TaskCreateElementSet::TaskCreateElementSet(Fem::FemSetElementNodesObject* pcObje QObject::connect(ui->toolButton_Rename, SIGNAL(clicked()), this, SLOT(CopyResultsMesh())); // check if the Link to the FemMesh is defined assert(pcObject->FemMesh.getValue()); - MeshViewProvider = dynamic_cast(Gui::Application::Instance->getViewProvider(pcObject->FemMesh.getValue())); + MeshViewProvider = + dynamic_cast(Gui::Application::Instance->getViewProvider( + pcObject->FemMesh.getValue())); assert(MeshViewProvider); elementTempSet = pcObject->Elements.getValues(); @@ -418,11 +476,10 @@ TaskCreateElementSet::TaskCreateElementSet(Fem::FemSetElementNodesObject* pcObje info = "Delete the generated data in the other project: " + std::string(currentProject); App::Document* doc = App::GetApplication().getActiveDocument(); newProject = doc->Label.getValue(); - if (strcmp(currentProject.c_str(), newProject.c_str()) != 0 && - (passResult + passFemMesh != 0)) - { + if (strcmp(currentProject.c_str(), newProject.c_str()) != 0 + && (passResult + passFemMesh != 0)) { QMessageBox::warning(Gui::getMainWindow(), -// QMessageBox::warning(Gui::MainWindow(), + // QMessageBox::warning(Gui::MainWindow(), qApp->translate("CmdFemCreateElementsSet", "Wrong selection"), qApp->translate("CmdFemCreateElementsSet", info.c_str())); return; @@ -434,16 +491,19 @@ void TaskCreateElementSet::Poly(void) Gui::Document* doc = Gui::Application::Instance->activeDocument(); Gui::MDIView* view = doc->getActiveView(); if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { - Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor* )view)->getViewer(); + Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer(); viewer->setEditing(true); viewer->startSelection(Gui::View3DInventorViewer::Clip); - viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), DefineElementsCallback, this); + viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), + DefineElementsCallback, + this); } } void TaskCreateElementSet::CopyResultsMesh(void) { - std::vector selection = Gui::Selection().getSelection(); // [0]; + std::vector selection = + Gui::Selection().getSelection(); // [0]; highLightMesh = selection[0].FeatName; myCopyResultsMesh(highLightMesh, actualResultMesh); Gui::Command::doCommand(Gui::Command::Doc, "Gui.activeDocument().resetEdit()"); @@ -452,68 +512,64 @@ void TaskCreateElementSet::CopyResultsMesh(void) void TaskCreateElementSet::Restore(void) { App::Document* doc = App::GetApplication().getActiveDocument(); - const std::vector &all = doc->getObjects(); + const std::vector& all = doc->getObjects(); int number = 0, xpos = 0; int elList = 0; // put reverse here std::vector STR; - for (std::vector::const_iterator it = all.begin(); - it != all.end(); ++it) - { + for (std::vector::const_iterator it = all.begin(); it != all.end(); + ++it) { std::string objectN = all[xpos]->getNameInDocument(); STR.push_back(objectN); xpos++; } // iterate through in reverse order - for (std::vector::reverse_iterator it = STR.rbegin(); it != STR.rend(); ++it) - { + for (std::vector::reverse_iterator it = STR.rbegin(); it != STR.rend(); ++it) { std::string objectN = (*it); - if (objectN.find(startResultMesh) != std::string::npos) - { + if (objectN.find(startResultMesh) != std::string::npos) { number++; myCopyResultsMesh(objectN, actualResultMesh); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.removeObject(\'%s\')", objectN.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.removeObject(\'%s\')", + objectN.c_str()); Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); } - else if (objectN.find(newResultMesh) != std::string::npos) - { + else if (objectN.find(newResultMesh) != std::string::npos) { number++; - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.removeObject(\'%s\')", objectN.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.removeObject(\'%s\')", + objectN.c_str()); Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); } - else if (objectN.find(actualResultMesh) != std::string::npos) - { - } - else if (objectN.find(newFemMesh) != std::string::npos) - { + else if (objectN.find(actualResultMesh) != std::string::npos) {} + else if (objectN.find(newFemMesh) != std::string::npos) { number++; - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.removeObject(\'%s\')", objectN.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.removeObject(\'%s\')", + objectN.c_str()); Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); } - else if (objectN.find(Fem::FemSetElementNodesObject::elementsName) != std::string::npos) - { - if (elList > 0) - { - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.removeObject(\'%s\')", objectN.c_str()); + else if (objectN.find(Fem::FemSetElementNodesObject::elementsName) != std::string::npos) { + if (elList > 0) { + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.removeObject(\'%s\')", + objectN.c_str()); Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); } - else if (elList == 0) - { + else if (elList == 0) { elList++; lastName = objectN; } } - } // for - if (strcmp(lastName.c_str(), "") != 0) - { + } // for + if (strcmp(lastName.c_str(), "") != 0) { // blank last name - no action } - else if (number == 0) - { + else if (number == 0) { QMessageBox::warning(Gui::getMainWindow(), -// QMessageBox::warning(Gui::MainWindow(), + // QMessageBox::warning(Gui::MainWindow(), qApp->translate("CmdFemCreateElementsSet", "Wrong selection"), qApp->translate("CmdFemCreateElementsSet", "No Data To Restore\n")); return; @@ -523,65 +579,69 @@ void TaskCreateElementSet::Restore(void) currentProject = ""; Gui::Command::doCommand(Gui::Command::Doc, "Gui.activeDocument().resetEdit()"); return; -} // restore +} // restore void TaskCreateElementSet::DefineElementsCallback(void* ud, SoEventCallback* n) { Gui::WaitCursor wc; - TaskCreateElementSet* taskBox = static_cast(ud); + TaskCreateElementSet* taskBox = static_cast(ud); // When this callback function is invoked we must in either case leave the edit mode - Gui::View3DInventorViewer* view = reinterpret_cast(n->getUserData()); + Gui::View3DInventorViewer* view = + reinterpret_cast(n->getUserData()); view->setEditing(false); view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), DefineElementsCallback, ud); n->setHandled(); Gui::SelectionRole role; std::vector clPoly = view->getGLPolygon(&role); - if (clPoly.size() < 3) + if (clPoly.size() < 3) { return; - if (clPoly.front() != clPoly.back()) + } + if (clPoly.front() != clPoly.back()) { clPoly.push_back(clPoly.front()); + } SoCamera* cam = view->getSoRenderManager()->getCamera(); SbViewVolume vv = cam->getViewVolume(); Gui::ViewVolumeProjection proj(vv); Base::Polygon2d polygon; - for (std::vector::const_iterator it = clPoly.begin(); it != clPoly.end(); ++it) + for (std::vector::const_iterator it = clPoly.begin(); it != clPoly.end(); ++it) { polygon.Add(Base::Vector2d((*it)[0], (*it)[1])); + } taskBox->DefineNodes(polygon, proj, role == Gui::SelectionRole::Inner ? true : false); -} // DefineElementsCallback +} // DefineElementsCallback -void TaskCreateElementSet::DefineNodes(const Base::Polygon2d &polygon, - const Gui::ViewVolumeProjection &proj, +void TaskCreateElementSet::DefineNodes(const Base::Polygon2d& polygon, + const Gui::ViewVolumeProjection& proj, bool inner) { - const SMESHDS_Mesh* srcMeshDS = const_cast(pcObject->FemMesh.getValue()->FemMesh.getValue().getSMesh())->GetMeshDS(); + const SMESHDS_Mesh* srcMeshDS = + const_cast( + pcObject->FemMesh.getValue()->FemMesh.getValue().getSMesh()) + ->GetMeshDS(); - std::vector selection = Gui::Selection().getSelection(); // [0]; + std::vector selection = + Gui::Selection().getSelection(); // [0]; highLightMesh = selection[0].FeatName; meshType = "NULL"; std::size_t found = myToUpper(highLightMesh).find(myToUpper(resultMesh)); -actualResultMesh = highLightMesh; -//highLightMesh.find(myToUpper(resultMesh)); + actualResultMesh = highLightMesh; + // highLightMesh.find(myToUpper(resultMesh)); - if (found != std::string::npos) - { + if (found != std::string::npos) { meshType = "result"; } - else - { + else { meshType = "femmesh"; } -// std::string lightMesh = selection[0].FeatID; + // std::string lightMesh = selection[0].FeatID; elementTempSet.clear(); - int nElements = - srcMeshDS->GetMeshInfo().NbElements(); - int nVolumes = - srcMeshDS->GetMeshInfo().NbVolumes(); - int requiredType = nVolumes > 0 ? 4 : 3; // type = 4 - 3D, type = 3 - 2D + int nElements = srcMeshDS->GetMeshInfo().NbElements(); + int nVolumes = srcMeshDS->GetMeshInfo().NbVolumes(); + int requiredType = nVolumes > 0 ? 4 : 3; // type = 4 - 3D, type = 3 - 2D double cOfGX, cOfGY, cOfGZ; const SMDS_MeshNode* nSrc; @@ -589,93 +649,81 @@ actualResultMesh = highLightMesh; currentProject = newProject; SMESHDS_Mesh* newMeshDS = new SMESHDS_Mesh(nElements, true); -// FemMesh femMesh = FemMesh(); // *getFemMeshPtr(); + // FemMesh femMesh = FemMesh(); // *getFemMeshPtr(); Base::Vector3f pt2d; SMDS_ElemIteratorPtr srcElemIt = srcMeshDS->elementsIterator(); SMDS_NodeIteratorPtr srcNode = srcMeshDS->nodesIterator(); const SMDS_MeshNode* nTgt; - std::vector nodes; + std::vector nodes; int keepElement = 0, maxNode = -1; - while (srcNode->more()) - { - const SMDS_MeshNode *aNode = srcNode->next(); - if (aNode->GetID() > maxNode) - { + while (srcNode->more()) { + const SMDS_MeshNode* aNode = srcNode->next(); + if (aNode->GetID() > maxNode) { maxNode = aNode->GetID(); } } nodeNumbers = new int[maxNode + 2]; - nodeCoords = new double *[maxNode + 2]; // these are node coords - for (int i = 0; i < maxNode + 2; i++) - { - nodeCoords[i] = new double[3]; // x,y,z + nodeCoords = new double*[maxNode + 2]; // these are node coords + for (int i = 0; i < maxNode + 2; i++) { + nodeCoords[i] = new double[3]; // x,y,z nodeNumbers[i] = 0; } - elementTempSet.insert(requiredType* -1); // the type of elements - int pNodes; // the first pnodes are used in the cofg calc + elementTempSet.insert(requiredType * -1); // the type of elements + int pNodes; // the first pnodes are used in the cofg calc - while (srcElemIt->more()) - { + while (srcElemIt->more()) { - pNodes = 4; // the first pnodes are used in the cofg calc + pNodes = 4; // the first pnodes are used in the cofg calc const SMDS_MeshElement* elem = srcElemIt->next(); nodes.resize(elem->NbNodes()); EID = elem->GetID(); - if (elem->GetType() != requiredType) - { + if (elem->GetType() != requiredType) { continue; } SMDS_ElemIteratorPtr nIt = elem->nodesIterator(); - if (requiredType == 4) // 3D + if (requiredType == 4) // 3D { - if (elem->NbNodes() == 8 || elem->NbNodes() == 20) - { // 8 or 20 node brick + if (elem->NbNodes() == 8 || elem->NbNodes() == 20) { // 8 or 20 node brick pNodes = 8; } - if (elem->NbNodes() == 6 || elem->NbNodes() == 15) - { // 6 or 15 node penta + if (elem->NbNodes() == 6 || elem->NbNodes() == 15) { // 6 or 15 node penta pNodes = 8; } } - else if (requiredType == 3) // 2D + else if (requiredType == 3) // 2D { - if (elem->NbNodes() == 3 || elem->NbNodes() == 6) - { // 3 or 6 node triangles + if (elem->NbNodes() == 3 || elem->NbNodes() == 6) { // 3 or 6 node triangles pNodes = 3; } } cOfGX = 0.0; cOfGY = 0.0; cOfGZ = 0.0; - for (int iN = 0; nIt->more(); ++iN) - { - nSrc = static_cast(nIt->next()); + for (int iN = 0; nIt->more(); ++iN) { + nSrc = static_cast(nIt->next()); nTgt = srcMeshDS->FindNode(nSrc->GetID()); nodes[iN] = nTgt; newMeshDS->AddNodeWithID(nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID()); - if (nodeNumbers[nSrc->GetID()] == 0) - { + if (nodeNumbers[nSrc->GetID()] == 0) { nodeCoords[nSrc->GetID()][0] = nSrc->X(); nodeCoords[nSrc->GetID()][1] = nSrc->Y(); nodeCoords[nSrc->GetID()][2] = nSrc->Z(); // write all nodes if result mesh - if (strcmp(meshType.c_str(), "result") == 0) - { + if (strcmp(meshType.c_str(), "result") == 0) { nodeNumbers[nSrc->GetID()] = nSrc->GetID(); } } - if (iN < pNodes) - { + if (iN < pNodes) { cOfGX += nSrc->X() / pNodes; cOfGY += nSrc->Y() / pNodes; cOfGZ += nSrc->Z() / pNodes; } - } // for iN + } // for iN SMESH_MeshEditor::ElemFeatures elemFeat(elem->GetType(), elem->IsPoly()); elemFeat.SetID(EID); @@ -683,72 +731,70 @@ actualResultMesh = highLightMesh; /* add the bit to determine which elements are outside the poly */ Base::Vector3f vec(cOfGX, cOfGY, cOfGZ); pt2d = proj(vec); - if (polygon.Contains(Base::Vector2d(pt2d.x, pt2d.y)) != inner) - { - if (strcmp(meshType.c_str(), "femmesh") == 0) - { - for (long unsigned int i = 0; i < nodes.size(); i++) - { + if (polygon.Contains(Base::Vector2d(pt2d.x, pt2d.y)) != inner) { + if (strcmp(meshType.c_str(), "femmesh") == 0) { + for (long unsigned int i = 0; i < nodes.size(); i++) { nodeNumbers[nodes[i]->GetID()] = nodes[i]->GetID(); } } elementTempSet.insert(EID); keepElement += 1; - if (requiredType == 4) - { + if (requiredType == 4) { addVolumeToMesh(nodes, newMeshDS, EID); } - else if (requiredType == 3) - { + else if (requiredType == 3) { addFaceToMesh(nodes, newMeshDS, EID); } } - } // while + } // while int erase; - if (nVolumes != 0) - { + if (nVolumes != 0) { erase = nVolumes - keepElement; } - else - { + else { erase = nElements - keepElement; } - if (keepElement > 0) - { - Base::Console().Warning( - "Number of Elements Kept: %d, Number of Elements Erased: %d\n", keepElement, erase); + if (keepElement > 0) { + Base::Console().Warning("Number of Elements Kept: %d, Number of Elements Erased: %d\n", + keepElement, + erase); writeToFile(inp_file, newMeshDS, nodeNumbers, nodeCoords, maxNode, requiredType); generateMesh(meshType); } - else - { - QMessageBox::warning(Gui::getMainWindow(), -// QMessageBox::warning(Gui::MainWindow(), - qApp->translate("CmdFemCreateElementsSet", "Erased Elements"), - qApp->translate("CmdFemCreateElementsSet", "All Elements Erased - no mesh generated.")); + else { + QMessageBox::warning( + Gui::getMainWindow(), + // QMessageBox::warning(Gui::MainWindow(), + qApp->translate("CmdFemCreateElementsSet", "Erased Elements"), + qApp->translate("CmdFemCreateElementsSet", "All Elements Erased - no mesh generated.")); } newMeshDS->Modified(); Gui::Command::doCommand(Gui::Command::Doc, "Gui.activeDocument().resetEdit()"); -} // void TaskCreateElementSet::DefineNodes +} // void TaskCreateElementSet::DefineNodes -void TaskCreateElementSet::onSelectionChanged(const Gui::SelectionChanges &msg) +void TaskCreateElementSet::onSelectionChanged(const Gui::SelectionChanges& msg) { - if (selectionMode == none) + if (selectionMode == none) { return; + } - if (msg.Type == Gui::SelectionChanges::AddSelection) - { + if (msg.Type == Gui::SelectionChanges::AddSelection) { std::string subName(msg.pSubName); unsigned int i = 0; - for (; i < subName.size(); i++) - if (msg.pSubName[i] == 'F') + for (; i < subName.size(); i++) { + if (msg.pSubName[i] == 'F') { break; + } + } int elem = atoi(subName.substr(4).c_str()); int face = atoi(subName.substr(i + 1).c_str()); elementTempSet.clear(); - std::set tmp = pcObject->FemMesh.getValue()->FemMesh.getValue().getSurfaceNodes(elem, face); + std::set tmp = + pcObject->FemMesh.getValue()->FemMesh.getValue().getSurfaceNodes( + elem, + face); elementTempSet.insert(tmp.begin(), tmp.end()); selectionMode = none; @@ -761,9 +807,10 @@ void TaskCreateElementSet::onSelectionChanged(const Gui::SelectionChanges &msg) TaskCreateElementSet::~TaskCreateElementSet() { // delete last elementsset - if (strcmp(lastName.c_str(), "") != 0) - { - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.removeObject(\'%s\')", lastName.c_str()); + if (strcmp(lastName.c_str(), "") != 0) { + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.removeObject(\'%s\')", + lastName.c_str()); Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); lastName = ""; } diff --git a/src/Mod/Fem/Gui/TaskCreateElementSet.h b/src/Mod/Fem/Gui/TaskCreateElementSet.h index 985bd6b4de..6ffd875b3c 100644 --- a/src/Mod/Fem/Gui/TaskCreateElementSet.h +++ b/src/Mod/Fem/Gui/TaskCreateElementSet.h @@ -31,7 +31,6 @@ #include - class Ui_TaskCreateElementSet; class SoEventCallback; @@ -56,17 +55,18 @@ namespace FemGui class ViewProviderFemMesh; -class TaskCreateElementSet : public Gui::TaskView::TaskBox, public Gui::SelectionObserver +class TaskCreateElementSet: public Gui::TaskView::TaskBox, public Gui::SelectionObserver { Q_OBJECT public: - explicit TaskCreateElementSet(Fem::FemSetElementNodesObject* pcObject,QWidget* parent = nullptr); + explicit TaskCreateElementSet(Fem::FemSetElementNodesObject* pcObject, + QWidget* parent = nullptr); ~TaskCreateElementSet() override; std::set elementTempSet; ViewProviderFemMesh* MeshViewProvider; - static std::string currentProject; + static std::string currentProject; private Q_SLOTS: void Poly(); @@ -75,8 +75,8 @@ private Q_SLOTS: protected: Fem::FemSetElementNodesObject* pcObject; - static void DefineElementsCallback(void* ud, SoEventCallback* n); - void DefineNodes(const Base::Polygon2d &polygon,const Gui::ViewVolumeProjection &proj, bool); + static void DefineElementsCallback(void* ud, SoEventCallback* n); + void DefineNodes(const Base::Polygon2d& polygon, const Gui::ViewVolumeProjection& proj, bool); protected: void onSelectionChanged(const Gui::SelectionChanges& msg) override; @@ -93,4 +93,4 @@ private: } // namespace FemGui -#endif // GUI_TASKVIEW_TaskCreateElementSet_H +#endif // GUI_TASKVIEW_TaskCreateElementSet_H diff --git a/src/Mod/Fem/Gui/TaskDlgCreateElementSet.cpp b/src/Mod/Fem/Gui/TaskDlgCreateElementSet.cpp index dc7da4b38a..a987486d93 100644 --- a/src/Mod/Fem/Gui/TaskDlgCreateElementSet.cpp +++ b/src/Mod/Fem/Gui/TaskDlgCreateElementSet.cpp @@ -43,8 +43,9 @@ using namespace FemGui; // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgCreateElementSet::TaskDlgCreateElementSet(Fem::FemSetElementNodesObject *obj) - : TaskDialog(),FemSetElementNodesObject(obj) +TaskDlgCreateElementSet::TaskDlgCreateElementSet(Fem::FemSetElementNodesObject* obj) + : TaskDialog() + , FemSetElementNodesObject(obj) { name = new TaskObjectName(obj); param = new TaskCreateElementSet(obj); @@ -54,9 +55,7 @@ TaskDlgCreateElementSet::TaskDlgCreateElementSet(Fem::FemSetElementNodesObject * } TaskDlgCreateElementSet::~TaskDlgCreateElementSet() -{ - -} +{} //==== calls from the TaskView =============================================================== @@ -66,7 +65,6 @@ void TaskDlgCreateElementSet::open() // select->activate(); // Edge2TaskObject->execute(); // param->setEdgeAndClusterNbr(Edge2TaskObject->NbrOfEdges,Edge2TaskObject->NbrOfCluster); - } bool TaskDlgCreateElementSet::accept() diff --git a/src/Mod/Fem/Gui/TaskDlgCreateElementSet.h b/src/Mod/Fem/Gui/TaskDlgCreateElementSet.h index 9848b2df36..dc0b96767b 100644 --- a/src/Mod/Fem/Gui/TaskDlgCreateElementSet.h +++ b/src/Mod/Fem/Gui/TaskDlgCreateElementSet.h @@ -49,12 +49,12 @@ namespace FemGui /// simulation dialog for the TaskView -class TaskDlgCreateElementSet : public Gui::TaskView::TaskDialog +class TaskDlgCreateElementSet: public Gui::TaskView::TaskDialog { Q_OBJECT public: - TaskDlgCreateElementSet(Fem::FemSetElementNodesObject *); + TaskDlgCreateElementSet(Fem::FemSetElementNodesObject*); ~TaskDlgCreateElementSet() override; public: @@ -81,7 +81,6 @@ protected: }; - } // namespace FemGui #endif // ROBOTGUI_TASKDLGSIMULATE_H diff --git a/src/Mod/Fem/Gui/ViewProviderSetElementNodes.h b/src/Mod/Fem/Gui/ViewProviderSetElementNodes.h index a8c038dda6..f9971d2b8a 100644 --- a/src/Mod/Fem/Gui/ViewProviderSetElementNodes.h +++ b/src/Mod/Fem/Gui/ViewProviderSetElementNodes.h @@ -32,7 +32,7 @@ namespace FemGui { -class ViewProviderSetElementNodes : public Gui::ViewProviderGeometryObject +class ViewProviderSetElementNodes: public Gui::ViewProviderGeometryObject { PROPERTY_HEADER_WITH_OVERRIDE(FemGui::ViewProviderSetElementNodes); diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index 43e14344d4..9ef6d4ae4d 100644 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -1,9 +1,9 @@ /*************************************************************************** * Copyright (c) 2023 Peter McB * - * additional statement(s) for element sets: * + * additional statement(s) for element sets: * * added entry to Gui::MenuItem* mesh * * * - * added to: Workbench.cpp + * added to: Workbench.cpp * Copyright (c) 2008 Werner Mayer * * * * This file is part of the FreeCAD CAx development system. *