diff --git a/src/Mod/Mesh/BuildRegularGeoms.py b/src/Mod/Mesh/BuildRegularGeoms.py index 0d08a7117b..4be4b09cfe 100644 --- a/src/Mod/Mesh/BuildRegularGeoms.py +++ b/src/Mod/Mesh/BuildRegularGeoms.py @@ -15,7 +15,8 @@ Sample code for creating a mesh: import math -def Sphere (radius, count): + +def Sphere(radius, count): """Creates a sphere with a given radius. bla bla bla @@ -23,11 +24,12 @@ def Sphere (radius, count): """ return Ellipsoid(radius, radius, count) -def Ellipsoid (lenX, lenY, count): + +def Ellipsoid(lenX, lenY, count): polyline = [] step = math.pi / count i = 0.0 - while (i < math.pi + step / 10.0): + while i < math.pi + step / 10.0: x = math.cos(i) * lenX y = math.sin(i) * lenY polyline.append([x, y]) @@ -35,53 +37,56 @@ def Ellipsoid (lenX, lenY, count): return RotationBody(polyline, count) -def Cylinder (radius, len, closed, edgelen, count): + +def Cylinder(radius, len, closed, edgelen, count): return Cone(radius, radius, len, closed, edgelen, count) -def Cone (radius1, radius2, len, closed, edgelen, count): + +def Cone(radius1, radius2, len, closed, edgelen, count): polyline = [] - if (closed): + if closed: try: step = radius2 / math.ceil(radius2 / edgelen) except ZeroDivisionError: pass else: i = 0.0 - while (i < radius2 - step / 2.0): + while i < radius2 - step / 2.0: polyline.append([len, i]) i = i + step ct = math.ceil(len / edgelen) step = len / ct rstep = (radius1 - radius2) / ct - i = len; + i = len r = radius2 - while (i > 0.0 + step / 2.0): + while i > 0.0 + step / 2.0: polyline.append([i, r]) i = i - step r = r + rstep polyline.append([0.0, radius1]) - if (closed): + if closed: try: step = radius1 / math.ceil(radius1 / edgelen) except ZeroDivisionError: pass else: i = radius1 - step - while (i > 0.0 + step / 2.0): + while i > 0.0 + step / 2.0: polyline.append([0.0, i]) i = i - step polyline.append([0.0, 0.0]) return RotationBody(polyline, count) -def Toroid (radius1, radius2, count): + +def Toroid(radius1, radius2, count): polyline = [] step = math.pi * 2.0 / count i = -math.pi - while (i < math.pi + step / 10.0): + while i < math.pi + step / 10.0: x = radius1 + math.cos(i) * radius2 y = radius1 + math.sin(i) * radius2 polyline.append([x, y]) @@ -90,7 +95,7 @@ def Toroid (radius1, radius2, count): return RotationBody(polyline, count) -def RotationBody (polyline, count): +def RotationBody(polyline, count): """Build a rotation body from a given (closed) polyline, rotation axis is the X-Axis. Parameter: polyline: list of tuple of 2 floats (2d vector) @@ -99,12 +104,12 @@ def RotationBody (polyline, count): facets = [] step = math.pi * 2.0 / count - i = -math.pi; - while (i < math.pi - step / 10.0): + i = -math.pi + while i < math.pi - step / 10.0: li = i + step for j in range(0, len(polyline) - 1): v1 = polyline[j] - v2 = polyline[j+1] + v2 = polyline[j + 1] x1 = v1[0] y1 = v1[1] * math.cos(i) @@ -119,21 +124,22 @@ def RotationBody (polyline, count): y4 = v2[1] * math.cos(li) z4 = v2[1] * math.sin(li) - if (v1[1] != 0.0): + if v1[1] != 0.0: facets.append([x1, y1, z1]) facets.append([x2, y2, z2]) facets.append([x3, y3, z3]) - if (v2[1] != 0.0): + if v2[1] != 0.0: facets.append([x2, y2, z2]) facets.append([x4, y4, z4]) facets.append([x3, y3, z3]) i = i + step - return facets; + return facets -def Cube (lenX, lenY, lenZ): + +def Cube(lenX, lenY, lenZ): hx = lenX / 2.0 hy = lenY / 2.0 hz = lenZ / 2.0 @@ -190,80 +196,83 @@ def Cube (lenX, lenY, lenZ): return facets -def FineCube (lenX, lenY, lenZ, edgelen): + +def FineCube(lenX, lenY, lenZ, edgelen): hx = lenX / 2.0 hy = lenY / 2.0 hz = lenZ / 2.0 - cx = int(max(lenX / edgelen,1)) + cx = int(max(lenX / edgelen, 1)) dx = lenX / cx - cy = int(max(lenY / edgelen,1)) + cy = int(max(lenY / edgelen, 1)) dy = lenY / cy - cz = int(max(lenZ / edgelen,1)) + cz = int(max(lenZ / edgelen, 1)) dz = lenZ / cz facets = [] # z - for i in range(0,cx): - for j in range(0,cy): - facets.append([-hx+(i+0)*dx, -hy+(j+0)*dy, -hz]) - facets.append([-hx+(i+0)*dx, -hy+(j+1)*dy, -hz]) - facets.append([-hx+(i+1)*dx, -hy+(j+1)*dy, -hz]) + for i in range(0, cx): + for j in range(0, cy): + facets.append([-hx + (i + 0) * dx, -hy + (j + 0) * dy, -hz]) + facets.append([-hx + (i + 0) * dx, -hy + (j + 1) * dy, -hz]) + facets.append([-hx + (i + 1) * dx, -hy + (j + 1) * dy, -hz]) - facets.append([-hx+(i+0)*dx, -hy+(j+0)*dy, -hz]) - facets.append([-hx+(i+1)*dx, -hy+(j+1)*dy, -hz]) - facets.append([-hx+(i+1)*dx, -hy+(j+0)*dy, -hz]) + facets.append([-hx + (i + 0) * dx, -hy + (j + 0) * dy, -hz]) + facets.append([-hx + (i + 1) * dx, -hy + (j + 1) * dy, -hz]) + facets.append([-hx + (i + 1) * dx, -hy + (j + 0) * dy, -hz]) - facets.append([-hx+(i+0)*dx, -hy+(j+0)*dy, hz]) - facets.append([-hx+(i+1)*dx, -hy+(j+1)*dy, hz]) - facets.append([-hx+(i+0)*dx, -hy+(j+1)*dy, hz]) + facets.append([-hx + (i + 0) * dx, -hy + (j + 0) * dy, hz]) + facets.append([-hx + (i + 1) * dx, -hy + (j + 1) * dy, hz]) + facets.append([-hx + (i + 0) * dx, -hy + (j + 1) * dy, hz]) - facets.append([-hx+(i+0)*dx, -hy+(j+0)*dy, hz]) - facets.append([-hx+(i+1)*dx, -hy+(j+0)*dy, hz]) - facets.append([-hx+(i+1)*dx, -hy+(j+1)*dy, hz]) + facets.append([-hx + (i + 0) * dx, -hy + (j + 0) * dy, hz]) + facets.append([-hx + (i + 1) * dx, -hy + (j + 0) * dy, hz]) + facets.append([-hx + (i + 1) * dx, -hy + (j + 1) * dy, hz]) # y - for i in range(0,cx): - for j in range(0,cz): - facets.append([-hx+(i+0)*dx, -hy, -hz+(j+0)*dz]) - facets.append([-hx+(i+1)*dx, -hy, -hz+(j+1)*dz]) - facets.append([-hx+(i+0)*dx, -hy, -hz+(j+1)*dz]) + for i in range(0, cx): + for j in range(0, cz): + facets.append([-hx + (i + 0) * dx, -hy, -hz + (j + 0) * dz]) + facets.append([-hx + (i + 1) * dx, -hy, -hz + (j + 1) * dz]) + facets.append([-hx + (i + 0) * dx, -hy, -hz + (j + 1) * dz]) - facets.append([-hx+(i+0)*dx, -hy, -hz+(j+0)*dz]) - facets.append([-hx+(i+1)*dx, -hy, -hz+(j+0)*dz]) - facets.append([-hx+(i+1)*dx, -hy, -hz+(j+1)*dz]) + facets.append([-hx + (i + 0) * dx, -hy, -hz + (j + 0) * dz]) + facets.append([-hx + (i + 1) * dx, -hy, -hz + (j + 0) * dz]) + facets.append([-hx + (i + 1) * dx, -hy, -hz + (j + 1) * dz]) - facets.append([-hx+(i+0)*dx, hy, -hz+(j+0)*dz]) - facets.append([-hx+(i+0)*dx, hy, -hz+(j+1)*dz]) - facets.append([-hx+(i+1)*dx, hy, -hz+(j+1)*dz]) + facets.append([-hx + (i + 0) * dx, hy, -hz + (j + 0) * dz]) + facets.append([-hx + (i + 0) * dx, hy, -hz + (j + 1) * dz]) + facets.append([-hx + (i + 1) * dx, hy, -hz + (j + 1) * dz]) - facets.append([-hx+(i+0)*dx, hy, -hz+(j+0)*dz]) - facets.append([-hx+(i+1)*dx, hy, -hz+(j+1)*dz]) - facets.append([-hx+(i+1)*dx, hy, -hz+(j+0)*dz]) + facets.append([-hx + (i + 0) * dx, hy, -hz + (j + 0) * dz]) + facets.append([-hx + (i + 1) * dx, hy, -hz + (j + 1) * dz]) + facets.append([-hx + (i + 1) * dx, hy, -hz + (j + 0) * dz]) # x - for i in range(0,cy): - for j in range(0,cz): - facets.append([-hx, -hy+(i+0)*dy, -hz+(j+0)*dz]) - facets.append([-hx, -hy+(i+0)*dy, -hz+(j+1)*dz]) - facets.append([-hx, -hy+(i+1)*dy, -hz+(j+1)*dz]) + for i in range(0, cy): + for j in range(0, cz): + facets.append([-hx, -hy + (i + 0) * dy, -hz + (j + 0) * dz]) + facets.append([-hx, -hy + (i + 0) * dy, -hz + (j + 1) * dz]) + facets.append([-hx, -hy + (i + 1) * dy, -hz + (j + 1) * dz]) - facets.append([-hx, -hy+(i+0)*dy, -hz+(j+0)*dz]) - facets.append([-hx, -hy+(i+1)*dy, -hz+(j+1)*dz]) - facets.append([-hx, -hy+(i+1)*dy, -hz+(j+0)*dz]) + facets.append([-hx, -hy + (i + 0) * dy, -hz + (j + 0) * dz]) + facets.append([-hx, -hy + (i + 1) * dy, -hz + (j + 1) * dz]) + facets.append([-hx, -hy + (i + 1) * dy, -hz + (j + 0) * dz]) - facets.append([hx, -hy+(i+0)*dy, -hz+(j+0)*dz]) - facets.append([hx, -hy+(i+1)*dy, -hz+(j+1)*dz]) - facets.append([hx, -hy+(i+0)*dy, -hz+(j+1)*dz]) + facets.append([hx, -hy + (i + 0) * dy, -hz + (j + 0) * dz]) + facets.append([hx, -hy + (i + 1) * dy, -hz + (j + 1) * dz]) + facets.append([hx, -hy + (i + 0) * dy, -hz + (j + 1) * dz]) - facets.append([hx, -hy+(i+0)*dy, -hz+(j+0)*dz]) - facets.append([hx, -hy+(i+1)*dy, -hz+(j+0)*dz]) - facets.append([hx, -hy+(i+1)*dy, -hz+(j+1)*dz]) + facets.append([hx, -hy + (i + 0) * dy, -hz + (j + 0) * dz]) + facets.append([hx, -hy + (i + 1) * dy, -hz + (j + 0) * dz]) + facets.append([hx, -hy + (i + 1) * dy, -hz + (j + 1) * dz]) return facets -def main (): - Cylinder (10.0, 20.0, 1, 10, 10) + +def main(): + Cylinder(10.0, 20.0, 1, 10, 10) + if __name__ == "__main__": main() diff --git a/src/Mod/Mesh/CMakeLists.txt b/src/Mod/Mesh/CMakeLists.txt index 11664eff9f..5201728eb4 100644 --- a/src/Mod/Mesh/CMakeLists.txt +++ b/src/Mod/Mesh/CMakeLists.txt @@ -47,4 +47,3 @@ INSTALL( INSTALL(FILES ${MeshTestDataFiles} DESTINATION Mod/Mesh/App/TestData) - diff --git a/src/Mod/Mesh/Gui/AppMeshGui.cpp b/src/Mod/Mesh/Gui/AppMeshGui.cpp index 3386a50806..c871bde735 100644 --- a/src/Mod/Mesh/Gui/AppMeshGui.cpp +++ b/src/Mod/Mesh/Gui/AppMeshGui.cpp @@ -22,12 +22,12 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include +#include +#include +#include +#include -# include +#include #endif #include @@ -35,13 +35,12 @@ #include #include #include -#include #include +#include #include "DlgEvaluateMeshImp.h" #include "DlgSettingsImportExportImp.h" #include "DlgSettingsMeshView.h" -#include "images.h" #include "PropertyEditorMesh.h" #include "SoFCIndexedFaceSet.h" #include "SoFCMeshObject.h" @@ -55,6 +54,7 @@ #include "ViewProviderTransform.h" #include "ViewProviderTransformDemolding.h" #include "Workbench.h" +#include "images.h" // use a different name to CreateCommand() @@ -68,16 +68,16 @@ void loadMeshResource() Gui::Translator::instance()->refresh(); } -namespace MeshGui { -class Module : public Py::ExtensionModule +namespace MeshGui +{ +class Module: public Py::ExtensionModule { public: - Module() : Py::ExtensionModule("MeshGui") + Module() + : Py::ExtensionModule("MeshGui") { - add_varargs_method("convertToSTL",&Module::convertToSTL, - "Convert a scene into an STL." - ); - initialize("This module is the MeshGui module."); // register with Python + add_varargs_method("convertToSTL", &Module::convertToSTL, "Convert a scene into an STL."); + initialize("This module is the MeshGui module."); // register with Python } private: @@ -85,8 +85,9 @@ private: { char* inname; char* outname; - if (!PyArg_ParseTuple(args.ptr(), "etet","utf-8",&inname,"utf-8",&outname)) + if (!PyArg_ParseTuple(args.ptr(), "etet", "utf-8", &inname, "utf-8", &outname)) { throw Py::Exception(); + } std::string inputName = std::string(inname); PyMem_Free(inname); std::string outputName = std::string(outname); @@ -95,7 +96,7 @@ private: bool ok = false; SoInput in; if (in.openFile(inputName.c_str())) { - SoSeparator * node = SoDB::readAll(&in); + SoSeparator* node = SoDB::readAll(&in); if (node) { node->ref(); SoSTLFileKit* stlKit = new SoSTLFileKit(); @@ -116,7 +117,7 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -} // namespace MeshGui +} // namespace MeshGui /* Python entry */ PyMOD_INIT_FUNC(MeshGui) @@ -130,7 +131,7 @@ PyMOD_INIT_FUNC(MeshGui) try { Base::Interpreter().loadModule("Mesh"); } - catch(const Base::Exception& e) { + catch (const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); PyMOD_Return(nullptr); } @@ -147,18 +148,22 @@ PyMOD_INIT_FUNC(MeshGui) } // try to instantiate flat-mesh commands - try{ + try { Base::Interpreter().runString("import MeshFlatteningCommand"); - } catch (Base::PyException &err){ + } + catch (Base::PyException& err) { err.ReportException(); } // register preferences pages - (void)new Gui::PrefPageProducer (QT_TRANSLATE_NOOP("QObject", "Display")); - (void)new Gui::PrefPageProducer ( QT_TRANSLATE_NOOP("QObject", "Import-Export") ); + (void)new Gui::PrefPageProducer( + QT_TRANSLATE_NOOP("QObject", "Display")); + (void)new Gui::PrefPageProducer( + QT_TRANSLATE_NOOP("QObject", "Import-Export")); Mesh::Extension3MFFactory::addProducer(new MeshGui::ThumbnailExtensionProducer); + // clang-format off MeshGui::SoFCMeshObjectElement ::initClass(); MeshGui::SoSFMeshObject ::initClass(); MeshGui::SoFCMeshObjectNode ::initClass(); @@ -197,6 +202,7 @@ PyMOD_INIT_FUNC(MeshGui) // add resources and reloads the translators loadMeshResource(); + // clang-format on PyMOD_Return(mod); } diff --git a/src/Mod/Mesh/Gui/Command.cpp b/src/Mod/Mesh/Gui/Command.cpp index 47ce40302e..cb188c68cc 100644 --- a/src/Mod/Mesh/Gui/Command.cpp +++ b/src/Mod/Mesh/Gui/Command.cpp @@ -22,25 +22,25 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# ifdef FC_OS_WIN32 -# include -# endif -# include +#ifdef FC_OS_WIN32 +#include +#endif +#include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include #endif #ifndef __InventorAll__ -# include +#include #endif -#include #include +#include #include #include #include @@ -57,9 +57,9 @@ #include #include +#include #include #include -#include #include "DlgDecimating.h" #include "DlgEvaluateMeshImp.h" @@ -77,24 +77,24 @@ using namespace Mesh; - DEF_STD_CMD_A(CmdMeshUnion) CmdMeshUnion::CmdMeshUnion() - :Command("Mesh_Union") + : Command("Mesh_Union") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Union"); - sToolTipText = sMenuText; - sWhatsThis = "Mesh_Union"; - sStatusTip = sMenuText; - sPixmap = "Mesh_Union"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Union"); + sToolTipText = sMenuText; + sWhatsThis = "Mesh_Union"; + sStatusTip = sMenuText; + sPixmap = "Mesh_Union"; } void CmdMeshUnion::activated(int) { - std::vector obj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector obj = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); std::string name1 = obj.front()->getNameInDocument(); std::string name2 = obj.back()->getNameInDocument(); std::string name3 = getUniqueObjectName("Union"); @@ -102,12 +102,16 @@ void CmdMeshUnion::activated(int) try { openCommand(QT_TRANSLATE_NOOP("Command", "Mesh union")); doCommand(Doc, - "import OpenSCADUtils\n" - "mesh = OpenSCADUtils.meshoptempfile('union',(App.ActiveDocument.%s.Mesh,App.ActiveDocument.%s.Mesh))\n" - "App.ActiveDocument.addObject(\"Mesh::Feature\",\"%s\")\n" - "App.ActiveDocument.%s.Mesh = mesh\n", - name1.c_str(), name2.c_str(), - name3.c_str(), name3.c_str()); + "import OpenSCADUtils\n" + "mesh = " + "OpenSCADUtils.meshoptempfile('union',(App.ActiveDocument.%s.Mesh,App." + "ActiveDocument.%s.Mesh))\n" + "App.ActiveDocument.addObject(\"Mesh::Feature\",\"%s\")\n" + "App.ActiveDocument.%s.Mesh = mesh\n", + name1.c_str(), + name2.c_str(), + name3.c_str(), + name3.c_str()); updateActive(); commitCommand(); @@ -129,15 +133,18 @@ void CmdMeshUnion::activated(int) } if (found) { - QMessageBox::critical(Gui::getMainWindow(), + QMessageBox::critical( + Gui::getMainWindow(), qApp->translate("Mesh_Union", "OpenSCAD"), qApp->translate("Mesh_Union", "Unknown error occurred while running OpenSCAD.")); } else { - QMessageBox::warning(Gui::getMainWindow(), + QMessageBox::warning( + Gui::getMainWindow(), qApp->translate("Mesh_Union", "OpenSCAD"), - qApp->translate("Mesh_Union", "OpenSCAD cannot be found on your system.\n" - "Please visit http://www.openscad.org/index.html to install it.")); + qApp->translate("Mesh_Union", + "OpenSCAD cannot be found on your system.\n" + "Please visit http://www.openscad.org/index.html to install it.")); } } } @@ -152,20 +159,21 @@ bool CmdMeshUnion::isActive() DEF_STD_CMD_A(CmdMeshDifference) CmdMeshDifference::CmdMeshDifference() - :Command("Mesh_Difference") + : Command("Mesh_Difference") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Difference"); - sToolTipText = sMenuText; - sWhatsThis = "Mesh_Difference"; - sStatusTip = sMenuText; - sPixmap = "Mesh_Difference"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Difference"); + sToolTipText = sMenuText; + sWhatsThis = "Mesh_Difference"; + sStatusTip = sMenuText; + sPixmap = "Mesh_Difference"; } void CmdMeshDifference::activated(int) { - std::vector obj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector obj = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); std::string name1 = obj.front()->getNameInDocument(); std::string name2 = obj.back()->getNameInDocument(); std::string name3 = getUniqueObjectName("Difference"); @@ -173,12 +181,16 @@ void CmdMeshDifference::activated(int) try { doCommand(Doc, - "import OpenSCADUtils\n" - "mesh = OpenSCADUtils.meshoptempfile('difference',(App.ActiveDocument.%s.Mesh,App.ActiveDocument.%s.Mesh))\n" - "App.ActiveDocument.addObject(\"Mesh::Feature\",\"%s\")\n" - "App.ActiveDocument.%s.Mesh = mesh\n", - name1.c_str(), name2.c_str(), - name3.c_str(), name3.c_str()); + "import OpenSCADUtils\n" + "mesh = " + "OpenSCADUtils.meshoptempfile('difference',(App.ActiveDocument.%s.Mesh,App." + "ActiveDocument.%s.Mesh))\n" + "App.ActiveDocument.addObject(\"Mesh::Feature\",\"%s\")\n" + "App.ActiveDocument.%s.Mesh = mesh\n", + name1.c_str(), + name2.c_str(), + name3.c_str(), + name3.c_str()); updateActive(); commitCommand(); @@ -200,15 +212,18 @@ void CmdMeshDifference::activated(int) } if (found) { - QMessageBox::critical(Gui::getMainWindow(), + QMessageBox::critical( + Gui::getMainWindow(), qApp->translate("Mesh_Union", "OpenSCAD"), qApp->translate("Mesh_Union", "Unknown error occurred while running OpenSCAD.")); } else { - QMessageBox::warning(Gui::getMainWindow(), + QMessageBox::warning( + Gui::getMainWindow(), qApp->translate("Mesh_Union", "OpenSCAD"), - qApp->translate("Mesh_Union", "OpenSCAD cannot be found on your system.\n" - "Please visit http://www.openscad.org/index.html to install it.")); + qApp->translate("Mesh_Union", + "OpenSCAD cannot be found on your system.\n" + "Please visit http://www.openscad.org/index.html to install it.")); } } } @@ -223,20 +238,21 @@ bool CmdMeshDifference::isActive() DEF_STD_CMD_A(CmdMeshIntersection) CmdMeshIntersection::CmdMeshIntersection() - :Command("Mesh_Intersection") + : Command("Mesh_Intersection") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Intersection"); - sToolTipText = sMenuText; - sWhatsThis = "Mesh_Intersection"; - sStatusTip = sMenuText; - sPixmap = "Mesh_Intersection"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Intersection"); + sToolTipText = sMenuText; + sWhatsThis = "Mesh_Intersection"; + sStatusTip = sMenuText; + sPixmap = "Mesh_Intersection"; } void CmdMeshIntersection::activated(int) { - std::vector obj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector obj = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); std::string name1 = obj.front()->getNameInDocument(); std::string name2 = obj.back()->getNameInDocument(); std::string name3 = getUniqueObjectName("Intersection"); @@ -244,12 +260,16 @@ void CmdMeshIntersection::activated(int) try { doCommand(Doc, - "import OpenSCADUtils\n" - "mesh = OpenSCADUtils.meshoptempfile('intersection',(App.ActiveDocument.%s.Mesh,App.ActiveDocument.%s.Mesh))\n" - "App.ActiveDocument.addObject(\"Mesh::Feature\",\"%s\")\n" - "App.ActiveDocument.%s.Mesh = mesh\n", - name1.c_str(), name2.c_str(), - name3.c_str(), name3.c_str()); + "import OpenSCADUtils\n" + "mesh = " + "OpenSCADUtils.meshoptempfile('intersection',(App.ActiveDocument.%s.Mesh,App." + "ActiveDocument.%s.Mesh))\n" + "App.ActiveDocument.addObject(\"Mesh::Feature\",\"%s\")\n" + "App.ActiveDocument.%s.Mesh = mesh\n", + name1.c_str(), + name2.c_str(), + name3.c_str(), + name3.c_str()); updateActive(); commitCommand(); @@ -271,15 +291,18 @@ void CmdMeshIntersection::activated(int) } if (found) { - QMessageBox::critical(Gui::getMainWindow(), + QMessageBox::critical( + Gui::getMainWindow(), qApp->translate("Mesh_Union", "OpenSCAD"), qApp->translate("Mesh_Union", "Unknown error occurred while running OpenSCAD.")); } else { - QMessageBox::warning(Gui::getMainWindow(), + QMessageBox::warning( + Gui::getMainWindow(), qApp->translate("Mesh_Union", "OpenSCAD"), - qApp->translate("Mesh_Union", "OpenSCAD cannot be found on your system.\n" - "Please visit http://www.openscad.org/index.html to install it.")); + qApp->translate("Mesh_Union", + "OpenSCAD cannot be found on your system.\n" + "Please visit http://www.openscad.org/index.html to install it.")); } } } @@ -294,22 +317,23 @@ bool CmdMeshIntersection::isActive() DEF_STD_CMD_A(CmdMeshImport) CmdMeshImport::CmdMeshImport() - :Command("Mesh_Import") + : Command("Mesh_Import") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Import mesh..."); - sToolTipText = QT_TR_NOOP("Imports a mesh from file"); - sWhatsThis = "Mesh_Import"; - sStatusTip = QT_TR_NOOP("Imports a mesh from file"); - sPixmap = "Mesh_Import"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Import mesh..."); + sToolTipText = QT_TR_NOOP("Imports a mesh from file"); + sWhatsThis = "Mesh_Import"; + sStatusTip = QT_TR_NOOP("Imports a mesh from file"); + sPixmap = "Mesh_Import"; } void CmdMeshImport::activated(int) { // use current path as default QStringList filter; - filter << QString::fromLatin1("%1 (*.stl *.ast *.bms *.obj *.off *.iv *.ply *.nas *.bdf)").arg(QObject::tr("All Mesh Files")); + filter << QString::fromLatin1("%1 (*.stl *.ast *.bms *.obj *.off *.iv *.ply *.nas *.bdf)") + .arg(QObject::tr("All Mesh Files")); filter << QString::fromLatin1("%1 (*.stl)").arg(QObject::tr("Binary STL")); filter << QString::fromLatin1("%1 (*.ast)").arg(QObject::tr("ASCII STL")); filter << QString::fromLatin1("%1 (*.bms)").arg(QObject::tr("Binary Mesh")); @@ -322,14 +346,15 @@ void CmdMeshImport::activated(int) // Allow multi selection QStringList fn = Gui::FileDialog::getOpenFileNames(Gui::getMainWindow(), - QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;"))); + QObject::tr("Import mesh"), + QString(), + filter.join(QLatin1String(";;"))); for (const auto& it : fn) { std::string unicodepath = Base::Tools::escapedUnicodeFromUtf8(it.toUtf8().data()); unicodepath = Base::Tools::escapeEncodeFilename(unicodepath); openCommand(QT_TRANSLATE_NOOP("Command", "Import Mesh")); - doCommand(Doc,"import Mesh"); - doCommand(Doc,"Mesh.insert(u\"%s\")", - unicodepath.c_str()); + doCommand(Doc, "import Mesh"); + doCommand(Doc, "Mesh.insert(u\"%s\")", unicodepath.c_str()); commitCommand(); updateActive(); } @@ -345,26 +370,28 @@ bool CmdMeshImport::isActive() DEF_STD_CMD_A(CmdMeshExport) CmdMeshExport::CmdMeshExport() - :Command("Mesh_Export") + : Command("Mesh_Export") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Export mesh..."); - sToolTipText = QT_TR_NOOP("Exports a mesh to file"); - sWhatsThis = "Mesh_Export"; - sStatusTip = QT_TR_NOOP("Exports a mesh to file"); - sPixmap = "Mesh_Export"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Export mesh..."); + sToolTipText = QT_TR_NOOP("Exports a mesh to file"); + sWhatsThis = "Mesh_Export"; + sStatusTip = QT_TR_NOOP("Exports a mesh to file"); + sPixmap = "Mesh_Export"; } void CmdMeshExport::activated(int) { - std::vector docObjs = Gui::Selection().getObjectsOfType - (Mesh::Feature::getClassTypeId()); - if (docObjs.size() != 1) + std::vector docObjs = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + if (docObjs.size() != 1) { return; + } App::DocumentObject* docObj = docObjs.front(); + // clang-format off QString dir = QString::fromUtf8(docObj->Label.getValue()); QList > ext; ext << qMakePair(QString::fromLatin1("%1 (*.stl)").arg(QObject::tr("Binary STL")), "STL"); @@ -386,13 +413,18 @@ void CmdMeshExport::activated(int) ext << qMakePair(QString::fromLatin1("%1 (*.asy)").arg(QObject::tr("Asymptote Format")), "ASY"); ext << qMakePair(QString::fromLatin1("%1 (*.3mf)").arg(QObject::tr("3D Manufacturing Format")), "3MF"); ext << qMakePair(QString::fromLatin1("%1 (*.*)").arg(QObject::tr("All Files")), ""); // Undefined + // clang-format on QStringList filter; - for (const auto& it : ext) + for (const auto& it : ext) { filter << it.first; + } QString format; QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), - QObject::tr("Export mesh"), dir, filter.join(QLatin1String(";;")), &format); + QObject::tr("Export mesh"), + dir, + filter.join(QLatin1String(";;")), + &format); if (!fn.isEmpty()) { QFileInfo fi(fn); QByteArray extension = fi.suffix().toLatin1(); @@ -403,7 +435,8 @@ void CmdMeshExport::activated(int) } } - MeshGui::ViewProviderMesh* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(docObj)); + MeshGui::ViewProviderMesh* vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(docObj)); if (vp) { vp->exportMesh((const char*)fn.toUtf8(), (const char*)extension); } @@ -420,26 +453,35 @@ bool CmdMeshExport::isActive() DEF_STD_CMD_A(CmdMeshFromGeometry) CmdMeshFromGeometry::CmdMeshFromGeometry() - :Command("Mesh_FromGeometry") + : Command("Mesh_FromGeometry") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Create mesh from geometry..."); - sToolTipText = QT_TR_NOOP("Create mesh from the selected geometry"); - sWhatsThis = "Mesh_FromGeometry"; - sStatusTip = QT_TR_NOOP("Create mesh from the selected geometry"); + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Create mesh from geometry..."); + sToolTipText = QT_TR_NOOP("Create mesh from the selected geometry"); + sWhatsThis = "Mesh_FromGeometry"; + sStatusTip = QT_TR_NOOP("Create mesh from the selected geometry"); } void CmdMeshFromGeometry::activated(int) { bool ok; - double tol = QInputDialog::getDouble(Gui::getMainWindow(), QObject::tr("Meshing Tolerance"), - QObject::tr("Enter tolerance for meshing geometry:"), 0.1, 0.01, 10.0, 2, &ok, Qt::MSWindowsFixedSizeDialogHint); - if (!ok) + double tol = QInputDialog::getDouble(Gui::getMainWindow(), + QObject::tr("Meshing Tolerance"), + QObject::tr("Enter tolerance for meshing geometry:"), + 0.1, + 0.01, + 10.0, + 2, + &ok, + Qt::MSWindowsFixedSizeDialogHint); + if (!ok) { return; + } App::Document* doc = App::GetApplication().getActiveDocument(); - std::vector geo = Gui::Selection().getObjectsOfType(App::GeoFeature::getClassTypeId()); + std::vector geo = + Gui::Selection().getObjectsOfType(App::GeoFeature::getClassTypeId()); for (auto it : geo) { if (!it->getTypeId().isDerivedFrom(Mesh::Feature::getClassTypeId())) { // exclude meshes @@ -447,19 +489,23 @@ void CmdMeshFromGeometry::activated(int) it->getPropertyMap(Map); Mesh::MeshObject mesh; for (const auto& jt : Map) { - if (jt.first == "Shape" && jt.second->getTypeId().isDerivedFrom(App::PropertyComplexGeoData::getClassTypeId())) { + if (jt.first == "Shape" + && jt.second->getTypeId().isDerivedFrom( + App::PropertyComplexGeoData::getClassTypeId())) { std::vector aPoints; std::vector aTopo; - const Data::ComplexGeoData* data = static_cast(jt.second)->getComplexData(); + const Data::ComplexGeoData* data = + static_cast(jt.second)->getComplexData(); if (data) { - data->getFaces(aPoints, aTopo,(float)tol); + data->getFaces(aPoints, aTopo, (float)tol); mesh.setFacets(aTopo, aPoints); } } } // create a mesh feature and assign the mesh - Mesh::Feature* mf = static_cast(doc->addObject("Mesh::Feature","Mesh")); + Mesh::Feature* mf = + static_cast(doc->addObject("Mesh::Feature", "Mesh")); mf->Mesh.setValue(mesh.getKernel()); } } @@ -468,8 +514,9 @@ void CmdMeshFromGeometry::activated(int) bool CmdMeshFromGeometry::isActive() { App::Document* doc = App::GetApplication().getActiveDocument(); - if (!doc) + if (!doc) { return false; + } return getSelection().countObjectsOfType(App::GeoFeature::getClassTypeId()) >= 1; } @@ -479,20 +526,20 @@ bool CmdMeshFromGeometry::isActive() DEF_STD_CMD_A(CmdMeshFromPartShape) CmdMeshFromPartShape::CmdMeshFromPartShape() - : Command("Mesh_FromPartShape") + : Command("Mesh_FromPartShape") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Create mesh from shape..."); - sToolTipText = QT_TR_NOOP("Tessellate shape"); - sWhatsThis = "Mesh_FromPartShape"; - sStatusTip = sToolTipText; - sPixmap = "Mesh_FromPartShape.svg"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Create mesh from shape..."); + sToolTipText = QT_TR_NOOP("Tessellate shape"); + sWhatsThis = "Mesh_FromPartShape"; + sStatusTip = sToolTipText; + sPixmap = "Mesh_FromPartShape.svg"; } void CmdMeshFromPartShape::activated(int) { - doCommand(Doc,"import MeshPartGui, FreeCADGui\nFreeCADGui.runCommand('MeshPart_Mesher')\n"); + doCommand(Doc, "import MeshPartGui, FreeCADGui\nFreeCADGui.runCommand('MeshPart_Mesher')\n"); } bool CmdMeshFromPartShape::isActive() @@ -505,32 +552,43 @@ bool CmdMeshFromPartShape::isActive() DEF_STD_CMD_A(CmdMeshVertexCurvature) CmdMeshVertexCurvature::CmdMeshVertexCurvature() - : Command("Mesh_VertexCurvature") + : Command("Mesh_VertexCurvature") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Curvature plot"); - sToolTipText = QT_TR_NOOP("Calculates the curvature of the vertices of a mesh"); - sWhatsThis = "Mesh_VertexCurvature"; - sStatusTip = QT_TR_NOOP("Calculates the curvature of the vertices of a mesh"); - sPixmap = "Mesh_VertexCurvature"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Curvature plot"); + sToolTipText = QT_TR_NOOP("Calculates the curvature of the vertices of a mesh"); + sWhatsThis = "Mesh_VertexCurvature"; + sStatusTip = QT_TR_NOOP("Calculates the curvature of the vertices of a mesh"); + sPixmap = "Mesh_VertexCurvature"; } void CmdMeshVertexCurvature::activated(int) { - std::vector meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector meshes = + getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); for (auto it : meshes) { std::string fName = it->getNameInDocument(); fName += "_Curvature"; fName = getUniqueObjectName(fName.c_str()); openCommand(QT_TRANSLATE_NOOP("Command", "Mesh VertexCurvature")); - App::DocumentObject* grp = App::DocumentObjectGroup::getGroupOfObject( it ); - if (grp) - doCommand(Doc,"App.activeDocument().getObject(\"%s\").newObject(\"Mesh::Curvature\",\"%s\")",grp->getNameInDocument(), fName.c_str()); - else - doCommand(Doc,"App.activeDocument().addObject(\"Mesh::Curvature\",\"%s\")",fName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",fName.c_str(), + App::DocumentObject* grp = App::DocumentObjectGroup::getGroupOfObject(it); + if (grp) { + doCommand( + Doc, + "App.activeDocument().getObject(\"%s\").newObject(\"Mesh::Curvature\",\"%s\")", + grp->getNameInDocument(), + fName.c_str()); + } + else { + doCommand(Doc, + "App.activeDocument().addObject(\"Mesh::Curvature\",\"%s\")", + fName.c_str()); + } + doCommand(Doc, + "App.activeDocument().%s.Source = App.activeDocument().%s", + fName.c_str(), it->getNameInDocument()); } @@ -549,15 +607,15 @@ bool CmdMeshVertexCurvature::isActive() DEF_STD_CMD_A(CmdMeshVertexCurvatureInfo) CmdMeshVertexCurvatureInfo::CmdMeshVertexCurvatureInfo() - :Command("Mesh_CurvatureInfo") + : Command("Mesh_CurvatureInfo") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Curvature info"); - sToolTipText = QT_TR_NOOP("Information about curvature"); - sWhatsThis = "Mesh_CurvatureInfo"; - sStatusTip = QT_TR_NOOP("Information about curvature"); - sPixmap = "Mesh_CurvatureInfo"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Curvature info"); + sToolTipText = QT_TR_NOOP("Information about curvature"); + sWhatsThis = "Mesh_CurvatureInfo"; + sStatusTip = QT_TR_NOOP("Information about curvature"); + sPixmap = "Mesh_CurvatureInfo"; } void CmdMeshVertexCurvatureInfo::activated(int) @@ -569,17 +627,19 @@ void CmdMeshVertexCurvatureInfo::activated(int) viewer->setEditing(true); viewer->setRedirectToSceneGraph(true); viewer->setSelectionEnabled(false); - viewer->setEditingCursor(QCursor(Gui::BitmapFactory().pixmapFromSvg("Mesh_Pipette",QSize(32,32)),4,29)); + viewer->setEditingCursor( + QCursor(Gui::BitmapFactory().pixmapFromSvg("Mesh_Pipette", QSize(32, 32)), 4, 29)); viewer->addEventCallback(SoEvent::getClassTypeId(), - MeshGui::ViewProviderMeshCurvature::curvatureInfoCallback); - } + MeshGui::ViewProviderMeshCurvature::curvatureInfoCallback); + } } bool CmdMeshVertexCurvatureInfo::isActive() { App::Document* doc = App::GetApplication().getActiveDocument(); - if (!doc || doc->countObjectsOfType(Mesh::Curvature::getClassTypeId()) == 0) + if (!doc || doc->countObjectsOfType(Mesh::Curvature::getClassTypeId()) == 0) { return false; + } Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { @@ -595,21 +655,23 @@ bool CmdMeshVertexCurvatureInfo::isActive() DEF_STD_CMD_A(CmdMeshPolySegm) CmdMeshPolySegm::CmdMeshPolySegm() - :Command("Mesh_PolySegm") + : Command("Mesh_PolySegm") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Make segment"); - sToolTipText = QT_TR_NOOP("Creates a mesh segment"); - sWhatsThis = "Mesh_PolySegm"; - sStatusTip = QT_TR_NOOP("Creates a mesh segment"); - sPixmap = "PolygonPick"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Make segment"); + sToolTipText = QT_TR_NOOP("Creates a mesh segment"); + sWhatsThis = "Mesh_PolySegm"; + sStatusTip = QT_TR_NOOP("Creates a mesh segment"); + sPixmap = "PolygonPick"; } void CmdMeshPolySegm::activated(int) { - std::vector docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); - for (std::vector::iterator it = docObj.begin(); it != docObj.end(); ++it) { + std::vector docObj = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + for (std::vector::iterator it = docObj.begin(); it != docObj.end(); + ++it) { if (it == docObj.begin()) { Gui::Document* doc = getActiveGuiDocument(); Gui::MDIView* view = doc->getActiveView(); @@ -626,16 +688,18 @@ void CmdMeshPolySegm::activated(int) } Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider(*it); - if (pVP->isVisible()) + if (pVP->isVisible()) { pVP->startEditing(); + } } } bool CmdMeshPolySegm::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) + if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { return false; + } Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { @@ -650,28 +714,29 @@ bool CmdMeshPolySegm::isActive() DEF_STD_CMD_A(CmdMeshAddFacet) CmdMeshAddFacet::CmdMeshAddFacet() - : Command("Mesh_AddFacet") + : Command("Mesh_AddFacet") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Add triangle"); - sToolTipText = QT_TR_NOOP("Add triangle manually to a mesh"); - sWhatsThis = "Mesh_AddFacet"; - sStatusTip = QT_TR_NOOP("Add triangle manually to a mesh"); - sPixmap = "Mesh_AddFacet"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Add triangle"); + sToolTipText = QT_TR_NOOP("Add triangle manually to a mesh"); + sWhatsThis = "Mesh_AddFacet"; + sStatusTip = QT_TR_NOOP("Add triangle manually to a mesh"); + sPixmap = "Mesh_AddFacet"; } void CmdMeshAddFacet::activated(int) { - std::vector docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector docObj = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); for (auto it : docObj) { Gui::Document* doc = Gui::Application::Instance->getDocument(it->getDocument()); Gui::MDIView* view = doc->getActiveView(); if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { - MeshGui::MeshFaceAddition* edit = new MeshGui::MeshFaceAddition - (static_cast(view)); - edit->startEditing(static_cast - (Gui::Application::Instance->getViewProvider(it))); + MeshGui::MeshFaceAddition* edit = + new MeshGui::MeshFaceAddition(static_cast(view)); + edit->startEditing(static_cast( + Gui::Application::Instance->getViewProvider(it))); break; } } @@ -680,8 +745,9 @@ void CmdMeshAddFacet::activated(int) bool CmdMeshAddFacet::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) + if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) { return false; + } Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { @@ -697,21 +763,23 @@ bool CmdMeshAddFacet::isActive() DEF_STD_CMD_A(CmdMeshPolyCut) CmdMeshPolyCut::CmdMeshPolyCut() - : Command("Mesh_PolyCut") + : Command("Mesh_PolyCut") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Cut mesh"); - sToolTipText = QT_TR_NOOP("Cuts a mesh with a picked polygon"); - sWhatsThis = "Mesh_PolyCut"; - sStatusTip = QT_TR_NOOP("Cuts a mesh with a picked polygon"); - sPixmap = "Mesh_PolyCut"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Cut mesh"); + sToolTipText = QT_TR_NOOP("Cuts a mesh with a picked polygon"); + sWhatsThis = "Mesh_PolyCut"; + sStatusTip = QT_TR_NOOP("Cuts a mesh with a picked polygon"); + sPixmap = "Mesh_PolyCut"; } void CmdMeshPolyCut::activated(int) { - std::vector docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); - for (std::vector::iterator it = docObj.begin(); it != docObj.end(); ++it) { + std::vector docObj = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + for (std::vector::iterator it = docObj.begin(); it != docObj.end(); + ++it) { if (it == docObj.begin()) { Gui::Document* doc = getActiveGuiDocument(); Gui::MDIView* view = doc->getActiveView(); @@ -721,7 +789,7 @@ void CmdMeshPolyCut::activated(int) Gui::PolyClipSelection* clip = new Gui::PolyClipSelection(); clip->setRole(Gui::SelectionRole::Split, true); - clip->setColor(0.0f,0.0f,1.0f); + clip->setColor(0.0f, 0.0f, 1.0f); clip->setLineWidth(1.0f); viewer->navigationStyle()->startSelection(clip); viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), @@ -733,16 +801,18 @@ void CmdMeshPolyCut::activated(int) } Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider(*it); - if (pVP->isVisible()) + if (pVP->isVisible()) { pVP->startEditing(); + } } } bool CmdMeshPolyCut::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) + if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { return false; + } Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { @@ -758,21 +828,23 @@ bool CmdMeshPolyCut::isActive() DEF_STD_CMD_A(CmdMeshPolyTrim) CmdMeshPolyTrim::CmdMeshPolyTrim() - : Command("Mesh_PolyTrim") + : Command("Mesh_PolyTrim") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Trim mesh"); - sToolTipText = QT_TR_NOOP("Trims a mesh with a picked polygon"); - sWhatsThis = "Mesh_PolyTrim"; - sStatusTip = QT_TR_NOOP("Trims a mesh with a picked polygon"); - sPixmap = "Mesh_PolyTrim"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Trim mesh"); + sToolTipText = QT_TR_NOOP("Trims a mesh with a picked polygon"); + sWhatsThis = "Mesh_PolyTrim"; + sStatusTip = QT_TR_NOOP("Trims a mesh with a picked polygon"); + sPixmap = "Mesh_PolyTrim"; } void CmdMeshPolyTrim::activated(int) { - std::vector docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); - for (std::vector::iterator it = docObj.begin(); it != docObj.end(); ++it) { + std::vector docObj = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + for (std::vector::iterator it = docObj.begin(); it != docObj.end(); + ++it) { if (it == docObj.begin()) { Gui::Document* doc = getActiveGuiDocument(); Gui::MDIView* view = doc->getActiveView(); @@ -782,7 +854,7 @@ void CmdMeshPolyTrim::activated(int) Gui::PolyClipSelection* clip = new Gui::PolyClipSelection(); clip->setRole(Gui::SelectionRole::Split, true); - clip->setColor(0.0f,0.0f,1.0f); + clip->setColor(0.0f, 0.0f, 1.0f); clip->setLineWidth(1.0f); viewer->navigationStyle()->startSelection(clip); viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), @@ -794,16 +866,18 @@ void CmdMeshPolyTrim::activated(int) } Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider(*it); - if (pVP->isVisible()) + if (pVP->isVisible()) { pVP->startEditing(); + } } } bool CmdMeshPolyTrim::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) + if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { return false; + } Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { @@ -819,26 +893,28 @@ bool CmdMeshPolyTrim::isActive() DEF_STD_CMD_A(CmdMeshTrimByPlane) CmdMeshTrimByPlane::CmdMeshTrimByPlane() - : Command("Mesh_TrimByPlane") + : Command("Mesh_TrimByPlane") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Trim mesh with a plane"); - sToolTipText = QT_TR_NOOP("Trims a mesh with a plane"); - sStatusTip = QT_TR_NOOP("Trims a mesh with a plane"); - sPixmap = "Mesh_TrimByPlane"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Trim mesh with a plane"); + sToolTipText = QT_TR_NOOP("Trims a mesh with a plane"); + sStatusTip = QT_TR_NOOP("Trims a mesh with a plane"); + sPixmap = "Mesh_TrimByPlane"; } void CmdMeshTrimByPlane::activated(int) { - doCommand(Doc,"import MeshPartGui, FreeCADGui\nFreeCADGui.runCommand('MeshPart_TrimByPlane')\n"); + doCommand(Doc, + "import MeshPartGui, FreeCADGui\nFreeCADGui.runCommand('MeshPart_TrimByPlane')\n"); } bool CmdMeshTrimByPlane::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) + if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) { return false; + } return true; } @@ -848,26 +924,28 @@ bool CmdMeshTrimByPlane::isActive() DEF_STD_CMD_A(CmdMeshSectionByPlane) CmdMeshSectionByPlane::CmdMeshSectionByPlane() - : Command("Mesh_SectionByPlane") + : Command("Mesh_SectionByPlane") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Create section from mesh and plane"); - sToolTipText = QT_TR_NOOP("Section from mesh and plane"); - sStatusTip = QT_TR_NOOP("Section from mesh and plane"); - sPixmap = "Mesh_SectionByPlane"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Create section from mesh and plane"); + sToolTipText = QT_TR_NOOP("Section from mesh and plane"); + sStatusTip = QT_TR_NOOP("Section from mesh and plane"); + sPixmap = "Mesh_SectionByPlane"; } void CmdMeshSectionByPlane::activated(int) { - doCommand(Doc,"import MeshPartGui, FreeCADGui\nFreeCADGui.runCommand('MeshPart_SectionByPlane')\n"); + doCommand(Doc, + "import MeshPartGui, FreeCADGui\nFreeCADGui.runCommand('MeshPart_SectionByPlane')\n"); } bool CmdMeshSectionByPlane::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) + if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) { return false; + } return true; } @@ -877,25 +955,26 @@ bool CmdMeshSectionByPlane::isActive() DEF_STD_CMD_A(CmdMeshCrossSections) CmdMeshCrossSections::CmdMeshCrossSections() - : Command("Mesh_CrossSections") + : Command("Mesh_CrossSections") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Cross-sections..."); - sToolTipText = QT_TR_NOOP("Cross-sections"); - sStatusTip = QT_TR_NOOP("Cross-sections"); - sPixmap = "Mesh_CrossSections"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Cross-sections..."); + sToolTipText = QT_TR_NOOP("Cross-sections"); + sStatusTip = QT_TR_NOOP("Cross-sections"); + sPixmap = "Mesh_CrossSections"; } void CmdMeshCrossSections::activated(int) { - doCommand(Doc,"import MeshPartGui, FreeCADGui\nFreeCADGui.runCommand('MeshPart_CrossSections')\n"); + doCommand(Doc, + "import MeshPartGui, FreeCADGui\nFreeCADGui.runCommand('MeshPart_CrossSections')\n"); } bool CmdMeshCrossSections::isActive() { - return (Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0 && - !Gui::Control().activeDialog()); + return (Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0 + && !Gui::Control().activeDialog()); } //-------------------------------------------------------------------------------------- @@ -903,20 +982,22 @@ bool CmdMeshCrossSections::isActive() DEF_STD_CMD_A(CmdMeshPolySplit) CmdMeshPolySplit::CmdMeshPolySplit() - : Command("Mesh_PolySplit") + : Command("Mesh_PolySplit") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Split mesh"); - sToolTipText = QT_TR_NOOP("Splits a mesh into two meshes"); - sWhatsThis = "Mesh_PolySplit"; - sStatusTip = QT_TR_NOOP("Splits a mesh into two meshes"); + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Split mesh"); + sToolTipText = QT_TR_NOOP("Splits a mesh into two meshes"); + sWhatsThis = "Mesh_PolySplit"; + sStatusTip = QT_TR_NOOP("Splits a mesh into two meshes"); } void CmdMeshPolySplit::activated(int) { - std::vector docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); - for (std::vector::iterator it = docObj.begin(); it != docObj.end(); ++it) { + std::vector docObj = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + for (std::vector::iterator it = docObj.begin(); it != docObj.end(); + ++it) { if (it == docObj.begin()) { Gui::Document* doc = getActiveGuiDocument(); Gui::MDIView* view = doc->getActiveView(); @@ -940,8 +1021,9 @@ void CmdMeshPolySplit::activated(int) bool CmdMeshPolySplit::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) + if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { return false; + } Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { @@ -957,16 +1039,16 @@ bool CmdMeshPolySplit::isActive() DEF_STD_CMD_A(CmdMeshEvaluation) CmdMeshEvaluation::CmdMeshEvaluation() - :Command("Mesh_Evaluation") + : Command("Mesh_Evaluation") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); // needs two ampersands to display one - sMenuText = QT_TR_NOOP("Evaluate and repair mesh..."); - sToolTipText = QT_TR_NOOP("Opens a dialog to analyze and repair a mesh"); - sWhatsThis = "Mesh_Evaluation"; - sStatusTip = QT_TR_NOOP("Opens a dialog to analyze and repair a mesh"); - sPixmap = "Mesh_Evaluation"; + sMenuText = QT_TR_NOOP("Evaluate and repair mesh..."); + sToolTipText = QT_TR_NOOP("Opens a dialog to analyze and repair a mesh"); + sWhatsThis = "Mesh_Evaluation"; + sStatusTip = QT_TR_NOOP("Opens a dialog to analyze and repair a mesh"); + sPixmap = "Mesh_Evaluation"; } void CmdMeshEvaluation::activated(int) @@ -978,7 +1060,8 @@ void CmdMeshEvaluation::activated(int) MeshGui::DlgEvaluateMeshImp* dlg = MeshGui::DockEvaluateMeshImp::instance(); dlg->setAttribute(Qt::WA_DeleteOnClose); - std::vector meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector meshes = + getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); for (auto it : meshes) { dlg->setMesh((Mesh::Feature*)(it)); break; @@ -990,8 +1073,9 @@ void CmdMeshEvaluation::activated(int) bool CmdMeshEvaluation::isActive() { App::Document* doc = App::GetApplication().getActiveDocument(); - if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) + if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { return false; + } return true; } @@ -1000,15 +1084,15 @@ bool CmdMeshEvaluation::isActive() DEF_STD_CMD_A(CmdMeshEvaluateFacet) CmdMeshEvaluateFacet::CmdMeshEvaluateFacet() - :Command("Mesh_EvaluateFacet") + : Command("Mesh_EvaluateFacet") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Face info"); - sToolTipText = QT_TR_NOOP("Information about face"); - sWhatsThis = "Mesh_EvaluateFacet"; - sStatusTip = QT_TR_NOOP("Information about face"); - sPixmap = "Mesh_EvaluateFacet"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Face info"); + sToolTipText = QT_TR_NOOP("Information about face"); + sWhatsThis = "Mesh_EvaluateFacet"; + sStatusTip = QT_TR_NOOP("Information about face"); + sPixmap = "Mesh_EvaluateFacet"; } void CmdMeshEvaluateFacet::activated(int) @@ -1018,16 +1102,19 @@ void CmdMeshEvaluateFacet::activated(int) if (view) { Gui::View3DInventorViewer* viewer = view->getViewer(); viewer->setEditing(true); - viewer->setEditingCursor(QCursor(Gui::BitmapFactory().pixmapFromSvg("Mesh_Pipette",QSize(32,32)),4,29)); - viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::faceInfoCallback); - } + viewer->setEditingCursor( + QCursor(Gui::BitmapFactory().pixmapFromSvg("Mesh_Pipette", QSize(32, 32)), 4, 29)); + viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), + MeshGui::ViewProviderMeshFaceSet::faceInfoCallback); + } } bool CmdMeshEvaluateFacet::isActive() { App::Document* doc = App::GetApplication().getActiveDocument(); - if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) + if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { return false; + } Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { @@ -1043,15 +1130,15 @@ bool CmdMeshEvaluateFacet::isActive() DEF_STD_CMD_A(CmdMeshRemoveComponents) CmdMeshRemoveComponents::CmdMeshRemoveComponents() - : Command("Mesh_RemoveComponents") + : Command("Mesh_RemoveComponents") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Remove components..."); - sToolTipText = QT_TR_NOOP("Remove topologic independent components from the mesh"); - sWhatsThis = "Mesh_RemoveComponents"; - sStatusTip = QT_TR_NOOP("Remove topologic independent components from the mesh"); - sPixmap = "Mesh_RemoveComponents"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Remove components..."); + sToolTipText = QT_TR_NOOP("Remove topologic independent components from the mesh"); + sWhatsThis = "Mesh_RemoveComponents"; + sStatusTip = QT_TR_NOOP("Remove topologic independent components from the mesh"); + sPixmap = "Mesh_RemoveComponents"; } void CmdMeshRemoveComponents::activated(int) @@ -1068,17 +1155,20 @@ bool CmdMeshRemoveComponents::isActive() { // Check for the selected mesh feature (all Mesh types) App::Document* doc = getDocument(); - if (!(doc && doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0)) + if (!(doc && doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0)) { return false; + } Gui::Document* viewDoc = Gui::Application::Instance->getDocument(doc); Gui::View3DInventor* view = dynamic_cast(viewDoc->getActiveView()); if (view) { Gui::View3DInventorViewer* viewer = view->getViewer(); - if (viewer->isEditing()) + if (viewer->isEditing()) { return false; + } } - if (Gui::Control().activeDialog()) + if (Gui::Control().activeDialog()) { return false; + } return true; } @@ -1088,15 +1178,15 @@ bool CmdMeshRemoveComponents::isActive() DEF_STD_CMD_A(CmdMeshRemeshGmsh) CmdMeshRemeshGmsh::CmdMeshRemeshGmsh() - : Command("Mesh_RemeshGmsh") + : Command("Mesh_RemeshGmsh") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Refinement..."); - sToolTipText = QT_TR_NOOP("Refine existing mesh"); - sStatusTip = QT_TR_NOOP("Refine existing mesh"); - sWhatsThis = "Mesh_RemeshGmsh"; - sPixmap = "Mesh_RemeshGmsh"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Refinement..."); + sToolTipText = QT_TR_NOOP("Refine existing mesh"); + sStatusTip = QT_TR_NOOP("Refine existing mesh"); + sWhatsThis = "Mesh_RemeshGmsh"; + sPixmap = "Mesh_RemeshGmsh"; } void CmdMeshRemeshGmsh::activated(int) @@ -1104,8 +1194,9 @@ void CmdMeshRemeshGmsh::activated(int) Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); if (!dlg) { std::vector mesh = getSelection().getObjectsOfType(); - if (mesh.size() != 1) + if (mesh.size() != 1) { return; + } dlg = new MeshGui::TaskRemeshGmsh(mesh.front()); } Gui::Control().showDialog(dlg); @@ -1121,15 +1212,15 @@ bool CmdMeshRemeshGmsh::isActive() DEF_STD_CMD_A(CmdMeshRemoveCompByHand) CmdMeshRemoveCompByHand::CmdMeshRemoveCompByHand() - :Command("Mesh_RemoveCompByHand") + : Command("Mesh_RemoveCompByHand") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Remove components by hand..."); - sToolTipText = QT_TR_NOOP("Mark a component to remove it from the mesh"); - sWhatsThis = "Mesh_RemoveCompByHand"; - sStatusTip = QT_TR_NOOP("Mark a component to remove it from the mesh"); - sPixmap = "Mesh_RemoveCompByHand"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Remove components by hand..."); + sToolTipText = QT_TR_NOOP("Mark a component to remove it from the mesh"); + sWhatsThis = "Mesh_RemoveCompByHand"; + sStatusTip = QT_TR_NOOP("Mark a component to remove it from the mesh"); + sPixmap = "Mesh_RemoveCompByHand"; } void CmdMeshRemoveCompByHand::activated(int) @@ -1140,7 +1231,8 @@ void CmdMeshRemoveCompByHand::activated(int) Gui::View3DInventorViewer* viewer = view->getViewer(); viewer->setEditing(true); viewer->setEditingCursor(QCursor(Qt::OpenHandCursor)); - viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::markPartCallback); + viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), + MeshGui::ViewProviderMeshFaceSet::markPartCallback); viewer->setSelectionEnabled(false); } } @@ -1148,10 +1240,12 @@ void CmdMeshRemoveCompByHand::activated(int) bool CmdMeshRemoveCompByHand::isActive() { App::Document* doc = App::GetApplication().getActiveDocument(); - if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) + if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { return false; + } - Gui::View3DInventor* view = dynamic_cast(Gui::getMainWindow()->activeWindow()); + Gui::View3DInventor* view = + dynamic_cast(Gui::getMainWindow()->activeWindow()); if (view) { Gui::View3DInventorViewer* viewer = view->getViewer(); return !viewer->isEditing(); @@ -1165,29 +1259,32 @@ bool CmdMeshRemoveCompByHand::isActive() DEF_STD_CMD_A(CmdMeshEvaluateSolid) CmdMeshEvaluateSolid::CmdMeshEvaluateSolid() - :Command("Mesh_EvaluateSolid") + : Command("Mesh_EvaluateSolid") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Check solid mesh"); - sToolTipText = QT_TR_NOOP("Checks whether the mesh is a solid"); - sWhatsThis = "Mesh_EvaluateSolid"; - sStatusTip = QT_TR_NOOP("Checks whether the mesh is a solid"); - sPixmap = "Mesh_EvaluateSolid"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Check solid mesh"); + sToolTipText = QT_TR_NOOP("Checks whether the mesh is a solid"); + sWhatsThis = "Mesh_EvaluateSolid"; + sStatusTip = QT_TR_NOOP("Checks whether the mesh is a solid"); + sPixmap = "Mesh_EvaluateSolid"; } void CmdMeshEvaluateSolid::activated(int) { - std::vector meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector meshes = + getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); for (auto it : meshes) { Mesh::Feature* mesh = (Mesh::Feature*)(it); QString msg; - if (mesh->Mesh.getValue().getKernel().HasOpenEdges()) + if (mesh->Mesh.getValue().getKernel().HasOpenEdges()) { msg = QObject::tr("The mesh '%1' is not a solid.") - .arg(QString::fromLatin1(mesh->Label.getValue())); - else + .arg(QString::fromLatin1(mesh->Label.getValue())); + } + else { msg = QObject::tr("The mesh '%1' is a solid.") - .arg(QString::fromLatin1(mesh->Label.getValue())); + .arg(QString::fromLatin1(mesh->Label.getValue())); + } QMessageBox::information(Gui::getMainWindow(), QObject::tr("Solid Mesh"), msg); } } @@ -1203,15 +1300,15 @@ bool CmdMeshEvaluateSolid::isActive() DEF_STD_CMD_A(CmdMeshSmoothing) CmdMeshSmoothing::CmdMeshSmoothing() - :Command("Mesh_Smoothing") + : Command("Mesh_Smoothing") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Smooth..."); - sToolTipText = QT_TR_NOOP("Smooth the selected meshes"); - sWhatsThis = "Mesh_Smoothing"; - sStatusTip = QT_TR_NOOP("Smooth the selected meshes"); - sPixmap = "Mesh_Smoothing"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Smooth..."); + sToolTipText = QT_TR_NOOP("Smooth the selected meshes"); + sWhatsThis = "Mesh_Smoothing"; + sStatusTip = QT_TR_NOOP("Smooth the selected meshes"); + sPixmap = "Mesh_Smoothing"; } void CmdMeshSmoothing::activated(int) @@ -1221,8 +1318,9 @@ void CmdMeshSmoothing::activated(int) bool CmdMeshSmoothing::isActive() { - if (Gui::Control().activeDialog()) + if (Gui::Control().activeDialog()) { return false; + } return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0; } @@ -1231,15 +1329,15 @@ bool CmdMeshSmoothing::isActive() DEF_STD_CMD_A(CmdMeshDecimating) CmdMeshDecimating::CmdMeshDecimating() - :Command("Mesh_Decimating") + : Command("Mesh_Decimating") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Decimation..."); - sToolTipText = QT_TR_NOOP("Decimates a mesh"); - sWhatsThis = QT_TR_NOOP("Decimates a mesh"); - sStatusTip = QT_TR_NOOP("Decimates a mesh"); - sPixmap = "Mesh_Decimating"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Decimation..."); + sToolTipText = QT_TR_NOOP("Decimates a mesh"); + sWhatsThis = QT_TR_NOOP("Decimates a mesh"); + sStatusTip = QT_TR_NOOP("Decimates a mesh"); + sPixmap = "Mesh_Decimating"; } void CmdMeshDecimating::activated(int) @@ -1250,8 +1348,9 @@ void CmdMeshDecimating::activated(int) bool CmdMeshDecimating::isActive() { #if 1 - if (Gui::Control().activeDialog()) + if (Gui::Control().activeDialog()) { return false; + } #endif // Check for the selected mesh feature (all Mesh types) return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0; @@ -1262,24 +1361,26 @@ bool CmdMeshDecimating::isActive() DEF_STD_CMD_A(CmdMeshHarmonizeNormals) CmdMeshHarmonizeNormals::CmdMeshHarmonizeNormals() - :Command("Mesh_HarmonizeNormals") + : Command("Mesh_HarmonizeNormals") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Harmonize normals"); - sToolTipText = QT_TR_NOOP("Harmonizes the normals of the mesh"); - sWhatsThis = "Mesh_HarmonizeNormals"; - sStatusTip = QT_TR_NOOP("Harmonizes the normals of the mesh"); - sPixmap = "Mesh_HarmonizeNormals"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Harmonize normals"); + sToolTipText = QT_TR_NOOP("Harmonizes the normals of the mesh"); + sWhatsThis = "Mesh_HarmonizeNormals"; + sStatusTip = QT_TR_NOOP("Harmonizes the normals of the mesh"); + sPixmap = "Mesh_HarmonizeNormals"; } void CmdMeshHarmonizeNormals::activated(int) { - std::vector meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector meshes = + getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); openCommand(QT_TRANSLATE_NOOP("Command", "Harmonize mesh normals")); for (auto it : meshes) { - doCommand(Doc,"App.activeDocument().getObject(\"%s\").Mesh.harmonizeNormals()" - ,it->getNameInDocument()); + doCommand(Doc, + "App.activeDocument().getObject(\"%s\").Mesh.harmonizeNormals()", + it->getNameInDocument()); } commitCommand(); updateActive(); @@ -1296,24 +1397,26 @@ bool CmdMeshHarmonizeNormals::isActive() DEF_STD_CMD_A(CmdMeshFlipNormals) CmdMeshFlipNormals::CmdMeshFlipNormals() - :Command("Mesh_FlipNormals") + : Command("Mesh_FlipNormals") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Flip normals"); - sToolTipText = QT_TR_NOOP("Flips the normals of the mesh"); - sWhatsThis = "Mesh_FlipNormals"; - sStatusTip = QT_TR_NOOP("Flips the normals of the mesh"); - sPixmap = "Mesh_FlipNormals"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Flip normals"); + sToolTipText = QT_TR_NOOP("Flips the normals of the mesh"); + sWhatsThis = "Mesh_FlipNormals"; + sStatusTip = QT_TR_NOOP("Flips the normals of the mesh"); + sPixmap = "Mesh_FlipNormals"; } void CmdMeshFlipNormals::activated(int) { - std::vector meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector meshes = + getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); openCommand(QT_TRANSLATE_NOOP("Command", "Flip mesh normals")); for (auto it : meshes) { - doCommand(Doc,"App.activeDocument().getObject(\"%s\").Mesh.flipNormals()" - ,it->getNameInDocument()); + doCommand(Doc, + "App.activeDocument().getObject(\"%s\").Mesh.flipNormals()", + it->getNameInDocument()); } commitCommand(); updateActive(); @@ -1330,32 +1433,42 @@ bool CmdMeshFlipNormals::isActive() DEF_STD_CMD_A(CmdMeshBoundingBox) CmdMeshBoundingBox::CmdMeshBoundingBox() - :Command("Mesh_BoundingBox") + : Command("Mesh_BoundingBox") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Boundings info..."); - sToolTipText = QT_TR_NOOP("Shows the boundings of the selected mesh"); - sWhatsThis = "Mesh_BoundingBox"; - sStatusTip = QT_TR_NOOP("Shows the boundings of the selected mesh"); - sPixmap = "Mesh_BoundingBox"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Boundings info..."); + sToolTipText = QT_TR_NOOP("Shows the boundings of the selected mesh"); + sWhatsThis = "Mesh_BoundingBox"; + sStatusTip = QT_TR_NOOP("Shows the boundings of the selected mesh"); + sPixmap = "Mesh_BoundingBox"; } void CmdMeshBoundingBox::activated(int) { - std::vector meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector meshes = + getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); for (auto it : meshes) { const MeshCore::MeshKernel& rMesh = ((Mesh::Feature*)it)->Mesh.getValue().getKernel(); const Base::BoundBox3f& box = rMesh.GetBoundBox(); Base::Console().Message("Boundings: Min=<%f,%f,%f>, Max=<%f,%f,%f>\n", - box.MinX,box.MinY,box.MinZ,box.MaxX,box.MaxY,box.MaxZ); + box.MinX, + box.MinY, + box.MinZ, + box.MaxX, + box.MaxY, + box.MaxZ); QString bound = qApp->translate("Mesh_BoundingBox", "Boundings of %1:") - .arg(QString::fromUtf8(it->Label.getValue())); + .arg(QString::fromUtf8(it->Label.getValue())); bound += QString::fromLatin1("\n\nMin=<%1,%2,%3>\n\nMax=<%4,%5,%6>") - .arg(box.MinX).arg(box.MinY).arg(box.MinZ) - .arg(box.MaxX).arg(box.MaxY).arg(box.MaxZ); + .arg(box.MinX) + .arg(box.MinY) + .arg(box.MinZ) + .arg(box.MaxX) + .arg(box.MaxY) + .arg(box.MaxZ); QMessageBox::information(Gui::getMainWindow(), QObject::tr("Boundings"), bound); break; } @@ -1372,22 +1485,23 @@ bool CmdMeshBoundingBox::isActive() DEF_STD_CMD_A(CmdMeshBuildRegularSolid) CmdMeshBuildRegularSolid::CmdMeshBuildRegularSolid() - :Command("Mesh_BuildRegularSolid") + : Command("Mesh_BuildRegularSolid") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Regular solid..."); - sToolTipText = QT_TR_NOOP("Builds a regular solid"); - sWhatsThis = "Mesh_BuildRegularSolid"; - sStatusTip = QT_TR_NOOP("Builds a regular solid"); - sPixmap = "Mesh_BuildRegularSolid"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Regular solid..."); + sToolTipText = QT_TR_NOOP("Builds a regular solid"); + sWhatsThis = "Mesh_BuildRegularSolid"; + sStatusTip = QT_TR_NOOP("Builds a regular solid"); + sPixmap = "Mesh_BuildRegularSolid"; } void CmdMeshBuildRegularSolid::activated(int) { static QPointer dlg = nullptr; - if (!dlg) + if (!dlg) { dlg = new MeshGui::DlgRegularSolidImp(Gui::getMainWindow()); + } dlg->setAttribute(Qt::WA_DeleteOnClose); dlg->show(); } @@ -1403,29 +1517,41 @@ bool CmdMeshBuildRegularSolid::isActive() DEF_STD_CMD_A(CmdMeshFillupHoles) CmdMeshFillupHoles::CmdMeshFillupHoles() - :Command("Mesh_FillupHoles") + : Command("Mesh_FillupHoles") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Fill holes..."); - sToolTipText = QT_TR_NOOP("Fill holes of the mesh"); - sWhatsThis = "Mesh_FillupHoles"; - sStatusTip = QT_TR_NOOP("Fill holes of the mesh"); - sPixmap = "Mesh_FillupHoles"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Fill holes..."); + sToolTipText = QT_TR_NOOP("Fill holes of the mesh"); + sWhatsThis = "Mesh_FillupHoles"; + sStatusTip = QT_TR_NOOP("Fill holes of the mesh"); + sPixmap = "Mesh_FillupHoles"; } void CmdMeshFillupHoles::activated(int) { - std::vector meshes = getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector meshes = + getSelection().getObjectsOfType(Mesh::Feature::getClassTypeId()); bool ok; - int FillupHolesOfLength = QInputDialog::getInt(Gui::getMainWindow(), QObject::tr("Fill holes"), - QObject::tr("Fill holes with maximum number of edges:"), 3, 3, 10000, 1, &ok, Qt::MSWindowsFixedSizeDialogHint); - if (!ok) + int FillupHolesOfLength = + QInputDialog::getInt(Gui::getMainWindow(), + QObject::tr("Fill holes"), + QObject::tr("Fill holes with maximum number of edges:"), + 3, + 3, + 10000, + 1, + &ok, + Qt::MSWindowsFixedSizeDialogHint); + if (!ok) { return; + } openCommand(QT_TRANSLATE_NOOP("Command", "Fill up holes")); for (auto mesh : meshes) { - doCommand(Doc,"App.activeDocument().getObject(\"%s\").Mesh.fillupHoles(%d)" - ,mesh->getNameInDocument(), FillupHolesOfLength); + doCommand(Doc, + "App.activeDocument().getObject(\"%s\").Mesh.fillupHoles(%d)", + mesh->getNameInDocument(), + FillupHolesOfLength); } commitCommand(); updateActive(); @@ -1442,15 +1568,15 @@ bool CmdMeshFillupHoles::isActive() DEF_STD_CMD_A(CmdMeshFillInteractiveHole) CmdMeshFillInteractiveHole::CmdMeshFillInteractiveHole() - :Command("Mesh_FillInteractiveHole") + : Command("Mesh_FillInteractiveHole") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Close hole"); - sToolTipText = QT_TR_NOOP("Close holes interactively"); - sWhatsThis = "Mesh_FillInteractiveHole"; - sStatusTip = QT_TR_NOOP("Close holes interactively"); - sPixmap = "Mesh_FillInteractiveHole"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Close hole"); + sToolTipText = QT_TR_NOOP("Close holes interactively"); + sWhatsThis = "Mesh_FillInteractiveHole"; + sStatusTip = QT_TR_NOOP("Close holes interactively"); + sPixmap = "Mesh_FillInteractiveHole"; } void CmdMeshFillInteractiveHole::activated(int) @@ -1460,17 +1586,19 @@ void CmdMeshFillInteractiveHole::activated(int) if (view) { Gui::View3DInventorViewer* viewer = view->getViewer(); viewer->setEditing(true); - viewer->setEditingCursor(QCursor(Gui::BitmapFactory().pixmap("mesh_fillhole"),5,5)); - viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::fillHoleCallback); + viewer->setEditingCursor(QCursor(Gui::BitmapFactory().pixmap("mesh_fillhole"), 5, 5)); + viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), + MeshGui::ViewProviderMeshFaceSet::fillHoleCallback); viewer->setSelectionEnabled(false); - } + } } bool CmdMeshFillInteractiveHole::isActive() { App::Document* doc = App::GetApplication().getActiveDocument(); - if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) + if (!doc || doc->countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { return false; + } Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { @@ -1484,21 +1612,21 @@ bool CmdMeshFillInteractiveHole::isActive() DEF_STD_CMD_A(CmdMeshSegmentation) CmdMeshSegmentation::CmdMeshSegmentation() - : Command("Mesh_Segmentation") + : Command("Mesh_Segmentation") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Create mesh segments..."); - sToolTipText = QT_TR_NOOP("Create mesh segments"); - sWhatsThis = "Mesh_Segmentation"; - sStatusTip = QT_TR_NOOP("Create mesh segments"); - sPixmap = "Mesh_Segmentation"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Create mesh segments..."); + sToolTipText = QT_TR_NOOP("Create mesh segments"); + sWhatsThis = "Mesh_Segmentation"; + sStatusTip = QT_TR_NOOP("Create mesh segments"); + sPixmap = "Mesh_Segmentation"; } void CmdMeshSegmentation::activated(int) { - std::vector objs = Gui::Selection().getObjectsOfType - (Mesh::Feature::getClassTypeId()); + std::vector objs = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); Mesh::Feature* mesh = static_cast(objs.front()); Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); if (!dlg) { @@ -1509,10 +1637,10 @@ void CmdMeshSegmentation::activated(int) bool CmdMeshSegmentation::isActive() { - if (Gui::Control().activeDialog()) + if (Gui::Control().activeDialog()) { return false; - return Gui::Selection().countObjectsOfType - (Mesh::Feature::getClassTypeId()) == 1; + } + return Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1; } //-------------------------------------------------------------------------------------- @@ -1520,21 +1648,21 @@ bool CmdMeshSegmentation::isActive() DEF_STD_CMD_A(CmdMeshSegmentationBestFit) CmdMeshSegmentationBestFit::CmdMeshSegmentationBestFit() - : Command("Mesh_SegmentationBestFit") + : Command("Mesh_SegmentationBestFit") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Create mesh segments from best-fit surfaces..."); - sToolTipText = QT_TR_NOOP("Create mesh segments from best-fit surfaces"); - sWhatsThis = "Mesh_SegmentationBestFit"; - sStatusTip = QT_TR_NOOP("Create mesh segments from best-fit surfaces"); - sPixmap = "Mesh_SegmentationBestFit"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Create mesh segments from best-fit surfaces..."); + sToolTipText = QT_TR_NOOP("Create mesh segments from best-fit surfaces"); + sWhatsThis = "Mesh_SegmentationBestFit"; + sStatusTip = QT_TR_NOOP("Create mesh segments from best-fit surfaces"); + sPixmap = "Mesh_SegmentationBestFit"; } void CmdMeshSegmentationBestFit::activated(int) { - std::vector objs = Gui::Selection().getObjectsOfType - (Mesh::Feature::getClassTypeId()); + std::vector objs = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); Mesh::Feature* mesh = static_cast(objs.front()); Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); if (!dlg) { @@ -1545,10 +1673,10 @@ void CmdMeshSegmentationBestFit::activated(int) bool CmdMeshSegmentationBestFit::isActive() { - if (Gui::Control().activeDialog()) + if (Gui::Control().activeDialog()) { return false; - return Gui::Selection().countObjectsOfType - (Mesh::Feature::getClassTypeId()) == 1; + } + return Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1; } //-------------------------------------------------------------------------------------- @@ -1556,27 +1684,30 @@ bool CmdMeshSegmentationBestFit::isActive() DEF_STD_CMD_A(CmdMeshMerge) CmdMeshMerge::CmdMeshMerge() - :Command("Mesh_Merge") + : Command("Mesh_Merge") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Merge"); - sToolTipText = QT_TR_NOOP("Merges selected meshes into one"); - sWhatsThis = "Mesh_Merge"; - sStatusTip = sToolTipText; - sPixmap = "Mesh_Merge"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Merge"); + sToolTipText = QT_TR_NOOP("Merges selected meshes into one"); + sWhatsThis = "Mesh_Merge"; + sStatusTip = sToolTipText; + sPixmap = "Mesh_Merge"; } void CmdMeshMerge::activated(int) { - App::Document *pcDoc = App::GetApplication().getActiveDocument(); - if (!pcDoc) + App::Document* pcDoc = App::GetApplication().getActiveDocument(); + if (!pcDoc) { return; + } openCommand(QT_TRANSLATE_NOOP("Command", "Mesh merge")); - Mesh::Feature *pcFeature = static_cast(pcDoc->addObject("Mesh::Feature", "Mesh")); + Mesh::Feature* pcFeature = + static_cast(pcDoc->addObject("Mesh::Feature", "Mesh")); Mesh::MeshObject* newMesh = pcFeature->Mesh.startEditing(); - std::vector objs = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector objs = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); for (auto obj : objs) { const MeshObject& mesh = static_cast(obj)->Mesh.getValue(); MeshCore::MeshKernel kernel = mesh.getKernel(); @@ -1599,34 +1730,37 @@ bool CmdMeshMerge::isActive() DEF_STD_CMD_A(CmdMeshSplitComponents) CmdMeshSplitComponents::CmdMeshSplitComponents() - : Command("Mesh_SplitComponents") + : Command("Mesh_SplitComponents") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Split by components"); - sToolTipText = QT_TR_NOOP("Split selected mesh into its components"); - sWhatsThis = "Mesh_SplitComponents"; - sStatusTip = sToolTipText; - sPixmap = "Mesh_SplitComponents"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Split by components"); + sToolTipText = QT_TR_NOOP("Split selected mesh into its components"); + sWhatsThis = "Mesh_SplitComponents"; + sStatusTip = sToolTipText; + sPixmap = "Mesh_SplitComponents"; } void CmdMeshSplitComponents::activated(int) { - App::Document *pcDoc = App::GetApplication().getActiveDocument(); - if (!pcDoc) + App::Document* pcDoc = App::GetApplication().getActiveDocument(); + if (!pcDoc) { return; + } openCommand(QT_TRANSLATE_NOOP("Command", "Mesh split")); - std::vector objs = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector objs = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); for (auto obj : objs) { const MeshObject& mesh = static_cast(obj)->Mesh.getValue(); - std::vector > comps = mesh.getComponents(); + std::vector> comps = mesh.getComponents(); for (const auto& comp : comps) { std::unique_ptr kernel(mesh.meshFromSegment(comp)); kernel->setTransform(mesh.getTransform()); - Mesh::Feature* feature = static_cast(pcDoc->addObject("Mesh::Feature", "Component")); + Mesh::Feature* feature = + static_cast(pcDoc->addObject("Mesh::Feature", "Component")); feature->Mesh.setValuePtr(kernel.release()); } } @@ -1645,33 +1779,43 @@ bool CmdMeshSplitComponents::isActive() DEF_STD_CMD_A(CmdMeshScale) CmdMeshScale::CmdMeshScale() - : Command("Mesh_Scale") + : Command("Mesh_Scale") { - sAppModule = "Mesh"; - sGroup = QT_TR_NOOP("Mesh"); - sMenuText = QT_TR_NOOP("Scale..."); - sToolTipText = QT_TR_NOOP("Scale selected meshes"); - sWhatsThis = "Mesh_Scale"; - sStatusTip = sToolTipText; - sPixmap = "Mesh_Scale"; + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Scale..."); + sToolTipText = QT_TR_NOOP("Scale selected meshes"); + sWhatsThis = "Mesh_Scale"; + sStatusTip = sToolTipText; + sPixmap = "Mesh_Scale"; } void CmdMeshScale::activated(int) { - App::Document *pcDoc = App::GetApplication().getActiveDocument(); - if (!pcDoc) + App::Document* pcDoc = App::GetApplication().getActiveDocument(); + if (!pcDoc) { return; + } bool ok; - double factor = QInputDialog::getDouble(Gui::getMainWindow(), QObject::tr("Scaling"), - QObject::tr("Enter scaling factor:"), 1, 0, DBL_MAX, 5, &ok, Qt::MSWindowsFixedSizeDialogHint); - if (!ok || factor == 0) + double factor = QInputDialog::getDouble(Gui::getMainWindow(), + QObject::tr("Scaling"), + QObject::tr("Enter scaling factor:"), + 1, + 0, + DBL_MAX, + 5, + &ok, + Qt::MSWindowsFixedSizeDialogHint); + if (!ok || factor == 0) { return; + } openCommand(QT_TRANSLATE_NOOP("Command", "Mesh scale")); - std::vector objs = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector objs = + Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); Base::Matrix4D mat; - mat.scale(factor,factor,factor); + mat.scale(factor, factor, factor); for (auto obj : objs) { MeshObject* mesh = static_cast(obj)->Mesh.startEditing(); MeshCore::MeshKernel& kernel = mesh->getKernel(); @@ -1691,7 +1835,7 @@ bool CmdMeshScale::isActive() void CreateMeshCommands() { - Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); rcCmdMgr.addCommand(new CmdMeshImport()); rcCmdMgr.addCommand(new CmdMeshExport()); rcCmdMgr.addCommand(new CmdMeshVertexCurvature()); diff --git a/src/Mod/Mesh/Gui/DlgDecimating.cpp b/src/Mod/Mesh/Gui/DlgDecimating.cpp index 647c71ab94..f5a5020df7 100644 --- a/src/Mod/Mesh/Gui/DlgDecimating.cpp +++ b/src/Mod/Mesh/Gui/DlgDecimating.cpp @@ -41,8 +41,10 @@ DlgDecimating::DlgDecimating(QWidget* parent, Qt::WindowFlags fl) , ui(new Ui_DlgDecimating) { ui->setupUi(this); - connect(ui->checkAbsoluteNumber, &QCheckBox::toggled, - this, &DlgDecimating::onCheckAbsoluteNumberToggled); + connect(ui->checkAbsoluteNumber, + &QCheckBox::toggled, + this, + &DlgDecimating::onCheckAbsoluteNumberToggled); ui->spinBoxReduction->setMinimumWidth(60); ui->checkAbsoluteNumber->setEnabled(false); onCheckAbsoluteNumberToggled(false); @@ -80,20 +82,33 @@ void DlgDecimating::onCheckAbsoluteNumberToggled(bool on) ui->groupBoxTolerance->setDisabled(on); if (on) { - disconnect(ui->sliderReduction, qOverload(&QSlider::valueChanged), ui->spinBoxReduction, &QSpinBox::setValue); - disconnect(ui->spinBoxReduction, qOverload(&QSpinBox::valueChanged), ui->sliderReduction, &QSlider::setValue); + disconnect(ui->sliderReduction, + qOverload(&QSlider::valueChanged), + ui->spinBoxReduction, + &QSpinBox::setValue); + disconnect(ui->spinBoxReduction, + qOverload(&QSpinBox::valueChanged), + ui->sliderReduction, + &QSlider::setValue); ui->spinBoxReduction->setRange(1, numberOfTriangles); ui->spinBoxReduction->setValue(numberOfTriangles * (1.0 - reduction())); ui->spinBoxReduction->setSuffix(QString()); - ui->checkAbsoluteNumber->setText(tr("Absolute number (Maximum: %1)").arg(numberOfTriangles)); + ui->checkAbsoluteNumber->setText( + tr("Absolute number (Maximum: %1)").arg(numberOfTriangles)); } else { ui->spinBoxReduction->setRange(0, 100); ui->spinBoxReduction->setValue(ui->sliderReduction->value()); ui->spinBoxReduction->setSuffix(QString::fromLatin1("%")); ui->checkAbsoluteNumber->setText(tr("Absolute number")); - connect(ui->sliderReduction, qOverload(&QSlider::valueChanged), ui->spinBoxReduction, &QSpinBox::setValue); - connect(ui->spinBoxReduction, qOverload(&QSpinBox::valueChanged), ui->sliderReduction, &QSlider::setValue); + connect(ui->sliderReduction, + qOverload(&QSlider::valueChanged), + ui->spinBoxReduction, + &QSpinBox::setValue); + connect(ui->spinBoxReduction, + qOverload(&QSpinBox::valueChanged), + ui->sliderReduction, + &QSlider::setValue); } } @@ -111,7 +126,7 @@ double DlgDecimating::reduction() const double max = static_cast(ui->sliderReduction->maximum()); double min = static_cast(ui->sliderReduction->minimum()); double val = static_cast(ui->sliderReduction->value()); - return (val - min)/(max - min); + return (val - min) / (max - min); } // --------------------------------------- @@ -121,8 +136,8 @@ double DlgDecimating::reduction() const TaskDecimating::TaskDecimating() { widget = new DlgDecimating(); - Gui::TaskView::TaskBox* taskbox = new Gui::TaskView::TaskBox( - QPixmap(), widget->windowTitle(), false, nullptr); + Gui::TaskView::TaskBox* taskbox = + new Gui::TaskView::TaskBox(QPixmap(), widget->windowTitle(), false, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); diff --git a/src/Mod/Mesh/Gui/DlgDecimating.h b/src/Mod/Mesh/Gui/DlgDecimating.h index 59890b0ac2..94616ae5e6 100644 --- a/src/Mod/Mesh/Gui/DlgDecimating.h +++ b/src/Mod/Mesh/Gui/DlgDecimating.h @@ -24,14 +24,15 @@ #ifndef MESHGUI_DLGDECIMATING_H #define MESHGUI_DLGDECIMATING_H -#include #include #include +#include #include -namespace MeshGui { +namespace MeshGui +{ class Ui_DlgDecimating; -class DlgDecimating : public QWidget +class DlgDecimating: public QWidget { Q_OBJECT @@ -55,7 +56,7 @@ private: /** * Embed the panel into a task dialog. */ -class TaskDecimating : public Gui::TaskView::TaskDialog +class TaskDecimating: public Gui::TaskView::TaskDialog { Q_OBJECT @@ -66,14 +67,18 @@ public: bool accept() override; QDialogButtonBox::StandardButtons getStandardButtons() const override - { return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; } + { + return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; + } bool isAllowedAlterDocument() const override - { return true; } + { + return true; + } private: DlgDecimating* widget; }; -} +} // namespace MeshGui -#endif // MESHGUI_DLGDECIMATING_H +#endif // MESHGUI_DLGDECIMATING_H diff --git a/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp b/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp index a99c344605..5439943b03 100644 --- a/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp +++ b/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp @@ -22,28 +22,28 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include +#include +#include +#include +#include #endif #include #include -#include #include +#include #include -#include #include #include -#include -#include +#include #include +#include +#include #include "DlgEvaluateMeshImp.h" -#include "ui_DlgEvaluateMesh.h" #include "DlgEvaluateSettings.h" #include "ViewProviderDefects.h" +#include "ui_DlgEvaluateMesh.h" using namespace MeshCore; @@ -51,7 +51,7 @@ using namespace Mesh; using namespace MeshGui; CleanupHandler::CleanupHandler() - : QObject(qApp) + : QObject(qApp) { // connect to lstWindowClosed signal connect(qApp, &QApplication::lastWindowClosed, this, &CleanupHandler::cleanup); @@ -69,9 +69,9 @@ void CleanupHandler::cleanup() class DlgEvaluateMeshImp::Private { public: - Private() : view(nullptr) - { - } + Private() + : view(nullptr) + {} void showFoldsFunction(bool on) { @@ -82,15 +82,15 @@ public: ui.repairFoldsButton->setVisible(on); } - Ui_DlgEvaluateMesh ui{}; + Ui_DlgEvaluateMesh ui {}; std::map vp; - Mesh::Feature* meshFeature{nullptr}; + Mesh::Feature* meshFeature {nullptr}; QPointer view; std::vector self_intersections; - bool enableFoldsCheck{false}; - bool checkNonManfoldPoints{false}; - bool strictlyDegenerated{true}; - float epsilonDegenerated{0.0f}; + bool enableFoldsCheck {false}; + bool checkNonManfoldPoints {false}; + bool strictlyDegenerated {true}; + float epsilonDegenerated {0.0f}; }; /* TRANSLATOR MeshGui::DlgEvaluateMeshImp */ @@ -100,7 +100,8 @@ public: * widget flags set to 'f'. */ DlgEvaluateMeshImp::DlgEvaluateMeshImp(QWidget* parent, Qt::WindowFlags fl) - : QDialog(parent, fl), d(new Private()) + : QDialog(parent, fl) + , d(new Private()) { d->ui.setupUi(this); setupConnections(); @@ -122,15 +123,17 @@ DlgEvaluateMeshImp::DlgEvaluateMeshImp(QWidget* parent, Qt::WindowFlags fl) d->ui.line_8->setFrameShape(QFrame::HLine); d->ui.line_8->setFrameShadow(QFrame::Sunken); - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Mod/Mesh/Evaluation"); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Mesh/Evaluation"); d->checkNonManfoldPoints = hGrp->GetBool("CheckNonManifoldPoints", false); d->enableFoldsCheck = hGrp->GetBool("EnableFoldsCheck", false); d->strictlyDegenerated = hGrp->GetBool("StrictlyDegenerated", true); - if (d->strictlyDegenerated) + if (d->strictlyDegenerated) { d->epsilonDegenerated = 0.0f; - else + } + else { d->epsilonDegenerated = MeshCore::MeshDefinitions::_fMinPointDistanceP2; + } d->showFoldsFunction(d->enableFoldsCheck); @@ -148,14 +151,15 @@ DlgEvaluateMeshImp::~DlgEvaluateMeshImp() { // no need to delete child widgets, Qt does it all for us for (const auto& it : d->vp) { - if (d->view) + if (d->view) { d->view->getViewer()->removeViewProvider(it.second); + } delete it.second; } try { - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Mod/Mesh/Evaluation"); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Mesh/Evaluation"); hGrp->SetBool("CheckNonManifoldPoints", d->checkNonManfoldPoints); hGrp->SetBool("EnableFoldsCheck", d->enableFoldsCheck); hGrp->SetBool("StrictlyDegenerated", d->strictlyDegenerated); @@ -169,6 +173,7 @@ DlgEvaluateMeshImp::~DlgEvaluateMeshImp() void DlgEvaluateMeshImp::setupConnections() { + // clang-format off connect(d->ui.checkOrientationButton, &QCheckBox::clicked, this, &DlgEvaluateMeshImp::onCheckOrientationButtonClicked); connect(d->ui.analyzeOrientationButton, &QPushButton::clicked, @@ -238,9 +243,10 @@ void DlgEvaluateMeshImp::setupConnections() this, &DlgEvaluateMeshImp::onButtonBoxClicked); connect(d->ui.buttonBox, &QDialogButtonBox::helpRequested, Gui::getMainWindow(), &Gui::MainWindow::whatsThis); + // clang-format on } -void DlgEvaluateMeshImp::changeEvent(QEvent *e) +void DlgEvaluateMeshImp::changeEvent(QEvent* e) { if (e->type() == QEvent::LanguageChange) { d->ui.retranslateUi(this); @@ -280,7 +286,8 @@ void DlgEvaluateMeshImp::slotDeletedObject(const App::DocumentObject& Obj) } } -void DlgEvaluateMeshImp::slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) +void DlgEvaluateMeshImp::slotChangedObject(const App::DocumentObject& Obj, + const App::Property& Prop) { // if the current mesh object was modified update everything if (&Obj == d->meshFeature && Prop.getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) { @@ -291,12 +298,12 @@ void DlgEvaluateMeshImp::slotChangedObject(const App::DocumentObject& Obj, const } else if (Obj.getTypeId().isDerivedFrom(Mesh::Feature::getClassTypeId())) { // if the label has changed update the entry in the list - if (Prop.getTypeId() == App::PropertyString::getClassTypeId() && - strcmp(Prop.getName(), "Label") == 0) { - QString label = QString::fromUtf8(Obj.Label.getValue()); - QString name = QString::fromLatin1(Obj.getNameInDocument()); - int index = d->ui.meshNameButton->findData(name); - d->ui.meshNameButton->setItemText(index, label); + if (Prop.getTypeId() == App::PropertyString::getClassTypeId() + && strcmp(Prop.getName(), "Label") == 0) { + QString label = QString::fromUtf8(Obj.Label.getValue()); + QString name = QString::fromLatin1(Obj.getNameInDocument()); + int index = d->ui.meshNameButton->findData(name); + d->ui.meshNameButton->setItemText(index, label); } } } @@ -321,14 +328,15 @@ void DlgEvaluateMeshImp::slotDeletedDocument(const App::Document& Doc) void DlgEvaluateMeshImp::setMesh(Mesh::Feature* m) { App::Document* doc = m->getDocument(); - if (doc != getDocument()) + if (doc != getDocument()) { attachDocument(doc); + } refreshList(); int ct = d->ui.meshNameButton->count(); QString objName = QString::fromLatin1(m->getNameInDocument()); - for (int i=1; iui.meshNameButton->itemData(i).toString() == objName) { d->ui.meshNameButton->setCurrentIndex(i); onMeshNameButtonActivated(i); @@ -337,15 +345,17 @@ void DlgEvaluateMeshImp::setMesh(Mesh::Feature* m) } } -void DlgEvaluateMeshImp::addViewProvider(const char* name, const std::vector& indices) +void DlgEvaluateMeshImp::addViewProvider(const char* name, + const std::vector& indices) { removeViewProvider(name); if (d->view) { - ViewProviderMeshDefects* vp = static_cast(Base::Type::createInstanceByName(name)); + ViewProviderMeshDefects* vp = + static_cast(Base::Type::createInstanceByName(name)); assert(vp->getTypeId().isDerivedFrom(Gui::ViewProvider::getClassTypeId())); vp->attach(d->meshFeature); - d->view->getViewer()->addViewProvider( vp ); + d->view->getViewer()->addViewProvider(vp); vp->showDefects(indices); d->vp[name] = vp; } @@ -355,8 +365,9 @@ void DlgEvaluateMeshImp::removeViewProvider(const char* name) { std::map::iterator it = d->vp.find(name); if (it != d->vp.end()) { - if (d->view) + if (d->view) { d->view->getViewer()->removeViewProvider(it->second); + } delete it->second; d->vp.erase(it); } @@ -365,8 +376,9 @@ void DlgEvaluateMeshImp::removeViewProvider(const char* name) void DlgEvaluateMeshImp::removeViewProviders() { for (const auto& it : d->vp) { - if (d->view) + if (d->view) { d->view->getViewer()->removeViewProvider(it.second); + } delete it.second; } d->vp.clear(); @@ -377,7 +389,8 @@ void DlgEvaluateMeshImp::onMeshNameButtonActivated(int i) QString item = d->ui.meshNameButton->itemData(i).toString(); d->meshFeature = nullptr; - std::vector objs = getDocument()->getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector objs = + getDocument()->getObjectsOfType(Mesh::Feature::getClassTypeId()); for (auto obj : objs) { if (item == QLatin1String(obj->getNameInDocument())) { d->meshFeature = static_cast(obj); @@ -385,7 +398,7 @@ void DlgEvaluateMeshImp::onMeshNameButtonActivated(int i) } } - if (i== 0) { + if (i == 0) { cleanInformation(); } else { @@ -395,9 +408,10 @@ void DlgEvaluateMeshImp::onMeshNameButtonActivated(int i) void DlgEvaluateMeshImp::refreshList() { - QVector > items; + QVector> items; if (this->getDocument()) { - std::vector objs = this->getDocument()->getObjectsOfType(Mesh::Feature::getClassTypeId()); + std::vector objs = + this->getDocument()->getObjectsOfType(Mesh::Feature::getClassTypeId()); for (auto obj : objs) { items.push_back(qMakePair(QString::fromUtf8(obj->Label.getValue()), QString::fromLatin1(obj->getNameInDocument()))); @@ -406,8 +420,9 @@ void DlgEvaluateMeshImp::refreshList() d->ui.meshNameButton->clear(); d->ui.meshNameButton->addItem(tr("No selection")); - for (const auto & item : items) + for (const auto& item : items) { d->ui.meshNameButton->addItem(item.first, item.second); + } d->ui.meshNameButton->setDisabled(items.empty()); cleanInformation(); } @@ -434,17 +449,17 @@ void DlgEvaluateMeshImp::showInformation() void DlgEvaluateMeshImp::cleanInformation() { - d->ui.textLabel4->setText( tr("No information") ); - d->ui.textLabel5->setText( tr("No information") ); - d->ui.textLabel6->setText( tr("No information") ); - d->ui.checkOrientationButton->setText( tr("No information") ); - d->ui.checkDuplicatedFacesButton->setText( tr("No information") ); - d->ui.checkDuplicatedPointsButton->setText( tr("No information") ); - d->ui.checkNonmanifoldsButton->setText( tr("No information") ); - d->ui.checkDegenerationButton->setText( tr("No information") ); - d->ui.checkIndicesButton->setText( tr("No information") ); - d->ui.checkSelfIntersectionButton->setText( tr("No information") ); - d->ui.checkFoldsButton->setText( tr("No information") ); + d->ui.textLabel4->setText(tr("No information")); + d->ui.textLabel5->setText(tr("No information")); + d->ui.textLabel6->setText(tr("No information")); + d->ui.checkOrientationButton->setText(tr("No information")); + d->ui.checkDuplicatedFacesButton->setText(tr("No information")); + d->ui.checkDuplicatedPointsButton->setText(tr("No information")); + d->ui.checkNonmanifoldsButton->setText(tr("No information")); + d->ui.checkDegenerationButton->setText(tr("No information")); + d->ui.checkIndicesButton->setText(tr("No information")); + d->ui.checkSelfIntersectionButton->setText(tr("No information")); + d->ui.checkFoldsButton->setText(tr("No information")); d->ui.analyzeOrientationButton->setDisabled(true); d->ui.repairOrientationButton->setDisabled(true); d->ui.analyzeDuplicatedFacesButton->setDisabled(true); @@ -485,12 +500,15 @@ void DlgEvaluateMeshImp::onRefreshButtonClicked() void DlgEvaluateMeshImp::onCheckOrientationButtonClicked() { - std::map::iterator it = d->vp.find("MeshGui::ViewProviderMeshOrientation"); + std::map::iterator it = + d->vp.find("MeshGui::ViewProviderMeshOrientation"); if (it != d->vp.end()) { - if (d->ui.checkOrientationButton->isChecked()) + if (d->ui.checkOrientationButton->isChecked()) { it->second->show(); - else + } + else { it->second->hide(); + } } } @@ -506,17 +524,17 @@ void DlgEvaluateMeshImp::onAnalyzeOrientationButtonClicked() std::vector inds = eval.GetIndices(); if (inds.empty()) { - d->ui.checkOrientationButton->setText( tr("No flipped normals") ); + d->ui.checkOrientationButton->setText(tr("No flipped normals")); d->ui.checkOrientationButton->setChecked(false); d->ui.repairOrientationButton->setEnabled(false); - removeViewProvider( "MeshGui::ViewProviderMeshOrientation" ); + removeViewProvider("MeshGui::ViewProviderMeshOrientation"); } else { - d->ui.checkOrientationButton->setText( tr("%1 flipped normals").arg(inds.size()) ); + d->ui.checkOrientationButton->setText(tr("%1 flipped normals").arg(inds.size())); d->ui.checkOrientationButton->setChecked(true); d->ui.repairOrientationButton->setEnabled(true); d->ui.repairAllTogether->setEnabled(true); - addViewProvider( "MeshGui::ViewProviderMeshOrientation", eval.GetIndices()); + addViewProvider("MeshGui::ViewProviderMeshOrientation", eval.GetIndices()); } qApp->restoreOverrideCursor(); @@ -532,9 +550,10 @@ void DlgEvaluateMeshImp::onRepairOrientationButtonClicked() Gui::Document* doc = Gui::Application::Instance->getDocument(docName); doc->openCommand(QT_TRANSLATE_NOOP("Command", "Harmonize normals")); try { - Gui::Command::doCommand(Gui::Command::App - , "App.getDocument(\"%s\").getObject(\"%s\").harmonizeNormals()" - , docName, objName); + Gui::Command::doCommand(Gui::Command::App, + "App.getDocument(\"%s\").getObject(\"%s\").harmonizeNormals()", + docName, + objName); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Orientation"), QString::fromLatin1(e.what())); @@ -545,7 +564,7 @@ void DlgEvaluateMeshImp::onRepairOrientationButtonClicked() d->ui.repairOrientationButton->setEnabled(false); d->ui.checkOrientationButton->setChecked(false); - removeViewProvider( "MeshGui::ViewProviderMeshOrientation" ); + removeViewProvider("MeshGui::ViewProviderMeshOrientation"); } } @@ -555,19 +574,23 @@ void DlgEvaluateMeshImp::onCheckNonmanifoldsButtonClicked() std::map::iterator it; it = d->vp.find("MeshGui::ViewProviderMeshNonManifolds"); if (it != d->vp.end()) { - if (d->ui.checkNonmanifoldsButton->isChecked()) + if (d->ui.checkNonmanifoldsButton->isChecked()) { it->second->show(); - else + } + else { it->second->hide(); + } } // non-manifold points it = d->vp.find("MeshGui::ViewProviderMeshNonManifoldPoints"); if (it != d->vp.end()) { - if (d->ui.checkNonmanifoldsButton->isChecked()) + if (d->ui.checkNonmanifoldsButton->isChecked()) { it->second->show(); - else + } + else { it->second->hide(); + } } } @@ -587,8 +610,9 @@ void DlgEvaluateMeshImp::onAnalyzeNonmanifoldsButtonClicked() if (d->checkNonManfoldPoints) { MeshEvalPointManifolds p_eval(rMesh); ok2 = p_eval.Evaluate(); - if (!ok2) + if (!ok2) { point_indices = p_eval.GetIndices(); + } } if (ok1 && ok2) { @@ -599,16 +623,18 @@ void DlgEvaluateMeshImp::onAnalyzeNonmanifoldsButtonClicked() removeViewProvider("MeshGui::ViewProviderMeshNonManifoldPoints"); } else { - d->ui.checkNonmanifoldsButton->setText(tr("%1 non-manifolds").arg(f_eval.CountManifolds()+point_indices.size())); + d->ui.checkNonmanifoldsButton->setText( + tr("%1 non-manifolds").arg(f_eval.CountManifolds() + point_indices.size())); d->ui.checkNonmanifoldsButton->setChecked(true); d->ui.repairNonmanifoldsButton->setEnabled(true); d->ui.repairAllTogether->setEnabled(true); if (!ok1) { - const std::vector >& inds = f_eval.GetIndices(); + const std::vector>& inds = + f_eval.GetIndices(); std::vector indices; - indices.reserve(2*inds.size()); - std::vector >::const_iterator it; + indices.reserve(2 * inds.size()); + std::vector>::const_iterator it; for (it = inds.begin(); it != inds.end(); ++it) { indices.push_back(it->first); indices.push_back(it->second); @@ -635,14 +661,18 @@ void DlgEvaluateMeshImp::onRepairNonmanifoldsButtonClicked() Gui::Document* doc = Gui::Application::Instance->getDocument(docName); doc->openCommand(QT_TRANSLATE_NOOP("Command", "Remove non-manifolds")); try { - Gui::Command::doCommand(Gui::Command::App - , "App.getDocument(\"%s\").getObject(\"%s\").removeNonManifolds()" - , docName, objName); + Gui::Command::doCommand( + Gui::Command::App, + "App.getDocument(\"%s\").getObject(\"%s\").removeNonManifolds()", + docName, + objName); if (d->checkNonManfoldPoints) { - Gui::Command::doCommand(Gui::Command::App - , "App.getDocument(\"%s\").getObject(\"%s\").removeNonManifoldPoints()" - , docName, objName); + Gui::Command::doCommand( + Gui::Command::App, + "App.getDocument(\"%s\").getObject(\"%s\").removeNonManifoldPoints()", + docName, + objName); } } catch (const Base::Exception& e) { @@ -664,12 +694,15 @@ void DlgEvaluateMeshImp::onRepairNonmanifoldsButtonClicked() void DlgEvaluateMeshImp::onCheckIndicesButtonClicked() { - std::map::iterator it = d->vp.find("MeshGui::ViewProviderMeshIndices"); + std::map::iterator it = + d->vp.find("MeshGui::ViewProviderMeshIndices"); if (it != d->vp.end()) { - if (d->ui.checkIndicesButton->isChecked()) + if (d->ui.checkIndicesButton->isChecked()) { it->second->show(); - else + } + else { it->second->hide(); + } } } @@ -698,7 +731,7 @@ void DlgEvaluateMeshImp::onAnalyzeIndicesButtonClicked() d->ui.checkIndicesButton->setChecked(true); d->ui.repairIndicesButton->setEnabled(true); d->ui.repairAllTogether->setEnabled(true); - //addViewProvider("MeshGui::ViewProviderMeshIndices", rp.GetIndices()); + // addViewProvider("MeshGui::ViewProviderMeshIndices", rp.GetIndices()); } else if (!cf.Evaluate()) { d->ui.checkIndicesButton->setText(tr("Multiple point indices")); @@ -734,9 +767,10 @@ void DlgEvaluateMeshImp::onRepairIndicesButtonClicked() Gui::Document* doc = Gui::Application::Instance->getDocument(docName); doc->openCommand(QT_TRANSLATE_NOOP("Command", "Fix indices")); try { - Gui::Command::doCommand(Gui::Command::App - , "App.getDocument(\"%s\").getObject(\"%s\").fixIndices()" - , docName, objName); + Gui::Command::doCommand(Gui::Command::App, + "App.getDocument(\"%s\").getObject(\"%s\").fixIndices()", + docName, + objName); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Indices"), QString::fromLatin1(e.what())); @@ -753,12 +787,15 @@ void DlgEvaluateMeshImp::onRepairIndicesButtonClicked() void DlgEvaluateMeshImp::onCheckDegenerationButtonClicked() { - std::map::iterator it = d->vp.find("MeshGui::ViewProviderMeshDegenerations"); + std::map::iterator it = + d->vp.find("MeshGui::ViewProviderMeshDegenerations"); if (it != d->vp.end()) { - if (d->ui.checkDegenerationButton->isChecked()) + if (d->ui.checkDegenerationButton->isChecked()) { it->second->show(); - else + } + else { it->second->hide(); + } } } @@ -800,9 +837,12 @@ void DlgEvaluateMeshImp::onRepairDegeneratedButtonClicked() Gui::Document* doc = Gui::Application::Instance->getDocument(docName); doc->openCommand(QT_TRANSLATE_NOOP("Command", "Remove degenerated faces")); try { - Gui::Command::doCommand(Gui::Command::App - , "App.getDocument(\"%s\").getObject(\"%s\").fixDegenerations(%f)" - , docName, objName, d->epsilonDegenerated); + Gui::Command::doCommand( + Gui::Command::App, + "App.getDocument(\"%s\").getObject(\"%s\").fixDegenerations(%f)", + docName, + objName, + d->epsilonDegenerated); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Degenerations"), QString::fromLatin1(e.what())); @@ -819,12 +859,15 @@ void DlgEvaluateMeshImp::onRepairDegeneratedButtonClicked() void DlgEvaluateMeshImp::onCheckDuplicatedFacesButtonClicked() { - std::map::iterator it = d->vp.find("MeshGui::ViewProviderMeshDuplicatedFaces"); + std::map::iterator it = + d->vp.find("MeshGui::ViewProviderMeshDuplicatedFaces"); if (it != d->vp.end()) { - if (d->ui.checkDuplicatedFacesButton->isChecked()) + if (d->ui.checkDuplicatedFacesButton->isChecked()) { it->second->show(); - else + } + else { it->second->hide(); + } } } @@ -867,9 +910,11 @@ void DlgEvaluateMeshImp::onRepairDuplicatedFacesButtonClicked() Gui::Document* doc = Gui::Application::Instance->getDocument(docName); doc->openCommand(QT_TRANSLATE_NOOP("Command", "Remove duplicated faces")); try { - Gui::Command::doCommand(Gui::Command::App - , "App.getDocument(\"%s\").getObject(\"%s\").removeDuplicatedFacets()" - , docName, objName); + Gui::Command::doCommand( + Gui::Command::App, + "App.getDocument(\"%s\").getObject(\"%s\").removeDuplicatedFacets()", + docName, + objName); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Duplicated faces"), QString::fromLatin1(e.what())); @@ -886,12 +931,15 @@ void DlgEvaluateMeshImp::onRepairDuplicatedFacesButtonClicked() void DlgEvaluateMeshImp::onCheckDuplicatedPointsButtonClicked() { - std::map::iterator it = d->vp.find("MeshGui::ViewProviderMeshDuplicatedPoints"); + std::map::iterator it = + d->vp.find("MeshGui::ViewProviderMeshDuplicatedPoints"); if (it != d->vp.end()) { - if (d->ui.checkDuplicatedPointsButton->isChecked()) + if (d->ui.checkDuplicatedPointsButton->isChecked()) { it->second->show(); - else + } + else { it->second->hide(); + } } } @@ -932,9 +980,11 @@ void DlgEvaluateMeshImp::onRepairDuplicatedPointsButtonClicked() Gui::Document* doc = Gui::Application::Instance->getDocument(docName); doc->openCommand(QT_TRANSLATE_NOOP("Command", "Remove duplicated points")); try { - Gui::Command::doCommand(Gui::Command::App - , "App.getDocument(\"%s\").getObject(\"%s\").removeDuplicatedPoints()" - , docName, objName); + Gui::Command::doCommand( + Gui::Command::App, + "App.getDocument(\"%s\").getObject(\"%s\").removeDuplicatedPoints()", + docName, + objName); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Duplicated points"), QString::fromLatin1(e.what())); @@ -951,12 +1001,15 @@ void DlgEvaluateMeshImp::onRepairDuplicatedPointsButtonClicked() void DlgEvaluateMeshImp::onCheckSelfIntersectionButtonClicked() { - std::map::iterator it = d->vp.find("MeshGui::ViewProviderMeshSelfIntersections"); + std::map::iterator it = + d->vp.find("MeshGui::ViewProviderMeshSelfIntersections"); if (it != d->vp.end()) { - if (d->ui.checkSelfIntersectionButton->isChecked()) + if (d->ui.checkSelfIntersectionButton->isChecked()) { it->second->show(); - else + } + else { it->second->hide(); + } } } @@ -969,7 +1022,7 @@ void DlgEvaluateMeshImp::onAnalyzeSelfIntersectionButtonClicked() const MeshKernel& rMesh = d->meshFeature->Mesh.getValue().getKernel(); MeshEvalSelfIntersection eval(rMesh); - std::vector > intersection; + std::vector> intersection; try { eval.GetIntersections(intersection); } @@ -990,8 +1043,8 @@ void DlgEvaluateMeshImp::onAnalyzeSelfIntersectionButtonClicked() d->ui.repairAllTogether->setEnabled(true); std::vector indices; - indices.reserve(2*intersection.size()); - std::vector >::iterator it; + indices.reserve(2 * intersection.size()); + std::vector>::iterator it; for (it = intersection.begin(); it != intersection.end(); ++it) { indices.push_back(it->first); indices.push_back(it->second); @@ -1027,12 +1080,15 @@ void DlgEvaluateMeshImp::onRepairSelfIntersectionButtonClicked() void DlgEvaluateMeshImp::onCheckFoldsButtonClicked() { - std::map::iterator it = d->vp.find("MeshGui::ViewProviderMeshFolds"); + std::map::iterator it = + d->vp.find("MeshGui::ViewProviderMeshFolds"); if (it != d->vp.end()) { - if (d->ui.checkFoldsButton->isChecked()) + if (d->ui.checkFoldsButton->isChecked()) { it->second->show(); - else + } + else { it->second->hide(); + } } } @@ -1058,7 +1114,7 @@ void DlgEvaluateMeshImp::onAnalyzeFoldsButtonClicked() removeViewProvider("MeshGui::ViewProviderMeshFolds"); } else { - std::vector inds = f_eval.GetIndices(); + std::vector inds = f_eval.GetIndices(); std::vector inds1 = s_eval.GetIndices(); std::vector inds2 = b_eval.GetIndices(); inds.insert(inds.end(), inds1.begin(), inds1.end()); @@ -1089,9 +1145,11 @@ void DlgEvaluateMeshImp::onRepairFoldsButtonClicked() qApp->setOverrideCursor(Qt::WaitCursor); doc->openCommand(QT_TRANSLATE_NOOP("Command", "Remove folds")); try { - Gui::Command::doCommand(Gui::Command::App - , "App.getDocument(\"%s\").getObject(\"%s\").removeFoldsOnSurface()" - , docName, objName); + Gui::Command::doCommand( + Gui::Command::App, + "App.getDocument(\"%s\").getObject(\"%s\").removeFoldsOnSurface()", + docName, + objName); } catch (const Base::Exception& e) { QMessageBox::warning(this, tr("Folds"), QString::fromLatin1(e.what())); @@ -1123,6 +1181,7 @@ void DlgEvaluateMeshImp::onAnalyzeAllTogetherClicked() void DlgEvaluateMeshImp::onRepairAllTogetherClicked() { + // clang-format off if (d->meshFeature) { Gui::WaitCursor wc; const char* docName = App::GetApplication().getDocumentName(d->meshFeature->getDocument()); @@ -1236,6 +1295,7 @@ void DlgEvaluateMeshImp::onRepairAllTogetherClicked() doc->commitCommand(); doc->getDocument()->recompute(); } + // clang-format on } void DlgEvaluateMeshImp::onButtonBoxClicked(QAbstractButton* button) @@ -1251,10 +1311,12 @@ void DlgEvaluateMeshImp::onButtonBoxClicked(QAbstractButton* button) d->enableFoldsCheck = dlg.isFoldsChecked(); d->showFoldsFunction(d->enableFoldsCheck); d->strictlyDegenerated = dlg.isDegeneratedFacetsChecked(); - if (d->strictlyDegenerated) + if (d->strictlyDegenerated) { d->epsilonDegenerated = 0.0f; - else + } + else { d->epsilonDegenerated = MeshCore::MeshDefinitions::_fMinPointDistanceP2; + } } } else if (type == QDialogButtonBox::Reset) { @@ -1263,8 +1325,9 @@ void DlgEvaluateMeshImp::onButtonBoxClicked(QAbstractButton* button) showInformation(); d->self_intersections.clear(); QList cbs = this->findChildren(); - Q_FOREACH (QCheckBox *cb, cbs) + Q_FOREACH (QCheckBox* cb, cbs) { cb->setChecked(false); + } } } @@ -1272,16 +1335,16 @@ void DlgEvaluateMeshImp::onButtonBoxClicked(QAbstractButton* button) /* TRANSLATOR MeshGui::DockEvaluateMeshImp */ -#if 0 // needed for Qt's lupdate utility +#if 0 // needed for Qt's lupdate utility qApp->translate("QDockWidget", "Evaluate & Repair Mesh"); #endif -DockEvaluateMeshImp* DockEvaluateMeshImp::_instance=nullptr; +DockEvaluateMeshImp* DockEvaluateMeshImp::_instance = nullptr; DockEvaluateMeshImp* DockEvaluateMeshImp::instance() { // not initialized? - if(!_instance) { + if (!_instance) { _instance = new DockEvaluateMeshImp(Gui::getMainWindow()); _instance->setSizeGripEnabled(false); } @@ -1289,10 +1352,10 @@ DockEvaluateMeshImp* DockEvaluateMeshImp::instance() return _instance; } -void DockEvaluateMeshImp::destruct () +void DockEvaluateMeshImp::destruct() { if (_instance) { - DockEvaluateMeshImp *pTmp = _instance; + DockEvaluateMeshImp* pTmp = _instance; _instance = nullptr; delete pTmp; } @@ -1307,8 +1370,8 @@ bool DockEvaluateMeshImp::hasInstance() * Constructs a DockEvaluateMeshImp which is a child of 'parent', with the * name 'name' and widget flags set to 'f' */ -DockEvaluateMeshImp::DockEvaluateMeshImp( QWidget* parent, Qt::WindowFlags fl ) - : DlgEvaluateMeshImp( parent, fl ) +DockEvaluateMeshImp::DockEvaluateMeshImp(QWidget* parent, Qt::WindowFlags fl) + : DlgEvaluateMeshImp(parent, fl) { scrollArea = new QScrollArea(); scrollArea->setObjectName(QLatin1String("scrollArea")); @@ -1320,9 +1383,9 @@ DockEvaluateMeshImp::DockEvaluateMeshImp( QWidget* parent, Qt::WindowFlags fl ) // embed this dialog into a dockable widget container Gui::DockWindowManager* pDockMgr = Gui::DockWindowManager::instance(); // use Qt macro for preparing for translation stuff (but not translating yet) - QDockWidget* dw = pDockMgr->addDockWindow("Evaluate & Repair Mesh", - scrollArea, Qt::RightDockWidgetArea); - dw->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); + QDockWidget* dw = + pDockMgr->addDockWindow("Evaluate & Repair Mesh", scrollArea, Qt::RightDockWidgetArea); + dw->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); dw->show(); } @@ -1351,10 +1414,9 @@ void DockEvaluateMeshImp::closeEvent(QCloseEvent*) /** * Returns an appropriate size hint for the dock window. */ -QSize DockEvaluateMeshImp::sizeHint () const +QSize DockEvaluateMeshImp::sizeHint() const { return {371, 579}; } #include "moc_DlgEvaluateMeshImp.cpp" - diff --git a/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.h b/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.h index 39e1900da4..02b99d07fc 100644 --- a/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.h +++ b/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.h @@ -36,14 +36,17 @@ class QAbstractButton; class QScrollArea; -namespace Gui { +namespace Gui +{ class View3DInventor; } -namespace Mesh { - class Feature; +namespace Mesh +{ +class Feature; } -namespace MeshGui { +namespace MeshGui +{ class ViewProviderMeshDefects; /** @@ -51,7 +54,7 @@ class ViewProviderMeshDefects; * module when the application is about to be closed. * @author Werner Mayer */ -class CleanupHandler : public QObject +class CleanupHandler: public QObject { Q_OBJECT @@ -65,7 +68,7 @@ private: /** * \author Werner Mayer */ -class DlgEvaluateMeshImp : public QDialog, public App::DocumentObserver +class DlgEvaluateMeshImp: public QDialog, public App::DocumentObserver { Q_OBJECT @@ -123,7 +126,7 @@ private: void onRefreshButtonClicked(); void onMeshNameButtonActivated(int); - void onButtonBoxClicked(QAbstractButton *); + void onButtonBoxClicked(QAbstractButton*); protected: void refreshList(); @@ -132,7 +135,7 @@ protected: void addViewProvider(const char* vp, const std::vector& indices); void removeViewProvider(const char* vp); void removeViewProviders(); - void changeEvent(QEvent *e) override; + void changeEvent(QEvent* e) override; private: class Private; @@ -143,12 +146,12 @@ private: * The DockEvaluateMeshImp class creates a single instance and embeds it into a dock window. * \author Werner Mayer */ -class DockEvaluateMeshImp : public DlgEvaluateMeshImp +class DockEvaluateMeshImp: public DlgEvaluateMeshImp { Q_OBJECT protected: - explicit DockEvaluateMeshImp( QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags() ); + explicit DockEvaluateMeshImp(QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags()); ~DockEvaluateMeshImp() override; void closeEvent(QCloseEvent* e) override; @@ -157,13 +160,13 @@ public: static void destruct(); static bool hasInstance(); - QSize sizeHint () const override; + QSize sizeHint() const override; private: QScrollArea* scrollArea; static DockEvaluateMeshImp* _instance; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_DLG_EVALUATE_MESH_IMP_H +#endif // MESHGUI_DLG_EVALUATE_MESH_IMP_H diff --git a/src/Mod/Mesh/Gui/DlgEvaluateSettings.cpp b/src/Mod/Mesh/Gui/DlgEvaluateSettings.cpp index 48a1a81594..42ff26ecdb 100644 --- a/src/Mod/Mesh/Gui/DlgEvaluateSettings.cpp +++ b/src/Mod/Mesh/Gui/DlgEvaluateSettings.cpp @@ -31,7 +31,8 @@ using namespace MeshGui; /* TRANSLATOR MeshGui::DlgEvaluateSettings */ DlgEvaluateSettings::DlgEvaluateSettings(QWidget* parent, Qt::WindowFlags fl) - : QDialog(parent, fl), ui(new Ui_DlgEvaluateSettings) + : QDialog(parent, fl) + , ui(new Ui_DlgEvaluateSettings) { ui->setupUi(this); } @@ -72,4 +73,3 @@ bool DlgEvaluateSettings::isDegeneratedFacetsChecked() const } #include "moc_DlgEvaluateSettings.cpp" - diff --git a/src/Mod/Mesh/Gui/DlgEvaluateSettings.h b/src/Mod/Mesh/Gui/DlgEvaluateSettings.h index 18685c4a54..305d93d1b2 100644 --- a/src/Mod/Mesh/Gui/DlgEvaluateSettings.h +++ b/src/Mod/Mesh/Gui/DlgEvaluateSettings.h @@ -26,14 +26,15 @@ #include -namespace MeshGui { +namespace MeshGui +{ class Ui_DlgEvaluateSettings; /** * \author Werner Mayer */ -class DlgEvaluateSettings : public QDialog +class DlgEvaluateSettings: public QDialog { Q_OBJECT @@ -54,6 +55,6 @@ private: Ui_DlgEvaluateSettings* ui; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_DLG_EVALUATE_SETTINGS_H +#endif // MESHGUI_DLG_EVALUATE_SETTINGS_H diff --git a/src/Mod/Mesh/Gui/DlgRegularSolidImp.cpp b/src/Mod/Mesh/Gui/DlgRegularSolidImp.cpp index a1db0c6860..3ffcabc003 100644 --- a/src/Mod/Mesh/Gui/DlgRegularSolidImp.cpp +++ b/src/Mod/Mesh/Gui/DlgRegularSolidImp.cpp @@ -23,8 +23,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -44,6 +44,7 @@ using namespace MeshGui; /* TRANSLATOR MeshGui::DlgRegularSolidImp */ +// clang-format off DlgRegularSolidImp::DlgRegularSolidImp(QWidget* parent, Qt::WindowFlags fl) : QDialog( parent, fl ) , ui(new Ui_DlgRegularSolid) @@ -217,5 +218,6 @@ void DlgRegularSolidImp::onCreateSolidButtonClicked() QString::fromLatin1(e.what())); } } +// clang-format on #include "moc_DlgRegularSolidImp.cpp" diff --git a/src/Mod/Mesh/Gui/DlgRegularSolidImp.h b/src/Mod/Mesh/Gui/DlgRegularSolidImp.h index 2f6900e201..4473febef7 100644 --- a/src/Mod/Mesh/Gui/DlgRegularSolidImp.h +++ b/src/Mod/Mesh/Gui/DlgRegularSolidImp.h @@ -27,9 +27,10 @@ #include #include -namespace MeshGui { +namespace MeshGui +{ class Ui_DlgRegularSolid; -class DlgRegularSolidImp : public QDialog +class DlgRegularSolidImp: public QDialog { Q_OBJECT @@ -41,12 +42,12 @@ private: void onCreateSolidButtonClicked(); protected: - void changeEvent(QEvent *e) override; + void changeEvent(QEvent* e) override; private: std::unique_ptr ui; }; -} +} // namespace MeshGui -#endif // MESHGUI_DLGREGULARSOLID_IMP_H +#endif // MESHGUI_DLGREGULARSOLID_IMP_H diff --git a/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.cpp b/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.cpp index 76e3825f60..cdda5fe0e4 100644 --- a/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.cpp +++ b/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.cpp @@ -32,7 +32,8 @@ using namespace MeshGui; DlgSettingsImportExport::DlgSettingsImportExport(QWidget* parent) - : PreferencePage(parent), ui(new Ui_DlgSettingsImportExport) + : PreferencePage(parent) + , ui(new Ui_DlgSettingsImportExport) { ui->setupUi(this); ui->exportAmfCompressed->setToolTip(tr("This parameter indicates whether ZIP compression\n" @@ -47,8 +48,8 @@ DlgSettingsImportExport::~DlgSettingsImportExport() void DlgSettingsImportExport::saveSettings() { - ParameterGrp::handle handle = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Mod/Mesh"); + ParameterGrp::handle handle = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Mesh"); double value = ui->maxDeviationExport->value().getValue(); handle->SetFloat("MaxDeviationExport", value); @@ -65,8 +66,8 @@ void DlgSettingsImportExport::saveSettings() void DlgSettingsImportExport::loadSettings() { - ParameterGrp::handle handle = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Mod/Mesh"); + ParameterGrp::handle handle = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Mesh"); double value = ui->maxDeviationExport->value().getValue(); value = handle->GetFloat("MaxDeviationExport", value); ui->maxDeviationExport->setValue(value); @@ -82,7 +83,7 @@ void DlgSettingsImportExport::loadSettings() /** * Sets the strings of the subwidgets using the current language. */ -void DlgSettingsImportExport::changeEvent(QEvent *e) +void DlgSettingsImportExport::changeEvent(QEvent* e) { if (e->type() == QEvent::LanguageChange) { ui->retranslateUi(this); @@ -93,4 +94,3 @@ void DlgSettingsImportExport::changeEvent(QEvent *e) } #include "moc_DlgSettingsImportExportImp.cpp" - diff --git a/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.h b/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.h index 76d174d883..6851b65cbe 100644 --- a/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.h +++ b/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.h @@ -24,19 +24,20 @@ #define MESHGUI_DLGSETTINGSIMPORTEXPORTIMP_H #ifndef MESH_GLOBAL_H -# include +#include #endif #include -namespace MeshGui { +namespace MeshGui +{ class Ui_DlgSettingsImportExport; /** * The DlgSettingsImportExportImp class implements a preference page to change settings * for Importing and Exporting mesh objects. */ -class DlgSettingsImportExport : public Gui::Dialog::PreferencePage +class DlgSettingsImportExport: public Gui::Dialog::PreferencePage { Q_OBJECT @@ -47,13 +48,12 @@ public: protected: void saveSettings() override; void loadSettings() override; - void changeEvent(QEvent *e) override; + void changeEvent(QEvent* e) override; private: Ui_DlgSettingsImportExport* ui; }; // end class DlgSettingsImportExport -} // namespace MeshGui - -#endif // MESHGUI_DLGSETTINGSIMPORTEXPORTIMP_H +} // namespace MeshGui +#endif // MESHGUI_DLGSETTINGSIMPORTEXPORTIMP_H diff --git a/src/Mod/Mesh/Gui/DlgSettingsMeshView.cpp b/src/Mod/Mesh/Gui/DlgSettingsMeshView.cpp index 51ef06c614..ce3b670594 100644 --- a/src/Mod/Mesh/Gui/DlgSettingsMeshView.cpp +++ b/src/Mod/Mesh/Gui/DlgSettingsMeshView.cpp @@ -34,8 +34,8 @@ using namespace MeshGui; * Constructs a DlgSettingsMeshView which is a child of 'parent'. */ DlgSettingsMeshView::DlgSettingsMeshView(QWidget* parent) - : PreferencePage(parent) - , ui(new Ui_DlgSettingsMeshView) + : PreferencePage(parent) + , ui(new Ui_DlgSettingsMeshView) { ui->setupUi(this); ui->labelBackfaceColor->hide(); @@ -64,9 +64,9 @@ void DlgSettingsMeshView::loadSettings() { Base::Reference hGrp = Gui::WindowParameter::getDefaultParameter(); hGrp = hGrp->GetGroup("View"); - if (!hGrp->GetBool("EnablePreselection",true) && - !hGrp->GetBool("EnableSelection",true)) + if (!hGrp->GetBool("EnablePreselection", true) && !hGrp->GetBool("EnableSelection", true)) { ui->checkboxBoundbox->setDisabled(true); + } ui->checkboxRendering->onRestore(); ui->checkboxBoundbox->onRestore(); ui->buttonMeshColor->onRestore(); @@ -81,7 +81,7 @@ void DlgSettingsMeshView::loadSettings() /** * Sets the strings of the subwidgets using the current language. */ -void DlgSettingsMeshView::changeEvent(QEvent *e) +void DlgSettingsMeshView::changeEvent(QEvent* e) { if (e->type() == QEvent::LanguageChange) { ui->retranslateUi(this); diff --git a/src/Mod/Mesh/Gui/DlgSettingsMeshView.h b/src/Mod/Mesh/Gui/DlgSettingsMeshView.h index 9abb757b5a..c0b5a4c56d 100644 --- a/src/Mod/Mesh/Gui/DlgSettingsMeshView.h +++ b/src/Mod/Mesh/Gui/DlgSettingsMeshView.h @@ -24,21 +24,22 @@ #define MESHGUI_DLGSETTINGSMESHVIEW_H #ifndef MESH_GLOBAL_H -# include +#include #endif #include #include -namespace MeshGui { +namespace MeshGui +{ class Ui_DlgSettingsMeshView; /** * The DlgSettingsMeshView class implements a preference page to change settings * for display of meshes. * @author Werner Mayer */ -class DlgSettingsMeshView : public Gui::Dialog::PreferencePage +class DlgSettingsMeshView: public Gui::Dialog::PreferencePage { Q_OBJECT @@ -49,12 +50,12 @@ public: protected: void saveSettings() override; void loadSettings() override; - void changeEvent(QEvent *e) override; + void changeEvent(QEvent* e) override; private: std::unique_ptr ui; }; -} // namespace Gui +} // namespace MeshGui -#endif // MESHGUI_DLGSETTINGSMESHVIEW_H +#endif // MESHGUI_DLGSETTINGSMESHVIEW_H diff --git a/src/Mod/Mesh/Gui/DlgSmoothing.cpp b/src/Mod/Mesh/Gui/DlgSmoothing.cpp index 914f2a8c29..ae3f4f8252 100644 --- a/src/Mod/Mesh/Gui/DlgSmoothing.cpp +++ b/src/Mod/Mesh/Gui/DlgSmoothing.cpp @@ -22,19 +22,19 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include #include #include -#include #include +#include #include "DlgSmoothing.h" -#include "ui_DlgSmoothing.h" #include "Selection.h" +#include "ui_DlgSmoothing.h" using namespace MeshGui; @@ -42,8 +42,10 @@ using namespace MeshGui; /* TRANSLATOR MeshGui::DlgSmoothing */ DlgSmoothing::DlgSmoothing(QWidget* parent) - : QWidget(parent), ui(new Ui_DlgSmoothing()) + : QWidget(parent) + , ui(new Ui_DlgSmoothing()) { + // clang-format off ui->setupUi(this); bg = new QButtonGroup(this); bg->addButton(ui->radioButtonTaubin, 0); @@ -62,6 +64,7 @@ DlgSmoothing::DlgSmoothing(QWidget* parent) ui->labelLambda->setText(QString::fromUtf8("\xce\xbb")); ui->labelMu->setText(QString::fromUtf8("\xce\xbc")); this->resize(this->sizeHint()); + // clang-format on } /* @@ -102,10 +105,12 @@ double DlgSmoothing::microStep() const DlgSmoothing::Smooth DlgSmoothing::method() const { - if (ui->radioButtonTaubin->isChecked()) + if (ui->radioButtonTaubin->isChecked()) { return DlgSmoothing::Taubin; - else if (ui->radioButtonLaplace->isChecked()) + } + else if (ui->radioButtonLaplace->isChecked()) { return DlgSmoothing::Laplace; + } return DlgSmoothing::None; } @@ -122,19 +127,17 @@ void DlgSmoothing::onCheckBoxSelectionToggled(bool on) // ------------------------------------------------ SmoothingDialog::SmoothingDialog(QWidget* parent, Qt::WindowFlags fl) - : QDialog(parent, fl) + : QDialog(parent, fl) { widget = new DlgSmoothing(this); this->setWindowTitle(widget->windowTitle()); QVBoxLayout* hboxLayout = new QVBoxLayout(this); QDialogButtonBox* buttonBox = new QDialogButtonBox(this); - buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); - connect(buttonBox, &QDialogButtonBox::accepted, - this, &QDialog::accept); - connect(buttonBox, &QDialogButtonBox::rejected, - this, &QDialog::reject); + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); hboxLayout->addWidget(widget); hboxLayout->addWidget(buttonBox); @@ -149,28 +152,29 @@ SmoothingDialog::~SmoothingDialog() = default; TaskSmoothing::TaskSmoothing() { widget = new DlgSmoothing(); - Gui::TaskView::TaskBox* taskbox = new Gui::TaskView::TaskBox( - QPixmap(), widget->windowTitle(), false, nullptr); + Gui::TaskView::TaskBox* taskbox = + new Gui::TaskView::TaskBox(QPixmap(), widget->windowTitle(), false, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); selection = new Selection(); - selection->setObjects(Gui::Selection().getSelectionEx(nullptr, Mesh::Feature::getClassTypeId())); + selection->setObjects( + Gui::Selection().getSelectionEx(nullptr, Mesh::Feature::getClassTypeId())); Gui::Selection().clearSelection(); Gui::TaskView::TaskBox* tasksel = new Gui::TaskView::TaskBox(); tasksel->groupLayout()->addWidget(selection); tasksel->hide(); Content.push_back(tasksel); - connect(widget, &DlgSmoothing::toggledSelection, - tasksel, &QWidget::setVisible); + connect(widget, &DlgSmoothing::toggledSelection, tasksel, &QWidget::setVisible); } bool TaskSmoothing::accept() { std::vector meshes = selection->getObjects(); - if (meshes.empty()) + if (meshes.empty()) { return true; + } Gui::WaitCursor wc; Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Mesh Smoothing")); @@ -186,44 +190,42 @@ bool TaskSmoothing::accept() mm->getFacetsFromSelection(selection); selection = mm->getPointsFromFacets(selection); mm->clearFacetSelection(); - if (!selection.empty()) + if (!selection.empty()) { hasSelection = true; + } } Mesh::MeshObject* mm = mesh->Mesh.startEditing(); switch (widget->method()) { - case MeshGui::DlgSmoothing::Taubin: - { - MeshCore::TaubinSmoothing s(mm->getKernel()); - s.SetLambda(widget->lambdaStep()); - s.SetMicro(widget->microStep()); - if (widget->smoothSelection()) { - s.SmoothPoints(widget->iterations(), selection); - } - else { - s.Smooth(widget->iterations()); - } - } break; - case MeshGui::DlgSmoothing::Laplace: - { - MeshCore::LaplaceSmoothing s(mm->getKernel()); - s.SetLambda(widget->lambdaStep()); - if (widget->smoothSelection()) { - s.SmoothPoints(widget->iterations(), selection); - } - else { - s.Smooth(widget->iterations()); - } - } break; - case MeshGui::DlgSmoothing::MedianFilter: - { - MeshCore::MedianFilterSmoothing s(mm->getKernel()); - if (widget->smoothSelection()) { - s.SmoothPoints(widget->iterations(), selection); - } - else { - s.Smooth(widget->iterations()); - } - } break; + case MeshGui::DlgSmoothing::Taubin: { + MeshCore::TaubinSmoothing s(mm->getKernel()); + s.SetLambda(widget->lambdaStep()); + s.SetMicro(widget->microStep()); + if (widget->smoothSelection()) { + s.SmoothPoints(widget->iterations(), selection); + } + else { + s.Smooth(widget->iterations()); + } + } break; + case MeshGui::DlgSmoothing::Laplace: { + MeshCore::LaplaceSmoothing s(mm->getKernel()); + s.SetLambda(widget->lambdaStep()); + if (widget->smoothSelection()) { + s.SmoothPoints(widget->iterations(), selection); + } + else { + s.Smooth(widget->iterations()); + } + } break; + case MeshGui::DlgSmoothing::MedianFilter: { + MeshCore::MedianFilterSmoothing s(mm->getKernel()); + if (widget->smoothSelection()) { + s.SmoothPoints(widget->iterations(), selection); + } + else { + s.Smooth(widget->iterations()); + } + } break; default: break; } diff --git a/src/Mod/Mesh/Gui/DlgSmoothing.h b/src/Mod/Mesh/Gui/DlgSmoothing.h index 816d88c828..a1051e997f 100644 --- a/src/Mod/Mesh/Gui/DlgSmoothing.h +++ b/src/Mod/Mesh/Gui/DlgSmoothing.h @@ -24,25 +24,27 @@ #ifndef MESHGUI_DLGSMOOTHING_H #define MESHGUI_DLGSMOOTHING_H -#include #include #include +#include #ifndef MESH_GLOBAL_H #include #endif class QButtonGroup; -namespace MeshGui { +namespace MeshGui +{ class Selection; class Ui_DlgSmoothing; -class DlgSmoothing : public QWidget +class DlgSmoothing: public QWidget { Q_OBJECT public: - enum Smooth { + enum Smooth + { None, Taubin, Laplace, @@ -72,7 +74,7 @@ private: /** * Embed the panel into a dialog. */ -class MeshGuiExport SmoothingDialog : public QDialog +class MeshGuiExport SmoothingDialog: public QDialog { Q_OBJECT @@ -81,15 +83,25 @@ public: ~SmoothingDialog() override; int iterations() const - { return widget->iterations(); } + { + return widget->iterations(); + } double lambdaStep() const - { return widget->lambdaStep(); } + { + return widget->lambdaStep(); + } double microStep() const - { return widget->microStep(); } + { + return widget->microStep(); + } DlgSmoothing::Smooth method() const - { return widget->method(); } + { + return widget->method(); + } bool smoothSelection() const - { return widget->smoothSelection(); } + { + return widget->smoothSelection(); + } private: DlgSmoothing* widget; @@ -98,7 +110,7 @@ private: /** * Embed the panel into a task dialog. */ -class TaskSmoothing : public Gui::TaskView::TaskDialog +class TaskSmoothing: public Gui::TaskView::TaskDialog { Q_OBJECT @@ -109,15 +121,19 @@ public: bool accept() override; QDialogButtonBox::StandardButtons getStandardButtons() const override - { return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; } + { + return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; + } bool isAllowedAlterDocument() const override - { return true; } + { + return true; + } private: DlgSmoothing* widget; Selection* selection; }; -} +} // namespace MeshGui -#endif // MESHGUI_DLGSMOOTHING_H +#endif // MESHGUI_DLGSMOOTHING_H diff --git a/src/Mod/Mesh/Gui/Doxygen.cpp b/src/Mod/Mesh/Gui/Doxygen.cpp index 7b5bb388ef..d8e722346a 100644 --- a/src/Mod/Mesh/Gui/Doxygen.cpp +++ b/src/Mod/Mesh/Gui/Doxygen.cpp @@ -26,9 +26,9 @@ \brief The namespace of the Mesh Graphical interface layer library This namespace includes the graphical interface of FreeCAD such as: - - The main window - - 3D View - - Tree + - The main window + - 3D View + - Tree and so on...... */ diff --git a/src/Mod/Mesh/Gui/MeshEditor.cpp b/src/Mod/Mesh/Gui/MeshEditor.cpp index e15df12cc4..d91771439b 100644 --- a/src/Mod/Mesh/Gui/MeshEditor.cpp +++ b/src/Mod/Mesh/Gui/MeshEditor.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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -51,8 +51,8 @@ #include #include #include -#include #include +#include #include "MeshEditor.h" #include "SoFCMeshObject.h" @@ -64,7 +64,9 @@ namespace sp = std::placeholders; PROPERTY_SOURCE(MeshGui::ViewProviderFace, Gui::ViewProviderDocumentObject) -ViewProviderFace::ViewProviderFace() : mesh(nullptr), current_index(-1) +ViewProviderFace::ViewProviderFace() + : mesh(nullptr) + , current_index(-1) { pcCoords = new SoCoordinate3(); pcCoords->ref(); @@ -95,7 +97,7 @@ void ViewProviderFace::attach(App::DocumentObject* obj) pointStyle->pointSize = 8.0f; markers->addChild(pointStyle); - SoBaseColor * markcol = new SoBaseColor; + SoBaseColor* markcol = new SoBaseColor; markcol->rgb.setValue(1.0f, 1.0f, 0.0f); SoPointSet* marker = new SoPointSet(); markers->addChild(markcol); @@ -108,9 +110,9 @@ void ViewProviderFace::attach(App::DocumentObject* obj) faceStyle->style = SoDrawStyle::FILLED; faces->addChild(faceStyle); - SoShapeHints * flathints = new SoShapeHints; - //flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE ; - //flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; + SoShapeHints* flathints = new SoShapeHints; + // flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE ; + // flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; faces->addChild(flathints); SoBaseColor* basecol = new SoBaseColor; @@ -137,10 +139,12 @@ void ViewProviderFace::attach(App::DocumentObject* obj) void ViewProviderFace::setDisplayMode(const char* ModeName) { - if (strcmp(ModeName, "Face") == 0) + if (strcmp(ModeName, "Face") == 0) { setDisplayMaskMode("Face"); - else if (strcmp(ModeName, "Marker") == 0) + } + else if (strcmp(ModeName, "Marker") == 0) { setDisplayMaskMode("Marker"); + } ViewProviderDocumentObject::setDisplayMode(ModeName); } @@ -157,7 +161,8 @@ std::vector ViewProviderFace::getDisplayModes() const return modes; } -SoPickedPoint* ViewProviderFace::getPickedPoint(const SbVec2s& pos, const Gui::View3DInventorViewer* viewer) const +SoPickedPoint* ViewProviderFace::getPickedPoint(const SbVec2s& pos, + const Gui::View3DInventorViewer* viewer) const { SoSeparator* root = new SoSeparator; root->ref(); @@ -172,7 +177,7 @@ SoPickedPoint* ViewProviderFace::getPickedPoint(const SbVec2s& pos, const Gui::V // returns a copy of the point SoPickedPoint* pick = rp.getPickedPoint(); - //return (pick ? pick->copy() : 0); // needs the same instance of CRT under MS Windows + // return (pick ? pick->copy() : 0); // needs the same instance of CRT under MS Windows return (pick ? new SoPickedPoint(*pick) : nullptr); } @@ -181,9 +186,9 @@ SoPickedPoint* ViewProviderFace::getPickedPoint(const SbVec2s& pos, const Gui::V /* TRANSLATOR MeshGui::MeshFaceAddition */ MeshFaceAddition::MeshFaceAddition(Gui::View3DInventor* parent) - : QObject(parent), faceView(new MeshGui::ViewProviderFace()) -{ -} + : QObject(parent) + , faceView(new MeshGui::ViewProviderFace()) +{} MeshFaceAddition::~MeshFaceAddition() { @@ -202,9 +207,8 @@ void MeshFaceAddition::startEditing(MeshGui::ViewProviderMesh* vp) faceView->mesh = vp; faceView->attach(vp->getObject()); viewer->addViewProvider(faceView); - //faceView->mesh->startEditing(); - viewer->addEventCallback(SoEvent::getClassTypeId(), - MeshFaceAddition::addFacetCallback, this); + // faceView->mesh->startEditing(); + viewer->addEventCallback(SoEvent::getClassTypeId(), MeshFaceAddition::addFacetCallback, this); } void MeshFaceAddition::finishEditing() @@ -217,9 +221,10 @@ void MeshFaceAddition::finishEditing() viewer->setRedirectToSceneGraphEnabled(false); viewer->removeViewProvider(faceView); - //faceView->mesh->finishEditing(); + // faceView->mesh->finishEditing(); viewer->removeEventCallback(SoEvent::getClassTypeId(), - MeshFaceAddition::addFacetCallback, this); + MeshFaceAddition::addFacetCallback, + this); this->deleteLater(); } @@ -252,8 +257,9 @@ void MeshFaceAddition::clearPoints() void MeshFaceAddition::flipNormal() { - if (faceView->index.size() < 3) + if (faceView->index.size() < 3) { return; + } std::swap(faceView->index[0], faceView->index[1]); SbVec3f v1 = faceView->pcCoords->point[0]; SbVec3f v2 = faceView->pcCoords->point[1]; @@ -263,14 +269,17 @@ void MeshFaceAddition::flipNormal() bool MeshFaceAddition::addMarkerPoint() { - if (faceView->current_index < 0) + if (faceView->current_index < 0) { return false; - if (faceView->index.size() >= 3) + } + if (faceView->index.size() >= 3) { return false; + } faceView->index.push_back(faceView->current_index); faceView->current_index = -1; - if (faceView->index.size() == 3) + if (faceView->index.size() == 3) { faceView->setDisplayMode("Face"); + } return true; } @@ -282,17 +291,20 @@ void MeshFaceAddition::showMarker(SoPickedPoint* pp) if (detail->isOfType(SoFaceDetail::getClassTypeId())) { const SoFaceDetail* fd = static_cast(detail); Mesh::Feature* mf = static_cast(faceView->mesh->getObject()); - const MeshCore::MeshFacetArray& facets = mf->Mesh.getValuePtr()->getKernel().GetFacets(); - const MeshCore::MeshPointArray& points = mf->Mesh.getValuePtr()->getKernel().GetPoints(); + const MeshCore::MeshFacetArray& facets = + mf->Mesh.getValuePtr()->getKernel().GetFacets(); + const MeshCore::MeshPointArray& points = + mf->Mesh.getValuePtr()->getKernel().GetPoints(); // is the face index valid? int face_index = fd->getFaceIndex(); - if (face_index >= (int)facets.size()) + if (face_index >= (int)facets.size()) { return; + } // is a border facet picked? MeshCore::MeshFacet f = facets[face_index]; if (!f.HasOpenEdge()) { // check if a neighbour facet is at the border - bool ok=false; + bool ok = false; for (Mesh::FacetIndex nbIndex : f._aulNeighbours) { if (facets[nbIndex].HasOpenEdge()) { f = facets[nbIndex]; @@ -300,8 +312,9 @@ void MeshFaceAddition::showMarker(SoPickedPoint* pp) break; } } - if (!ok) + if (!ok) { return; + } } int point_index = -1; @@ -309,28 +322,31 @@ void MeshFaceAddition::showMarker(SoPickedPoint* pp) Base::Vector3f pnt; SbVec3f face_pnt; - for (int i=0; i<3; i++) { + for (int i = 0; i < 3; i++) { int index = (int)f._aulPoints[i]; - if (std::find(faceView->index.begin(), faceView->index.end(), index) != faceView->index.end()) - continue; // already inside - if (f._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX || - f._aulNeighbours[(i+2)%3] == MeshCore::FACET_INDEX_MAX) { + if (std::find(faceView->index.begin(), faceView->index.end(), index) + != faceView->index.end()) { + continue; // already inside + } + if (f._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX + || f._aulNeighbours[(i + 2) % 3] == MeshCore::FACET_INDEX_MAX) { pnt = points[index]; - float len = Base::DistanceP2(pnt, Base::Vector3f(vec[0],vec[1],vec[2])); + float len = Base::DistanceP2(pnt, Base::Vector3f(vec[0], vec[1], vec[2])); if (len < distance) { distance = len; point_index = index; - face_pnt.setValue(pnt.x,pnt.y,pnt.z); + face_pnt.setValue(pnt.x, pnt.y, pnt.z); } } } - if (point_index < 0) - return; // picked point is rejected + if (point_index < 0) { + return; // picked point is rejected + } int num = faceView->pcCoords->point.getNum(); if (faceView->current_index >= 0) { - num = std::max(num-1, 0); + num = std::max(num - 1, 0); } faceView->current_index = point_index; faceView->pcCoords->point.set1Value(num, face_pnt); @@ -339,11 +355,11 @@ void MeshFaceAddition::showMarker(SoPickedPoint* pp) } } -void MeshFaceAddition::addFacetCallback(void * ud, SoEventCallback * n) +void MeshFaceAddition::addFacetCallback(void* ud, SoEventCallback* n) { MeshFaceAddition* that = static_cast(ud); - ViewProviderFace* face = that->faceView; - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + ViewProviderFace* face = that->faceView; + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); const SoEvent* ev = n->getEvent(); // If we are in navigation mode then ignore all but key events @@ -355,7 +371,7 @@ void MeshFaceAddition::addFacetCallback(void * ud, SoEventCallback * n) if (ev->getTypeId() == SoLocation2Event::getClassTypeId()) { n->setHandled(); if (face->index.size() < 3) { - SoPickedPoint * point = face->getPickedPoint(ev->getPosition(), view); + SoPickedPoint* point = face->getPickedPoint(ev->getPosition(), view); if (point) { that->showMarker(point); delete point; @@ -363,16 +379,18 @@ void MeshFaceAddition::addFacetCallback(void * ud, SoEventCallback * n) } } else if (ev->getTypeId() == SoMouseButtonEvent::getClassTypeId()) { - const SoMouseButtonEvent * mbe = static_cast(ev); - if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 || - mbe->getButton() == SoMouseButtonEvent::BUTTON2 || - mbe->getButton() == SoMouseButtonEvent::BUTTON3) { + const SoMouseButtonEvent* mbe = static_cast(ev); + if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 + || mbe->getButton() == SoMouseButtonEvent::BUTTON2 + || mbe->getButton() == SoMouseButtonEvent::BUTTON3) { n->setHandled(); } - if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { + if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 + && mbe->getState() == SoButtonEvent::DOWN) { that->addMarkerPoint(); } - else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::UP) { + else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 + && mbe->getState() == SoButtonEvent::UP) { if (face->index.size() == 3) { QMenu menu; QAction* add = menu.addAction(MeshFaceAddition::tr("Add triangle")); @@ -390,7 +408,8 @@ void MeshFaceAddition::addFacetCallback(void * ud, SoEventCallback * n) } } } - else if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) { + else if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 + && mbe->getState() == SoButtonEvent::UP) { QMenu menu; QAction* fin = menu.addAction(MeshFaceAddition::tr("Finish")); QAction* act = menu.exec(QCursor::pos()); @@ -401,9 +420,8 @@ void MeshFaceAddition::addFacetCallback(void * ud, SoEventCallback * n) } // toggle between edit and navigation mode else if (ev->getTypeId().isDerivedFrom(SoKeyboardEvent::getClassTypeId())) { - const SoKeyboardEvent * const ke = static_cast(ev); - if (ke->getState() == SoButtonEvent::DOWN && - ke->getKey() == SoKeyboardEvent::ESCAPE) { + const SoKeyboardEvent* const ke = static_cast(ev); + if (ke->getState() == SoButtonEvent::DOWN && ke->getKey() == SoKeyboardEvent::ESCAPE) { SbBool toggle = view->isRedirectedToSceneGraph(); view->setRedirectToSceneGraph(!toggle); n->setHandled(); @@ -413,27 +431,28 @@ void MeshFaceAddition::addFacetCallback(void * ud, SoEventCallback * n) // ---------------------------------------------------------------------- -namespace MeshGui { - // for sorting of elements - struct NofFacetsCompare +namespace MeshGui +{ +// for sorting of elements +struct NofFacetsCompare +{ + bool operator()(const std::vector& rclC1, + const std::vector& rclC2) { - bool operator () (const std::vector &rclC1, - const std::vector &rclC2) - { - return rclC1.size() < rclC2.size(); - } - }; -} + return rclC1.size() < rclC2.size(); + } +}; +} // namespace MeshGui /* TRANSLATOR MeshGui::MeshFillHole */ MeshFillHole::MeshFillHole(MeshHoleFiller& hf, Gui::View3DInventor* parent) - : QObject(parent) - , myMesh(nullptr) - , myNumPoints(0) - , myVertex1(0) - , myVertex2(0) - , myHoleFiller(hf) + : QObject(parent) + , myMesh(nullptr) + , myNumPoints(0) + , myVertex1(0) + , myVertex2(0) + , myHoleFiller(hf) { myBoundariesRoot = new SoSeparator; myBoundariesRoot->ref(); @@ -449,7 +468,7 @@ MeshFillHole::MeshFillHole(MeshHoleFiller& hf, Gui::View3DInventor* parent) pointStyle->pointSize = 8.0f; myBridgeRoot->addChild(pointStyle); - SoBaseColor * markcol = new SoBaseColor; + SoBaseColor* markcol = new SoBaseColor; markcol->rgb.setValue(1.0f, 1.0f, 0.0f); myBridgeRoot->addChild(markcol); @@ -473,13 +492,12 @@ void MeshFillHole::startEditing(MeshGui::ViewProviderMesh* vp) Gui::View3DInventor* view = static_cast(parent()); Gui::View3DInventorViewer* viewer = view->getViewer(); viewer->setEditing(true); - //viewer->setRedirectToSceneGraph(true); - viewer->addEventCallback(SoEvent::getClassTypeId(), - MeshFillHole::fileHoleCallback, this); - //NOLINTBEGIN + // viewer->setRedirectToSceneGraph(true); + viewer->addEventCallback(SoEvent::getClassTypeId(), MeshFillHole::fileHoleCallback, this); + // NOLINTBEGIN myConnection = App::GetApplication().signalChangedObject.connect( std::bind(&MeshFillHole::slotChangedObject, this, sp::_1, sp::_2)); - //NOLINTEND + // NOLINTEND Gui::coinRemoveAllChildren(myBoundariesRoot); myBoundariesRoot->addChild(viewer->getHeadlight()); @@ -497,9 +515,8 @@ void MeshFillHole::finishEditing() Gui::View3DInventor* view = static_cast(parent()); Gui::View3DInventorViewer* viewer = view->getViewer(); viewer->setEditing(false); - //viewer->setRedirectToSceneGraph(false); - viewer->removeEventCallback(SoEvent::getClassTypeId(), - MeshFillHole::fileHoleCallback, this); + // viewer->setRedirectToSceneGraph(false); + viewer->removeEventCallback(SoEvent::getClassTypeId(), MeshFillHole::fileHoleCallback, this); myConnection.disconnect(); this->deleteLater(); static_cast(viewer->getSceneGraph())->removeChild(myBridgeRoot); @@ -513,8 +530,9 @@ void MeshFillHole::closeBridge() TBoundary::iterator jt = std::find(myPolygon.begin(), myPolygon.end(), myVertex2); if (it != myPolygon.end() && jt != myPolygon.end()) { // which iterator comes first - if (jt < it) + if (jt < it) { std::swap(it, jt); + } // split the boundary into two loops and take the shorter one std::list bounds; TBoundary loop1, loop2; @@ -522,28 +540,33 @@ void MeshFillHole::closeBridge() loop1.insert(loop1.end(), jt, myPolygon.end()); loop2.insert(loop2.end(), it, jt); // this happens when myVertex1 == myVertex2 - if (loop2.empty()) + if (loop2.empty()) { bounds.push_back(loop1); - else if (loop1.size() < loop2.size()) + } + else if (loop1.size() < loop2.size()) { bounds.push_back(loop1); - else + } + else { bounds.push_back(loop2); + } App::Document* doc = myMesh->getDocument(); doc->openTransaction("Bridge && Fill hole"); Mesh::MeshObject* pMesh = myMesh->Mesh.startEditing(); bool ok = myHoleFiller.fillHoles(*pMesh, bounds, myVertex1, myVertex2); myMesh->Mesh.finishEditing(); - if (ok) + if (ok) { doc->commitTransaction(); - else + } + else { doc->abortTransaction(); + } } } void MeshFillHole::slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) { - if (&Obj == myMesh && strcmp(Prop.getName(),"Mesh") == 0) { + if (&Obj == myMesh && strcmp(Prop.getName(), "Mesh") == 0) { Gui::coinRemoveAllChildren(myBoundariesGroup); myVertex->point.setNum(0); myNumPoints = 0; @@ -564,10 +587,10 @@ void MeshFillHole::createPolygons() myBoundaryRoot->addChild(pickStyle); // get mesh kernel - const MeshCore::MeshKernel & rMesh = this->myMesh->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = this->myMesh->Mesh.getValue().getKernel(); // get the mesh boundaries as an array of point indices - std::list > borders; + std::list> borders; MeshCore::MeshAlgorithm cAlgo(rMesh); MeshCore::MeshPointIterator p_iter(rMesh); cAlgo.GetMeshBorders(borders); @@ -576,10 +599,11 @@ void MeshFillHole::createPolygons() // sort the borders in ascending order of the number of edges borders.sort(NofFacetsCompare()); - int32_t count=0; - for (auto & border : borders) { - if (border.front() == border.back()) + int32_t count = 0; + for (auto& border : borders) { + if (border.front() == border.back()) { border.pop_back(); + } count += border.size(); } @@ -589,7 +613,7 @@ void MeshFillHole::createPolygons() coords->point.setNum(count); int32_t index = 0; - for (const auto & border : borders) { + for (const auto& border : borders) { SoPolygon* polygon = new SoPolygon(); polygon->startIndex = index; polygon->numVertices = border.size(); @@ -597,18 +621,20 @@ void MeshFillHole::createPolygons() myPolygons[polygon] = border; for (Mesh::PointIndex jt : border) { p_iter.Set(jt); - coords->point.set1Value(index++,p_iter->x,p_iter->y,p_iter->z); + coords->point.set1Value(index++, p_iter->x, p_iter->y, p_iter->z); } } } -SoNode* MeshFillHole::getPickedPolygon(const SoRayPickAction& action/*SoNode* root, const SbVec2s& pos*/) const +SoNode* MeshFillHole::getPickedPolygon( + const SoRayPickAction& action /*SoNode* root, const SbVec2s& pos*/) const { SoPolygon* poly = nullptr; - const SoPickedPointList & points = action.getPickedPointList(); - for (int i=0; i < points.getLength(); i++) { - const SoPickedPoint * point = points[i]; - if (point && point->getPath()->getTail()->getTypeId() == MeshGui::SoPolygon::getClassTypeId()) { + const SoPickedPointList& points = action.getPickedPointList(); + for (int i = 0; i < points.getLength(); i++) { + const SoPickedPoint* point = points[i]; + if (point + && point->getPath()->getTail()->getTypeId() == MeshGui::SoPolygon::getClassTypeId()) { // we have something picked, now check if it was an SoPolygon node SoPolygon* node = static_cast(point->getPath()->getTail()); if (!poly) { @@ -624,21 +650,23 @@ SoNode* MeshFillHole::getPickedPolygon(const SoRayPickAction& action/*SoNode* ro return poly; } -float MeshFillHole::findClosestPoint(const SbLine& ray, const TBoundary& polygon, - Mesh::PointIndex& vertex_index, SbVec3f& closestPoint) const +float MeshFillHole::findClosestPoint(const SbLine& ray, + const TBoundary& polygon, + Mesh::PointIndex& vertex_index, + SbVec3f& closestPoint) const { // now check which vertex of the polygon is closest to the ray float minDist = FLT_MAX; vertex_index = MeshCore::POINT_INDEX_MAX; - const MeshCore::MeshKernel & rMesh = myMesh->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = myMesh->Mesh.getValue().getKernel(); const MeshCore::MeshPointArray& pts = rMesh.GetPoints(); for (Mesh::PointIndex it : polygon) { SbVec3f vertex; const Base::Vector3f& v = pts[it]; - vertex.setValue(v.x,v.y,v.z); + vertex.setValue(v.x, v.y, v.z); SbVec3f point = ray.getClosestPoint(vertex); - float distance = (vertex-point).sqrLength(); + float distance = (vertex - point).sqrLength(); if (distance < minDist) { minDist = distance; vertex_index = it; @@ -649,10 +677,10 @@ float MeshFillHole::findClosestPoint(const SbLine& ray, const TBoundary& polygon return minDist; } -void MeshFillHole::fileHoleCallback(void * ud, SoEventCallback * n) +void MeshFillHole::fileHoleCallback(void* ud, SoEventCallback* n) { MeshFillHole* self = static_cast(ud); - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); const SoEvent* ev = n->getEvent(); if (ev->getTypeId() == SoLocation2Event::getClassTypeId()) { @@ -660,10 +688,12 @@ void MeshFillHole::fileHoleCallback(void * ud, SoEventCallback * n) SoRayPickAction rp(view->getSoRenderManager()->getViewportRegion()); rp.setPoint(ev->getPosition()); rp.setPickAll(true); - if (self->myNumPoints == 0) + if (self->myNumPoints == 0) { rp.apply(self->myBoundariesRoot); - else + } + else { rp.apply(self->myBoundaryRoot); + } SoNode* node = self->getPickedPolygon(rp); if (node) { std::map::iterator it = self->myPolygons.find(node); @@ -671,29 +701,36 @@ void MeshFillHole::fileHoleCallback(void * ud, SoEventCallback * n) // now check which vertex of the polygon is closest to the ray Mesh::PointIndex vertex_index; SbVec3f closestPoint; - float minDist = self->findClosestPoint(rp.getLine(), it->second, vertex_index, closestPoint); + float minDist = + self->findClosestPoint(rp.getLine(), it->second, vertex_index, closestPoint); if (minDist < 1.0f) { - if (self->myNumPoints == 0) + if (self->myNumPoints == 0) { self->myVertex->point.set1Value(0, closestPoint); - else + } + else { self->myVertex->point.set1Value(1, closestPoint); + } } } } } else if (ev->getTypeId() == SoMouseButtonEvent::getClassTypeId()) { n->setHandled(); - const SoMouseButtonEvent * mbe = static_cast(ev); - if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::UP) { - if (self->myNumPoints > 1) + const SoMouseButtonEvent* mbe = static_cast(ev); + if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 + && mbe->getState() == SoButtonEvent::UP) { + if (self->myNumPoints > 1) { return; + } SoRayPickAction rp(view->getSoRenderManager()->getViewportRegion()); rp.setPoint(ev->getPosition()); rp.setPickAll(true); - if (self->myNumPoints == 0) + if (self->myNumPoints == 0) { rp.apply(self->myBoundariesRoot); - else + } + else { rp.apply(self->myBoundaryRoot); + } SoNode* node = self->getPickedPolygon(rp); if (node) { std::map::iterator it = self->myPolygons.find(node); @@ -701,7 +738,10 @@ void MeshFillHole::fileHoleCallback(void * ud, SoEventCallback * n) // now check which vertex of the polygon is closest to the ray Mesh::PointIndex vertex_index; SbVec3f closestPoint; - float minDist = self->findClosestPoint(rp.getLine(), it->second, vertex_index, closestPoint); + float minDist = self->findClosestPoint(rp.getLine(), + it->second, + vertex_index, + closestPoint); if (minDist < 1.0f) { if (self->myNumPoints == 0) { self->myBoundaryRoot->addChild(node); @@ -722,7 +762,8 @@ void MeshFillHole::fileHoleCallback(void * ud, SoEventCallback * n) } } } - else if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) { + else if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 + && mbe->getState() == SoButtonEvent::UP) { QMenu menu; QAction* fin = menu.addAction(MeshFillHole::tr("Finish")); QAction* act = menu.exec(QCursor::pos()); diff --git a/src/Mod/Mesh/Gui/MeshEditor.h b/src/Mod/Mesh/Gui/MeshEditor.h index 01e6c56bc0..a7a6ee4c62 100644 --- a/src/Mod/Mesh/Gui/MeshEditor.h +++ b/src/Mod/Mesh/Gui/MeshEditor.h @@ -38,16 +38,27 @@ class SoRayPickAction; class SbLine; class SbVec3f; -namespace Gui { class View3DInventor; class View3DInventorViewer;} -namespace Mesh { class MeshObject; } -namespace Mesh { class Feature; } -namespace MeshGui { +namespace Gui +{ +class View3DInventor; +class View3DInventorViewer; +} // namespace Gui +namespace Mesh +{ +class MeshObject; +} +namespace Mesh +{ +class Feature; +} +namespace MeshGui +{ class SoFCMeshPickNode; /** The ViewProviderFace class is used to display a single face. * @author Werner Mayer */ -class MeshGuiExport ViewProviderFace : public Gui::ViewProviderDocumentObject +class MeshGuiExport ViewProviderFace: public Gui::ViewProviderDocumentObject { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderFace); @@ -60,14 +71,15 @@ public: void setDisplayMode(const char* ModeName) override; const char* getDefaultDisplayMode() const override; std::vector getDisplayModes() const override; - SoPickedPoint* getPickedPoint(const SbVec2s& pos, const Gui::View3DInventorViewer* viewer) const; + SoPickedPoint* getPickedPoint(const SbVec2s& pos, + const Gui::View3DInventorViewer* viewer) const; ViewProviderMesh* mesh; std::vector index; int current_index; - SoCoordinate3 * pcCoords; - SoFaceSet * pcFaces; + SoCoordinate3* pcCoords; + SoFaceSet* pcFaces; SoFCMeshPickNode* pcMeshPick; }; @@ -75,7 +87,7 @@ public: * Display data of a mesh kernel. * \author Werner Mayer */ -class MeshGuiExport MeshFaceAddition : public QObject +class MeshGuiExport MeshFaceAddition: public QObject { Q_OBJECT @@ -96,7 +108,7 @@ private Q_SLOTS: private: bool addMarkerPoint(); void showMarker(SoPickedPoint*); - static void addFacetCallback(void * ud, SoEventCallback * n); + static void addFacetCallback(void* ud, SoEventCallback* n); private: ViewProviderFace* faceView; @@ -109,10 +121,12 @@ public: virtual ~MeshHoleFiller() = default; MeshHoleFiller(const MeshHoleFiller&) = delete; MeshHoleFiller(MeshHoleFiller&&) = delete; - MeshHoleFiller& operator = (const MeshHoleFiller&) = delete; - MeshHoleFiller& operator = (MeshHoleFiller&&) = delete; - virtual bool fillHoles(Mesh::MeshObject&, const std::list >&, - Mesh::PointIndex, Mesh::PointIndex) + MeshHoleFiller& operator=(const MeshHoleFiller&) = delete; + MeshHoleFiller& operator=(MeshHoleFiller&&) = delete; + virtual bool fillHoles(Mesh::MeshObject&, + const std::list>&, + Mesh::PointIndex, + Mesh::PointIndex) { return false; } @@ -122,7 +136,7 @@ public: * Display data of a mesh kernel. * \author Werner Mayer */ -class MeshGuiExport MeshFillHole : public QObject +class MeshGuiExport MeshFillHole: public QObject { Q_OBJECT @@ -142,11 +156,13 @@ private: using TBoundary = std::vector; using Connection = boost::signals2::connection; - static void fileHoleCallback(void * ud, SoEventCallback * n); + static void fileHoleCallback(void* ud, SoEventCallback* n); void createPolygons(); SoNode* getPickedPolygon(const SoRayPickAction& action) const; - float findClosestPoint(const SbLine& ray, const TBoundary& polygon, - Mesh::PointIndex&, SbVec3f&) const; + float findClosestPoint(const SbLine& ray, + const TBoundary& polygon, + Mesh::PointIndex&, + SbVec3f&) const; void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop); private: @@ -165,8 +181,7 @@ private: Connection myConnection; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_MESHEDITOR_H - +#endif // MESHGUI_MESHEDITOR_H diff --git a/src/Mod/Mesh/Gui/MeshSelection.cpp b/src/Mod/Mesh/Gui/MeshSelection.cpp index eb464ffe2b..7368e3fd77 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.cpp +++ b/src/Mod/Mesh/Gui/MeshSelection.cpp @@ -22,15 +22,15 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include #endif #include @@ -44,10 +44,10 @@ #include #include #include -#include -#include #include +#include #include +#include #include "MeshSelection.h" #include "ViewProvider.h" @@ -60,19 +60,19 @@ using namespace MeshGui; #define CROSS_HOT_X 7 #define CROSS_HOT_Y 7 +// clang-format off unsigned char MeshSelection::cross_bitmap[] = { - 0xc0, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, - 0x40, 0x02, 0x40, 0x02, 0x7f, 0xfe, 0x01, 0x80, - 0x01, 0x80, 0x7f, 0xfe, 0x40, 0x02, 0x40, 0x02, - 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0xc0, 0x03 -}; + 0xc0, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, + 0x40, 0x02, 0x40, 0x02, 0x7f, 0xfe, 0x01, 0x80, + 0x01, 0x80, 0x7f, 0xfe, 0x40, 0x02, 0x40, 0x02, + 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0xc0, 0x03}; unsigned char MeshSelection::cross_mask_bitmap[] = { - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03, - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03 -}; + 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, + 0xc0, 0x03, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03, + 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03}; +// clang-format on MeshSelection::MeshSelection() { @@ -83,8 +83,9 @@ MeshSelection::~MeshSelection() { if (this->activeCB) { Gui::View3DInventorViewer* viewer = this->getViewer(); - if (viewer) + if (viewer) { stopInteractiveCallback(viewer); + } } } @@ -96,7 +97,7 @@ void MeshSelection::setEnabledViewerSelection(bool on) } } -void MeshSelection::setCallback(SoEventCallbackCB *cb) +void MeshSelection::setCallback(SoEventCallbackCB* cb) { selectionCB = cb; } @@ -120,8 +121,9 @@ std::vector MeshSelection::getObjects() const // get all objects of the active document else { App::Document* doc = App::GetApplication().getActiveDocument(); - if (doc) + if (doc) { objs = doc->getObjectsOfType(Mesh::Feature::getClassTypeId()); + } } return objs; @@ -134,8 +136,9 @@ std::list MeshSelection::getViewProviders() const for (auto obj : objs) { if (obj->isDerivedFrom(Mesh::Feature::getClassTypeId())) { Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj); - if (vp->isVisible()) + if (vp->isVisible()) { vps.push_back(static_cast(vp)); + } } } @@ -150,12 +153,14 @@ void MeshSelection::setViewer(Gui::View3DInventorViewer* v) Gui::View3DInventorViewer* MeshSelection::getViewer() const { // if a special viewer was set from outside then use this - if (ivViewer) + if (ivViewer) { return ivViewer; + } Gui::Document* doc = Gui::Application::Instance->activeDocument(); - if (!doc) + if (!doc) { return nullptr; + } Gui::MDIView* view = doc->getActiveView(); if (view && view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { Gui::View3DInventorViewer* viewer = static_cast(view)->getViewer(); @@ -165,10 +170,12 @@ Gui::View3DInventorViewer* MeshSelection::getViewer() const return nullptr; } -void MeshSelection::startInteractiveCallback(Gui::View3DInventorViewer* viewer,SoEventCallbackCB *cb) +void MeshSelection::startInteractiveCallback(Gui::View3DInventorViewer* viewer, + SoEventCallbackCB* cb) { - if (this->activeCB) + if (this->activeCB) { return; + } viewer->setEditing(true); viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), cb, this); this->activeCB = cb; @@ -176,14 +183,15 @@ void MeshSelection::startInteractiveCallback(Gui::View3DInventorViewer* viewer,S void MeshSelection::stopInteractiveCallback(Gui::View3DInventorViewer* viewer) { - if (!this->activeCB) + if (!this->activeCB) { return; + } viewer->setEditing(false); viewer->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), this->activeCB, this); this->activeCB = nullptr; } -void MeshSelection::prepareFreehandSelection(bool add,SoEventCallbackCB *cb) +void MeshSelection::prepareFreehandSelection(bool add, SoEventCallbackCB* cb) { // a rubberband to select a rectangle area of the meshes Gui::View3DInventorViewer* viewer = this->getViewer(); @@ -213,7 +221,9 @@ void MeshSelection::prepareFreehandSelection(bool add,SoEventCallbackCB *cb) viewer->setComponentCursor(custom); }; - QObject::connect(viewer, &Gui::View3DInventorViewer::devicePixelRatioChanged, setComponentCursor); + QObject::connect(viewer, + &Gui::View3DInventorViewer::devicePixelRatioChanged, + setComponentCursor); setComponentCursor(); this->addToSelection = add; } @@ -266,15 +276,16 @@ bool MeshSelection::deleteSelection() std::list views = getViewProviders(); for (auto view : views) { Mesh::Feature* mf = static_cast(view->getObject()); - unsigned long ct = MeshCore::MeshAlgorithm(mf->Mesh.getValue().getKernel()). - CountFacetFlag(MeshCore::MeshFacet::SELECTED); + unsigned long ct = MeshCore::MeshAlgorithm(mf->Mesh.getValue().getKernel()) + .CountFacetFlag(MeshCore::MeshFacet::SELECTED); if (ct > 0) { selected = true; break; } } - if (!selected) - return false; // nothing todo + if (!selected) { + return false; // nothing todo + } for (auto view : views) { view->deleteSelection(); @@ -350,14 +361,15 @@ void MeshSelection::selectComponent(int size) Mesh::Feature* mf = static_cast(view->getObject()); const Mesh::MeshObject* mo = mf->Mesh.getValuePtr(); - std::vector > segm; + std::vector> segm; MeshCore::MeshComponents comp(mo->getKernel()); - comp.SearchForComponents(MeshCore::MeshComponents::OverEdge,segm); + comp.SearchForComponents(MeshCore::MeshComponents::OverEdge, segm); std::vector faces; - for (const auto & jt : segm) { - if (jt.size() < (Mesh::FacetIndex)size) + for (const auto& jt : segm) { + if (jt.size() < (Mesh::FacetIndex)size) { faces.insert(faces.end(), jt.begin(), jt.end()); + } } view->addSelection(faces); @@ -371,14 +383,15 @@ void MeshSelection::deselectComponent(int size) Mesh::Feature* mf = static_cast(view->getObject()); const Mesh::MeshObject* mo = mf->Mesh.getValuePtr(); - std::vector > segm; + std::vector> segm; MeshCore::MeshComponents comp(mo->getKernel()); - comp.SearchForComponents(MeshCore::MeshComponents::OverEdge,segm); + comp.SearchForComponents(MeshCore::MeshComponents::OverEdge, segm); std::vector faces; - for (const auto & jt : segm) { - if (jt.size() > (Mesh::FacetIndex)size) + for (const auto& jt : segm) { + if (jt.size() > (Mesh::FacetIndex)size) { faces.insert(faces.end(), jt.begin(), jt.end()); + } } view->removeSelection(faces); @@ -441,27 +454,30 @@ void MeshSelection::setRemoveComponentOnClick(bool on) removeComponent = on; } -void MeshSelection::selectGLCallback(void * ud, SoEventCallback * n) +void MeshSelection::selectGLCallback(void* ud, SoEventCallback* n) { // When this callback function is invoked we must leave the edit mode - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); MeshSelection* self = static_cast(ud); self->stopInteractiveCallback(view); n->setHandled(); std::vector polygon = view->getGLPolygon(); - if (polygon.size() < 3) + if (polygon.size() < 3) { return; - if (polygon.front() != polygon.back()) + } + if (polygon.front() != polygon.back()) { polygon.push_back(polygon.front()); + } SbVec3f pnt, dir; view->getNearPlane(pnt, dir); - Base::Vector3f normal(dir[0],dir[1],dir[2]); + Base::Vector3f normal(dir[0], dir[1], dir[2]); std::list views = self->getViewProviders(); for (auto vp : views) { std::vector faces; - const Mesh::MeshObject& mesh = static_cast(vp->getObject())->Mesh.getValue(); + const Mesh::MeshObject& mesh = + static_cast(vp->getObject())->Mesh.getValue(); const MeshCore::MeshKernel& kernel = mesh.getKernel(); // simply get all triangles under the polygon @@ -475,20 +491,24 @@ void MeshSelection::selectGLCallback(void * ud, SoEventCallback * n) if (self->onlyVisibleTriangles) { const SbVec2s& sz = view->getSoRenderManager()->getViewportRegion().getWindowSize(); - short width,height; sz.getValue(width,height); + short width, height; + sz.getValue(width, height); std::vector pixelPoly = view->getPolygon(); SbBox2s rect; - for (const auto & p : pixelPoly) { - rect.extendBy(SbVec2s(p[0],height-p[1])); + for (const auto& p : pixelPoly) { + rect.extendBy(SbVec2s(p[0], height - p[1])); } - std::vector rf; rf.swap(faces); - std::vector vf = vp->getVisibleFacetsAfterZoom - (rect, view->getSoRenderManager()->getViewportRegion(), view->getSoRenderManager()->getCamera()); + std::vector rf; + rf.swap(faces); + std::vector vf = + vp->getVisibleFacetsAfterZoom(rect, + view->getSoRenderManager()->getViewportRegion(), + view->getSoRenderManager()->getCamera()); // get common facets of the viewport and the visible one std::sort(vf.begin(), vf.end()); std::sort(rf.begin(), rf.end()); - std::back_insert_iterator > biit(faces); + std::back_insert_iterator> biit(faces); std::set_intersection(vf.begin(), vf.end(), rf.begin(), rf.end(), biit); } @@ -507,26 +527,30 @@ void MeshSelection::selectGLCallback(void * ud, SoEventCallback * n) faces.swap(screen); } - if (self->addToSelection) + if (self->addToSelection) { vp->addSelection(faces); - else + } + else { vp->removeSelection(faces); + } } view->redraw(); } -void MeshSelection::pickFaceCallback(void * ud, SoEventCallback * n) +void MeshSelection::pickFaceCallback(void* ud, SoEventCallback* n) { // handle only mouse button events if (n->getEvent()->isOfType(SoMouseButtonEvent::getClassTypeId())) { - const SoMouseButtonEvent * mbe = static_cast(n->getEvent()); - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + const SoMouseButtonEvent* mbe = static_cast(n->getEvent()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); - // Mark all incoming mouse button events as handled, especially, to deactivate the selection node + // Mark all incoming mouse button events as handled, especially, to deactivate the selection + // node n->getAction()->setHandled(); - if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { - const SoPickedPoint * point = n->getPickedPoint(); + if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 + && mbe->getState() == SoButtonEvent::DOWN) { + const SoPickedPoint* point = n->getPickedPoint(); if (!point) { Base::Console().Message("No facet picked.\n"); return; @@ -537,28 +561,34 @@ void MeshSelection::pickFaceCallback(void * ud, SoEventCallback * n) // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); - if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) + if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) { return; + } ViewProviderMesh* mesh = static_cast(vp); MeshSelection* self = static_cast(ud); std::list views = self->getViewProviders(); - if (std::find(views.begin(), views.end(), mesh) == views.end()) + if (std::find(views.begin(), views.end(), mesh) == views.end()) { return; + } const SoDetail* detail = point->getDetail(/*mesh->getShapeNode()*/); if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) { // get the boundary to the picked facet Mesh::FacetIndex uFacet = static_cast(detail)->getFaceIndex(); if (self->addToSelection) { - if (self->addComponent) + if (self->addComponent) { mesh->selectComponent(uFacet); - else + } + else { mesh->selectFacet(uFacet); + } } else { - if (self->removeComponent) + if (self->removeComponent) { mesh->deselectComponent(uFacet); - else + } + else { mesh->deselectFacet(uFacet); + } } } } diff --git a/src/Mod/Mesh/Gui/MeshSelection.h b/src/Mod/Mesh/Gui/MeshSelection.h index f4323fa4a9..a8703a4406 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.h +++ b/src/Mod/Mesh/Gui/MeshSelection.h @@ -23,21 +23,23 @@ #ifndef MESHGUI_MESHSELECTION_H #define MESHGUI_MESHSELECTION_H -#include #include +#include #include #include #ifndef MESH_GLOBAL_H -# include +#include #endif -namespace Gui { - class View3DInventorViewer; +namespace Gui +{ +class View3DInventorViewer; } -namespace MeshGui { +namespace MeshGui +{ class ViewProviderMesh; @@ -74,32 +76,32 @@ public: void setViewer(Gui::View3DInventorViewer* v); protected: - void setCallback(SoEventCallbackCB *cb); + void setCallback(SoEventCallbackCB* cb); std::list getViewProviders() const; Gui::View3DInventorViewer* getViewer() const; - void prepareFreehandSelection(bool,SoEventCallbackCB *cb); - void startInteractiveCallback(Gui::View3DInventorViewer* viewer,SoEventCallbackCB *cb); + void prepareFreehandSelection(bool, SoEventCallbackCB* cb); + void startInteractiveCallback(Gui::View3DInventorViewer* viewer, SoEventCallbackCB* cb); void stopInteractiveCallback(Gui::View3DInventorViewer* viewer); private: - static void selectGLCallback(void * ud, SoEventCallback * n); - static void pickFaceCallback(void * ud, SoEventCallback * n); + static void selectGLCallback(void* ud, SoEventCallback* n); + static void pickFaceCallback(void* ud, SoEventCallback* n); private: - bool onlyPointToUserTriangles{false}; - bool onlyVisibleTriangles{false}; - bool addToSelection{false}; - bool addComponent{false}; - bool removeComponent{false}; - SoEventCallbackCB *activeCB{nullptr}; - SoEventCallbackCB *selectionCB{nullptr}; - Gui::View3DInventorViewer* ivViewer{nullptr}; + bool onlyPointToUserTriangles {false}; + bool onlyVisibleTriangles {false}; + bool addToSelection {false}; + bool addComponent {false}; + bool removeComponent {false}; + SoEventCallbackCB* activeCB {nullptr}; + SoEventCallbackCB* selectionCB {nullptr}; + Gui::View3DInventorViewer* ivViewer {nullptr}; mutable std::vector meshObjects; static unsigned char cross_bitmap[]; static unsigned char cross_mask_bitmap[]; }; -} +} // namespace MeshGui -#endif // MESHGUI_MESHSELECTION_H +#endif // MESHGUI_MESHSELECTION_H diff --git a/src/Mod/Mesh/Gui/PreCompiled.h b/src/Mod/Mesh/Gui/PreCompiled.h index fafdf068b9..e492cbd9aa 100644 --- a/src/Mod/Mesh/Gui/PreCompiled.h +++ b/src/Mod/Mesh/Gui/PreCompiled.h @@ -27,19 +27,19 @@ // point at which warnings of overly long specifiers disabled (needed for VC6) #ifdef _MSC_VER -# pragma warning( disable : 4005 ) -# pragma warning( disable : 4251 ) -# pragma warning( disable : 4503 ) -# pragma warning( disable : 4275 ) -# pragma warning( disable : 4273 ) -# pragma warning( disable : 4786 ) // specifier longer then 255 chars +#pragma warning(disable : 4005) +#pragma warning(disable : 4251) +#pragma warning(disable : 4503) +#pragma warning(disable : 4275) +#pragma warning(disable : 4273) +#pragma warning(disable : 4786) // specifier longer then 255 chars #endif #ifdef _PreComp_ // Gts #ifdef FC_USE_GTS -# include +#include #endif // standard @@ -56,19 +56,19 @@ // Qt Toolkit #ifndef __QtAll__ -# include +#include #endif // Inventor #ifndef __InventorAll__ -# include +#include #endif #elif defined(FC_OS_WIN32) #ifndef NOMINMAX -# define NOMINMAX +#define NOMINMAX #endif #include #endif //_PreComp_ -#endif // MESHGUI_PRECOMPILED_H +#endif // MESHGUI_PRECOMPILED_H diff --git a/src/Mod/Mesh/Gui/PropertyEditorMesh.cpp b/src/Mod/Mesh/Gui/PropertyEditorMesh.cpp index 2e54997a6f..11dffcf3f1 100644 --- a/src/Mod/Mesh/Gui/PropertyEditorMesh.cpp +++ b/src/Mod/Mesh/Gui/PropertyEditorMesh.cpp @@ -35,18 +35,18 @@ PROPERTYITEM_SOURCE(MeshGui::PropertyMeshKernelItem) PropertyMeshKernelItem::PropertyMeshKernelItem() { - m_p = static_cast - (Gui::PropertyEditor::PropertyIntegerItem::create()); + m_p = static_cast( + Gui::PropertyEditor::PropertyIntegerItem::create()); m_p->setParent(this); m_p->setPropertyName(QLatin1String("Points")); this->appendChild(m_p); - m_e = static_cast - (Gui::PropertyEditor::PropertyIntegerItem::create()); + m_e = static_cast( + Gui::PropertyEditor::PropertyIntegerItem::create()); m_e->setParent(this); m_e->setPropertyName(QLatin1String("Edges")); this->appendChild(m_e); - m_f = static_cast - (Gui::PropertyEditor::PropertyIntegerItem::create()); + m_f = static_cast( + Gui::PropertyEditor::PropertyIntegerItem::create()); m_f->setParent(this); m_f->setPropertyName(QLatin1String("Faces")); this->appendChild(m_f); @@ -72,7 +72,7 @@ QVariant PropertyMeshKernelItem::value(const App::Property*) const ctF += (int)rMesh.CountFacets(); } - QString str = QObject::tr("[Points: %1, Edges: %2, Faces: %3]").arg(ctP).arg(ctE).arg(ctF); + QString str = QObject::tr("[Points: %1, Edges: %2, Faces: %3]").arg(ctP).arg(ctE).arg(ctF); return {str}; } @@ -86,7 +86,9 @@ void PropertyMeshKernelItem::setValue(const QVariant& value) Q_UNUSED(value); } -QWidget* PropertyMeshKernelItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const +QWidget* PropertyMeshKernelItem::createEditor(QWidget* parent, + const QObject* receiver, + const char* method) const { Q_UNUSED(parent); Q_UNUSED(receiver); @@ -94,13 +96,13 @@ QWidget* PropertyMeshKernelItem::createEditor(QWidget* parent, const QObject* re return nullptr; } -void PropertyMeshKernelItem::setEditorData(QWidget *editor, const QVariant& data) const +void PropertyMeshKernelItem::setEditorData(QWidget* editor, const QVariant& data) const { Q_UNUSED(editor); Q_UNUSED(data); } -QVariant PropertyMeshKernelItem::editorData(QWidget *editor) const +QVariant PropertyMeshKernelItem::editorData(QWidget* editor) const { Q_UNUSED(editor); return {}; diff --git a/src/Mod/Mesh/Gui/PropertyEditorMesh.h b/src/Mod/Mesh/Gui/PropertyEditorMesh.h index 694b42e19f..670272a3c8 100644 --- a/src/Mod/Mesh/Gui/PropertyEditorMesh.h +++ b/src/Mod/Mesh/Gui/PropertyEditorMesh.h @@ -25,17 +25,18 @@ #include #ifndef MESH_GLOBAL_H -# include +#include #endif -namespace MeshGui { +namespace MeshGui +{ /** * Display data of a mesh kernel. * \author Werner Mayer */ -class MeshGuiExport PropertyMeshKernelItem : public Gui::PropertyEditor::PropertyItem +class MeshGuiExport PropertyMeshKernelItem: public Gui::PropertyEditor::PropertyItem { Q_OBJECT Q_PROPERTY(int Points READ countPoints CONSTANT) @@ -43,9 +44,13 @@ class MeshGuiExport PropertyMeshKernelItem : public Gui::PropertyEditor::Propert Q_PROPERTY(int Faces READ countFaces CONSTANT) PROPERTYITEM_HEADER - QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const override; - void setEditorData(QWidget *editor, const QVariant& data) const override; - QVariant editorData(QWidget *editor) const override; + // clang-format off + QWidget* createEditor(QWidget* parent, + const QObject* receiver, + const char* method) const override; + // clang-format on + void setEditorData(QWidget* editor, const QVariant& data) const override; + QVariant editorData(QWidget* editor) const override; int countPoints() const; int countEdges() const; @@ -66,8 +71,7 @@ private: Gui::PropertyEditor::PropertyIntegerItem* m_f; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_PROPERTYEDITOR_MESH_H - +#endif // MESHGUI_PROPERTYEDITOR_MESH_H diff --git a/src/Mod/Mesh/Gui/RemeshGmsh.cpp b/src/Mod/Mesh/Gui/RemeshGmsh.cpp index f6b80871d6..7632035553 100644 --- a/src/Mod/Mesh/Gui/RemeshGmsh.cpp +++ b/src/Mod/Mesh/Gui/RemeshGmsh.cpp @@ -22,10 +22,10 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include +#include +#include +#include +#include #endif #include @@ -43,15 +43,17 @@ using namespace MeshGui; -class GmshWidget::Private { +class GmshWidget::Private +{ public: explicit Private(QWidget* parent) - : gmsh(parent) + : gmsh(parent) { /* coverity[uninit_ctor] Members of ui are set in setupUI() */ } - void appendText(const QString& text, bool error) { + void appendText(const QString& text, bool error) + { syntax->setParagraphType(error ? Gui::DockWnd::ReportHighlighter::Error : Gui::DockWnd::ReportHighlighter::Message); QTextCursor cursor(ui.outputWindow->document()); @@ -71,8 +73,8 @@ public: }; GmshWidget::GmshWidget(QWidget* parent, Qt::WindowFlags fl) - : QWidget(parent, fl) - , d(new Private(parent)) + : QWidget(parent, fl) + , d(new Private(parent)) { d->ui.setupUi(this); setupConnections(); @@ -82,7 +84,8 @@ GmshWidget::GmshWidget(QWidget* parent, Qt::WindowFlags fl) // 2D Meshing algorithms // https://gmsh.info/doc/texinfo/gmsh.html#index-Mesh_002eAlgorithm - enum { + enum + { MeshAdapt = 1, Automatic = 2, Delaunay = 5, @@ -108,6 +111,7 @@ GmshWidget::~GmshWidget() void GmshWidget::setupConnections() { + // clang-format off connect(&d->gmsh, &QProcess::started, this, &GmshWidget::started); connect(&d->gmsh, qOverload(&QProcess::finished), this, &GmshWidget::finished); @@ -121,9 +125,10 @@ void GmshWidget::setupConnections() this, &GmshWidget::onKillButtonClicked); connect(d->ui.clearButton, &QPushButton::clicked, this, &GmshWidget::onClearButtonClicked); + // clang-format on } -void GmshWidget::changeEvent(QEvent *e) +void GmshWidget::changeEvent(QEvent* e) { if (e->type() == QEvent::LanguageChange) { d->ui.retranslateUi(this); @@ -177,12 +182,8 @@ void GmshWidget::accept() // ./gmsh - -bin -2 /tmp/mesh.geo -o /tmp/best.stl QString proc = d->ui.fileChooser->fileName(); QStringList args; - args << QLatin1String("-") - << QLatin1String("-bin") - << QLatin1String("-2") - << inpFile - << QLatin1String("-o") - << outFile; + args << QLatin1String("-") << QLatin1String("-bin") << QLatin1String("-2") << inpFile + << QLatin1String("-o") << outFile; d->gmsh.start(proc, args); d->time.start(); @@ -239,10 +240,12 @@ void GmshWidget::started() void GmshWidget::finished(int /*exitCode*/, QProcess::ExitStatus exitStatus) { d->ui.killButton->setDisabled(true); - if (d->label) + if (d->label) { d->label->close(); + } - d->ui.labelTime->setText(QString::fromLatin1("%1 %2 ms").arg(tr("Time:")).arg(d->time.elapsed())); + d->ui.labelTime->setText( + QString::fromLatin1("%1 %2 ms").arg(tr("Time:")).arg(d->time.elapsed())); if (exitStatus == QProcess::NormalExit) { loadOutput(); } @@ -252,11 +255,11 @@ void GmshWidget::errorOccurred(QProcess::ProcessError error) { QString msg; switch (error) { - case QProcess::FailedToStart: - msg = tr("Failed to start"); - break; - default: - break; + case QProcess::FailedToStart: + msg = tr("Failed to start"); + break; + default: + break; } if (!msg.isEmpty()) { @@ -271,12 +274,12 @@ void GmshWidget::reject() // ------------------------------------------------- -class RemeshGmsh::Private { +class RemeshGmsh::Private +{ public: explicit Private(Mesh::Feature* mesh) - : mesh(mesh) - { - } + : mesh(mesh) + {} public: App::DocumentObjectWeakPtrT mesh; @@ -286,8 +289,8 @@ public: }; RemeshGmsh::RemeshGmsh(Mesh::Feature* mesh, QWidget* parent, Qt::WindowFlags fl) - : GmshWidget(parent, fl) - , d(new Private(mesh)) + : GmshWidget(parent, fl) + , d(new Private(mesh)) { // Copy mesh that is used each time when applying Gmsh's remeshing function d->copy = mesh->Mesh.getValue().getKernel(); @@ -299,6 +302,7 @@ RemeshGmsh::~RemeshGmsh() = default; bool RemeshGmsh::writeProject(QString& inpFile, QString& outFile) { + // clang-format off if (!d->mesh.expired()) { Base::FileInfo stl(d->stlFile); MeshCore::MeshOutput output(d->copy); @@ -358,12 +362,14 @@ bool RemeshGmsh::writeProject(QString& inpFile, QString& outFile) } return false; + // clang-format on } bool RemeshGmsh::loadOutput() { - if (d->mesh.expired()) + if (d->mesh.expired()) { return false; + } // Now read-in modified mesh Base::FileInfo stl(d->stlFile); @@ -394,8 +400,7 @@ bool RemeshGmsh::loadOutput() TaskRemeshGmsh::TaskRemeshGmsh(Mesh::Feature* mesh) { widget = new RemeshGmsh(mesh); - taskbox = new Gui::TaskView::TaskBox( - QPixmap(), widget->windowTitle(), false, nullptr); + taskbox = new Gui::TaskView::TaskBox(QPixmap(), widget->windowTitle(), false, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } diff --git a/src/Mod/Mesh/Gui/RemeshGmsh.h b/src/Mod/Mesh/Gui/RemeshGmsh.h index 6a7f6f725b..c00c7fc833 100644 --- a/src/Mod/Mesh/Gui/RemeshGmsh.h +++ b/src/Mod/Mesh/Gui/RemeshGmsh.h @@ -23,30 +23,33 @@ #ifndef MESHGUI_REMESHGMSH_H #define MESHGUI_REMESHGMSH_H -#include #include #include +#include #include #include #include -namespace Mesh { +namespace Mesh +{ class Feature; } -namespace Gui { +namespace Gui +{ class StatusWidget; } -namespace MeshGui { +namespace MeshGui +{ /** * Non-modal dialog to remesh an existing mesh. * @author Werner Mayer */ -class MeshGuiExport GmshWidget : public QWidget +class MeshGuiExport GmshWidget: public QWidget { Q_OBJECT @@ -57,7 +60,7 @@ public: void reject(); protected: - void changeEvent(QEvent *e) override; + void changeEvent(QEvent* e) override; int meshingAlgorithm() const; double getAngle() const; double getMaxSize() const; @@ -85,12 +88,14 @@ private: * Non-modal dialog to remesh an existing mesh. * @author Werner Mayer */ -class MeshGuiExport RemeshGmsh : public GmshWidget +class MeshGuiExport RemeshGmsh: public GmshWidget { Q_OBJECT public: - explicit RemeshGmsh(Mesh::Feature* mesh, QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags()); + explicit RemeshGmsh(Mesh::Feature* mesh, + QWidget* parent = nullptr, + Qt::WindowFlags fl = Qt::WindowFlags()); ~RemeshGmsh() override; protected: @@ -105,7 +110,7 @@ private: /** * Embed the panel into a task dialog. */ -class TaskRemeshGmsh : public Gui::TaskView::TaskDialog +class TaskRemeshGmsh: public Gui::TaskView::TaskDialog { Q_OBJECT @@ -116,15 +121,19 @@ public: void clicked(int) override; QDialogButtonBox::StandardButtons getStandardButtons() const override - { return QDialogButtonBox::Apply | QDialogButtonBox::Close; } + { + return QDialogButtonBox::Apply | QDialogButtonBox::Close; + } bool isAllowedAlterDocument() const override - { return true; } + { + return true; + } private: RemeshGmsh* widget; Gui::TaskView::TaskBox* taskbox; }; -} +} // namespace MeshGui -#endif // MESHGUI_REMESHGMSH_H +#endif // MESHGUI_REMESHGMSH_H diff --git a/src/Mod/Mesh/Gui/RemoveComponents.cpp b/src/Mod/Mesh/Gui/RemoveComponents.cpp index e39ab61cac..3857897640 100644 --- a/src/Mod/Mesh/Gui/RemoveComponents.cpp +++ b/src/Mod/Mesh/Gui/RemoveComponents.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -36,7 +36,7 @@ using namespace MeshGui; RemoveComponents::RemoveComponents(QWidget* parent, Qt::WindowFlags fl) - : QWidget(parent, fl) + : QWidget(parent, fl) { ui = new Ui_RemoveComponents; ui->setupUi(this); @@ -60,6 +60,7 @@ RemoveComponents::~RemoveComponents() void RemoveComponents::setupConnections() { + // clang-format off connect(ui->selectRegion, &QPushButton::clicked, this, &RemoveComponents::onSelectRegionClicked); connect(ui->selectAll, &QPushButton::clicked, @@ -84,9 +85,10 @@ void RemoveComponents::setupConnections() this, &RemoveComponents::onSelectCompToggled); connect(ui->cbDeselectComp, &QCheckBox::toggled, this, &RemoveComponents::onDeselectCompToggled); + // clang-format on } -void RemoveComponents::changeEvent(QEvent *e) +void RemoveComponents::changeEvent(QEvent* e) { if (e->type() == QEvent::LanguageChange) { ui->retranslateUi(this); @@ -153,15 +155,18 @@ void RemoveComponents::onDeselectCompToggled(bool on) void RemoveComponents::deleteSelection() { Gui::Document* doc = Gui::Application::Instance->activeDocument(); - if (!doc) + if (!doc) { return; + } // delete all selected faces doc->openCommand(QT_TRANSLATE_NOOP("Command", "Delete selection")); bool ok = meshSel.deleteSelection(); - if (!ok) + if (!ok) { doc->abortCommand(); - else + } + else { doc->commitCommand(); + } } void RemoveComponents::invertSelection() @@ -191,21 +196,19 @@ void RemoveComponents::reject() // ------------------------------------------------- RemoveComponentsDialog::RemoveComponentsDialog(QWidget* parent, Qt::WindowFlags fl) - : QDialog(parent, fl) + : QDialog(parent, fl) { widget = new RemoveComponents(this); this->setWindowTitle(widget->windowTitle()); QVBoxLayout* hboxLayout = new QVBoxLayout(this); QDialogButtonBox* buttonBox = new QDialogButtonBox(this); - buttonBox->setStandardButtons(QDialogButtonBox::Close|QDialogButtonBox::Ok); + buttonBox->setStandardButtons(QDialogButtonBox::Close | QDialogButtonBox::Ok); QPushButton* okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setText(MeshGui::TaskRemoveComponents::tr("Delete")); - buttonBox->addButton(MeshGui::TaskRemoveComponents::tr("Invert"), - QDialogButtonBox::ActionRole); + buttonBox->addButton(MeshGui::TaskRemoveComponents::tr("Invert"), QDialogButtonBox::ActionRole); - connect(buttonBox, &QDialogButtonBox::clicked, - this, &RemoveComponentsDialog::clicked); + connect(buttonBox, &QDialogButtonBox::clicked, this, &RemoveComponentsDialog::clicked); hboxLayout->addWidget(widget); hboxLayout->addWidget(buttonBox); @@ -241,8 +244,7 @@ void RemoveComponentsDialog::clicked(QAbstractButton* btn) TaskRemoveComponents::TaskRemoveComponents() { widget = new RemoveComponents(); - taskbox = new Gui::TaskView::TaskBox( - QPixmap(), widget->windowTitle(), false, nullptr); + taskbox = new Gui::TaskView::TaskBox(QPixmap(), widget->windowTitle(), false, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } diff --git a/src/Mod/Mesh/Gui/RemoveComponents.h b/src/Mod/Mesh/Gui/RemoveComponents.h index 8647c85cc9..f71c52ef31 100644 --- a/src/Mod/Mesh/Gui/RemoveComponents.h +++ b/src/Mod/Mesh/Gui/RemoveComponents.h @@ -24,13 +24,14 @@ #ifndef MESHGUI_REMOVECOMPONENTS_H #define MESHGUI_REMOVECOMPONENTS_H -#include +#include "MeshSelection.h" #include #include #include -#include "MeshSelection.h" +#include -namespace MeshGui { +namespace MeshGui +{ class Ui_RemoveComponents; /** @@ -38,7 +39,7 @@ class Ui_RemoveComponents; * of a mesh and delete them. * @author Werner Mayer */ -class MeshGuiExport RemoveComponents : public QWidget +class MeshGuiExport RemoveComponents: public QWidget { Q_OBJECT @@ -64,7 +65,7 @@ public: void onDeselectCompToggled(bool); protected: - void changeEvent(QEvent *e) override; + void changeEvent(QEvent* e) override; private: void setupConnections(); @@ -77,12 +78,13 @@ private: /** * Embed the panel into a dialog. */ -class MeshGuiExport RemoveComponentsDialog : public QDialog +class MeshGuiExport RemoveComponentsDialog: public QDialog { Q_OBJECT public: - explicit RemoveComponentsDialog(QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags()); + explicit RemoveComponentsDialog(QWidget* parent = nullptr, + Qt::WindowFlags fl = Qt::WindowFlags()); ~RemoveComponentsDialog() override; void reject() override; @@ -96,7 +98,7 @@ private: /** * Embed the panel into a task dialog. */ -class TaskRemoveComponents : public Gui::TaskView::TaskDialog +class TaskRemoveComponents: public Gui::TaskView::TaskDialog { Q_OBJECT @@ -108,9 +110,13 @@ public: void clicked(int) override; QDialogButtonBox::StandardButtons getStandardButtons() const override - { return QDialogButtonBox::Ok | QDialogButtonBox::Close; } + { + return QDialogButtonBox::Ok | QDialogButtonBox::Close; + } bool isAllowedAlterDocument() const override - { return true; } + { + return true; + } void modifyStandardButtons(QDialogButtonBox*) override; private: @@ -118,6 +124,6 @@ private: Gui::TaskView::TaskBox* taskbox; }; -} +} // namespace MeshGui -#endif // MESHGUI_REMOVECOMPONENTS_H +#endif // MESHGUI_REMOVECOMPONENTS_H diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_af.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_af.ts index f3c19db6bb..8527b40f36 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_af.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_af.ts @@ -1102,7 +1102,7 @@ Check failed due to folds on the surface. Please run the command to repair folds first - Kontrole het misluk weens voue op die oppervlak. + Kontrole het misluk weens voue op die oppervlak. Gee eers die opdrag om die voue te herstel diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_ca.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_ca.ts index 90e4d174b9..bf510bab2e 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_ca.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_ca.ts @@ -1489,7 +1489,7 @@ Amb un ombrejat pla, les normals de la superfície no es defineixen per vèrtex If face angle < crease angle, smooth shading is used L’angle de plec és un angle llindar entre dues cares. -Si l'angle de la cara ≥ l'angle de plec, s'utilitza l'ombrejat de facetes +Si l'angle de la cara ≥ l'angle de plec, s'utilitza l'ombrejat de facetes Si angle de la cara < l'angle de plec, s'utilitza un ombrejat suau diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_fi.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_fi.ts index 65dd87c838..d207914dec 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_fi.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_fi.ts @@ -1369,7 +1369,7 @@ This parameter indicates whether ZIP compression is used when writing a file in AMF format - Tämä parametri ilmaisee, on ZIP pakkaaminen + Tämä parametri ilmaisee, on ZIP pakkaaminen käytössä kirjoitettaessa tiedostoa AMF muodossa @@ -1428,7 +1428,7 @@ If not checked, it depends on the option "Enable backlight color" will be used or black. Pinnan alareuna on renderöity samalla tavalla kuin yläpuolella. Jos ei ole valittuna, se riippuu vaihtoehdosta "Ota taustavalo väri käyttöön" -(asetruksien osiossa Näyttö -> 3D Näkymä). Joko taustavalon väriä +(asetruksien osiossa Näyttö -> 3D Näkymä). Joko taustavalon väriä käytetään tai se on musta. @@ -2083,7 +2083,7 @@ sileämpään ulkonäköön. OpenSCAD cannot be found on your system. Please visit http://www.openscad.org/index.html to install it. - OpenSCAD:ia ei löydy järjestelmästäsi. Käy + OpenSCAD:ia ei löydy järjestelmästäsi. Käy http://www.openscad.org/index.html asentaaksesi sen. diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_hr.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_hr.ts index 4aeebcb54b..59f71d5591 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_hr.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_hr.ts @@ -1427,7 +1427,7 @@ If not checked, it depends on the option "Enable backlight color" will be used or black. Donja strana površine bit će prikazana na isti način kao gornja strana. Ako nije potvrđeno, ovisi o opciji "Omogući boju pozadinskog osvjetljenja" -(odjeljak postavki prikaza -> 3D prikaz). Koristit će se boja pozadinskog +(odjeljak postavki prikaza -> 3D prikaz). Koristit će se boja pozadinskog osvjetljenja ili crno. @@ -2084,7 +2084,7 @@ vodi do uglađenijeg izgleda. OpenSCAD cannot be found on your system. Please visit http://www.openscad.org/index.html to install it. - OpenSCAD nije moguće pronaći na vašem sustavu. + OpenSCAD nije moguće pronaći na vašem sustavu. Posjetite http://www.openscad.org/index.html da biste ga instalirali. diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_ka.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_ka.ts index 6b4c14f2d5..51ab40647e 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_ka.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_ka.ts @@ -1369,7 +1369,7 @@ This parameter indicates whether ZIP compression is used when writing a file in AMF format - ეს პარამეტრი განსაზღვრავს ჩართულია თუ არა + ეს პარამეტრი განსაზღვრავს ჩართულია თუ არა ZIP კომპრესია AMF ფაილის ფორმატის ჩაწერის დროს diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_nl.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_nl.ts index fb087110de..a3096f30eb 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_nl.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_nl.ts @@ -1464,7 +1464,7 @@ to a smoother appearance. Als deze optie is ingesteld, wordt de Phong-beschaduwing gebruikt, anders vlakke schaduwen. De beschaduwing bepaalt het uiterlijk van de oppervlakken. -Bij vlakke beschaduwingen worden de oppervlaktenormen niet per eindpunt gedefinieerd, wat leidt +Bij vlakke beschaduwingen worden de oppervlaktenormen niet per eindpunt gedefinieerd, wat leidt tot een onrealistisch uiterlijk voor gebogen oppervlakken, terwijl het gebruik van Phong-beschaduwing tot een gladder uiterlijk leidt. diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_pl.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_pl.ts index e3f837026a..69ce210e9b 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_pl.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_pl.ts @@ -2083,7 +2083,7 @@ do gładszego wyglądu. OpenSCAD cannot be found on your system. Please visit http://www.openscad.org/index.html to install it. - OpenSCAD nie został odnaleziony w Twoim systemie. + OpenSCAD nie został odnaleziony w Twoim systemie. Odwiedź http://www.openscad.org/index.html żeby go zainstalować. diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_sr-CS.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_sr-CS.ts index a777ea268b..f0536595f9 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_sr-CS.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_sr-CS.ts @@ -1428,7 +1428,7 @@ If not checked, it depends on the option "Enable backlight color" will be used or black. Donja strana površine će biti prikazana na isti način kao gornja strana. Ako nije čekirano, zavisi od opcije „Omogući boju pozadinskog osvetljenja“ -(Podešavanja -> Prikaz -> 3D prikaz). Ili će se koristiti boja pozadinskog +(Podešavanja -> Prikaz -> 3D prikaz). Ili će se koristiti boja pozadinskog osvetljenja ili crna boja. diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_sr.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_sr.ts index 158505669f..dc612350a1 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_sr.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_sr.ts @@ -1428,7 +1428,7 @@ If not checked, it depends on the option "Enable backlight color" will be used or black. Доња страна површине ће бити приказана на исти начин као горња страна. Ако није чекирано, зависи од опције „Омогући боју позадинског осветљења“ -(Подешавања -> Приказ -> 3Д приказ). Или ће се користити боја позадинског +(Подешавања -> Приказ -> 3Д приказ). Или ће се користити боја позадинског осветљења или црна боја. diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_uk.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_uk.ts index 0a32be1c8e..b42347e297 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_uk.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_uk.ts @@ -1464,7 +1464,7 @@ to a smoother appearance. Затінення визначає зовнішній вигляд поверхонь. При плоскому затіненні поверхневих стандартів не визначаються для кожної вершини, що веде -до уявного вигляду для криволінійних поверхонь під час використання відтінків Phong +до уявного вигляду для криволінійних поверхонь під час використання відтінків Phong до більш гладкого вигляду. diff --git a/src/Mod/Mesh/Gui/Resources/translations/Mesh_val-ES.ts b/src/Mod/Mesh/Gui/Resources/translations/Mesh_val-ES.ts index b161f63872..cb9256b114 100644 --- a/src/Mod/Mesh/Gui/Resources/translations/Mesh_val-ES.ts +++ b/src/Mod/Mesh/Gui/Resources/translations/Mesh_val-ES.ts @@ -1489,7 +1489,7 @@ Amb un ombrejat pla, les normals de la superfície no es defineixen per vèrtex If face angle < crease angle, smooth shading is used L’angle de plec és un angle llindar entre dues cares. -Si l'angle de la cara ≥ l'angle de plec, s'utilitza l'ombrejat de facetes +Si l'angle de la cara ≥ l'angle de plec, s'utilitza l'ombrejat de facetes Si angle de la cara < l'angle de plec, s'utilitza un ombrejat suau diff --git a/src/Mod/Mesh/Gui/Segmentation.cpp b/src/Mod/Mesh/Gui/Segmentation.cpp index 1e2bc7edcf..434a294f53 100644 --- a/src/Mod/Mesh/Gui/Segmentation.cpp +++ b/src/Mod/Mesh/Gui/Segmentation.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -40,7 +40,8 @@ using namespace MeshGui; Segmentation::Segmentation(Mesh::Feature* mesh, QWidget* parent, Qt::WindowFlags fl) - : QWidget(parent, fl), myMesh(mesh) + : QWidget(parent, fl) + , myMesh(mesh) { ui = new Ui_Segmentation; ui->setupUi(this); @@ -83,22 +84,34 @@ void Segmentation::accept() std::vector segm; if (ui->groupBoxFree->isChecked()) { - segm.emplace_back(std::make_shared - (meshCurv.GetCurvature(), ui->numFree->value(), - ui->tol1Free->value(), ui->tol2Free->value(), - ui->crv1Free->value(), ui->crv2Free->value())); + segm.emplace_back( + std::make_shared(meshCurv.GetCurvature(), + ui->numFree->value(), + ui->tol1Free->value(), + ui->tol2Free->value(), + ui->crv1Free->value(), + ui->crv2Free->value())); } if (ui->groupBoxCyl->isChecked()) { - segm.emplace_back(std::make_shared - (meshCurv.GetCurvature(), ui->numCyl->value(), ui->tol1Cyl->value(), ui->tol2Cyl->value(), ui->crvCyl->value())); + segm.emplace_back( + std::make_shared(meshCurv.GetCurvature(), + ui->numCyl->value(), + ui->tol1Cyl->value(), + ui->tol2Cyl->value(), + ui->crvCyl->value())); } if (ui->groupBoxSph->isChecked()) { - segm.emplace_back(std::make_shared - (meshCurv.GetCurvature(), ui->numSph->value(), ui->tolSph->value(), ui->crvSph->value())); + segm.emplace_back( + std::make_shared(meshCurv.GetCurvature(), + ui->numSph->value(), + ui->tolSph->value(), + ui->crvSph->value())); } if (ui->groupBoxPln->isChecked()) { - segm.emplace_back(std::make_shared - (meshCurv.GetCurvature(), ui->numPln->value(), ui->tolPln->value())); + segm.emplace_back( + std::make_shared(meshCurv.GetCurvature(), + ui->numPln->value(), + ui->tolPln->value())); } finder.FindSegments(segm); @@ -107,16 +120,17 @@ void Segmentation::accept() std::string internalname = "Segments_"; internalname += myMesh->getNameInDocument(); - App::DocumentObjectGroup* group = static_cast(document->addObject - ("App::DocumentObjectGroup", internalname.c_str())); + App::DocumentObjectGroup* group = static_cast( + document->addObject("App::DocumentObjectGroup", internalname.c_str())); std::string labelname = "Segments "; labelname += myMesh->Label.getValue(); group->Label.setValue(labelname); - for (const auto & it : segm) { + for (const auto& it : segm) { const std::vector& data = it->GetSegments(); - for (const auto & jt : data) { + for (const auto& jt : data) { Mesh::MeshObject* segment = mesh->meshFromSegment(jt); - Mesh::Feature* feaSegm = static_cast(group->addObject("Mesh::Feature", "Segment")); + Mesh::Feature* feaSegm = + static_cast(group->addObject("Mesh::Feature", "Segment")); Mesh::MeshObject* feaMesh = feaSegm->Mesh.startEditing(); feaMesh->swap(*segment); feaSegm->Mesh.finishEditing(); @@ -130,7 +144,7 @@ void Segmentation::accept() document->commitTransaction(); } -void Segmentation::changeEvent(QEvent *e) +void Segmentation::changeEvent(QEvent* e) { if (e->type() == QEvent::LanguageChange) { ui->retranslateUi(this); @@ -145,8 +159,7 @@ void Segmentation::changeEvent(QEvent *e) TaskSegmentation::TaskSegmentation(Mesh::Feature* mesh) { widget = new Segmentation(mesh); - taskbox = new Gui::TaskView::TaskBox( - QPixmap(), widget->windowTitle(), false, nullptr); + taskbox = new Gui::TaskView::TaskBox(QPixmap(), widget->windowTitle(), false, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } diff --git a/src/Mod/Mesh/Gui/Segmentation.h b/src/Mod/Mesh/Gui/Segmentation.h index 4ea53397b7..17c3c5235d 100644 --- a/src/Mod/Mesh/Gui/Segmentation.h +++ b/src/Mod/Mesh/Gui/Segmentation.h @@ -28,25 +28,31 @@ #include #include #ifndef MESH_GLOBAL_H -# include +#include #endif // forward declarations -namespace Mesh { class Feature; } +namespace Mesh +{ +class Feature; +} -namespace MeshGui { +namespace MeshGui +{ class Ui_Segmentation; -class MeshGuiExport Segmentation : public QWidget +class MeshGuiExport Segmentation: public QWidget { public: - explicit Segmentation(Mesh::Feature* mesh, QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags()); + explicit Segmentation(Mesh::Feature* mesh, + QWidget* parent = nullptr, + Qt::WindowFlags fl = Qt::WindowFlags()); ~Segmentation() override; void accept(); protected: - void changeEvent(QEvent *e) override; + void changeEvent(QEvent* e) override; private: Ui_Segmentation* ui; @@ -56,7 +62,7 @@ private: /** * Embed the panel into a task dialog. */ -class TaskSegmentation : public Gui::TaskView::TaskDialog +class TaskSegmentation: public Gui::TaskView::TaskDialog { public: explicit TaskSegmentation(Mesh::Feature* mesh); @@ -65,13 +71,15 @@ public: bool accept() override; QDialogButtonBox::StandardButtons getStandardButtons() const override - { return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; } + { + return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; + } private: Segmentation* widget; Gui::TaskView::TaskBox* taskbox; }; -} +} // namespace MeshGui -#endif // MESHGUI_SEGMENTATION_H +#endif // MESHGUI_SEGMENTATION_H diff --git a/src/Mod/Mesh/Gui/SegmentationBestFit.cpp b/src/Mod/Mesh/Gui/SegmentationBestFit.cpp index a1a3efe8d3..c7c8acc9a1 100644 --- a/src/Mod/Mesh/Gui/SegmentationBestFit.cpp +++ b/src/Mod/Mesh/Gui/SegmentationBestFit.cpp @@ -22,13 +22,13 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include #endif #include @@ -46,13 +46,15 @@ using namespace MeshGui; -namespace MeshGui { -class PlaneFitParameter : public FitParameter +namespace MeshGui +{ +class PlaneFitParameter: public FitParameter { public: PlaneFitParameter() = default; ~PlaneFitParameter() override = default; - std::vector getParameter(FitParameter::Points pts) const override { + std::vector getParameter(FitParameter::Points pts) const override + { std::vector values; MeshCore::PlaneFit fit; fit.AddPoints(pts.points); @@ -70,12 +72,13 @@ public: } }; -class CylinderFitParameter : public FitParameter +class CylinderFitParameter: public FitParameter { public: CylinderFitParameter() = default; ~CylinderFitParameter() override = default; - std::vector getParameter(FitParameter::Points pts) const override { + std::vector getParameter(FitParameter::Points pts) const override + { std::vector values; MeshCore::CylinderFit fit; fit.AddPoints(pts.points); @@ -106,16 +109,26 @@ public: // Only for testing purposes try { float height = Base::Distance(base, top); - Gui::Command::doCommand(Gui::Command::App, - "cyl = App.ActiveDocument.addObject('Part::Cylinder', 'Cylinder')\n" - "cyl.Radius = %f\n" - "cyl.Height = %f\n" - "cyl.Placement = App.Placement(App.Vector(%f,%f,%f), App.Rotation(App.Vector(0,0,1), App.Vector(%f,%f,%f)))\n", - radius, height, base.x, base.y, base.z, axis.x, axis.y, axis.z); + Gui::Command::doCommand( + Gui::Command::App, + "cyl = App.ActiveDocument.addObject('Part::Cylinder', 'Cylinder')\n" + "cyl.Radius = %f\n" + "cyl.Height = %f\n" + "cyl.Placement = App.Placement(App.Vector(%f,%f,%f), " + "App.Rotation(App.Vector(0,0,1), App.Vector(%f,%f,%f)))\n", + radius, + height, + base.x, + base.y, + base.z, + axis.x, + axis.y, + axis.z); - Gui::Command::doCommand(Gui::Command::App, - "axis = cyl.Placement.Rotation.multVec(App.Vector(0,0,1))\n" - "print('Final axis: ({}, {}, {})'.format(axis.x, axis.y, axis.z))\n"); + Gui::Command::doCommand( + Gui::Command::App, + "axis = cyl.Placement.Rotation.multVec(App.Vector(0,0,1))\n" + "print('Final axis: ({}, {}, {})'.format(axis.x, axis.y, axis.z))\n"); } catch (...) { } @@ -125,12 +138,13 @@ public: } }; -class SphereFitParameter : public FitParameter +class SphereFitParameter: public FitParameter { public: SphereFitParameter() = default; ~SphereFitParameter() override = default; - std::vector getParameter(FitParameter::Points pts) const override { + std::vector getParameter(FitParameter::Points pts) const override + { std::vector values; MeshCore::SphereFit fit; fit.AddPoints(pts.points); @@ -145,10 +159,12 @@ public: return values; } }; -} +} // namespace MeshGui -ParametersDialog::ParametersDialog(std::vector& val, FitParameter* fitPar, - ParameterList par, Mesh::Feature* mesh, +ParametersDialog::ParametersDialog(std::vector& val, + FitParameter* fitPar, + ParameterList par, + Mesh::Feature* mesh, QWidget* parent) : QDialog(parent) , values(val) @@ -158,54 +174,54 @@ ParametersDialog::ParametersDialog(std::vector& val, FitParameter* fitPar { this->setWindowTitle(tr("Surface fit")); - QGridLayout *gridLayout; + QGridLayout* gridLayout; gridLayout = new QGridLayout(this); - QGroupBox *groupBox; + QGroupBox* groupBox; groupBox = new QGroupBox(this); groupBox->setTitle(tr("Parameters")); gridLayout->addWidget(groupBox, 0, 0, 1, 1); - QGroupBox *selectBox; + QGroupBox* selectBox; selectBox = new QGroupBox(this); selectBox->setTitle(tr("Selection")); gridLayout->addWidget(selectBox, 1, 0, 1, 1); - QVBoxLayout *selectLayout; + QVBoxLayout* selectLayout; selectLayout = new QVBoxLayout(selectBox); - QPushButton *regionButton; + QPushButton* regionButton; regionButton = new QPushButton(this); regionButton->setText(tr("Region")); regionButton->setObjectName(QString::fromLatin1("region")); selectLayout->addWidget(regionButton); - QPushButton *singleButton; + QPushButton* singleButton; singleButton = new QPushButton(this); singleButton->setText(tr("Triangle")); singleButton->setObjectName(QString::fromLatin1("single")); selectLayout->addWidget(singleButton); - QPushButton *clearButton; + QPushButton* clearButton; clearButton = new QPushButton(this); clearButton->setText(tr("Clear")); clearButton->setObjectName(QString::fromLatin1("clear")); selectLayout->addWidget(clearButton); - QPushButton *computeButton; + QPushButton* computeButton; computeButton = new QPushButton(this); computeButton->setText(tr("Compute")); computeButton->setObjectName(QString::fromLatin1("compute")); gridLayout->addWidget(computeButton, 2, 0, 1, 1); - QDialogButtonBox *buttonBox; + QDialogButtonBox* buttonBox; buttonBox = new QDialogButtonBox(this); buttonBox->setOrientation(Qt::Horizontal); - buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); gridLayout->addWidget(buttonBox, 3, 0, 1, 1); int index = 0; - QGridLayout *layout; + QGridLayout* layout; layout = new QGridLayout(groupBox); for (const auto& it : parameter) { QLabel* label = new QLabel(groupBox); @@ -221,12 +237,14 @@ ParametersDialog::ParametersDialog(std::vector& val, FitParameter* fitPar ++index; } + // clang-format off connect(buttonBox, &QDialogButtonBox::accepted, this, &ParametersDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &ParametersDialog::reject); connect(regionButton, &QPushButton::clicked, this, &ParametersDialog::onRegionClicked); connect(singleButton, &QPushButton::clicked, this, &ParametersDialog::onSingleClicked); connect(clearButton, &QPushButton::clicked, this, &ParametersDialog::onClearClicked); connect(computeButton, &QPushButton::clicked, this, &ParametersDialog::onComputeClicked); + // clang-format on Gui::SelectionObject obj(mesh); std::vector sel; @@ -277,7 +295,7 @@ void ParametersDialog::onComputeClicked() values = fitParameter->getParameter(fitpts); if (values.size() == spinBoxes.size()) { - for (std::size_t i=0; isetValue(values[i]); } } @@ -285,15 +303,18 @@ void ParametersDialog::onComputeClicked() meshSel.clearSelection(); } else { - QMessageBox::warning(this, tr("No selection"), tr("Before fitting the surface select an area.")); + QMessageBox::warning(this, + tr("No selection"), + tr("Before fitting the surface select an area.")); } } void ParametersDialog::accept() { std::vector v; - for (auto it : spinBoxes) + for (auto it : spinBoxes) { v.push_back(it->value()); + } values = v; QDialog::accept(); } @@ -309,7 +330,8 @@ void ParametersDialog::reject() /* TRANSLATOR MeshGui::SegmentationBestFit */ SegmentationBestFit::SegmentationBestFit(Mesh::Feature* mesh, QWidget* parent, Qt::WindowFlags fl) - : QWidget(parent, fl), myMesh(mesh) + : QWidget(parent, fl) + , myMesh(mesh) { ui = new Ui_SegmentationBestFit; ui->setupUi(this); @@ -336,12 +358,14 @@ SegmentationBestFit::~SegmentationBestFit() void SegmentationBestFit::setupConnections() { + // clang-format off connect(ui->planeParameters, &QPushButton::clicked, this, &SegmentationBestFit::onPlaneParametersClicked); connect(ui->cylinderParameters, &QPushButton::clicked, this, &SegmentationBestFit::onCylinderParametersClicked); connect(ui->sphereParameters, &QPushButton::clicked, this, &SegmentationBestFit::onSphereParametersClicked); + // clang-format on } void SegmentationBestFit::onPlaneParametersClicked() @@ -362,10 +386,9 @@ void SegmentationBestFit::onPlaneParametersClicked() list.push_back(std::make_pair(axis + z, p[5])); static QPointer dialog = nullptr; - if (!dialog) - dialog = new ParametersDialog(planeParameter, - new PlaneFitParameter, - list, myMesh, this); + if (!dialog) { + dialog = new ParametersDialog(planeParameter, new PlaneFitParameter, list, myMesh, this); + } dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } @@ -387,13 +410,13 @@ void SegmentationBestFit::onCylinderParametersClicked() list.push_back(std::make_pair(axis + x, p[3])); list.push_back(std::make_pair(axis + y, p[4])); list.push_back(std::make_pair(axis + z, p[5])); - list.push_back(std::make_pair(radius, p[6])); + list.push_back(std::make_pair(radius, p[6])); static QPointer dialog = nullptr; - if (!dialog) - dialog = new ParametersDialog(cylinderParameter, - new CylinderFitParameter, - list, myMesh, this); + if (!dialog) { + dialog = + new ParametersDialog(cylinderParameter, new CylinderFitParameter, list, myMesh, this); + } dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } @@ -411,13 +434,12 @@ void SegmentationBestFit::onSphereParametersClicked() list.push_back(std::make_pair(base + x, p[0])); list.push_back(std::make_pair(base + y, p[1])); list.push_back(std::make_pair(base + z, p[2])); - list.push_back(std::make_pair(radius, p[3])); + list.push_back(std::make_pair(radius, p[3])); static QPointer dialog = nullptr; - if (!dialog) - dialog = new ParametersDialog(sphereParameter, - new SphereFitParameter, - list, myMesh, this); + if (!dialog) { + dialog = new ParametersDialog(sphereParameter, new SphereFitParameter, list, myMesh, this); + } dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } @@ -434,44 +456,49 @@ void SegmentationBestFit::accept() MeshCore::AbstractSurfaceFit* fitter; if (cylinderParameter.size() == 7) { std::vector& p = cylinderParameter; - fitter = new MeshCore::CylinderSurfaceFit( - Base::Vector3f(p[0],p[1],p[2]), - Base::Vector3f(p[3],p[4],p[5]), - p[6]); + fitter = new MeshCore::CylinderSurfaceFit(Base::Vector3f(p[0], p[1], p[2]), + Base::Vector3f(p[3], p[4], p[5]), + p[6]); } else { fitter = new MeshCore::CylinderSurfaceFit; } - segm.emplace_back(std::make_shared - (fitter, kernel, ui->numCyl->value(), ui->tolCyl->value())); + segm.emplace_back( + std::make_shared(fitter, + kernel, + ui->numCyl->value(), + ui->tolCyl->value())); } if (ui->groupBoxSph->isChecked()) { MeshCore::AbstractSurfaceFit* fitter; if (sphereParameter.size() == 4) { std::vector& p = sphereParameter; - fitter = new MeshCore::SphereSurfaceFit( - Base::Vector3f(p[0],p[1],p[2]), - p[3]); + fitter = new MeshCore::SphereSurfaceFit(Base::Vector3f(p[0], p[1], p[2]), p[3]); } else { fitter = new MeshCore::SphereSurfaceFit; } - segm.emplace_back(std::make_shared - (fitter, kernel, ui->numSph->value(), ui->tolSph->value())); + segm.emplace_back( + std::make_shared(fitter, + kernel, + ui->numSph->value(), + ui->tolSph->value())); } if (ui->groupBoxPln->isChecked()) { MeshCore::AbstractSurfaceFit* fitter; if (planeParameter.size() == 6) { std::vector& p = planeParameter; - fitter = new MeshCore::PlaneSurfaceFit( - Base::Vector3f(p[0],p[1],p[2]), - Base::Vector3f(p[3],p[4],p[5])); + fitter = new MeshCore::PlaneSurfaceFit(Base::Vector3f(p[0], p[1], p[2]), + Base::Vector3f(p[3], p[4], p[5])); } else { fitter = new MeshCore::PlaneSurfaceFit; } - segm.emplace_back(std::make_shared - (fitter, kernel, ui->numPln->value(), ui->tolPln->value())); + segm.emplace_back( + std::make_shared(fitter, + kernel, + ui->numPln->value(), + ui->tolPln->value())); } finder.FindSegments(segm); @@ -480,16 +507,17 @@ void SegmentationBestFit::accept() std::string internalname = "Segments_"; internalname += myMesh->getNameInDocument(); - App::DocumentObjectGroup* group = static_cast(document->addObject - ("App::DocumentObjectGroup", internalname.c_str())); + App::DocumentObjectGroup* group = static_cast( + document->addObject("App::DocumentObjectGroup", internalname.c_str())); std::string labelname = "Segments "; labelname += myMesh->Label.getValue(); group->Label.setValue(labelname); - for (const auto & it : segm) { + for (const auto& it : segm) { const std::vector& data = it->GetSegments(); - for (const auto & jt : data) { + for (const auto& jt : data) { Mesh::MeshObject* segment = mesh->meshFromSegment(jt); - Mesh::Feature* feaSegm = static_cast(group->addObject("Mesh::Feature", "Segment")); + Mesh::Feature* feaSegm = + static_cast(group->addObject("Mesh::Feature", "Segment")); Mesh::MeshObject* feaMesh = feaSegm->Mesh.startEditing(); feaMesh->swap(*segment); feaSegm->Mesh.finishEditing(); @@ -503,7 +531,7 @@ void SegmentationBestFit::accept() document->commitTransaction(); } -void SegmentationBestFit::changeEvent(QEvent *e) +void SegmentationBestFit::changeEvent(QEvent* e) { if (e->type() == QEvent::LanguageChange) { ui->retranslateUi(this); @@ -518,8 +546,7 @@ void SegmentationBestFit::changeEvent(QEvent *e) TaskSegmentationBestFit::TaskSegmentationBestFit(Mesh::Feature* mesh) { widget = new SegmentationBestFit(mesh); - taskbox = new Gui::TaskView::TaskBox( - QPixmap(), widget->windowTitle(), false, nullptr); + taskbox = new Gui::TaskView::TaskBox(QPixmap(), widget->windowTitle(), false, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } diff --git a/src/Mod/Mesh/Gui/SegmentationBestFit.h b/src/Mod/Mesh/Gui/SegmentationBestFit.h index 54a95401f1..3339129725 100644 --- a/src/Mod/Mesh/Gui/SegmentationBestFit.h +++ b/src/Mod/Mesh/Gui/SegmentationBestFit.h @@ -23,28 +23,33 @@ #ifndef MESHGUI_SEGMENTATIONBESTFIT_H #define MESHGUI_SEGMENTATIONBESTFIT_H -#include #include +#include #include #include -#include #include "MeshSelection.h" +#include class QDoubleSpinBox; // forward declarations -namespace Mesh { class Feature; } +namespace Mesh +{ +class Feature; +} -namespace MeshGui { +namespace MeshGui +{ class Ui_SegmentationBestFit; class FitParameter { public: - struct Points { + struct Points + { std::vector points; std::vector normals; }; @@ -52,15 +57,17 @@ public: virtual std::vector getParameter(Points) const = 0; }; -using ParameterList = std::list >; -class ParametersDialog : public QDialog +using ParameterList = std::list>; +class ParametersDialog: public QDialog { Q_OBJECT public: - ParametersDialog(std::vector&, FitParameter*, - ParameterList, Mesh::Feature* mesh, - QWidget* parent=nullptr); + ParametersDialog(std::vector&, + FitParameter*, + ParameterList, + Mesh::Feature* mesh, + QWidget* parent = nullptr); ~ParametersDialog() override; void accept() override; void reject() override; @@ -80,17 +87,19 @@ private: std::vector spinBoxes; }; -class MeshGuiExport SegmentationBestFit : public QWidget +class MeshGuiExport SegmentationBestFit: public QWidget { Q_OBJECT public: - explicit SegmentationBestFit(Mesh::Feature* mesh, QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags()); + explicit SegmentationBestFit(Mesh::Feature* mesh, + QWidget* parent = nullptr, + Qt::WindowFlags fl = Qt::WindowFlags()); ~SegmentationBestFit() override; void accept(); protected: - void changeEvent(QEvent *e) override; + void changeEvent(QEvent* e) override; private: void setupConnections(); @@ -110,7 +119,7 @@ private: /** * Embed the panel into a task dialog. */ -class TaskSegmentationBestFit : public Gui::TaskView::TaskDialog +class TaskSegmentationBestFit: public Gui::TaskView::TaskDialog { public: explicit TaskSegmentationBestFit(Mesh::Feature* mesh); @@ -119,13 +128,15 @@ public: bool accept() override; QDialogButtonBox::StandardButtons getStandardButtons() const override - { return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; } + { + return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; + } private: SegmentationBestFit* widget; Gui::TaskView::TaskBox* taskbox; }; -} +} // namespace MeshGui -#endif // MESHGUI_SEGMENTATIONBESTFIT_H +#endif // MESHGUI_SEGMENTATIONBESTFIT_H diff --git a/src/Mod/Mesh/Gui/Selection.cpp b/src/Mod/Mesh/Gui/Selection.cpp index 45ae22f7e5..b78934e8f1 100644 --- a/src/Mod/Mesh/Gui/Selection.cpp +++ b/src/Mod/Mesh/Gui/Selection.cpp @@ -31,7 +31,8 @@ using namespace MeshGui; /* TRANSLATOR MeshGui::Selection */ Selection::Selection(QWidget* parent) - : QWidget(parent), ui(new Ui_Selection()) + : QWidget(parent) + , ui(new Ui_Selection()) { ui->setupUi(this); setupConnections(); @@ -56,6 +57,7 @@ Selection::~Selection() void Selection::setupConnections() { + // clang-format off connect(ui->addSelection, &QPushButton::clicked, this, &Selection::onAddSelectionClicked); connect(ui->clearSelection, &QPushButton::clicked, @@ -64,6 +66,7 @@ void Selection::setupConnections() this, &Selection::onVisibleTrianglesToggled); connect(ui->screenTriangles, &QPushButton::clicked, this, &Selection::onScreenTrianglesToggled); + // clang-format on } void Selection::setObjects(const std::vector& o) diff --git a/src/Mod/Mesh/Gui/Selection.h b/src/Mod/Mesh/Gui/Selection.h index 8c31f494a4..9df6f396a5 100644 --- a/src/Mod/Mesh/Gui/Selection.h +++ b/src/Mod/Mesh/Gui/Selection.h @@ -23,18 +23,19 @@ #ifndef MESHGUI_SELECTION_H #define MESHGUI_SELECTION_H -#include #include +#include #include #include "MeshSelection.h" -namespace MeshGui { +namespace MeshGui +{ class Ui_Selection; -class Selection : public QWidget +class Selection: public QWidget { Q_OBJECT @@ -57,6 +58,6 @@ private: Ui_Selection* ui; }; -} +} // namespace MeshGui -#endif // MESHGUI_SELECTION_H +#endif // MESHGUI_SELECTION_H diff --git a/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp b/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp index 9667e1e6c4..f29e59f20f 100644 --- a/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp +++ b/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp @@ -23,37 +23,37 @@ #include "PreCompiled.h" #ifndef FC_OS_WIN32 -# ifndef GL_GLEXT_PROTOTYPES -# define GL_GLEXT_PROTOTYPES 1 -# endif +#ifndef GL_GLEXT_PROTOTYPES +#define GL_GLEXT_PROTOTYPES 1 +#endif #endif #ifndef _PreComp_ -# include -# include -# ifdef FC_OS_MACOSX -# include -# include -# include -# else -# include -# include -# include -# endif -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#ifdef FC_OS_MACOSX +#include +#include +#include +#else +#include +#include +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -70,35 +70,36 @@ using namespace MeshGui; #if defined RENDER_GL_VAO -class MeshRenderer::Private { +class MeshRenderer::Private +{ public: Gui::OpenGLMultiBuffer vertices; Gui::OpenGLMultiBuffer indices; - const SbColor * pcolors{nullptr}; - SoMaterialBindingElement::Binding matbinding{SoMaterialBindingElement::OVERALL}; - bool initialized{false}; + const SbColor* pcolors {nullptr}; + SoMaterialBindingElement::Binding matbinding {SoMaterialBindingElement::OVERALL}; + bool initialized {false}; Private(); - bool canRenderGLArray(SoGLRenderAction *) const; + bool canRenderGLArray(SoGLRenderAction*) const; void generateGLArrays(SoGLRenderAction* action, - SoMaterialBindingElement::Binding matbind, - std::vector& vertex, std::vector& index); + SoMaterialBindingElement::Binding matbind, + std::vector& vertex, + std::vector& index); void renderFacesGLArray(SoGLRenderAction*); - void renderCoordsGLArray(SoGLRenderAction *); + void renderCoordsGLArray(SoGLRenderAction*); void update(); - bool needUpdate(SoGLRenderAction *); + bool needUpdate(SoGLRenderAction*); private: - void renderGLArray(SoGLRenderAction *, GLenum); + void renderGLArray(SoGLRenderAction*, GLenum); }; MeshRenderer::Private::Private() - : vertices(GL_ARRAY_BUFFER) - , indices(GL_ELEMENT_ARRAY_BUFFER) -{ -} + : vertices(GL_ARRAY_BUFFER) + , indices(GL_ELEMENT_ARRAY_BUFFER) +{} -bool MeshRenderer::Private::canRenderGLArray(SoGLRenderAction *action) const +bool MeshRenderer::Private::canRenderGLArray(SoGLRenderAction* action) const { static bool init = false; static bool vboAvailable = false; @@ -116,10 +117,12 @@ bool MeshRenderer::Private::canRenderGLArray(SoGLRenderAction *action) const void MeshRenderer::Private::generateGLArrays(SoGLRenderAction* action, SoMaterialBindingElement::Binding matbind, - std::vector& vertex, std::vector& index) + std::vector& vertex, + std::vector& index) { - if (vertex.empty() || index.empty()) + if (vertex.empty() || index.empty()) { return; + } // lazy initialization vertices.setCurrentContext(action->getCacheContext()); @@ -130,22 +133,19 @@ void MeshRenderer::Private::generateGLArrays(SoGLRenderAction* action, indices.create(); vertices.bind(); - vertices.allocate(&(vertex[0]), - vertex.size() * sizeof(float)); + vertices.allocate(&(vertex[0]), vertex.size() * sizeof(float)); vertices.release(); indices.bind(); - indices.allocate(&(index[0]), - index.size() * sizeof(int32_t)); + indices.allocate(&(index[0]), index.size() * sizeof(int32_t)); indices.release(); this->matbinding = matbind; } -void MeshRenderer::Private::renderGLArray(SoGLRenderAction *action, GLenum mode) +void MeshRenderer::Private::renderGLArray(SoGLRenderAction* action, GLenum mode) { if (!initialized) { - SoDebugError::postWarning("MeshRenderer", - "not initialized"); + SoDebugError::postWarning("MeshRenderer", "not initialized"); return; } @@ -159,13 +159,14 @@ void MeshRenderer::Private::renderGLArray(SoGLRenderAction *action, GLenum mode) vertices.bind(); indices.bind(); - if (matbinding != SoMaterialBindingElement::OVERALL) + if (matbinding != SoMaterialBindingElement::OVERALL) { glInterleavedArrays(GL_C4F_N3F_V3F, 0, nullptr); - else + } + else { glInterleavedArrays(GL_N3F_V3F, 0, nullptr); + } - glDrawElements(mode, indices.size() / sizeof(uint32_t), - GL_UNSIGNED_INT, nullptr); + glDrawElements(mode, indices.size() / sizeof(uint32_t), GL_UNSIGNED_INT, nullptr); vertices.release(); indices.release(); @@ -175,12 +176,12 @@ void MeshRenderer::Private::renderGLArray(SoGLRenderAction *action, GLenum mode) glDisableClientState(GL_VERTEX_ARRAY); } -void MeshRenderer::Private::renderFacesGLArray(SoGLRenderAction *action) +void MeshRenderer::Private::renderFacesGLArray(SoGLRenderAction* action) { renderGLArray(action, GL_TRIANGLES); } -void MeshRenderer::Private::renderCoordsGLArray(SoGLRenderAction *action) +void MeshRenderer::Private::renderCoordsGLArray(SoGLRenderAction* action) { renderGLArray(action, GL_POINTS); } @@ -191,51 +192,53 @@ void MeshRenderer::Private::update() indices.destroy(); } -bool MeshRenderer::Private::needUpdate(SoGLRenderAction *action) +bool MeshRenderer::Private::needUpdate(SoGLRenderAction* action) { - return !vertices.isCreated(action->getCacheContext()) || - !indices.isCreated(action->getCacheContext()); + return !vertices.isCreated(action->getCacheContext()) + || !indices.isCreated(action->getCacheContext()); } #elif defined RENDER_GLARRAYS -class MeshRenderer::Private { +class MeshRenderer::Private +{ public: std::vector index_array; std::vector vertex_array; - const SbColor * pcolors; + const SbColor* pcolors; SoMaterialBindingElement::Binding matbinding; Private() - : pcolors(0) - , matbinding(SoMaterialBindingElement::OVERALL) - { - } + : pcolors(0) + , matbinding(SoMaterialBindingElement::OVERALL) + {} - bool canRenderGLArray(SoGLRenderAction *) const; + bool canRenderGLArray(SoGLRenderAction*) const; void generateGLArrays(SoGLRenderAction* action, - SoMaterialBindingElement::Binding matbind, - std::vector& vertex, std::vector& index); - void renderFacesGLArray(SoGLRenderAction *action); - void renderCoordsGLArray(SoGLRenderAction *action); + SoMaterialBindingElement::Binding matbind, + std::vector& vertex, + std::vector& index); + void renderFacesGLArray(SoGLRenderAction* action); + void renderCoordsGLArray(SoGLRenderAction* action); void update() - { - } - bool needUpdate(SoGLRenderAction *) + {} + bool needUpdate(SoGLRenderAction*) { return false; } }; -bool MeshRenderer::Private::canRenderGLArray(SoGLRenderAction *) const +bool MeshRenderer::Private::canRenderGLArray(SoGLRenderAction*) const { return true; } void MeshRenderer::Private::generateGLArrays(SoGLRenderAction*, SoMaterialBindingElement::Binding matbind, - std::vector& vertex, std::vector& index) + std::vector& vertex, + std::vector& index) { - if (vertex.empty() || index.empty()) + if (vertex.empty() || index.empty()) { return; + } this->index_array.resize(0); this->vertex_array.resize(0); @@ -245,7 +248,7 @@ void MeshRenderer::Private::generateGLArrays(SoGLRenderAction*, this->matbinding = matbind; } -void MeshRenderer::Private::renderFacesGLArray(SoGLRenderAction *action) +void MeshRenderer::Private::renderFacesGLArray(SoGLRenderAction* action) { (void)action; int cnt = index_array.size(); @@ -253,63 +256,64 @@ void MeshRenderer::Private::renderFacesGLArray(SoGLRenderAction *action) glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); - if (matbinding != SoMaterialBindingElement::OVERALL) + if (matbinding != SoMaterialBindingElement::OVERALL) { glInterleavedArrays(GL_C4F_N3F_V3F, 0, &(vertex_array[0])); - else + } + else { glInterleavedArrays(GL_N3F_V3F, 0, &(vertex_array[0])); + } glDrawElements(GL_TRIANGLES, cnt, GL_UNSIGNED_INT, &(index_array[0])); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); - } -void MeshRenderer::Private::renderCoordsGLArray(SoGLRenderAction *) +void MeshRenderer::Private::renderCoordsGLArray(SoGLRenderAction*) { int cnt = index_array.size(); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); - if (matbinding != SoMaterialBindingElement::OVERALL) + if (matbinding != SoMaterialBindingElement::OVERALL) { glInterleavedArrays(GL_C4F_N3F_V3F, 0, &(vertex_array[0])); - else + } + else { glInterleavedArrays(GL_N3F_V3F, 0, &(vertex_array[0])); + } glDrawElements(GL_POINTS, cnt, GL_UNSIGNED_INT, &(index_array[0])); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); } #else -class MeshRenderer::Private { +class MeshRenderer::Private +{ public: - const SbColor * pcolors; + const SbColor* pcolors; SoMaterialBindingElement::Binding matbinding; Private() - : pcolors(0) - , matbinding(SoMaterialBindingElement::OVERALL) - { - } + : pcolors(0) + , matbinding(SoMaterialBindingElement::OVERALL) + {} - bool canRenderGLArray(SoGLRenderAction *) const { + bool canRenderGLArray(SoGLRenderAction*) const + { return false; } void generateGLArrays(SoGLRenderAction*, - SoMaterialBindingElement::Binding, - std::vector&, std::vector&) - { - } - void renderFacesGLArray(SoGLRenderAction *) - { - } - void renderCoordsGLArray(SoGLRenderAction *) - { - } + SoMaterialBindingElement::Binding, + std::vector&, + std::vector&) + {} + void renderFacesGLArray(SoGLRenderAction*) + {} + void renderCoordsGLArray(SoGLRenderAction*) + {} void update() - { - } - bool needUpdate(SoGLRenderAction *) + {} + bool needUpdate(SoGLRenderAction*) { return false; } @@ -317,9 +321,8 @@ public: #endif MeshRenderer::MeshRenderer() - : p(new Private) -{ -} + : p(new Private) +{} MeshRenderer::~MeshRenderer() { @@ -331,13 +334,15 @@ void MeshRenderer::update() p->update(); } -bool MeshRenderer::needUpdate(SoGLRenderAction *action) +bool MeshRenderer::needUpdate(SoGLRenderAction* action) { return p->needUpdate(action); } -void MeshRenderer::generateGLArrays(SoGLRenderAction* action, SoMaterialBindingElement::Binding matbind, - std::vector& vertex, std::vector& index) +void MeshRenderer::generateGLArrays(SoGLRenderAction* action, + SoMaterialBindingElement::Binding matbind, + std::vector& vertex, + std::vector& index) { SoGLLazyElement* gl = SoGLLazyElement::getInstance(action->getState()); if (gl) { @@ -351,7 +356,7 @@ void MeshRenderer::generateGLArrays(SoGLRenderAction* action, SoMaterialBindingE // drawCoords (every 4th vertex) | 20.0 // renderCoordsGLArray (all vertexes) | 20.0 // -void MeshRenderer::renderCoordsGLArray(SoGLRenderAction *action) +void MeshRenderer::renderCoordsGLArray(SoGLRenderAction* action) { p->renderCoordsGLArray(action); } @@ -371,12 +376,12 @@ void MeshRenderer::renderCoordsGLArray(SoGLRenderAction *action) // With GL_PRIMITIVE_RESTART_FIXED_INDEX | 0.9 // Without GL_PRIMITIVE_RESTART | 8.5 // Vertex-Array-Object (RENDER_GL_VAO) | 60.0 -void MeshRenderer::renderFacesGLArray(SoGLRenderAction *action) +void MeshRenderer::renderFacesGLArray(SoGLRenderAction* action) { p->renderFacesGLArray(action); } -bool MeshRenderer::canRenderGLArray(SoGLRenderAction *action) const +bool MeshRenderer::canRenderGLArray(SoGLRenderAction* action) const { return p->canRenderGLArray(action); } @@ -390,14 +395,15 @@ bool MeshRenderer::matchMaterial(SoState* state) const // * set to wireframe mode // => the material of the shaded mode instead of that of the // wireframe mode - SoMaterialBindingElement::Binding matbind = - SoMaterialBindingElement::get(state); - if (p->matbinding != matbind) + SoMaterialBindingElement::Binding matbind = SoMaterialBindingElement::get(state); + if (p->matbinding != matbind) { return false; + } // the buffer doesn't contain color information - if (matbind == SoMaterialBindingElement::OVERALL) + if (matbind == SoMaterialBindingElement::OVERALL) { return true; - const SbColor * pcolors = nullptr; + } + const SbColor* pcolors = nullptr; SoGLLazyElement* gl = SoGLLazyElement::getInstance(state); if (gl) { pcolors = gl->getDiffusePointer(); @@ -434,7 +440,7 @@ void SoFCMaterialEngine::initClass() SO_ENGINE_INIT_CLASS(SoFCMaterialEngine, SoEngine, "Engine"); } -void SoFCMaterialEngine::inputChanged(SoField *) +void SoFCMaterialEngine::inputChanged(SoField*) { SO_ENGINE_OUTPUT(trigger, SoSFBool, setValue(true)); } @@ -454,7 +460,7 @@ void SoFCIndexedFaceSet::initClass() } SoFCIndexedFaceSet::SoFCIndexedFaceSet() - : renderTriangleLimit(UINT_MAX) + : renderTriangleLimit(UINT_MAX) { SO_NODE_CONSTRUCTOR(SoFCIndexedFaceSet); SO_NODE_ADD_FIELD(updateGLArray, (false)); @@ -465,10 +471,11 @@ SoFCIndexedFaceSet::SoFCIndexedFaceSet() /** * Either renders the complete mesh or only a subset of the points. */ -void SoFCIndexedFaceSet::GLRender(SoGLRenderAction *action) +void SoFCIndexedFaceSet::GLRender(SoGLRenderAction* action) { - if (this->coordIndex.getNum() < 3) + if (this->coordIndex.getNum() < 3) { return; + } if (!this->shouldGLRender(action)) { // Transparency is handled inside 'shouldGLRender' but the base class @@ -482,15 +489,16 @@ void SoFCIndexedFaceSet::GLRender(SoGLRenderAction *action) } #if defined(RENDER_GL_VAO) - SoState * state = action->getState(); + SoState* state = action->getState(); // get the VBO status of the viewer SbBool useVBO = true; Gui::SoGLVBOActivatedElement::get(state, useVBO); // Check for a matching OpenGL context - if (!render.canRenderGLArray(action)) + if (!render.canRenderGLArray(action)) { useVBO = false; + } // use VBO for fast rendering if possible if (useVBO) { @@ -520,16 +528,15 @@ void SoFCIndexedFaceSet::GLRender(SoGLRenderAction *action) #endif } -void SoFCIndexedFaceSet::drawFaces(SoGLRenderAction *action) +void SoFCIndexedFaceSet::drawFaces(SoGLRenderAction* action) { - SoState * state = action->getState(); + SoState* state = action->getState(); SbBool mode = Gui::SoFCInteractiveElement::get(state); - unsigned int num = this->coordIndex.getNum()/4; + unsigned int num = this->coordIndex.getNum() / 4; if (!mode || num <= this->renderTriangleLimit) { #ifdef RENDER_GLARRAYS - SoMaterialBindingElement::Binding matbind = - SoMaterialBindingElement::get(state); + SoMaterialBindingElement::Binding matbind = SoMaterialBindingElement::get(state); SbBool matchCtx = render.canRenderGLArray(action); if (matbind == SoMaterialBindingElement::OVERALL && matchCtx) { @@ -549,22 +556,21 @@ void SoFCIndexedFaceSet::drawFaces(SoGLRenderAction *action) #endif } else { -#if 0 && defined (RENDER_GLARRAYS) +#if 0 && defined(RENDER_GLARRAYS) SoMaterialBundle mb(action); mb.sendFirst(); render.renderCoordsGLArray(action); #else - SoMaterialBindingElement::Binding matbind = - SoMaterialBindingElement::get(state); + SoMaterialBindingElement::Binding matbind = SoMaterialBindingElement::get(state); int32_t binding = (int32_t)(matbind); - const SoCoordinateElement * coords; - const SbVec3f * normals; - const int32_t * cindices; + const SoCoordinateElement* coords; + const SbVec3f* normals; + const int32_t* cindices; int numindices; - const int32_t * nindices; - const int32_t * tindices; - const int32_t * mindices; + const int32_t* nindices; + const int32_t* tindices; + const int32_t* mindices; SbBool normalCacheUsed; SoMaterialBundle mb(action); @@ -572,20 +578,36 @@ void SoFCIndexedFaceSet::drawFaces(SoGLRenderAction *action) SoTextureCoordinateBundle tb(action, true, false); SbBool sendNormals = !mb.isColorOnly() || tb.isFunction(); - this->getVertexData(state, coords, normals, cindices, - nindices, tindices, mindices, numindices, - sendNormals, normalCacheUsed); + this->getVertexData(state, + coords, + normals, + cindices, + nindices, + tindices, + mindices, + numindices, + sendNormals, + normalCacheUsed); - mb.sendFirst(); // make sure we have the correct material + mb.sendFirst(); // make sure we have the correct material - drawCoords(static_cast(coords), cindices, numindices, - normals, nindices, &mb, mindices, binding, &tb, tindices); + drawCoords(static_cast(coords), + cindices, + numindices, + normals, + nindices, + &mb, + mindices, + binding, + &tb, + tindices); // getVertexData() internally calls readLockNormalCache() that read locks // the normal cache. When the cache is not needed any more we must call // readUnlockNormalCache() - if (normalCacheUsed) + if (normalCacheUsed) { this->readUnlockNormalCache(); + } // Disable caching for this node SoGLCacheContextElement::shouldAutoCache(state, SoGLCacheContextElement::DONT_AUTO_CACHE); @@ -593,22 +615,22 @@ void SoFCIndexedFaceSet::drawFaces(SoGLRenderAction *action) } } -void SoFCIndexedFaceSet::drawCoords(const SoGLCoordinateElement * const vertexlist, - const int32_t *vertexindices, +void SoFCIndexedFaceSet::drawCoords(const SoGLCoordinateElement* const vertexlist, + const int32_t* vertexindices, int numindices, - const SbVec3f *normals, - const int32_t *normalindices, - SoMaterialBundle *materials, - const int32_t * /*matindices*/, + const SbVec3f* normals, + const int32_t* normalindices, + SoMaterialBundle* materials, + const int32_t* /*matindices*/, const int32_t binding, - const SoTextureCoordinateBundle * const /*texcoords*/, - const int32_t * /*texindices*/) + const SoTextureCoordinateBundle* const /*texcoords*/, + const int32_t* /*texindices*/) { - const SbVec3f * coords3d = nullptr; + const SbVec3f* coords3d = nullptr; coords3d = vertexlist->getArrayPtr3(); - int mod = numindices/(4*this->renderTriangleLimit)+1; - float size = std::min((float)mod,3.0f); + int mod = numindices / (4 * this->renderTriangleLimit) + 1; + float size = std::min((float)mod, 3.0f); glPointSize(size); SbBool per_face = false; @@ -624,49 +646,69 @@ void SoFCIndexedFaceSet::drawCoords(const SoGLCoordinateElement * const vertexli break; } - int ct=0; - const int32_t *viptr = vertexindices; + int ct = 0; + const int32_t* viptr = vertexindices; int32_t v1, v2, v3; - SbVec3f dummynormal(0,0,1); - const SbVec3f *currnormal = &dummynormal; - if (normals) currnormal = normals; + SbVec3f dummynormal(0, 0, 1); + const SbVec3f* currnormal = &dummynormal; + if (normals) { + currnormal = normals; + } glBegin(GL_POINTS); - for (int index=0; indexsend(ct, true); - v1 = *viptr++; index++; - if (per_vert) + } + v1 = *viptr++; + index++; + if (per_vert) { materials->send(v1, true); - if (normals) + } + if (normals) { currnormal = &normals[*normalindices++]; + } glNormal3fv((const GLfloat*)currnormal); glVertex3fv((const GLfloat*)(coords3d + v1)); - v2 = *viptr++; index++; - if (per_vert) + v2 = *viptr++; + index++; + if (per_vert) { materials->send(v2, true); - if (normals) + } + if (normals) { currnormal = &normals[*normalindices++]; + } glNormal3fv((const GLfloat*)currnormal); glVertex3fv((const GLfloat*)(coords3d + v2)); - v3 = *viptr++; index++; - if (per_vert) + v3 = *viptr++; + index++; + if (per_vert) { materials->send(v3, true); - if (normals) + } + if (normals) { currnormal = &normals[*normalindices++]; + } glNormal3fv((const GLfloat*)currnormal); glVertex3fv((const GLfloat*)(coords3d + v3)); } else { - viptr++; index++; normalindices++; - viptr++; index++; normalindices++; - viptr++; index++; normalindices++; + viptr++; + index++; + normalindices++; + viptr++; + index++; + normalindices++; + viptr++; + index++; + normalindices++; } - viptr++; index++; normalindices++; + viptr++; + index++; + normalindices++; } glEnd(); } @@ -676,30 +718,36 @@ void SoFCIndexedFaceSet::invalidate() updateGLArray.setValue(true); } -void SoFCIndexedFaceSet::generateGLArrays(SoGLRenderAction * action) +void SoFCIndexedFaceSet::generateGLArrays(SoGLRenderAction* action) { - const SoCoordinateElement * coords; - const SbVec3f * normals; - const int32_t * cindices; - const SbColor * pcolors = nullptr; - const float * transp = nullptr; + const SoCoordinateElement* coords; + const SbVec3f* normals; + const int32_t* cindices; + const SbColor* pcolors = nullptr; + const float* transp = nullptr; int numindices, numcolors = 0, numtransp = 0; - const int32_t * nindices; - const int32_t * tindices; - const int32_t * mindices; + const int32_t* nindices; + const int32_t* tindices; + const int32_t* mindices; SbBool normalCacheUsed; SbBool sendNormals = true; SoState* state = action->getState(); - this->getVertexData(state, coords, normals, cindices, - nindices, tindices, mindices, numindices, - sendNormals, normalCacheUsed); + this->getVertexData(state, + coords, + normals, + cindices, + nindices, + tindices, + mindices, + numindices, + sendNormals, + normalCacheUsed); - const SbVec3f * points = coords->getArrayPtr3(); + const SbVec3f* points = coords->getArrayPtr3(); - SoMaterialBindingElement::Binding matbind = - SoMaterialBindingElement::get(state); + SoMaterialBindingElement::Binding matbind = SoMaterialBindingElement::get(state); SoGLLazyElement* gl = SoGLLazyElement::getInstance(state); if (gl) { pcolors = gl->getDiffusePointer(); @@ -721,21 +769,25 @@ void SoFCIndexedFaceSet::generateGLArrays(SoGLRenderAction * action) SoNormalBindingElement::Binding normbind = SoNormalBindingElement::get(state); if (normbind == SoNormalBindingElement::PER_VERTEX_INDEXED) { if (matbind == SoMaterialBindingElement::PER_FACE) { - face_vertices.reserve(3 * numTria * 10); // duplicate each vertex (rgba, normal, vertex) + face_vertices.reserve(3 * numTria + * 10); // duplicate each vertex (rgba, normal, vertex) face_indices.resize(3 * numTria); if (numcolors != static_cast(numTria)) { - SoDebugError::postWarning("SoFCIndexedFaceSet::generateGLArrays", - "The number of faces (%d) doesn't match with the number of colors (%d).", numTria, numcolors); + SoDebugError::postWarning( + "SoFCIndexedFaceSet::generateGLArrays", + "The number of faces (%d) doesn't match with the number of colors (%d).", + numTria, + numcolors); } // the nindices must have the length of numindices int32_t vertex = 0; int index = 0; float t = transp ? transp[0] : 0; - for (std::size_t i=0; igetNum()) { - SoDebugError::postWarning("SoFCIndexedFaceSet::generateGLArrays", - "The number of points (%d) doesn't match with the number of colors (%d).", coords->getNum(), numcolors); + SoDebugError::postWarning( + "SoFCIndexedFaceSet::generateGLArrays", + "The number of points (%d) doesn't match with the number of colors (%d).", + coords->getNum(), + numcolors); } // the nindices must have the length of numindices int32_t vertex = 0; int index = 0; float t = transp ? transp[0] : 0; - for (std::size_t i=0; igetNum(); face_vertices.reserve(6 * numPts); - for (std::size_t i=0; ireadUnlockNormalCache(); + } } -void SoFCIndexedFaceSet::doAction(SoAction * action) +void SoFCIndexedFaceSet::doAction(SoAction* action) { if (action->getTypeId() == Gui::SoGLSelectAction::getClassTypeId()) { SoNode* node = action->getNodeAppliedTo(); - if (!node) // on no node applied + if (!node) { // on no node applied return; + } // The node we have is the parent of this node and the coordinate node // thus we search there for it. @@ -880,22 +937,25 @@ void SoFCIndexedFaceSet::doAction(SoAction * action) sa.setSearchingAll(false); sa.setType(SoCoordinate3::getClassTypeId(), 1); sa.apply(node); - SoPath * path = sa.getPath(); - if (!path) + SoPath* path = sa.getPath(); + if (!path) { return; + } // make sure we got the node we wanted SoNode* coords = path->getNodeFromTail(0); - if (!(coords && coords->getTypeId().isDerivedFrom(SoCoordinate3::getClassTypeId()))) + if (!(coords && coords->getTypeId().isDerivedFrom(SoCoordinate3::getClassTypeId()))) { return; + } startSelection(action); renderSelectionGeometry(static_cast(coords)->point.getValues(0)); stopSelection(action); } else if (action->getTypeId() == Gui::SoVisibleFaceAction::getClassTypeId()) { SoNode* node = action->getNodeAppliedTo(); - if (!node) // on no node applied + if (!node) { // on no node applied return; + } // The node we have is the parent of this node and the coordinate node // thus we search there for it. @@ -904,14 +964,16 @@ void SoFCIndexedFaceSet::doAction(SoAction * action) sa.setSearchingAll(false); sa.setType(SoCoordinate3::getClassTypeId(), 1); sa.apply(node); - SoPath * path = sa.getPath(); - if (!path) + SoPath* path = sa.getPath(); + if (!path) { return; + } // make sure we got the node we wanted SoNode* coords = path->getNodeFromTail(0); - if (!(coords && coords->getTypeId().isDerivedFrom(SoCoordinate3::getClassTypeId()))) + if (!(coords && coords->getTypeId().isDerivedFrom(SoCoordinate3::getClassTypeId()))) { return; + } startVisibility(action); renderVisibleFaces(static_cast(coords)->point.getValues(0)); stopVisibility(action); @@ -920,20 +982,22 @@ void SoFCIndexedFaceSet::doAction(SoAction * action) inherited::doAction(action); } -void SoFCIndexedFaceSet::startSelection(SoAction * action) +void SoFCIndexedFaceSet::startSelection(SoAction* action) { - Gui::SoGLSelectAction *doaction = static_cast(action); + Gui::SoGLSelectAction* doaction = static_cast(action); const SbViewportRegion& vp = doaction->getViewportRegion(); int x = vp.getViewportOriginPixels()[0]; int y = vp.getViewportOriginPixels()[1]; int w = vp.getViewportSizePixels()[0]; int h = vp.getViewportSizePixels()[1]; - int bufSize = 5*(this->coordIndex.getNum()/4); // make the buffer big enough + int bufSize = 5 * (this->coordIndex.getNum() / 4); // make the buffer big enough this->selectBuf = new GLuint[bufSize]; - SbMatrix view = SoViewingMatrixElement::get(action->getState()); // clazy:exclude=rule-of-two-soft - SbMatrix proj = SoProjectionMatrixElement::get(action->getState()); // clazy:exclude=rule-of-two-soft + SbMatrix view = + SoViewingMatrixElement::get(action->getState()); // clazy:exclude=rule-of-two-soft + SbMatrix proj = + SoProjectionMatrixElement::get(action->getState()); // clazy:exclude=rule-of-two-soft glSelectBuffer(bufSize, selectBuf); glRenderMode(GL_SELECT); @@ -942,23 +1006,25 @@ void SoFCIndexedFaceSet::startSelection(SoAction * action) glPushName(-1); GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT,viewport); + glGetIntegerv(GL_VIEWPORT, viewport); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); if (w > 0 && h > 0) { - glTranslatef((viewport[2] - 2 * (x - viewport[0])) / w, (viewport[3] - 2 * (y - viewport[1])) / h, 0); + glTranslatef((viewport[2] - 2 * (x - viewport[0])) / w, + (viewport[3] - 2 * (y - viewport[1])) / h, + 0); glScalef(viewport[2] / w, viewport[3] / h, 1.0); } - glMultMatrixf(/*mp*/(float*)proj); + glMultMatrixf(/*mp*/ (float*)proj); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadMatrixf((float*)view); } -void SoFCIndexedFaceSet::stopSelection(SoAction * action) +void SoFCIndexedFaceSet::stopSelection(SoAction* action) { // restoring the original projection matrix glPopMatrix(); @@ -970,51 +1036,53 @@ void SoFCIndexedFaceSet::stopSelection(SoAction * action) // returning to normal rendering mode GLint hits = glRenderMode(GL_RENDER); - int bufSize = 5*(this->coordIndex.getNum()/4); - std::vector< std::pair > hit; - GLint index=0; - for (GLint ii=0;iicoordIndex.getNum() / 4); + std::vector> hit; + GLint index = 0; + for (GLint ii = 0; ii < hits && index < bufSize; ii++) { GLint ct = (GLint)selectBuf[index]; - hit.emplace_back(selectBuf[index+1]/4294967295.0,selectBuf[index+3]); - index = index+ct+3; + hit.emplace_back(selectBuf[index + 1] / 4294967295.0, selectBuf[index + 3]); + index = index + ct + 3; } - delete [] selectBuf; + delete[] selectBuf; selectBuf = nullptr; - std::sort(hit.begin(),hit.end()); + std::sort(hit.begin(), hit.end()); - Gui::SoGLSelectAction *doaction = static_cast(action); + Gui::SoGLSelectAction* doaction = static_cast(action); doaction->indices.reserve(hit.size()); - for (GLint ii=0;iiindices.push_back(hit[ii].second); } } -void SoFCIndexedFaceSet::renderSelectionGeometry(const SbVec3f * coords3d) +void SoFCIndexedFaceSet::renderSelectionGeometry(const SbVec3f* coords3d) { - int numfaces = this->coordIndex.getNum()/4; - const int32_t * cindices = this->coordIndex.getValues(0); + int numfaces = this->coordIndex.getNum() / 4; + const int32_t* cindices = this->coordIndex.getValues(0); - int fcnt=0; + int fcnt = 0; int32_t v1, v2, v3; - for (int index=0; indexgetState()); // clazy:exclude=rule-of-two-soft - SbMatrix proj = SoProjectionMatrixElement::get(action->getState()); // clazy:exclude=rule-of-two-soft + SbMatrix view = + SoViewingMatrixElement::get(action->getState()); // clazy:exclude=rule-of-two-soft + SbMatrix proj = + SoProjectionMatrixElement::get(action->getState()); // clazy:exclude=rule-of-two-soft glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -1025,7 +1093,7 @@ void SoFCIndexedFaceSet::startVisibility(SoAction * action) glLoadMatrixf((float*)view); } -void SoFCIndexedFaceSet::stopVisibility(SoAction * /*action*/) +void SoFCIndexedFaceSet::stopVisibility(SoAction* /*action*/) { // restoring the original projection matrix glPopMatrix(); @@ -1035,32 +1103,32 @@ void SoFCIndexedFaceSet::stopVisibility(SoAction * /*action*/) glFlush(); } -void SoFCIndexedFaceSet::renderVisibleFaces(const SbVec3f * coords3d) +void SoFCIndexedFaceSet::renderVisibleFaces(const SbVec3f* coords3d) { - glDisable (GL_BLEND); - glDisable (GL_DITHER); - glDisable (GL_FOG); - glDisable (GL_LIGHTING); - glDisable (GL_TEXTURE_1D); - glDisable (GL_TEXTURE_2D); - glShadeModel (GL_FLAT); + glDisable(GL_BLEND); + glDisable(GL_DITHER); + glDisable(GL_FOG); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_1D); + glDisable(GL_TEXTURE_2D); + glShadeModel(GL_FLAT); - uint32_t numfaces = this->coordIndex.getNum()/4; - const int32_t * cindices = this->coordIndex.getValues(0); + uint32_t numfaces = this->coordIndex.getNum() / 4; + const int32_t* cindices = this->coordIndex.getValues(0); int32_t v1, v2, v3; - for (uint32_t index=0; index& vertex, std::vector& index); - void renderFacesGLArray(SoGLRenderAction *action); - void renderCoordsGLArray(SoGLRenderAction *action); - bool canRenderGLArray(SoGLRenderAction *action) const; + void generateGLArrays(SoGLRenderAction*, + SoMaterialBindingElement::Binding binding, + std::vector& vertex, + std::vector& index); + void renderFacesGLArray(SoGLRenderAction* action); + void renderCoordsGLArray(SoGLRenderAction* action); + bool canRenderGLArray(SoGLRenderAction* action) const; bool matchMaterial(SoState*) const; void update(); - bool needUpdate(SoGLRenderAction *action); + bool needUpdate(SoGLRenderAction* action); static bool shouldRenderDirectly(bool); private: @@ -68,7 +71,7 @@ private: * * @author Werner Mayer */ -class MeshGuiExport SoFCMaterialEngine : public SoEngine +class MeshGuiExport SoFCMaterialEngine: public SoEngine { SO_ENGINE_HEADER(SoFCMaterialEngine); @@ -82,7 +85,7 @@ public: private: ~SoFCMaterialEngine() override; void evaluate() override; - void inputChanged(SoField *) override; + void inputChanged(SoField*) override; }; /** @@ -92,7 +95,8 @@ private: * * @author Werner Mayer */ -class MeshGuiExport SoFCIndexedFaceSet : public SoIndexedFaceSet { +class MeshGuiExport SoFCIndexedFaceSet: public SoIndexedFaceSet +{ using inherited = SoIndexedFaceSet; SO_NODE_HEADER(SoFCIndexedFaceSet); @@ -109,38 +113,37 @@ public: protected: // Force using the reference count mechanism. ~SoFCIndexedFaceSet() override = default; - void GLRender(SoGLRenderAction *action) override; - void drawFaces(SoGLRenderAction *action); - void drawCoords(const SoGLCoordinateElement * const vertexlist, - const int32_t *vertexindices, + void GLRender(SoGLRenderAction* action) override; + void drawFaces(SoGLRenderAction* action); + void drawCoords(const SoGLCoordinateElement* const vertexlist, + const int32_t* vertexindices, int numindices, - const SbVec3f *normals, - const int32_t *normalindices, - SoMaterialBundle *materials, - const int32_t *matindices, + const SbVec3f* normals, + const int32_t* normalindices, + SoMaterialBundle* materials, + const int32_t* matindices, const int32_t binding, - const SoTextureCoordinateBundle * const texcoords, - const int32_t *texindices); + const SoTextureCoordinateBundle* const texcoords, + const int32_t* texindices); - void doAction(SoAction * action) override; + void doAction(SoAction* action) override; private: - void startSelection(SoAction * action); - void stopSelection(SoAction * action); - void renderSelectionGeometry(const SbVec3f *); - void startVisibility(SoAction * action); - void stopVisibility(SoAction * action); - void renderVisibleFaces(const SbVec3f *); + void startSelection(SoAction* action); + void stopSelection(SoAction* action); + void renderSelectionGeometry(const SbVec3f*); + void startVisibility(SoAction* action); + void stopVisibility(SoAction* action); + void renderVisibleFaces(const SbVec3f*); - void generateGLArrays(SoGLRenderAction * action); + void generateGLArrays(SoGLRenderAction* action); private: MeshRenderer render; - GLuint *selectBuf{nullptr}; + GLuint* selectBuf {nullptr}; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_SOFCINDEXEDFACESET_H - +#endif // MESHGUI_SOFCINDEXEDFACESET_H diff --git a/src/Mod/Mesh/Gui/SoFCMeshObject.cpp b/src/Mod/Mesh/Gui/SoFCMeshObject.cpp index 8cbdc0205e..f56cf1dd1e 100644 --- a/src/Mod/Mesh/Gui/SoFCMeshObject.cpp +++ b/src/Mod/Mesh/Gui/SoFCMeshObject.cpp @@ -22,32 +22,32 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# ifdef FC_OS_WIN32 -# include -# endif -# ifdef FC_OS_MACOSX -# include -# include -# else -# include -# include -# endif -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#ifdef FC_OS_WIN32 +#include +#endif +#ifdef FC_OS_MACOSX +#include +#include +#else +#include +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -64,12 +64,13 @@ using namespace MeshGui; -class SoOutputStreambuf : public std::streambuf +class SoOutputStreambuf: public std::streambuf { public: - explicit SoOutputStreambuf(SoOutput* o) : out(o) - { - } + explicit SoOutputStreambuf(SoOutput* o) + : out(o) + {} + protected: int overflow(int c = EOF) override { @@ -79,7 +80,7 @@ protected: } return c; } - std::streamsize xsputn (const char* s, std::streamsize num) override + std::streamsize xsputn(const char* s, std::streamsize num) override { out->write(s); return num; @@ -89,26 +90,29 @@ private: SoOutput* out; }; -class SoOutputStream : public std::ostream +class SoOutputStream: public std::ostream { public: - explicit SoOutputStream(SoOutput* o) : std::ostream(nullptr), buf(o) + explicit SoOutputStream(SoOutput* o) + : std::ostream(nullptr) + , buf(o) { this->rdbuf(&buf); } + private: SoOutputStreambuf buf; }; -class SoInputStreambuf : public std::streambuf +class SoInputStreambuf: public std::streambuf { public: - explicit SoInputStreambuf(SoInput* o) : inp(o) + explicit SoInputStreambuf(SoInput* o) + : inp(o) { - setg (buffer+pbSize, - buffer+pbSize, - buffer+pbSize); + setg(buffer + pbSize, buffer + pbSize, buffer + pbSize); } + protected: int underflow() override { @@ -122,26 +126,25 @@ protected: numPutback = pbSize; } - memcpy (buffer+(pbSize-numPutback), gptr()-numPutback, numPutback); + memcpy(buffer + (pbSize - numPutback), gptr() - numPutback, numPutback); - int num=0; - for (int i=0; iget(c); if (ok) { num++; - buffer[pbSize+i] = c; - if (c == '\n') + buffer[pbSize + i] = c; + if (c == '\n') { break; + } } - else if (num==0) { + else if (num == 0) { return EOF; } } - setg (buffer+(pbSize-numPutback), - buffer+pbSize, - buffer+pbSize+num); + setg(buffer + (pbSize - numPutback), buffer + pbSize, buffer + pbSize + num); return *gptr(); } @@ -149,14 +152,16 @@ protected: private: static const int pbSize = 4; static const int bufSize = 1024; - char buffer[bufSize+pbSize]; + char buffer[bufSize + pbSize]; SoInput* inp; }; -class SoInputStream : public std::istream +class SoInputStream: public std::istream { public: - explicit SoInputStream(SoInput* o) : std::istream(nullptr), buf(o) + explicit SoInputStream(SoInput* o) + : std::istream(nullptr) + , buf(o) { this->rdbuf(&buf); } @@ -168,7 +173,9 @@ private: // Defines all required member variables and functions for a // single-value field -SO_SFIELD_SOURCE(SoSFMeshObject, Base::Reference, Base::Reference) +SO_SFIELD_SOURCE(SoSFMeshObject, + Base::Reference, + Base::Reference) void SoSFMeshObject::initClass() @@ -180,7 +187,7 @@ void SoSFMeshObject::initClass() // This reads the value of a field from a file. It returns false if the value could not be read // successfully. -SbBool SoSFMeshObject::readValue(SoInput *in) +SbBool SoSFMeshObject::readValue(SoInput* in) { if (!in->isBinary()) { SoInputStream str(in); @@ -199,33 +206,37 @@ SbBool SoSFMeshObject::readValue(SoInput *in) int32_t countPt; in->read(countPt); std::vector verts(countPt); - in->readBinaryArray(&(verts[0]),countPt); + in->readBinaryArray(&(verts[0]), countPt); MeshCore::MeshPointArray rPoints; - rPoints.reserve(countPt/3); - for (std::vector::iterator it = verts.begin(); - it != verts.end();) { - Base::Vector3f p; - p.x = *it; ++it; - p.y = *it; ++it; - p.z = *it; ++it; - rPoints.push_back(p); + rPoints.reserve(countPt / 3); + for (std::vector::iterator it = verts.begin(); it != verts.end();) { + Base::Vector3f p; + p.x = *it; + ++it; + p.y = *it; + ++it; + p.z = *it; + ++it; + rPoints.push_back(p); } int32_t countFt; in->read(countFt); std::vector faces(countFt); - in->readBinaryArray(&(faces[0]),countFt); + in->readBinaryArray(&(faces[0]), countFt); MeshCore::MeshFacetArray rFacets; - rFacets.reserve(countFt/3); - for (std::vector::iterator it = faces.begin(); - it != faces.end();) { - MeshCore::MeshFacet f; - f._aulPoints[0] = *it; ++it; - f._aulPoints[1] = *it; ++it; - f._aulPoints[2] = *it; ++it; - rFacets.push_back(f); + rFacets.reserve(countFt / 3); + for (std::vector::iterator it = faces.begin(); it != faces.end();) { + MeshCore::MeshFacet f; + f._aulPoints[0] = *it; + ++it; + f._aulPoints[1] = *it; + ++it; + f._aulPoints[2] = *it; + ++it; + rFacets.push_back(f); } MeshCore::MeshKernel kernel; @@ -241,7 +252,7 @@ SbBool SoSFMeshObject::readValue(SoInput *in) } // This writes the value of a field to a file. -void SoSFMeshObject::writeValue(SoOutput *out) const +void SoSFMeshObject::writeValue(SoOutput* out) const { if (!value) { int32_t count = 0; @@ -258,8 +269,8 @@ void SoSFMeshObject::writeValue(SoOutput *out) const const MeshCore::MeshPointArray& rPoints = value->getKernel().GetPoints(); std::vector verts; - verts.reserve(3*rPoints.size()); - for (const auto & rPoint : rPoints) { + verts.reserve(3 * rPoints.size()); + for (const auto& rPoint : rPoints) { verts.push_back(rPoint.x); verts.push_back(rPoint.y); verts.push_back(rPoint.z); @@ -267,12 +278,12 @@ void SoSFMeshObject::writeValue(SoOutput *out) const int32_t countPt = (int32_t)verts.size(); out->write(countPt); - out->writeBinaryArray(&(verts[0]),countPt); + out->writeBinaryArray(&(verts[0]), countPt); const MeshCore::MeshFacetArray& rFacets = value->getKernel().GetFacets(); std::vector faces; - faces.reserve(3*rFacets.size()); - for (const auto & rFacet : rFacets) { + faces.reserve(3 * rFacets.size()); + for (const auto& rFacet : rFacets) { faces.push_back((int32_t)rFacet._aulPoints[0]); faces.push_back((int32_t)rFacet._aulPoints[1]); faces.push_back((int32_t)rFacet._aulPoints[2]); @@ -280,7 +291,7 @@ void SoSFMeshObject::writeValue(SoOutput *out) const int32_t countFt = (int32_t)faces.size(); out->write(countFt); - out->writeBinaryArray((const int32_t*)&(faces[0]),countFt); + out->writeBinaryArray((const int32_t*)&(faces[0]), countFt); } // ------------------------------------------------------- @@ -292,7 +303,7 @@ void SoFCMeshObjectElement::initClass() SO_ELEMENT_INIT_CLASS(SoFCMeshObjectElement, inherited); } -void SoFCMeshObjectElement::init(SoState * state) +void SoFCMeshObjectElement::init(SoState* state) { inherited::init(state); this->mesh = nullptr; @@ -300,29 +311,30 @@ void SoFCMeshObjectElement::init(SoState * state) SoFCMeshObjectElement::~SoFCMeshObjectElement() = default; -void SoFCMeshObjectElement::set(SoState * const state, SoNode * const node, const Mesh::MeshObject * const mesh) +void SoFCMeshObjectElement::set(SoState* const state, + SoNode* const node, + const Mesh::MeshObject* const mesh) { - SoFCMeshObjectElement * elem = (SoFCMeshObjectElement *) - SoReplacedElement::getElement(state, classStackIndex, node); + SoFCMeshObjectElement* elem = + (SoFCMeshObjectElement*)SoReplacedElement::getElement(state, classStackIndex, node); if (elem) { elem->mesh = mesh; elem->nodeId = node->getNodeId(); } } -const Mesh::MeshObject * SoFCMeshObjectElement::get(SoState * const state) +const Mesh::MeshObject* SoFCMeshObjectElement::get(SoState* const state) { return SoFCMeshObjectElement::getInstance(state)->mesh; } -const SoFCMeshObjectElement * SoFCMeshObjectElement::getInstance(SoState * state) +const SoFCMeshObjectElement* SoFCMeshObjectElement::getInstance(SoState* state) { - return (const SoFCMeshObjectElement *) SoElement::getConstElement(state, classStackIndex); + return (const SoFCMeshObjectElement*)SoElement::getConstElement(state, classStackIndex); } -void SoFCMeshObjectElement::print(FILE * /* file */) const -{ -} +void SoFCMeshObjectElement::print(FILE* /* file */) const +{} // ------------------------------------------------------- @@ -352,9 +364,9 @@ void SoFCMeshPickNode::initClass() SO_NODE_INIT_CLASS(SoFCMeshPickNode, SoNode, "Node"); } -void SoFCMeshPickNode::notify(SoNotList *list) +void SoFCMeshPickNode::notify(SoNotList* list) { - SoField *f = list->getLastField(); + SoField* f = list->getLastField(); if (f == &mesh) { const Mesh::MeshObject* meshObject = mesh.getValue(); if (meshObject) { @@ -367,12 +379,11 @@ void SoFCMeshPickNode::notify(SoNotList *list) } // Doc from superclass. -void SoFCMeshPickNode::rayPick(SoRayPickAction * /*action*/) -{ -} +void SoFCMeshPickNode::rayPick(SoRayPickAction* /*action*/) +{} // Doc from superclass. -void SoFCMeshPickNode::pick(SoPickAction * action) +void SoFCMeshPickNode::pick(SoPickAction* action) { SoRayPickAction* raypick = static_cast(action); raypick->setObjectSpace(); @@ -383,11 +394,11 @@ void SoFCMeshPickNode::pick(SoPickAction * action) const SbLine& line = raypick->getLine(); const SbVec3f& pos = line.getPosition(); const SbVec3f& dir = line.getDirection(); - Base::Vector3f pt(pos[0],pos[1],pos[2]); - Base::Vector3f dr(dir[0],dir[1],dir[2]); + Base::Vector3f pt(pos[0], pos[1], pos[2]); + Base::Vector3f dr(dir[0], dir[1], dir[2]); Mesh::FacetIndex index; if (alg.NearestFacetOnRay(pt, dr, *meshGrid, pt, index)) { - SoPickedPoint* pp = raypick->addIntersection(SbVec3f(pt.x,pt.y,pt.z)); + SoPickedPoint* pp = raypick->addIntersection(SbVec3f(pt.x, pt.y, pt.z)); if (pp) { SoFaceDetail* det = new SoFaceDetail(); det->setFaceIndex(index); @@ -407,9 +418,9 @@ SoFCMeshGridNode::SoFCMeshGridNode() { SO_NODE_CONSTRUCTOR(SoFCMeshGridNode); - SO_NODE_ADD_FIELD(minGrid, (SbVec3f(0,0,0))); - SO_NODE_ADD_FIELD(maxGrid, (SbVec3f(0,0,0))); - SO_NODE_ADD_FIELD(lenGrid, (SbVec3s(0,0,0))); + SO_NODE_ADD_FIELD(minGrid, (SbVec3f(0, 0, 0))); + SO_NODE_ADD_FIELD(maxGrid, (SbVec3f(0, 0, 0))); + SO_NODE_ADD_FIELD(lenGrid, (SbVec3s(0, 0, 0))); } /*! @@ -423,21 +434,24 @@ void SoFCMeshGridNode::initClass() SO_NODE_INIT_CLASS(SoFCMeshGridNode, SoNode, "Node"); } -void SoFCMeshGridNode::GLRender(SoGLRenderAction * /*action*/) +void SoFCMeshGridNode::GLRender(SoGLRenderAction* /*action*/) { const SbVec3f& min = minGrid.getValue(); const SbVec3f& max = maxGrid.getValue(); const SbVec3s& len = lenGrid.getValue(); - short u,v,w; len.getValue(u,v,w); - float minX, minY, minZ; min.getValue(minX, minY, minZ); - float maxX, maxY, maxZ; max.getValue(maxX, maxY, maxZ); - float dx = (maxX-minX)/(float)u; - float dy = (maxY-minY)/(float)v; - float dz = (maxZ-minZ)/(float)w; - glColor3f(0.0f,1.0f,0.0); + short u, v, w; + len.getValue(u, v, w); + float minX, minY, minZ; + min.getValue(minX, minY, minZ); + float maxX, maxY, maxZ; + max.getValue(maxX, maxY, maxZ); + float dx = (maxX - minX) / (float)u; + float dy = (maxY - minY) / (float)v; + float dz = (maxZ - minZ) / (float)w; + glColor3f(0.0f, 1.0f, 0.0); glBegin(GL_LINES); - for (short i=0; igetState(), this, mesh.getValue()); } // Doc from superclass. -void SoFCMeshObjectNode::GLRender(SoGLRenderAction * action) +void SoFCMeshObjectNode::GLRender(SoGLRenderAction* action) { SoFCMeshObjectNode::doAction(action); } // Doc from superclass. -void SoFCMeshObjectNode::callback(SoCallbackAction * action) +void SoFCMeshObjectNode::callback(SoCallbackAction* action) { SoFCMeshObjectNode::doAction(action); } // Doc from superclass. -void SoFCMeshObjectNode::pick(SoPickAction * action) +void SoFCMeshObjectNode::pick(SoPickAction* action) { SoFCMeshObjectNode::doAction(action); } // Doc from superclass. -void SoFCMeshObjectNode::getBoundingBox(SoGetBoundingBoxAction * action) +void SoFCMeshObjectNode::getBoundingBox(SoGetBoundingBoxAction* action) { SoFCMeshObjectNode::doAction(action); } // Doc from superclass. -void SoFCMeshObjectNode::getPrimitiveCount(SoGetPrimitiveCountAction * action) +void SoFCMeshObjectNode::getPrimitiveCount(SoGetPrimitiveCountAction* action) { SoFCMeshObjectNode::doAction(action); } @@ -552,7 +566,9 @@ void SoFCMeshObjectNode::getPrimitiveCount(SoGetPrimitiveCountAction * action) inline void glVertex(const MeshCore::MeshPoint& _v) { float v[3]; - v[0]=_v.x; v[1]=_v.y;v[2]=_v.z; + v[0] = _v.x; + v[1] = _v.y; + v[2] = _v.z; glVertex3fv(v); } @@ -560,7 +576,9 @@ inline void glVertex(const MeshCore::MeshPoint& _v) inline void glNormal(const Base::Vector3f& _n) { float n[3]; - n[0]=_n.x; n[1]=_n.y;n[2]=_n.z; + n[0] = _n.x; + n[1] = _n.y; + n[2] = _n.z; glNormal3fv(n); } @@ -592,7 +610,7 @@ SoFCMeshObjectShape::SoFCMeshObjectShape() SoFCMeshObjectShape::~SoFCMeshObjectShape() = default; -void SoFCMeshObjectShape::notify(SoNotList * node) +void SoFCMeshObjectShape::notify(SoNotList* node) { inherited::notify(node); updateGLArray = true; @@ -603,11 +621,10 @@ void SoFCMeshObjectShape::notify(SoNotList * node) /** * Either renders the complete mesh or only a subset of the points. */ -void SoFCMeshObjectShape::GLRender(SoGLRenderAction *action) +void SoFCMeshObjectShape::GLRender(SoGLRenderAction* action) { - if (shouldGLRender(action)) - { - SoState* state = action->getState(); + if (shouldGLRender(action)) { + SoState* state = action->getState(); // Here we must save the model and projection matrices because // we need them later for picking @@ -615,21 +632,23 @@ void SoFCMeshObjectShape::GLRender(SoGLRenderAction *action) glGetFloatv(GL_PROJECTION_MATRIX, this->projection); SbBool mode = Gui::SoFCInteractiveElement::get(state); - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); - if (!mesh || mesh->countPoints() == 0) + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); + if (!mesh || mesh->countPoints() == 0) { return; + } Binding mbind = this->findMaterialBinding(state); SoMaterialBundle mb(action); - //SoTextureCoordinateBundle tb(action, true, false); + // SoTextureCoordinateBundle tb(action, true, false); - SbBool needNormals = !mb.isColorOnly()/* || tb.isFunction()*/; + SbBool needNormals = !mb.isColorOnly() /* || tb.isFunction()*/; mb.sendFirst(); // make sure we have the correct material SbBool ccw = true; - if (SoShapeHintsElement::getVertexOrdering(state) == SoShapeHintsElement::CLOCKWISE) + if (SoShapeHintsElement::getVertexOrdering(state) == SoShapeHintsElement::CLOCKWISE) { ccw = false; + } if (!mode || mesh->countFacets() <= this->renderTriangleLimit) { if (mbind != OVERALL) { @@ -648,7 +667,7 @@ void SoFCMeshObjectShape::GLRender(SoGLRenderAction *action) } } else { -#if 0 && defined (RENDER_GLARRAYS) +#if 0 && defined(RENDER_GLARRAYS) renderCoordsGLArray(action); #else drawPoints(mesh, needNormals, ccw); @@ -660,92 +679,99 @@ void SoFCMeshObjectShape::GLRender(SoGLRenderAction *action) /** * Translates current material binding into the internal Binding enum. */ -SoFCMeshObjectShape::Binding SoFCMeshObjectShape::findMaterialBinding(SoState * const state) const +SoFCMeshObjectShape::Binding SoFCMeshObjectShape::findMaterialBinding(SoState* const state) const { Binding binding = OVERALL; SoMaterialBindingElement::Binding matbind = SoMaterialBindingElement::get(state); switch (matbind) { - case SoMaterialBindingElement::OVERALL: - binding = OVERALL; - break; - case SoMaterialBindingElement::PER_VERTEX: - binding = PER_VERTEX_INDEXED; - break; - case SoMaterialBindingElement::PER_VERTEX_INDEXED: - binding = PER_VERTEX_INDEXED; - break; - case SoMaterialBindingElement::PER_PART: - case SoMaterialBindingElement::PER_FACE: - binding = PER_FACE_INDEXED; - break; - case SoMaterialBindingElement::PER_PART_INDEXED: - case SoMaterialBindingElement::PER_FACE_INDEXED: - binding = PER_FACE_INDEXED; - break; - default: - break; + case SoMaterialBindingElement::OVERALL: + binding = OVERALL; + break; + case SoMaterialBindingElement::PER_VERTEX: + binding = PER_VERTEX_INDEXED; + break; + case SoMaterialBindingElement::PER_VERTEX_INDEXED: + binding = PER_VERTEX_INDEXED; + break; + case SoMaterialBindingElement::PER_PART: + case SoMaterialBindingElement::PER_FACE: + binding = PER_FACE_INDEXED; + break; + case SoMaterialBindingElement::PER_PART_INDEXED: + case SoMaterialBindingElement::PER_FACE_INDEXED: + binding = PER_FACE_INDEXED; + break; + default: + break; } return binding; } /** * Renders the triangles of the complete mesh. - * FIXME: Do it the same way as Coin did to have only one implementation which is controlled by defines + * FIXME: Do it the same way as Coin did to have only one implementation which is controlled by + * defines * FIXME: Implement using different values of transparency for each vertex or face */ -void SoFCMeshObjectShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBundle* mb, - Binding bind, SbBool needNormals, SbBool ccw) const +void SoFCMeshObjectShape::drawFaces(const Mesh::MeshObject* mesh, + SoMaterialBundle* mb, + Binding bind, + SbBool needNormals, + SbBool ccw) const { - const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints(); - const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); + const MeshCore::MeshPointArray& rPoints = mesh->getKernel().GetPoints(); + const MeshCore::MeshFacetArray& rFacets = mesh->getKernel().GetFacets(); bool perVertex = (mb && bind == PER_VERTEX_INDEXED); bool perFace = (mb && bind == PER_FACE_INDEXED); - if (needNormals) - { + if (needNormals) { glBegin(GL_TRIANGLES); if (ccw) { // counterclockwise ordering - for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it) - { + for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); + it != rFacets.end(); + ++it) { const MeshCore::MeshPoint& v0 = rPoints[it->_aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[it->_aulPoints[1]]; const MeshCore::MeshPoint& v2 = rPoints[it->_aulPoints[2]]; // Calculate the normal n = (v1-v0)x(v2-v0) float n[3]; - n[0] = (v1.y-v0.y)*(v2.z-v0.z)-(v1.z-v0.z)*(v2.y-v0.y); - n[1] = (v1.z-v0.z)*(v2.x-v0.x)-(v1.x-v0.x)*(v2.z-v0.z); - n[2] = (v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x); + n[0] = (v1.y - v0.y) * (v2.z - v0.z) - (v1.z - v0.z) * (v2.y - v0.y); + n[1] = (v1.z - v0.z) * (v2.x - v0.x) - (v1.x - v0.x) * (v2.z - v0.z); + n[2] = (v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x); - if(perFace) - mb->send(it-rFacets.begin(), true); + if (perFace) { + mb->send(it - rFacets.begin(), true); + } glNormal(n); - if(perVertex) - mb->send(it->_aulPoints[0], true); + if (perVertex) { + mb->send(it->_aulPoints[0], true); + } glVertex(v0); - if(perVertex) - mb->send(it->_aulPoints[1], true); + if (perVertex) { + mb->send(it->_aulPoints[1], true); + } glVertex(v1); - if(perVertex) - mb->send(it->_aulPoints[2], true); + if (perVertex) { + mb->send(it->_aulPoints[2], true); + } glVertex(v2); } } else { // clockwise ordering - for (const auto & rFacet : rFacets) - { + for (const auto& rFacet : rFacets) { const MeshCore::MeshPoint& v0 = rPoints[rFacet._aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[rFacet._aulPoints[1]]; const MeshCore::MeshPoint& v2 = rPoints[rFacet._aulPoints[2]]; // Calculate the normal n = -(v1-v0)x(v2-v0) float n[3]; - n[0] = -((v1.y-v0.y)*(v2.z-v0.z)-(v1.z-v0.z)*(v2.y-v0.y)); - n[1] = -((v1.z-v0.z)*(v2.x-v0.x)-(v1.x-v0.x)*(v2.z-v0.z)); - n[2] = -((v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x)); + n[0] = -((v1.y - v0.y) * (v2.z - v0.z) - (v1.z - v0.z) * (v2.y - v0.y)); + n[1] = -((v1.z - v0.z) * (v2.x - v0.x) - (v1.x - v0.x) * (v2.z - v0.z)); + n[2] = -((v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x)); glNormal(n); glVertex(v0); @@ -757,8 +783,7 @@ void SoFCMeshObjectShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBun } else { glBegin(GL_TRIANGLES); - for (const auto & rFacet : rFacets) - { + for (const auto& rFacet : rFacets) { glVertex(rPoints[rFacet._aulPoints[0]]); glVertex(rPoints[rFacet._aulPoints[1]]); glVertex(rPoints[rFacet._aulPoints[2]]); @@ -770,62 +795,65 @@ void SoFCMeshObjectShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBun /** * Renders the gravity points of a subset of triangles. */ -void SoFCMeshObjectShape::drawPoints(const Mesh::MeshObject * mesh, SbBool needNormals, SbBool ccw) const +void SoFCMeshObjectShape::drawPoints(const Mesh::MeshObject* mesh, + SbBool needNormals, + SbBool ccw) const { - const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints(); - const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); - int mod = rFacets.size()/renderTriangleLimit+1; + const MeshCore::MeshPointArray& rPoints = mesh->getKernel().GetPoints(); + const MeshCore::MeshFacetArray& rFacets = mesh->getKernel().GetFacets(); + int mod = rFacets.size() / renderTriangleLimit + 1; - float size = std::min((float)mod,3.0f); + float size = std::min((float)mod, 3.0f); glPointSize(size); - if (needNormals) - { + if (needNormals) { glBegin(GL_POINTS); - int ct=0; + int ct = 0; if (ccw) { - for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it, ct++) - { - if (ct%mod==0) { + for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); + it != rFacets.end(); + ++it, ct++) { + if (ct % mod == 0) { const MeshCore::MeshPoint& v0 = rPoints[it->_aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[it->_aulPoints[1]]; const MeshCore::MeshPoint& v2 = rPoints[it->_aulPoints[2]]; // Calculate the normal n = (v1-v0)x(v2-v0) float n[3]; - n[0] = (v1.y-v0.y)*(v2.z-v0.z)-(v1.z-v0.z)*(v2.y-v0.y); - n[1] = (v1.z-v0.z)*(v2.x-v0.x)-(v1.x-v0.x)*(v2.z-v0.z); - n[2] = (v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x); + n[0] = (v1.y - v0.y) * (v2.z - v0.z) - (v1.z - v0.z) * (v2.y - v0.y); + n[1] = (v1.z - v0.z) * (v2.x - v0.x) - (v1.x - v0.x) * (v2.z - v0.z); + n[2] = (v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x); // Calculate the center point p=(v0+v1+v2)/3 float p[3]; - p[0] = (v0.x+v1.x+v2.x)/3.0f; - p[1] = (v0.y+v1.y+v2.y)/3.0f; - p[2] = (v0.z+v1.z+v2.z)/3.0f; + p[0] = (v0.x + v1.x + v2.x) / 3.0f; + p[1] = (v0.y + v1.y + v2.y) / 3.0f; + p[2] = (v0.z + v1.z + v2.z) / 3.0f; glNormal3fv(n); glVertex3fv(p); } } } else { - for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it, ct++) - { - if (ct%mod==0) { + for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); + it != rFacets.end(); + ++it, ct++) { + if (ct % mod == 0) { const MeshCore::MeshPoint& v0 = rPoints[it->_aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[it->_aulPoints[1]]; const MeshCore::MeshPoint& v2 = rPoints[it->_aulPoints[2]]; // Calculate the normal n = -(v1-v0)x(v2-v0) float n[3]; - n[0] = -((v1.y-v0.y)*(v2.z-v0.z)-(v1.z-v0.z)*(v2.y-v0.y)); - n[1] = -((v1.z-v0.z)*(v2.x-v0.x)-(v1.x-v0.x)*(v2.z-v0.z)); - n[2] = -((v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x)); + n[0] = -((v1.y - v0.y) * (v2.z - v0.z) - (v1.z - v0.z) * (v2.y - v0.y)); + n[1] = -((v1.z - v0.z) * (v2.x - v0.x) - (v1.x - v0.x) * (v2.z - v0.z)); + n[2] = -((v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x)); // Calculate the center point p=(v0+v1+v2)/3 float p[3]; - p[0] = (v0.x+v1.x+v2.x)/3.0f; - p[1] = (v0.y+v1.y+v2.y)/3.0f; - p[2] = (v0.z+v1.z+v2.z)/3.0f; + p[0] = (v0.x + v1.x + v2.x) / 3.0f; + p[1] = (v0.y + v1.y + v2.y) / 3.0f; + p[2] = (v0.z + v1.z + v2.z) / 3.0f; glNormal3fv(n); glVertex3fv(p); } @@ -835,18 +863,18 @@ void SoFCMeshObjectShape::drawPoints(const Mesh::MeshObject * mesh, SbBool needN } else { glBegin(GL_POINTS); - int ct=0; - for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it, ct++) - { - if (ct%mod==0) { + int ct = 0; + for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); + ++it, ct++) { + if (ct % mod == 0) { const MeshCore::MeshPoint& v0 = rPoints[it->_aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[it->_aulPoints[1]]; const MeshCore::MeshPoint& v2 = rPoints[it->_aulPoints[2]]; // Calculate the center point p=(v0+v1+v2)/3 float p[3]; - p[0] = (v0.x+v1.x+v2.x)/3.0f; - p[1] = (v0.y+v1.y+v2.y)/3.0f; - p[2] = (v0.z+v1.z+v2.z)/3.0f; + p[0] = (v0.x + v1.x + v2.x) / 3.0f; + p[1] = (v0.y + v1.y + v2.y) / 3.0f; + p[2] = (v0.z + v1.z + v2.z) / 3.0f; glVertex3fv(p); } } @@ -854,9 +882,9 @@ void SoFCMeshObjectShape::drawPoints(const Mesh::MeshObject * mesh, SbBool needN } } -void SoFCMeshObjectShape::generateGLArrays(SoState * state) +void SoFCMeshObjectShape::generateGLArrays(SoState* state) { - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); this->index_array.resize(0); this->vertex_array.resize(0); @@ -869,11 +897,11 @@ void SoFCMeshObjectShape::generateGLArrays(SoState * state) const MeshCore::MeshFacetArray& cF = kernel.GetFacets(); // Flat shading - face_vertices.reserve(3 * cF.size() * 6); // duplicate each vertex + face_vertices.reserve(3 * cF.size() * 6); // duplicate each vertex face_indices.resize(3 * cF.size()); int indexed = 0; - for (const auto & it : cF) { + for (const auto& it : cF) { Base::Vector3f n = kernel.GetFacet(it).GetNormal(); for (Mesh::PointIndex ptIndex : it._aulPoints) { face_vertices.push_back(n.x); @@ -892,7 +920,7 @@ void SoFCMeshObjectShape::generateGLArrays(SoState * state) this->vertex_array.swap(face_vertices); } -void SoFCMeshObjectShape::renderFacesGLArray(SoGLRenderAction *action) +void SoFCMeshObjectShape::renderFacesGLArray(SoGLRenderAction* action) { (void)action; GLsizei cnt = static_cast(index_array.size()); @@ -907,7 +935,7 @@ void SoFCMeshObjectShape::renderFacesGLArray(SoGLRenderAction *action) glDisableClientState(GL_NORMAL_ARRAY); } -void SoFCMeshObjectShape::renderCoordsGLArray(SoGLRenderAction *action) +void SoFCMeshObjectShape::renderCoordsGLArray(SoGLRenderAction* action) { (void)action; int cnt = index_array.size(); @@ -922,12 +950,13 @@ void SoFCMeshObjectShape::renderCoordsGLArray(SoGLRenderAction *action) glDisableClientState(GL_NORMAL_ARRAY); } -void SoFCMeshObjectShape::doAction(SoAction * action) +void SoFCMeshObjectShape::doAction(SoAction* action) { if (action->getTypeId() == Gui::SoGLSelectAction::getClassTypeId()) { SoNode* node = action->getNodeAppliedTo(); - if (!node) // on no node applied + if (!node) { // on no node applied return; + } // The node we have is the parent of this node and the coordinate node // thus we search there for it. @@ -936,14 +965,16 @@ void SoFCMeshObjectShape::doAction(SoAction * action) sa.setSearchingAll(false); sa.setType(SoFCMeshObjectNode::getClassTypeId(), 1); sa.apply(node); - SoPath * path = sa.getPath(); - if (!path) + SoPath* path = sa.getPath(); + if (!path) { return; + } // make sure we got the node we wanted SoNode* coords = path->getNodeFromTail(0); - if (!(coords && coords->getTypeId().isDerivedFrom(SoFCMeshObjectNode::getClassTypeId()))) + if (!(coords && coords->getTypeId().isDerivedFrom(SoFCMeshObjectNode::getClassTypeId()))) { return; + } const Mesh::MeshObject* mesh = static_cast(coords)->mesh.getValue(); startSelection(action, mesh); renderSelectionGeometry(mesh); @@ -953,16 +984,16 @@ void SoFCMeshObjectShape::doAction(SoAction * action) inherited::doAction(action); } -void SoFCMeshObjectShape::startSelection(SoAction * action, const Mesh::MeshObject* mesh) +void SoFCMeshObjectShape::startSelection(SoAction* action, const Mesh::MeshObject* mesh) { - Gui::SoGLSelectAction *doaction = static_cast(action); + Gui::SoGLSelectAction* doaction = static_cast(action); const SbViewportRegion& vp = doaction->getViewportRegion(); int x = vp.getViewportOriginPixels()[0]; int y = vp.getViewportOriginPixels()[1]; int w = vp.getViewportSizePixels()[0]; int h = vp.getViewportSizePixels()[1]; - unsigned int bufSize = 5*mesh->countFacets(); // make the buffer big enough + unsigned int bufSize = 5 * mesh->countFacets(); // make the buffer big enough this->selectBuf = new GLuint[bufSize]; glSelectBuffer(bufSize, selectBuf); @@ -972,21 +1003,23 @@ void SoFCMeshObjectShape::startSelection(SoAction * action, const Mesh::MeshObje glPushName(-1); GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT,viewport); + glGetIntegerv(GL_VIEWPORT, viewport); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); if (w > 0 && h > 0) { - glTranslatef((viewport[2] - 2 * (x - viewport[0])) / w, (viewport[3] - 2 * (y - viewport[1])) / h, 0); + glTranslatef((viewport[2] - 2 * (x - viewport[0])) / w, + (viewport[3] - 2 * (y - viewport[1])) / h, + 0); glScalef(viewport[2] / w, viewport[3] / h, 1.0); } - glMultMatrixf(/*mp*/this->projection); + glMultMatrixf(/*mp*/ this->projection); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadMatrixf(this->modelview); } -void SoFCMeshObjectShape::stopSelection(SoAction * action, const Mesh::MeshObject* mesh) +void SoFCMeshObjectShape::stopSelection(SoAction* action, const Mesh::MeshObject* mesh) { // restoring the original projection matrix glPopMatrix(); @@ -998,31 +1031,31 @@ void SoFCMeshObjectShape::stopSelection(SoAction * action, const Mesh::MeshObjec // returning to normal rendering mode GLint hits = glRenderMode(GL_RENDER); - unsigned int bufSize = 5*mesh->countFacets(); - std::vector< std::pair > hit; - GLuint index=0; - for (GLint ii=0;iicountFacets(); + std::vector> hit; + GLuint index = 0; + for (GLint ii = 0; ii < hits && index < bufSize; ii++) { GLint ct = (GLint)selectBuf[index]; - hit.emplace_back(selectBuf[index+1]/4294967295.0,selectBuf[index+3]); - index = index+ct+3; + hit.emplace_back(selectBuf[index + 1] / 4294967295.0, selectBuf[index + 3]); + index = index + ct + 3; } - delete [] selectBuf; + delete[] selectBuf; selectBuf = nullptr; - std::sort(hit.begin(),hit.end()); + std::sort(hit.begin(), hit.end()); - Gui::SoGLSelectAction *doaction = static_cast(action); + Gui::SoGLSelectAction* doaction = static_cast(action); doaction->indices.reserve(hit.size()); - for (GLint ii=0;iiindices.push_back(hit[ii].second); } } void SoFCMeshObjectShape::renderSelectionGeometry(const Mesh::MeshObject* mesh) { - int fcnt=0; - const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints(); - const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); + int fcnt = 0; + const MeshCore::MeshPointArray& rPoints = mesh->getKernel().GetPoints(); + const MeshCore::MeshFacetArray& rFacets = mesh->getKernel().GetFacets(); MeshCore::MeshFacetArray::_TConstIterator it_end = rFacets.end(); for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != it_end; ++it) { const MeshCore::MeshPoint& v0 = rPoints[it->_aulPoints[0]]; @@ -1042,8 +1075,7 @@ void SoFCMeshObjectShape::renderSelectionGeometry(const Mesh::MeshObject* mesh) /** * Calculates picked point based on primitives generated by subclasses. */ -void -SoFCMeshObjectShape::rayPick(SoRayPickAction * action) +void SoFCMeshObjectShape::rayPick(SoRayPickAction* action) { inherited::rayPick(action); } @@ -1055,16 +1087,19 @@ SoFCMeshObjectShape::rayPick(SoRayPickAction * action) */ void SoFCMeshObjectShape::generatePrimitives(SoAction* action) { - SoState* state = action->getState(); + SoState* state = action->getState(); const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); - if (!mesh) + if (!mesh) { return; - const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints(); - const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); - if (rPoints.size() < 3) + } + const MeshCore::MeshPointArray& rPoints = mesh->getKernel().GetPoints(); + const MeshCore::MeshFacetArray& rFacets = mesh->getKernel().GetFacets(); + if (rPoints.size() < 3) { return; - if (rFacets.empty()) + } + if (rFacets.empty()) { return; + } // get material binding Binding mbind = this->findMaterialBinding(state); @@ -1077,19 +1112,17 @@ void SoFCMeshObjectShape::generatePrimitives(SoAction* action) vertex.setDetail(&pointDetail); beginShape(action, TRIANGLES, &faceDetail); - try - { - for (const auto & rFacet : rFacets) - { + try { + for (const auto& rFacet : rFacets) { const MeshCore::MeshPoint& v0 = rPoints[rFacet._aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[rFacet._aulPoints[1]]; const MeshCore::MeshPoint& v2 = rPoints[rFacet._aulPoints[2]]; // Calculate the normal n = (v1-v0)x(v2-v0) SbVec3f n; - n[0] = (v1.y-v0.y)*(v2.z-v0.z)-(v1.z-v0.z)*(v2.y-v0.y); - n[1] = (v1.z-v0.z)*(v2.x-v0.x)-(v1.x-v0.x)*(v2.z-v0.z); - n[2] = (v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x); + n[0] = (v1.y - v0.y) * (v2.z - v0.z) - (v1.z - v0.z) * (v2.y - v0.y); + n[1] = (v1.z - v0.z) * (v2.x - v0.x) - (v1.x - v0.x) * (v2.z - v0.z); + n[2] = (v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x); // Set the normal vertex.setNormal(n); @@ -1140,11 +1173,11 @@ void SoFCMeshObjectShape::generatePrimitives(SoAction* action) * Against the default OpenInventor implementation which returns 0 as well * Coin3d fills in the point and face indices. */ -SoDetail * SoFCMeshObjectShape::createTriangleDetail(SoRayPickAction * action, - const SoPrimitiveVertex * v1, - const SoPrimitiveVertex * v2, - const SoPrimitiveVertex * v3, - SoPickedPoint * pp) +SoDetail* SoFCMeshObjectShape::createTriangleDetail(SoRayPickAction* action, + const SoPrimitiveVertex* v1, + const SoPrimitiveVertex* v2, + const SoPrimitiveVertex* v3, + SoPickedPoint* pp) { SoDetail* detail = inherited::createTriangleDetail(action, v1, v2, v3, pp); return detail; @@ -1153,32 +1186,33 @@ SoDetail * SoFCMeshObjectShape::createTriangleDetail(SoRayPickAction * action, /** * Sets the bounding box of the mesh to \a box and its center to \a center. */ -void SoFCMeshObjectShape::computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er) +void SoFCMeshObjectShape::computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center) { - SoState* state = action->getState(); - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); + SoState* state = action->getState(); + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); if (mesh && mesh->countPoints() > 0) { Base::BoundBox3f cBox = mesh->getKernel().GetBoundBox(); - box.setBounds(SbVec3f(cBox.MinX,cBox.MinY,cBox.MinZ), - SbVec3f(cBox.MaxX,cBox.MaxY,cBox.MaxZ)); + box.setBounds(SbVec3f(cBox.MinX, cBox.MinY, cBox.MinZ), + SbVec3f(cBox.MaxX, cBox.MaxY, cBox.MaxZ)); Base::Vector3f mid = cBox.GetCenter(); - center.setValue(mid.x,mid.y,mid.z); + center.setValue(mid.x, mid.y, mid.z); } else { - box.setBounds(SbVec3f(0,0,0), SbVec3f(0,0,0)); - center.setValue(0.0f,0.0f,0.0f); + box.setBounds(SbVec3f(0, 0, 0), SbVec3f(0, 0, 0)); + center.setValue(0.0f, 0.0f, 0.0f); } } /** * Adds the number of the triangles to the \a SoGetPrimitiveCountAction. */ -void SoFCMeshObjectShape::getPrimitiveCount(SoGetPrimitiveCountAction * action) +void SoFCMeshObjectShape::getPrimitiveCount(SoGetPrimitiveCountAction* action) { - if (!this->shouldPrimitiveCount(action)) + if (!this->shouldPrimitiveCount(action)) { return; - SoState* state = action->getState(); - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); + } + SoState* state = action->getState(); + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); action->addNumTriangles(mesh->countFacets()); action->addNumPoints(mesh->countPoints()); } @@ -1186,10 +1220,10 @@ void SoFCMeshObjectShape::getPrimitiveCount(SoGetPrimitiveCountAction * action) /** * Counts the number of triangles. If a mesh is not set yet it returns 0. */ -unsigned int SoFCMeshObjectShape::countTriangles(SoAction * action) const +unsigned int SoFCMeshObjectShape::countTriangles(SoAction* action) const { - SoState* state = action->getState(); - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); + SoState* state = action->getState(); + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); return (unsigned int)mesh->countFacets(); } @@ -1202,7 +1236,8 @@ void SoFCMeshSegmentShape::initClass() SO_NODE_INIT_CLASS(SoFCMeshSegmentShape, SoShape, "Shape"); } -SoFCMeshSegmentShape::SoFCMeshSegmentShape() : renderTriangleLimit(UINT_MAX) +SoFCMeshSegmentShape::SoFCMeshSegmentShape() + : renderTriangleLimit(UINT_MAX) { SO_NODE_CONSTRUCTOR(SoFCMeshSegmentShape); SO_NODE_ADD_FIELD(index, (0)); @@ -1211,34 +1246,37 @@ SoFCMeshSegmentShape::SoFCMeshSegmentShape() : renderTriangleLimit(UINT_MAX) /** * Either renders the complete mesh or only a subset of the points. */ -void SoFCMeshSegmentShape::GLRender(SoGLRenderAction *action) +void SoFCMeshSegmentShape::GLRender(SoGLRenderAction* action) { - if (shouldGLRender(action)) - { - SoState* state = action->getState(); + if (shouldGLRender(action)) { + SoState* state = action->getState(); SbBool mode = Gui::SoFCInteractiveElement::get(state); - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); - if (!mesh) + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); + if (!mesh) { return; + } Binding mbind = this->findMaterialBinding(state); SoMaterialBundle mb(action); - //SoTextureCoordinateBundle tb(action, true, false); + // SoTextureCoordinateBundle tb(action, true, false); - SbBool needNormals = !mb.isColorOnly()/* || tb.isFunction()*/; + SbBool needNormals = !mb.isColorOnly() /* || tb.isFunction()*/; mb.sendFirst(); // make sure we have the correct material SbBool ccw = true; - if (SoShapeHintsElement::getVertexOrdering(state) == SoShapeHintsElement::CLOCKWISE) + if (SoShapeHintsElement::getVertexOrdering(state) == SoShapeHintsElement::CLOCKWISE) { ccw = false; + } if (!mode || mesh->countFacets() <= this->renderTriangleLimit) { - if (mbind != OVERALL) + if (mbind != OVERALL) { drawFaces(mesh, &mb, mbind, needNormals, ccw); - else + } + else { drawFaces(mesh, nullptr, mbind, needNormals, ccw); + } } else { drawPoints(mesh, needNormals, ccw); @@ -1249,59 +1287,62 @@ void SoFCMeshSegmentShape::GLRender(SoGLRenderAction *action) /** * Translates current material binding into the internal Binding enum. */ -SoFCMeshSegmentShape::Binding SoFCMeshSegmentShape::findMaterialBinding(SoState * const state) const +SoFCMeshSegmentShape::Binding SoFCMeshSegmentShape::findMaterialBinding(SoState* const state) const { Binding binding = OVERALL; SoMaterialBindingElement::Binding matbind = SoMaterialBindingElement::get(state); switch (matbind) { - case SoMaterialBindingElement::OVERALL: - binding = OVERALL; - break; - case SoMaterialBindingElement::PER_VERTEX: - binding = PER_VERTEX_INDEXED; - break; - case SoMaterialBindingElement::PER_VERTEX_INDEXED: - binding = PER_VERTEX_INDEXED; - break; - case SoMaterialBindingElement::PER_PART: - case SoMaterialBindingElement::PER_FACE: - binding = PER_FACE_INDEXED; - break; - case SoMaterialBindingElement::PER_PART_INDEXED: - case SoMaterialBindingElement::PER_FACE_INDEXED: - binding = PER_FACE_INDEXED; - break; - default: - break; + case SoMaterialBindingElement::OVERALL: + binding = OVERALL; + break; + case SoMaterialBindingElement::PER_VERTEX: + binding = PER_VERTEX_INDEXED; + break; + case SoMaterialBindingElement::PER_VERTEX_INDEXED: + binding = PER_VERTEX_INDEXED; + break; + case SoMaterialBindingElement::PER_PART: + case SoMaterialBindingElement::PER_FACE: + binding = PER_FACE_INDEXED; + break; + case SoMaterialBindingElement::PER_PART_INDEXED: + case SoMaterialBindingElement::PER_FACE_INDEXED: + binding = PER_FACE_INDEXED; + break; + default: + break; } return binding; } /** * Renders the triangles of the complete mesh. - * FIXME: Do it the same way as Coin did to have only one implementation which is controlled by defines + * FIXME: Do it the same way as Coin did to have only one implementation which is controlled by + * defines * FIXME: Implement using different values of transparency for each vertex or face */ -void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBundle* mb, - Binding bind, SbBool needNormals, SbBool ccw) const +void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject* mesh, + SoMaterialBundle* mb, + Binding bind, + SbBool needNormals, + SbBool ccw) const { - const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints(); - const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); - if (mesh->countSegments() <= this->index.getValue()) + const MeshCore::MeshPointArray& rPoints = mesh->getKernel().GetPoints(); + const MeshCore::MeshFacetArray& rFacets = mesh->getKernel().GetFacets(); + if (mesh->countSegments() <= this->index.getValue()) { return; - const std::vector rSegm = mesh->getSegment - (this->index.getValue()).getIndices(); + } + const std::vector rSegm = + mesh->getSegment(this->index.getValue()).getIndices(); bool perVertex = (mb && bind == PER_VERTEX_INDEXED); bool perFace = (mb && bind == PER_FACE_INDEXED); - if (needNormals) - { + if (needNormals) { glBegin(GL_TRIANGLES); if (ccw) { // counterclockwise ordering - for (Mesh::FacetIndex it : rSegm) - { + for (Mesh::FacetIndex it : rSegm) { const MeshCore::MeshFacet& f = rFacets[it]; const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[f._aulPoints[1]]; @@ -1309,28 +1350,31 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu // Calculate the normal n = (v1-v0)x(v2-v0) float n[3]; - n[0] = (v1.y-v0.y)*(v2.z-v0.z)-(v1.z-v0.z)*(v2.y-v0.y); - n[1] = (v1.z-v0.z)*(v2.x-v0.x)-(v1.x-v0.x)*(v2.z-v0.z); - n[2] = (v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x); + n[0] = (v1.y - v0.y) * (v2.z - v0.z) - (v1.z - v0.z) * (v2.y - v0.y); + n[1] = (v1.z - v0.z) * (v2.x - v0.x) - (v1.x - v0.x) * (v2.z - v0.z); + n[2] = (v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x); - if(perFace) - mb->send(it, true); + if (perFace) { + mb->send(it, true); + } glNormal(n); - if(perVertex) - mb->send(f._aulPoints[0], true); + if (perVertex) { + mb->send(f._aulPoints[0], true); + } glVertex(v0); - if(perVertex) - mb->send(f._aulPoints[1], true); + if (perVertex) { + mb->send(f._aulPoints[1], true); + } glVertex(v1); - if(perVertex) - mb->send(f._aulPoints[2], true); + if (perVertex) { + mb->send(f._aulPoints[2], true); + } glVertex(v2); } } else { // clockwise ordering - for (Mesh::FacetIndex it : rSegm) - { + for (Mesh::FacetIndex it : rSegm) { const MeshCore::MeshFacet& f = rFacets[it]; const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[f._aulPoints[1]]; @@ -1338,9 +1382,9 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu // Calculate the normal n = -(v1-v0)x(v2-v0) float n[3]; - n[0] = -((v1.y-v0.y)*(v2.z-v0.z)-(v1.z-v0.z)*(v2.y-v0.y)); - n[1] = -((v1.z-v0.z)*(v2.x-v0.x)-(v1.x-v0.x)*(v2.z-v0.z)); - n[2] = -((v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x)); + n[0] = -((v1.y - v0.y) * (v2.z - v0.z) - (v1.z - v0.z) * (v2.y - v0.y)); + n[1] = -((v1.z - v0.z) * (v2.x - v0.x) - (v1.x - v0.x) * (v2.z - v0.z)); + n[2] = -((v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x)); glNormal(n); glVertex(v0); @@ -1352,8 +1396,7 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu } else { glBegin(GL_TRIANGLES); - for (Mesh::FacetIndex it : rSegm) - { + for (Mesh::FacetIndex it : rSegm) { const MeshCore::MeshFacet& f = rFacets[it]; glVertex(rPoints[f._aulPoints[0]]); glVertex(rPoints[f._aulPoints[1]]); @@ -1366,27 +1409,30 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu /** * Renders the gravity points of a subset of triangles. */ -void SoFCMeshSegmentShape::drawPoints(const Mesh::MeshObject * mesh, SbBool needNormals, SbBool ccw) const +void SoFCMeshSegmentShape::drawPoints(const Mesh::MeshObject* mesh, + SbBool needNormals, + SbBool ccw) const { - const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints(); - const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); - if (mesh->countSegments() <= this->index.getValue()) + const MeshCore::MeshPointArray& rPoints = mesh->getKernel().GetPoints(); + const MeshCore::MeshFacetArray& rFacets = mesh->getKernel().GetFacets(); + if (mesh->countSegments() <= this->index.getValue()) { return; - const std::vector rSegm = mesh->getSegment - (this->index.getValue()).getIndices(); - int mod = rSegm.size()/renderTriangleLimit+1; + } + const std::vector rSegm = + mesh->getSegment(this->index.getValue()).getIndices(); + int mod = rSegm.size() / renderTriangleLimit + 1; - float size = std::min((float)mod,3.0f); + float size = std::min((float)mod, 3.0f); glPointSize(size); - if (needNormals) - { + if (needNormals) { glBegin(GL_POINTS); - int ct=0; + int ct = 0; if (ccw) { - for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it, ct++) - { - if (ct%mod==0) { + for (std::vector::const_iterator it = rSegm.begin(); + it != rSegm.end(); + ++it, ct++) { + if (ct % mod == 0) { const MeshCore::MeshFacet& f = rFacets[*it]; const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[f._aulPoints[1]]; @@ -1394,24 +1440,25 @@ void SoFCMeshSegmentShape::drawPoints(const Mesh::MeshObject * mesh, SbBool need // Calculate the normal n = (v1-v0)x(v2-v0) float n[3]; - n[0] = (v1.y-v0.y)*(v2.z-v0.z)-(v1.z-v0.z)*(v2.y-v0.y); - n[1] = (v1.z-v0.z)*(v2.x-v0.x)-(v1.x-v0.x)*(v2.z-v0.z); - n[2] = (v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x); + n[0] = (v1.y - v0.y) * (v2.z - v0.z) - (v1.z - v0.z) * (v2.y - v0.y); + n[1] = (v1.z - v0.z) * (v2.x - v0.x) - (v1.x - v0.x) * (v2.z - v0.z); + n[2] = (v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x); // Calculate the center point p=(v0+v1+v2)/3 float p[3]; - p[0] = (v0.x+v1.x+v2.x)/3.0f; - p[1] = (v0.y+v1.y+v2.y)/3.0f; - p[2] = (v0.z+v1.z+v2.z)/3.0f; + p[0] = (v0.x + v1.x + v2.x) / 3.0f; + p[1] = (v0.y + v1.y + v2.y) / 3.0f; + p[2] = (v0.z + v1.z + v2.z) / 3.0f; glNormal3fv(n); glVertex3fv(p); } } } else { - for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it, ct++) - { - if (ct%mod==0) { + for (std::vector::const_iterator it = rSegm.begin(); + it != rSegm.end(); + ++it, ct++) { + if (ct % mod == 0) { const MeshCore::MeshFacet& f = rFacets[*it]; const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[f._aulPoints[1]]; @@ -1419,15 +1466,15 @@ void SoFCMeshSegmentShape::drawPoints(const Mesh::MeshObject * mesh, SbBool need // Calculate the normal n = -(v1-v0)x(v2-v0) float n[3]; - n[0] = -((v1.y-v0.y)*(v2.z-v0.z)-(v1.z-v0.z)*(v2.y-v0.y)); - n[1] = -((v1.z-v0.z)*(v2.x-v0.x)-(v1.x-v0.x)*(v2.z-v0.z)); - n[2] = -((v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x)); + n[0] = -((v1.y - v0.y) * (v2.z - v0.z) - (v1.z - v0.z) * (v2.y - v0.y)); + n[1] = -((v1.z - v0.z) * (v2.x - v0.x) - (v1.x - v0.x) * (v2.z - v0.z)); + n[2] = -((v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x)); // Calculate the center point p=(v0+v1+v2)/3 float p[3]; - p[0] = (v0.x+v1.x+v2.x)/3.0f; - p[1] = (v0.y+v1.y+v2.y)/3.0f; - p[2] = (v0.z+v1.z+v2.z)/3.0f; + p[0] = (v0.x + v1.x + v2.x) / 3.0f; + p[1] = (v0.y + v1.y + v2.y) / 3.0f; + p[2] = (v0.z + v1.z + v2.z) / 3.0f; glNormal3fv(n); glVertex3fv(p); } @@ -1437,19 +1484,19 @@ void SoFCMeshSegmentShape::drawPoints(const Mesh::MeshObject * mesh, SbBool need } else { glBegin(GL_POINTS); - int ct=0; - for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it, ct++) - { - if (ct%mod==0) { + int ct = 0; + for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); + ++it, ct++) { + if (ct % mod == 0) { const MeshCore::MeshFacet& f = rFacets[*it]; const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[f._aulPoints[1]]; const MeshCore::MeshPoint& v2 = rPoints[f._aulPoints[2]]; // Calculate the center point p=(v0+v1+v2)/3 float p[3]; - p[0] = (v0.x+v1.x+v2.x)/3.0f; - p[1] = (v0.y+v1.y+v2.y)/3.0f; - p[2] = (v0.z+v1.z+v2.z)/3.0f; + p[0] = (v0.x + v1.x + v2.x) / 3.0f; + p[1] = (v0.y + v1.y + v2.y) / 3.0f; + p[2] = (v0.z + v1.z + v2.z) / 3.0f; glVertex3fv(p); } } @@ -1464,20 +1511,24 @@ void SoFCMeshSegmentShape::drawPoints(const Mesh::MeshObject * mesh, SbBool need */ void SoFCMeshSegmentShape::generatePrimitives(SoAction* action) { - SoState* state = action->getState(); + SoState* state = action->getState(); const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); - if (!mesh) + if (!mesh) { return; - const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints(); - const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); - if (rPoints.size() < 3) + } + const MeshCore::MeshPointArray& rPoints = mesh->getKernel().GetPoints(); + const MeshCore::MeshFacetArray& rFacets = mesh->getKernel().GetFacets(); + if (rPoints.size() < 3) { return; - if (rFacets.empty()) + } + if (rFacets.empty()) { return; - if (mesh->countSegments() <= this->index.getValue()) + } + if (mesh->countSegments() <= this->index.getValue()) { return; - const std::vector rSegm = mesh->getSegment - (this->index.getValue()).getIndices(); + } + const std::vector rSegm = + mesh->getSegment(this->index.getValue()).getIndices(); // get material binding Binding mbind = this->findMaterialBinding(state); @@ -1490,10 +1541,8 @@ void SoFCMeshSegmentShape::generatePrimitives(SoAction* action) vertex.setDetail(&pointDetail); beginShape(action, TRIANGLES, &faceDetail); - try - { - for (Mesh::FacetIndex it : rSegm) - { + try { + for (Mesh::FacetIndex it : rSegm) { const MeshCore::MeshFacet& f = rFacets[it]; const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]]; const MeshCore::MeshPoint& v1 = rPoints[f._aulPoints[1]]; @@ -1501,9 +1550,9 @@ void SoFCMeshSegmentShape::generatePrimitives(SoAction* action) // Calculate the normal n = (v1-v0)x(v2-v0) SbVec3f n; - n[0] = (v1.y-v0.y)*(v2.z-v0.z)-(v1.z-v0.z)*(v2.y-v0.y); - n[1] = (v1.z-v0.z)*(v2.x-v0.x)-(v1.x-v0.x)*(v2.z-v0.z); - n[2] = (v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x); + n[0] = (v1.y - v0.y) * (v2.z - v0.z) - (v1.z - v0.z) * (v2.y - v0.y); + n[1] = (v1.z - v0.z) * (v2.x - v0.x) - (v1.x - v0.x) * (v2.z - v0.z); + n[2] = (v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x); // Set the normal vertex.setNormal(n); @@ -1549,13 +1598,13 @@ void SoFCMeshSegmentShape::generatePrimitives(SoAction* action) /** * Sets the bounding box of the mesh to \a box and its center to \a center. */ -void SoFCMeshSegmentShape::computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er) +void SoFCMeshSegmentShape::computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center) { - box.setBounds(SbVec3f(0,0,0), SbVec3f(0,0,0)); - center.setValue(0.0f,0.0f,0.0f); + box.setBounds(SbVec3f(0, 0, 0), SbVec3f(0, 0, 0)); + center.setValue(0.0f, 0.0f, 0.0f); - SoState* state = action->getState(); - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); + SoState* state = action->getState(); + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); if (mesh && mesh->countSegments() > this->index.getValue()) { const Mesh::Segment& segm = mesh->getSegment(this->index.getValue()); const std::vector& indices = segm.getIndices(); @@ -1571,10 +1620,10 @@ void SoFCMeshSegmentShape::computeBBox(SoAction *action, SbBox3f &box, SbVec3f & cBox.Add(rPoint[face._aulPoints[2]]); } - box.setBounds(SbVec3f(cBox.MinX,cBox.MinY,cBox.MinZ), - SbVec3f(cBox.MaxX,cBox.MaxY,cBox.MaxZ)); + box.setBounds(SbVec3f(cBox.MinX, cBox.MinY, cBox.MinZ), + SbVec3f(cBox.MaxX, cBox.MaxY, cBox.MaxZ)); Base::Vector3f mid = cBox.GetCenter(); - center.setValue(mid.x,mid.y,mid.z); + center.setValue(mid.x, mid.y, mid.z); } } } @@ -1582,12 +1631,13 @@ void SoFCMeshSegmentShape::computeBBox(SoAction *action, SbBox3f &box, SbVec3f & /** * Adds the number of the triangles to the \a SoGetPrimitiveCountAction. */ -void SoFCMeshSegmentShape::getPrimitiveCount(SoGetPrimitiveCountAction * action) +void SoFCMeshSegmentShape::getPrimitiveCount(SoGetPrimitiveCountAction* action) { - if (!this->shouldPrimitiveCount(action)) + if (!this->shouldPrimitiveCount(action)) { return; - SoState* state = action->getState(); - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); + } + SoState* state = action->getState(); + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); if (mesh && mesh->countSegments() > this->index.getValue()) { const Mesh::Segment& segm = mesh->getSegment(this->index.getValue()); action->addNumTriangles(segm.getIndices().size()); @@ -1611,14 +1661,14 @@ SoFCMeshObjectBoundary::SoFCMeshObjectBoundary() /** * Renders the open edges only. */ -void SoFCMeshObjectBoundary::GLRender(SoGLRenderAction *action) +void SoFCMeshObjectBoundary::GLRender(SoGLRenderAction* action) { - if (shouldGLRender(action)) - { - SoState* state = action->getState(); - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); - if (!mesh) + if (shouldGLRender(action)) { + SoState* state = action->getState(); + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); + if (!mesh) { return; + } SoMaterialBundle mb(action); SoTextureCoordinateBundle tb(action, true, false); @@ -1632,24 +1682,24 @@ void SoFCMeshObjectBoundary::GLRender(SoGLRenderAction *action) /** * Renders the triangles of the complete mesh. */ -void SoFCMeshObjectBoundary::drawLines(const Mesh::MeshObject * mesh) const +void SoFCMeshObjectBoundary::drawLines(const Mesh::MeshObject* mesh) const { - const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints(); - const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); + const MeshCore::MeshPointArray& rPoints = mesh->getKernel().GetPoints(); + const MeshCore::MeshFacetArray& rFacets = mesh->getKernel().GetFacets(); // When rendering open edges use the given line width * 3 GLfloat lineWidth; glGetFloatv(GL_LINE_WIDTH, &lineWidth); - glLineWidth(3.0f*lineWidth); + glLineWidth(3.0f * lineWidth); // Use the data structure directly and not through MeshFacetIterator as this // class is quite slowly (at least for rendering) glBegin(GL_LINES); - for (const auto & rFacet : rFacets) { - for (int i=0; i<3; i++) { + for (const auto& rFacet : rFacets) { + for (int i = 0; i < 3; i++) { if (rFacet._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) { glVertex(rPoints[rFacet._aulPoints[i]]); - glVertex(rPoints[rFacet._aulPoints[(i+1)%3]]); + glVertex(rPoints[rFacet._aulPoints[(i + 1) % 3]]); } } } @@ -1661,12 +1711,13 @@ void SoFCMeshObjectBoundary::generatePrimitives(SoAction* action) { // do not create primitive information as an SoFCMeshObjectShape // should already be used that delivers the information - SoState* state = action->getState(); + SoState* state = action->getState(); const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); - if (!mesh) + if (!mesh) { return; - const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints(); - const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); + } + const MeshCore::MeshPointArray& rPoints = mesh->getKernel().GetPoints(); + const MeshCore::MeshFacetArray& rFacets = mesh->getKernel().GetFacets(); // Create the information when moving over or picking into the scene SoPrimitiveVertex vertex; @@ -1676,12 +1727,11 @@ void SoFCMeshObjectBoundary::generatePrimitives(SoAction* action) vertex.setDetail(&pointDetail); beginShape(action, LINES, &lineDetail); - for (const auto & rFacet : rFacets) - { - for (int i=0; i<3; i++) { + for (const auto& rFacet : rFacets) { + for (int i = 0; i < 3; i++) { if (rFacet._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) { const MeshCore::MeshPoint& v0 = rPoints[rFacet._aulPoints[i]]; - const MeshCore::MeshPoint& v1 = rPoints[rFacet._aulPoints[(i+1)%3]]; + const MeshCore::MeshPoint& v1 = rPoints[rFacet._aulPoints[(i + 1) % 3]]; // Vertex 0 pointDetail.setCoordinateIndex(rFacet._aulPoints[i]); @@ -1689,7 +1739,7 @@ void SoFCMeshObjectBoundary::generatePrimitives(SoAction* action) shapeVertex(&vertex); // Vertex 1 - pointDetail.setCoordinateIndex(rFacet._aulPoints[(i+1)%3]); + pointDetail.setCoordinateIndex(rFacet._aulPoints[(i + 1) % 3]); vertex.setPoint(sbvec3f(v1)); shapeVertex(&vertex); @@ -1705,44 +1755,48 @@ void SoFCMeshObjectBoundary::generatePrimitives(SoAction* action) /** * Sets the bounding box of the mesh to \a box and its center to \a center. */ -void SoFCMeshObjectBoundary::computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er) +void SoFCMeshObjectBoundary::computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center) { - SoState* state = action->getState(); - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); - if (!mesh) + SoState* state = action->getState(); + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); + if (!mesh) { return; - const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints(); + } + const MeshCore::MeshPointArray& rPoints = mesh->getKernel().GetPoints(); if (!rPoints.empty()) { Base::BoundBox3f cBox; - for (const auto & rPoint : rPoints) + for (const auto& rPoint : rPoints) { cBox.Add(rPoint); - box.setBounds(SbVec3f(cBox.MinX,cBox.MinY,cBox.MinZ), - SbVec3f(cBox.MaxX,cBox.MaxY,cBox.MaxZ)); + } + box.setBounds(SbVec3f(cBox.MinX, cBox.MinY, cBox.MinZ), + SbVec3f(cBox.MaxX, cBox.MaxY, cBox.MaxZ)); Base::Vector3f mid = cBox.GetCenter(); - center.setValue(mid.x,mid.y,mid.z); + center.setValue(mid.x, mid.y, mid.z); } else { - box.setBounds(SbVec3f(0,0,0), SbVec3f(0,0,0)); - center.setValue(0.0f,0.0f,0.0f); + box.setBounds(SbVec3f(0, 0, 0), SbVec3f(0, 0, 0)); + center.setValue(0.0f, 0.0f, 0.0f); } } /** * Adds the number of the triangles to the \a SoGetPrimitiveCountAction. */ -void SoFCMeshObjectBoundary::getPrimitiveCount(SoGetPrimitiveCountAction * action) +void SoFCMeshObjectBoundary::getPrimitiveCount(SoGetPrimitiveCountAction* action) { - if (!this->shouldPrimitiveCount(action)) + if (!this->shouldPrimitiveCount(action)) { return; - SoState* state = action->getState(); - const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); - if (!mesh) + } + SoState* state = action->getState(); + const Mesh::MeshObject* mesh = SoFCMeshObjectElement::get(state); + if (!mesh) { return; - const MeshCore::MeshFacetArray & rFaces = mesh->getKernel().GetFacets(); + } + const MeshCore::MeshFacetArray& rFaces = mesh->getKernel().GetFacets(); // Count number of open edges first - int ctEdges=0; - for (const auto & rFace : rFaces) { + int ctEdges = 0; + for (const auto& rFace : rFaces) { for (Mesh::FacetIndex nbIndex : rFace._aulNeighbours) { if (nbIndex == MeshCore::FACET_INDEX_MAX) { ctEdges++; diff --git a/src/Mod/Mesh/Gui/SoFCMeshObject.h b/src/Mod/Mesh/Gui/SoFCMeshObject.h index ac0adf5199..8dd008c233 100644 --- a/src/Mod/Mesh/Gui/SoFCMeshObject.h +++ b/src/Mod/Mesh/Gui/SoFCMeshObject.h @@ -23,12 +23,12 @@ #ifndef MESHGUI_SOFCMESHOBJECT_H #define MESHGUI_SOFCMESHOBJECT_H -#include +#include #include #include #include +#include #include -#include #include @@ -36,14 +36,21 @@ using GLuint = unsigned int; using GLint = int; using GLfloat = float; -namespace MeshCore { class MeshFacetGrid; } +namespace MeshCore +{ +class MeshFacetGrid; +} -namespace MeshGui { +namespace MeshGui +{ -class MeshGuiExport SoSFMeshObject : public SoSField { +class MeshGuiExport SoSFMeshObject: public SoSField +{ using inherited = SoSField; - SO_SFIELD_HEADER(SoSFMeshObject, Base::Reference, Base::Reference) + SO_SFIELD_HEADER(SoSFMeshObject, + Base::Reference, + Base::Reference) public: static void initClass(); @@ -53,7 +60,8 @@ public: // ------------------------------------------------------- -class MeshGuiExport SoFCMeshObjectElement : public SoReplacedElement { +class MeshGuiExport SoFCMeshObjectElement: public SoReplacedElement +{ using inherited = SoReplacedElement; SO_ELEMENT_HEADER(SoFCMeshObjectElement); @@ -61,20 +69,21 @@ class MeshGuiExport SoFCMeshObjectElement : public SoReplacedElement { public: static void initClass(); - void init(SoState * state) override; - static void set(SoState * const state, SoNode * const node, const Mesh::MeshObject * const mesh); - static const Mesh::MeshObject * get(SoState * const state); - static const SoFCMeshObjectElement * getInstance(SoState * state); - void print(FILE * file) const override; + void init(SoState* state) override; + static void set(SoState* const state, SoNode* const node, const Mesh::MeshObject* const mesh); + static const Mesh::MeshObject* get(SoState* const state); + static const SoFCMeshObjectElement* getInstance(SoState* state); + void print(FILE* file) const override; protected: ~SoFCMeshObjectElement() override; - const Mesh::MeshObject *mesh; + const Mesh::MeshObject* mesh; }; // ------------------------------------------------------- -class MeshGuiExport SoFCMeshPickNode : public SoNode { +class MeshGuiExport SoFCMeshPickNode: public SoNode +{ using inherited = SoNode; SO_NODE_HEADER(SoFCMeshPickNode); @@ -82,23 +91,24 @@ class MeshGuiExport SoFCMeshPickNode : public SoNode { public: static void initClass(); SoFCMeshPickNode(); - void notify(SoNotList *) override; + void notify(SoNotList*) override; SoSFMeshObject mesh; - void rayPick(SoRayPickAction * action) override; - void pick(SoPickAction * action) override; + void rayPick(SoRayPickAction* action) override; + void pick(SoPickAction* action) override; protected: ~SoFCMeshPickNode() override; private: - MeshCore::MeshFacetGrid* meshGrid{nullptr}; + MeshCore::MeshFacetGrid* meshGrid {nullptr}; }; // ------------------------------------------------------- -class MeshGuiExport SoFCMeshGridNode : public SoNode { +class MeshGuiExport SoFCMeshGridNode: public SoNode +{ using inherited = SoNode; SO_NODE_HEADER(SoFCMeshGridNode); @@ -106,7 +116,7 @@ class MeshGuiExport SoFCMeshGridNode : public SoNode { public: static void initClass(); SoFCMeshGridNode(); - void GLRender(SoGLRenderAction * action) override; + void GLRender(SoGLRenderAction* action) override; SoSFVec3f minGrid; SoSFVec3f maxGrid; @@ -118,7 +128,8 @@ protected: // ------------------------------------------------------- -class MeshGuiExport SoFCMeshObjectNode : public SoNode { +class MeshGuiExport SoFCMeshObjectNode: public SoNode +{ using inherited = SoNode; SO_NODE_HEADER(SoFCMeshObjectNode); @@ -129,12 +140,12 @@ public: SoSFMeshObject mesh; - void doAction(SoAction * action) override; - void GLRender(SoGLRenderAction * action) override; - void callback(SoCallbackAction * action) override; - void getBoundingBox(SoGetBoundingBoxAction * action) override; - void pick(SoPickAction * action) override; - void getPrimitiveCount(SoGetPrimitiveCountAction * action) override; + void doAction(SoAction* action) override; + void GLRender(SoGLRenderAction* action) override; + void callback(SoCallbackAction* action) override; + void getBoundingBox(SoGetBoundingBoxAction* action) override; + void pick(SoPickAction* action) override; + void getPrimitiveCount(SoGetPrimitiveCountAction* action) override; protected: ~SoFCMeshObjectNode() override; @@ -160,7 +171,8 @@ protected: * * @author Werner Mayer */ -class MeshGuiExport SoFCMeshObjectShape : public SoShape { +class MeshGuiExport SoFCMeshObjectShape: public SoShape +{ using inherited = SoShape; SO_NODE_HEADER(SoFCMeshObjectShape); @@ -172,22 +184,23 @@ public: unsigned int renderTriangleLimit; protected: - void doAction(SoAction * action) override; - void GLRender(SoGLRenderAction *action) override; - void computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er) override; - void getPrimitiveCount(SoGetPrimitiveCountAction * action) override; - void rayPick (SoRayPickAction *action) override; - void generatePrimitives(SoAction *action) override; - SoDetail * createTriangleDetail(SoRayPickAction * action, - const SoPrimitiveVertex * v1, - const SoPrimitiveVertex * v2, - const SoPrimitiveVertex * v3, - SoPickedPoint * pp) override; + void doAction(SoAction* action) override; + void GLRender(SoGLRenderAction* action) override; + void computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center) override; + void getPrimitiveCount(SoGetPrimitiveCountAction* action) override; + void rayPick(SoRayPickAction* action) override; + void generatePrimitives(SoAction* action) override; + SoDetail* createTriangleDetail(SoRayPickAction* action, + const SoPrimitiveVertex* v1, + const SoPrimitiveVertex* v2, + const SoPrimitiveVertex* v3, + SoPickedPoint* pp) override; // Force using the reference count mechanism. ~SoFCMeshObjectShape() override; private: - enum Binding { + enum Binding + { OVERALL = 0, PER_FACE_INDEXED, PER_VERTEX_INDEXED, @@ -195,33 +208,37 @@ private: }; private: - void notify(SoNotList * list) override; - Binding findMaterialBinding(SoState * const state) const; + void notify(SoNotList* list) override; + Binding findMaterialBinding(SoState* const state) const; // Draw faces - void drawFaces(const Mesh::MeshObject *, SoMaterialBundle* mb, Binding bind, - SbBool needNormals, SbBool ccw) const; - void drawPoints(const Mesh::MeshObject *, SbBool needNormals, SbBool ccw) const; - unsigned int countTriangles(SoAction * action) const; + void drawFaces(const Mesh::MeshObject*, + SoMaterialBundle* mb, + Binding bind, + SbBool needNormals, + SbBool ccw) const; + void drawPoints(const Mesh::MeshObject*, SbBool needNormals, SbBool ccw) const; + unsigned int countTriangles(SoAction* action) const; - void startSelection(SoAction * action, const Mesh::MeshObject*); - void stopSelection(SoAction * action, const Mesh::MeshObject*); + void startSelection(SoAction* action, const Mesh::MeshObject*); + void stopSelection(SoAction* action, const Mesh::MeshObject*); void renderSelectionGeometry(const Mesh::MeshObject*); - void generateGLArrays(SoState * state); - void renderFacesGLArray(SoGLRenderAction *action); - void renderCoordsGLArray(SoGLRenderAction *action); + void generateGLArrays(SoState* state); + void renderFacesGLArray(SoGLRenderAction* action); + void renderCoordsGLArray(SoGLRenderAction* action); private: - GLuint *selectBuf{nullptr}; - GLfloat modelview[16]{}; - GLfloat projection[16]{}; + GLuint* selectBuf {nullptr}; + GLfloat modelview[16] {}; + GLfloat projection[16] {}; // Vertex array handling std::vector index_array; std::vector vertex_array; - SbBool updateGLArray{false}; + SbBool updateGLArray {false}; }; -class MeshGuiExport SoFCMeshSegmentShape : public SoShape { +class MeshGuiExport SoFCMeshSegmentShape: public SoShape +{ using inherited = SoShape; SO_NODE_HEADER(SoFCMeshSegmentShape); @@ -234,15 +251,16 @@ public: unsigned int renderTriangleLimit; protected: - void GLRender(SoGLRenderAction *action) override; - void computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er) override; - void getPrimitiveCount(SoGetPrimitiveCountAction * action) override; - void generatePrimitives(SoAction *action) override; + void GLRender(SoGLRenderAction* action) override; + void computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center) override; + void getPrimitiveCount(SoGetPrimitiveCountAction* action) override; + void generatePrimitives(SoAction* action) override; // Force using the reference count mechanism. ~SoFCMeshSegmentShape() override = default; private: - enum Binding { + enum Binding + { OVERALL = 0, PER_FACE_INDEXED, PER_VERTEX_INDEXED, @@ -250,14 +268,18 @@ private: }; private: - Binding findMaterialBinding(SoState * const state) const; + Binding findMaterialBinding(SoState* const state) const; // Draw faces - void drawFaces(const Mesh::MeshObject *, SoMaterialBundle* mb, Binding bind, - SbBool needNormals, SbBool ccw) const; - void drawPoints(const Mesh::MeshObject *, SbBool needNormals, SbBool ccw) const; + void drawFaces(const Mesh::MeshObject*, + SoMaterialBundle* mb, + Binding bind, + SbBool needNormals, + SbBool ccw) const; + void drawPoints(const Mesh::MeshObject*, SbBool needNormals, SbBool ccw) const; }; -class MeshGuiExport SoFCMeshObjectBoundary : public SoShape { +class MeshGuiExport SoFCMeshObjectBoundary: public SoShape +{ using inherited = SoShape; SO_NODE_HEADER(SoFCMeshObjectBoundary); @@ -267,19 +289,18 @@ public: SoFCMeshObjectBoundary(); protected: - void GLRender(SoGLRenderAction *action) override; - void computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er) override; - void getPrimitiveCount(SoGetPrimitiveCountAction * action) override; - void generatePrimitives(SoAction *action) override; + void GLRender(SoGLRenderAction* action) override; + void computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center) override; + void getPrimitiveCount(SoGetPrimitiveCountAction* action) override; + void generatePrimitives(SoAction* action) override; // Force using the reference count mechanism. ~SoFCMeshObjectBoundary() override = default; private: - void drawLines(const Mesh::MeshObject *) const ; + void drawLines(const Mesh::MeshObject*) const; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_SOFCMESHOBJECT_H - +#endif // MESHGUI_SOFCMESHOBJECT_H diff --git a/src/Mod/Mesh/Gui/SoPolygon.cpp b/src/Mod/Mesh/Gui/SoPolygon.cpp index a25c8695a1..572bd2a086 100644 --- a/src/Mod/Mesh/Gui/SoPolygon.cpp +++ b/src/Mod/Mesh/Gui/SoPolygon.cpp @@ -22,23 +22,23 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# ifdef FC_OS_WIN32 -# include -# endif -# ifdef FC_OS_MACOSX -# include -# else -# include -# endif -# include -# include +#ifdef FC_OS_WIN32 +#include +#endif +#ifdef FC_OS_MACOSX +#include +#else +#include +#endif +#include +#include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include #endif #include "SoPolygon.h" @@ -66,17 +66,18 @@ SoPolygon::SoPolygon() /** * Renders the polygon. */ -void SoPolygon::GLRender(SoGLRenderAction *action) +void SoPolygon::GLRender(SoGLRenderAction* action) { - if (shouldGLRender(action) && render.getValue()) - { - SoState* state = action->getState(); - const SoCoordinateElement * coords = SoCoordinateElement::getInstance(state); - if (!coords) + if (shouldGLRender(action) && render.getValue()) { + SoState* state = action->getState(); + const SoCoordinateElement* coords = SoCoordinateElement::getInstance(state); + if (!coords) { return; - const SbVec3f * points = coords->getArrayPtr3(); - if (!points) + } + const SbVec3f* points = coords->getArrayPtr3(); + if (!points) { return; + } SoMaterialBundle mb(action); SoTextureCoordinateBundle tb(action, true, false); @@ -91,18 +92,19 @@ void SoPolygon::GLRender(SoGLRenderAction *action) /** * Renders the polygon. */ -void SoPolygon::drawPolygon(const SbVec3f * points,int32_t len) const +void SoPolygon::drawPolygon(const SbVec3f* points, int32_t len) const { glLineWidth(3.0f); int32_t beg = startIndex.getValue(); int32_t cnt = numVertices.getValue(); int32_t end = beg + cnt; - if (end > len) - return; // wrong setup, too few points + if (end > len) { + return; // wrong setup, too few points + } // draw control mesh glBegin(GL_LINES); for (int32_t i = beg; i < end; ++i) { - int32_t j = (i-beg+1) % cnt + beg; + int32_t j = (i - beg + 1) % cnt + beg; glVertex3fv(points[i].getValue()); glVertex3fv(points[j].getValue()); } @@ -112,11 +114,10 @@ void SoPolygon::drawPolygon(const SbVec3f * points,int32_t len) const /** * Calculates picked point based on primitives generated by subclasses. */ -void -SoPolygon::rayPick(SoRayPickAction * action) +void SoPolygon::rayPick(SoRayPickAction* action) { - //if (this->shouldRayPick(action)) { - // this->computeObjectSpaceRay(action); + // if (this->shouldRayPick(action)) { + // this->computeObjectSpaceRay(action); // const SoBoundingBoxCache* bboxcache = getBoundingBoxCache(); // if (!bboxcache || !bboxcache->isValid(action->getState()) || @@ -128,43 +129,43 @@ SoPolygon::rayPick(SoRayPickAction * action) } void SoPolygon::generatePrimitives(SoAction* /*action*/) -{ -} +{} /** * Sets the bounding box of the mesh to \a box and its center to \a center. */ -void SoPolygon::computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er) +void SoPolygon::computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center) { - SoState* state = action->getState(); - const SoCoordinateElement * coords = SoCoordinateElement::getInstance(state); - if (!coords) + SoState* state = action->getState(); + const SoCoordinateElement* coords = SoCoordinateElement::getInstance(state); + if (!coords) { return; - const SbVec3f * points = coords->getArrayPtr3(); - if (!points) + } + const SbVec3f* points = coords->getArrayPtr3(); + if (!points) { return; - float maxX=-FLT_MAX, minX=FLT_MAX, - maxY=-FLT_MAX, minY=FLT_MAX, - maxZ=-FLT_MAX, minZ=FLT_MAX; + } + float maxX = -FLT_MAX, minX = FLT_MAX, maxY = -FLT_MAX, minY = FLT_MAX, maxZ = -FLT_MAX, + minZ = FLT_MAX; int32_t len = coords->getNum(); int32_t beg = startIndex.getValue(); int32_t cnt = numVertices.getValue(); int32_t end = beg + cnt; if (end <= len) { - for (int32_t i=beg; i(maxX,points[i][0]); - minX = std::min(minX,points[i][0]); - maxY = std::max(maxY,points[i][1]); - minY = std::min(minY,points[i][1]); - maxZ = std::max(maxZ,points[i][2]); - minZ = std::min(minZ,points[i][2]); + for (int32_t i = beg; i < end; i++) { + maxX = std::max(maxX, points[i][0]); + minX = std::min(minX, points[i][0]); + maxY = std::max(maxY, points[i][1]); + minY = std::min(minY, points[i][1]); + maxZ = std::max(maxZ, points[i][2]); + minZ = std::min(minZ, points[i][2]); } - box.setBounds(minX,minY,minZ,maxX,maxY,maxZ); - center.setValue(0.5f*(minX+maxX),0.5f*(minY+maxY),0.5f*(minZ+maxZ)); + box.setBounds(minX, minY, minZ, maxX, maxY, maxZ); + center.setValue(0.5f * (minX + maxX), 0.5f * (minY + maxY), 0.5f * (minZ + maxZ)); } else { - box.setBounds(SbVec3f(0,0,0), SbVec3f(0,0,0)); - center.setValue(0.0f,0.0f,0.0f); + box.setBounds(SbVec3f(0, 0, 0), SbVec3f(0, 0, 0)); + center.setValue(0.0f, 0.0f, 0.0f); } } diff --git a/src/Mod/Mesh/Gui/SoPolygon.h b/src/Mod/Mesh/Gui/SoPolygon.h index afa4d1df0a..0801d99ae2 100644 --- a/src/Mod/Mesh/Gui/SoPolygon.h +++ b/src/Mod/Mesh/Gui/SoPolygon.h @@ -28,13 +28,15 @@ #include #include #ifndef MESH_GLOBAL_H -# include +#include #endif -namespace MeshGui { +namespace MeshGui +{ -class MeshGuiExport SoPolygon : public SoShape { +class MeshGuiExport SoPolygon: public SoShape +{ using inherited = SoShape; SO_NODE_HEADER(SoPolygon); @@ -45,22 +47,21 @@ public: SoSFInt32 startIndex; SoSFInt32 numVertices; - SoSFBool highlight; - SoSFBool render; + SoSFBool highlight; + SoSFBool render; protected: ~SoPolygon() override = default; - void GLRender(SoGLRenderAction *action) override; - void computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er) override; - void rayPick (SoRayPickAction *action) override; - void generatePrimitives(SoAction *action) override; + void GLRender(SoGLRenderAction* action) override; + void computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center) override; + void rayPick(SoRayPickAction* action) override; + void generatePrimitives(SoAction* action) override; private: - void drawPolygon(const SbVec3f *,int32_t) const; + void drawPolygon(const SbVec3f*, int32_t) const; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_SOPOLYGON_H - +#endif // MESHGUI_SOPOLYGON_H diff --git a/src/Mod/Mesh/Gui/ThumbnailExtension.cpp b/src/Mod/Mesh/Gui/ThumbnailExtension.cpp index 0a15266feb..6a678216d6 100644 --- a/src/Mod/Mesh/Gui/ThumbnailExtension.cpp +++ b/src/Mod/Mesh/Gui/ThumbnailExtension.cpp @@ -22,16 +22,16 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -42,7 +42,7 @@ using namespace MeshGui; -Mesh::Extension3MF::Resource ThumbnailExtension3MF::addMesh(const Mesh::MeshObject &mesh) +Mesh::Extension3MF::Resource ThumbnailExtension3MF::addMesh(const Mesh::MeshObject& mesh) { SoCoordinate3* coord = new SoCoordinate3(); SoIndexedFaceSet* faces = new SoIndexedFaceSet(); @@ -78,7 +78,8 @@ Mesh::Extension3MF::Resource ThumbnailExtension3MF::addMesh(const Mesh::MeshObje Mesh::Extension3MF::Resource res; res.extension = "png"; res.contentType = "image/png"; - res.relationshipType = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail"; + res.relationshipType = + "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail"; res.fileContent = std::string(data.data(), data.size()); setContentName(res); diff --git a/src/Mod/Mesh/Gui/ThumbnailExtension.h b/src/Mod/Mesh/Gui/ThumbnailExtension.h index e773e40b86..4b80c074a4 100644 --- a/src/Mod/Mesh/Gui/ThumbnailExtension.h +++ b/src/Mod/Mesh/Gui/ThumbnailExtension.h @@ -23,14 +23,16 @@ #ifndef MESHGUI_THUMBNAIL_EXTENSION_H #define MESHGUI_THUMBNAIL_EXTENSION_H -#include #include +#include -namespace MeshGui { +namespace MeshGui +{ -class ThumbnailExtension3MF : public Mesh::Extension3MF { +class ThumbnailExtension3MF: public Mesh::Extension3MF +{ public: - Mesh::Extension3MF::Resource addMesh(const Mesh::MeshObject & mesh) override; + Mesh::Extension3MF::Resource addMesh(const Mesh::MeshObject& mesh) override; private: void setContentName(Mesh::Extension3MF::Resource&); @@ -39,15 +41,18 @@ private: int index = 0; }; -class ThumbnailExtensionProducer : public Mesh::Extension3MFProducer { +class ThumbnailExtensionProducer: public Mesh::Extension3MFProducer +{ public: - Mesh::AbstractFormatExtensionPtr create() const override { + Mesh::AbstractFormatExtensionPtr create() const override + { return std::make_shared(); } - void initialize() override {} + void initialize() override + {} }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_THUMBNAIL_EXTENSION_H +#endif // MESHGUI_THUMBNAIL_EXTENSION_H diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index d16a0e468e..a2dbc6c431 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -22,37 +22,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 -# 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 +#include #include #include @@ -68,15 +68,14 @@ #include #include #include +#include #include #include #include -#include #include +#include #include #include -#include -#include #include #include #include @@ -84,28 +83,30 @@ #include #include #include +#include #include #include -#include "ViewProvider.h" #include "SoFCIndexedFaceSet.h" #include "SoFCMeshObject.h" +#include "ViewProvider.h" using namespace MeshGui; namespace sp = std::placeholders; using Mesh::Feature; -using MeshCore::MeshKernel; -using MeshCore::MeshPointIterator; +using MeshCore::MeshFacet; using MeshCore::MeshFacetIterator; using MeshCore::MeshGeomFacet; -using MeshCore::MeshFacet; +using MeshCore::MeshKernel; +using MeshCore::MeshPointIterator; -void ViewProviderMeshBuilder::buildNodes(const App::Property* prop, std::vector& nodes) const +void ViewProviderMeshBuilder::buildNodes(const App::Property* prop, + std::vector& nodes) const { - SoCoordinate3 *pcPointsCoord=nullptr; - SoIndexedFaceSet *pcFaces=nullptr; + SoCoordinate3* pcPointsCoord = nullptr; + SoIndexedFaceSet* pcFaces = nullptr; if (nodes.empty()) { pcPointsCoord = new SoCoordinate3(); @@ -114,46 +115,53 @@ void ViewProviderMeshBuilder::buildNodes(const App::Property* prop, std::vector< nodes.push_back(pcFaces); } else if (nodes.size() == 2) { - if (nodes[0]->getTypeId() == SoCoordinate3::getClassTypeId()) + if (nodes[0]->getTypeId() == SoCoordinate3::getClassTypeId()) { pcPointsCoord = static_cast(nodes[0]); - if (nodes[1]->getTypeId() == SoIndexedFaceSet::getClassTypeId()) + } + if (nodes[1]->getTypeId() == SoIndexedFaceSet::getClassTypeId()) { pcFaces = static_cast(nodes[1]); + } } - if (pcPointsCoord && pcFaces) + if (pcPointsCoord && pcFaces) { createMesh(prop, pcPointsCoord, pcFaces); + } } -void ViewProviderMeshBuilder::createMesh(const App::Property* prop, SoCoordinate3* coords, SoIndexedFaceSet* faces) const +void ViewProviderMeshBuilder::createMesh(const App::Property* prop, + SoCoordinate3* coords, + SoIndexedFaceSet* faces) const { const Mesh::PropertyMeshKernel* mesh = static_cast(prop); const MeshCore::MeshKernel& rcMesh = mesh->getValue().getKernel(); createMesh(rcMesh, coords, faces); } -void ViewProviderMeshBuilder::createMesh(const MeshCore::MeshKernel& kernel, SoCoordinate3* coords, SoIndexedFaceSet* faces) const +void ViewProviderMeshBuilder::createMesh(const MeshCore::MeshKernel& kernel, + SoCoordinate3* coords, + SoIndexedFaceSet* faces) const { // set the point coordinates const MeshCore::MeshPointArray& cP = kernel.GetPoints(); coords->point.setNum(kernel.CountPoints()); SbVec3f* verts = coords->point.startEditing(); - int i=0; + int i = 0; for (MeshCore::MeshPointArray::_TConstIterator it = cP.begin(); it != cP.end(); ++it, i++) { verts[i].setValue(it->x, it->y, it->z); } coords->point.finishEditing(); // set the face indices - int j=0; + int j = 0; const MeshCore::MeshFacetArray& cF = kernel.GetFacets(); - faces->coordIndex.setNum(4*kernel.CountFacets()); + faces->coordIndex.setNum(4 * kernel.CountFacets()); int32_t* indices = faces->coordIndex.startEditing(); for (MeshCore::MeshFacetArray::_TConstIterator it = cF.begin(); it != cF.end(); ++it, j++) { - for (int i=0; i<3; i++) { - indices[4*j+i] = it->_aulPoints[i]; + for (int i = 0; i < 3; i++) { + indices[4 * j + i] = it->_aulPoints[i]; } - indices[4*j+3] = SO_END_FACE_INDEX; + indices[4 * j + 3] = SO_END_FACE_INDEX; } faces->coordIndex.finishEditing(); } @@ -178,6 +186,7 @@ const char* ViewProviderExport::getDefaultDisplayMode() const QIcon ViewProviderExport::getIcon() const { + // clang-format off const char * Mesh_Feature_xpm[] = { "22 22 6 1", ". c None", @@ -210,6 +219,7 @@ QIcon ViewProviderExport::getIcon() const "......................"}; QPixmap px(Mesh_Feature_xpm); return px; + // clang-format on } // ------------------------------------------------------ @@ -217,33 +227,39 @@ QIcon ViewProviderExport::getIcon() const App::PropertyFloatConstraint::Constraints ViewProviderMesh::floatRange = {1.0f, 64.0f, 1.0f}; App::PropertyFloatConstraint::Constraints ViewProviderMesh::angleRange = {0.0f, 180.0f, 1.0f}; App::PropertyIntegerConstraint::Constraints ViewProviderMesh::intPercent = {0, 100, 5}; -const char* ViewProviderMesh::LightingEnums[]= {"One side", "Two side", nullptr}; +const char* ViewProviderMesh::LightingEnums[] = {"One side", "Two side", nullptr}; PROPERTY_SOURCE(MeshGui::ViewProviderMesh, Gui::ViewProviderGeometryObject) -ViewProviderMesh::ViewProviderMesh() : highlightMode{HighlighMode::None} +ViewProviderMesh::ViewProviderMesh() + : highlightMode {HighlighMode::None} { - static const char *osgroup = "Object Style"; + static const char* osgroup = "Object Style"; - ADD_PROPERTY_TYPE(LineTransparency,(0), osgroup, App::Prop_None, "Set line transparency."); + ADD_PROPERTY_TYPE(LineTransparency, (0), osgroup, App::Prop_None, "Set line transparency."); LineTransparency.setConstraints(&intPercent); - ADD_PROPERTY_TYPE(LineWidth,(1.0f), osgroup, App::Prop_None, "Set line width."); + ADD_PROPERTY_TYPE(LineWidth, (1.0f), osgroup, App::Prop_None, "Set line width."); LineWidth.setConstraints(&floatRange); - ADD_PROPERTY_TYPE(PointSize,(2.0f), osgroup, App::Prop_None, "Set point size."); + ADD_PROPERTY_TYPE(PointSize, (2.0f), osgroup, App::Prop_None, "Set point size."); PointSize.setConstraints(&floatRange); - ADD_PROPERTY_TYPE(CreaseAngle,(0.0f), osgroup, App::Prop_None, "Set crease angle."); + ADD_PROPERTY_TYPE(CreaseAngle, (0.0f), osgroup, App::Prop_None, "Set crease angle."); CreaseAngle.setConstraints(&angleRange); - ADD_PROPERTY_TYPE(OpenEdges,(false), osgroup, App::Prop_None, "Set open edges."); - ADD_PROPERTY_TYPE(Coloring,(false), osgroup, App::Prop_None, "Set coloring."); - ADD_PROPERTY_TYPE(Lighting,(1), osgroup, App::Prop_None, "Set if the illumination comes from two sides\n or one side in the 3D view."); + ADD_PROPERTY_TYPE(OpenEdges, (false), osgroup, App::Prop_None, "Set open edges."); + ADD_PROPERTY_TYPE(Coloring, (false), osgroup, App::Prop_None, "Set coloring."); + ADD_PROPERTY_TYPE(Lighting, + (1), + osgroup, + App::Prop_None, + "Set if the illumination comes from two sides\n or one side in the 3D view."); Lighting.setEnums(LightingEnums); - ADD_PROPERTY_TYPE(LineColor,(0,0,0), osgroup, App::Prop_None, "Set line color."); + ADD_PROPERTY_TYPE(LineColor, (0, 0, 0), osgroup, App::Prop_None, "Set line color."); // Create the selection node pcHighlight = Gui::ViewProviderBuilder::createSelection(); pcHighlight->ref(); - if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF) + if (pcHighlight->selectionMode.getValue() == Gui::SoFCSelection::SEL_OFF) { Selectable.setValue(false); + } pcShapeGroup = new SoGroup(); pcShapeGroup->ref(); @@ -276,7 +292,8 @@ ViewProviderMesh::ViewProviderMesh() : highlightMode{HighlighMode::None} LineColor.touch(); // read the correct shape color from the preferences - Base::Reference hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); + Base::Reference hGrp = + Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); // Mesh color App::Color color = ShapeColor.getValue(); @@ -299,8 +316,12 @@ ViewProviderMesh::ViewProviderMesh() : highlightMode{HighlighMode::None} LineTransparency.setValue(hGrp->GetInt("LineTransparency", 0)); bool twoside = hGrp->GetBool("TwoSideRendering", false); - if (twoside) Lighting.setValue(1); - else Lighting.setValue((long)0); + if (twoside) { + Lighting.setValue(1); + } + else { + Lighting.setValue((long)0); + } bool normal_per_vertex = hGrp->GetBool("VertexPerNormals", false); if (normal_per_vertex) { @@ -334,7 +355,7 @@ void ViewProviderMesh::onChanged(const App::Property* prop) pcMatBinding->value = SoMaterialBinding::OVERALL; } if (prop == &LineTransparency) { - float trans = LineTransparency.getValue()/100.0f; + float trans = LineTransparency.getValue() / 100.0f; pLineColor->transparency = trans; } else if (prop == &LineWidth) { @@ -359,14 +380,14 @@ void ViewProviderMesh::onChanged(const App::Property* prop) } else if (prop == &LineColor) { const App::Color& c = LineColor.getValue(); - pLineColor->diffuseColor.setValue(c.r,c.g,c.b); + pLineColor->diffuseColor.setValue(c.r, c.g, c.b); } else if (prop == &Coloring) { tryColorPerVertexOrFace(Coloring.getValue()); } else if (prop == &SelectionStyle) { - pcHighlight->style = SelectionStyle.getValue() ? Gui::SoFCSelection::BOX - : Gui::SoFCSelection::EMISSIVE; + pcHighlight->style = + SelectionStyle.getValue() ? Gui::SoFCSelection::BOX : Gui::SoFCSelection::EMISSIVE; } else { // Set the inverse color for open edges @@ -383,9 +404,12 @@ void ViewProviderMesh::onChanged(const App::Property* prop) void ViewProviderMesh::setOpenEdgeColorFrom(const App::Color& c) { - float r=1.0f-c.r; r = r < 0.5f ? 0.0f : 1.0f; - float g=1.0f-c.g; g = g < 0.5f ? 0.0f : 1.0f; - float b=1.0f-c.b; b = b < 0.5f ? 0.0f : 1.0f; + float r = 1.0f - c.r; + r = r < 0.5f ? 0.0f : 1.0f; + float g = 1.0f - c.g; + g = g < 0.5f ? 0.0f : 1.0f; + float b = 1.0f - c.b; + b = b < 0.5f ? 0.0f : 1.0f; pOpenColor->rgb.setValue(r, g, b); } @@ -403,7 +427,7 @@ SoNode* ViewProviderMesh::getCoordNode() const * Extracts the mesh data from the feature \a pcFeature and creates * an Inventor node \a SoNode with these data. */ -void ViewProviderMesh::attach(App::DocumentObject *pcFeat) +void ViewProviderMesh::attach(App::DocumentObject* pcFeat) { ViewProviderGeometryObject::attach(pcFeat); @@ -441,7 +465,7 @@ void ViewProviderMesh::attach(App::DocumentObject *pcFeat) pcWireRoot->addChild(pcLineStyle); pcWireRoot->addChild(pcLightModel); SoMaterialBinding* binding = new SoMaterialBinding; - binding->value = SoMaterialBinding::OVERALL; // doesn't set several colors + binding->value = SoMaterialBinding::OVERALL; // doesn't set several colors pcWireRoot->addChild(binding); pcWireRoot->addChild(pLineColor); pcWireRoot->addChild(pcHighlight); @@ -497,9 +521,9 @@ QIcon ViewProviderMesh::getIcon() const App::PropertyColorList* ViewProviderMesh::getColorProperty() const { if (pcObject) { - std::map Map; + std::map Map; pcObject->getPropertyMap(Map); - for (const auto & it : Map) { + for (const auto& it : Map) { Base::Type type = it.second->getTypeId(); if (type == App::PropertyColorList::getClassTypeId()) { App::PropertyColorList* colors = static_cast(it.second); @@ -507,7 +531,7 @@ App::PropertyColorList* ViewProviderMesh::getColorProperty() const } } } - return nullptr; // no such property found + return nullptr; // no such property found } void ViewProviderMesh::tryColorPerVertexOrFace(bool on) @@ -572,8 +596,8 @@ void ViewProviderMesh::tryColorPerVertexOrFace(bool on) else { pcMatBinding->value = SoMaterialBinding::OVERALL; const App::Color& c = ShapeColor.getValue(); - pcShapeMaterial->diffuseColor.setValue(c.r,c.g,c.b); - pcShapeMaterial->transparency.setValue(Transparency.getValue()/100.0f); + pcShapeMaterial->diffuseColor.setValue(c.r, c.g, c.b); + pcShapeMaterial->transparency.setValue(Transparency.getValue() / 100.0f); } } @@ -594,7 +618,7 @@ void ViewProviderMesh::setColorField(const std::vector& val, SoMFCol field.setNum(val.size()); SbColor* col = field.startEditing(); - std::size_t i=0; + std::size_t i = 0; for (auto it : val) { col[i++].setValue(it.r, it.g, it.b); } @@ -625,9 +649,9 @@ void ViewProviderMesh::setEmissiveColor(const std::vector& val) Mesh::PropertyMaterial* ViewProviderMesh::getMaterialProperty() const { if (pcObject) { - std::map Map; + std::map Map; pcObject->getPropertyMap(Map); - for (const auto & it : Map) { + for (const auto& it : Map) { Base::Type type = it.second->getTypeId(); if (type == Mesh::PropertyMaterial::getClassTypeId()) { Mesh::PropertyMaterial* material = static_cast(it.second); @@ -636,21 +660,21 @@ Mesh::PropertyMaterial* ViewProviderMesh::getMaterialProperty() const } } - return nullptr; // no such property found + return nullptr; // no such property found } void ViewProviderMesh::setDisplayMode(const char* ModeName) { - if (strcmp("Shaded",ModeName)==0) { + if (strcmp("Shaded", ModeName) == 0) { setDisplayMaskMode("Shaded"); } - else if (strcmp("Points",ModeName)==0) { + else if (strcmp("Points", ModeName) == 0) { setDisplayMaskMode("Point"); } - else if (strcmp("Flat Lines",ModeName)==0) { + else if (strcmp("Flat Lines", ModeName) == 0) { setDisplayMaskMode("Flat Lines"); } - else if (strcmp("Wireframe",ModeName)==0) { + else if (strcmp("Wireframe", ModeName) == 0) { setDisplayMaskMode("Wireframe"); } @@ -670,7 +694,9 @@ std::vector ViewProviderMesh::getDisplayModes() const return StrList; } -bool ViewProviderMesh::exportToVrml(const char* filename, const MeshCore::Material& mat, bool binary) const +bool ViewProviderMesh::exportToVrml(const char* filename, + const MeshCore::Material& mat, + bool binary) const { SoCoordinate3* coords = new SoCoordinate3(); SoIndexedFaceSet* faces = new SoIndexedFaceSet(); @@ -683,15 +709,16 @@ bool ViewProviderMesh::exportToVrml(const char* filename, const MeshCore::Materi if (static_cast(mat.diffuseColor.size()) == coords->point.getNum()) { binding->value = SoMaterialBinding::PER_VERTEX_INDEXED; } - else if (static_cast(mat.diffuseColor.size()) == faces->coordIndex.getNum()/4) { + else if (static_cast(mat.diffuseColor.size()) == faces->coordIndex.getNum() / 4) { binding->value = SoMaterialBinding::PER_FACE_INDEXED; } if (mat.diffuseColor.size() > 1) { material->diffuseColor.setNum(mat.diffuseColor.size()); SbColor* colors = material->diffuseColor.startEditing(); - for (unsigned int i=0; idiffuseColor.finishEditing(); } @@ -706,10 +733,10 @@ bool ViewProviderMesh::exportToVrml(const char* filename, const MeshCore::Materi group->ref(); tovrml2.apply(group); group->unref(); - SoVRMLGroup *vrmlRoot = tovrml2.getVRML2SceneGraph(); + SoVRMLGroup* vrmlRoot = tovrml2.getVRML2SceneGraph(); vrmlRoot->ref(); std::string buffer = Gui::SoFCDB::writeNodesToString(vrmlRoot); - vrmlRoot->unref(); // release the memory as soon as possible + vrmlRoot->unref(); // release the memory as soon as possible Base::FileInfo fi(filename); if (binary) { @@ -746,19 +773,22 @@ void ViewProviderMesh::exportMesh(const char* filename, const char* fmt) const int numColors = pcShapeMaterial->diffuseColor.getNum(); const SbColor* colors = pcShapeMaterial->diffuseColor.getValues(0); mat.diffuseColor.reserve(numColors); - for (int i=0; i(getObject())->Mesh.getValue(); mesh.setPlacement(static_cast(getObject())->globalPlacement()); - if (mat.diffuseColor.size() == mesh.countPoints()) + if (mat.diffuseColor.size() == mesh.countPoints()) { mat.binding = MeshCore::MeshIO::PER_VERTEX; - else if (mat.diffuseColor.size() == mesh.countFacets()) + } + else if (mat.diffuseColor.size() == mesh.countFacets()) { mat.binding = MeshCore::MeshIO::PER_FACE; - else + } + else { mat.binding = MeshCore::MeshIO::OVERALL; + } mesh.save(filename, format, &mat, getObject()->Label.getValue()); } @@ -771,17 +801,17 @@ void ViewProviderMesh::setupContextMenu(QMenu* menu, QObject* receiver, const ch Gui::ActionFunction* func = new Gui::ActionFunction(menu); QAction* act = menu->addAction(QObject::tr("Display components")); act->setCheckable(true); - act->setChecked(pcMatBinding->value.getValue() == SoMaterialBinding::PER_FACE && - highlightMode == HighlighMode::Component); - func->toggle(act, [this](bool on){ + act->setChecked(pcMatBinding->value.getValue() == SoMaterialBinding::PER_FACE + && highlightMode == HighlighMode::Component); + func->toggle(act, [this](bool on) { this->setHighlightedComponents(on); }); QAction* seg = menu->addAction(QObject::tr("Display segments")); seg->setCheckable(true); - seg->setChecked(pcMatBinding->value.getValue() == SoMaterialBinding::PER_FACE && - highlightMode == HighlighMode::Segment); - func->toggle(seg, [this](bool on){ + seg->setChecked(pcMatBinding->value.getValue() == SoMaterialBinding::PER_FACE + && highlightMode == HighlighMode::Segment); + func->toggle(seg, [this](bool on) { this->setHighlightedSegments(on); }); @@ -789,30 +819,36 @@ void ViewProviderMesh::setupContextMenu(QMenu* menu, QObject* receiver, const ch col->setVisible(canHighlightColors()); col->setCheckable(true); col->setChecked(highlightMode == HighlighMode::Color); - func->toggle(col, [this](bool on){ + func->toggle(col, [this](bool on) { this->setHighlightedColors(on); }); } bool ViewProviderMesh::setEdit(int ModNum) { - if (ModNum == ViewProvider::Transform) + if (ModNum == ViewProvider::Transform) { return ViewProviderGeometryObject::setEdit(ModNum); - else if (ModNum == ViewProvider::Color) + } + else if (ModNum == ViewProvider::Color) { highlightComponents(); + } return true; } void ViewProviderMesh::unsetEdit(int ModNum) { - if (ModNum == ViewProvider::Transform) + if (ModNum == ViewProvider::Transform) { ViewProviderGeometryObject::unsetEdit(ModNum); - else if (ModNum == ViewProvider::Color) + } + else if (ModNum == ViewProvider::Color) { unhighlightSelection(); + } } -bool ViewProviderMesh::createToolMesh(const std::vector& rclPoly, const SbViewVolume& vol, - const Base::Vector3f& rcNormal, std::vector& aFaces) +bool ViewProviderMesh::createToolMesh(const std::vector& rclPoly, + const SbViewVolume& vol, + const Base::Vector3f& rcNormal, + std::vector& aFaces) { float fX, fY, fZ; SbVec3f pt1, pt2, pt3, pt4; @@ -822,10 +858,12 @@ bool ViewProviderMesh::createToolMesh(const std::vector& rclPoly, const for (std::vector::const_iterator it = rclPoly.begin(); it != rclPoly.end(); ++it) { // the following element std::vector::const_iterator nt = it + 1; - if (nt == rclPoly.end()) + if (nt == rclPoly.end()) { nt = rclPoly.begin(); - else if (*it == *nt) - continue; // two adjacent vertices are equal + } + else if (*it == *nt) { + continue; // two adjacent vertices are equal + } vol.projectPointToLine(*it, pt1, pt2); vol.projectPointToLine(*nt, pt3, pt4); @@ -837,8 +875,9 @@ bool ViewProviderMesh::createToolMesh(const std::vector& rclPoly, const face._aclPoints[1].Set(fX, fY, fZ); pt3.getValue(fX, fY, fZ); face._aclPoints[2].Set(fX, fY, fZ); - if (face.Area() > 0) + if (face.Area() > 0) { aFaces.push_back(face); + } // 2nd facet pt1.getValue(fX, fY, fZ); @@ -847,17 +886,18 @@ bool ViewProviderMesh::createToolMesh(const std::vector& rclPoly, const face._aclPoints[1].Set(fX, fY, fZ); pt4.getValue(fX, fY, fZ); face._aclPoints[2].Set(fX, fY, fZ); - if (face.Area() > 0) + if (face.Area() > 0) { aFaces.push_back(face); + } - if (it+1 < rclPoly.end()) { + if (it + 1 < rclPoly.end()) { pt1.getValue(fX, fY, fZ); - top.emplace_back(fX, fY, fZ ); + top.emplace_back(fX, fY, fZ); pt2.getValue(fX, fY, fZ); - bottom.emplace_back(fX, fY, fZ ); + bottom.emplace_back(fX, fY, fZ); // polygon we need to triangulate (in x,y-plane) it->getValue(fX, fY); - polygon.emplace_back(fX, fY, 0.0f ); + polygon.emplace_back(fX, fY, 0.0f); } } @@ -868,7 +908,7 @@ bool ViewProviderMesh::createToolMesh(const std::vector& rclPoly, const bool ok = cTria.TriangulatePolygon(); std::vector faces = cTria.GetFacets(); - for (const auto & face : faces) { + for (const auto& face : faces) { MeshGeomFacet topFacet; topFacet._aclPoints[0] = top[face._aulPoints[0]]; topFacet._aclPoints[1] = top[face._aulPoints[1]]; @@ -898,8 +938,10 @@ void ViewProviderMesh::showOpenEdges(bool show) (void)show; } -namespace MeshGui { -class MeshSplit { +namespace MeshGui +{ +class MeshSplit +{ public: MeshSplit(ViewProviderMesh* mesh, const std::vector& poly, @@ -907,10 +949,9 @@ public: : mesh(mesh) , poly(poly) , proj(proj) + {} + void cutMesh() { - - } - void cutMesh() { Gui::Document* gui = mesh->getDocument(); gui->openCommand(QT_TRANSLATE_NOOP("Command", "Cut")); ViewProviderMesh* copy = makeCopy(); @@ -919,7 +960,8 @@ public: gui->commitCommand(); delete this; } - void trimMesh() { + void trimMesh() + { Gui::Document* gui = mesh->getDocument(); gui->openCommand(QT_TRANSLATE_NOOP("Command", "Trim")); ViewProviderMesh* copy = makeCopy(); @@ -928,7 +970,8 @@ public: gui->commitCommand(); delete this; } - ViewProviderMesh* makeCopy() const { + ViewProviderMesh* makeCopy() const + { Gui::Document* gui = mesh->getDocument(); App::Document* doc = gui->getDocument(); @@ -945,29 +988,33 @@ private: std::vector poly; Gui::ViewVolumeProjection proj; }; -} +} // namespace MeshGui -void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n) +void ViewProviderMesh::clipMeshCallback(void* ud, SoEventCallback* n) { // show the wait cursor because this could take quite some time Gui::WaitCursor wc; // When this callback function is invoked we must in either case leave the edit mode - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); view->setEditing(false); - view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), clipMeshCallback,ud); + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), clipMeshCallback, 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()); + } - std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = + view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); if (!views.empty()) { - Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Cut")); + Gui::Application::Instance->activeDocument()->openCommand( + QT_TRANSLATE_NOOP("Command", "Cut")); bool commitCommand = false; for (auto it : views) { ViewProviderMesh* self = static_cast(it); @@ -976,8 +1023,9 @@ void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n) SoCamera* cam = view->getSoRenderManager()->getCamera(); SbViewVolume vv = cam->getViewVolume(); Gui::ViewVolumeProjection proj(vv); - proj.setTransform(static_cast(self->getObject())-> - Placement.getValue().toMatrix()); + proj.setTransform(static_cast(self->getObject()) + ->Placement.getValue() + .toMatrix()); if (role == Gui::SelectionRole::Inner) { self->cutMesh(clPoly, proj, true); commitCommand = true; @@ -993,7 +1041,7 @@ void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n) Gui::TimerFunction* func = new Gui::TimerFunction(); func->setAutoDelete(true); MeshSplit* split = new MeshSplit(self, clPoly, proj); - func->setFunction([split](){ + func->setFunction([split]() { split->cutMesh(); }); func->singleShot(0); @@ -1001,36 +1049,42 @@ void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n) } } - if (commitCommand) + if (commitCommand) { Gui::Application::Instance->activeDocument()->commitCommand(); - else + } + else { Gui::Application::Instance->activeDocument()->abortCommand(); + } view->redraw(); } } -void ViewProviderMesh::trimMeshCallback(void * ud, SoEventCallback * n) +void ViewProviderMesh::trimMeshCallback(void* ud, SoEventCallback* n) { // show the wait cursor because this could take quite some time Gui::WaitCursor wc; // When this callback function is invoked we must in either case leave the edit mode - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); view->setEditing(false); - view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), trimMeshCallback,ud); + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), trimMeshCallback, 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()); + } - std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = + view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); if (!views.empty()) { - Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Trim")); + Gui::Application::Instance->activeDocument()->openCommand( + QT_TRANSLATE_NOOP("Command", "Trim")); bool commitCommand = false; for (auto it : views) { ViewProviderMesh* self = static_cast(it); @@ -1039,8 +1093,9 @@ void ViewProviderMesh::trimMeshCallback(void * ud, SoEventCallback * n) SoCamera* cam = view->getSoRenderManager()->getCamera(); SbViewVolume vv = cam->getViewVolume(); Gui::ViewVolumeProjection proj(vv); - proj.setTransform(static_cast(self->getObject())-> - Placement.getValue().toMatrix()); + proj.setTransform(static_cast(self->getObject()) + ->Placement.getValue() + .toMatrix()); if (role == Gui::SelectionRole::Inner) { self->trimMesh(clPoly, proj, true); commitCommand = true; @@ -1056,7 +1111,7 @@ void ViewProviderMesh::trimMeshCallback(void * ud, SoEventCallback * n) Gui::TimerFunction* func = new Gui::TimerFunction(); func->setAutoDelete(true); MeshSplit* split = new MeshSplit(self, clPoly, proj); - func->setFunction([split](){ + func->setFunction([split]() { split->trimMesh(); }); func->singleShot(0); @@ -1064,44 +1119,50 @@ void ViewProviderMesh::trimMeshCallback(void * ud, SoEventCallback * n) } } - if (commitCommand) + if (commitCommand) { Gui::Application::Instance->activeDocument()->commitCommand(); - else + } + else { Gui::Application::Instance->activeDocument()->abortCommand(); + } view->redraw(); } } -void ViewProviderMesh::partMeshCallback(void * ud, SoEventCallback * cb) +void ViewProviderMesh::partMeshCallback(void* ud, SoEventCallback* cb) { // show the wait cursor because this could take quite some time Gui::WaitCursor wc; // When this callback function is invoked we must in either case leave the edit mode - Gui::View3DInventorViewer* view = static_cast(cb->getUserData()); + Gui::View3DInventorViewer* view = static_cast(cb->getUserData()); view->setEditing(false); - view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), partMeshCallback,ud); + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), partMeshCallback, ud); cb->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()); + } // get the normal of the front clipping plane - SbVec3f b,n; + SbVec3f b, n; view->getNearPlane(b, n); - Base::Vector3f cNormal(n[0],n[1],n[2]); + Base::Vector3f cNormal(n[0], n[1], n[2]); SoCamera* pCam = view->getSoRenderManager()->getCamera(); - SbViewVolume vol = pCam->getViewVolume(); + SbViewVolume vol = pCam->getViewVolume(); // create a tool shape from these points std::vector aFaces; - if (!ViewProviderMesh::createToolMesh(clPoly, vol, cNormal, aFaces)) - Base::Console().Message("The picked polygon seems to have self-overlappings. This could lead to strange results."); + if (!ViewProviderMesh::createToolMesh(clPoly, vol, cNormal, aFaces)) { + Base::Console().Message("The picked polygon seems to have self-overlappings. This could " + "lead to strange results."); + } MeshCore::MeshKernel toolMesh; bool locked = Base::Sequencer().setLocked(true); @@ -1109,26 +1170,31 @@ void ViewProviderMesh::partMeshCallback(void * ud, SoEventCallback * cb) Base::Sequencer().setLocked(locked); // Open a transaction object for the undo/redo stuff - Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Split")); + Gui::Application::Instance->activeDocument()->openCommand( + QT_TRANSLATE_NOOP("Command", "Split")); try { - std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = + view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (auto view : views) { ViewProviderMesh* that = static_cast(view); if (that->getEditingMode() > -1) { that->finishEditing(); - Base::Placement plm = static_cast(that->getObject())->Placement.getValue(); + Base::Placement plm = + static_cast(that->getObject())->Placement.getValue(); plm.invert(); MeshCore::MeshKernel copyToolMesh(toolMesh); copyToolMesh.Transform(plm.toMatrix()); - if (role == Gui::SelectionRole::Inner) + if (role == Gui::SelectionRole::Inner) { that->splitMesh(copyToolMesh, cNormal, true); - else + } + else { that->splitMesh(copyToolMesh, cNormal, false); + } } } } - catch(...) { + catch (...) { // Don't rethrow any exception } @@ -1137,35 +1203,39 @@ void ViewProviderMesh::partMeshCallback(void * ud, SoEventCallback * cb) view->redraw(); } -void ViewProviderMesh::segmMeshCallback(void * ud, SoEventCallback * cb) +void ViewProviderMesh::segmMeshCallback(void* ud, SoEventCallback* cb) { // show the wait cursor because this could take quite some time Gui::WaitCursor wc; // When this callback function is invoked we must in either case leave the edit mode - Gui::View3DInventorViewer* view = static_cast(cb->getUserData()); + Gui::View3DInventorViewer* view = static_cast(cb->getUserData()); view->setEditing(false); - view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), segmMeshCallback,ud); + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), segmMeshCallback, ud); cb->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()); + } // get the normal of the front clipping plane - SbVec3f b,n; + SbVec3f b, n; view->getNearPlane(b, n); - Base::Vector3f cNormal(n[0],n[1],n[2]); + Base::Vector3f cNormal(n[0], n[1], n[2]); SoCamera* pCam = view->getSoRenderManager()->getCamera(); - SbViewVolume vol = pCam->getViewVolume(); + SbViewVolume vol = pCam->getViewVolume(); // create a tool shape from these points std::vector aFaces; - if (!ViewProviderMesh::createToolMesh(clPoly, vol, cNormal, aFaces)) - Base::Console().Message("The picked polygon seems to have self-overlappings. This could lead to strange results."); + if (!ViewProviderMesh::createToolMesh(clPoly, vol, cNormal, aFaces)) { + Base::Console().Message("The picked polygon seems to have self-overlappings. This could " + "lead to strange results."); + } MeshCore::MeshKernel toolMesh; bool locked = Base::Sequencer().setLocked(true); @@ -1173,26 +1243,31 @@ void ViewProviderMesh::segmMeshCallback(void * ud, SoEventCallback * cb) Base::Sequencer().setLocked(locked); // Open a transaction object for the undo/redo stuff - Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Segment")); + Gui::Application::Instance->activeDocument()->openCommand( + QT_TRANSLATE_NOOP("Command", "Segment")); try { - std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = + view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (auto view : views) { ViewProviderMesh* that = static_cast(view); if (that->getEditingMode() > -1) { that->finishEditing(); - Base::Placement plm = static_cast(that->getObject())->Placement.getValue(); + Base::Placement plm = + static_cast(that->getObject())->Placement.getValue(); plm.invert(); MeshCore::MeshKernel copyToolMesh(toolMesh); copyToolMesh.Transform(plm.toMatrix()); - if (role == Gui::SelectionRole::Inner) + if (role == Gui::SelectionRole::Inner) { that->segmentMesh(copyToolMesh, cNormal, true); - else + } + else { that->segmentMesh(copyToolMesh, cNormal, false); + } } } } - catch(...) { + catch (...) { // Don't rethrow any exception } @@ -1201,30 +1276,32 @@ void ViewProviderMesh::segmMeshCallback(void * ud, SoEventCallback * cb) view->redraw(); } -void ViewProviderMesh::selectGLCallback(void * ud, SoEventCallback * n) +void ViewProviderMesh::selectGLCallback(void* ud, SoEventCallback* n) { // When this callback function is invoked we must in either case leave the edit mode - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); view->setEditing(false); - view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), selectGLCallback,ud); + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), selectGLCallback, ud); n->setHandled(); std::vector clPoly = view->getGLPolygon(); - if (clPoly.size() != 2) + if (clPoly.size() != 2) { return; + } const SoEvent* ev = n->getEvent(); SbVec2f pos = clPoly[0]; - float pX,pY; pos.getValue(pX,pY); + float pX, pY; + pos.getValue(pX, pY); const SbVec2s& sz = view->getSoRenderManager()->getViewportRegion().getViewportSizePixels(); float fRatio = view->getSoRenderManager()->getViewportRegion().getViewportAspectRatio(); if (fRatio > 1.0f) { pX = (pX - 0.5f) / fRatio + 0.5f; - pos.setValue(pX,pY); + pos.setValue(pX, pY); } else if (fRatio < 1.0f) { pY = (pY - 0.5f) * fRatio + 0.5f; - pos.setValue(pX,pY); + pos.setValue(pX, pY); } short x1 = (short)(pX * sz[0] + 0.5f); @@ -1233,12 +1310,16 @@ void ViewProviderMesh::selectGLCallback(void * ud, SoEventCallback * n) short x2 = loc[0]; short y2 = loc[1]; - short x = (x1+x2)/2; - short y = (y1+y2)/2; - short w = (x2-x1); - short h = (y2-y1); - if (w<0) w = -w; - if (h<0) h = -h; + short x = (x1 + x2) / 2; + short y = (y1 + y2) / 2; + short w = (x2 - x1); + short h = (y2 - y1); + if (w < 0) { + w = -w; + } + if (h < 0) { + h = -h; + } std::vector views; views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); @@ -1246,7 +1327,12 @@ void ViewProviderMesh::selectGLCallback(void * ud, SoEventCallback * n) ViewProviderMesh* that = static_cast(it); if (that->getEditingMode() > -1) { that->finishEditing(); - that->selectArea(x, y, w, h, view->getSoRenderManager()->getViewportRegion(), view->getSoRenderManager()->getCamera()); + that->selectArea(x, + y, + w, + h, + view->getSoRenderManager()->getViewportRegion(), + view->getSoRenderManager()->getCamera()); } } @@ -1260,8 +1346,9 @@ void ViewProviderMesh::getFacetsFromPolygon(const std::vector& picked, { const bool ok = true; Base::Polygon2d polygon; - for (auto it : picked) - polygon.Add(Base::Vector2d(it[0],it[1])); + for (auto it : picked) { + polygon.Add(Base::Vector2d(it[0], it[1])); + } // Get the attached mesh property Mesh::PropertyMeshKernel& meshProp = static_cast(pcObject)->Mesh; @@ -1274,18 +1361,20 @@ void ViewProviderMesh::getFacetsFromPolygon(const std::vector& picked, std::generate(complete.begin(), complete.end(), Base::iotaGen(0)); std::sort(indices.begin(), indices.end()); std::vector complementary; - std::back_insert_iterator > biit(complementary); + std::back_insert_iterator> biit(complementary); std::set_difference(complete.begin(), complete.end(), indices.begin(), indices.end(), biit); indices = complementary; } - if (!ok) // note: the mouse grabbing needs to be released - Base::Console().Message("The picked polygon seems to have self-overlappings. This could lead to strange results."); + if (!ok) { // note: the mouse grabbing needs to be released + Base::Console().Message("The picked polygon seems to have self-overlappings. This could " + "lead to strange results."); + } } std::vector ViewProviderMesh::getFacetsOfRegion(const SbViewportRegion& select, - const SbViewportRegion& region, - SoCamera* camera) const + const SbViewportRegion& region, + SoCamera* camera) const { SoSeparator* root = new SoSeparator(); root->ref(); @@ -1301,13 +1390,18 @@ std::vector ViewProviderMesh::getFacetsOfRegion(const SbViewpo return faces; } -void ViewProviderMesh::panCamera(SoCamera * cam, float aspectratio, const SbPlane & panplane, - const SbVec2f & currpos, const SbVec2f & prevpos) +void ViewProviderMesh::panCamera(SoCamera* cam, + float aspectratio, + const SbPlane& panplane, + const SbVec2f& currpos, + const SbVec2f& prevpos) { - if (!cam) // can happen for empty scenegraph + if (!cam) { // can happen for empty scenegraph return; - if (currpos == prevpos) // useless invocation + } + if (currpos == prevpos) { // useless invocation return; + } // Find projection points for the last and current mouse coordinates. @@ -1325,31 +1419,33 @@ void ViewProviderMesh::panCamera(SoCamera * cam, float aspectratio, const SbPlan cam->position = cam->position.getValue() - (current_planept - old_planept); } -void ViewProviderMesh::boxZoom(const SbBox2s& box, const SbViewportRegion & vp, SoCamera* cam) +void ViewProviderMesh::boxZoom(const SbBox2s& box, const SbViewportRegion& vp, SoCamera* cam) { SbViewVolume vv = cam->getViewVolume(vp.getViewportAspectRatio()); - short sizeX,sizeY; + short sizeX, sizeY; box.getSize(sizeX, sizeY); SbVec2s size = vp.getViewportSizePixels(); // The bbox must not be empty i.e. width and length is zero, but it is possible that // either width or length is zero - if (sizeX == 0 && sizeY == 0) + if (sizeX == 0 && sizeY == 0) { return; + } // Get the new center in normalized pixel coordinates - short xmin,xmax,ymin,ymax; - box.getBounds(xmin,ymin,xmax,ymax); - const SbVec2f center((float) ((xmin+xmax)/2) / (float) std::max((int)(size[0] - 1), 1), - (float) (size[1]-(ymin+ymax)/2) / (float) std::max((int)(size[1] - 1), 1)); + short xmin, xmax, ymin, ymax; + box.getBounds(xmin, ymin, xmax, ymax); + const SbVec2f center((float)((xmin + xmax) / 2) / (float)std::max((int)(size[0] - 1), 1), + (float)(size[1] - (ymin + ymax) / 2) + / (float)std::max((int)(size[1] - 1), 1)); SbPlane plane = vv.getPlane(cam->focalDistance.getValue()); - panCamera(cam,vp.getViewportAspectRatio(),plane, SbVec2f(0.5,0.5), center); + panCamera(cam, vp.getViewportAspectRatio(), plane, SbVec2f(0.5, 0.5), center); // Set height or height angle of the camera - float scaleX = (float)sizeX/(float)size[0]; - float scaleY = (float)sizeY/(float)size[1]; + float scaleX = (float)sizeX / (float)size[0]; + float scaleY = (float)sizeY / (float)size[1]; float scale = std::max(scaleX, scaleY); if (cam->getTypeId() == SoOrthographicCamera::getClassTypeId()) { float height = static_cast(cam)->height.getValue() * scale; @@ -1362,18 +1458,19 @@ void ViewProviderMesh::boxZoom(const SbBox2s& box, const SbViewportRegion & vp, } } -std::vector ViewProviderMesh::getVisibleFacetsAfterZoom(const SbBox2s& rect, - const SbViewportRegion& vp, - SoCamera* camera) const +std::vector +ViewProviderMesh::getVisibleFacetsAfterZoom(const SbBox2s& rect, + const SbViewportRegion& vp, + SoCamera* camera) const { // camera copy will be deleted inside getVisibleFacets() // because the ref counter reaches 0 camera = static_cast(camera->copy()); - boxZoom(rect,vp,camera); + boxZoom(rect, vp, camera); return getVisibleFacets(vp, camera); } -void ViewProviderMesh::renderGLCallback(void * ud, SoAction * action) +void ViewProviderMesh::renderGLCallback(void* ud, SoAction* action) { if (action->isOfType(SoGLRenderAction::getClassTypeId())) { ViewProviderMesh* mesh = static_cast(ud); @@ -1382,7 +1479,8 @@ void ViewProviderMesh::renderGLCallback(void * ud, SoAction * action) } } -namespace MeshGui { +namespace MeshGui +{ class Vertex { @@ -1390,11 +1488,10 @@ public: Vertex(const MeshCore::MeshKernel& kernel, const MeshCore::MeshFacetGrid& grid, const Base::Vector3f& pos) - : kernel(kernel) - , grid(grid) - , pos(pos) - { - } + : kernel(kernel) + , grid(grid) + , pos(pos) + {} bool visible(const Base::Vector3f& base) const { MeshCore::MeshAlgorithm meshAlg(kernel); @@ -1408,10 +1505,10 @@ private: Base::Vector3f pos; }; -} +} // namespace MeshGui std::vector ViewProviderMesh::getVisibleFacets(const SbViewportRegion& vp, - SoCamera* camera) const + SoCamera* camera) const { const Mesh::PropertyMeshKernel& meshProp = static_cast(pcObject)->Mesh; const Mesh::MeshObject& mesh = meshProp.getValue(); @@ -1427,9 +1524,9 @@ std::vector ViewProviderMesh::getVisibleFacets(const SbViewpor SoMaterial* mat = new SoMaterial(); mat->diffuseColor.setNum(count); SbColor* diffcol = mat->diffuseColor.startEditing(); - for (uint32_t i=0; idiffuseColor.finishEditing(); @@ -1442,8 +1539,8 @@ std::vector ViewProviderMesh::getVisibleFacets(const SbViewpor root->addChild(this->getCoordNode()); root->addChild(this->getShapeNode()); - // Coin3d's off-screen renderer doesn't work out-of-the-box any more on most recent Linux systems. - // So, use FreeCAD's offscreen renderer now. + // Coin3d's off-screen renderer doesn't work out-of-the-box any more on most recent Linux + // systems. So, use FreeCAD's offscreen renderer now. Gui::SoQtOffscreenRenderer renderer(vp); renderer.setBackgroundColor(SbColor4f(0.0f, 0.0f, 0.0f)); @@ -1454,12 +1551,12 @@ std::vector ViewProviderMesh::getVisibleFacets(const SbViewpor int width = img.width(); int height = img.height(); - QRgb color=0; + QRgb color = 0; std::vector faces; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { - QRgb rgb = img.pixel(x,y); - rgb = rgb-(0xff << 24); + QRgb rgb = img.pixel(x, y); + rgb = rgb - (0xff << 24); if (rgb != 0 && rgb != color) { color = rgb; faces.push_back((Mesh::FacetIndex)rgb); @@ -1474,7 +1571,8 @@ std::vector ViewProviderMesh::getVisibleFacets(const SbViewpor } void ViewProviderMesh::cutMesh(const std::vector& picked, - const Base::ViewProjMethod& proj, SbBool inner) + const Base::ViewProjMethod& proj, + SbBool inner) { // Get the facet indices inside the tool mesh std::vector indices; @@ -1483,23 +1581,25 @@ void ViewProviderMesh::cutMesh(const std::vector& picked, } void ViewProviderMesh::trimMesh(const std::vector& polygon, - const Base::ViewProjMethod& proj, SbBool inner) + const Base::ViewProjMethod& proj, + SbBool inner) { Mesh::MeshObject* mesh = static_cast(pcObject)->Mesh.startEditing(); Base::Polygon2d polygon2d; - for (auto it : polygon) - polygon2d.Add(Base::Vector2d(it[0],it[1])); + for (auto it : polygon) { + polygon2d.Add(Base::Vector2d(it[0], it[1])); + } - Mesh::MeshObject::CutType type = inner ? - Mesh::MeshObject::INNER : - Mesh::MeshObject::OUTER; + Mesh::MeshObject::CutType type = inner ? Mesh::MeshObject::INNER : Mesh::MeshObject::OUTER; mesh->trim(polygon2d, proj, type); static_cast(pcObject)->Mesh.finishEditing(); pcObject->purgeTouched(); } -void ViewProviderMesh::splitMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool clip_inner) +void ViewProviderMesh::splitMesh(const MeshCore::MeshKernel& toolMesh, + const Base::Vector3f& normal, + SbBool clip_inner) { // Get the attached mesh property Mesh::PropertyMeshKernel& meshProp = static_cast(pcObject)->Mesh; @@ -1516,7 +1616,7 @@ void ViewProviderMesh::splitMesh(const MeshCore::MeshKernel& toolMesh, const Bas std::generate(complete.begin(), complete.end(), Base::iotaGen(0)); std::sort(indices.begin(), indices.end()); std::vector complementary; - std::back_insert_iterator > biit(complementary); + std::back_insert_iterator> biit(complementary); std::set_difference(complete.begin(), complete.end(), indices.begin(), indices.end(), biit); indices = complementary; } @@ -1524,14 +1624,17 @@ void ViewProviderMesh::splitMesh(const MeshCore::MeshKernel& toolMesh, const Bas // Remove the facets from the mesh and create a new one Mesh::MeshObject* kernel = meshProp.getValue().meshFromSegment(indices); removeFacets(indices); - Mesh::Feature* splitMesh = static_cast(App::GetApplication().getActiveDocument() - ->addObject("Mesh::Feature",pcObject->getNameInDocument())); + Mesh::Feature* splitMesh = static_cast( + App::GetApplication().getActiveDocument()->addObject("Mesh::Feature", + pcObject->getNameInDocument())); // Note: deletes also kernel splitMesh->Mesh.setValuePtr(kernel); static_cast(pcObject)->purgeTouched(); } -void ViewProviderMesh::segmentMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool clip_inner) +void ViewProviderMesh::segmentMesh(const MeshCore::MeshKernel& toolMesh, + const Base::Vector3f& normal, + SbBool clip_inner) { // Get the attached mesh property Mesh::PropertyMeshKernel& meshProp = static_cast(pcObject)->Mesh; @@ -1548,7 +1651,7 @@ void ViewProviderMesh::segmentMesh(const MeshCore::MeshKernel& toolMesh, const B std::generate(complete.begin(), complete.end(), Base::iotaGen(0)); std::sort(indices.begin(), indices.end()); std::vector complementary; - std::back_insert_iterator > biit(complementary); + std::back_insert_iterator> biit(complementary); std::set_difference(complete.begin(), complete.end(), indices.begin(), indices.end(), biit); indices = complementary; } @@ -1559,12 +1662,13 @@ void ViewProviderMesh::segmentMesh(const MeshCore::MeshKernel& toolMesh, const B static_cast(pcObject)->purgeTouched(); } -void ViewProviderMesh::faceInfoCallback(void * ud, SoEventCallback * n) +void ViewProviderMesh::faceInfoCallback(void* ud, SoEventCallback* n) { - const SoMouseButtonEvent * mbe = static_cast(n->getEvent()); - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + const SoMouseButtonEvent* mbe = static_cast(n->getEvent()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); - // Mark all incoming mouse button events as handled, especially, to deactivate the selection node + // Mark all incoming mouse button events as handled, especially, to deactivate the selection + // node n->getAction()->setHandled(); if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) { n->setHandled(); @@ -1575,20 +1679,23 @@ void ViewProviderMesh::faceInfoCallback(void * ud, SoEventCallback * n) if (cl == id) { view->setEditing(false); view->getWidget()->setCursor(QCursor(Qt::ArrowCursor)); - view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), faceInfoCallback,ud); - std::list glItems = view->getGraphicsItemsOfType(Gui::GLFlagWindow::getClassTypeId()); + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), faceInfoCallback, ud); + std::list glItems = + view->getGraphicsItemsOfType(Gui::GLFlagWindow::getClassTypeId()); for (auto glItem : glItems) { view->removeGraphicsItem(glItem); delete glItem; } // See comment below - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/View"); hGrp->SetBool("ShowNaviCube", hGrp->GetBool("ShowNaviCube", true)); } } - else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { - const SoPickedPoint * point = n->getPickedPoint(); + else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 + && mbe->getState() == SoButtonEvent::DOWN) { + const SoPickedPoint* point = n->getPickedPoint(); if (!point) { Base::Console().Message("No facet picked.\n"); return; @@ -1599,8 +1706,9 @@ void ViewProviderMesh::faceInfoCallback(void * ud, SoEventCallback * n) // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); - if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) + if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) { return; + } // FIXME: The Flag class doesn't work well (flickering) when the NaviCube is enabled. // To avoid this the NaviCube is disabled for the time the flags are shown. @@ -1616,7 +1724,8 @@ void ViewProviderMesh::faceInfoCallback(void * ud, SoEventCallback * n) Mesh::FacetIndex uFacet = faceDetail->getFaceIndex(); that->faceInfo(uFacet); Gui::GLFlagWindow* flags = nullptr; - std::list glItems = view->getGraphicsItemsOfType(Gui::GLFlagWindow::getClassTypeId()); + std::list glItems = + view->getGraphicsItemsOfType(Gui::GLFlagWindow::getClassTypeId()); if (glItems.empty()) { flags = new Gui::GLFlagWindow(view); view->addGraphicsItem(flags); @@ -1625,15 +1734,20 @@ void ViewProviderMesh::faceInfoCallback(void * ud, SoEventCallback * n) flags = static_cast(glItems.front()); } - int point1 = static_cast(faceDetail->getPoint(0))->getCoordinateIndex(); - int point2 = static_cast(faceDetail->getPoint(1))->getCoordinateIndex(); - int point3 = static_cast(faceDetail->getPoint(2))->getCoordinateIndex(); + int point1 = + static_cast(faceDetail->getPoint(0))->getCoordinateIndex(); + int point2 = + static_cast(faceDetail->getPoint(1))->getCoordinateIndex(); + int point3 = + static_cast(faceDetail->getPoint(2))->getCoordinateIndex(); Gui::Flag* flag = new Gui::Flag; flag->setText(QObject::tr("Index: %1").arg(uFacet)); QString toolTip = QString::fromLatin1("Facet index: %1\n" "Points: <%2, %3, %4>") - .arg(uFacet) - .arg(point1).arg(point2).arg(point3); + .arg(uFacet) + .arg(point1) + .arg(point2) + .arg(point3); flag->setToolTip(toolTip); flag->setOrigin(point->getPoint()); flags->addFlag(flag, Gui::FlagLayout::TopRight); @@ -1641,12 +1755,13 @@ void ViewProviderMesh::faceInfoCallback(void * ud, SoEventCallback * n) } } -void ViewProviderMesh::fillHoleCallback(void * ud, SoEventCallback * n) +void ViewProviderMesh::fillHoleCallback(void* ud, SoEventCallback* n) { - const SoMouseButtonEvent * mbe = static_cast(n->getEvent()); - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + const SoMouseButtonEvent* mbe = static_cast(n->getEvent()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); - // Mark all incoming mouse button events as handled, especially, to deactivate the selection node + // Mark all incoming mouse button events as handled, especially, to deactivate the selection + // node n->getAction()->setHandled(); if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) { n->setHandled(); @@ -1658,11 +1773,12 @@ void ViewProviderMesh::fillHoleCallback(void * ud, SoEventCallback * n) view->setEditing(false); view->setSelectionEnabled(true); view->getWidget()->setCursor(QCursor(Qt::ArrowCursor)); - view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), fillHoleCallback,ud); + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), fillHoleCallback, ud); } } - else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { - const SoPickedPoint * point = n->getPickedPoint(); + else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 + && mbe->getState() == SoButtonEvent::DOWN) { + const SoPickedPoint* point = n->getPickedPoint(); if (!point) { Base::Console().Message("No facet picked.\n"); return; @@ -1673,11 +1789,12 @@ void ViewProviderMesh::fillHoleCallback(void * ud, SoEventCallback * n) // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); - if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) + if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) { return; + } ViewProviderMesh* that = static_cast(vp); const SoDetail* detail = point->getDetail(that->getShapeNode()); - if ( detail && detail->getTypeId() == SoFaceDetail::getClassTypeId() ) { + if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) { // get the boundary to the picked facet Mesh::FacetIndex uFacet = ((SoFaceDetail*)detail)->getFaceIndex(); that->fillHole(uFacet); @@ -1685,16 +1802,18 @@ void ViewProviderMesh::fillHoleCallback(void * ud, SoEventCallback * n) } } -void ViewProviderMesh::markPartCallback(void * ud, SoEventCallback * n) +void ViewProviderMesh::markPartCallback(void* ud, SoEventCallback* n) { // handle only mouse button events if (n->getEvent()->isOfType(SoMouseButtonEvent::getClassTypeId())) { - const SoMouseButtonEvent * mbe = static_cast(n->getEvent()); - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + const SoMouseButtonEvent* mbe = static_cast(n->getEvent()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); - // Mark all incoming mouse button events as handled, especially, to deactivate the selection node + // Mark all incoming mouse button events as handled, especially, to deactivate the selection + // node n->getAction()->setHandled(); - if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) { + if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 + && mbe->getState() == SoButtonEvent::UP) { n->setHandled(); // context-menu QMenu menu; @@ -1705,22 +1824,28 @@ void ViewProviderMesh::markPartCallback(void * ud, SoEventCallback * n) if (cl == id) { view->setEditing(false); view->setSelectionEnabled(true); - view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), markPartCallback,ud); + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), + markPartCallback, + ud); - std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = + view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (auto view : views) { static_cast(view)->clearSelection(); } } else if (cf == id) { - std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = + view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (auto view : views) { static_cast(view)->clearSelection(); } } else if (rm == id) { - Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Delete")); - std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + Gui::Application::Instance->activeDocument()->openCommand( + QT_TRANSLATE_NOOP("Command", "Delete")); + std::vector views = + view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (auto view : views) { static_cast(view)->deleteSelection(); } @@ -1728,8 +1853,9 @@ void ViewProviderMesh::markPartCallback(void * ud, SoEventCallback * n) Gui::Application::Instance->activeDocument()->commitCommand(); } } - else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { - const SoPickedPoint * point = n->getPickedPoint(); + else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 + && mbe->getState() == SoButtonEvent::DOWN) { + const SoPickedPoint* point = n->getPickedPoint(); if (!point) { Base::Console().Message("No facet picked.\n"); return; @@ -1740,11 +1866,12 @@ void ViewProviderMesh::markPartCallback(void * ud, SoEventCallback * n) // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); - if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) + if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) { return; + } ViewProviderMesh* that = static_cast(vp); const SoDetail* detail = point->getDetail(that->getShapeNode()); - if ( detail && detail->getTypeId() == SoFaceDetail::getClassTypeId() ) { + if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) { // get the boundary to the picked facet Mesh::FacetIndex uFacet = static_cast(detail)->getFaceIndex(); that->selectComponent(uFacet); @@ -1761,20 +1888,34 @@ void ViewProviderMesh::faceInfo(Mesh::FacetIndex uFacet) if (uFacet < facets.size()) { MeshCore::MeshFacet face = facets[uFacet]; MeshCore::MeshGeomFacet tria = rKernel.GetFacet(face); - Base::Console().Message("Mesh: %s Facet %lu: Points: <%lu, %lu, %lu>, Neighbours: <%lu, %lu, %lu>\n" - "Triangle: <[%.6f, %.6f, %.6f], [%.6f, %.6f, %.6f], [%.6f, %.6f, %.6f]>\n", fea->getNameInDocument(), uFacet, - face._aulPoints[0], face._aulPoints[1], face._aulPoints[2], - face._aulNeighbours[0], face._aulNeighbours[1], face._aulNeighbours[2], - tria._aclPoints[0].x, tria._aclPoints[0].y, tria._aclPoints[0].z, - tria._aclPoints[1].x, tria._aclPoints[1].y, tria._aclPoints[1].z, - tria._aclPoints[2].x, tria._aclPoints[2].y, tria._aclPoints[2].z); + Base::Console().Message( + "Mesh: %s Facet %lu: Points: <%lu, %lu, %lu>, Neighbours: <%lu, %lu, %lu>\n" + "Triangle: <[%.6f, %.6f, %.6f], [%.6f, %.6f, %.6f], [%.6f, %.6f, %.6f]>\n", + fea->getNameInDocument(), + uFacet, + face._aulPoints[0], + face._aulPoints[1], + face._aulPoints[2], + face._aulNeighbours[0], + face._aulNeighbours[1], + face._aulNeighbours[2], + tria._aclPoints[0].x, + tria._aclPoints[0].y, + tria._aclPoints[0].z, + tria._aclPoints[1].x, + tria._aclPoints[1].y, + tria._aclPoints[1].z, + tria._aclPoints[2].x, + tria._aclPoints[2].y, + tria._aclPoints[2].z); } } void ViewProviderMesh::fillHole(Mesh::FacetIndex uFacet) { // get parameter from user settings - Base::Reference hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); + Base::Reference hGrp = + Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); int level = (int)hGrp->GetInt("FillHoleLevel", 2); // get the boundary to the picked facet @@ -1785,35 +1926,38 @@ void ViewProviderMesh::fillHole(Mesh::FacetIndex uFacet) MeshCore::MeshAlgorithm meshAlg(rKernel); meshAlg.GetFacetBorder(uFacet, aBorder); std::vector boundary(aBorder.begin(), aBorder.end()); - std::list > boundaries; + std::list> boundaries; boundaries.push_back(boundary); meshAlg.SplitBoundaryLoops(boundaries); std::vector newFacets; std::vector newPoints; unsigned long numberOfOldPoints = rKernel.CountPoints(); - for (const auto & it : boundaries) { - if (it.size() < 3/* || it->size() > 200*/) + for (const auto& it : boundaries) { + if (it.size() < 3 /* || it->size() > 200*/) { continue; + } boundary = it; MeshCore::MeshFacetArray faces; MeshCore::MeshPointArray points; - MeshCore::QuasiDelaunayTriangulator cTria/*(0.05f)*/; + MeshCore::QuasiDelaunayTriangulator cTria /*(0.05f)*/; cTria.SetVerifier(new MeshCore::TriangulationVerifierV2); if (meshAlg.FillupHole(boundary, cTria, faces, points, level, &cPt2Fac)) { - if (boundary.front() == boundary.back()) + if (boundary.front() == boundary.back()) { boundary.pop_back(); - // the triangulation may produce additional points which we must take into account when appending to the mesh + } + // the triangulation may produce additional points which we must take into account when + // appending to the mesh unsigned long countBoundaryPoints = boundary.size(); unsigned long countDifference = points.size() - countBoundaryPoints; if (countDifference > 0) { MeshCore::MeshPointArray::_TIterator pt = points.begin() + countBoundaryPoints; - for (unsigned long i=0; iactiveDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Fill hole")); + // add the facets to the mesh and open a transaction object for the undo/redo stuff + Gui::Application::Instance->activeDocument()->openCommand( + QT_TRANSLATE_NOOP("Command", "Fill hole")); Mesh::MeshObject* kernel = fea->Mesh.startEditing(); kernel->addFacets(newFacets, newPoints, true); fea->Mesh.finishEditing(); @@ -1839,15 +1985,17 @@ void ViewProviderMesh::setFacetTransparency(const std::vector& facetTrans App::Color c = ShapeColor.getValue(); pcShapeMaterial->diffuseColor.setNum(facetTransparency.size()); SbColor* cols = pcShapeMaterial->diffuseColor.startEditing(); - for (std::size_t index = 0; index < facetTransparency.size(); ++index) + for (std::size_t index = 0; index < facetTransparency.size(); ++index) { cols[index].setValue(c.r, c.g, c.b); + } pcShapeMaterial->diffuseColor.finishEditing(); } pcShapeMaterial->transparency.setNum(facetTransparency.size()); float* tran = pcShapeMaterial->transparency.startEditing(); - for (std::size_t index = 0; index < facetTransparency.size(); ++index) + for (std::size_t index = 0; index < facetTransparency.size(); ++index) { tran[index] = facetTransparency[index]; + } pcShapeMaterial->transparency.finishEditing(); pcMatBinding->value = SoMaterialBinding::PER_FACE; @@ -1863,8 +2011,7 @@ void ViewProviderMesh::resetFacetTransparency() /*! The triangles with the passed indices are already added to the mesh. */ void ViewProviderMesh::appendFacets(const std::vector&) -{ -} +{} void ViewProviderMesh::removeFacets(const std::vector& facets) { @@ -1901,22 +2048,24 @@ void ViewProviderMesh::removeFacets(const std::vector& facets) Coloring.setValue(false); std::vector validFacets(kernel->countFacets(), true); - for (auto it : facets) + for (auto it : facets) { validFacets[it] = false; + } const std::vector& colors = prop->getValues(); std::vector valid_colors; valid_colors.reserve(colors.size()); std::size_t numColors = colors.size(); for (std::size_t index = 0; index < numColors; index++) { - if (validFacets[index]) + if (validFacets[index]) { valid_colors.push_back(colors[index]); + } } prop->setValues(valid_colors); } - //Remove the facets from the mesh and open a transaction object for the undo/redo stuff + // Remove the facets from the mesh and open a transaction object for the undo/redo stuff kernel->deleteFacets(facets); meshProp.finishEditing(); pcObject->purgeTouched(); @@ -1940,7 +2089,7 @@ void ViewProviderMesh::selectFacet(Mesh::FacetIndex facet) highlightSelection(); } else { - pcShapeMaterial->diffuseColor.set1Value(facet,1.0f,0.0f,0.0f); + pcShapeMaterial->diffuseColor.set1Value(facet, 1.0f, 0.0f, 0.0f); } } @@ -1962,7 +2111,7 @@ void ViewProviderMesh::deselectFacet(Mesh::FacetIndex facet) } else { App::Color c = ShapeColor.getValue(); - pcShapeMaterial->diffuseColor.set1Value(facet,c.r,c.g,c.b); + pcShapeMaterial->diffuseColor.set1Value(facet, c.r, c.g, c.b); } } else { @@ -2006,10 +2155,12 @@ void ViewProviderMesh::deselectComponent(Mesh::FacetIndex uFacet) rMesh.removeFacetsFromSelection(selection); // Colorize the selection - if (rMesh.hasSelectedFacets()) + if (rMesh.hasSelectedFacets()) { highlightSelection(); - else + } + else { unhighlightSelection(); + } } void ViewProviderMesh::setSelection(const std::vector& indices) @@ -2019,10 +2170,12 @@ void ViewProviderMesh::setSelection(const std::vector& indices rMesh.addFacetsToSelection(indices); // Colorize the selection - if (indices.empty()) + if (indices.empty()) { unhighlightSelection(); - else + } + else { highlightSelection(); + } } void ViewProviderMesh::addSelection(const std::vector& indices) @@ -2040,10 +2193,12 @@ void ViewProviderMesh::removeSelection(const std::vector& indi rMesh.removeFacetsFromSelection(indices); // Colorize the selection - if (rMesh.hasSelectedFacets()) + if (rMesh.hasSelectedFacets()) { highlightSelection(); - else + } + else { unhighlightSelection(); + } } void ViewProviderMesh::invertSelection() @@ -2051,7 +2206,8 @@ void ViewProviderMesh::invertSelection() const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); const MeshCore::MeshFacetArray& faces = rMesh.getKernel().GetFacets(); MeshCore::MeshIsNotFlag flag; - unsigned long num_notsel = std::count_if(faces.begin(), faces.end(), [flag](const MeshCore::MeshFacet& f) { + unsigned long num_notsel = + std::count_if(faces.begin(), faces.end(), [flag](const MeshCore::MeshFacet& f) { return flag(f, MeshCore::MeshFacet::SELECTED); }); std::vector notselect; @@ -2059,8 +2215,9 @@ void ViewProviderMesh::invertSelection() MeshCore::MeshFacetArray::_TConstIterator beg = faces.begin(); MeshCore::MeshFacetArray::_TConstIterator end = faces.end(); for (MeshCore::MeshFacetArray::_TConstIterator jt = beg; jt != end; ++jt) { - if (!jt->IsFlag(MeshCore::MeshFacet::SELECTED)) - notselect.push_back(jt-beg); + if (!jt->IsFlag(MeshCore::MeshFacet::SELECTED)) { + notselect.push_back(jt - beg); + } } setSelection(notselect); } @@ -2092,12 +2249,15 @@ bool ViewProviderMesh::hasSelection() const return rMesh.hasSelectedFacets(); } -void ViewProviderMesh::selectArea(short x, short y, short w, short h, +void ViewProviderMesh::selectArea(short x, + short y, + short w, + short h, const SbViewportRegion& region, SoCamera* camera) { SbViewportRegion vp; - vp.setViewportPixels (x, y, w, h); + vp.setViewportPixels(x, y, w, h); std::vector faces = getFacetsOfRegion(vp, region, camera); const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); @@ -2125,10 +2285,12 @@ void ViewProviderMesh::highlightSelection() pcShapeMaterial->diffuseColor.setNum(uCtFacets); SbColor* cols = pcShapeMaterial->diffuseColor.startEditing(); - for (int i=0; idiffuseColor.finishEditing(); } @@ -2137,7 +2299,7 @@ void ViewProviderMesh::unhighlightSelection() App::Color c = ShapeColor.getValue(); pcMatBinding->value = SoMaterialBinding::OVERALL; pcShapeMaterial->diffuseColor.setNum(1); - pcShapeMaterial->diffuseColor.setValue(c.r,c.g,c.b); + pcShapeMaterial->diffuseColor.setValue(c.r, c.g, c.b); } void ViewProviderMesh::setHighlightedComponents(bool on) @@ -2155,7 +2317,7 @@ void ViewProviderMesh::setHighlightedComponents(bool on) void ViewProviderMesh::highlightComponents() { const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); - std::vector > comps = rMesh.getComponents(); + std::vector> comps = rMesh.getComponents(); // Colorize the components pcMatBinding->value = SoMaterialBinding::PER_FACE; @@ -2163,13 +2325,13 @@ void ViewProviderMesh::highlightComponents() pcShapeMaterial->diffuseColor.setNum(uCtFacets); SbColor* cols = pcShapeMaterial->diffuseColor.startEditing(); - for (const auto & comp : comps) { + for (const auto& comp : comps) { float fMax = (float)RAND_MAX; - float fRed = (float)rand()/fMax; - float fGrn = (float)rand()/fMax; - float fBlu = (float)rand()/fMax; + float fRed = (float)rand() / fMax; + float fGrn = (float)rand() / fMax; + float fBlu = (float)rand() / fMax; for (Mesh::FacetIndex jt : comp) { - cols[jt].setValue(fRed,fGrn,fBlu); + cols[jt].setValue(fRed, fGrn, fBlu); } } pcShapeMaterial->diffuseColor.finishEditing(); @@ -2194,10 +2356,11 @@ void ViewProviderMesh::highlightSegments() unsigned long numSegm = rMesh.countSegments(); colors.resize(numSegm, this->ShapeColor.getValue()); - for (unsigned long i=0; i& colors) pcShapeMaterial->diffuseColor.setNum(uCtFacets); SbColor* cols = pcShapeMaterial->diffuseColor.startEditing(); - for (unsigned long i=0; i segm = rMesh.getSegment(i).getIndices(); float fRed = colors[i].r; float fGrn = colors[i].g; float fBlu = colors[i].b; for (Mesh::FacetIndex it : segm) { - cols[it].setValue(fRed,fGrn,fBlu); + cols[it].setValue(fRed, fGrn, fBlu); } } pcShapeMaterial->diffuseColor.finishEditing(); @@ -2230,7 +2393,7 @@ void ViewProviderMesh::highlightSegments(const std::vector& colors) float fRed = colors[0].r; float fGrn = colors[0].g; float fBlu = colors[0].b; - pcShapeMaterial->diffuseColor.setValue(fRed,fGrn,fBlu); + pcShapeMaterial->diffuseColor.setValue(fRed, fGrn, fBlu); } } @@ -2250,13 +2413,15 @@ void ViewProviderMesh::highlightColors() { const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); { - App::PropertyColorList* prop = Base::freecad_dynamic_cast(pcObject->getPropertyByName("FaceColors")); + App::PropertyColorList* prop = Base::freecad_dynamic_cast( + pcObject->getPropertyByName("FaceColors")); if (prop && prop->getSize() == int(rMesh.countFacets())) { setColorPerFace(prop); } } { - App::PropertyColorList* prop = Base::freecad_dynamic_cast(pcObject->getPropertyByName("VertexColors")); + App::PropertyColorList* prop = Base::freecad_dynamic_cast( + pcObject->getPropertyByName("VertexColors")); if (prop && prop->getSize() == int(rMesh.countPoints())) { setColorPerVertex(prop); } @@ -2267,14 +2432,18 @@ bool ViewProviderMesh::canHighlightColors() const { const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); { - App::PropertyColorList* prop = Base::freecad_dynamic_cast(pcObject->getPropertyByName("FaceColors")); - if (prop && prop->getSize() == int(rMesh.countFacets())) + App::PropertyColorList* prop = Base::freecad_dynamic_cast( + pcObject->getPropertyByName("FaceColors")); + if (prop && prop->getSize() == int(rMesh.countFacets())) { return true; + } } { - App::PropertyColorList* prop = Base::freecad_dynamic_cast(pcObject->getPropertyByName("VertexColors")); - if (prop && prop->getSize() == int(rMesh.countPoints())) + App::PropertyColorList* prop = Base::freecad_dynamic_cast( + pcObject->getPropertyByName("VertexColors")); + if (prop && prop->getSize() == int(rMesh.countPoints())) { return true; + } } return false; @@ -2282,8 +2451,9 @@ bool ViewProviderMesh::canHighlightColors() const PyObject* ViewProviderMesh::getPyObject() { - if (!pyViewObject) + if (!pyViewObject) { pyViewObject = new ViewProviderMeshPy(this); + } pyViewObject->IncRef(); return pyViewObject; } @@ -2304,7 +2474,7 @@ ViewProviderIndexedFaceSet::~ViewProviderIndexedFaceSet() = default; * Extracts the mesh data from the feature \a pcFeature and creates * an Inventor node \a SoNode with these data. */ -void ViewProviderIndexedFaceSet::attach(App::DocumentObject *pcFeat) +void ViewProviderIndexedFaceSet::attach(App::DocumentObject* pcFeat) { ViewProviderMesh::attach(pcFeat); @@ -2315,9 +2485,13 @@ void ViewProviderIndexedFaceSet::attach(App::DocumentObject *pcFeat) pcHighlight->addChild(pcMeshFaces); // read the threshold from the preferences - Base::Reference hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); + Base::Reference hGrp = + Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); int size = hGrp->GetInt("RenderTriangleLimit", -1); - if (size > 0) static_cast(pcMeshFaces)->renderTriangleLimit = (unsigned int)(pow(10.0f,size)); + if (size > 0) { + static_cast(pcMeshFaces)->renderTriangleLimit = + (unsigned int)(pow(10.0f, size)); + } } void ViewProviderIndexedFaceSet::updateData(const App::Property* prop) @@ -2352,15 +2526,16 @@ void ViewProviderIndexedFaceSet::showOpenEdges(bool show) pcRoot->addChild(pcOpenEdge); // Build up the lines with indices to the list of vertices 'pcMeshCoord' - int index=0; - const MeshCore::MeshKernel& rMesh = static_cast(pcObject)->Mesh.getValue().getKernel(); + int index = 0; + const MeshCore::MeshKernel& rMesh = + static_cast(pcObject)->Mesh.getValue().getKernel(); const MeshCore::MeshFacetArray& rFaces = rMesh.GetFacets(); - for (const auto & rFace : rFaces) { - for (int i=0; i<3; i++) { + for (const auto& rFace : rFaces) { + for (int i = 0; i < 3; i++) { if (rFace._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) { - lines->coordIndex.set1Value(index++,rFace._aulPoints[i]); - lines->coordIndex.set1Value(index++,rFace._aulPoints[(i+1)%3]); - lines->coordIndex.set1Value(index++,SO_END_LINE_INDEX); + lines->coordIndex.set1Value(index++, rFace._aulPoints[i]); + lines->coordIndex.set1Value(index++, rFace._aulPoints[(i + 1) % 3]); + lines->coordIndex.set1Value(index++, SO_END_LINE_INDEX); } } } @@ -2389,7 +2564,7 @@ ViewProviderMeshObject::ViewProviderMeshObject() ViewProviderMeshObject::~ViewProviderMeshObject() = default; -void ViewProviderMeshObject::attach(App::DocumentObject *pcFeat) +void ViewProviderMeshObject::attach(App::DocumentObject* pcFeat) { ViewProviderMesh::attach(pcFeat); @@ -2400,9 +2575,12 @@ void ViewProviderMeshObject::attach(App::DocumentObject *pcFeat) pcHighlight->addChild(pcMeshShape); // read the threshold from the preferences - Base::Reference hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); + Base::Reference hGrp = + Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); int size = hGrp->GetInt("RenderTriangleLimit", -1); - if (size > 0) pcMeshShape->renderTriangleLimit = (unsigned int)(pow(10.0f,size)); + if (size > 0) { + pcMeshShape->renderTriangleLimit = (unsigned int)(pow(10.0f, size)); + } } void ViewProviderMeshObject::updateData(const App::Property* prop) @@ -2410,7 +2588,8 @@ void ViewProviderMeshObject::updateData(const App::Property* prop) ViewProviderMesh::updateData(prop); if (prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) { const Mesh::PropertyMeshKernel* mesh = static_cast(prop); - this->pcMeshNode->mesh.setValue(Base::Reference(mesh->getValuePtr())); + this->pcMeshNode->mesh.setValue( + Base::Reference(mesh->getValuePtr())); // Needs to update internal bounding box caches this->pcMeshShape->touch(); } diff --git a/src/Mod/Mesh/Gui/ViewProvider.h b/src/Mod/Mesh/Gui/ViewProvider.h index ad03b2ce66..1da1023638 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.h +++ b/src/Mod/Mesh/Gui/ViewProvider.h @@ -27,8 +27,8 @@ #include #include -#include #include +#include class SoGroup; @@ -49,35 +49,41 @@ class SbVec2f; class SbBox2s; class SbPlane; -namespace App { - class Color; - class PropertyColorList; +namespace App +{ +class Color; +class PropertyColorList; +} // namespace App + +namespace Base +{ +class ViewProjMethod; } -namespace Base { - class ViewProjMethod; -} - -namespace Gui { - class View3DInventorViewer; - class SoFCSelection; -} +namespace Gui +{ +class View3DInventorViewer; +class SoFCSelection; +} // namespace Gui -namespace MeshCore { - class MeshKernel; - struct Material; -} +namespace MeshCore +{ +class MeshKernel; +struct Material; +} // namespace MeshCore -namespace Mesh { +namespace Mesh +{ class PropertyMaterial; } -namespace MeshGui { +namespace MeshGui +{ class SoFCMeshObjectNode; class SoFCMeshObjectShape; -class MeshGuiExport ViewProviderMeshBuilder : public Gui::ViewProviderBuilder +class MeshGuiExport ViewProviderMeshBuilder: public Gui::ViewProviderBuilder { public: ViewProviderMeshBuilder() = default; @@ -90,7 +96,7 @@ public: * The ViewProviderExport class creates an empty node. * @author Werner Mayer */ -class MeshGuiExport ViewProviderExport : public Gui::ViewProviderDocumentObject +class MeshGuiExport ViewProviderExport: public Gui::ViewProviderDocumentObject { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderExport); @@ -99,7 +105,10 @@ public: ~ViewProviderExport() override; QIcon getIcon() const override; - SoSeparator* getRoot() const override {return nullptr;} + SoSeparator* getRoot() const override + { + return nullptr; + } std::vector getDisplayModes() const override; const char* getDefaultDisplayMode() const override; }; @@ -109,7 +118,7 @@ public: * and many algorithms to work on or edit the mesh. * @author Werner Mayer */ -class MeshGuiExport ViewProviderMesh : public Gui::ViewProviderGeometryObject +class MeshGuiExport ViewProviderMesh: public Gui::ViewProviderGeometryObject { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMesh); @@ -127,24 +136,33 @@ public: App::PropertyEnumeration Lighting; App::PropertyColor LineColor; - void attach(App::DocumentObject *) override; + void attach(App::DocumentObject*) override; void updateData(const App::Property*) override; - bool useNewSelectionModel() const override {return false;} - Gui::SoFCSelection* getHighlightNode() const { return pcHighlight; } + bool useNewSelectionModel() const override + { + return false; + } + Gui::SoFCSelection* getHighlightNode() const + { + return pcHighlight; + } QIcon getIcon() const override; /// Sets the correct display mode void setDisplayMode(const char* ModeName) override; /// returns a list of all possible modes std::vector getDisplayModes() const override; - bool exportToVrml(const char* filename, const MeshCore::Material&, bool binary=false) const; - void exportMesh(const char* filename, const char* fmt=nullptr) const; + bool exportToVrml(const char* filename, const MeshCore::Material&, bool binary = false) const; + void exportMesh(const char* filename, const char* fmt = nullptr) const; void setupContextMenu(QMenu*, QObject*, const char*) override; /// Get the python wrapper for that ViewProvider PyObject* getPyObject() override; /** @name Editing */ //@{ - bool doubleClicked() override{ return false; } + bool doubleClicked() override + { + return false; + } bool isFacetSelected(Mesh::FacetIndex facet); void selectComponent(Mesh::FacetIndex facet); void deselectComponent(Mesh::FacetIndex facet); @@ -158,13 +176,18 @@ public: void deleteSelection(); bool hasSelection() const; void getFacetsFromPolygon(const std::vector& picked, - const Base::ViewProjMethod& proj, SbBool inner, + const Base::ViewProjMethod& proj, + SbBool inner, std::vector& indices) const; - std::vector getFacetsOfRegion(const SbViewportRegion&, const SbViewportRegion&, SoCamera*) const; - std::vector getVisibleFacetsAfterZoom(const SbBox2s&, const SbViewportRegion&, SoCamera*) const; + std::vector + getFacetsOfRegion(const SbViewportRegion&, const SbViewportRegion&, SoCamera*) const; + std::vector + getVisibleFacetsAfterZoom(const SbBox2s&, const SbViewportRegion&, SoCamera*) const; std::vector getVisibleFacets(const SbViewportRegion&, SoCamera*) const; - virtual void cutMesh(const std::vector& picked, const Base::ViewProjMethod& proj, SbBool inner); - virtual void trimMesh(const std::vector& picked, const Base::ViewProjMethod& proj, SbBool inner); + virtual void + cutMesh(const std::vector& picked, const Base::ViewProjMethod& proj, SbBool inner); + virtual void + trimMesh(const std::vector& picked, const Base::ViewProjMethod& proj, SbBool inner); virtual void appendFacets(const std::vector&); virtual void removeFacets(const std::vector&); /*! The size of the array must be equal to the number of facets. */ @@ -182,8 +205,10 @@ protected: void onChanged(const App::Property* prop) override; virtual void showOpenEdges(bool); void setOpenEdgeColorFrom(const App::Color& col); - virtual void splitMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool inner); - virtual void segmentMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool inner); + virtual void + splitMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool inner); + virtual void + segmentMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool inner); virtual void faceInfo(Mesh::FacetIndex facet); virtual void fillHole(Mesh::FacetIndex facet); virtual void selectArea(short, short, short, short, const SbViewportRegion&, SoCamera*); @@ -212,42 +237,45 @@ protected: virtual SoNode* getCoordNode() const; public: - static void faceInfoCallback(void * ud, SoEventCallback * n); - static void fillHoleCallback(void * ud, SoEventCallback * n); - static void markPartCallback(void * ud, SoEventCallback * n); - static void clipMeshCallback(void * ud, SoEventCallback * n); - static void trimMeshCallback(void * ud, SoEventCallback * n); - static void partMeshCallback(void * ud, SoEventCallback * n); - static void segmMeshCallback(void * ud, SoEventCallback * n); - static void selectGLCallback(void * ud, SoEventCallback * n); + static void faceInfoCallback(void* ud, SoEventCallback* n); + static void fillHoleCallback(void* ud, SoEventCallback* n); + static void markPartCallback(void* ud, SoEventCallback* n); + static void clipMeshCallback(void* ud, SoEventCallback* n); + static void trimMeshCallback(void* ud, SoEventCallback* n); + static void partMeshCallback(void* ud, SoEventCallback* n); + static void segmMeshCallback(void* ud, SoEventCallback* n); + static void selectGLCallback(void* ud, SoEventCallback* n); /// Creates a tool mesh from the previous picked polygon on the viewer - static bool createToolMesh(const std::vector& rclPoly, const SbViewVolume& vol, - const Base::Vector3f& rcNormal, std::vector&); + static bool createToolMesh(const std::vector& rclPoly, + const SbViewVolume& vol, + const Base::Vector3f& rcNormal, + std::vector&); private: - static void renderGLCallback(void * ud, SoAction * a); - static void boxZoom(const SbBox2s& box, const SbViewportRegion & vp, SoCamera* cam); + static void renderGLCallback(void* ud, SoAction* a); + static void boxZoom(const SbBox2s& box, const SbViewportRegion& vp, SoCamera* cam); static void panCamera(SoCamera*, float, const SbPlane&, const SbVec2f&, const SbVec2f&); protected: - enum class HighlighMode { + enum class HighlighMode + { None, Component, Segment, Color }; - //NOLINTBEGIN + // NOLINTBEGIN HighlighMode highlightMode; - Gui::SoFCSelection * pcHighlight{nullptr}; - SoGroup * pcShapeGroup{nullptr}; - SoDrawStyle * pcLineStyle{nullptr}; - SoDrawStyle * pcPointStyle{nullptr}; - SoSeparator * pcOpenEdge{nullptr}; - SoBaseColor * pOpenColor{nullptr}; - SoMaterial * pLineColor{nullptr}; - SoShapeHints * pShapeHints{nullptr}; - SoMaterialBinding * pcMatBinding{nullptr}; - //NOLINTEND + Gui::SoFCSelection* pcHighlight {nullptr}; + SoGroup* pcShapeGroup {nullptr}; + SoDrawStyle* pcLineStyle {nullptr}; + SoDrawStyle* pcPointStyle {nullptr}; + SoSeparator* pcOpenEdge {nullptr}; + SoBaseColor* pOpenColor {nullptr}; + SoMaterial* pLineColor {nullptr}; + SoShapeHints* pShapeHints {nullptr}; + SoMaterialBinding* pcMatBinding {nullptr}; + // NOLINTEND private: static App::PropertyFloatConstraint::Constraints floatRange; @@ -261,7 +289,7 @@ private: * to render the mesh data structure. * @author Werner Mayer */ -class MeshGuiExport ViewProviderIndexedFaceSet : public ViewProviderMesh +class MeshGuiExport ViewProviderIndexedFaceSet: public ViewProviderMesh { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderIndexedFaceSet); @@ -269,7 +297,7 @@ public: ViewProviderIndexedFaceSet(); ~ViewProviderIndexedFaceSet() override; - void attach(App::DocumentObject *) override; + void attach(App::DocumentObject*) override; /// Update the Mesh representation void updateData(const App::Property*) override; @@ -279,8 +307,8 @@ protected: SoNode* getCoordNode() const override; private: - SoCoordinate3 * pcMeshCoord; - SoIndexedFaceSet * pcMeshFaces; + SoCoordinate3* pcMeshCoord; + SoIndexedFaceSet* pcMeshFaces; }; /** @@ -288,7 +316,7 @@ private: * to directly render the mesh data structure. * @author Werner Mayer */ -class MeshGuiExport ViewProviderMeshObject : public ViewProviderMesh +class MeshGuiExport ViewProviderMeshObject: public ViewProviderMesh { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshObject); @@ -296,7 +324,7 @@ public: ViewProviderMeshObject(); ~ViewProviderMeshObject() override; - void attach(App::DocumentObject *pcFeat) override; + void attach(App::DocumentObject* pcFeat) override; void updateData(const App::Property*) override; protected: @@ -305,12 +333,11 @@ protected: void showOpenEdges(bool) override; private: - SoFCMeshObjectNode * pcMeshNode; - SoFCMeshObjectShape * pcMeshShape; + SoFCMeshObjectNode* pcMeshNode; + SoFCMeshObjectShape* pcMeshShape; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_VIEWPROVIDERMESH_H - +#endif // MESHGUI_VIEWPROVIDERMESH_H diff --git a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp index 22fffd7638..985cd7ae87 100644 --- a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp @@ -22,26 +22,26 @@ #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 #endif -# include +#include #include #include @@ -114,8 +114,8 @@ ViewProviderMeshCurvature::ViewProviderMeshCurvature() mat.transparency = trans[0]; } - ADD_PROPERTY(TextureMaterial,(mat)); - SelectionStyle.setValue(1); // BBOX + ADD_PROPERTY(TextureMaterial, (mat)); + SelectionStyle.setValue(1); // BBOX } ViewProviderMeshCurvature::~ViewProviderMeshCurvature() @@ -131,9 +131,15 @@ void ViewProviderMeshCurvature::onChanged(const App::Property* prop) { if (prop == &TextureMaterial) { const App::Material& Mat = TextureMaterial.getValue(); - pcColorMat->ambientColor.setValue(Mat.ambientColor.r,Mat.ambientColor.g,Mat.ambientColor.b); - pcColorMat->specularColor.setValue(Mat.specularColor.r,Mat.specularColor.g,Mat.specularColor.b); - pcColorMat->emissiveColor.setValue(Mat.emissiveColor.r,Mat.emissiveColor.g,Mat.emissiveColor.b); + pcColorMat->ambientColor.setValue(Mat.ambientColor.r, + Mat.ambientColor.g, + Mat.ambientColor.b); + pcColorMat->specularColor.setValue(Mat.specularColor.r, + Mat.specularColor.g, + Mat.specularColor.b); + pcColorMat->emissiveColor.setValue(Mat.emissiveColor.r, + Mat.emissiveColor.g, + Mat.emissiveColor.b); pcColorMat->shininess.setValue(Mat.shininess); pcColorMat->transparency.setValue(Mat.transparency); } @@ -160,58 +166,62 @@ void ViewProviderMeshCurvature::init(const Mesh::PropertyCurvatureList* pCurvInf aMinValues.reserve(fCurvInfo.size()); aMaxValues.reserve(fCurvInfo.size()); - for (const auto & jt : fCurvInfo) { - aMinValues.push_back( jt.fMinCurvature ); - aMaxValues.push_back( jt.fMaxCurvature ); + for (const auto& jt : fCurvInfo) { + aMinValues.push_back(jt.fMinCurvature); + aMaxValues.push_back(jt.fMaxCurvature); } - if ( aMinValues.empty() || aMaxValues.empty() ) - return; // no values inside + if (aMinValues.empty() || aMaxValues.empty()) { + return; // no values inside + } - float fMin = *std::min_element( aMinValues.begin(), aMinValues.end() ); - float fMax = *std::max_element( aMinValues.begin(), aMinValues.end() ); + float fMin = *std::min_element(aMinValues.begin(), aMinValues.end()); + float fMax = *std::max_element(aMinValues.begin(), aMinValues.end()); // histogram over all values std::map aHistogram; for (float aMinValue : aMinValues) { - int grp = (int)(10.0f*( aMinValue - fMin )/( fMax - fMin )); + int grp = (int)(10.0f * (aMinValue - fMin) / (fMax - fMin)); aHistogram[grp]++; } - float fRMin=-1.0f; - for (const auto & mIt : aHistogram) { - if ( (float)mIt.second / (float)aMinValues.size() > 0.15f ) { - fRMin = mIt.first * ( fMax - fMin )/10.0f + fMin; + float fRMin = -1.0f; + for (const auto& mIt : aHistogram) { + if ((float)mIt.second / (float)aMinValues.size() > 0.15f) { + fRMin = mIt.first * (fMax - fMin) / 10.0f + fMin; break; } } - fMin = *std::min_element( aMaxValues.begin(), aMaxValues.end() ); - fMax = *std::max_element( aMaxValues.begin(), aMaxValues.end() ); + fMin = *std::min_element(aMaxValues.begin(), aMaxValues.end()); + fMax = *std::max_element(aMaxValues.begin(), aMaxValues.end()); // histogram over all values aHistogram.clear(); for (float aMaxValue : aMaxValues) { - int grp = (int)(10.0f*( aMaxValue - fMin )/( fMax - fMin )); + int grp = (int)(10.0f * (aMaxValue - fMin) / (fMax - fMin)); aHistogram[grp]++; } - float fRMax=1.0f; - for ( std::map::reverse_iterator rIt2 = aHistogram.rbegin(); rIt2 != aHistogram.rend(); ++rIt2 ) { - if ( (float)rIt2->second / (float)aMaxValues.size() > 0.15f ) { - fRMax = rIt2->first * ( fMax - fMin )/10.0f + fMin; + float fRMax = 1.0f; + for (std::map::reverse_iterator rIt2 = aHistogram.rbegin(); rIt2 != aHistogram.rend(); + ++rIt2) { + if ((float)rIt2->second / (float)aMaxValues.size() > 0.15f) { + fRMax = rIt2->first * (fMax - fMin) / 10.0f + fMin; break; } } float fAbs = std::max(fabs(fRMin), fabs(fRMax)); fRMin = -fAbs; - fRMax = fAbs; - fMin = fRMin; fMax = fRMax; - pcColorBar->setRange( fMin, fMax, 3 ); + fRMax = fAbs; + fMin = fRMin; + fMax = fRMax; + pcColorBar->setRange(fMin, fMax, 3); } -void ViewProviderMeshCurvature::slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) +void ViewProviderMeshCurvature::slotChangedObject(const App::DocumentObject& Obj, + const App::Property& Prop) { // we get this for any object for that a property has changed. Thus, we must regard that object // which is linked by our link property @@ -222,26 +232,27 @@ void ViewProviderMeshCurvature::slotChangedObject(const App::DocumentObject& Obj const Mesh::MeshObject& kernel = mesh.getValue(); pcColorMat->diffuseColor.setNum((int)kernel.countPoints()); pcColorMat->transparency.setNum((int)kernel.countPoints()); - static_cast(pcObject)->Source.touch(); // make sure to recompute the feature + static_cast(pcObject) + ->Source.touch(); // make sure to recompute the feature } } } -void ViewProviderMeshCurvature::attach(App::DocumentObject *pcFeat) +void ViewProviderMeshCurvature::attach(App::DocumentObject* pcFeat) { // creates the standard viewing modes inherited::attach(pcFeat); attachDocument(pcFeat->getDocument()); - SoShapeHints * flathints = new SoShapeHints; - flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE ; + SoShapeHints* flathints = new SoShapeHints; + flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; SoGroup* pcColorShadedRoot = new SoGroup(); pcColorShadedRoot->addChild(flathints); // color shaded - SoDrawStyle *pcFlatStyle = new SoDrawStyle(); + SoDrawStyle* pcFlatStyle = new SoDrawStyle(); pcFlatStyle->style = SoDrawStyle::FILLED; pcColorShadedRoot->addChild(pcFlatStyle); @@ -254,8 +265,9 @@ void ViewProviderMeshCurvature::attach(App::DocumentObject *pcFeat) addDisplayMaskMode(pcColorShadedRoot, "ColorShaded"); // Check for an already existing color bar - Gui::SoFCColorBar* pcBar = ((Gui::SoFCColorBar*)findFrontRootOfType( Gui::SoFCColorBar::getClassTypeId() )); - if ( pcBar ) { + Gui::SoFCColorBar* pcBar = + ((Gui::SoFCColorBar*)findFrontRootOfType(Gui::SoFCColorBar::getClassTypeId())); + if (pcBar) { float fMin = pcColorBar->getMinValue(); float fMax = pcColorBar->getMaxValue(); @@ -276,7 +288,8 @@ void ViewProviderMeshCurvature::updateData(const App::Property* prop) { // set to the expected size if (prop->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId())) { - Mesh::Feature* object = static_cast(prop)->getValue(); + Mesh::Feature* object = + static_cast(prop)->getValue(); Gui::coinRemoveAllChildren(this->pcLinkRoot); if (object) { const Mesh::MeshObject& kernel = object->Mesh.getValue(); @@ -289,15 +302,18 @@ void ViewProviderMeshCurvature::updateData(const App::Property* prop) ViewProviderMesh* view = static_cast(pDoc->getViewProvider(object)); this->pcLinkRoot->addChild(view->getHighlightNode()); - Base::Placement p = static_cast(view->getObject())->Placement.getValue(); + Base::Placement p = + static_cast(view->getObject())->Placement.getValue(); ViewProviderMesh::updateTransform(p, pcTransform); } } else if (prop->getTypeId() == Mesh::PropertyCurvatureList::getClassTypeId()) { - const Mesh::PropertyCurvatureList* curv = static_cast(prop); - if (curv->getSize() < 3) // invalid array + const Mesh::PropertyCurvatureList* curv = + static_cast(prop); + if (curv->getSize() < 3) { // invalid array return; -#if 0 // FIXME: Do not always change the range + } +#if 0 // FIXME: Do not always change the range init(curv); // init color bar #endif setActiveMode(); @@ -311,7 +327,7 @@ SoSeparator* ViewProviderMeshCurvature::getFrontRoot() const void ViewProviderMeshCurvature::setVertexCurvatureMode(int mode) { - using PropertyMap = std::map; + using PropertyMap = std::map; Mesh::PropertyCurvatureList* pCurvInfo = nullptr; PropertyMap Map; pcObject->getPropertyMap(Map); @@ -321,8 +337,9 @@ void ViewProviderMeshCurvature::setVertexCurvatureMode(int mode) return (type == Mesh::PropertyCurvatureList::getClassTypeId()); }); - if (it == Map.end()) - return; // cannot display this feature type due to missing curvature property + if (it == Map.end()) { + return; // cannot display this feature type due to missing curvature property + } pCurvInfo = static_cast(it->second); @@ -367,23 +384,23 @@ QIcon ViewProviderMeshCurvature::getIcon() const void ViewProviderMeshCurvature::setDisplayMode(const char* ModeName) { - if ( strcmp("Mean curvature",ModeName)==0 ) { + if (strcmp("Mean curvature", ModeName) == 0) { setVertexCurvatureMode(Mesh::PropertyCurvatureList::MeanCurvature); setDisplayMaskMode("ColorShaded"); } - else if ( strcmp("Gaussian curvature",ModeName)==0 ) { + else if (strcmp("Gaussian curvature", ModeName) == 0) { setVertexCurvatureMode(Mesh::PropertyCurvatureList::GaussCurvature); setDisplayMaskMode("ColorShaded"); } - else if ( strcmp("Maximum curvature",ModeName)==0 ) { + else if (strcmp("Maximum curvature", ModeName) == 0) { setVertexCurvatureMode(Mesh::PropertyCurvatureList::MaxCurvature); setDisplayMaskMode("ColorShaded"); } - else if ( strcmp("Minimum curvature",ModeName)==0 ) { + else if (strcmp("Minimum curvature", ModeName) == 0) { setVertexCurvatureMode(Mesh::PropertyCurvatureList::MinCurvature); setDisplayMaskMode("ColorShaded"); } - else if ( strcmp("Absolute curvature",ModeName)==0 ) { + else if (strcmp("Absolute curvature", ModeName) == 0) { setVertexCurvatureMode(Mesh::PropertyCurvatureList::AbsCurvature); setDisplayMaskMode("ColorShaded"); } @@ -410,23 +427,28 @@ std::vector ViewProviderMeshCurvature::getDisplayModes() const return StrList; } -void ViewProviderMeshCurvature::OnChange(Base::Subject &/*rCaller*/,int /*rcReason*/) +void ViewProviderMeshCurvature::OnChange(Base::Subject& /*rCaller*/, int /*rcReason*/) { setActiveMode(); } -namespace MeshGui { +namespace MeshGui +{ class Annotation { public: Annotation(Gui::ViewProviderDocumentObject* vp, - const QString& s,const SbVec3f& p, const SbVec3f& n) - : vp(vp), s(s), p(p), n(n) - { - } + const QString& s, + const SbVec3f& p, + const SbVec3f& n) + : vp(vp) + , s(s) + , p(p) + , n(n) + {} - static void run(void * data, SoSensor * sensor) + static void run(void* data, SoSensor* sensor) { Annotation* self = static_cast(data); self->show(); @@ -438,33 +460,34 @@ public: { App::Document* doc = vp->getObject()->getDocument(); - std::vector groups = doc->getObjectsOfType - (App::DocumentObjectGroup::getClassTypeId()); + std::vector groups = + doc->getObjectsOfType(App::DocumentObjectGroup::getClassTypeId()); App::DocumentObjectGroup* group = nullptr; std::string internalname = "CurvatureGroup"; - for (const auto & it : groups) { + for (const auto& it : groups) { if (internalname == it->getNameInDocument()) { group = static_cast(it); break; } } if (!group) { - group = static_cast(doc->addObject - ("App::DocumentObjectGroup",internalname.c_str())); + group = static_cast( + doc->addObject("App::DocumentObjectGroup", internalname.c_str())); } - App::AnnotationLabel* anno = static_cast - (group->addObject("App::AnnotationLabel", internalname.c_str())); + App::AnnotationLabel* anno = static_cast( + group->addObject("App::AnnotationLabel", internalname.c_str())); QStringList lines = s.split(QLatin1String("\n")); std::vector text; - for (const auto & line : lines) + for (const auto& line : lines) { text.emplace_back((const char*)line.toLatin1()); + } anno->LabelText.setValues(text); std::stringstream str; str << "Curvature info (" << group->Group.getSize() << ")"; anno->Label.setValue(str.str()); - anno->BasePosition.setValue(p[0],p[1],p[2]); - anno->TextPosition.setValue(n[0],n[1],n[2]); + anno->BasePosition.setValue(p[0], p[1], p[2]); + anno->TextPosition.setValue(n[0], n[1], n[2]); } private: @@ -474,18 +497,20 @@ private: SbVec3f n; }; -} +} // namespace MeshGui -void ViewProviderMeshCurvature::curvatureInfoCallback(void * ud, SoEventCallback * n) +void ViewProviderMeshCurvature::curvatureInfoCallback(void* ud, SoEventCallback* n) { - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); const SoEvent* ev = n->getEvent(); if (ev->getTypeId() == SoMouseButtonEvent::getClassTypeId()) { - const SoMouseButtonEvent * mbe = static_cast(ev); + const SoMouseButtonEvent* mbe = static_cast(ev); - // Mark all incoming mouse button events as handled, especially, to deactivate the selection node + // Mark all incoming mouse button events as handled, especially, to deactivate the selection + // node n->getAction()->setHandled(); - if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) { + if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 + && mbe->getState() == SoButtonEvent::UP) { n->setHandled(); // context-menu QMenu menu; @@ -505,8 +530,9 @@ void ViewProviderMeshCurvature::curvatureInfoCallback(void * ud, SoEventCallback view->removeEventCallback(SoEvent::getClassTypeId(), curvatureInfoCallback, ud); } } - else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::UP) { - const SoPickedPoint * point = n->getPickedPoint(); + else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 + && mbe->getState() == SoButtonEvent::UP) { + const SoPickedPoint* point = n->getPickedPoint(); if (!point) { Base::Console().Message("No facet picked.\n"); return; @@ -517,12 +543,14 @@ void ViewProviderMeshCurvature::curvatureInfoCallback(void * ud, SoEventCallback // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); - if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMeshCurvature::getClassTypeId())) + if (!vp + || !vp->getTypeId().isDerivedFrom(ViewProviderMeshCurvature::getClassTypeId())) { return; + } ViewProviderMeshCurvature* self = static_cast(vp); const SoDetail* detail = point->getDetail(point->getPath()->getTail()); if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) { - const SoFaceDetail * facedetail = static_cast(detail); + const SoFaceDetail* facedetail = static_cast(detail); // get the curvature info of the three points of the picked facet int index1 = facedetail->getPoint(0)->getCoordinateIndex(); int index2 = facedetail->getPoint(1)->getCoordinateIndex(); @@ -543,31 +571,34 @@ void ViewProviderMeshCurvature::curvatureInfoCallback(void * ud, SoEventCallback } } else if (ev->getTypeId().isDerivedFrom(SoLocation2Event::getClassTypeId())) { - const SoPickedPoint * point = n->getPickedPoint(); - if (!point) + const SoPickedPoint* point = n->getPickedPoint(); + if (!point) { return; + } n->setHandled(); // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); - if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMeshCurvature::getClassTypeId())) + if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMeshCurvature::getClassTypeId())) { return; + } ViewProviderMeshCurvature* that = static_cast(vp); const SoDetail* detail = point->getDetail(point->getPath()->getTail()); if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) { - const SoFaceDetail * facedetail = static_cast(detail); + const SoFaceDetail* facedetail = static_cast(detail); // get the curvature info of the three points of the picked facet int index1 = facedetail->getPoint(0)->getCoordinateIndex(); int index2 = facedetail->getPoint(1)->getCoordinateIndex(); int index3 = facedetail->getPoint(2)->getCoordinateIndex(); std::string info = that->curvatureInfo(false, index1, index2, index3); - Gui::getMainWindow()->setPaneText(1,QString::fromLatin1(info.c_str())); + Gui::getMainWindow()->setPaneText(1, QString::fromLatin1(info.c_str())); } } } -std::string ViewProviderMeshCurvature::curvatureInfo(bool detail, int index1, int index2, int index3) const +std::string +ViewProviderMeshCurvature::curvatureInfo(bool detail, int index1, int index2, int index3) const { // get the curvature info of the three points of the picked facet App::Property* prop = pcObject->getPropertyByName("CurvInfo"); @@ -577,9 +608,11 @@ std::string ViewProviderMeshCurvature::curvatureInfo(bool detail, int index1, in const Mesh::CurvatureInfo& cVal1 = (*curv)[index1]; const Mesh::CurvatureInfo& cVal2 = (*curv)[index2]; const Mesh::CurvatureInfo& cVal3 = (*curv)[index3]; - float fVal1 = 0.0f; float fVal2 = 0.0f; float fVal3 = 0.0f; + float fVal1 = 0.0f; + float fVal2 = 0.0f; + float fVal3 = 0.0f; - bool print=true; + bool print = true; std::string mode = getActiveDisplayMode(); if (mode == "Minimum curvature") { fVal1 = cVal1.fMinCurvature; @@ -592,19 +625,22 @@ std::string ViewProviderMeshCurvature::curvatureInfo(bool detail, int index1, in fVal3 = cVal3.fMaxCurvature; } else if (mode == "Gaussian curvature") { - fVal1 = cVal1.fMaxCurvature*cVal1.fMinCurvature; - fVal2 = cVal2.fMaxCurvature*cVal2.fMinCurvature; - fVal3 = cVal3.fMaxCurvature*cVal3.fMinCurvature; + fVal1 = cVal1.fMaxCurvature * cVal1.fMinCurvature; + fVal2 = cVal2.fMaxCurvature * cVal2.fMinCurvature; + fVal3 = cVal3.fMaxCurvature * cVal3.fMinCurvature; } else if (mode == "Mean curvature") { - fVal1 = 0.5f*(cVal1.fMaxCurvature+cVal1.fMinCurvature); - fVal2 = 0.5f*(cVal2.fMaxCurvature+cVal2.fMinCurvature); - fVal3 = 0.5f*(cVal3.fMaxCurvature+cVal3.fMinCurvature); + fVal1 = 0.5f * (cVal1.fMaxCurvature + cVal1.fMinCurvature); + fVal2 = 0.5f * (cVal2.fMaxCurvature + cVal2.fMinCurvature); + fVal3 = 0.5f * (cVal3.fMaxCurvature + cVal3.fMinCurvature); } else if (mode == "Absolute curvature") { - fVal1 = fabs(cVal1.fMaxCurvature) > fabs(cVal1.fMinCurvature) ? cVal1.fMaxCurvature : cVal1.fMinCurvature; - fVal2 = fabs(cVal2.fMaxCurvature) > fabs(cVal2.fMinCurvature) ? cVal2.fMaxCurvature : cVal2.fMinCurvature; - fVal3 = fabs(cVal3.fMaxCurvature) > fabs(cVal3.fMinCurvature) ? cVal3.fMaxCurvature : cVal3.fMinCurvature; + fVal1 = fabs(cVal1.fMaxCurvature) > fabs(cVal1.fMinCurvature) ? cVal1.fMaxCurvature + : cVal1.fMinCurvature; + fVal2 = fabs(cVal2.fMaxCurvature) > fabs(cVal2.fMinCurvature) ? cVal2.fMaxCurvature + : cVal2.fMinCurvature; + fVal3 = fabs(cVal3.fMaxCurvature) > fabs(cVal3.fMinCurvature) ? cVal3.fMaxCurvature + : cVal3.fMinCurvature; } else { print = false; diff --git a/src/Mod/Mesh/Gui/ViewProviderCurvature.h b/src/Mod/Mesh/Gui/ViewProviderCurvature.h index 66576c7338..b1199d8949 100644 --- a/src/Mod/Mesh/Gui/ViewProviderCurvature.h +++ b/src/Mod/Mesh/Gui/ViewProviderCurvature.h @@ -40,26 +40,30 @@ class SoPath; class SoLocateHighlight; class SoTransformerManip; -namespace Gui { - class SoFCColorBar; - class View3DInventorViewer; +namespace Gui +{ +class SoFCColorBar; +class View3DInventorViewer; +} // namespace Gui + +namespace Mesh +{ +class PropertyCurvatureList; } -namespace Mesh { - class PropertyCurvatureList; -} +namespace MeshGui +{ -namespace MeshGui { - -/** The ViewProviderMeshCurvature class is associated to the mesh curvature feature. It allows to display the most known types of - * curvatures, such as Gaussian curvature, mean curvature, minimum and maximum curvature. - * Moreover a color bar is also added to the scene. +/** The ViewProviderMeshCurvature class is associated to the mesh curvature feature. It allows to + * display the most known types of curvatures, such as Gaussian curvature, mean curvature, minimum + * and maximum curvature. Moreover a color bar is also added to the scene. * * @author Werner Mayer */ -class MeshGuiExport ViewProviderMeshCurvature : public Gui::ViewProviderDocumentObject, - public App::DocumentObserver, - public Base::Observer { +class MeshGuiExport ViewProviderMeshCurvature: public Gui::ViewProviderDocumentObject, + public App::DocumentObserver, + public Base::Observer +{ using inherited = Gui::ViewProviderDocumentObject; PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshCurvature); @@ -70,9 +74,13 @@ public: App::PropertyMaterial TextureMaterial; - /// Extracts the mesh data from the feature \a pcFeature and creates an Inventor node \a SoNode with these data. + /// Extracts the mesh data from the feature \a pcFeature and creates an Inventor node \a SoNode + /// with these data. void attach(App::DocumentObject* pcFeature) override; - bool useNewSelectionModel() const override {return false;} + bool useNewSelectionModel() const override + { + return false; + } /// Sets the viewing mode void setDisplayMode(const char* ModeName) override; /// get the default display mode @@ -83,8 +91,9 @@ public: void updateData(const App::Property*) override; /// Returns a pixmap for the associated feature type QIcon getIcon() const override; - /// Once the color bar settinhs has been changed this method gets called to update the feature's representation - void OnChange(Base::Subject &rCaller,int rcReason) override; + /// Once the color bar settinhs has been changed this method gets called to update the feature's + /// representation + void OnChange(Base::Subject& rCaller, int rcReason) override; /// Returns a color bar SoSeparator* getFrontRoot() const override; /// Hide the object in the view @@ -93,7 +102,7 @@ public: void show() override; public: - static void curvatureInfoCallback(void * ud, SoEventCallback * n); + static void curvatureInfoCallback(void* ud, SoEventCallback* n); protected: void onChanged(const App::Property* prop) override; @@ -102,23 +111,22 @@ protected: void touchShapeNode(); private: - void init(const Mesh::PropertyCurvatureList *prop); + void init(const Mesh::PropertyCurvatureList* prop); void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) override; protected: - SoMaterial * pcColorMat; - SoGroup * pcLinkRoot; + SoMaterial* pcColorMat; + SoGroup* pcLinkRoot; Gui::SoFCColorBar* pcColorBar; - SoDrawStyle * pcColorStyle; - SoSeparator * pcColorRoot; + SoDrawStyle* pcColorStyle; + SoSeparator* pcColorRoot; private: static bool addflag; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_VIEWPROVIDER_MESH_CURVATURE_H - +#endif // MESHGUI_VIEWPROVIDER_MESH_CURVATURE_H diff --git a/src/Mod/Mesh/Gui/ViewProviderDefects.cpp b/src/Mod/Mesh/Gui/ViewProviderDefects.cpp index d76bcf337b..992ce876bd 100644 --- a/src/Mod/Mesh/Gui/ViewProviderDefects.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderDefects.cpp @@ -22,22 +22,22 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include #include #include -#include #include #include +#include #include "ViewProviderDefects.h" @@ -59,7 +59,7 @@ PROPERTY_SOURCE(MeshGui::ViewProviderMeshFolds, MeshGui::ViewProviderMeshDefects ViewProviderMeshDefects::ViewProviderMeshDefects() { - ADD_PROPERTY(LineWidth,(2.0f)); + ADD_PROPERTY(LineWidth, (2.0f)); pcCoords = new SoCoordinate3(); pcCoords->ref(); @@ -80,8 +80,9 @@ void ViewProviderMeshDefects::onChanged(const App::Property* prop) if (prop == &LineWidth) { pcDrawStyle->lineWidth = LineWidth.getValue(); } - // Visibility changes must be handled here because in the base class it changes the attribute of the feature - // and thus affects the visibility of the mesh view provider which is undesired behaviour + // Visibility changes must be handled here because in the base class it changes the attribute of + // the feature and thus affects the visibility of the mesh view provider which is undesired + // behaviour else if (prop == &Visibility) { Visibility.getValue() ? show() : hide(); } @@ -105,7 +106,7 @@ ViewProviderMeshOrientation::~ViewProviderMeshOrientation() void ViewProviderMeshOrientation::attach(App::DocumentObject* pcFeat) { - ViewProviderDocumentObject::attach( pcFeat ); + ViewProviderDocumentObject::attach(pcFeat); SoGroup* pcFaceRoot = new SoGroup(); @@ -113,24 +114,28 @@ void ViewProviderMeshOrientation::attach(App::DocumentObject* pcFeat) pcFlatStyle->style = SoDrawStyle::FILLED; pcFaceRoot->addChild(pcFlatStyle); - SoShapeHints * flathints = new SoShapeHints; - flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE ; + SoShapeHints* flathints = new SoShapeHints; + flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; pcFaceRoot->addChild(flathints); // Draw faces SoSeparator* linesep = new SoSeparator; - SoBaseColor * basecol = new SoBaseColor; - basecol->rgb.setValue( 1.0f, 0.5f, 0.0f ); + SoBaseColor* basecol = new SoBaseColor; + basecol->rgb.setValue(1.0f, 0.5f, 0.0f); linesep->addChild(basecol); linesep->addChild(pcCoords); linesep->addChild(pcFaces); // Draw markers - SoBaseColor * markcol = new SoBaseColor; - markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); + SoBaseColor* markcol = new SoBaseColor; + markcol->rgb.setValue(1.0f, 1.0f, 0.0f); SoMarkerSet* marker = new SoMarkerSet; - marker->markerIndex=Gui::Inventor::MarkerBitmaps::getMarkerIndex("PLUS", App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetInt("MarkerSize", 7)); + marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex( + "PLUS", + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetInt("MarkerSize", 7)); linesep->addChild(markcol); linesep->addChild(marker); @@ -142,19 +147,19 @@ void ViewProviderMeshOrientation::attach(App::DocumentObject* pcFeat) void ViewProviderMeshOrientation::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); - const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel(); pcCoords->point.deleteValues(0); - pcCoords->point.setNum(3*inds.size()); + pcCoords->point.setNum(3 * inds.size()); MeshCore::MeshFacetIterator cF(rMesh); - int i=0; - int j=0; + int i = 0; + int j = 0; for (Mesh::ElementIndex ind : inds) { cF.Set(ind); for (auto cP : cF->_aclPoints) { // move a bit in opposite normal direction to overlay the original faces cP -= 0.001f * cF->GetNormal(); - pcCoords->point.set1Value(i++,cP.x,cP.y,cP.z); + pcCoords->point.set1Value(i++, cP.x, cP.y, cP.z); } pcFaces->numVertices.set1Value(j++, 3); } @@ -177,7 +182,7 @@ ViewProviderMeshNonManifolds::~ViewProviderMeshNonManifolds() void ViewProviderMeshNonManifolds::attach(App::DocumentObject* pcFeat) { - ViewProviderDocumentObject::attach( pcFeat ); + ViewProviderDocumentObject::attach(pcFeat); SoGroup* pcLineRoot = new SoGroup(); pcDrawStyle->lineWidth = 3; @@ -185,18 +190,22 @@ void ViewProviderMeshNonManifolds::attach(App::DocumentObject* pcFeat) // Draw lines SoSeparator* linesep = new SoSeparator; - SoBaseColor * basecol = new SoBaseColor; - basecol->rgb.setValue( 1.0f, 0.0f, 0.0f ); + SoBaseColor* basecol = new SoBaseColor; + basecol->rgb.setValue(1.0f, 0.0f, 0.0f); linesep->addChild(basecol); linesep->addChild(pcCoords); linesep->addChild(pcLines); pcLineRoot->addChild(linesep); // Draw markers - SoBaseColor * markcol = new SoBaseColor; - markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); + SoBaseColor* markcol = new SoBaseColor; + markcol->rgb.setValue(1.0f, 1.0f, 0.0f); SoMarkerSet* marker = new SoMarkerSet; - marker->markerIndex=Gui::Inventor::MarkerBitmaps::getMarkerIndex("PLUS", App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetInt("MarkerSize", 7)); + marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex( + "PLUS", + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetInt("MarkerSize", 7)); linesep->addChild(markcol); linesep->addChild(marker); @@ -205,22 +214,24 @@ void ViewProviderMeshNonManifolds::attach(App::DocumentObject* pcFeat) void ViewProviderMeshNonManifolds::showDefects(const std::vector& inds) { - if ((inds.size() % 2) != 0) + if ((inds.size() % 2) != 0) { return; + } Mesh::Feature* f = static_cast(pcObject); - const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel(); pcCoords->point.deleteValues(0); pcCoords->point.setNum(inds.size()); MeshCore::MeshPointIterator cP(rMesh); - int i=0; - int j=0; - for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { + int i = 0; + int j = 0; + for (std::vector::const_iterator it = inds.begin(); it != inds.end(); + ++it) { cP.Set(*it); - pcCoords->point.set1Value(i++,cP->x,cP->y,cP->z); - ++it; // go to end point + pcCoords->point.set1Value(i++, cP->x, cP->y, cP->z); + ++it; // go to end point cP.Set(*it); - pcCoords->point.set1Value(i++,cP->x,cP->y,cP->z); + pcCoords->point.set1Value(i++, cP->x, cP->y, cP->z); pcLines->numVertices.set1Value(j++, 2); } @@ -242,7 +253,7 @@ ViewProviderMeshNonManifoldPoints::~ViewProviderMeshNonManifoldPoints() void ViewProviderMeshNonManifoldPoints::attach(App::DocumentObject* pcFeat) { - ViewProviderDocumentObject::attach( pcFeat ); + ViewProviderDocumentObject::attach(pcFeat); SoGroup* pcPointRoot = new SoGroup(); pcDrawStyle->pointSize = 3; @@ -250,18 +261,22 @@ void ViewProviderMeshNonManifoldPoints::attach(App::DocumentObject* pcFeat) // Draw points SoSeparator* pointsep = new SoSeparator; - SoBaseColor * basecol = new SoBaseColor; - basecol->rgb.setValue( 1.0f, 0.5f, 0.0f ); + SoBaseColor* basecol = new SoBaseColor; + basecol->rgb.setValue(1.0f, 0.5f, 0.0f); pointsep->addChild(basecol); pointsep->addChild(pcCoords); pointsep->addChild(pcPoints); pcPointRoot->addChild(pointsep); // Draw markers - SoBaseColor * markcol = new SoBaseColor; - markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); + SoBaseColor* markcol = new SoBaseColor; + markcol->rgb.setValue(1.0f, 1.0f, 0.0f); SoMarkerSet* marker = new SoMarkerSet; - marker->markerIndex=Gui::Inventor::MarkerBitmaps::getMarkerIndex("PLUS", App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetInt("MarkerSize", 7)); + marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex( + "PLUS", + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetInt("MarkerSize", 7)); pointsep->addChild(markcol); pointsep->addChild(marker); @@ -271,14 +286,14 @@ void ViewProviderMeshNonManifoldPoints::attach(App::DocumentObject* pcFeat) void ViewProviderMeshNonManifoldPoints::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); - const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel(); pcCoords->point.deleteValues(0); pcCoords->point.setNum(inds.size()); MeshCore::MeshPointIterator cP(rMesh); int i = 0; for (Mesh::ElementIndex ind : inds) { cP.Set(ind); - pcCoords->point.set1Value(i++,cP->x,cP->y,cP->z); + pcCoords->point.set1Value(i++, cP->x, cP->y, cP->z); } setDisplayMaskMode("Point"); @@ -299,7 +314,7 @@ ViewProviderMeshDuplicatedFaces::~ViewProviderMeshDuplicatedFaces() void ViewProviderMeshDuplicatedFaces::attach(App::DocumentObject* pcFeat) { - ViewProviderDocumentObject::attach( pcFeat ); + ViewProviderDocumentObject::attach(pcFeat); SoGroup* pcFaceRoot = new SoGroup(); @@ -307,25 +322,29 @@ void ViewProviderMeshDuplicatedFaces::attach(App::DocumentObject* pcFeat) pcFlatStyle->style = SoDrawStyle::FILLED; pcFaceRoot->addChild(pcFlatStyle); - SoShapeHints * flathints = new SoShapeHints; - flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE ; + SoShapeHints* flathints = new SoShapeHints; + flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; pcFaceRoot->addChild(flathints); // Draw lines SoSeparator* linesep = new SoSeparator; - SoBaseColor * basecol = new SoBaseColor; - basecol->rgb.setValue( 1.0f, 0.0f, 0.0f ); + SoBaseColor* basecol = new SoBaseColor; + basecol->rgb.setValue(1.0f, 0.0f, 0.0f); linesep->addChild(basecol); linesep->addChild(pcCoords); linesep->addChild(pcFaces); pcFaceRoot->addChild(linesep); // Draw markers - SoBaseColor * markcol = new SoBaseColor; - markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); + SoBaseColor* markcol = new SoBaseColor; + markcol->rgb.setValue(1.0f, 1.0f, 0.0f); SoMarkerSet* marker = new SoMarkerSet; - marker->markerIndex=Gui::Inventor::MarkerBitmaps::getMarkerIndex("PLUS", App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetInt("MarkerSize", 7)); + marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex( + "PLUS", + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetInt("MarkerSize", 7)); linesep->addChild(markcol); linesep->addChild(marker); @@ -335,19 +354,19 @@ void ViewProviderMeshDuplicatedFaces::attach(App::DocumentObject* pcFeat) void ViewProviderMeshDuplicatedFaces::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); - const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel(); pcCoords->point.deleteValues(0); - pcCoords->point.setNum(3*inds.size()); + pcCoords->point.setNum(3 * inds.size()); MeshCore::MeshFacetIterator cF(rMesh); - int i=0; - int j=0; + int i = 0; + int j = 0; for (Mesh::ElementIndex ind : inds) { cF.Set(ind); for (auto cP : cF->_aclPoints) { // move a bit in normal direction to overlay the original faces cP += 0.001f * cF->GetNormal(); - pcCoords->point.set1Value(i++,cP.x,cP.y,cP.z); + pcCoords->point.set1Value(i++, cP.x, cP.y, cP.z); } pcFaces->numVertices.set1Value(j++, 3); } @@ -370,7 +389,7 @@ ViewProviderMeshDuplicatedPoints::~ViewProviderMeshDuplicatedPoints() void ViewProviderMeshDuplicatedPoints::attach(App::DocumentObject* pcFeat) { - ViewProviderDocumentObject::attach( pcFeat ); + ViewProviderDocumentObject::attach(pcFeat); SoGroup* pcPointRoot = new SoGroup(); pcDrawStyle->pointSize = 3; @@ -378,18 +397,22 @@ void ViewProviderMeshDuplicatedPoints::attach(App::DocumentObject* pcFeat) // Draw points SoSeparator* pointsep = new SoSeparator; - SoBaseColor * basecol = new SoBaseColor; - basecol->rgb.setValue( 1.0f, 0.5f, 0.0f ); + SoBaseColor* basecol = new SoBaseColor; + basecol->rgb.setValue(1.0f, 0.5f, 0.0f); pointsep->addChild(basecol); pointsep->addChild(pcCoords); pointsep->addChild(pcPoints); pcPointRoot->addChild(pointsep); // Draw markers - SoBaseColor * markcol = new SoBaseColor; - markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); + SoBaseColor* markcol = new SoBaseColor; + markcol->rgb.setValue(1.0f, 1.0f, 0.0f); SoMarkerSet* marker = new SoMarkerSet; - marker->markerIndex=Gui::Inventor::MarkerBitmaps::getMarkerIndex("PLUS", App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetInt("MarkerSize", 7)); + marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex( + "PLUS", + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetInt("MarkerSize", 7)); pointsep->addChild(markcol); pointsep->addChild(marker); @@ -399,14 +422,14 @@ void ViewProviderMeshDuplicatedPoints::attach(App::DocumentObject* pcFeat) void ViewProviderMeshDuplicatedPoints::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); - const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel(); pcCoords->point.deleteValues(0); pcCoords->point.setNum(inds.size()); MeshCore::MeshPointIterator cP(rMesh); int i = 0; for (Mesh::ElementIndex ind : inds) { cP.Set(ind); - pcCoords->point.set1Value(i++,cP->x,cP->y,cP->z); + pcCoords->point.set1Value(i++, cP->x, cP->y, cP->z); } setDisplayMaskMode("Point"); @@ -427,7 +450,7 @@ ViewProviderMeshDegenerations::~ViewProviderMeshDegenerations() void ViewProviderMeshDegenerations::attach(App::DocumentObject* pcFeat) { - ViewProviderDocumentObject::attach( pcFeat ); + ViewProviderDocumentObject::attach(pcFeat); SoGroup* pcLineRoot = new SoGroup(); pcDrawStyle->lineWidth = 3; @@ -435,18 +458,22 @@ void ViewProviderMeshDegenerations::attach(App::DocumentObject* pcFeat) // Draw lines SoSeparator* linesep = new SoSeparator; - SoBaseColor * basecol = new SoBaseColor; - basecol->rgb.setValue( 1.0f, 0.5f, 0.0f ); + SoBaseColor* basecol = new SoBaseColor; + basecol->rgb.setValue(1.0f, 0.5f, 0.0f); linesep->addChild(basecol); linesep->addChild(pcCoords); linesep->addChild(pcLines); pcLineRoot->addChild(linesep); // Draw markers - SoBaseColor * markcol = new SoBaseColor; - markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); + SoBaseColor* markcol = new SoBaseColor; + markcol->rgb.setValue(1.0f, 1.0f, 0.0f); SoMarkerSet* marker = new SoMarkerSet; - marker->markerIndex=Gui::Inventor::MarkerBitmaps::getMarkerIndex("PLUS", App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetInt("MarkerSize", 7)); + marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex( + "PLUS", + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetInt("MarkerSize", 7)); linesep->addChild(markcol); linesep->addChild(marker); @@ -456,13 +483,13 @@ void ViewProviderMeshDegenerations::attach(App::DocumentObject* pcFeat) void ViewProviderMeshDegenerations::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); - const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel(); pcCoords->point.deleteValues(0); - pcCoords->point.setNum(2*inds.size()); + pcCoords->point.setNum(2 * inds.size()); MeshCore::MeshFacetIterator cF(rMesh); - int i=0; - int j=0; + int i = 0; + int j = 0; for (Mesh::ElementIndex ind : inds) { cF.Set(ind); const MeshCore::MeshPoint& rE0 = cF->_aclPoints[0]; @@ -474,32 +501,38 @@ void ViewProviderMeshDegenerations::showDefects(const std::vectorpoint.set1Value(i++,cP1.x,cP1.y,cP1.z); - pcCoords->point.set1Value(i++,cP2.x,cP2.y,cP2.z); + cP1.Set(rE1.x + eps, rE1.y + eps, rE1.z + eps); + cP2.Set(rE2.x - eps, rE2.y - eps, rE2.z - eps); + pcCoords->point.set1Value(i++, cP1.x, cP1.y, cP1.z); + pcCoords->point.set1Value(i++, cP2.x, cP2.y, cP2.z); } else if (rE0 == rE1) { - pcCoords->point.set1Value(i++,rE1.x,rE1.y,rE1.z); - pcCoords->point.set1Value(i++,rE2.x,rE2.y,rE2.z); + pcCoords->point.set1Value(i++, rE1.x, rE1.y, rE1.z); + pcCoords->point.set1Value(i++, rE2.x, rE2.y, rE2.z); } else if (rE1 == rE2) { - pcCoords->point.set1Value(i++,rE2.x,rE2.y,rE2.z); - pcCoords->point.set1Value(i++,rE0.x,rE0.y,rE0.z); + pcCoords->point.set1Value(i++, rE2.x, rE2.y, rE2.z); + pcCoords->point.set1Value(i++, rE0.x, rE0.y, rE0.z); } else if (rE2 == rE0) { - pcCoords->point.set1Value(i++,rE0.x,rE0.y,rE0.z); - pcCoords->point.set1Value(i++,rE1.x,rE1.y,rE1.z); + pcCoords->point.set1Value(i++, rE0.x, rE0.y, rE0.z); + pcCoords->point.set1Value(i++, rE1.x, rE1.y, rE1.z); } else { - for (int j=0; j<3; j++) { - Base::Vector3f cVec1 = cF->_aclPoints[(j+1)%3] - cF->_aclPoints[j]; - Base::Vector3f cVec2 = cF->_aclPoints[(j+2)%3] - cF->_aclPoints[j]; + for (int j = 0; j < 3; j++) { + Base::Vector3f cVec1 = cF->_aclPoints[(j + 1) % 3] - cF->_aclPoints[j]; + Base::Vector3f cVec2 = cF->_aclPoints[(j + 2) % 3] - cF->_aclPoints[j]; // adjust the neighbourhoods and point indices if (cVec1 * cVec2 < 0.0f) { - pcCoords->point.set1Value(i++,cF->_aclPoints[(j+1)%3].x,cF->_aclPoints[(j+1)%3].y,cF->_aclPoints[(j+1)%3].z); - pcCoords->point.set1Value(i++,cF->_aclPoints[(j+2)%3].x,cF->_aclPoints[(j+2)%3].y,cF->_aclPoints[(j+2)%3].z); + pcCoords->point.set1Value(i++, + cF->_aclPoints[(j + 1) % 3].x, + cF->_aclPoints[(j + 1) % 3].y, + cF->_aclPoints[(j + 1) % 3].z); + pcCoords->point.set1Value(i++, + cF->_aclPoints[(j + 2) % 3].x, + cF->_aclPoints[(j + 2) % 3].y, + cF->_aclPoints[(j + 2) % 3].z); break; } } @@ -526,7 +559,7 @@ ViewProviderMeshIndices::~ViewProviderMeshIndices() void ViewProviderMeshIndices::attach(App::DocumentObject* pcFeat) { - ViewProviderDocumentObject::attach( pcFeat ); + ViewProviderDocumentObject::attach(pcFeat); SoGroup* pcFaceRoot = new SoGroup(); @@ -534,25 +567,29 @@ void ViewProviderMeshIndices::attach(App::DocumentObject* pcFeat) pcFlatStyle->style = SoDrawStyle::FILLED; pcFaceRoot->addChild(pcFlatStyle); - SoShapeHints * flathints = new SoShapeHints; - flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE ; + SoShapeHints* flathints = new SoShapeHints; + flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; pcFaceRoot->addChild(flathints); // Draw lines SoSeparator* linesep = new SoSeparator; - SoBaseColor * basecol = new SoBaseColor; - basecol->rgb.setValue( 1.0f, 0.5f, 0.0f ); + SoBaseColor* basecol = new SoBaseColor; + basecol->rgb.setValue(1.0f, 0.5f, 0.0f); linesep->addChild(basecol); linesep->addChild(pcCoords); linesep->addChild(pcFaces); pcFaceRoot->addChild(linesep); // Draw markers - SoBaseColor * markcol = new SoBaseColor; - markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); + SoBaseColor* markcol = new SoBaseColor; + markcol->rgb.setValue(1.0f, 1.0f, 0.0f); SoMarkerSet* marker = new SoMarkerSet; - marker->markerIndex=Gui::Inventor::MarkerBitmaps::getMarkerIndex("PLUS", App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetInt("MarkerSize", 7)); + marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex( + "PLUS", + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetInt("MarkerSize", 7)); linesep->addChild(markcol); linesep->addChild(marker); @@ -562,20 +599,20 @@ void ViewProviderMeshIndices::attach(App::DocumentObject* pcFeat) void ViewProviderMeshIndices::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); - const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel(); if (!inds.empty()) { pcCoords->point.deleteValues(0); - pcCoords->point.setNum(3*inds.size()); + pcCoords->point.setNum(3 * inds.size()); MeshCore::MeshFacetIterator cF(rMesh); - int i=0; - int j=0; + int i = 0; + int j = 0; for (Mesh::ElementIndex ind : inds) { cF.Set(ind); for (auto cP : cF->_aclPoints) { // move a bit in opposite normal direction to overlay the original faces cP -= 0.001f * cF->GetNormal(); - pcCoords->point.set1Value(i++,cP.x,cP.y,cP.z); + pcCoords->point.set1Value(i++, cP.x, cP.y, cP.z); } pcFaces->numVertices.set1Value(j++, 3); } @@ -599,7 +636,7 @@ ViewProviderMeshSelfIntersections::~ViewProviderMeshSelfIntersections() void ViewProviderMeshSelfIntersections::attach(App::DocumentObject* pcFeat) { - ViewProviderDocumentObject::attach( pcFeat ); + ViewProviderDocumentObject::attach(pcFeat); SoGroup* pcLineRoot = new SoGroup(); pcDrawStyle->lineWidth = 3; @@ -607,18 +644,22 @@ void ViewProviderMeshSelfIntersections::attach(App::DocumentObject* pcFeat) // Draw lines SoSeparator* linesep = new SoSeparator; - SoBaseColor * basecol = new SoBaseColor; - basecol->rgb.setValue( 1.0f, 0.5f, 0.0f ); + SoBaseColor* basecol = new SoBaseColor; + basecol->rgb.setValue(1.0f, 0.5f, 0.0f); linesep->addChild(basecol); linesep->addChild(pcCoords); linesep->addChild(pcLines); pcLineRoot->addChild(linesep); // Draw markers - SoBaseColor * markcol = new SoBaseColor; - markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); + SoBaseColor* markcol = new SoBaseColor; + markcol->rgb.setValue(1.0f, 1.0f, 0.0f); SoMarkerSet* marker = new SoMarkerSet; - marker->markerIndex=Gui::Inventor::MarkerBitmaps::getMarkerIndex("PLUS", App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetInt("MarkerSize", 7)); + marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex( + "PLUS", + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetInt("MarkerSize", 7)); linesep->addChild(markcol); linesep->addChild(marker); @@ -627,30 +668,33 @@ void ViewProviderMeshSelfIntersections::attach(App::DocumentObject* pcFeat) void ViewProviderMeshSelfIntersections::showDefects(const std::vector& indices) { - if (indices.size() % 2 != 0) + if (indices.size() % 2 != 0) { return; + } Mesh::Feature* f = static_cast(pcObject); - const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel(); MeshCore::MeshEvalSelfIntersection eval(rMesh); - std::vector > intersection; + std::vector> intersection; std::vector::const_iterator it; - for (it = indices.begin(); it != indices.end(); ) { - Mesh::ElementIndex id1 = *it; ++it; - Mesh::ElementIndex id2 = *it; ++it; - intersection.emplace_back(id1,id2); + for (it = indices.begin(); it != indices.end();) { + Mesh::ElementIndex id1 = *it; + ++it; + Mesh::ElementIndex id2 = *it; + ++it; + intersection.emplace_back(id1, id2); } - std::vector > lines; + std::vector> lines; eval.GetIntersections(intersection, lines); pcCoords->point.deleteValues(0); - pcCoords->point.setNum(2*lines.size()); - int i=0; - int j=0; - for (const auto & line : lines) { - pcCoords->point.set1Value(i++,line.first.x,line.first.y,line.first.z); - pcCoords->point.set1Value(i++,line.second.x,line.second.y,line.second.z); + pcCoords->point.setNum(2 * lines.size()); + int i = 0; + int j = 0; + for (const auto& line : lines) { + pcCoords->point.set1Value(i++, line.first.x, line.first.y, line.first.z); + pcCoords->point.set1Value(i++, line.second.x, line.second.y, line.second.z); pcLines->numVertices.set1Value(j++, 2); } @@ -672,7 +716,7 @@ ViewProviderMeshFolds::~ViewProviderMeshFolds() void ViewProviderMeshFolds::attach(App::DocumentObject* pcFeat) { - ViewProviderDocumentObject::attach( pcFeat ); + ViewProviderDocumentObject::attach(pcFeat); SoGroup* pcFaceRoot = new SoGroup(); @@ -680,25 +724,29 @@ void ViewProviderMeshFolds::attach(App::DocumentObject* pcFeat) pcFlatStyle->style = SoDrawStyle::FILLED; pcFaceRoot->addChild(pcFlatStyle); - SoShapeHints * flathints = new SoShapeHints; - flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE ; + SoShapeHints* flathints = new SoShapeHints; + flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; pcFaceRoot->addChild(flathints); // Draw lines SoSeparator* linesep = new SoSeparator; - SoBaseColor * basecol = new SoBaseColor; - basecol->rgb.setValue( 1.0f, 0.0f, 0.0f ); + SoBaseColor* basecol = new SoBaseColor; + basecol->rgb.setValue(1.0f, 0.0f, 0.0f); linesep->addChild(basecol); linesep->addChild(pcCoords); linesep->addChild(pcFaces); pcFaceRoot->addChild(linesep); // Draw markers - SoBaseColor * markcol = new SoBaseColor; - markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); + SoBaseColor* markcol = new SoBaseColor; + markcol->rgb.setValue(1.0f, 1.0f, 0.0f); SoMarkerSet* marker = new SoMarkerSet; - marker->markerIndex=Gui::Inventor::MarkerBitmaps::getMarkerIndex("PLUS", App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetInt("MarkerSize", 7)); + marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex( + "PLUS", + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetInt("MarkerSize", 7)); linesep->addChild(markcol); linesep->addChild(marker); @@ -708,19 +756,19 @@ void ViewProviderMeshFolds::attach(App::DocumentObject* pcFeat) void ViewProviderMeshFolds::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); - const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); + const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel(); pcCoords->point.deleteValues(0); - pcCoords->point.setNum(3*inds.size()); + pcCoords->point.setNum(3 * inds.size()); MeshCore::MeshFacetIterator cF(rMesh); - int i=0; - int j=0; + int i = 0; + int j = 0; for (Mesh::ElementIndex ind : inds) { cF.Set(ind); for (auto cP : cF->_aclPoints) { // move a bit in normal direction to overlay the original faces cP += 0.001f * cF->GetNormal(); - pcCoords->point.set1Value(i++,cP.x,cP.y,cP.z); + pcCoords->point.set1Value(i++, cP.x, cP.y, cP.z); } pcFaces->numVertices.set1Value(j++, 3); } diff --git a/src/Mod/Mesh/Gui/ViewProviderDefects.h b/src/Mod/Mesh/Gui/ViewProviderDefects.h index 776c93d9d4..c94daf67f5 100644 --- a/src/Mod/Mesh/Gui/ViewProviderDefects.h +++ b/src/Mod/Mesh/Gui/ViewProviderDefects.h @@ -30,13 +30,15 @@ class SoPointSet; class SoLineSet; class SoFaceSet; -namespace MeshGui { +namespace MeshGui +{ -/** The ViewProviderMeshDefects class is used to display the most known types of defects of a polymesh. - * In subclasses defects like non-manifolds, wrong oriented facets, degenerated facets, duplicates, .... are displayed. +/** The ViewProviderMeshDefects class is used to display the most known types of defects of a + * polymesh. In subclasses defects like non-manifolds, wrong oriented facets, degenerated facets, + * duplicates, .... are displayed. * @author Werner Mayer */ -class MeshGuiExport ViewProviderMeshDefects : public Gui::ViewProviderDocumentObject +class MeshGuiExport ViewProviderMeshDefects: public Gui::ViewProviderDocumentObject { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshDefects); @@ -56,14 +58,15 @@ protected: /// get called by the container whenever a property has been changed void onChanged(const App::Property* prop) override; - SoCoordinate3 * pcCoords; - SoDrawStyle * pcDrawStyle; + SoCoordinate3* pcCoords; + SoDrawStyle* pcDrawStyle; }; -/** The ViewProviderMeshOrientation class displays wrong oriented facets (i.e. flipped normals) in orange. +/** The ViewProviderMeshOrientation class displays wrong oriented facets (i.e. flipped normals) in + * orange. * @author Werner Mayer */ -class MeshGuiExport ViewProviderMeshOrientation : public ViewProviderMeshDefects +class MeshGuiExport ViewProviderMeshOrientation: public ViewProviderMeshDefects { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshOrientation); @@ -81,7 +84,7 @@ protected: /** The ViewProviderMeshNonManifolds class displays edges with more than two faces attached in red. * @author Werner Mayer */ -class MeshGuiExport ViewProviderMeshNonManifolds : public ViewProviderMeshDefects +class MeshGuiExport ViewProviderMeshNonManifolds: public ViewProviderMeshDefects { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshNonManifolds); @@ -99,7 +102,7 @@ protected: /** The ViewProviderMeshNonManifoldPoints class displays non-manifold vertexes in red. * @author Werner Mayer */ -class MeshGuiExport ViewProviderMeshNonManifoldPoints : public ViewProviderMeshDefects +class MeshGuiExport ViewProviderMeshNonManifoldPoints: public ViewProviderMeshDefects { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshNonManifoldPoints); @@ -117,7 +120,7 @@ protected: /** The ViewProviderMeshDuplicatedFaces class displays duplicated faces in red. * @author Werner Mayer */ -class MeshGuiExport ViewProviderMeshDuplicatedFaces : public ViewProviderMeshDefects +class MeshGuiExport ViewProviderMeshDuplicatedFaces: public ViewProviderMeshDefects { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshDuplicatedFaces); @@ -132,10 +135,11 @@ protected: SoFaceSet* pcFaces; }; -/** The ViewProviderMeshDegenerations class displays degenerated faces to a line or even a point in orange. +/** The ViewProviderMeshDegenerations class displays degenerated faces to a line or even a point in + * orange. * @author Werner Mayer */ -class MeshGuiExport ViewProviderMeshDegenerations : public ViewProviderMeshDefects +class MeshGuiExport ViewProviderMeshDegenerations: public ViewProviderMeshDefects { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshDegenerations); @@ -150,7 +154,7 @@ protected: SoLineSet* pcLines; }; -class MeshGuiExport ViewProviderMeshDuplicatedPoints : public ViewProviderMeshDefects +class MeshGuiExport ViewProviderMeshDuplicatedPoints: public ViewProviderMeshDefects { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshDuplicatedPoints); @@ -165,7 +169,7 @@ protected: SoPointSet* pcPoints; }; -class MeshGuiExport ViewProviderMeshIndices : public ViewProviderMeshDefects +class MeshGuiExport ViewProviderMeshIndices: public ViewProviderMeshDefects { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshIndices); @@ -183,7 +187,7 @@ protected: /** The ViewProviderMeshSelfIntersections class displays lines of self-intersections. * @author Werner Mayer */ -class MeshGuiExport ViewProviderMeshSelfIntersections : public ViewProviderMeshDefects +class MeshGuiExport ViewProviderMeshSelfIntersections: public ViewProviderMeshDefects { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshSelfIntersections); @@ -198,7 +202,7 @@ protected: SoLineSet* pcLines; }; -class MeshGuiExport ViewProviderMeshFolds : public ViewProviderMeshDefects +class MeshGuiExport ViewProviderMeshFolds: public ViewProviderMeshDefects { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshFolds); @@ -213,8 +217,7 @@ protected: SoFaceSet* pcFaces; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_VIEWPROVIDER_MESH_DEFECTS_H - +#endif // MESHGUI_VIEWPROVIDER_MESH_DEFECTS_H diff --git a/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.cpp b/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.cpp index 6d7febbbf0..53e62186e5 100644 --- a/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.cpp @@ -22,26 +22,26 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include #endif #include #include #include -#include #include #include +#include -#include "ViewProviderMeshFaceSet.h" #include "SoFCIndexedFaceSet.h" #include "SoFCMeshObject.h" +#include "ViewProviderMeshFaceSet.h" using namespace MeshGui; @@ -77,7 +77,7 @@ ViewProviderMeshFaceSet::~ViewProviderMeshFaceSet() pcMeshFaces->unref(); } -void ViewProviderMeshFaceSet::attach(App::DocumentObject *pcFeat) +void ViewProviderMeshFaceSet::attach(App::DocumentObject* pcFeat) { ViewProviderMesh::attach(pcFeat); @@ -85,11 +85,13 @@ void ViewProviderMeshFaceSet::attach(App::DocumentObject *pcFeat) pcShapeGroup->addChild(pcMeshFaces); // read the threshold from the preferences - Base::Reference hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); + Base::Reference hGrp = + Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); int size = hGrp->GetInt("RenderTriangleLimit", -1); if (size > 0) { - pcMeshShape->renderTriangleLimit = (unsigned int)(pow(10.0f,size)); - static_cast(pcMeshFaces)->renderTriangleLimit = (unsigned int)(pow(10.0f,size)); + pcMeshShape->renderTriangleLimit = (unsigned int)(pow(10.0f, size)); + static_cast(pcMeshFaces)->renderTriangleLimit = + (unsigned int)(pow(10.0f, size)); } } @@ -97,7 +99,8 @@ void ViewProviderMeshFaceSet::updateData(const App::Property* prop) { ViewProviderMesh::updateData(prop); if (prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) { - const Mesh::MeshObject* mesh = static_cast(prop)->getValuePtr(); + const Mesh::MeshObject* mesh = + static_cast(prop)->getValuePtr(); bool direct = MeshRenderer::shouldRenderDirectly(mesh->countFacets() > this->triangleCount); if (direct) { @@ -130,10 +133,12 @@ void ViewProviderMeshFaceSet::updateData(const App::Property* prop) showOpenEdges(OpenEdges.getValue()); std::vector selection; mesh->getFacetsFromSelection(selection); - if (selection.empty()) + if (selection.empty()) { unhighlightSelection(); - else + } + else { highlightSelection(); + } } } @@ -160,15 +165,16 @@ void ViewProviderMeshFaceSet::showOpenEdges(bool show) pcOpenEdge->addChild(lines); // Build up the lines with indices to the list of vertices 'pcMeshCoord' - int index=0; - const MeshCore::MeshKernel& rMesh = static_cast(pcObject)->Mesh.getValue().getKernel(); + int index = 0; + const MeshCore::MeshKernel& rMesh = + static_cast(pcObject)->Mesh.getValue().getKernel(); const MeshCore::MeshFacetArray& rFaces = rMesh.GetFacets(); - for (const auto & rFace : rFaces) { - for (int i=0; i<3; i++) { + for (const auto& rFace : rFaces) { + for (int i = 0; i < 3; i++) { if (rFace._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) { - lines->coordIndex.set1Value(index++,rFace._aulPoints[i]); - lines->coordIndex.set1Value(index++,rFace._aulPoints[(i+1)%3]); - lines->coordIndex.set1Value(index++,SO_END_LINE_INDEX); + lines->coordIndex.set1Value(index++, rFace._aulPoints[i]); + lines->coordIndex.set1Value(index++, rFace._aulPoints[(i + 1) % 3]); + lines->coordIndex.set1Value(index++, SO_END_LINE_INDEX); } } } @@ -181,14 +187,16 @@ void ViewProviderMeshFaceSet::showOpenEdges(bool show) SoShape* ViewProviderMeshFaceSet::getShapeNode() const { - if (directRendering) + if (directRendering) { return this->pcMeshShape; + } return this->pcMeshFaces; } SoNode* ViewProviderMeshFaceSet::getCoordNode() const { - if (directRendering) + if (directRendering) { return this->pcMeshNode; + } return this->pcMeshCoord; } diff --git a/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.h b/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.h index 9bc233f949..dd6413cfb6 100644 --- a/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.h +++ b/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.h @@ -25,7 +25,8 @@ #include -namespace MeshGui { +namespace MeshGui +{ class SoFCIndexedFaceSet; /** @@ -46,7 +47,7 @@ class SoFCIndexedFaceSet; * For more details @see SoFCMeshNode and SoFCMeshFaceSet. * @author Werner Mayer */ -class MeshGuiExport ViewProviderMeshFaceSet : public ViewProviderMesh +class MeshGuiExport ViewProviderMeshFaceSet: public ViewProviderMesh { PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshFaceSet); @@ -54,7 +55,7 @@ public: ViewProviderMeshFaceSet(); ~ViewProviderMeshFaceSet() override; - void attach(App::DocumentObject *pcFeat) override; + void attach(App::DocumentObject* pcFeat) override; void updateData(const App::Property*) override; protected: @@ -65,14 +66,13 @@ protected: private: bool directRendering; unsigned long triangleCount; - SoCoordinate3 * pcMeshCoord; - SoFCIndexedFaceSet * pcMeshFaces; - SoFCMeshObjectNode * pcMeshNode; - SoFCMeshObjectShape * pcMeshShape; + SoCoordinate3* pcMeshCoord; + SoFCIndexedFaceSet* pcMeshFaces; + SoFCMeshObjectNode* pcMeshNode; + SoFCMeshObjectShape* pcMeshShape; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_VIEWPROVIDERMESHFACESET_H - +#endif // MESHGUI_VIEWPROVIDERMESHFACESET_H diff --git a/src/Mod/Mesh/Gui/ViewProviderMeshPyImp.cpp b/src/Mod/Mesh/Gui/ViewProviderMeshPyImp.cpp index afd209c706..3e5d4c9344 100644 --- a/src/Mod/Mesh/Gui/ViewProviderMeshPyImp.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderMeshPyImp.cpp @@ -22,13 +22,15 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif +// clang-format off #include "ViewProvider.h" // inclusion of the generated files (generated out of ViewProviderMeshPy.xml) #include "ViewProviderMeshPy.h" #include "ViewProviderMeshPy.cpp" +// clang-format on using namespace MeshGui; @@ -42,11 +44,12 @@ std::string ViewProviderMeshPy::representation() const return str.str(); } -PyObject* ViewProviderMeshPy::setSelection(PyObject *args) +PyObject* ViewProviderMeshPy::setSelection(PyObject* args) { PyObject* obj; - if (!PyArg_ParseTuple(args, "O", &obj)) + if (!PyArg_ParseTuple(args, "O", &obj)) { return nullptr; + } Py::Sequence list(obj); std::vector selection; @@ -62,11 +65,12 @@ PyObject* ViewProviderMeshPy::setSelection(PyObject *args) Py_Return; } -PyObject* ViewProviderMeshPy::addSelection(PyObject *args) +PyObject* ViewProviderMeshPy::addSelection(PyObject* args) { PyObject* obj; - if (!PyArg_ParseTuple(args, "O", &obj)) + if (!PyArg_ParseTuple(args, "O", &obj)) { return nullptr; + } Py::Sequence list(obj); std::vector selection; @@ -82,11 +86,12 @@ PyObject* ViewProviderMeshPy::addSelection(PyObject *args) Py_Return; } -PyObject* ViewProviderMeshPy::removeSelection(PyObject *args) +PyObject* ViewProviderMeshPy::removeSelection(PyObject* args) { PyObject* obj; - if (!PyArg_ParseTuple(args, "O", &obj)) + if (!PyArg_ParseTuple(args, "O", &obj)) { return nullptr; + } Py::Sequence list(obj); std::vector selection; @@ -102,31 +107,34 @@ PyObject* ViewProviderMeshPy::removeSelection(PyObject *args) Py_Return; } -PyObject* ViewProviderMeshPy::invertSelection(PyObject *args) +PyObject* ViewProviderMeshPy::invertSelection(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } ViewProviderMesh* vp = getViewProviderMeshPtr(); vp->invertSelection(); Py_Return; } -PyObject* ViewProviderMeshPy::clearSelection(PyObject *args) +PyObject* ViewProviderMeshPy::clearSelection(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } ViewProviderMesh* vp = getViewProviderMeshPtr(); vp->clearSelection(); Py_Return; } -PyObject* ViewProviderMeshPy::highlightSegments(PyObject *args) +PyObject* ViewProviderMeshPy::highlightSegments(PyObject* args) { PyObject* list; - if (!PyArg_ParseTuple(args, "O", &list)) + if (!PyArg_ParseTuple(args, "O", &list)) { return nullptr; + } App::PropertyColorList colors; colors.setPyObject(list); @@ -136,7 +144,7 @@ PyObject* ViewProviderMeshPy::highlightSegments(PyObject *args) Py_Return; } -PyObject *ViewProviderMeshPy::getCustomAttributes(const char* /*attr*/) const +PyObject* ViewProviderMeshPy::getCustomAttributes(const char* /*attr*/) const { return nullptr; } diff --git a/src/Mod/Mesh/Gui/ViewProviderPython.cpp b/src/Mod/Mesh/Gui/ViewProviderPython.cpp index c623cd90a9..d5c0f88e61 100644 --- a/src/Mod/Mesh/Gui/ViewProviderPython.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderPython.cpp @@ -21,15 +21,15 @@ ***************************************************************************/ -#include "PreCompiled.h" #include "ViewProviderPython.h" +#include "PreCompiled.h" -namespace Gui { +namespace Gui +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(MeshGui::ViewProviderPython, MeshGui::ViewProviderMeshFaceSet) /// @endcond // explicit template instantiation template class MeshGuiExport ViewProviderPythonFeatureT; -} - +} // namespace Gui diff --git a/src/Mod/Mesh/Gui/ViewProviderPython.h b/src/Mod/Mesh/Gui/ViewProviderPython.h index 663c0972bb..4117965dc5 100644 --- a/src/Mod/Mesh/Gui/ViewProviderPython.h +++ b/src/Mod/Mesh/Gui/ViewProviderPython.h @@ -27,12 +27,12 @@ #include #include -namespace MeshGui { +namespace MeshGui +{ using ViewProviderPython = Gui::ViewProviderPythonFeatureT; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_VIEWPROVIDERPYTHON_H - +#endif // MESHGUI_VIEWPROVIDERPYTHON_H diff --git a/src/Mod/Mesh/Gui/ViewProviderTransform.cpp b/src/Mod/Mesh/Gui/ViewProviderTransform.cpp index efa37db4f6..7c8e21b035 100644 --- a/src/Mod/Mesh/Gui/ViewProviderTransform.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderTransform.cpp @@ -22,11 +22,11 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include #endif #include @@ -42,60 +42,59 @@ PROPERTY_SOURCE(MeshGui::ViewProviderMeshTransform, MeshGui::ViewProviderMesh) ViewProviderMeshTransform::ViewProviderMeshTransform() { - pcTransformerDragger = new SoTransformerManip(); - pcTransformerDragger->ref(); + pcTransformerDragger = new SoTransformerManip(); + pcTransformerDragger->ref(); } ViewProviderMeshTransform::~ViewProviderMeshTransform() { - pcTransformerDragger->unref(); + pcTransformerDragger->unref(); } -void ViewProviderMeshTransform::attach(App::DocumentObject *pcFeat) +void ViewProviderMeshTransform::attach(App::DocumentObject* pcFeat) { - // creates the standard viewing modes - ViewProviderMesh::attach(pcFeat); + // creates the standard viewing modes + ViewProviderMesh::attach(pcFeat); - SoSeparator* pcEditRoot = new SoSeparator(); + SoSeparator* pcEditRoot = new SoSeparator(); - // flat shaded (Normal) ------------------------------------------ - SoDrawStyle *pcFlatStyle = new SoDrawStyle(); - pcFlatStyle->style = SoDrawStyle::FILLED; - SoNormalBinding* pcBinding = new SoNormalBinding(); - pcBinding->value=SoNormalBinding::PER_FACE; + // flat shaded (Normal) ------------------------------------------ + SoDrawStyle* pcFlatStyle = new SoDrawStyle(); + pcFlatStyle->style = SoDrawStyle::FILLED; + SoNormalBinding* pcBinding = new SoNormalBinding(); + pcBinding->value = SoNormalBinding::PER_FACE; - pcEditRoot->addChild(pcTransformerDragger); - pcEditRoot->addChild(pcFlatStyle); - pcEditRoot->addChild(pcShapeMaterial); - pcEditRoot->addChild(pcBinding); - pcEditRoot->addChild(pcHighlight); + pcEditRoot->addChild(pcTransformerDragger); + pcEditRoot->addChild(pcFlatStyle); + pcEditRoot->addChild(pcShapeMaterial); + pcEditRoot->addChild(pcBinding); + pcEditRoot->addChild(pcHighlight); - // adding to the switch - addDisplayMaskMode(pcEditRoot, "Edit"); + // adding to the switch + addDisplayMaskMode(pcEditRoot, "Edit"); } void ViewProviderMeshTransform::updateData(const App::Property* prop) { - ViewProviderMesh::updateData(prop); + ViewProviderMesh::updateData(prop); } void ViewProviderMeshTransform::setDisplayMode(const char* ModeName) { - if ( strcmp("Transform",ModeName) == 0 ) - setDisplayMaskMode("Edit"); - ViewProviderMesh::setDisplayMode(ModeName); + if (strcmp("Transform", ModeName) == 0) { + setDisplayMaskMode("Edit"); + } + ViewProviderMesh::setDisplayMode(ModeName); } const char* ViewProviderMeshTransform::getDefaultDisplayMode() const { - return "Transform"; + return "Transform"; } std::vector ViewProviderMeshTransform::getDisplayModes() const { - std::vector StrList = ViewProviderMesh::getDisplayModes(); - StrList.emplace_back("Transform"); - return StrList; + std::vector StrList = ViewProviderMesh::getDisplayModes(); + StrList.emplace_back("Transform"); + return StrList; } - - diff --git a/src/Mod/Mesh/Gui/ViewProviderTransform.h b/src/Mod/Mesh/Gui/ViewProviderTransform.h index 476a63f268..29032671bc 100644 --- a/src/Mod/Mesh/Gui/ViewProviderTransform.h +++ b/src/Mod/Mesh/Gui/ViewProviderTransform.h @@ -36,45 +36,45 @@ class SoPath; class SoLocateHighlight; class SoTransformerManip; -namespace Gui { - class View3DInventorViewer; +namespace Gui +{ +class View3DInventorViewer; } -namespace MeshGui { +namespace MeshGui +{ /** Like Mesh viewprovider but with manipulator */ -class ViewProviderMeshTransform : public ViewProviderMesh +class ViewProviderMeshTransform: public ViewProviderMesh { - PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshTransform); + PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshTransform); public: - ViewProviderMeshTransform(); - ~ViewProviderMeshTransform() override; + ViewProviderMeshTransform(); + ~ViewProviderMeshTransform() override; - /** - * Extracts the mesh data from the feature \a pcFeature and creates - * an Inventor node \a SoNode with these data. - */ - void attach(App::DocumentObject *) override; + /** + * Extracts the mesh data from the feature \a pcFeature and creates + * an Inventor node \a SoNode with these data. + */ + void attach(App::DocumentObject*) override; - /// set the viewing mode - void setDisplayMode(const char* ModeName) override; - /// get the default display mode - const char* getDefaultDisplayMode() const override; - /// returns a list of all possible modes - std::vector getDisplayModes() const override; - /// Update the Mesh representation - void updateData(const App::Property*) override; + /// set the viewing mode + void setDisplayMode(const char* ModeName) override; + /// get the default display mode + const char* getDefaultDisplayMode() const override; + /// returns a list of all possible modes + std::vector getDisplayModes() const override; + /// Update the Mesh representation + void updateData(const App::Property*) override; protected: - - SoTransformerManip *pcTransformerDragger; + SoTransformerManip* pcTransformerDragger; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESHGUI_VIEWPROVIDERMESHTRANSFORM_H - +#endif // MESHGUI_VIEWPROVIDERMESHTRANSFORM_H diff --git a/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.cpp b/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.cpp index 9349efa341..dd37366bff 100644 --- a/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.cpp @@ -22,30 +22,30 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include #include -#include #include +#include #include "ViewProviderTransformDemolding.h" using Mesh::Feature; -using MeshCore::MeshKernel; using MeshCore::MeshFacetIterator; using MeshCore::MeshGeomFacet; +using MeshCore::MeshKernel; using namespace MeshGui; @@ -54,95 +54,94 @@ PROPERTY_SOURCE(MeshGui::ViewProviderMeshTransformDemolding, MeshGui::ViewProvid ViewProviderMeshTransformDemolding::ViewProviderMeshTransformDemolding() { - pcTrackballDragger = new SoTrackballDragger; - pcTrackballDragger->ref(); - pcTransformDrag = nullptr; - pcColorMat = nullptr; + pcTrackballDragger = new SoTrackballDragger; + pcTrackballDragger->ref(); + pcTransformDrag = nullptr; + pcColorMat = nullptr; } ViewProviderMeshTransformDemolding::~ViewProviderMeshTransformDemolding() { - pcTrackballDragger->unref(); + pcTrackballDragger->unref(); } -void ViewProviderMeshTransformDemolding::attach(App::DocumentObject *pcFeat) +void ViewProviderMeshTransformDemolding::attach(App::DocumentObject* pcFeat) { - // creates the standard viewing modes - ViewProviderMesh::attach(pcFeat); + // creates the standard viewing modes + ViewProviderMesh::attach(pcFeat); - SoGroup* pcDemoldRoot = new SoGroup(); + SoGroup* pcDemoldRoot = new SoGroup(); - SoDrawStyle *pcFlatStyle = new SoDrawStyle(); - pcFlatStyle->style = SoDrawStyle::FILLED; - pcDemoldRoot->addChild(pcFlatStyle); + SoDrawStyle* pcFlatStyle = new SoDrawStyle(); + pcFlatStyle->style = SoDrawStyle::FILLED; + pcDemoldRoot->addChild(pcFlatStyle); - // dragger - SoSeparator * surroundsep = new SoSeparator; + // dragger + SoSeparator* surroundsep = new SoSeparator; - SoSurroundScale * ss = new SoSurroundScale; - ss->numNodesUpToReset = 1; - ss->numNodesUpToContainer = 2; - surroundsep->addChild(ss); + SoSurroundScale* ss = new SoSurroundScale; + ss->numNodesUpToReset = 1; + ss->numNodesUpToContainer = 2; + surroundsep->addChild(ss); - SoAntiSquish * antisquish = new SoAntiSquish; - antisquish->sizing = SoAntiSquish::AVERAGE_DIMENSION ; - surroundsep->addChild(antisquish); + SoAntiSquish* antisquish = new SoAntiSquish; + antisquish->sizing = SoAntiSquish::AVERAGE_DIMENSION; + surroundsep->addChild(antisquish); - pcTrackballDragger->addValueChangedCallback(sValueChangedCallback,this); - pcTrackballDragger->addFinishCallback (sDragEndCallback,this); - surroundsep->addChild(pcTrackballDragger); + pcTrackballDragger->addValueChangedCallback(sValueChangedCallback, this); + pcTrackballDragger->addFinishCallback(sDragEndCallback, this); + surroundsep->addChild(pcTrackballDragger); - pcTransformDrag = new SoTransform(); + pcTransformDrag = new SoTransform(); - SoMaterialBinding* pcMatBinding = new SoMaterialBinding; - //pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED; - pcMatBinding->value = SoMaterialBinding::PER_FACE_INDEXED; - pcColorMat = new SoMaterial; - pcColorMat->diffuseColor.set1Value(0, 1,1,0); - pcColorMat->diffuseColor.set1Value(1, 1,0,0); - pcColorMat->diffuseColor.set1Value(2, 0,1,0); - - pcDemoldRoot->addChild(surroundsep); - pcDemoldRoot->addChild(pcTransformDrag); - pcDemoldRoot->addChild(pcColorMat); - pcDemoldRoot->addChild(pcMatBinding); - pcDemoldRoot->addChild(pcHighlight); + SoMaterialBinding* pcMatBinding = new SoMaterialBinding; + // pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED; + pcMatBinding->value = SoMaterialBinding::PER_FACE_INDEXED; + pcColorMat = new SoMaterial; + pcColorMat->diffuseColor.set1Value(0, 1, 1, 0); + pcColorMat->diffuseColor.set1Value(1, 1, 0, 0); + pcColorMat->diffuseColor.set1Value(2, 0, 1, 0); - // adding to the switch - addDisplayMaskMode(pcDemoldRoot, "Demold"); + pcDemoldRoot->addChild(surroundsep); + pcDemoldRoot->addChild(pcTransformDrag); + pcDemoldRoot->addChild(pcColorMat); + pcDemoldRoot->addChild(pcMatBinding); + pcDemoldRoot->addChild(pcHighlight); - calcNormalVector(); - calcMaterialIndex(SbRotation()); - // getting center point - center = static_cast(pcObject)->Mesh.getValue().getKernel().GetBoundBox().GetCenter(); + // adding to the switch + addDisplayMaskMode(pcDemoldRoot, "Demold"); - //SoGetBoundingBoxAction boxAction; - //pcHighlight->getBoundingBox(&boxAction); - //SbVector3f Center = boxAction->getCenter(); + calcNormalVector(); + calcMaterialIndex(SbRotation()); + // getting center point + center = static_cast(pcObject)->Mesh.getValue().getKernel().GetBoundBox().GetCenter(); + + // SoGetBoundingBoxAction boxAction; + // pcHighlight->getBoundingBox(&boxAction); + // SbVector3f Center = boxAction->getCenter(); } void ViewProviderMeshTransformDemolding::calcNormalVector() { - const MeshKernel& cMesh = static_cast(pcObject)->Mesh.getValue().getKernel(); + const MeshKernel& cMesh = static_cast(pcObject)->Mesh.getValue().getKernel(); - MeshFacetIterator cFIt(cMesh); - for( cFIt.Init(); cFIt.More(); cFIt.Next()) - { - const MeshGeomFacet& rFace = *cFIt; + MeshFacetIterator cFIt(cMesh); + for (cFIt.Init(); cFIt.More(); cFIt.Next()) { + const MeshGeomFacet& rFace = *cFIt; - Base::Vector3f norm(rFace.GetNormal()); - normalVector.emplace_back(norm.x,norm.y,norm.z); - } + Base::Vector3f norm(rFace.GetNormal()); + normalVector.emplace_back(norm.x, norm.y, norm.z); + } } -void ViewProviderMeshTransformDemolding::calcMaterialIndex(const SbRotation &rot) +void ViewProviderMeshTransformDemolding::calcMaterialIndex(const SbRotation& rot) { SbVec3f Up(0, 0, 1), result; int i = 0; - for (std::vector::const_iterator it = normalVector.begin(); it != normalVector.end(); ++it, i++) - { + for (std::vector::const_iterator it = normalVector.begin(); it != normalVector.end(); + ++it, i++) { rot.multVec(*it, result); float Angle = acos((result.dot(Up)) / (result.length() * Up.length())) * (180 / M_PI); @@ -159,58 +158,58 @@ void ViewProviderMeshTransformDemolding::calcMaterialIndex(const SbRotation &rot } } -void ViewProviderMeshTransformDemolding::sValueChangedCallback(void *This, SoDragger *) +void ViewProviderMeshTransformDemolding::sValueChangedCallback(void* This, SoDragger*) { - static_cast(This)->valueChangedCallback(); + static_cast(This)->valueChangedCallback(); } -void ViewProviderMeshTransformDemolding::sDragEndCallback(void *This, SoDragger *) +void ViewProviderMeshTransformDemolding::sDragEndCallback(void* This, SoDragger*) { - static_cast(This)->DragEndCallback(); + static_cast(This)->DragEndCallback(); } void ViewProviderMeshTransformDemolding::DragEndCallback() { - SbRotation rot = pcTrackballDragger->rotation.getValue(); - calcMaterialIndex(rot); - - Base::Console().Log("View: Finish dragging\n"); + SbRotation rot = pcTrackballDragger->rotation.getValue(); + calcMaterialIndex(rot); + Base::Console().Log("View: Finish dragging\n"); } void ViewProviderMeshTransformDemolding::valueChangedCallback() { - //Base::Console().Log("Value change Callback\n"); - //setTransformation(pcTrackballDragger->getMotionMatrix()); - //pcTransform->rotation = pcTrackballDragger->rotation; - SbMatrix temp; - SbRotation rot = pcTrackballDragger->rotation.getValue(); + // Base::Console().Log("Value change Callback\n"); + // setTransformation(pcTrackballDragger->getMotionMatrix()); + // pcTransform->rotation = pcTrackballDragger->rotation; + SbMatrix temp; + SbRotation rot = pcTrackballDragger->rotation.getValue(); - //calcMaterialIndex(rot); + // calcMaterialIndex(rot); - temp.setTransform( SbVec3f(0,0,0), // no transformation - rot, // rotation from the dragger - SbVec3f(1,1,1), // no scaling - SbRotation() , // no scaling orientation - SbVec3f(center.x,center.y,center.z)); // center of rotation - pcTransformDrag->setMatrix( temp ); + temp.setTransform(SbVec3f(0, 0, 0), // no transformation + rot, // rotation from the dragger + SbVec3f(1, 1, 1), // no scaling + SbRotation(), // no scaling orientation + SbVec3f(center.x, center.y, center.z)); // center of rotation + pcTransformDrag->setMatrix(temp); } void ViewProviderMeshTransformDemolding::setDisplayMode(const char* ModeName) { - if ( strcmp("Demold",ModeName) == 0 ) - setDisplayMaskMode("Demold"); - ViewProviderMesh::setDisplayMode(ModeName); + if (strcmp("Demold", ModeName) == 0) { + setDisplayMaskMode("Demold"); + } + ViewProviderMesh::setDisplayMode(ModeName); } const char* ViewProviderMeshTransformDemolding::getDefaultDisplayMode() const { - return "Demold"; + return "Demold"; } std::vector ViewProviderMeshTransformDemolding::getDisplayModes() const { - std::vector StrList = ViewProviderMesh::getDisplayModes(); - StrList.emplace_back("Demold"); - return StrList; + std::vector StrList = ViewProviderMesh::getDisplayModes(); + StrList.emplace_back("Demold"); + return StrList; } diff --git a/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.h b/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.h index b45290d1b4..b2f47ee312 100644 --- a/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.h +++ b/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.h @@ -40,56 +40,56 @@ class SbRotation; class SoTrackballDragger; class SoTransformerManip; -namespace Gui { - class View3DInventorViewer; +namespace Gui +{ +class View3DInventorViewer; } -namespace MeshGui { +namespace MeshGui +{ /** Like Mesh viewprovider but with manipulator */ -class ViewProviderMeshTransformDemolding : public ViewProviderMesh +class ViewProviderMeshTransformDemolding: public ViewProviderMesh { - PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshTransformDemolding); + PROPERTY_HEADER_WITH_OVERRIDE(MeshGui::ViewProviderMeshTransformDemolding); public: - ViewProviderMeshTransformDemolding(); - ~ViewProviderMeshTransformDemolding() override; + ViewProviderMeshTransformDemolding(); + ~ViewProviderMeshTransformDemolding() override; - /** - * Extracts the mesh data from the feature \a pcFeature and creates - * an Inventor node \a SoNode with these data. - */ - void attach(App::DocumentObject *) override; + /** + * Extracts the mesh data from the feature \a pcFeature and creates + * an Inventor node \a SoNode with these data. + */ + void attach(App::DocumentObject*) override; - /// set the viewing mode - void setDisplayMode(const char* ModeName) override; - /// get the default display mode - const char* getDefaultDisplayMode() const override; - /// returns a list of all possible modes - std::vector getDisplayModes() const override; + /// set the viewing mode + void setDisplayMode(const char* ModeName) override; + /// get the default display mode + const char* getDefaultDisplayMode() const override; + /// returns a list of all possible modes + std::vector getDisplayModes() const override; protected: - void calcMaterialIndex(const SbRotation &rot); - void calcNormalVector(); + void calcMaterialIndex(const SbRotation& rot); + void calcNormalVector(); - static void sValueChangedCallback(void *, SoDragger *); - void valueChangedCallback(); + static void sValueChangedCallback(void*, SoDragger*); + void valueChangedCallback(); - static void sDragEndCallback(void *, SoDragger *); - void DragEndCallback(); - - SoTrackballDragger *pcTrackballDragger; - SoTransform *pcTransformDrag; - SoMaterial *pcColorMat; - std::vector normalVector; - Base::Vector3f center; + static void sDragEndCallback(void*, SoDragger*); + void DragEndCallback(); + SoTrackballDragger* pcTrackballDragger; + SoTransform* pcTransformDrag; + SoMaterial* pcColorMat; + std::vector normalVector; + Base::Vector3f center; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESGUI_VIEWPROVIDERMESHTRANSFORMDEMOLDING_H - +#endif // MESGUI_VIEWPROVIDERMESHTRANSFORMDEMOLDING_H diff --git a/src/Mod/Mesh/Gui/Workbench.cpp b/src/Mod/Mesh/Gui/Workbench.cpp index 2cdcf5860a..06fd6cf689 100644 --- a/src/Mod/Mesh/Gui/Workbench.cpp +++ b/src/Mod/Mesh/Gui/Workbench.cpp @@ -22,16 +22,16 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include #include #include #include -#include #include +#include #include #include "Workbench.h" @@ -39,7 +39,7 @@ using namespace MeshGui; -#if 0 // needed for Qt's lupdate utility +#if 0 // needed for Qt's lupdate utility qApp->translate("Workbench", "Analyze"); qApp->translate("Workbench", "Boolean"); qApp->translate("Workbench", "&Meshes"); @@ -57,10 +57,11 @@ TYPESYSTEM_SOURCE(MeshGui::Workbench, Gui::StdWorkbench) Workbench::Workbench() = default; -class MeshInfoWatcher : public Gui::TaskView::TaskWatcher, public Gui::SelectionObserver +class MeshInfoWatcher: public Gui::TaskView::TaskWatcher, public Gui::SelectionObserver { public: - MeshInfoWatcher() : TaskWatcher(nullptr) + MeshInfoWatcher() + : TaskWatcher(nullptr) { labelPoints = new QLabel(); labelPoints->setText(tr("Number of points:")); @@ -82,7 +83,7 @@ public: QGroupBox* box = new QGroupBox(); box->setTitle(tr("Mesh info box")); - //box->setAutoFillBackground(true); + // box->setAutoFillBackground(true); QGridLayout* grid = new QGridLayout(box); grid->addWidget(labelPoints, 0, 0); grid->addWidget(numPoints, 0, 1); @@ -94,8 +95,8 @@ public: grid->addWidget(labelMax, 3, 0); grid->addWidget(numMax, 3, 1); - Gui::TaskView::TaskBox* taskbox = new Gui::TaskView::TaskBox( - QPixmap(), tr("Mesh info"), false, nullptr); + Gui::TaskView::TaskBox* taskbox = + new Gui::TaskView::TaskBox(QPixmap(), tr("Mesh info"), false, nullptr); taskbox->groupLayout()->addWidget(box); Content.push_back(taskbox); } @@ -106,7 +107,7 @@ public: void onSelectionChanged(const Gui::SelectionChanges&) override { Base::BoundBox3d bbox; - unsigned long countPoints=0, countFacets=0; + unsigned long countPoints = 0, countFacets = 0; std::vector mesh = Gui::Selection().getObjectsOfType(); for (auto it : mesh) { countPoints += it->Mesh.getValue().countPoints(); @@ -117,10 +118,8 @@ public: if (countPoints > 0) { numPoints->setText(QString::number(countPoints)); numFacets->setText(QString::number(countFacets)); - numMin->setText(tr("X: %1\tY: %2\tZ: %3") - .arg(bbox.MinX).arg(bbox.MinY).arg(bbox.MinZ)); - numMax->setText(tr("X: %1\tY: %2\tZ: %3") - .arg(bbox.MaxX).arg(bbox.MaxY).arg(bbox.MaxZ)); + numMin->setText(tr("X: %1\tY: %2\tZ: %3").arg(bbox.MinX).arg(bbox.MinY).arg(bbox.MinZ)); + numMax->setText(tr("X: %1\tY: %2\tZ: %3").arg(bbox.MaxX).arg(bbox.MaxY).arg(bbox.MaxZ)); } else { numPoints->setText(QString::fromLatin1("")); @@ -154,15 +153,16 @@ void Workbench::deactivated() { Gui::Workbench::deactivated(); removeTaskWatcher(); - } -void Workbench::setupContextMenu(const char* recipient,Gui::MenuItem* item) const +void Workbench::setupContextMenu(const char* recipient, Gui::MenuItem* item) const { - StdWorkbench::setupContextMenu( recipient, item ); - if (Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0) - { - *item << "Separator" << "Mesh_Import" << "Mesh_Export" << "Mesh_VertexCurvature"; + StdWorkbench::setupContextMenu(recipient, item); + if (Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0) { + *item << "Separator" + << "Mesh_Import" + << "Mesh_Export" + << "Mesh_VertexCurvature"; } } @@ -171,13 +171,17 @@ Gui::MenuItem* Workbench::setupMenuBar() const Gui::MenuItem* root = StdWorkbench::setupMenuBar(); Gui::MenuItem* item = root->findItem("&Windows"); Gui::MenuItem* mesh = new Gui::MenuItem; - root->insertItem( item, mesh ); + root->insertItem(item, mesh); // analyze Gui::MenuItem* analyze = new Gui::MenuItem; analyze->setCommand("Analyze"); - *analyze << "Mesh_Evaluation" << "Mesh_EvaluateFacet" << "Mesh_CurvatureInfo" << "Separator" - << "Mesh_EvaluateSolid" << "Mesh_BoundingBox"; + *analyze << "Mesh_Evaluation" + << "Mesh_EvaluateFacet" + << "Mesh_CurvatureInfo" + << "Separator" + << "Mesh_EvaluateSolid" + << "Mesh_BoundingBox"; // boolean Gui::MenuItem* boolean = new Gui::MenuItem; @@ -191,7 +195,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const cutting->setCommand("Cutting"); *cutting << "Mesh_PolyCut" << "Mesh_PolyTrim" - //<< "Mesh_PolySegm" + //<< "Mesh_PolySegm" << "Mesh_TrimByPlane" << "Mesh_SectionByPlane" << "Mesh_CrossSections"; @@ -201,9 +205,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "Mesh_Export" << "Mesh_FromPartShape" << "Mesh_RemeshGmsh" - << "Separator" - << analyze - << "Mesh_VertexCurvature" + << "Separator" << analyze << "Mesh_VertexCurvature" << "Mesh_HarmonizeNormals" << "Mesh_FlipNormals" << "Separator" @@ -219,18 +221,17 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "Mesh_Decimating" << "Mesh_Scale" << "Separator" - << "Mesh_BuildRegularSolid" - << boolean - << cutting - << "Separator" + << "Mesh_BuildRegularSolid" << boolean << cutting << "Separator" << "Mesh_Merge" << "Mesh_SplitComponents" << "Separator"; Gui::CommandManager& mgr = Gui::Application::Instance->commandManager(); - if (mgr.getCommandByName("MeshPart_CreateFlatMesh")) + if (mgr.getCommandByName("MeshPart_CreateFlatMesh")) { *mesh << "MeshPart_CreateFlatMesh"; - if (mgr.getCommandByName("MeshPart_CreateFlatFace")) + } + if (mgr.getCommandByName("MeshPart_CreateFlatFace")) { *mesh << "MeshPart_CreateFlatFace"; + } return root; } @@ -298,14 +299,17 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const Gui::ToolBarItem* root = new Gui::ToolBarItem; Gui::ToolBarItem* mesh; - mesh = new Gui::ToolBarItem( root ); + mesh = new Gui::ToolBarItem(root); mesh->setCommand("Mesh tools"); - *mesh << "Mesh_Import" << "Mesh_Export" << "Mesh_PolyCut"; + *mesh << "Mesh_Import" + << "Mesh_Export" + << "Mesh_PolyCut"; - mesh = new Gui::ToolBarItem( root ); + mesh = new Gui::ToolBarItem(root); mesh->setCommand("Mesh test suite"); - *mesh << "Mesh_Demolding" << "Mesh_Transform" << "Separator" ; + *mesh << "Mesh_Demolding" + << "Mesh_Transform" + << "Separator"; return root; } - diff --git a/src/Mod/Mesh/Gui/Workbench.h b/src/Mod/Mesh/Gui/Workbench.h index 737dd2db3f..f83e5f1490 100644 --- a/src/Mod/Mesh/Gui/Workbench.h +++ b/src/Mod/Mesh/Gui/Workbench.h @@ -25,33 +25,34 @@ #include #ifndef MESH_GLOBAL_H -# include +#include #endif -namespace MeshGui { +namespace MeshGui +{ /** * @author Werner Mayer */ -class MeshGuiExport Workbench : public Gui::StdWorkbench +class MeshGuiExport Workbench: public Gui::StdWorkbench { TYPESYSTEM_HEADER_WITH_OVERRIDE(); public: - Workbench(); + Workbench(); - void activated() override; - void deactivated() override; - void setupContextMenu(const char* recipient, Gui::MenuItem*) const override; + void activated() override; + void deactivated() override; + void setupContextMenu(const char* recipient, Gui::MenuItem*) const override; protected: - Gui::MenuItem* setupMenuBar() const override; - Gui::ToolBarItem* setupToolBars() const override; - Gui::ToolBarItem* setupCommandBars() const override; + Gui::MenuItem* setupMenuBar() const override; + Gui::ToolBarItem* setupToolBars() const override; + Gui::ToolBarItem* setupCommandBars() const override; }; -} // namespace MeshGui +} // namespace MeshGui -#endif // MESH_WORKBENCH_H +#endif // MESH_WORKBENCH_H diff --git a/src/Mod/Mesh/Gui/images.h b/src/Mod/Mesh/Gui/images.h index 3a6ddaad18..5ba0bd5c6b 100644 --- a/src/Mod/Mesh/Gui/images.h +++ b/src/Mod/Mesh/Gui/images.h @@ -1,3 +1,4 @@ +// clang-format off /* XPM */ static const char *mesh_fillhole[]={ "32 32 3 1", @@ -36,4 +37,4 @@ static const char *mesh_fillhole[]={ "................................", "................................", "................................"}; - +// clang-format on diff --git a/src/Mod/Mesh/Init.py b/src/Mod/Mesh/Init.py index c0cbf4c1b7..fd176afa20 100644 --- a/src/Mod/Mesh/Init.py +++ b/src/Mod/Mesh/Init.py @@ -21,4 +21,4 @@ FreeCAD.addExportType("Additive Manufacturing Format (*.amf)", "Mesh") FreeCAD.addExportType("Simple Model Format (*.smf)", "Mesh") FreeCAD.addExportType("3D Manufacturing Format (*.3mf)", "Mesh") -FreeCAD.__unit_test__ += [ "MeshTestsApp" ] +FreeCAD.__unit_test__ += ["MeshTestsApp"] diff --git a/src/Mod/Mesh/InitGui.py b/src/Mod/Mesh/InitGui.py index cd5273b683..25674fa251 100644 --- a/src/Mod/Mesh/InitGui.py +++ b/src/Mod/Mesh/InitGui.py @@ -5,46 +5,54 @@ # This is the second one of three init scripts, the third one # runs when the gui is up -#*************************************************************************** -#* Copyright (c) 2004 Werner Mayer * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2004 Werner Mayer * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ -class MeshWorkbench (Workbench): + +class MeshWorkbench(Workbench): "Mesh workbench object" + def __init__(self): - self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Mesh/Resources/icons/MeshWorkbench.svg" + self.__class__.Icon = ( + FreeCAD.getResourceDir() + "Mod/Mesh/Resources/icons/MeshWorkbench.svg" + ) self.__class__.MenuText = "Mesh" self.__class__.ToolTip = "Mesh workbench" def Initialize(self): import Mesh import MeshGui + try: import flatmesh import MeshFlatteningCommand except ImportError as e: import FreeCAD + FreeCAD.Console.PrintLog((str(e))) + def GetClassName(self): return "MeshGui::Workbench" + Gui.addWorkbench(MeshWorkbench()) diff --git a/src/Mod/Mesh/MeshEnums.py b/src/Mod/Mesh/MeshEnums.py index 883500c646..e61b17a337 100644 --- a/src/Mod/Mesh/MeshEnums.py +++ b/src/Mod/Mesh/MeshEnums.py @@ -27,8 +27,8 @@ __doc__ = "Enum types" from enum import IntEnum + class Binding(IntEnum): OVERALL = 0 PER_VERTEX = 1 PER_FACE = 2 - diff --git a/src/Mod/Mesh/MeshGlobal.h b/src/Mod/Mesh/MeshGlobal.h index bf8d4d3589..2800bfe9b2 100644 --- a/src/Mod/Mesh/MeshGlobal.h +++ b/src/Mod/Mesh/MeshGlobal.h @@ -29,19 +29,19 @@ // Mesh #ifndef MeshExport #ifdef Mesh_EXPORTS -# define MeshExport FREECAD_DECL_EXPORT +#define MeshExport FREECAD_DECL_EXPORT #else -# define MeshExport FREECAD_DECL_IMPORT +#define MeshExport FREECAD_DECL_IMPORT #endif #endif // MeshGui #ifndef MeshGuiExport #ifdef MeshGui_EXPORTS -# define MeshGuiExport FREECAD_DECL_EXPORT +#define MeshGuiExport FREECAD_DECL_EXPORT #else -# define MeshGuiExport FREECAD_DECL_IMPORT +#define MeshGuiExport FREECAD_DECL_IMPORT #endif #endif -#endif //MESH_GLOBAL_H +#endif // MESH_GLOBAL_H diff --git a/src/Mod/Mesh/mesh.dox b/src/Mod/Mesh/mesh.dox index bee44c684e..0edd24a4bd 100644 --- a/src/Mod/Mesh/mesh.dox +++ b/src/Mod/Mesh/mesh.dox @@ -2,4 +2,3 @@ * \ingroup CWORKBENCHES * \brief Tools to work with polygon meshes */ -