From 6fb7c51c1827d4e3989e2d562292cae8dee6d93f Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 3 Jun 2024 10:34:17 +0200 Subject: [PATCH] App: Prepare for clang-format --- .pre-commit-config.yaml | 4 ++++ src/App/Application.cpp | 10 ++++++++++ src/App/Application.h | 2 ++ src/App/Color.cpp | 2 ++ src/App/ElementNamingUtils.h | 4 +++- src/App/ExtensionContainer.cpp | 2 +- src/App/ExtensionContainer.h | 9 ++++++--- src/App/FeaturePythonPyImp.h | 2 ++ src/App/FeaturePythonPyImp.inl | 2 ++ src/App/FreeCADInit.py | 3 ++- src/App/MeasureDistance.cpp | 3 ++- src/App/Origin.cpp | 5 ++++- src/App/Property.cpp | 4 +++- src/App/PropertyContainer.h | 2 ++ src/App/PropertyGeo.cpp | 12 ++++++++++-- 15 files changed, 55 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 145df4de6f..ef736332d2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,6 +37,10 @@ exclude: | (?x)^( .*vcproj.*| .*vcxproj.*| + src/App/ExpressionParser.tab.c| + src/App/ExpressionParser.tab.h| + src/App/ExpressionParser.y| + src/App/lex.ExpressionParser.c| src/Mod/Import/App/SCL| src/Mod/Import/App/SCL_output| src/Mod/Mesh/App/TestData| diff --git a/src/App/Application.cpp b/src/App/Application.cpp index ae18fde81e..73c9165534 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -175,6 +175,7 @@ AppExport std::map Application::mConfig; //************************************************************************** // Construction and destruction +// clang-format off PyDoc_STRVAR(FreeCAD_doc, "The functions in the FreeCAD module allow working with documents.\n" "The FreeCAD instance provides a list of references of documents which\n" @@ -237,6 +238,7 @@ init_image_module() }; return PyModule_Create(&ImageModuleDef); } +// clang-format on Application::Application(std::map &mConfig) : _mConfig(mConfig) @@ -264,6 +266,7 @@ void Application::setupPythonTypes() } Py::Module(pAppModule).setAttr(std::string("ActiveDocument"),Py::None()); + // clang-format off static struct PyModuleDef ConsoleModuleDef = { PyModuleDef_HEAD_INIT, "__FreeCADConsole__", Console_doc, -1, @@ -371,8 +374,10 @@ void Application::setupPythonTypes() Base::Vector2dPy::init_type(); Base::Interpreter().addType(Base::Vector2dPy::type_object(), pBaseModule,"Vector2d"); + // clang-format on } +// clang-format off void Application::setupPythonException(PyObject* module) { // Define custom Python exception types @@ -421,6 +426,7 @@ void Application::setupPythonException(PyObject* module) Py_INCREF(Base::PyExc_FC_CADKernelError); PyModule_AddObject(module, "CADKernelError", Base::PyExc_FC_CADKernelError); } +// clang-format on //************************************************************************** // Interface @@ -488,6 +494,7 @@ Document* Application::newDocument(const char * Name, const char * UserName, boo _pActiveDoc = doc; //NOLINTBEGIN + // clang-format off // connect the signals to the application for the new document _pActiveDoc->signalBeforeChange.connect(std::bind(&App::Application::slotBeforeChangeDocument, this, sp::_1, sp::_2)); _pActiveDoc->signalChanged.connect(std::bind(&App::Application::slotChangedDocument, this, sp::_1, sp::_2)); @@ -508,6 +515,7 @@ Document* Application::newDocument(const char * Name, const char * UserName, boo _pActiveDoc->signalStartSave.connect(std::bind(&App::Application::slotStartSaveDocument, this, sp::_1, sp::_2)); _pActiveDoc->signalFinishSave.connect(std::bind(&App::Application::slotFinishSaveDocument, this, sp::_1, sp::_2)); _pActiveDoc->signalChangePropertyEditor.connect(std::bind(&App::Application::slotChangePropertyEditor, this, sp::_1, sp::_2)); + // clang-format on //NOLINTEND // make sure that the active document is set in case no GUI is up @@ -1921,6 +1929,7 @@ void Application::init(int argc, char ** argv) } } +// clang-format off void Application::initTypes() { // Base types @@ -2484,6 +2493,7 @@ void processProgramOptions(const variables_map& vm, std::mapisPythonExtension()) { delete ext; std::stringstream str; - str << "Extension is not a python addable version: '" << Type << "'" << std::ends; + str << "Extension is not a python addable version: '" << Type << "'"; throw Base::TypeError(str.str()); } diff --git a/src/App/ExtensionContainer.h b/src/App/ExtensionContainer.h index 9a3b0e6fc0..7ff7091a3c 100644 --- a/src/App/ExtensionContainer.h +++ b/src/App/ExtensionContainer.h @@ -120,11 +120,14 @@ public: ~ExtensionContainer() override; void registerExtension(Base::Type extension, App::Extension* ext); - bool hasExtension(Base::Type, bool derived=true) const; //returns first of type (or derived from if set to true) and throws otherwise - bool hasExtension(const std::string& name) const; //this version does not check derived classes + //returns first of type (or derived from if set to true) and throws otherwise + bool hasExtension(Base::Type, bool derived=true) const; + //this version does not check derived classes + bool hasExtension(const std::string& name) const; bool hasExtensions() const; App::Extension* getExtension(Base::Type, bool derived = true, bool no_except=false) const; - App::Extension* getExtension(const std::string& name) const; //this version does not check derived classes + //this version does not check derived classes + App::Extension* getExtension(const std::string& name) const; // this version checks for derived types and doesn't throw template ExtensionT* getExtension() const { diff --git a/src/App/FeaturePythonPyImp.h b/src/App/FeaturePythonPyImp.h index 0fbb04abf3..d01190fe7d 100644 --- a/src/App/FeaturePythonPyImp.h +++ b/src/App/FeaturePythonPyImp.h @@ -20,6 +20,7 @@ * * ***************************************************************************/ +// clang-format off #ifndef APP_FEATUREPYTHONPYIMP_H #define APP_FEATUREPYTHONPYIMP_H @@ -117,3 +118,4 @@ private: #endif #endif // APP_FEATUREPYTHONPYIMP_H +// clang-format on diff --git a/src/App/FeaturePythonPyImp.inl b/src/App/FeaturePythonPyImp.inl index afff283d73..962b6e356d 100644 --- a/src/App/FeaturePythonPyImp.inl +++ b/src/App/FeaturePythonPyImp.inl @@ -21,6 +21,7 @@ ***************************************************************************/ +// clang-format off namespace App { @@ -200,3 +201,4 @@ PyObject *FeaturePythonPyT::_getattr(const char *attr) } } //namespace App +// clang-format on diff --git a/src/App/FreeCADInit.py b/src/App/FreeCADInit.py index d50393b9e6..d7dfd7c5a1 100644 --- a/src/App/FreeCADInit.py +++ b/src/App/FreeCADInit.py @@ -695,6 +695,7 @@ FreeCAD.addImportType("FreeCAD document (*.FCStd)","FreeCAD") # set to no gui, is overwritten by InitGui App.GuiUp = 0 +# fmt: off # fill up unit definitions App.Units.NanoMetre = App.Units.Quantity('nm') @@ -898,7 +899,7 @@ App.Units.VolumetricThermalExpansionCoefficient = App.Units.Unit(0,0,0,0,-1) App.Units.Work = App.Units.Unit(2,1,-2) App.Units.YieldStrength = App.Units.Unit(-1,1,-2) App.Units.YoungsModulus = App.Units.Unit(-1,1,-2) - +# fmt: on # Add an enum for the different unit schemes from enum import IntEnum diff --git a/src/App/MeasureDistance.cpp b/src/App/MeasureDistance.cpp index 08d6f63f36..9bd75333ac 100644 --- a/src/App/MeasureDistance.cpp +++ b/src/App/MeasureDistance.cpp @@ -32,11 +32,12 @@ PROPERTY_SOURCE(App::MeasureDistance, App::DocumentObject) MeasureDistance::MeasureDistance() { + // clang-format off ADD_PROPERTY_TYPE(P1,(Base::Vector3d()),"Measurement",Prop_None,"First point of measurement"); ADD_PROPERTY_TYPE(P2,(Base::Vector3d()),"Measurement",Prop_None,"Second point of measurement"); ADD_PROPERTY_TYPE(Distance,(0.0) ,"Measurement",App::PropertyType(Prop_ReadOnly|Prop_Output), "Distance between the points"); - + // clang-format on } MeasureDistance::~MeasureDistance() = default; diff --git a/src/App/Origin.cpp b/src/App/Origin.cpp index e0de6dc31d..a79951669a 100644 --- a/src/App/Origin.cpp +++ b/src/App/Origin.cpp @@ -136,13 +136,16 @@ void Origin::setupObject () { const char *role; const QString label; Base::Rotation rot; - } setupData [] = { + } + setupData [] = { + // clang-format off {App::Line::getClassTypeId(), AxisRoles[0], tr("X-axis"), Base::Rotation()}, {App::Line::getClassTypeId(), AxisRoles[1], tr("Y-axis"), Base::Rotation(Base::Vector3d(1,1,1), M_PI*2/3)}, {App::Line::getClassTypeId(), AxisRoles[2], tr("Z-axis"), Base::Rotation(Base::Vector3d(1,-1,1), M_PI*2/3)}, {App::Plane::getClassTypeId(), PlaneRoles[0], tr("XY-plane"), Base::Rotation()}, {App::Plane::getClassTypeId(), PlaneRoles[1], tr("XZ-plane"), Base::Rotation(1.0, 0.0, 0.0, 1.0 )}, {App::Plane::getClassTypeId(), PlaneRoles[2], tr("YZ-plane"), Base::Rotation(Base::Vector3d(1,1,1), M_PI*2/3)} + // clang-format on }; App::Document *doc = getDocument (); diff --git a/src/App/Property.cpp b/src/App/Property.cpp index fd02085d85..89e71e8268 100644 --- a/src/App/Property.cpp +++ b/src/App/Property.cpp @@ -261,8 +261,9 @@ void Property::Paste(const Property& /*from*/) } void Property::setStatusValue(unsigned long status) { + // clang-format off static const unsigned long mask = - (1<" << endl; + // clang-format off + writer.Stream() << writer.ind() + << "" << endl; + // clang-format on } void PropertyVector::Restore(Base::XMLReader &reader) @@ -437,12 +443,14 @@ void PropertyMatrix::setPyObject(PyObject *value) void PropertyMatrix::Save (Base::Writer &writer) const { + // clang-format off writer.Stream() << writer.ind() << "" << endl; + // clang-format on } void PropertyMatrix::Restore(Base::XMLReader &reader) @@ -1291,4 +1299,4 @@ void PropertyComplexGeoData::afterRestore() } } PropertyGeometry::afterRestore(); -} \ No newline at end of file +}