diff --git a/src/App/Application.cpp b/src/App/Application.cpp index c02e2ebbad..87b5c14e2f 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -99,6 +99,7 @@ #include "InventorObject.h" #include "Link.h" #include "LinkBaseExtensionPy.h" +#include "VarSet.h" #include "MaterialObject.h" #include "MeasureDistance.h" #include "Origin.h" @@ -2102,6 +2103,7 @@ void Application::initTypes() App::LinkElementPython ::init(); App::LinkGroup ::init(); App::LinkGroupPython ::init(); + App::VarSet ::init(); // Expression classes App::Expression ::init(); diff --git a/src/App/CMakeLists.txt b/src/App/CMakeLists.txt index 4e0f0abf19..ff9ac1dee3 100644 --- a/src/App/CMakeLists.txt +++ b/src/App/CMakeLists.txt @@ -171,6 +171,7 @@ SET(Document_CPP_SRCS TextDocument.cpp Link.cpp LinkBaseExtensionPyImp.cpp + VarSet.cpp License.h ) @@ -213,6 +214,7 @@ SET(Document_HPP_SRCS MaterialObject.h MergeDocuments.h TextDocument.h + VarSet.h Link.h ) SET(Document_SRCS diff --git a/src/App/VarSet.cpp b/src/App/VarSet.cpp new file mode 100644 index 0000000000..9e9fdc9305 --- /dev/null +++ b/src/App/VarSet.cpp @@ -0,0 +1,36 @@ +/**************************************************************************** + * Copyright (c) 2024 Ondsel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * 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. * + * * + * 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. * + * * + * 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 * + * * + ****************************************************************************/ + +#include + +#include "VarSet.h" +#include "DocumentObject.h" + +using namespace App; + +PROPERTY_SOURCE(App::VarSet, App::DocumentObject) + +const char* VarSet::getViewProviderName() const +{ + return "Gui::ViewProviderVarSet"; +} + diff --git a/src/App/VarSet.h b/src/App/VarSet.h new file mode 100644 index 0000000000..9d55ca680a --- /dev/null +++ b/src/App/VarSet.h @@ -0,0 +1,46 @@ +/**************************************************************************** + * Copyright (c) 2024 Ondsel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * 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. * + * * + * 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. * + * * + * 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 * + * * + ****************************************************************************/ + +#ifndef APP_VARSET_H +#define APP_VARSET_H + +#include "DocumentObject.h" + +namespace App +{ + +/** A DocumentObject class with the purpose to store variables +*/ +class AppExport VarSet : public App::DocumentObject +{ + PROPERTY_HEADER_WITH_OVERRIDE(App::VarSet); + +public: + + VarSet() = default; + ~VarSet() override = default; + + const char* getViewProviderName() const override; +}; + +} +#endif diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 4061ae6e3b..f5118aae54 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -123,6 +123,7 @@ #include "ViewProviderPythonFeature.h" #include "ViewProviderTextDocument.h" #include "ViewProviderVRMLObject.h" +#include "ViewProviderVarSet.h" #include "WaitCursor.h" #include "Workbench.h" #include "WorkbenchManager.h" @@ -2277,6 +2278,7 @@ void Application::initTypes() Gui::LinkView ::init(); Gui::ViewProviderLink ::init(); Gui::ViewProviderLinkPython ::init(); + Gui::ViewProviderVarSet ::init(); Gui::AxisOrigin ::init(); // Workbench diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index e109492e96..cd4d3c21cf 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -923,6 +923,7 @@ SET(Viewprovider_CPP_SRCS ViewProviderLink.cpp LinkViewPyImp.cpp ViewProviderLinkPyImp.cpp + ViewProviderVarSet.cpp AxisOriginPyImp.cpp AxisOrigin.cpp ) @@ -957,6 +958,7 @@ SET(Viewprovider_SRCS ViewProviderMaterialObject.h ViewProviderTextDocument.h ViewProviderLink.h + ViewProviderVarSet.h AxisOrigin.h ) SOURCE_GROUP("View3D\\Viewprovider" FILES ${Viewprovider_SRCS}) diff --git a/src/Gui/Icons/VarSet.svg b/src/Gui/Icons/VarSet.svg new file mode 100644 index 0000000000..9c5448eeb2 --- /dev/null +++ b/src/Gui/Icons/VarSet.svg @@ -0,0 +1,239 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + 2005-10-15 + + + Andreas Nilsson + + + + + edit + copy + + + + + + Jakub Steiner + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Gui/Icons/resource.qrc b/src/Gui/Icons/resource.qrc index 10d04069cd..9e562cf8bb 100644 --- a/src/Gui/Icons/resource.qrc +++ b/src/Gui/Icons/resource.qrc @@ -267,6 +267,7 @@ image-open.svg image-plane.svg image-scaling.svg + VarSet.svg diff --git a/src/Gui/ViewProviderVarSet.cpp b/src/Gui/ViewProviderVarSet.cpp new file mode 100644 index 0000000000..bf6611548f --- /dev/null +++ b/src/Gui/ViewProviderVarSet.cpp @@ -0,0 +1,36 @@ +/**************************************************************************** + * Copyright (c) 2024 Ondsel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * 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. * + * * + * 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. * + * * + * 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 * + * * + ****************************************************************************/ + +#include "PreCompiled.h" + +#include "ViewProviderVarSet.h" + +using namespace Gui; + +PROPERTY_SOURCE(Gui::ViewProviderVarSet, Gui::ViewProviderDocumentObject) + +ViewProviderVarSet::ViewProviderVarSet() +{ + sPixmap = "VarSet"; +} + + diff --git a/src/Gui/ViewProviderVarSet.h b/src/Gui/ViewProviderVarSet.h new file mode 100644 index 0000000000..3e0bc8cc86 --- /dev/null +++ b/src/Gui/ViewProviderVarSet.h @@ -0,0 +1,44 @@ +/**************************************************************************** + * Copyright (c) 2024 Ondsel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * 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. * + * * + * 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. * + * * + * 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 * + * * + ****************************************************************************/ + +#ifndef GUI_ViewProviderVarSet_H +#define GUI_ViewProviderVarSet_H + +#include "ViewProviderDocumentObject.h" + +namespace Gui { + +/** View provider associated with an App::VarSet + */ +class GuiExport ViewProviderVarSet : public ViewProviderDocumentObject { + PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderVarSet); +public: + ViewProviderVarSet(); + ~ViewProviderVarSet() override = default; + + bool isShow() const override { return true; } +}; + +} + +#endif + diff --git a/tests/src/App/CMakeLists.txt b/tests/src/App/CMakeLists.txt index c54c1d1343..05b489ba92 100644 --- a/tests/src/App/CMakeLists.txt +++ b/tests/src/App/CMakeLists.txt @@ -16,4 +16,5 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/Property.cpp ${CMAKE_CURRENT_SOURCE_DIR}/PropertyExpressionEngine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/StringHasher.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/VarSet.cpp ) diff --git a/tests/src/App/VarSet.cpp b/tests/src/App/VarSet.cpp new file mode 100644 index 0000000000..db5eead3d7 --- /dev/null +++ b/tests/src/App/VarSet.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** + * Copyright (c) 2024 Ondsel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * 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. * + * * + * 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. * + * * + * 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 * + * * + ****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include +#include "App/Document.h" +#include +#include + +using ::testing::NotNull; + +// NOLINTBEGIN(readability-magic-numbers) + +class VarSet: public ::testing::Test +{ +protected: + static void SetUpTestSuite() + { + tests::initApplication(); + } + + void SetUp() override + { + _docName = App::GetApplication().getUniqueDocumentName("test"); + _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); + } + + void TearDown() override + { + App::GetApplication().closeDocument(_docName.c_str()); + } + + App::Document* doc() + { + return _doc; + } + +private: + std::string _docName; + App::Document* _doc {}; +}; + +// Tests whether we can create a VarSet +TEST_F(VarSet, createVarSet) +{ + // Arrange + const char* nameVarSet = "VarSet"; + + // Act + doc()->addObject("App::VarSet", nameVarSet); + auto varSet = dynamic_cast(doc()->getObject(nameVarSet)); + + // Assert + EXPECT_THAT(varSet, NotNull()); +} + +// Tests whether we can add a property to a VarSet +TEST_F(VarSet, addProperty) +{ + // Arrange + const char* nameVarSet = "VarSet001"; + const long VALUE = 123; + + doc()->addObject("App::VarSet", nameVarSet); + auto varSet = dynamic_cast(doc()->getObject(nameVarSet)); + + // Act + auto prop = dynamic_cast( + varSet->addDynamicProperty("App::PropertyInteger", "Variable", "Variables")); + prop->setValue(VALUE); + + // Assert + EXPECT_EQ(prop->getValue(), VALUE); +} + +// NOLINTEND(readability-magic-numbers)