From 37c7169ee4d0258749366804c97fcb6e2c9ffc7c Mon Sep 17 00:00:00 2001 From: David Carter Date: Mon, 25 Sep 2023 07:33:07 -0400 Subject: [PATCH] Material: Material handling enhancements Rework of the material handling system. This first part concntrates on a rework of the material cards. Rather than use a fixed list of possible properties, properties can be defined separately in their own files and mixed to provide a complete list of possible properties. Properties can be inherited. The cards then provide values for the properties. These can also be inherited allowing for small changes in cards as required. The new property definitions are more extensive than previously. 2 and 3 dimensional arrays of properties can be defined. Values are obtained by calling an API instead of reading from a dictionary. For compatibility, a Python dictionary of values can be obtained similar to how it was done previously, but this is considered a deprecated API and won't support the newer advanced features. The editor is completely reworked. It will be able to edit older format material cards, but can only save them in the new format. For testing during the development phase, a system preference can specifiy wether the old or new material editors are to be used. This option will be removed before release. --- cMake/FreeCAD_Helpers/SetupLibYaml.cmake | 9 +- src/Mod/Fem/Gui/AppFemGui.cpp | 142 +++++++++--------- src/Mod/Material/App/AppMaterial.cpp | 33 ++-- src/Mod/Material/App/Exceptions.h | 51 +++---- src/Mod/Material/App/FolderTree.h | 43 +++--- src/Mod/Material/App/MaterialConfigLoader.cpp | 29 ++-- src/Mod/Material/App/MaterialConfigLoader.h | 31 ++-- src/Mod/Material/App/MaterialLibrary.cpp | 42 +++--- src/Mod/Material/App/MaterialLibrary.h | 39 ++--- src/Mod/Material/App/MaterialLoader.cpp | 50 +++--- src/Mod/Material/App/MaterialLoader.h | 51 +++---- src/Mod/Material/App/MaterialManager.cpp | 81 +++++----- src/Mod/Material/App/MaterialManager.h | 52 ++++--- .../Material/App/MaterialManagerPyImpl.cpp | 42 +++--- src/Mod/Material/App/MaterialPyImpl.cpp | 31 ++-- src/Mod/Material/App/MaterialValue.cpp | 29 ++-- src/Mod/Material/App/MaterialValue.h | 39 ++--- src/Mod/Material/App/Materials.cpp | 98 ++++++------ src/Mod/Material/App/Materials.h | 67 +++++---- src/Mod/Material/App/Model.cpp | 27 ++-- src/Mod/Material/App/Model.h | 37 ++--- src/Mod/Material/App/ModelLibrary.cpp | 27 ++-- src/Mod/Material/App/ModelLibrary.h | 37 ++--- src/Mod/Material/App/ModelLoader.cpp | 36 ++--- src/Mod/Material/App/ModelLoader.h | 43 +++--- src/Mod/Material/App/ModelManager.cpp | 48 +++--- src/Mod/Material/App/ModelManager.h | 47 +++--- src/Mod/Material/App/ModelManagerPyImpl.cpp | 37 +++-- src/Mod/Material/App/ModelPropertyPyImpl.cpp | 31 ++-- src/Mod/Material/App/ModelPyImpl.cpp | 31 ++-- src/Mod/Material/App/ModelUuids.h | 31 ++-- src/Mod/Material/App/PreCompiled.cpp | 28 ++-- src/Mod/Material/App/PreCompiled.h | 53 +++---- src/Mod/Material/App/trim.h | 31 ++-- src/Mod/Material/Gui/AppMatGui.cpp | 35 ++--- src/Mod/Material/Gui/Array2D.cpp | 34 ++--- src/Mod/Material/Gui/Array2D.h | 35 +++-- src/Mod/Material/Gui/Array3D.cpp | 36 ++--- src/Mod/Material/Gui/Array3D.h | 35 +++-- src/Mod/Material/Gui/ArrayDelegate.cpp | 27 ++-- src/Mod/Material/Gui/ArrayDelegate.h | 31 ++-- src/Mod/Material/Gui/ArrayModel.cpp | 57 ++++--- src/Mod/Material/Gui/ArrayModel.h | 55 ++++--- src/Mod/Material/Gui/CMakeLists.txt | 5 +- src/Mod/Material/Gui/Command.cpp | 28 ++-- src/Mod/Material/Gui/DlgSettingsMaterial.cpp | 31 ++-- src/Mod/Material/Gui/DlgSettingsMaterial.h | 33 ++-- src/Mod/Material/Gui/MaterialDelegate.cpp | 33 ++-- src/Mod/Material/Gui/MaterialDelegate.h | 33 ++-- src/Mod/Material/Gui/MaterialSave.cpp | 51 +++---- src/Mod/Material/Gui/MaterialSave.h | 40 ++--- src/Mod/Material/Gui/MaterialTreeView.h | 0 src/Mod/Material/Gui/MaterialsEditor.cpp | 51 +++---- src/Mod/Material/Gui/MaterialsEditor.h | 40 ++--- src/Mod/Material/Gui/ModelSelect.cpp | 47 +++--- src/Mod/Material/Gui/ModelSelect.h | 35 +++-- src/Mod/Material/Gui/PreCompiled.cpp | 28 ++-- src/Mod/Material/Gui/PreCompiled.h | 35 ++--- src/Mod/Material/Gui/Workbench.cpp | 34 +++++ src/Mod/Material/Gui/Workbench.h | 47 ++++++ src/Mod/Material/InitGui.py | 28 +++- src/Mod/Material/MaterialGlobal.h | 37 +++-- .../Material/materialtools/MaterialModels.py | 30 ++-- tests/src/Mod/Material/App/Model.cpp | 24 ++- 64 files changed, 1303 insertions(+), 1235 deletions(-) create mode 100644 src/Mod/Material/Gui/MaterialTreeView.h create mode 100644 src/Mod/Material/Gui/Workbench.cpp create mode 100644 src/Mod/Material/Gui/Workbench.h diff --git a/cMake/FreeCAD_Helpers/SetupLibYaml.cmake b/cMake/FreeCAD_Helpers/SetupLibYaml.cmake index 3b6d1a37af..dcbc6439c7 100644 --- a/cMake/FreeCAD_Helpers/SetupLibYaml.cmake +++ b/cMake/FreeCAD_Helpers/SetupLibYaml.cmake @@ -1,11 +1,4 @@ macro(SetupYamlCpp) -# -------------------------------- YamlCpp -------------------------------- - + # -------------------------------- YamlCpp -------------------------------- find_package(yaml-cpp REQUIRED) - if(NOT yaml-cpp_FOUND) - message(FATAL_ERROR "==================\n" - "YamlCpp not found.\n" - "==================\n") - endif(NOT yaml-cpp_FOUND) - endmacro(SetupYamlCpp) diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index 1dd5e7a730..82e3f3441a 100644 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -25,8 +25,8 @@ #include #include #include -#include #include +#include #include "DlgSettingsFemCcxImp.h" #include "DlgSettingsFemElmerImp.h" @@ -38,13 +38,21 @@ #include "DlgSettingsFemZ88Imp.h" #include "PropertyFemMeshItem.h" #include "ViewProviderAnalysis.h" +#include "ViewProviderFemMesh.h" +#include "ViewProviderFemMeshShape.h" +#include "ViewProviderFemMeshShapeNetgen.h" +#include "ViewProviderSetElements.h" +#include "ViewProviderSetFaces.h" +#include "ViewProviderSetGeometry.h" +#include "ViewProviderSetNodes.h" +#include "ViewProviderSolver.h" #include "ViewProviderFemConstraint.h" #include "ViewProviderFemConstraintBearing.h" #include "ViewProviderFemConstraintContact.h" #include "ViewProviderFemConstraintDisplacement.h" #include "ViewProviderFemConstraintFixed.h" -#include "ViewProviderFemConstraintFluidBoundary.h" #include "ViewProviderFemConstraintForce.h" +#include "ViewProviderFemConstraintFluidBoundary.h" #include "ViewProviderFemConstraintGear.h" #include "ViewProviderFemConstraintHeatflux.h" #include "ViewProviderFemConstraintInitialTemperature.h" @@ -55,15 +63,7 @@ #include "ViewProviderFemConstraintSpring.h" #include "ViewProviderFemConstraintTemperature.h" #include "ViewProviderFemConstraintTransform.h" -#include "ViewProviderFemMesh.h" -#include "ViewProviderFemMeshShape.h" -#include "ViewProviderFemMeshShapeNetgen.h" #include "ViewProviderResult.h" -#include "ViewProviderSetElements.h" -#include "ViewProviderSetFaces.h" -#include "ViewProviderSetGeometry.h" -#include "ViewProviderSetNodes.h" -#include "ViewProviderSolver.h" #include "Workbench.h" #ifdef FC_USE_VTK @@ -74,7 +74,7 @@ #endif -// use a different name to CreateCommand() + // use a different name to CreateCommand() void CreateFemCommands(); void loadFemResource() @@ -85,9 +85,8 @@ void loadFemResource() Gui::Translator::instance()->refresh(); } -namespace FemGui -{ -extern PyObject* initModule(); +namespace FemGui { + extern PyObject* initModule(); } @@ -107,89 +106,84 @@ PyMOD_INIT_FUNC(FemGui) // clang-format off // addition objects - FemGui::Workbench ::init(); + FemGui::Workbench ::init(); - FemGui::ViewProviderFemAnalysis ::init(); - FemGui::ViewProviderFemAnalysisPython ::init(); + FemGui::ViewProviderFemAnalysis ::init(); + FemGui::ViewProviderFemAnalysisPython ::init(); - FemGui::ViewProviderFemConstraint ::init(); - FemGui::ViewProviderFemConstraintPython ::init(); + FemGui::ViewProviderFemConstraint ::init(); + FemGui::ViewProviderFemConstraintPython ::init(); - FemGui::ViewProviderFemConstraintOnBoundary ::init(); - FemGui::ViewProviderFemConstraintBearing ::init(); - FemGui::ViewProviderFemConstraintContact ::init(); - FemGui::ViewProviderFemConstraintDisplacement ::init(); - FemGui::ViewProviderFemConstraintFixed ::init(); - FemGui::ViewProviderFemConstraintFluidBoundary ::init(); - FemGui::ViewProviderFemConstraintForce ::init(); - FemGui::ViewProviderFemConstraintGear ::init(); - FemGui::ViewProviderFemConstraintHeatflux ::init(); - FemGui::ViewProviderFemConstraintInitialTemperature ::init(); - FemGui::ViewProviderFemConstraintPlaneRotation ::init(); - FemGui::ViewProviderFemConstraintPressure ::init(); - FemGui::ViewProviderFemConstraintPulley ::init(); - FemGui::ViewProviderFemConstraintTemperature ::init(); - FemGui::ViewProviderFemConstraintTransform ::init(); - FemGui::ViewProviderFemConstraintSpring ::init(); + FemGui::ViewProviderFemConstraintOnBoundary ::init(); + FemGui::ViewProviderFemConstraintBearing ::init(); + FemGui::ViewProviderFemConstraintContact ::init(); + FemGui::ViewProviderFemConstraintDisplacement ::init(); + FemGui::ViewProviderFemConstraintFixed ::init(); + FemGui::ViewProviderFemConstraintFluidBoundary ::init(); + FemGui::ViewProviderFemConstraintForce ::init(); + FemGui::ViewProviderFemConstraintGear ::init(); + FemGui::ViewProviderFemConstraintHeatflux ::init(); + FemGui::ViewProviderFemConstraintInitialTemperature ::init(); + FemGui::ViewProviderFemConstraintPlaneRotation ::init(); + FemGui::ViewProviderFemConstraintPressure ::init(); + FemGui::ViewProviderFemConstraintPulley ::init(); + FemGui::ViewProviderFemConstraintTemperature ::init(); + FemGui::ViewProviderFemConstraintTransform ::init(); + FemGui::ViewProviderFemConstraintSpring ::init(); - FemGui::ViewProviderFemMesh ::init(); - FemGui::ViewProviderFemMeshPython ::init(); - FemGui::ViewProviderFemMeshShape ::init(); - FemGui::ViewProviderFemMeshShapeNetgen ::init(); - FemGui::PropertyFemMeshItem ::init(); + FemGui::ViewProviderFemMesh ::init(); + FemGui::ViewProviderFemMeshPython ::init(); + FemGui::ViewProviderFemMeshShape ::init(); + FemGui::ViewProviderFemMeshShapeNetgen ::init(); + FemGui::PropertyFemMeshItem ::init(); - FemGui::ViewProviderSetElements ::init(); - FemGui::ViewProviderSetFaces ::init(); - FemGui::ViewProviderSetGeometry ::init(); - FemGui::ViewProviderSetNodes ::init(); + FemGui::ViewProviderSetElements ::init(); + FemGui::ViewProviderSetFaces ::init(); + FemGui::ViewProviderSetGeometry ::init(); + FemGui::ViewProviderSetNodes ::init(); - FemGui::ViewProviderSolver ::init(); - FemGui::ViewProviderSolverPython ::init(); + FemGui::ViewProviderSolver ::init(); + FemGui::ViewProviderSolverPython ::init(); - FemGui::ViewProviderResult ::init(); - FemGui::ViewProviderResultPython ::init(); + FemGui::ViewProviderResult ::init(); + FemGui::ViewProviderResultPython ::init(); #ifdef FC_USE_VTK - FemGui::ViewProviderFemPostObject ::init(); - FemGui::ViewProviderFemPostPipeline ::init(); - FemGui::ViewProviderFemPostClip ::init(); - FemGui::ViewProviderFemPostContours ::init(); - FemGui::ViewProviderFemPostCut ::init(); - FemGui::ViewProviderFemPostDataAlongLine ::init(); - FemGui::ViewProviderFemPostDataAtPoint ::init(); - FemGui::ViewProviderFemPostScalarClip ::init(); - FemGui::ViewProviderFemPostWarpVector ::init(); + FemGui::ViewProviderFemPostObject ::init(); + FemGui::ViewProviderFemPostPipeline ::init(); + FemGui::ViewProviderFemPostClip ::init(); + FemGui::ViewProviderFemPostContours ::init(); + FemGui::ViewProviderFemPostCut ::init(); + FemGui::ViewProviderFemPostDataAlongLine ::init(); + FemGui::ViewProviderFemPostDataAtPoint ::init(); + FemGui::ViewProviderFemPostScalarClip ::init(); + FemGui::ViewProviderFemPostWarpVector ::init(); - FemGui::ViewProviderFemPostFunction ::init(); - FemGui::ViewProviderFemPostFunctionProvider ::init(); - FemGui::ViewProviderFemPostBoxFunction ::init(); - FemGui::ViewProviderFemPostCylinderFunction ::init(); - FemGui::ViewProviderFemPostPlaneFunction ::init(); - FemGui::ViewProviderFemPostSphereFunction ::init(); + FemGui::ViewProviderFemPostFunction ::init(); + FemGui::ViewProviderFemPostFunctionProvider ::init(); + FemGui::ViewProviderFemPostBoxFunction ::init(); + FemGui::ViewProviderFemPostCylinderFunction ::init(); + FemGui::ViewProviderFemPostPlaneFunction ::init(); + FemGui::ViewProviderFemPostSphereFunction ::init(); #endif - // register preferences pages on FEM, the order here will be the order of the tabs in pref - // widget - new Gui::PrefPageProducer( - QT_TRANSLATE_NOOP("QObject", "FEM")); + // register preferences pages on FEM, the order here will be the order of the tabs in pref widget + new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "FEM")); new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "FEM")); new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "FEM")); new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "FEM")); - new Gui::PrefPageProducer( - QT_TRANSLATE_NOOP("QObject", "FEM")); + new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "FEM")); new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "FEM")); // register preferences pages on Import-Export - new Gui::PrefPageProducer( - QT_TRANSLATE_NOOP("QObject", "Import-Export")); - new Gui::PrefPageProducer( - QT_TRANSLATE_NOOP("QObject", "Import-Export")); + new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Import-Export")); + new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Import-Export")); // add resources and reloads the translators loadFemResource(); // clang-format on PyMOD_Return(mod); -} +} \ No newline at end of file diff --git a/src/Mod/Material/App/AppMaterial.cpp b/src/Mod/Material/App/AppMaterial.cpp index 2f0ed8a40f..ced297ec95 100644 --- a/src/Mod/Material/App/AppMaterial.cpp +++ b/src/Mod/Material/App/AppMaterial.cpp @@ -1,26 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * 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 free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * 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. * + * 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 * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ - + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -45,7 +42,7 @@ public: Module() : Py::ExtensionModule("Material") { - initialize("This module is the Material module.");// register with Python + initialize("This module is the Material module."); // register with Python } ~Module() override = default; @@ -58,7 +55,7 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -}// namespace Materials +} // namespace Materials PyMOD_INIT_FUNC(Material) { diff --git a/src/Mod/Material/App/Exceptions.h b/src/Mod/Material/App/Exceptions.h index 3a70f7260e..c67e9df4eb 100644 --- a/src/Mod/Material/App/Exceptions.h +++ b/src/Mod/Material/App/Exceptions.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_EXCEPTIONS_H #define MATERIAL_EXCEPTIONS_H @@ -38,7 +37,7 @@ public: { this->setMessage(msg); } - ~Uninitialized() throw() override = default; + ~Uninitialized() noexcept override = default; }; class ModelNotFound: public Base::Exception @@ -50,7 +49,7 @@ public: { this->setMessage(msg); } - ~ModelNotFound() throw() override = default; + ~ModelNotFound() noexcept override = default; }; class MaterialNotFound: public Base::Exception @@ -62,7 +61,7 @@ public: { this->setMessage(msg); } - ~MaterialNotFound() throw() override = default; + ~MaterialNotFound() noexcept override = default; }; class PropertyNotFound: public Base::Exception @@ -74,7 +73,7 @@ public: { this->setMessage(msg); } - ~PropertyNotFound() throw() override = default; + ~PropertyNotFound() noexcept override = default; }; class LibraryNotFound: public Base::Exception @@ -86,7 +85,7 @@ public: { this->setMessage(msg); } - ~LibraryNotFound() throw() override = default; + ~LibraryNotFound() noexcept override = default; }; class InvalidModel: public Base::Exception @@ -98,7 +97,7 @@ public: { this->setMessage(msg); } - ~InvalidModel() throw() override = default; + ~InvalidModel() noexcept override = default; }; class InvalidRow: public Base::Exception @@ -110,7 +109,7 @@ public: { this->setMessage(msg); } - ~InvalidRow() throw() override = default; + ~InvalidRow() noexcept override = default; }; class InvalidColumn: public Base::Exception @@ -122,7 +121,7 @@ public: { this->setMessage(msg); } - ~InvalidColumn() throw() override = default; + ~InvalidColumn() noexcept override = default; }; class InvalidIndex: public Base::Exception @@ -134,7 +133,7 @@ public: { this->setMessage(msg); } - ~InvalidIndex() throw() override = default; + ~InvalidIndex() noexcept override = default; }; class UnknownValueType: public Base::Exception @@ -146,9 +145,9 @@ public: { this->setMessage(msg); } - ~UnknownValueType() throw() override = default; + ~UnknownValueType() noexcept override = default; }; -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_EXCEPTIONS_H +#endif // MATERIAL_EXCEPTIONS_H diff --git a/src/Mod/Material/App/FolderTree.h b/src/Mod/Material/App/FolderTree.h index 779f1ee0ec..75dd3dfcc7 100644 --- a/src/Mod/Material/App/FolderTree.h +++ b/src/Mod/Material/App/FolderTree.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_FOLDERTREE_H #define MATERIAL_FOLDERTREE_H @@ -43,7 +42,7 @@ public: {} virtual ~FolderTreeNode() = default; - NodeType getType(void) const + NodeType getType() const { return _type; } @@ -52,20 +51,20 @@ public: _type = type; } - const std::map*>* getFolder(void) const + const std::shared_ptr*>> getFolder() const { return _folder; } - std::map*>* getFolder(void) + std::shared_ptr*>> getFolder() { return _folder; } - const T* getData(void) const + const T* getData() const { return _data; } - void setFolder(std::map*>* folder) + void setFolder(std::shared_ptr*>> folder) { setType(FolderNode); _folder = folder; @@ -78,10 +77,10 @@ public: private: NodeType _type; - std::map*>* _folder; + std::shared_ptr*>> _folder; const T* _data; }; -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_FOLDERTREE_H +#endif // MATERIAL_FOLDERTREE_H diff --git a/src/Mod/Material/App/MaterialConfigLoader.cpp b/src/Mod/Material/App/MaterialConfigLoader.cpp index 4796c83100..6e5e287600 100644 --- a/src/Mod/Material/App/MaterialConfigLoader.cpp +++ b/src/Mod/Material/App/MaterialConfigLoader.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -378,7 +377,7 @@ Material* MaterialConfigLoader::getMaterialFromPath(const MaterialLibrary& libra // Now add the data setPhysicalValue(finalModel, "KindOfMaterial", kindOfMaterial); setPhysicalValue(finalModel, "MaterialNumber", materialNumber); - setPhysicalValue(finalModel, "StandardCode", norm);// Norm is the same as StandardCode + setPhysicalValue(finalModel, "StandardCode", norm); // Norm is the same as StandardCode setPhysicalValue(finalModel, "StandardCode", standardCode); } diff --git a/src/Mod/Material/App/MaterialConfigLoader.h b/src/Mod/Material/App/MaterialConfigLoader.h index 06a923c175..f2337cd04f 100644 --- a/src/Mod/Material/App/MaterialConfigLoader.h +++ b/src/Mod/Material/App/MaterialConfigLoader.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MATERIALCONFIGLOADER_H #define MATERIAL_MATERIALCONFIGLOADER_H @@ -76,6 +75,6 @@ private: static void addVectorRendering(const QSettings& fcmat, Material* finalModel); }; -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_MATERIALCONFIGLOADER_H +#endif // MATERIAL_MATERIALCONFIGLOADER_H diff --git a/src/Mod/Material/App/MaterialLibrary.cpp b/src/Mod/Material/App/MaterialLibrary.cpp index 224202d266..1233752be4 100644 --- a/src/Mod/Material/App/MaterialLibrary.cpp +++ b/src/Mod/Material/App/MaterialLibrary.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -35,16 +34,13 @@ using namespace Materials; /* TRANSLATOR Material::Materials */ -std::map* MaterialLibrary::_materialPathMap = nullptr; +std::unique_ptr> MaterialLibrary::_materialPathMap = + std::make_unique>(); TYPESYSTEM_SOURCE(Materials::MaterialLibrary, LibraryBase) MaterialLibrary::MaterialLibrary() -{ - if (_materialPathMap == nullptr) { - _materialPathMap = new std::map(); - } -} +{} MaterialLibrary::MaterialLibrary(const QString& libraryName, const QString& dir, @@ -52,11 +48,7 @@ MaterialLibrary::MaterialLibrary(const QString& libraryName, bool readOnly) : LibraryBase(libraryName, dir, icon) , _readOnly(readOnly) -{ - if (_materialPathMap == nullptr) { - _materialPathMap = new std::map(); - } -} +{} void MaterialLibrary::createPath(const QString& path) { diff --git a/src/Mod/Material/App/MaterialLibrary.h b/src/Mod/Material/App/MaterialLibrary.h index a247ce6828..a217bbec13 100644 --- a/src/Mod/Material/App/MaterialLibrary.h +++ b/src/Mod/Material/App/MaterialLibrary.h @@ -1,28 +1,29 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MATERIALLIBRARY_H #define MATERIAL_MATERIALLIBRARY_H +#include + #include #include #include @@ -46,7 +47,7 @@ public: const QString& dir, const QString& icon, bool readOnly = true); - virtual ~MaterialLibrary() = default; + ~MaterialLibrary() override = default; bool operator==(const MaterialLibrary& library) const { @@ -71,7 +72,7 @@ protected: const QString getUUIDFromPath(const QString& path) const; bool _readOnly; - static std::map* _materialPathMap; + static std::unique_ptr> _materialPathMap; }; class MaterialsExport MaterialExternalLibrary: public MaterialLibrary @@ -84,12 +85,12 @@ public: const QString& dir, const QString& icon, bool readOnly = true); - virtual ~MaterialExternalLibrary(); + ~MaterialExternalLibrary() override; }; -}// namespace Materials +} // namespace Materials Q_DECLARE_METATYPE(Materials::MaterialLibrary) Q_DECLARE_METATYPE(Materials::MaterialExternalLibrary) -#endif// MATERIAL_MATERIALLIBRARY_H +#endif // MATERIAL_MATERIALLIBRARY_H diff --git a/src/Mod/Material/App/MaterialLoader.cpp b/src/Mod/Material/App/MaterialLoader.cpp index fd87c4d40c..0756753de0 100644 --- a/src/Mod/Material/App/MaterialLoader.cpp +++ b/src/Mod/Material/App/MaterialLoader.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -74,7 +73,7 @@ QString MaterialYamlEntry::yamlValue(const YAML::Node& node, return QString::fromStdString(defaultValue); } -void MaterialYamlEntry::addToTree(std::map* materialMap) +void MaterialYamlEntry::addToTree(std::shared_ptr> materialMap) { std::set exclude; exclude.insert(QString::fromStdString("General")); @@ -100,7 +99,7 @@ void MaterialYamlEntry::addToTree(std::map* materialMap) std::string nodeName = it->second["UUID"].as(); finalModel->setParentUUID( - QString::fromStdString(nodeName));// Should only be one. Need to check + QString::fromStdString(nodeName)); // Should only be one. Need to check } } @@ -167,10 +166,10 @@ void MaterialYamlEntry::addToTree(std::map* materialMap) (*materialMap)[uuid] = library.addMaterial(*finalModel, path); } -std::map* MaterialLoader::_materialEntryMap = nullptr; +std::unique_ptr> MaterialLoader::_materialEntryMap = nullptr; -MaterialLoader::MaterialLoader(std::map* materialMap, - std::list* libraryList) +MaterialLoader::MaterialLoader(std::shared_ptr> materialMap, + std::shared_ptr> libraryList) : _materialMap(materialMap) , _libraryList(libraryList) { @@ -313,7 +312,7 @@ void MaterialLoader::dereference(Material* material) void MaterialLoader::loadLibrary(MaterialLibrary& library) { if (_materialEntryMap == nullptr) { - _materialEntryMap = new std::map(); + _materialEntryMap = std::make_unique>(); } QDirIterator it(library.getDirectory(), QDirIterator::Subdirectories); @@ -337,9 +336,9 @@ void MaterialLoader::loadLibrary(MaterialLibrary& library) } } -void MaterialLoader::loadLibraries(void) +void MaterialLoader::loadLibraries() { - std::list* _libraryList = getMaterialLibraries(); + auto _libraryList = getMaterialLibraries(); if (_libraryList) { for (auto it = _libraryList->begin(); it != _libraryList->end(); it++) { loadLibrary(**it); @@ -351,7 +350,7 @@ void MaterialLoader::loadLibraries(void) } } -std::list* MaterialLoader::getMaterialLibraries() +std::shared_ptr> MaterialLoader::getMaterialLibraries() { auto param = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/Mod/Material/Resources"); @@ -426,9 +425,10 @@ std::list* MaterialLoader::getMaterialLibraries() return _libraryList; } -std::list* MaterialLoader::getMaterialFolders(const MaterialLibrary& library) +std::shared_ptr> +MaterialLoader::getMaterialFolders(const MaterialLibrary& library) { - std::list* pathList = new std::list(); + std::shared_ptr> pathList = std::make_shared>(); QDirIterator it(library.getDirectory(), QDirIterator::Subdirectories); while (it.hasNext()) { auto pathname = it.next(); diff --git a/src/Mod/Material/App/MaterialLoader.h b/src/Mod/Material/App/MaterialLoader.h index 3bcaf673d1..f4bac08939 100644 --- a/src/Mod/Material/App/MaterialLoader.h +++ b/src/Mod/Material/App/MaterialLoader.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MATERIALLOADER_H #define MATERIAL_MATERIALLOADER_H @@ -43,7 +42,7 @@ public: const QString& modelUuid); virtual ~MaterialEntry() = default; - virtual void addToTree(std::map* materialMap) = 0; + virtual void addToTree(std::shared_ptr> materialMap) = 0; const MaterialLibrary& getLibrary() const { @@ -79,7 +78,7 @@ public: const YAML::Node& modelData); ~MaterialYamlEntry() override = default; - void addToTree(std::map* materialMap) override; + void addToTree(std::shared_ptr> materialMap) override; const YAML::Node& getModel() const { @@ -102,12 +101,12 @@ private: class MaterialLoader { public: - explicit MaterialLoader(std::map* materialMap, - std::list* libraryList); + explicit MaterialLoader(std::shared_ptr> materialMap, + std::shared_ptr> libraryList); virtual ~MaterialLoader(); - std::list* getMaterialLibraries(); - static std::list* getMaterialFolders(const MaterialLibrary& library); + std::shared_ptr> getMaterialLibraries(); + static std::shared_ptr> getMaterialFolders(const MaterialLibrary& library); static void showYaml(const YAML::Node& yaml); private: @@ -118,12 +117,12 @@ private: MaterialEntry* getMaterialFromPath(MaterialLibrary& library, const QString& path) const; void addLibrary(MaterialLibrary* model); void loadLibrary(MaterialLibrary& library); - void loadLibraries(void); - static std::map* _materialEntryMap; - std::map* _materialMap; - std::list* _libraryList; + void loadLibraries(); + static std::unique_ptr> _materialEntryMap; + std::shared_ptr> _materialMap; + std::shared_ptr> _libraryList; }; -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_MATERIALLOADER_H +#endif // MATERIAL_MATERIALLOADER_H diff --git a/src/Mod/Material/App/MaterialManager.cpp b/src/Mod/Material/App/MaterialManager.cpp index 2415a53ae4..717a273cff 100644 --- a/src/Mod/Material/App/MaterialManager.cpp +++ b/src/Mod/Material/App/MaterialManager.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -38,8 +37,8 @@ using namespace Materials; /* TRANSLATOR Material::Materials */ -std::list* MaterialManager::_libraryList = nullptr; -std::map* MaterialManager::_materialMap = nullptr; +std::shared_ptr> MaterialManager::_libraryList = nullptr; +std::shared_ptr> MaterialManager::_materialMap = nullptr; QMutex MaterialManager::_mutex; TYPESYSTEM_SOURCE(Materials::MaterialManager, Base::BaseClass) @@ -61,10 +60,10 @@ void MaterialManager::initLibraries() delete manager; - _materialMap = new std::map(); + _materialMap = std::make_shared>(); if (_libraryList == nullptr) { - _libraryList = new std::list(); + _libraryList = std::make_shared>(); } // Load the libraries @@ -139,8 +138,8 @@ const Material& MaterialManager::getMaterialByPath(const QString& path) const const Material& MaterialManager::getMaterialByPath(const QString& path, const QString& lib) const { - auto library = getLibrary(lib); // May throw LibraryNotFound - return library->getMaterialByPath(path);// May throw MaterialNotFound + auto library = getLibrary(lib); // May throw LibraryNotFound + return library->getMaterialByPath(path); // May throw MaterialNotFound } MaterialLibrary* MaterialManager::getLibrary(const QString& name) const @@ -154,13 +153,13 @@ MaterialLibrary* MaterialManager::getLibrary(const QString& name) const throw LibraryNotFound(); } -std::list* MaterialManager::getMaterialLibraries() +std::shared_ptr> MaterialManager::getMaterialLibraries() { if (_libraryList == nullptr) { if (_materialMap == nullptr) { - _materialMap = new std::map(); + _materialMap = std::make_shared>(); } - _libraryList = new std::list(); + _libraryList = std::make_shared>(); // Load the libraries MaterialLoader loader(_materialMap, _libraryList); @@ -168,10 +167,11 @@ std::list* MaterialManager::getMaterialLibraries() return _libraryList; } -std::map* -MaterialManager::getMaterialTree(const MaterialLibrary& library) +std::shared_ptr> +MaterialManager::getMaterialTree(const MaterialLibrary& library) const { - std::map* materialTree = new std::map(); + std::shared_ptr> materialTree = + std::make_shared>(); for (auto it = _materialMap->begin(); it != _materialMap->end(); it++) { auto filename = it->first; @@ -181,7 +181,7 @@ MaterialManager::getMaterialTree(const MaterialLibrary& library) fs::path path = material->getDirectory().toStdString(); // Start at the root - std::map* node = materialTree; + auto node = materialTree; for (auto itp = path.begin(); itp != path.end(); itp++) { if (QString::fromStdString(itp->string()) .endsWith(QString::fromStdString(".FCMat"))) { @@ -192,9 +192,9 @@ MaterialManager::getMaterialTree(const MaterialLibrary& library) else { // Add the folder only if it's not already there QString folderName = QString::fromStdString(itp->string()); - std::map* mapPtr; + std::shared_ptr> mapPtr; if (node->count(folderName) == 0) { - mapPtr = new std::map(); + mapPtr = std::make_shared>(); MaterialTreeNode* child = new MaterialTreeNode(); child->setFolder(mapPtr); (*node)[folderName] = child; @@ -208,18 +208,18 @@ MaterialManager::getMaterialTree(const MaterialLibrary& library) } } - std::list* folderList = getMaterialFolders(library); + auto folderList = getMaterialFolders(library); for (auto folder : *folderList) { fs::path path = folder.toStdString(); // Start at the root - std::map* node = materialTree; + auto node = materialTree; for (auto itp = path.begin(); itp != path.end(); itp++) { // Add the folder only if it's not already there QString folderName = QString::fromStdString(itp->string()); if (node->count(folderName) == 0) { - std::map* mapPtr = - new std::map(); + std::shared_ptr> mapPtr = + std::make_shared>(); MaterialTreeNode* child = new MaterialTreeNode(); child->setFolder(mapPtr); (*node)[folderName] = child; @@ -230,19 +230,20 @@ MaterialManager::getMaterialTree(const MaterialLibrary& library) } } } - delete folderList; return materialTree; } -std::list* MaterialManager::getMaterialFolders(const MaterialLibrary& library) +std::shared_ptr> +MaterialManager::getMaterialFolders(const MaterialLibrary& library) const { return MaterialLoader::getMaterialFolders(library); } -std::map* MaterialManager::materialsWithModel(QString uuid) +std::shared_ptr> MaterialManager::materialsWithModel(QString uuid) { - std::map* dict = new std::map(); + std::shared_ptr> dict = + std::make_shared>(); for (auto it = _materialMap->begin(); it != _materialMap->end(); it++) { QString key = it->first; @@ -256,9 +257,11 @@ std::map* MaterialManager::materialsWithModel(QString uuid) return dict; } -std::map* MaterialManager::materialsWithModelComplete(QString uuid) +std::shared_ptr> +MaterialManager::materialsWithModelComplete(QString uuid) { - std::map* dict = new std::map(); + std::shared_ptr> dict = + std::make_shared>(); for (auto it = _materialMap->begin(); it != _materialMap->end(); it++) { QString key = it->first; diff --git a/src/Mod/Material/App/MaterialManager.h b/src/Mod/Material/App/MaterialManager.h index eacebabca7..200bdf6d76 100644 --- a/src/Mod/Material/App/MaterialManager.h +++ b/src/Mod/Material/App/MaterialManager.h @@ -1,28 +1,29 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MATERIALMANAGER_H #define MATERIAL_MATERIALMANAGER_H +#include + #include #include @@ -43,9 +44,9 @@ class MaterialsExport MaterialManager: public Base::BaseClass public: MaterialManager(); - virtual ~MaterialManager() = default; + ~MaterialManager() override = default; - std::map* getMaterials() + std::shared_ptr> getMaterials() { return _materialMap; } @@ -55,9 +56,10 @@ public: MaterialLibrary* getLibrary(const QString& name) const; // Library management - static std::list* getMaterialLibraries(); - std::map* getMaterialTree(const MaterialLibrary& library); - std::list* getMaterialFolders(const MaterialLibrary& library); + static std::shared_ptr> getMaterialLibraries(); + std::shared_ptr> + getMaterialTree(const MaterialLibrary& library) const; + std::shared_ptr> getMaterialFolders(const MaterialLibrary& library) const; void createPath(MaterialLibrary* library, const QString& path) { library->createPath(path); @@ -69,17 +71,17 @@ public: static bool isMaterial(const fs::path& p); - std::map* materialsWithModel(QString uuid); - std::map* materialsWithModelComplete(QString uuid); + std::shared_ptr> materialsWithModel(QString uuid); + std::shared_ptr> materialsWithModelComplete(QString uuid); private: - static std::list* _libraryList; - static std::map* _materialMap; + static std::shared_ptr> _libraryList; + static std::shared_ptr> _materialMap; static QMutex _mutex; static void initLibraries(); }; -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_MATERIALMANAGER_H +#endif // MATERIAL_MATERIALMANAGER_H diff --git a/src/Mod/Material/App/MaterialManagerPyImpl.cpp b/src/Mod/Material/App/MaterialManagerPyImpl.cpp index 0f37e603f6..733b2cba2c 100644 --- a/src/Mod/Material/App/MaterialManagerPyImpl.cpp +++ b/src/Mod/Material/App/MaterialManagerPyImpl.cpp @@ -1,24 +1,23 @@ /*************************************************************************** - * Copyright (c) 2008 Werner Mayer * + * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" @@ -45,7 +44,7 @@ std::string MaterialManagerPy::representation() const return str.str(); } -PyObject* MaterialManagerPy::PyMake(struct _typeobject*, PyObject*, PyObject*)// Python wrapper +PyObject* MaterialManagerPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper { // never create such objects with the constructor return new MaterialManagerPy(new MaterialManager()); @@ -113,7 +112,7 @@ PyObject* MaterialManagerPy::getMaterialByPath(PyObject* args) Py::List MaterialManagerPy::getMaterialLibraries() const { - std::list* libraries = getMaterialManagerPtr()->getMaterialLibraries(); + auto libraries = getMaterialManagerPtr()->getMaterialLibraries(); Py::List list; for (auto it = libraries->begin(); it != libraries->end(); it++) { @@ -133,7 +132,7 @@ Py::Dict MaterialManagerPy::getMaterials() const { Py::Dict dict; - std::map* materials = getMaterialManagerPtr()->getMaterials(); + auto materials = getMaterialManagerPtr()->getMaterials(); for (auto it = materials->begin(); it != materials->end(); it++) { QString key = it->first; @@ -164,8 +163,7 @@ PyObject* MaterialManagerPy::materialsWithModel(PyObject* args) return nullptr; } - std::map* materials = - getMaterialManagerPtr()->materialsWithModel(QString::fromStdString(uuid)); + auto materials = getMaterialManagerPtr()->materialsWithModel(QString::fromStdString(uuid)); PyObject* dict = PyDict_New(); for (auto it = materials->begin(); it != materials->end(); it++) { @@ -175,7 +173,6 @@ PyObject* MaterialManagerPy::materialsWithModel(PyObject* args) PyObject* materialPy = new MaterialPy(new Material(*material)); PyDict_SetItem(dict, PyUnicode_FromString(key.toStdString().c_str()), materialPy); } - delete materials; return dict; } @@ -187,7 +184,7 @@ PyObject* MaterialManagerPy::materialsWithModelComplete(PyObject* args) return nullptr; } - std::map* materials = + auto materials = getMaterialManagerPtr()->materialsWithModelComplete(QString::fromStdString(uuid)); PyObject* dict = PyDict_New(); @@ -198,7 +195,6 @@ PyObject* MaterialManagerPy::materialsWithModelComplete(PyObject* args) PyObject* materialPy = new MaterialPy(new Material(*material)); PyDict_SetItem(dict, PyUnicode_FromString(key.toStdString().c_str()), materialPy); } - delete materials; return dict; } diff --git a/src/Mod/Material/App/MaterialPyImpl.cpp b/src/Mod/Material/App/MaterialPyImpl.cpp index 4d54aab955..0120b66b00 100644 --- a/src/Mod/Material/App/MaterialPyImpl.cpp +++ b/src/Mod/Material/App/MaterialPyImpl.cpp @@ -1,24 +1,23 @@ /*************************************************************************** - * Copyright (c) 2008 Werner Mayer * + * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" @@ -80,7 +79,7 @@ std::string MaterialPy::representation() const return str.str(); } -PyObject* MaterialPy::PyMake(struct _typeobject*, PyObject*, PyObject*)// Python wrapper +PyObject* MaterialPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper { // never create such objects with the constructor return new MaterialPy(new Material()); diff --git a/src/Mod/Material/App/MaterialValue.cpp b/src/Mod/Material/App/MaterialValue.cpp index d9f27fa24c..76805d369b 100644 --- a/src/Mod/Material/App/MaterialValue.cpp +++ b/src/Mod/Material/App/MaterialValue.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -109,7 +108,7 @@ void Material2DArray::setValue(int row, int column, const QVariant& value) } } -const QVariant Material2DArray::getValue(int row, int column) +const QVariant Material2DArray::getValue(int row, int column) const { try { auto val = getRow(row); diff --git a/src/Mod/Material/App/MaterialValue.h b/src/Mod/Material/App/MaterialValue.h index d6df062623..a39ff4578b 100644 --- a/src/Mod/Material/App/MaterialValue.h +++ b/src/Mod/Material/App/MaterialValue.h @@ -1,28 +1,29 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MATERIALVALUE_H #define MATERIAL_MATERIALVALUE_H +#include + #include namespace Materials @@ -52,12 +53,12 @@ public: explicit MaterialValue(ValueType type); virtual ~MaterialValue() = default; - ValueType getType() + ValueType getType() const { return _valueType; } - const QVariant getValue(void) const + const QVariant getValue() const { return _value; } @@ -118,7 +119,7 @@ public: void deleteRow(int row); void setValue(int row, int column, const QVariant& value); - const QVariant getValue(int row, int column); + const QVariant getValue(int row, int column) const; protected: std::vector*> _rows; @@ -178,10 +179,10 @@ protected: bool _defaultSet; }; -}// namespace Materials +} // namespace Materials Q_DECLARE_METATYPE(Materials::MaterialValue) Q_DECLARE_METATYPE(Materials::Material2DArray) Q_DECLARE_METATYPE(Materials::Material3DArray) -#endif// MATERIAL_MATERIALVALUE_H +#endif // MATERIAL_MATERIALVALUE_H diff --git a/src/Mod/Material/App/Materials.cpp b/src/Mod/Material/App/Materials.cpp index 01d25de872..a2c3b23add 100644 --- a/src/Mod/Material/App/Materials.cpp +++ b/src/Mod/Material/App/Materials.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -43,7 +42,7 @@ TYPESYSTEM_SOURCE(Materials::MaterialProperty, Materials::ModelProperty) MaterialProperty::MaterialProperty() { - _valuePtr = new MaterialValue(MaterialValue::None); + _valuePtr = std::make_shared(MaterialValue::None); } MaterialProperty::MaterialProperty(const ModelProperty& property) @@ -59,10 +58,10 @@ MaterialProperty::MaterialProperty(const ModelProperty& property) } if (_valuePtr->getType() == MaterialValue::Array2D) { - reinterpret_cast(_valuePtr)->setDefault(getColumnNull(0)); + std::static_pointer_cast(_valuePtr)->setDefault(getColumnNull(0)); } else if (_valuePtr->getType() == MaterialValue::Array3D) { - reinterpret_cast(_valuePtr)->setDefault(getColumnNull(0)); + std::static_pointer_cast(_valuePtr)->setDefault(getColumnNull(0)); } } @@ -71,7 +70,7 @@ MaterialProperty::MaterialProperty(const MaterialProperty& other) { _modelUUID = other._modelUUID; if (other._valuePtr != nullptr) { - _valuePtr = new MaterialValue(*(other._valuePtr)); + _valuePtr = std::make_shared(*(other._valuePtr)); } else { _valuePtr = nullptr; @@ -82,25 +81,30 @@ MaterialProperty::MaterialProperty(const MaterialProperty& other) } } -MaterialProperty::~MaterialProperty() -{} +// MaterialProperty::~MaterialProperty() +// {} void MaterialProperty::setModelUUID(const QString& uuid) { _modelUUID = uuid; } -const QVariant MaterialProperty::getValue(void) const +const QVariant MaterialProperty::getValue() const { return _valuePtr->getValue(); } -MaterialValue* MaterialProperty::getMaterialValue(void) +std::shared_ptr MaterialProperty::getMaterialValue() { return _valuePtr; } -const QString MaterialProperty::getString(void) const +const std::shared_ptr MaterialProperty::getMaterialValue() const +{ + return _valuePtr; +} + +const QString MaterialProperty::getString() const { if (getType() == MaterialValue::Quantity) { Base::Quantity quantity = getValue().value(); @@ -117,49 +121,45 @@ void MaterialProperty::setPropertyType(const QString& type) void MaterialProperty::setType(const QString& type) { - if (_valuePtr) { - delete _valuePtr; - } - if (type == QString::fromStdString("String")) { - _valuePtr = new MaterialValue(MaterialValue::String); + _valuePtr = std::make_shared(MaterialValue::String); } else if (type == QString::fromStdString("Boolean")) { - _valuePtr = new MaterialValue(MaterialValue::Boolean); + _valuePtr = std::make_shared(MaterialValue::Boolean); } else if (type == QString::fromStdString("Integer")) { - _valuePtr = new MaterialValue(MaterialValue::Integer); + _valuePtr = std::make_shared(MaterialValue::Integer); } else if (type == QString::fromStdString("Float")) { - _valuePtr = new MaterialValue(MaterialValue::Float); + _valuePtr = std::make_shared(MaterialValue::Float); } else if (type == QString::fromStdString("URL")) { - _valuePtr = new MaterialValue(MaterialValue::URL); + _valuePtr = std::make_shared(MaterialValue::URL); } else if (type == QString::fromStdString("Quantity")) { - _valuePtr = new MaterialValue(MaterialValue::Quantity); + _valuePtr = std::make_shared(MaterialValue::Quantity); } else if (type == QString::fromStdString("Color")) { - _valuePtr = new MaterialValue(MaterialValue::Color); + _valuePtr = std::make_shared(MaterialValue::Color); } else if (type == QString::fromStdString("File")) { - _valuePtr = new MaterialValue(MaterialValue::File); + _valuePtr = std::make_shared(MaterialValue::File); } else if (type == QString::fromStdString("Image")) { - _valuePtr = new MaterialValue(MaterialValue::Image); + _valuePtr = std::make_shared(MaterialValue::Image); } else if (type == QString::fromStdString("List")) { - _valuePtr = new MaterialValue(MaterialValue::List); + _valuePtr = std::make_shared(MaterialValue::List); } else if (type == QString::fromStdString("2DArray")) { - _valuePtr = new Material2DArray(); + _valuePtr = std::make_shared(); } else if (type == QString::fromStdString("3DArray")) { - _valuePtr = new Material3DArray(); + _valuePtr = std::make_shared(); } else { // Error. Throw something - _valuePtr = new MaterialValue(MaterialValue::None); + _valuePtr = std::make_shared(MaterialValue::None); std::string stringType = type.toStdString(); std::string name = getName().toStdString(); throw UnknownValueType(); @@ -176,6 +176,16 @@ MaterialProperty& MaterialProperty::getColumn(int column) } } +const MaterialProperty& MaterialProperty::getColumn(int column) const +{ + try { + return _columns.at(column); + } + catch (std::out_of_range const&) { + throw InvalidColumn(); + } +} + MaterialValue::ValueType MaterialProperty::getColumnType(int column) const { try { @@ -337,9 +347,9 @@ MaterialProperty& MaterialProperty::operator=(const MaterialProperty& other) ModelProperty::operator=(other); _modelUUID = other._modelUUID; - delete _valuePtr; + if (other._valuePtr != nullptr) { - _valuePtr = new MaterialValue(*(other._valuePtr)); + _valuePtr = std::make_shared(*(other._valuePtr)); } else { _valuePtr = nullptr; @@ -531,7 +541,7 @@ void Material::setPhysicalValue(const QString& name, const QString& value) { setPhysicalEditState(name); - _physical[name].setValue(value);// may not be a string type + _physical[name].setValue(value); // may not be a string type } void Material::setPhysicalValue(const QString& name, int value) @@ -559,7 +569,7 @@ void Material::setAppearanceValue(const QString& name, const QString& value) { setAppearanceEditState(name); - _appearance[name].setValue(value);// may not be a string type + _appearance[name].setValue(value); // may not be a string type } MaterialProperty& Material::getPhysicalProperty(const QString& name) diff --git a/src/Mod/Material/App/Materials.h b/src/Mod/Material/App/Materials.h index b8a950459f..a4ff89cd44 100644 --- a/src/Mod/Material/App/Materials.h +++ b/src/Mod/Material/App/Materials.h @@ -1,28 +1,29 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MATERIALS_H #define MATERIAL_MATERIALS_H +#include + #include #include #include @@ -46,28 +47,30 @@ public: MaterialProperty(); explicit MaterialProperty(const ModelProperty& property); explicit MaterialProperty(const MaterialProperty& property); - virtual ~MaterialProperty(); + ~MaterialProperty() override = default; - MaterialValue::ValueType getType(void) const + MaterialValue::ValueType getType() const { return _valuePtr->getType(); } - const QString getModelUUID(void) const; - const QVariant getValue(void) const; + const QString getModelUUID() const; + const QVariant getValue() const; bool isNull() const { return _valuePtr->isNull(); } - MaterialValue* getMaterialValue(void); - const QString getString(void) const; - bool getBoolean(void) const; - int getInt(void) const; - double getFloat(void) const; - const Base::Quantity& getQuantity(void) const; - const QString getURL(void) const; + std::shared_ptr getMaterialValue(); + const std::shared_ptr getMaterialValue() const; + const QString getString() const; + bool getBoolean() const; + int getInt() const; + double getFloat() const; + const Base::Quantity& getQuantity() const; + const QString getURL() const; MaterialProperty& getColumn(int column); + const MaterialProperty& getColumn(int column) const; MaterialValue::ValueType getColumnType(int column) const; QString getColumnUnits(int column) const; QVariant getColumnNull(int column) const; @@ -102,7 +105,7 @@ protected: private: QString _modelUUID; - MaterialValue* _valuePtr; + std::shared_ptr _valuePtr; std::vector _columns; }; @@ -113,9 +116,9 @@ class MaterialsExport Material: public Base::BaseClass public: enum ModelEdit { - ModelEdit_None, // No change - ModelEdit_Alter,// Existing values are changed - ModelEdit_Extend// New values added + ModelEdit_None, // No change + ModelEdit_Alter, // Existing values are changed + ModelEdit_Extend // New values added }; Material(); @@ -320,15 +323,15 @@ private: std::list _tags; std::vector _physicalUuids; std::vector _appearanceUuids; - std::vector _allUuids;// Includes inherited models + std::vector _allUuids; // Includes inherited models std::map _physical; std::map _appearance; bool _dereferenced; ModelEdit _editState; }; -}// namespace Materials +} // namespace Materials Q_DECLARE_METATYPE(Materials::Material*) -#endif// MATERIAL_MATERIALS_H +#endif // MATERIAL_MATERIALS_H diff --git a/src/Mod/Material/App/Model.cpp b/src/Mod/Material/App/Model.cpp index a6b8990db6..87020a96fa 100644 --- a/src/Mod/Material/App/Model.cpp +++ b/src/Mod/Material/App/Model.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ diff --git a/src/Mod/Material/App/Model.h b/src/Mod/Material/App/Model.h index 5284e0042e..5202e4d9c6 100644 --- a/src/Mod/Material/App/Model.h +++ b/src/Mod/Material/App/Model.h @@ -1,28 +1,29 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MODEL_H #define MATERIAL_MODEL_H +#include + #include #include #include @@ -46,7 +47,7 @@ public: const QString& url, const QString& description); explicit ModelProperty(const ModelProperty& other); - virtual ~ModelProperty() = default; + ~ModelProperty() override = default; const QString getName() const { @@ -147,7 +148,7 @@ public: const QString& description, const QString& url, const QString& doi); - virtual ~Model() = default; + ~Model() override = default; const ModelLibrary& getLibrary() const { @@ -292,6 +293,6 @@ private: std::map _properties; }; -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_MODEL_H +#endif // MATERIAL_MODEL_H diff --git a/src/Mod/Material/App/ModelLibrary.cpp b/src/Mod/Material/App/ModelLibrary.cpp index d42676b8ec..901795bd30 100644 --- a/src/Mod/Material/App/ModelLibrary.cpp +++ b/src/Mod/Material/App/ModelLibrary.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ diff --git a/src/Mod/Material/App/ModelLibrary.h b/src/Mod/Material/App/ModelLibrary.h index bca16e1180..1dfa04cbb1 100644 --- a/src/Mod/Material/App/ModelLibrary.h +++ b/src/Mod/Material/App/ModelLibrary.h @@ -1,28 +1,29 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MODELLIBRARY_H #define MATERIAL_MODELLIBRARY_H +#include + #include #include #include @@ -42,7 +43,7 @@ class MaterialsExport LibraryBase: public Base::BaseClass public: LibraryBase(); explicit LibraryBase(const QString& libraryName, const QString& dir, const QString& icon); - virtual ~LibraryBase() = default; + ~LibraryBase() override = default; const QString getName() const { @@ -81,7 +82,7 @@ class MaterialsExport ModelLibrary: public LibraryBase public: ModelLibrary(); explicit ModelLibrary(const QString& libraryName, const QString& dir, const QString& icon); - virtual ~ModelLibrary() = default; + ~ModelLibrary() override = default; bool operator==(const ModelLibrary& library) const { @@ -95,6 +96,6 @@ public: Model* addModel(const Model& model, const QString& path); }; -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_MODELLIBRARY_H +#endif // MATERIAL_MODELLIBRARY_H diff --git a/src/Mod/Material/App/ModelLoader.cpp b/src/Mod/Material/App/ModelLoader.cpp index 7d7e65c7fd..81c33c2253 100644 --- a/src/Mod/Material/App/ModelLoader.cpp +++ b/src/Mod/Material/App/ModelLoader.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -53,9 +52,10 @@ ModelEntry::ModelEntry(const ModelLibrary& library, , _dereferenced(false) {} -std::map* ModelLoader::_modelEntryMap = nullptr; +std::unique_ptr> ModelLoader::_modelEntryMap = nullptr; -ModelLoader::ModelLoader(std::map* modelMap, std::list* libraryList) +ModelLoader::ModelLoader(std::shared_ptr> modelMap, + std::shared_ptr> libraryList) : _modelMap(modelMap) , _libraryList(libraryList) { @@ -305,7 +305,7 @@ void ModelLoader::addToTree(ModelEntry* model, void ModelLoader::loadLibrary(const ModelLibrary& library) { if (_modelEntryMap == nullptr) { - _modelEntryMap = new std::map(); + _modelEntryMap = std::make_unique>(); } QDirIterator it(library.getDirectory(), QDirIterator::Subdirectories); @@ -340,7 +340,7 @@ void ModelLoader::loadLibrary(const ModelLibrary& library) // delete inheritances; } -void ModelLoader::loadLibraries(void) +void ModelLoader::loadLibraries() { getModelLibraries(); if (_libraryList) { diff --git a/src/Mod/Material/App/ModelLoader.h b/src/Mod/Material/App/ModelLoader.h index 410fb74d18..b843b9e1fb 100644 --- a/src/Mod/Material/App/ModelLoader.h +++ b/src/Mod/Material/App/ModelLoader.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MODELLOADER_H #define MATERIAL_MODELLOADER_H @@ -96,8 +95,8 @@ private: class ModelLoader { public: - explicit ModelLoader(std::map* modelMap, - std::list* libraryList); + explicit ModelLoader(std::shared_ptr> modelMap, + std::shared_ptr> libraryList); virtual ~ModelLoader() = default; static const QString getUUIDFromPath(const QString& path); @@ -119,12 +118,12 @@ private: ModelEntry* getModelFromPath(const ModelLibrary& library, const QString& path) const; void addLibrary(ModelLibrary* model); void loadLibrary(const ModelLibrary& library); - void loadLibraries(void); - static std::map* _modelEntryMap; - std::map* _modelMap; - std::list* _libraryList; + void loadLibraries(); + static std::unique_ptr> _modelEntryMap; + std::shared_ptr> _modelMap; + std::shared_ptr> _libraryList; }; -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_MODELLOADER_H +#endif // MATERIAL_MODELLOADER_H diff --git a/src/Mod/Material/App/ModelManager.cpp b/src/Mod/Material/App/ModelManager.cpp index 63f303d7f4..2900fdde55 100644 --- a/src/Mod/Material/App/ModelManager.cpp +++ b/src/Mod/Material/App/ModelManager.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -35,8 +34,8 @@ using namespace Materials; -std::list* ModelManager::_libraryList = nullptr; -std::map* ModelManager::_modelMap = nullptr; +std::shared_ptr> ModelManager::_libraryList = nullptr; +std::shared_ptr> ModelManager::_modelMap = nullptr; QMutex ModelManager::_mutex; TYPESYSTEM_SOURCE(Materials::ModelManager, Base::BaseClass) @@ -51,9 +50,9 @@ void ModelManager::initLibraries() QMutexLocker locker(&_mutex); if (_modelMap == nullptr) { - _modelMap = new std::map(); + _modelMap = std::make_shared>(); if (_libraryList == nullptr) { - _libraryList = new std::list(); + _libraryList = std::make_shared>(); } // Load the libraries @@ -126,10 +125,11 @@ bool ModelManager::passFilter(ModelFilter filter, Model::ModelType modelType) co return false; } -std::map* ModelManager::getModelTree(const ModelLibrary& library, - ModelFilter filter) +std::shared_ptr> +ModelManager::getModelTree(const ModelLibrary& library, ModelFilter filter) const { - std::map* modelTree = new std::map(); + std::shared_ptr> modelTree = + std::make_shared>(); for (auto it = _modelMap->begin(); it != _modelMap->end(); it++) { auto filename = it->first; @@ -140,7 +140,7 @@ std::map* ModelManager::getModelTree(const ModelLibrary Base::Console().Log("Relative path '%s'\n\t", path.string().c_str()); // Start at the root - std::map* node = modelTree; + std::shared_ptr> node = modelTree; for (auto itp = path.begin(); itp != path.end(); itp++) { if (isModel(itp->string())) { ModelTreeNode* child = new ModelTreeNode(); @@ -150,9 +150,9 @@ std::map* ModelManager::getModelTree(const ModelLibrary else { // Add the folder only if it's not already there QString folderName = QString::fromStdString(itp->string()); - std::map* mapPtr; + std::shared_ptr> mapPtr; if (node->count(QString::fromStdString(itp->string())) == 0) { - mapPtr = new std::map(); + mapPtr = std::make_shared>(); ModelTreeNode* child = new ModelTreeNode(); child->setFolder(mapPtr); (*node)[QString::fromStdString(itp->string())] = child; diff --git a/src/Mod/Material/App/ModelManager.h b/src/Mod/Material/App/ModelManager.h index 06b97297d9..6fc79bc3c9 100644 --- a/src/Mod/Material/App/ModelManager.h +++ b/src/Mod/Material/App/ModelManager.h @@ -1,28 +1,29 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MODELMANAGER_H #define MATERIAL_MODELMANAGER_H +#include + #include #include @@ -51,20 +52,20 @@ public: }; ModelManager(); - virtual ~ModelManager() = default; + ~ModelManager() override = default; void refresh(); - std::list* getModelLibraries() + std::shared_ptr> getModelLibraries() { return _libraryList; } - std::map* getModels() + std::shared_ptr> getModels() { return _modelMap; } - std::map* getModelTree(const ModelLibrary& library, - ModelFilter filter = ModelFilter_None); + std::shared_ptr> + getModelTree(const ModelLibrary& library, ModelFilter filter = ModelFilter_None) const; const Model& getModel(const QString& uuid) const; const Model& getModelByPath(const QString& path) const; const Model& getModelByPath(const QString& path, const QString& libraryPath) const; @@ -75,11 +76,11 @@ public: private: static void initLibraries(); - static std::list* _libraryList; - static std::map* _modelMap; + static std::shared_ptr> _libraryList; + static std::shared_ptr> _modelMap; static QMutex _mutex; }; -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_MODELMANAGER_H +#endif // MATERIAL_MODELMANAGER_H diff --git a/src/Mod/Material/App/ModelManagerPyImpl.cpp b/src/Mod/Material/App/ModelManagerPyImpl.cpp index 0df3749a8c..793a80a63b 100644 --- a/src/Mod/Material/App/ModelManagerPyImpl.cpp +++ b/src/Mod/Material/App/ModelManagerPyImpl.cpp @@ -1,24 +1,23 @@ /*************************************************************************** - * Copyright (c) 2008 Werner Mayer * + * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" @@ -43,7 +42,7 @@ std::string ModelManagerPy::representation() const return str.str(); } -PyObject* ModelManagerPy::PyMake(struct _typeobject*, PyObject*, PyObject*)// Python wrapper +PyObject* ModelManagerPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper { // never create such objects with the constructor return new ModelManagerPy(new ModelManager()); @@ -68,7 +67,7 @@ PyObject* ModelManagerPy::getModel(PyObject* args) } catch (ModelNotFound const&) { QString error = QString::fromStdString("Model not found:\n"); - std::map* _modelMap = getModelManagerPtr()->getModels(); + auto _modelMap = getModelManagerPtr()->getModels(); error += QString::fromStdString("ModelMap:\n"); for (auto itp = _modelMap->begin(); itp != _modelMap->end(); itp++) { error += QString::fromStdString("\t_modelMap[") + itp->first @@ -120,7 +119,7 @@ PyObject* ModelManagerPy::getModelByPath(PyObject* args) Py::List ModelManagerPy::getModelLibraries() const { - std::list* libraries = getModelManagerPtr()->getModelLibraries(); + std::shared_ptr> libraries = getModelManagerPtr()->getModelLibraries(); Py::List list; for (auto it = libraries->begin(); it != libraries->end(); it++) { @@ -138,7 +137,7 @@ Py::List ModelManagerPy::getModelLibraries() const Py::Dict ModelManagerPy::getModels() const { - std::map* models = getModelManagerPtr()->getModels(); + auto models = getModelManagerPtr()->getModels(); Py::Dict dict; for (auto it = models->begin(); it != models->end(); it++) { diff --git a/src/Mod/Material/App/ModelPropertyPyImpl.cpp b/src/Mod/Material/App/ModelPropertyPyImpl.cpp index dea18c1ead..e87cb6f15f 100644 --- a/src/Mod/Material/App/ModelPropertyPyImpl.cpp +++ b/src/Mod/Material/App/ModelPropertyPyImpl.cpp @@ -1,24 +1,23 @@ /*************************************************************************** - * Copyright (c) 2008 Werner Mayer * + * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" @@ -53,7 +52,7 @@ std::string ModelPropertyPy::representation() const return str.str(); } -PyObject* ModelPropertyPy::PyMake(struct _typeobject*, PyObject*, PyObject*)// Python wrapper +PyObject* ModelPropertyPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper { // never create such objects with the constructor return new ModelPropertyPy(new ModelProperty()); diff --git a/src/Mod/Material/App/ModelPyImpl.cpp b/src/Mod/Material/App/ModelPyImpl.cpp index 431939c396..1d83d99e65 100644 --- a/src/Mod/Material/App/ModelPyImpl.cpp +++ b/src/Mod/Material/App/ModelPyImpl.cpp @@ -1,24 +1,23 @@ /*************************************************************************** - * Copyright (c) 2008 Werner Mayer * + * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" @@ -74,7 +73,7 @@ std::string ModelPy::representation() const return str.str(); } -PyObject* ModelPy::PyMake(struct _typeobject*, PyObject*, PyObject*)// Python wrapper +PyObject* ModelPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper { // never create such objects with the constructor return new ModelPy(new Model()); diff --git a/src/Mod/Material/App/ModelUuids.h b/src/Mod/Material/App/ModelUuids.h index cf4074cb21..d6648252e3 100644 --- a/src/Mod/Material/App/ModelUuids.h +++ b/src/Mod/Material/App/ModelUuids.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_MODELUUIDS_H #define MATERIAL_MODELUUIDS_H @@ -68,6 +67,6 @@ static const QString ModelUUID_Rendering_Advanced = static const QString ModelUUID_Rendering_Vector = QString::fromStdString("fdf5a80e-de50-4157-b2e5-b6e5f88b680e"); -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_MODELUUIDS_H +#endif // MATERIAL_MODELUUIDS_H diff --git a/src/Mod/Material/App/PreCompiled.cpp b/src/Mod/Material/App/PreCompiled.cpp index c2507f9804..48eade6cc8 100644 --- a/src/Mod/Material/App/PreCompiled.cpp +++ b/src/Mod/Material/App/PreCompiled.cpp @@ -1,24 +1,22 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ - + **************************************************************************/ #include "PreCompiled.h" diff --git a/src/Mod/Material/App/PreCompiled.h b/src/Mod/Material/App/PreCompiled.h index 43d31c08af..c643eb4f42 100644 --- a/src/Mod/Material/App/PreCompiled.h +++ b/src/Mod/Material/App/PreCompiled.h @@ -1,45 +1,42 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ -#ifndef MATGUI_PRECOMPILED_H -#define MATGUI_PRECOMPILED_H +#ifndef MATERIAL_PRECOMPILED_H +#define MATERIAL_PRECOMPILED_H #include -#include - // point at which warnings of overly long specifiers disabled (needed for VC6) #ifdef _MSC_VER -# pragma warning( disable : 4251 ) -# pragma warning( disable : 4503 ) -# pragma warning( disable : 4786 ) // specifier longer then 255 chars -# pragma warning( disable : 4273 ) +#pragma warning(disable : 4251) +#pragma warning(disable : 4503) +#pragma warning(disable : 4786) // specifier longer then 255 chars +#pragma warning(disable : 4273) #endif #ifdef FC_OS_WIN32 -# ifndef NOMINMAX -# define NOMINMAX -# endif -# include +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include #endif #ifdef _PreComp_ @@ -59,9 +56,9 @@ #include // Boost -#include #include +#include #endif //_PreComp_ -#endif // MATGUI_PRECOMPILED_H +#endif // MATERIAL_PRECOMPILED_H diff --git a/src/Mod/Material/App/trim.h b/src/Mod/Material/App/trim.h index 79d8844a86..c4b038567a 100644 --- a/src/Mod/Material/App/trim.h +++ b/src/Mod/Material/App/trim.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATERIAL_TRIM_H #define MATERIAL_TRIM_H @@ -76,6 +75,6 @@ static inline std::string trim_copy(std::string s) return s; } -}// namespace Materials +} // namespace Materials -#endif// MATERIAL_TRIM_H +#endif // MATERIAL_TRIM_H diff --git a/src/Mod/Material/Gui/AppMatGui.cpp b/src/Mod/Material/Gui/AppMatGui.cpp index 629b4457a4..f20967589b 100644 --- a/src/Mod/Material/Gui/AppMatGui.cpp +++ b/src/Mod/Material/Gui/AppMatGui.cpp @@ -1,25 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * 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 free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * 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. * + * 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 * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" @@ -34,6 +32,7 @@ #include #include "DlgSettingsMaterial.h" +#include "Workbench.h" // use a different name to CreateCommand() void CreateMaterialCommands(); @@ -54,7 +53,7 @@ public: Module() : Py::ExtensionModule("MatGui") { - initialize("This module is the MatGui module.");// register with Python + initialize("This module is the MatGui module."); // register with Python } ~Module() override @@ -68,7 +67,7 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -}// namespace MatGui +} // namespace MatGui PyMOD_INIT_FUNC(MatGui) { @@ -90,6 +89,8 @@ PyMOD_INIT_FUNC(MatGui) Base::Console().Log("Loading GUI of Material module... done\n"); + MatGui::Workbench ::init(); + // instantiating the commands CreateMaterialCommands(); diff --git a/src/Mod/Material/Gui/Array2D.cpp b/src/Mod/Material/Gui/Array2D.cpp index 4c10d789ea..5e39884d82 100644 --- a/src/Mod/Material/Gui/Array2D.cpp +++ b/src/Mod/Material/Gui/Array2D.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -56,7 +55,8 @@ Array2D::Array2D(const QString& propertyName, Materials::Material* material, QWi _property = nullptr; } if (_property) { - _value = static_cast(_property->getMaterialValue()); + _value = + std::static_pointer_cast(_property->getMaterialValue()); } else { _value = nullptr; @@ -76,7 +76,7 @@ void Array2D::setupDefault() } try { - Materials::MaterialProperty& column1 = _property->getColumn(0); + const Materials::MaterialProperty& column1 = _property->getColumn(0); QString label = QString::fromStdString("Default ") + column1.getName(); ui->labelDefault->setText(label); if (column1.getPropertyType() == QString::fromStdString("Quantity")) { @@ -118,7 +118,7 @@ void Array2D::setColumnDelegates(QTableView* table) { int length = _property->columns(); for (int i = 0; i < length; i++) { - Materials::MaterialProperty& column = _property->getColumn(i); + const Materials::MaterialProperty& column = _property->getColumn(i); table->setItemDelegateForColumn( i, new ArrayDelegate(column.getType(), column.getUnits(), this)); diff --git a/src/Mod/Material/Gui/Array2D.h b/src/Mod/Material/Gui/Array2D.h index 1195739b72..f32f97e93e 100644 --- a/src/Mod/Material/Gui/Array2D.h +++ b/src/Mod/Material/Gui/Array2D.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATGUI_ARRAY2D_H #define MATGUI_ARRAY2D_H @@ -53,8 +52,8 @@ public: private: std::unique_ptr ui; - Materials::MaterialProperty* _property; - Materials::Material2DArray* _value; + const Materials::MaterialProperty* _property; + std::shared_ptr _value; void setupDefault(); void setHeaders(QStandardItemModel* model); @@ -63,6 +62,6 @@ private: void setupArray(); }; -}// namespace MatGui +} // namespace MatGui -#endif// MATGUI_ARRAY2D_H +#endif // MATGUI_ARRAY2D_H diff --git a/src/Mod/Material/Gui/Array3D.cpp b/src/Mod/Material/Gui/Array3D.cpp index 150f639376..99bf3d546a 100644 --- a/src/Mod/Material/Gui/Array3D.cpp +++ b/src/Mod/Material/Gui/Array3D.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -55,7 +54,8 @@ Array3D::Array3D(const QString& propertyName, Materials::Material* material, QWi _property = nullptr; } if (_property) { - _value = static_cast(_property->getMaterialValue()); + _value = + std::static_pointer_cast(_property->getMaterialValue()); } else { _value = nullptr; @@ -95,7 +95,7 @@ void Array3D::setupDefault() } try { - Materials::MaterialProperty& column1 = _property->getColumn(0); + auto& column1 = _property->getColumn(0); QString label = QString::fromStdString("Default ") + column1.getName(); ui->labelDefault->setText(label); if (column1.getPropertyType() == QString::fromStdString("Quantity")) { @@ -122,7 +122,7 @@ void Array3D::defaultValueChanged(const Base::Quantity& value) void Array3D::setDepthColumnDelegate(QTableView* table) { - Materials::MaterialProperty& column = _property->getColumn(0); + auto& column = _property->getColumn(0); table->setItemDelegateForColumn(0, new ArrayDelegate(column.getType(), column.getUnits(), this)); } @@ -159,7 +159,7 @@ void Array3D::setColumnDelegates(QTableView* table) { int length = _property->columns(); for (int i = 0; i < length; i++) { - Materials::MaterialProperty& column = _property->getColumn(i); + auto& column = _property->getColumn(i); table->setItemDelegateForColumn( i, new ArrayDelegate(column.getType(), column.getUnits(), this)); diff --git a/src/Mod/Material/Gui/Array3D.h b/src/Mod/Material/Gui/Array3D.h index 7759a674ff..307a1b669a 100644 --- a/src/Mod/Material/Gui/Array3D.h +++ b/src/Mod/Material/Gui/Array3D.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATGUI_ARRAY3D_H #define MATGUI_ARRAY3D_H @@ -50,8 +49,8 @@ public: private: std::unique_ptr ui; - Materials::MaterialProperty* _property; - Materials::Material3DArray* _value; + const Materials::MaterialProperty* _property; + std::shared_ptr _value; void setupDefault(); void setDepthColumnWidth(QTableView* table); @@ -62,6 +61,6 @@ private: void setupArray(); }; -}// namespace MatGui +} // namespace MatGui -#endif// MATGUI_ARRAY3D_H +#endif // MATGUI_ARRAY3D_H diff --git a/src/Mod/Material/Gui/ArrayDelegate.cpp b/src/Mod/Material/Gui/ArrayDelegate.cpp index ea5df4a7fb..95c030a159 100644 --- a/src/Mod/Material/Gui/ArrayDelegate.cpp +++ b/src/Mod/Material/Gui/ArrayDelegate.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ diff --git a/src/Mod/Material/Gui/ArrayDelegate.h b/src/Mod/Material/Gui/ArrayDelegate.h index 71e3bdd222..74e9c76c36 100644 --- a/src/Mod/Material/Gui/ArrayDelegate.h +++ b/src/Mod/Material/Gui/ArrayDelegate.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATGUI_ArrayDelegate_H #define MATGUI_ArrayDelegate_H @@ -70,6 +69,6 @@ private: QWidget* createWidget(QWidget* parent, const QVariant& item) const; }; -}// namespace MatGui +} // namespace MatGui -#endif// MATGUI_ArrayDelegate_H +#endif // MATGUI_ArrayDelegate_H diff --git a/src/Mod/Material/Gui/ArrayModel.cpp b/src/Mod/Material/Gui/ArrayModel.cpp index 3114c7ef67..24c0ba8b42 100644 --- a/src/Mod/Material/Gui/ArrayModel.cpp +++ b/src/Mod/Material/Gui/ArrayModel.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -47,8 +46,8 @@ AbstractArrayModel::AbstractArrayModel(QObject* parent) //=== -Array2DModel::Array2DModel(Materials::MaterialProperty* property, - Materials::Material2DArray* value, +Array2DModel::Array2DModel(const Materials::MaterialProperty* property, + std::shared_ptr value, QObject* parent) : AbstractArrayModel(parent) , _property(property) @@ -58,10 +57,10 @@ Array2DModel::Array2DModel(Materials::MaterialProperty* property, int Array2DModel::rowCount(const QModelIndex& parent) const { if (parent.isValid()) { - return 0;// No children + return 0; // No children } - return _value->rows() + 1;// Will always have 1 empty row + return _value->rows() + 1; // Will always have 1 empty row } bool Array2DModel::newRow(const QModelIndex& index) const @@ -105,7 +104,7 @@ QVariant Array2DModel::headerData(int section, Qt::Orientation orientation, int { if (role == Qt::DisplayRole) { if (orientation == Qt::Horizontal) { - Materials::MaterialProperty& column = _property->getColumn(section); + const Materials::MaterialProperty& column = _property->getColumn(section); return QVariant(column.getName()); } else if (orientation == Qt::Vertical) { @@ -188,8 +187,8 @@ bool Array2DModel::removeColumns(int column, int count, const QModelIndex& paren //=== -Array3DDepthModel::Array3DDepthModel(Materials::MaterialProperty* property, - Materials::Material3DArray* value, +Array3DDepthModel::Array3DDepthModel(const Materials::MaterialProperty* property, + std::shared_ptr value, QObject* parent) : AbstractArrayModel(parent) , _property(property) @@ -199,10 +198,10 @@ Array3DDepthModel::Array3DDepthModel(Materials::MaterialProperty* property, int Array3DDepthModel::rowCount(const QModelIndex& parent) const { if (parent.isValid()) { - return 0;// No children + return 0; // No children } - return _value->depth() + 1;// Will always have 1 empty row + return _value->depth() + 1; // Will always have 1 empty row } bool Array3DDepthModel::newRow(const QModelIndex& index) const @@ -239,7 +238,7 @@ QVariant Array3DDepthModel::headerData(int section, Qt::Orientation orientation, { if (role == Qt::DisplayRole) { if (orientation == Qt::Horizontal) { - Materials::MaterialProperty& column = _property->getColumn(section); + const Materials::MaterialProperty& column = _property->getColumn(section); return QVariant(column.getName()); } else if (orientation == Qt::Vertical) { @@ -322,8 +321,8 @@ bool Array3DDepthModel::removeColumns(int column, int count, const QModelIndex& //=== -Array3DModel::Array3DModel(Materials::MaterialProperty* property, - Materials::Material3DArray* value, +Array3DModel::Array3DModel(const Materials::MaterialProperty* property, + std::shared_ptr value, QObject* parent) : AbstractArrayModel(parent) , _property(property) @@ -333,10 +332,10 @@ Array3DModel::Array3DModel(Materials::MaterialProperty* property, int Array3DModel::rowCount(const QModelIndex& parent) const { if (parent.isValid()) { - return 0;// No children + return 0; // No children } - return _value->depth() + 1;// Will always have 1 empty row + return _value->depth() + 1; // Will always have 1 empty row } int Array3DModel::columnCount(const QModelIndex& parent) const @@ -384,7 +383,7 @@ QVariant Array3DModel::headerData(int section, Qt::Orientation orientation, int { if (role == Qt::DisplayRole) { if (orientation == Qt::Horizontal) { - Materials::MaterialProperty& column = _property->getColumn(section + 1); + const Materials::MaterialProperty& column = _property->getColumn(section + 1); return QVariant(column.getName()); } else if (orientation == Qt::Vertical) { diff --git a/src/Mod/Material/Gui/ArrayModel.h b/src/Mod/Material/Gui/ArrayModel.h index 021f041be4..7bb4f6816d 100644 --- a/src/Mod/Material/Gui/ArrayModel.h +++ b/src/Mod/Material/Gui/ArrayModel.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATGUI_ARRAYMODEL_H #define MATGUI_ARRAYMODEL_H @@ -46,8 +45,8 @@ public: class Array2DModel: public AbstractArrayModel { public: - explicit Array2DModel(Materials::MaterialProperty* property = nullptr, - Materials::Material2DArray* value = nullptr, + explicit Array2DModel(const Materials::MaterialProperty* property = nullptr, + std::shared_ptr value = nullptr, QObject* parent = nullptr); ~Array2DModel() override = default; @@ -68,15 +67,15 @@ public: bool removeColumns(int column, int count, const QModelIndex& parent = QModelIndex()) override; private: - Materials::MaterialProperty* _property; - Materials::Material2DArray* _value; + const Materials::MaterialProperty* _property; + std::shared_ptr _value; }; class Array3DDepthModel: public AbstractArrayModel { public: - explicit Array3DDepthModel(Materials::MaterialProperty* property = nullptr, - Materials::Material3DArray* value = nullptr, + explicit Array3DDepthModel(const Materials::MaterialProperty* property = nullptr, + std::shared_ptr value = nullptr, QObject* parent = nullptr); ~Array3DDepthModel() override = default; @@ -101,15 +100,15 @@ public: bool removeColumns(int column, int count, const QModelIndex& parent = QModelIndex()) override; private: - Materials::MaterialProperty* _property; - Materials::Material3DArray* _value; + const Materials::MaterialProperty* _property; + std::shared_ptr _value; }; class Array3DModel: public AbstractArrayModel { public: - explicit Array3DModel(Materials::MaterialProperty* property = nullptr, - Materials::Material3DArray* value = nullptr, + explicit Array3DModel(const Materials::MaterialProperty* property = nullptr, + std::shared_ptr value = nullptr, QObject* parent = nullptr); ~Array3DModel() override = default; @@ -130,10 +129,10 @@ public: bool removeColumns(int column, int count, const QModelIndex& parent = QModelIndex()) override; private: - Materials::MaterialProperty* _property; - Materials::Material3DArray* _value; + const Materials::MaterialProperty* _property; + std::shared_ptr _value; }; -}// namespace MatGui +} // namespace MatGui -#endif// MATGUI_ARRAYMODEL_H +#endif // MATGUI_ARRAYMODEL_H diff --git a/src/Mod/Material/Gui/CMakeLists.txt b/src/Mod/Material/Gui/CMakeLists.txt index 07e6ba0c0c..78b6fa0638 100644 --- a/src/Mod/Material/Gui/CMakeLists.txt +++ b/src/Mod/Material/Gui/CMakeLists.txt @@ -30,7 +30,7 @@ list(APPEND MatGui_LIBS ${QtConcurrent_LIBRARIES} ) -set (Material_TR_QRC ${CMAKE_CURRENT_BINARY_DIR}/Resources/Material_translation.qrc) +set(Material_TR_QRC ${CMAKE_CURRENT_BINARY_DIR}/Resources/Material_translation.qrc) qt_find_and_add_translation(QM_SRCS "Resources/translations/*_*.ts" ${CMAKE_CURRENT_BINARY_DIR}/Resources/translations) qt_create_resource_file(${Material_TR_QRC} ${QM_SRCS}) @@ -76,6 +76,8 @@ SET(MatGui_SRCS ModelSelect.ui PreCompiled.cpp PreCompiled.h + Workbench.cpp + Workbench.h ) if(FREECAD_USE_PCH) @@ -96,7 +98,6 @@ SET(MatGuiIcon_SVG add_library(MatGui SHARED ${MatGui_SRCS} ${MatGuiIcon_SVG}) target_link_libraries(MatGui ${MatGui_LIBS}) - SET_BIN_DIR(MatGui MatGui /Mod/Material) SET_PYTHON_PREFIX_SUFFIX(MatGui) diff --git a/src/Mod/Material/Gui/Command.cpp b/src/Mod/Material/Gui/Command.cpp index b3d1e3ff4e..33e13c24db 100644 --- a/src/Mod/Material/Gui/Command.cpp +++ b/src/Mod/Material/Gui/Command.cpp @@ -1,25 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ - + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ diff --git a/src/Mod/Material/Gui/DlgSettingsMaterial.cpp b/src/Mod/Material/Gui/DlgSettingsMaterial.cpp index 5c05c62256..5c0436ae68 100644 --- a/src/Mod/Material/Gui/DlgSettingsMaterial.cpp +++ b/src/Mod/Material/Gui/DlgSettingsMaterial.cpp @@ -1,26 +1,23 @@ /*************************************************************************** - * Copyright (c) 2018 FreeCAD Developers * - * Author: Bernd Hahnebach * - * Based on src/Mod/Fem/Gui/DlgSettingsFemElmerImp.cpp * + * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" diff --git a/src/Mod/Material/Gui/DlgSettingsMaterial.h b/src/Mod/Material/Gui/DlgSettingsMaterial.h index b0d62cdb4d..4f62921794 100644 --- a/src/Mod/Material/Gui/DlgSettingsMaterial.h +++ b/src/Mod/Material/Gui/DlgSettingsMaterial.h @@ -1,26 +1,23 @@ -/************************************************************************** - * Copyright (c) 2018 FreeCAD Developers * - * Author: Bernd Hahnebach * - * Based on src/Mod/Fem/Gui/DlgSettingsFemElmer.h * +/*************************************************************************** + * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATGUI_DLGSETTINGSMATERIAL_H #define MATGUI_DLGSETTINGSMATERIAL_H diff --git a/src/Mod/Material/Gui/MaterialDelegate.cpp b/src/Mod/Material/Gui/MaterialDelegate.cpp index 8a3e434c2f..92f96ab7dd 100644 --- a/src/Mod/Material/Gui/MaterialDelegate.cpp +++ b/src/Mod/Material/Gui/MaterialDelegate.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -112,7 +111,7 @@ bool MaterialDelegate::editorEvent(QEvent* event, void MaterialDelegate::showColorModal(QStandardItem* item) { - QColor currentColor;// = d->col; + QColor currentColor; // = d->col; currentColor.setRgba(parseColor(item->text())); QColorDialog* dlg = new QColorDialog(currentColor); @@ -275,7 +274,7 @@ QSize MaterialDelegate::sizeHint(const QStyleOptionViewItem& option, const QMode std::string type = propertyType.toStdString(); if (type == "Color") { - return QSize(75, 23);// Standard QPushButton size + return QSize(75, 23); // Standard QPushButton size } else if (type == "2DArray" || type == "3DArray") { return QSize(23, 23); @@ -421,7 +420,7 @@ QWidget* MaterialDelegate::createWidget(QWidget* parent, Gui::InputField* input = new Gui::InputField(); input->setMinimum(std::numeric_limits::min()); input->setMaximum(std::numeric_limits::max()); - input->setUnitText(propertyUnits);// TODO: Ensure this exists + input->setUnitText(propertyUnits); // TODO: Ensure this exists input->setPrecision(6); input->setQuantityString(propertyValue); diff --git a/src/Mod/Material/Gui/MaterialDelegate.h b/src/Mod/Material/Gui/MaterialDelegate.h index 749feecf42..1febeb11cf 100644 --- a/src/Mod/Material/Gui/MaterialDelegate.h +++ b/src/Mod/Material/Gui/MaterialDelegate.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATGUI_MATERIALDELEGATE_H #define MATGUI_MATERIALDELEGATE_H @@ -46,7 +45,7 @@ class MaterialDelegate: public QStyledItemDelegate Q_OBJECT public: explicit MaterialDelegate(QObject* parent = nullptr); - virtual ~MaterialDelegate() = default; + ~MaterialDelegate() override = default; QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem&, @@ -82,6 +81,6 @@ private: void showArray3DModal(const QString& propertyName, QStandardItem* item); }; -}// namespace MatGui +} // namespace MatGui -#endif// MATGUI_MATERIALDELEGATE_H +#endif // MATGUI_MATERIALDELEGATE_H diff --git a/src/Mod/Material/Gui/MaterialSave.cpp b/src/Mod/Material/Gui/MaterialSave.cpp index 82d0f30c5e..58d610e4e8 100644 --- a/src/Mod/Material/Gui/MaterialSave.cpp +++ b/src/Mod/Material/Gui/MaterialSave.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -56,7 +55,7 @@ MaterialSave::MaterialSave(Materials::Material* material, QWidget* parent) else { ui->editFilename->setText(QString::fromStdString("NewMaterial.FCMat")); } - _filename = QString(ui->editFilename->text());// No filename by default + _filename = QString(ui->editFilename->text()); // No filename by default connect(ui->standardButtons->button(QDialogButtonBox::Ok), &QPushButton::clicked, @@ -97,7 +96,7 @@ void MaterialSave::onOk(bool checked) Base::Console().Log("name '%s'\n", _filename.toStdString().c_str()); if (name != _material->getName()) { _material->setName(name); - _material->setEditStateAlter();// ? Does a name change count? + _material->setEditStateAlter(); // ? Does a name change count? } auto variant = ui->comboLibrary->currentData(); @@ -132,8 +131,8 @@ void MaterialSave::reject() void MaterialSave::setLibraries() { - std::list* libraries = _manager.getMaterialLibraries(); - for (Materials::MaterialLibrary* library : *libraries) { + auto libraries = _manager.getMaterialLibraries(); + for (auto library : *libraries) { if (!library->isReadOnly()) { QVariant libraryVariant; libraryVariant.setValue(*library); @@ -162,10 +161,11 @@ void MaterialSave::addExpanded(QTreeView* tree, QStandardItemModel* parent, QSta tree->setExpanded(child->index(), true); } -void MaterialSave::addMaterials(QStandardItem& parent, - const std::map* modelTree, - const QIcon& folderIcon, - const QIcon& icon) +void MaterialSave::addMaterials( + QStandardItem& parent, + const std::shared_ptr> modelTree, + const QIcon& folderIcon, + const QIcon& icon) { auto tree = ui->treeMaterials; for (auto& mat : *modelTree) { @@ -188,7 +188,7 @@ void MaterialSave::addMaterials(QStandardItem& parent, auto node = new QStandardItem(folderIcon, mat.first); addExpanded(tree, &parent, node); // node->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled); - const std::map* treeMap = nodePtr->getFolder(); + auto treeMap = nodePtr->getFolder(); addMaterials(*node, treeMap, folderIcon, icon); } } @@ -212,8 +212,7 @@ void MaterialSave::showSelectedTree() lib->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled); addExpanded(tree, model, lib); - std::map* modelTree = - _manager.getMaterialTree(library); + auto modelTree = _manager.getMaterialTree(library); addMaterials(*lib, modelTree, folderIcon, icon); } else { @@ -241,7 +240,7 @@ void MaterialSave::onSelectModel(const QItemSelection& selected, const QItemSele // Q_UNUSED(selected); Q_UNUSED(deselected); - _filename = QString(ui->editFilename->text());// No filename by default + _filename = QString(ui->editFilename->text()); // No filename by default QStandardItemModel* model = static_cast(ui->treeMaterials->model()); QModelIndexList indexes = selected.indexes(); if (indexes.count() == 0) { diff --git a/src/Mod/Material/Gui/MaterialSave.h b/src/Mod/Material/Gui/MaterialSave.h index c515e76a08..56dc196cd1 100644 --- a/src/Mod/Material/Gui/MaterialSave.h +++ b/src/Mod/Material/Gui/MaterialSave.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATGUI_MATERIALSAVE_H #define MATGUI_MATERIALSAVE_H @@ -49,10 +48,11 @@ public: void createModelTree(); void addExpanded(QTreeView* tree, QStandardItem* parent, QStandardItem* child); void addExpanded(QTreeView* tree, QStandardItemModel* parent, QStandardItem* child); - void addMaterials(QStandardItem& parent, - const std::map* modelTree, - const QIcon& folderIcon, - const QIcon& icon); + void + addMaterials(QStandardItem& parent, + const std::shared_ptr> modelTree, + const QIcon& folderIcon, + const QIcon& icon); void showSelectedTree(); void onSelectModel(const QItemSelection& selected, const QItemSelection& deselected); @@ -76,6 +76,6 @@ private: QString getPath(const QStandardItem* item) const; }; -}// namespace MatGui +} // namespace MatGui -#endif// MATGUI_MATERIALSAVE_H +#endif // MATGUI_MATERIALSAVE_H diff --git a/src/Mod/Material/Gui/MaterialTreeView.h b/src/Mod/Material/Gui/MaterialTreeView.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Mod/Material/Gui/MaterialsEditor.cpp b/src/Mod/Material/Gui/MaterialsEditor.cpp index 96cba4c2cd..7916805b0c 100644 --- a/src/Mod/Material/Gui/MaterialsEditor.cpp +++ b/src/Mod/Material/Gui/MaterialsEditor.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -378,10 +377,11 @@ void MaterialsEditor::reject() // auto pixmap = icon.pixmap(); // } -void MaterialsEditor::addMaterials(QStandardItem& parent, - const std::map* modelTree, - const QIcon& folderIcon, - const QIcon& icon) +void MaterialsEditor::addMaterials( + QStandardItem& parent, + const std::shared_ptr> modelTree, + const QIcon& folderIcon, + const QIcon& icon) { auto tree = ui->treeMaterials; for (auto& mat : *modelTree) { @@ -404,7 +404,7 @@ void MaterialsEditor::addMaterials(QStandardItem& parent, auto node = new QStandardItem(folderIcon, mat.first); addExpanded(tree, &parent, node); node->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled); - const std::map* treeMap = nodePtr->getFolder(); + auto treeMap = nodePtr->getFolder(); addMaterials(*node, treeMap, folderIcon, icon); } } @@ -549,8 +549,7 @@ void MaterialsEditor::fillMaterialTree() QIcon icon(library->getIconPath()); QIcon folderIcon(QString::fromStdString(":/icons/folder.svg")); - std::map* modelTree = - _materialManager.getMaterialTree(*library); + auto modelTree = _materialManager.getMaterialTree(*library); addMaterials(*lib, modelTree, folderIcon, icon); } } @@ -650,16 +649,16 @@ QString MaterialsEditor::getColorHash(const QString& colorString, int colorRange std::stringstream stream(colorString.toStdString()); char c; - stream >> c;// read "(" + stream >> c; // read "(" double red; stream >> red; - stream >> c;// "," + stream >> c; // "," double green; stream >> green; - stream >> c;// "," + stream >> c; // "," double blue; stream >> blue; - stream >> c;// "," + stream >> c; // "," double alpha = 1.0; if (c == ',') { stream >> alpha; @@ -888,7 +887,7 @@ int MaterialsEditor::confirmSave(QWidget* parent) } int res = QMessageBox::Cancel; - box.adjustSize();// Silence warnings from Qt on Windows + box.adjustSize(); // Silence warnings from Qt on Windows switch (box.exec()) { case QMessageBox::Save: saveMaterial(); diff --git a/src/Mod/Material/Gui/MaterialsEditor.h b/src/Mod/Material/Gui/MaterialsEditor.h index 0776027c5c..6a1169724b 100644 --- a/src/Mod/Material/Gui/MaterialsEditor.h +++ b/src/Mod/Material/Gui/MaterialsEditor.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATGUI_MATERIALSEDITOR_H #define MATGUI_MATERIALSEDITOR_H @@ -116,16 +115,17 @@ private: void createMaterialTree(); void fillMaterialTree(); void refreshMaterialTree(); - void addMaterials(QStandardItem& parent, - const std::map* modelTree, - const QIcon& folderIcon, - const QIcon& icon); + void + addMaterials(QStandardItem& parent, + const std::shared_ptr> modelTree, + const QIcon& folderIcon, + const QIcon& icon); bool isMaterial(const fs::path& p) const { return Materials::MaterialManager::isMaterial(p); } }; -}// namespace MatGui +} // namespace MatGui -#endif// MATGUI_MATERIALSEDITOR_H +#endif // MATGUI_MATERIALSEDITOR_H diff --git a/src/Mod/Material/Gui/ModelSelect.cpp b/src/Mod/Material/Gui/ModelSelect.cpp index 39b6d9c348..2294cc4f8e 100644 --- a/src/Mod/Material/Gui/ModelSelect.cpp +++ b/src/Mod/Material/Gui/ModelSelect.cpp @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ @@ -233,9 +232,10 @@ void ModelSelect::addExpanded(QTreeView* tree, QStandardItemModel* parent, QStan tree->setExpanded(child->index(), true); } -void ModelSelect::addModels(QStandardItem& parent, - const std::map* modelTree, - const QIcon& icon) +void ModelSelect::addModels( + QStandardItem& parent, + const std::shared_ptr> modelTree, + const QIcon& icon) { auto tree = ui->treeModels; for (auto& mod : *modelTree) { @@ -255,7 +255,7 @@ void ModelSelect::addModels(QStandardItem& parent, auto node = new QStandardItem(mod.first); addExpanded(tree, &parent, node); node->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled); - const std::map* treeMap = nodePtr->getFolder(); + auto treeMap = nodePtr->getFolder(); addModels(*node, treeMap, icon); } } @@ -343,16 +343,13 @@ void ModelSelect::fillTree() addExpanded(tree, model, lib); addRecents(lib); - std::list* libraries = getModelManager().getModelLibraries(); - for (Materials::ModelLibrary* library : *libraries) { + auto libraries = getModelManager().getModelLibraries(); + for (auto library : *libraries) { lib = new QStandardItem(library->getName()); lib->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled); addExpanded(tree, model, lib); - // auto path = library->getDirectoryPath(); - std::map* modelTree = - getModelManager().getModelTree(*library, _filter); - // delete modelTree; + auto modelTree = getModelManager().getModelTree(*library, _filter); addModels(*lib, modelTree, QIcon(library->getIconPath())); } } @@ -450,7 +447,7 @@ void ModelSelect::updateMaterialModel(const QString& uuid) updateModelProperties(model); } -void ModelSelect::clearMaterialModel(void) +void ModelSelect::clearMaterialModel() { // Update the general information ui->editName->setText(QString::fromStdString("")); diff --git a/src/Mod/Material/Gui/ModelSelect.h b/src/Mod/Material/Gui/ModelSelect.h index 444f4d3b92..8d74ed7a71 100644 --- a/src/Mod/Material/Gui/ModelSelect.h +++ b/src/Mod/Material/Gui/ModelSelect.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATGUI_MODELSELECT_H #define MATGUI_MODELSELECT_H @@ -78,10 +77,10 @@ private: void addRecents(QStandardItem* parent); void addFavorites(QStandardItem* parent); void addModels(QStandardItem& parent, - const std::map* modelTree, + const std::shared_ptr> modelTree, const QIcon& icon); void updateMaterialModel(const QString& uuid); - void clearMaterialModel(void); + void clearMaterialModel(); void createModelTree(); void refreshModelTree(); void fillTree(); @@ -104,6 +103,6 @@ private: int _recentMax; }; -}// namespace MatGui +} // namespace MatGui -#endif// MATGUI_MODELSELECT_H +#endif // MATGUI_MODELSELECT_H diff --git a/src/Mod/Material/Gui/PreCompiled.cpp b/src/Mod/Material/Gui/PreCompiled.cpp index c2507f9804..48eade6cc8 100644 --- a/src/Mod/Material/Gui/PreCompiled.cpp +++ b/src/Mod/Material/Gui/PreCompiled.cpp @@ -1,24 +1,22 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ - + **************************************************************************/ #include "PreCompiled.h" diff --git a/src/Mod/Material/Gui/PreCompiled.h b/src/Mod/Material/Gui/PreCompiled.h index 8d8aeec82a..6c9e2163ab 100644 --- a/src/Mod/Material/Gui/PreCompiled.h +++ b/src/Mod/Material/Gui/PreCompiled.h @@ -1,37 +1,34 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #ifndef MATGUI_PRECOMPILED_H #define MATGUI_PRECOMPILED_H #include -#include - // point at which warnings of overly long specifiers disabled (needed for VC6) #ifdef _MSC_VER #pragma warning(disable : 4251) #pragma warning(disable : 4503) -#pragma warning(disable : 4786)// specifier longer then 255 chars +#pragma warning(disable : 4786) // specifier longer then 255 chars #pragma warning(disable : 4273) #endif @@ -72,6 +69,6 @@ // # include // #endif -#endif//_PreComp_ +#endif //_PreComp_ -#endif// MATGUI_PRECOMPILED_H +#endif // MATGUI_PRECOMPILED_H diff --git a/src/Mod/Material/Gui/Workbench.cpp b/src/Mod/Material/Gui/Workbench.cpp new file mode 100644 index 0000000000..21c244052f --- /dev/null +++ b/src/Mod/Material/Gui/Workbench.cpp @@ -0,0 +1,34 @@ +/*************************************************************************** + * Copyright (c) 2023 David Carter * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * 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 Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + **************************************************************************/ + + +#include "PreCompiled.h" + +#include "Workbench.h" + +using namespace MatGui; + +/// @namespace MatGui @class Workbench +TYPESYSTEM_SOURCE(MatGui::Workbench, Gui::StdWorkbench) + +Workbench::Workbench() = default; + +Workbench::~Workbench() = default; diff --git a/src/Mod/Material/Gui/Workbench.h b/src/Mod/Material/Gui/Workbench.h new file mode 100644 index 0000000000..d0de5238c6 --- /dev/null +++ b/src/Mod/Material/Gui/Workbench.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (c) 2023 David Carter * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * 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 Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + **************************************************************************/ + + +#ifndef MATGUI_WORKBENCH_H +#define MATGUI_WORKBENCH_H + +#include +#include + +namespace MatGui +{ + +/** + * @author David Carter + */ +class MatGuiExport Workbench: public Gui::StdWorkbench +{ + TYPESYSTEM_HEADER_WITH_OVERRIDE(); + +public: + Workbench(); + ~Workbench() override; +}; + +} // namespace MatGui + + +#endif // MATGUI_WORKBENCH_H diff --git a/src/Mod/Material/InitGui.py b/src/Mod/Material/InitGui.py index 125e63647d..898d045b01 100644 --- a/src/Mod/Material/InitGui.py +++ b/src/Mod/Material/InitGui.py @@ -18,8 +18,30 @@ #* USA * #* * #*************************************************************************** +"""Initialization of the Material Workbench graphical interface.""" -# import FreeCADGui +import FreeCAD as App +import FreeCADGui as Gui +import os -# import Material_rc -# FreeCADGui.addPreferencePage(":/ui/preferences-material.ui","Material") + +class MaterialWorkbench(Gui.Workbench): + """Part workbench object.""" + + def __init__(self): + self.__class__.Icon = os.path.join(App.getResourceDir(), + "Mod", "Material", + "Resources", "icons", + "MaterialWorkbench.svg") + self.__class__.MenuText = "Material" + self.__class__.ToolTip = "Material workbench" + + def Initialize(self): + # load the module + import MatGui + + def GetClassName(self): + return "MatGui::Workbench" + + +Gui.addWorkbench(MaterialWorkbench()) diff --git a/src/Mod/Material/MaterialGlobal.h b/src/Mod/Material/MaterialGlobal.h index c1c4ce429a..24aa8fdfb2 100644 --- a/src/Mod/Material/MaterialGlobal.h +++ b/src/Mod/Material/MaterialGlobal.h @@ -1,24 +1,23 @@ /*************************************************************************** * Copyright (c) 2023 David Carter * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * * * - * This library 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 Library General Public License for more details. * + * 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 this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * - ***************************************************************************/ + **************************************************************************/ #include @@ -28,19 +27,19 @@ // Material #ifndef MaterialsExport #ifdef Material_EXPORTS -# define MaterialsExport FREECAD_DECL_EXPORT +#define MaterialsExport FREECAD_DECL_EXPORT #else -# define MaterialsExport FREECAD_DECL_IMPORT +#define MaterialsExport FREECAD_DECL_IMPORT #endif #endif // MatGui #ifndef MatGuiExport #ifdef MatGui_EXPORTS -# define MatGuiExport FREECAD_DECL_EXPORT +#define MatGuiExport FREECAD_DECL_EXPORT #else -# define MatGuiExport FREECAD_DECL_IMPORT +#define MatGuiExport FREECAD_DECL_IMPORT #endif #endif -#endif //MATERIAL_GLOBAL_H +#endif // MATERIAL_GLOBAL_H diff --git a/src/Mod/Material/materialtools/MaterialModels.py b/src/Mod/Material/materialtools/MaterialModels.py index c7f5380826..2599dd1c2b 100644 --- a/src/Mod/Material/materialtools/MaterialModels.py +++ b/src/Mod/Material/materialtools/MaterialModels.py @@ -1,23 +1,23 @@ # *************************************************************************** -# * Copyright (c) 2023 David Carter * +# * Copyright (c) 2023 David Carter * # * * -# * 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. * +# * This file is part of FreeCAD. * # * * -# * This program 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 Library General Public License for more details. * +# * FreeCAD is free software: you can redistribute it and/or modify it * +# * under the terms of the GNU Lesser General Public License as * +# * published by the Free Software Foundation, either version 2.1 of the * +# * License, or (at your option) any later version. * # * * -# * You should have received a copy of the GNU Library General Public * -# * License along with this program; if not, write to the Free Software * -# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -# * USA * +# * 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 Lesser General Public * +# * License along with FreeCAD. If not, see * +# * . * +# * * +# **************************************************************************/ __title__ = "material model utilities" __author__ = "David Carter" diff --git a/tests/src/Mod/Material/App/Model.cpp b/tests/src/Mod/Material/App/Model.cpp index e77102f6db..9fb76575d8 100644 --- a/tests/src/Mod/Material/App/Model.cpp +++ b/tests/src/Mod/Material/App/Model.cpp @@ -1,4 +1,24 @@ // SPDX-License-Identifier: LGPL-2.1-or-later +/*************************************************************************** + * Copyright (c) 2023 David Carter * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * 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 Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + **************************************************************************/ #include "gtest/gtest.h" @@ -90,10 +110,6 @@ TEST_F(MaterialTest, TestMaterialsWithModel) auto mat = itp->first; EXPECT_NO_THROW(materials->at(mat)); } - - delete materials; - delete materialsComplete; - delete materialsLinearElastic; } TEST_F(MaterialTest, testMaterialByPath)