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.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
add_subdirectory(Material)
|
||||
add_subdirectory(Mesh)
|
||||
add_subdirectory(Part)
|
||||
add_subdirectory(Points)
|
||||
|
||||
6
tests/src/Mod/Material/App/CMakeLists.txt
Normal file
6
tests/src/Mod/Material/App/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
target_sources(
|
||||
Material_tests_run
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Model.cpp
|
||||
)
|
||||
125
tests/src/Mod/Material/App/Model.cpp
Normal file
125
tests/src/Mod/Material/App/Model.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <Mod/Material/App/PreCompiled.h>
|
||||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <App/Application.h>
|
||||
|
||||
#include <Mod/Material/App/MaterialManager.h>
|
||||
#include <Mod/Material/App/Model.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
class MaterialTest : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
if (App::Application::GetARGC() == 0) {
|
||||
constexpr int argc = 1;
|
||||
std::array<char*, argc> argv {"FreeCAD"};
|
||||
App::Application::Config()["ExeName"] = "FreeCAD";
|
||||
App::Application::init(argc, argv.data());
|
||||
}
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
_modelManager = new Materials::ModelManager();
|
||||
_materialManager = new Materials::MaterialManager();
|
||||
}
|
||||
|
||||
// void TearDown() override {}
|
||||
Materials::ModelManager* _modelManager;
|
||||
Materials::MaterialManager* _materialManager;
|
||||
};
|
||||
|
||||
TEST_F(MaterialTest, TestApplication)
|
||||
{
|
||||
App::Application& application = App::GetApplication();
|
||||
if (&application == nullptr)
|
||||
ADD_FAILURE() << "Application failure\n";
|
||||
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST_F(MaterialTest, TestResources)
|
||||
{
|
||||
try {
|
||||
auto param = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Material/Resources");
|
||||
EXPECT_NE(param, nullptr);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
FAIL() << "Exception: " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MaterialTest, TestModelLoad)
|
||||
{
|
||||
EXPECT_NE(_modelManager, nullptr);
|
||||
|
||||
auto density = _modelManager->getModel(QString::fromStdString("454661e5-265b-4320-8e6f-fcf6223ac3af"));
|
||||
EXPECT_EQ(density.getName(), QString::fromStdString("Density"));
|
||||
EXPECT_EQ(density.getUUID(), QString::fromStdString("454661e5-265b-4320-8e6f-fcf6223ac3af"));
|
||||
|
||||
auto& prop = density[QString::fromStdString("Density")];
|
||||
EXPECT_EQ(prop.getName(), QString::fromStdString("Density"));
|
||||
}
|
||||
|
||||
TEST_F(MaterialTest, TestMaterialsWithModel)
|
||||
{
|
||||
auto materials = _materialManager->materialsWithModel(
|
||||
QString::fromStdString("f6f9e48c-b116-4e82-ad7f-3659a9219c50")); // IsotropicLinearElastic
|
||||
EXPECT_GT(materials->size(), 0);
|
||||
|
||||
auto materialsComplete = _materialManager->materialsWithModelComplete(
|
||||
QString::fromStdString("f6f9e48c-b116-4e82-ad7f-3659a9219c50")); // IsotropicLinearElastic
|
||||
EXPECT_LE(materialsComplete->size(), materials->size());
|
||||
|
||||
auto materialsLinearElastic = _materialManager->materialsWithModel(
|
||||
QString::fromStdString("7b561d1d-fb9b-44f6-9da9-56a4f74d7536")); // LinearElastic
|
||||
|
||||
// All LinearElastic models should be in IsotropicLinearElastic since it is inherited
|
||||
EXPECT_LE(materialsLinearElastic->size(), materials->size());
|
||||
for (auto itp = materialsLinearElastic->begin(); itp != materialsLinearElastic->end(); itp++) {
|
||||
auto mat = itp->first;
|
||||
EXPECT_NO_THROW(materials->at(mat));
|
||||
}
|
||||
|
||||
delete materials;
|
||||
delete materialsComplete;
|
||||
delete materialsLinearElastic;
|
||||
}
|
||||
|
||||
TEST_F(MaterialTest, testMaterialByPath)
|
||||
{
|
||||
auto& steel = _materialManager->getMaterialByPath(
|
||||
QString::fromStdString("StandardMaterial/Metal/Steel/CalculiX-Steel.FCMat"),
|
||||
QString::fromStdString("System"));
|
||||
EXPECT_NE(&steel, nullptr);
|
||||
EXPECT_EQ(steel.getName(), QString::fromStdString("CalculiX-Steel"));
|
||||
EXPECT_EQ(steel.getUUID(), QString::fromStdString("92589471-a6cb-4bbc-b748-d425a17dea7d"));
|
||||
|
||||
// The same but with a leading '/'
|
||||
auto& steel2 = _materialManager->getMaterialByPath(
|
||||
QString::fromStdString("/System/StandardMaterial/Metal/Steel/CalculiX-Steel.FCMat"),
|
||||
QString::fromStdString("System"));
|
||||
EXPECT_NE(&steel2, nullptr);
|
||||
EXPECT_EQ(steel2.getName(), QString::fromStdString("CalculiX-Steel"));
|
||||
EXPECT_EQ(steel2.getUUID(), QString::fromStdString("92589471-a6cb-4bbc-b748-d425a17dea7d"));
|
||||
|
||||
// Same with the library name as a prefix
|
||||
auto& steel3 = _materialManager->getMaterialByPath(
|
||||
QString::fromStdString("StandardMaterial/Metal/Steel/CalculiX-Steel.FCMat"),
|
||||
QString::fromStdString("System"));
|
||||
EXPECT_NE(&steel3, nullptr);
|
||||
EXPECT_EQ(steel3.getName(), QString::fromStdString("CalculiX-Steel"));
|
||||
EXPECT_EQ(steel3.getUUID(), QString::fromStdString("92589471-a6cb-4bbc-b748-d425a17dea7d"));
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
15
tests/src/Mod/Material/CMakeLists.txt
Normal file
15
tests/src/Mod/Material/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
target_include_directories(Material_tests_run PUBLIC
|
||||
${EIGEN3_INCLUDE_DIR}
|
||||
${OCC_INCLUDE_DIR}
|
||||
${Python3_INCLUDE_DIRS}
|
||||
${XercesC_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(Material_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Material
|
||||
)
|
||||
|
||||
add_subdirectory(App)
|
||||
Reference in New Issue
Block a user