From 80670094eb81742a62c8d4e4a627488731ecf042 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 17 Jun 2024 15:55:53 +0200 Subject: [PATCH] Clean-up code and improve formatting --- src/Gui/Application.cpp | 2 + src/Gui/DlgMaterialPropertiesImp.cpp | 2 - src/Gui/ViewProviderGeometryObject.h | 1 - src/Mod/Part/Gui/AppPartGui.cpp | 51 ++++++++------------- src/Mod/Part/Gui/DlgProjectionOnSurface.cpp | 50 ++++++++++---------- src/Mod/Surface/Gui/TaskSections.cpp | 4 +- 6 files changed, 47 insertions(+), 63 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index e8e14cb233..1fd880074b 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1875,6 +1875,7 @@ void Application::initApplication() void Application::initTypes() { + // clang-format off // views Gui::BaseView ::init(); Gui::MDIView ::init(); @@ -1945,6 +1946,7 @@ void Application::initTypes() // register transaction type new App::TransactionProducer (ViewProviderDocumentObject::getClassTypeId()); + // clang-format on } void Application::initOpenInventor() diff --git a/src/Gui/DlgMaterialPropertiesImp.cpp b/src/Gui/DlgMaterialPropertiesImp.cpp index 13f48a4147..4c76a481de 100644 --- a/src/Gui/DlgMaterialPropertiesImp.cpp +++ b/src/Gui/DlgMaterialPropertiesImp.cpp @@ -22,10 +22,8 @@ #include "PreCompiled.h" -#include #include -#include "Application.h" #include "DlgMaterialPropertiesImp.h" #include "ui_DlgMaterialProperties.h" #include "ViewProvider.h" diff --git a/src/Gui/ViewProviderGeometryObject.h b/src/Gui/ViewProviderGeometryObject.h index 5a8b4134e6..48e04369b6 100644 --- a/src/Gui/ViewProviderGeometryObject.h +++ b/src/Gui/ViewProviderGeometryObject.h @@ -96,7 +96,6 @@ public: /// Get the python wrapper for that ViewProvider PyObject* getPyObject() override; - static App::Material getUserDefinedMaterial(); protected: /// get called by the container whenever a property has been changed diff --git a/src/Mod/Part/Gui/AppPartGui.cpp b/src/Mod/Part/Gui/AppPartGui.cpp index 519a449fc0..998436403e 100644 --- a/src/Mod/Part/Gui/AppPartGui.cpp +++ b/src/Mod/Part/Gui/AppPartGui.cpp @@ -109,7 +109,6 @@ private: PyObject* initModule() { return Base::Interpreter().addModule(new Module); - ; } } // namespace PartGui @@ -140,15 +139,17 @@ PyMOD_INIT_FUNC(PartGui) Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/parametric")); Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/tools")); - static struct PyModuleDef pAttachEngineTextsModuleDef = {PyModuleDef_HEAD_INIT, - "AttachEngineResources", - "AttachEngineResources", - -1, - AttacherGui::AttacherGuiPy::Methods, - nullptr, - nullptr, - nullptr, - nullptr}; + // clang-format off + static struct PyModuleDef pAttachEngineTextsModuleDef = { + PyModuleDef_HEAD_INIT, + "AttachEngineResources", + "AttachEngineResources", + -1, + AttacherGui::AttacherGuiPy::Methods, + nullptr, nullptr, nullptr, nullptr + }; + // clang-format on + PyObject* pAttachEngineTextsModule = PyModule_Create(&pAttachEngineTextsModuleDef); Py_INCREF(pAttachEngineTextsModule); @@ -218,7 +219,6 @@ PyMOD_INIT_FUNC(PartGui) PartGui::Workbench ::init(); auto manip = std::make_shared(); Gui::WorkbenchManipulator::installManipulator(manip); - // clang-format on // instantiating the commands CreatePartCommands(); @@ -226,8 +226,8 @@ PyMOD_INIT_FUNC(PartGui) CreateParamPartCommands(); CreatePartSelectCommands(); try { - Py::Object ae = - Base::Interpreter().runStringObject("__import__('AttachmentEditor.Commands').Commands"); + const char* cmd = "__import__('AttachmentEditor.Commands').Commands"; + Py::Object ae = Base::Interpreter().runStringObject(cmd); Py::Module(partGuiModule).setAttr(std::string("AttachmentEditor"), ae); } catch (Base::PyException& err) { @@ -235,29 +235,18 @@ PyMOD_INIT_FUNC(PartGui) } // register preferences pages - Gui::Dialog::DlgPreferencesImp::setGroupData("Part/Part Design", - "Part design", - QObject::tr("Part and Part Design workbench")); - (void)new Gui::PrefPageProducer( - QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); - (void)new Gui::PrefPageProducer( - QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); - (void)new Gui::PrefPageProducer( - QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); - (void)new Gui::PrefPageProducer( - QT_TRANSLATE_NOOP("QObject", "Import-Export")); - (void)new Gui::PrefPageProducer( - QT_TRANSLATE_NOOP("QObject", "Import-Export")); + Gui::Dialog::DlgPreferencesImp::setGroupData("Part/Part Design", "Part design", QObject::tr("Part and Part Design workbench")); + (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); + (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); + (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); + (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Import-Export")); + (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Import-Export")); Gui::ViewProviderBuilder::add(Part::PropertyPartShape::getClassTypeId(), PartGui::ViewProviderPart::getClassTypeId()); + // clang-format on // add resources and reloads the translators loadPartResource(); - // register bitmaps - // Gui::BitmapFactoryInst& rclBmpFactory = Gui::BitmapFactory(); - // rclBmpFactory.addXPM("Part_Feature",(const char**) PartFeature_xpm); - // rclBmpFactory.addXPM("Part_FeatureImport",(const char**) PartFeatureImport_xpm); - PyMOD_Return(partGuiModule); } diff --git a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp index 8dd5b95069..fc0781421e 100644 --- a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp +++ b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp @@ -720,38 +720,34 @@ void PartGui::DlgProjectionOnSurface::higlight_object(Part::Feature* iCurrentObj auto vp = dynamic_cast( Gui::Application::Instance->getViewProvider(iCurrentObject)); if (vp) { - App::Color aColor; - aColor.setPackedValue(iColor); + std::vector colors; + App::Color defaultColor; if (currentShapeType == TopAbs_FACE) { - std::vector colors = vp->ShapeAppearance.getValues(); - App::Color defaultColor = vp->ShapeAppearance.getDiffuseColor(); - - if (static_cast(colors.size()) != anIndices.Extent()) { - colors.resize(anIndices.Extent(), vp->ShapeAppearance[0]); - } - - if (iHighlight) { - colors.at(index - 1).diffuseColor = aColor; - } - else { - colors.at(index - 1).diffuseColor = defaultColor; - } - vp->ShapeAppearance.setValues(colors); + colors = vp->ShapeAppearance.getDiffuseColors(); + defaultColor = colors.front(); } else if (currentShapeType == TopAbs_EDGE) { - std::vector colors = vp->LineColorArray.getValues(); - App::Color defaultColor = vp->LineColor.getValue(); + colors = vp->LineColorArray.getValues(); + defaultColor = vp->LineColor.getValue(); + } - if (static_cast(colors.size()) != anIndices.Extent()) { - colors.resize(anIndices.Extent(), defaultColor); - } + if (static_cast(colors.size()) != anIndices.Extent()) { + colors.resize(anIndices.Extent(), defaultColor); + } - if (iHighlight) { - colors.at(index - 1) = aColor; - } - else { - colors.at(index - 1) = defaultColor; - } + if (iHighlight) { + App::Color aColor; + aColor.setPackedValue(iColor); + colors.at(index - 1) = aColor; + } + else { + colors.at(index - 1) = defaultColor; + } + if (currentShapeType == TopAbs_FACE) { + vp->ShapeAppearance.setDiffuseColors(colors); + } + else if (currentShapeType == TopAbs_EDGE) { + vp->LineColorArray.setValues(colors); } } } diff --git a/src/Mod/Surface/Gui/TaskSections.cpp b/src/Mod/Surface/Gui/TaskSections.cpp index d7ee73aa54..b8f6d856f7 100644 --- a/src/Mod/Surface/Gui/TaskSections.cpp +++ b/src/Mod/Surface/Gui/TaskSections.cpp @@ -172,8 +172,8 @@ void ViewProviderSections::highlightReferences(ShapeType type, const References& // check again that the index is in range because it's possible that // the sub-names are invalid if (idx < materials.size()) { - materials[idx].diffuseColor = - App::Color(1.0, 0.0, 1.0); // magenta + // magenta + materials[idx].diffuseColor = App::Color(1.0, 0.0, 1.0); } }