[Core] Managing Custom Data Elements: VarSet (#12135)
* [Core] Add a basic VarSet document object * [Core] Add basic tests for VarSets * Core: Replace the VarSet icon with an outlined one
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
36
src/App/VarSet.cpp
Normal file
36
src/App/VarSet.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2024 Ondsel <development@ondsel.com> *
|
||||
* *
|
||||
* 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 <iostream>
|
||||
|
||||
#include "VarSet.h"
|
||||
#include "DocumentObject.h"
|
||||
|
||||
using namespace App;
|
||||
|
||||
PROPERTY_SOURCE(App::VarSet, App::DocumentObject)
|
||||
|
||||
const char* VarSet::getViewProviderName() const
|
||||
{
|
||||
return "Gui::ViewProviderVarSet";
|
||||
}
|
||||
|
||||
46
src/App/VarSet.h
Normal file
46
src/App/VarSet.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2024 Ondsel <development@ondsel.com> *
|
||||
* *
|
||||
* 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
|
||||
@@ -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
|
||||
|
||||
@@ -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})
|
||||
|
||||
239
src/Gui/Icons/VarSet.svg
Normal file
239
src/Gui/Icons/VarSet.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 13 KiB |
@@ -267,6 +267,7 @@
|
||||
<file>image-open.svg</file>
|
||||
<file>image-plane.svg</file>
|
||||
<file>image-scaling.svg</file>
|
||||
<file>VarSet.svg</file>
|
||||
</qresource>
|
||||
<!-- Demonstrating support for an embedded icon theme -->
|
||||
<!-- See also http://permalink.gmane.org/gmane.comp.lib.qt.general/26374 -->
|
||||
|
||||
36
src/Gui/ViewProviderVarSet.cpp
Normal file
36
src/Gui/ViewProviderVarSet.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2024 Ondsel <development@ondsel.com> *
|
||||
* *
|
||||
* 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";
|
||||
}
|
||||
|
||||
|
||||
44
src/Gui/ViewProviderVarSet.h
Normal file
44
src/Gui/ViewProviderVarSet.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2024 Ondsel <development@ondsel.com> *
|
||||
* *
|
||||
* 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
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
97
tests/src/App/VarSet.cpp
Normal file
97
tests/src/App/VarSet.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2024 Ondsel <development@ondsel.com> *
|
||||
* *
|
||||
* 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 <App/Application.h>
|
||||
#include "App/Document.h"
|
||||
#include <App/VarSet.h>
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
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<App::VarSet*>(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<App::VarSet*>(doc()->getObject(nameVarSet));
|
||||
|
||||
// Act
|
||||
auto prop = dynamic_cast<App::PropertyInteger*>(
|
||||
varSet->addDynamicProperty("App::PropertyInteger", "Variable", "Variables"));
|
||||
prop->setValue(VALUE);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(prop->getValue(), VALUE);
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers)
|
||||
Reference in New Issue
Block a user