Merge pull request #10690 from davesrocketshop/material_merge

Material: Material handling enhancements
This commit is contained in:
Chris Hennes
2023-09-27 16:15:06 -05:00
committed by GitHub
402 changed files with 19356 additions and 4377 deletions

View File

@@ -2,9 +2,9 @@ if(MSVC)
add_compile_options(/wd4251)
option(
gtest_force_shared_crt
"Use shared (DLL) run-time lib even when Google Test is built as static lib."
ON)
gtest_force_shared_crt
"Use shared (DLL) run-time lib even when Google Test is built as static lib."
ON)
set(Google_Tests_LIBS
oldnames.lib
@@ -14,8 +14,8 @@ if(MSVC)
optimized msvcprt.lib
)
#Universal C runtime introduced in VS 2015 (cl version 19)
if (NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19"))
# Universal C runtime introduced in VS 2015 (cl version 19)
if(NOT(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19"))
list(APPEND Google_Tests_LIBS
debug vcruntimed.lib
debug ucrtd.lib
@@ -40,32 +40,35 @@ endif()
set(CMAKE_AUTOMOC ON)
function(setup_qt_test)
foreach (_testname ${ARGN})
foreach(_testname ${ARGN})
add_executable(${_testname}_Tests_run ${_testname}.cpp)
add_test(NAME ${_testname}_Tests_run COMMAND ${_testname}_Tests_run)
if (NOT BUILD_DYNAMIC_LINK_PYTHON)
if(NOT BUILD_DYNAMIC_LINK_PYTHON)
list(APPEND ${_testname}_LIBS
${PYTHON_LIBRARIES}
)
endif ()
${PYTHON_LIBRARIES}
)
endif()
target_include_directories(${_testname}_Tests_run PUBLIC
${Python3_INCLUDE_DIRS}
${XercesC_INCLUDE_DIRS}
${QtGui_INCLUDE_DIRS}
${QtWidgets_INCLUDE_DIRS}
${QtTest_INCLUDE_DIRS}
${COIN3D_INCLUDE_DIRS})
${Python3_INCLUDE_DIRS}
${XercesC_INCLUDE_DIRS}
${QtGui_INCLUDE_DIRS}
${QtWidgets_INCLUDE_DIRS}
${QtTest_INCLUDE_DIRS}
${COIN3D_INCLUDE_DIRS})
target_link_libraries(${_testname}_Tests_run
FreeCADApp
FreeCADGui
${QtCore_LIBRARIES}
${QtWidgets_LIBRARIES}
${QtTest_LIBRARIES}
${${_testname}_LIBS})
endforeach ()
FreeCADApp
FreeCADGui
${QtCore_LIBRARIES}
${QtWidgets_LIBRARIES}
${QtTest_LIBRARIES}
${${_testname}_LIBS})
endforeach()
endfunction()
add_executable(Tests_run)
add_executable(Material_tests_run)
add_executable(Mesh_tests_run)
add_executable(Part_tests_run)
add_executable(Points_tests_run)
@@ -82,4 +85,3 @@ target_link_libraries(Tests_run
${Google_Tests_LIBS}
FreeCADApp
)

View File

@@ -1,3 +1,4 @@
add_subdirectory(Material)
add_subdirectory(Mesh)
add_subdirectory(Part)
add_subdirectory(Points)

View File

@@ -0,0 +1,6 @@
target_sources(
Material_tests_run
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Model.cpp
)

View File

@@ -0,0 +1,141 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
* *
* 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 *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#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));
}
}
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

View 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)