FreeCAD WebAssembly development snapshot
Some checks failed
FreeCAD master CI / Prepare (push) Has been cancelled
FreeCAD master CI / Pixi (push) Has been cancelled
FreeCAD master CI / Ubuntu (push) Has been cancelled
FreeCAD master CI / Windows (push) Has been cancelled
FreeCAD master CI / Lint (push) Has been cancelled
FreeCAD master CI / WrapUp (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Stale Issues / stale (push) Has been cancelled
Some checks failed
FreeCAD master CI / Prepare (push) Has been cancelled
FreeCAD master CI / Pixi (push) Has been cancelled
FreeCAD master CI / Ubuntu (push) Has been cancelled
FreeCAD master CI / Windows (push) Has been cancelled
FreeCAD master CI / Lint (push) Has been cancelled
FreeCAD master CI / WrapUp (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Stale Issues / stale (push) Has been cancelled
This commit is contained in:
55
tests/src/Mod/Assembly/App/AssemblyObject.cpp
Normal file
55
tests/src/Mod/Assembly/App/AssemblyObject.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <FCConfig.h>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/Expression.h>
|
||||
#include <App/ObjectIdentifier.h>
|
||||
#include <Mod/Assembly/App/AssemblyObject.h>
|
||||
#include <Mod/Assembly/App/JointGroup.h>
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
class AssemblyObjectTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
auto _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
_assemblyObj = _doc->addObject<Assembly::AssemblyObject>();
|
||||
_jointGroupObj = _assemblyObj->addObject<Assembly::JointGroup>("jointGroupTest");
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
Assembly::AssemblyObject* getObject()
|
||||
{
|
||||
return _assemblyObj;
|
||||
}
|
||||
|
||||
private:
|
||||
// TODO: use shared_ptr or something else here?
|
||||
Assembly::AssemblyObject* _assemblyObj;
|
||||
Assembly::JointGroup* _jointGroupObj;
|
||||
std::string _docName;
|
||||
};
|
||||
|
||||
TEST_F(AssemblyObjectTest, createAssemblyObject) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
|
||||
// Assert
|
||||
}
|
||||
5
tests/src/Mod/Assembly/App/CMakeLists.txt
Normal file
5
tests/src/Mod/Assembly/App/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(Assembly_tests_run
|
||||
AssemblyObject.cpp
|
||||
)
|
||||
15
tests/src/Mod/Assembly/CMakeLists.txt
Normal file
15
tests/src/Mod/Assembly/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
if (NOT FREECAD_USE_EXTERNAL_ONDSELSOLVER)
|
||||
target_include_directories(Assembly_tests_run PUBLIC
|
||||
${CMAKE_SOURCE_DIR}/src/3rdParty/OndselSolver
|
||||
)
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Assembly_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Assembly
|
||||
)
|
||||
35
tests/src/Mod/CMakeLists.txt
Normal file
35
tests/src/Mod/CMakeLists.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
if(BUILD_ASSEMBLY)
|
||||
add_subdirectory(Assembly)
|
||||
endif(BUILD_ASSEMBLY)
|
||||
if(BUILD_MATERIAL)
|
||||
add_subdirectory(Material)
|
||||
endif(BUILD_MATERIAL)
|
||||
if(BUILD_MEASURE)
|
||||
add_subdirectory(Measure)
|
||||
endif(BUILD_MEASURE)
|
||||
if(BUILD_MESH)
|
||||
add_subdirectory(Mesh)
|
||||
endif(BUILD_MESH)
|
||||
if(BUILD_MESH_PART)
|
||||
add_subdirectory(MeshPart)
|
||||
endif(BUILD_MESH_PART)
|
||||
if(BUILD_PART)
|
||||
add_subdirectory(Part)
|
||||
endif(BUILD_PART)
|
||||
if(BUILD_PART_DESIGN)
|
||||
add_subdirectory(PartDesign)
|
||||
endif(BUILD_PART_DESIGN)
|
||||
if(BUILD_POINTS)
|
||||
add_subdirectory(Points)
|
||||
endif(BUILD_POINTS)
|
||||
if(BUILD_SKETCHER)
|
||||
add_subdirectory(Sketcher)
|
||||
endif(BUILD_SKETCHER)
|
||||
if(BUILD_SPREADSHEET)
|
||||
add_subdirectory(Spreadsheet)
|
||||
endif()
|
||||
if(BUILD_START)
|
||||
add_subdirectory(Start)
|
||||
endif()
|
||||
37
tests/src/Mod/Material/App/CMakeLists.txt
Normal file
37
tests/src/Mod/Material/App/CMakeLists.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(Material_tests_run
|
||||
TestMaterialCards.cpp
|
||||
TestMaterialFilter.cpp
|
||||
TestMaterialProperties.cpp
|
||||
TestMaterials.cpp
|
||||
TestMaterialValue.cpp
|
||||
TestModel.cpp
|
||||
TestModelProperties.cpp
|
||||
)
|
||||
|
||||
target_include_directories(Material_tests_run SYSTEM PUBLIC
|
||||
${QtCore_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(MaterialTestData_Files
|
||||
Materials/TestAcrylicLegacy.FCMat
|
||||
Materials/TestAluminumAppearance.FCMat
|
||||
Materials/TestAluminumMixed.FCMat
|
||||
Materials/TestAluminumPhysical.FCMat
|
||||
Materials/TestBrassAppearance.FCMat
|
||||
)
|
||||
|
||||
ADD_CUSTOM_TARGET(MaterialTestData ALL
|
||||
SOURCES ${MaterialTestData_Files}
|
||||
)
|
||||
|
||||
fc_target_copy_resource(MaterialTestData
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR}/tests
|
||||
${MaterialTestData_Files})
|
||||
|
||||
# INSTALL(
|
||||
# FILES ${MaterialTest_Files}
|
||||
# DESTINATION Mod/Material/materialtests
|
||||
# )
|
||||
13
tests/src/Mod/Material/App/Materials/TestAcrylicLegacy.FCMat
Normal file
13
tests/src/Mod/Material/App/Materials/TestAcrylicLegacy.FCMat
Normal file
@@ -0,0 +1,13 @@
|
||||
; Acrylic
|
||||
; Automatically generated by the Rocket Workbench
|
||||
; information about the content of such cards can be found on the wiki:
|
||||
; https://www.freecad.org/wiki/Material
|
||||
|
||||
[General]
|
||||
Name = TestAcrylicLegacy
|
||||
Description = Acrylic
|
||||
KindOfMaterial = Solid
|
||||
|
||||
[Mechanical]
|
||||
Density = 1190.0 kg/m^3
|
||||
Hardness = 10
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
# File created by ConvertFCMat.py
|
||||
General:
|
||||
UUID: "3c6d0407-66b3-48ea-a2e8-ee843edf0311"
|
||||
Author: "David Carter"
|
||||
License: "GPL-2.0-or-later"
|
||||
Name: "TestAluminumAppearance"
|
||||
Description: "Defines the Aluminum appearance properties"
|
||||
AppearanceModels:
|
||||
BasicRendering:
|
||||
UUID: 'f006c7e4-35b7-43d5-bbf9-c5d572309e6e'
|
||||
AmbientColor: "(0.3000, 0.3000, 0.3000, 1.0)"
|
||||
DiffuseColor: "(0.3000, 0.3000, 0.3000, 1.0)"
|
||||
EmissiveColor: "(0.0000, 0.0000, 0.0000, 1.0)"
|
||||
Shininess: "0.0900"
|
||||
SpecularColor: "(0.3000, 0.3000, 0.3000, 1.0)"
|
||||
Transparency: "0.0"
|
||||
33
tests/src/Mod/Material/App/Materials/TestAluminumMixed.FCMat
Normal file
33
tests/src/Mod/Material/App/Materials/TestAluminumMixed.FCMat
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
# File created by ConvertFCMat.py
|
||||
General:
|
||||
UUID: "5f546608-fcbb-40db-98d7-d8e104eb33ce"
|
||||
Author: "M. Münch"
|
||||
License: "LGPL-2.0-or-later"
|
||||
Name: "TestAluminumMixed"
|
||||
Inherits:
|
||||
Aluminum:
|
||||
UUID: "3c6d0407-66b3-48ea-a2e8-ee843edf0311"
|
||||
Models:
|
||||
Father:
|
||||
UUID: '9cdda8b6-b606-4778-8f13-3934d8668e67'
|
||||
Father: "Metal"
|
||||
MaterialStandard:
|
||||
UUID: '1e2c0088-904a-4537-925f-64064c07d700'
|
||||
KindOfMaterial: "Aluminium"
|
||||
MaterialNumber: "3.3535.26"
|
||||
StandardCode: "DIN 1725"
|
||||
LinearElastic:
|
||||
UUID: '7b561d1d-fb9b-44f6-9da9-56a4f74d7536'
|
||||
Density: "2700 kg/m^3"
|
||||
PoissonRatio: "0.3"
|
||||
ShearModulus: "27000 MPa"
|
||||
UltimateStrain: "5"
|
||||
UltimateTensileStrength: "250 MPa"
|
||||
YieldStrength: "180 MPa"
|
||||
YoungsModulus: "70000 MPa"
|
||||
Thermal:
|
||||
UUID: '9959d007-a970-4ea7-bae4-3eb1b8b883c7'
|
||||
SpecificHeat: "900 J/kg/K"
|
||||
ThermalConductivity: "150 W/m/K"
|
||||
ThermalExpansionCoefficient: "23 µm/m/K"
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
# File created by ConvertFCMat.py
|
||||
General:
|
||||
UUID: "a8e60089-550d-4370-8e7e-1734db12a3a9"
|
||||
Author: "M. Münch"
|
||||
License: "LGPL-2.0-or-later"
|
||||
Name: "TestAluminumPhysical"
|
||||
Models:
|
||||
Father:
|
||||
UUID: '9cdda8b6-b606-4778-8f13-3934d8668e67'
|
||||
Father: "Metal"
|
||||
MaterialStandard:
|
||||
UUID: '1e2c0088-904a-4537-925f-64064c07d700'
|
||||
KindOfMaterial: "Aluminium"
|
||||
MaterialNumber: "3.3535.26"
|
||||
StandardCode: "DIN 1725"
|
||||
LinearElastic:
|
||||
UUID: '7b561d1d-fb9b-44f6-9da9-56a4f74d7536'
|
||||
Density: "2700 kg/m^3"
|
||||
PoissonRatio: "0.3"
|
||||
ShearModulus: "27000 MPa"
|
||||
# UltimateStrain: "5"
|
||||
UltimateTensileStrength: "250 MPa"
|
||||
YieldStrength: "180 MPa"
|
||||
YoungsModulus: "70000 MPa"
|
||||
Thermal:
|
||||
UUID: '9959d007-a970-4ea7-bae4-3eb1b8b883c7'
|
||||
SpecificHeat: "900 J/kg/K"
|
||||
ThermalConductivity: "150 W/m/K"
|
||||
ThermalExpansionCoefficient: "23 µm/m/K"
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
# File created by ConvertFCMat.py
|
||||
General:
|
||||
UUID: "fff3d5c8-98c3-4ee2-8fe5-7e17403c48fcc"
|
||||
Author: "David Carter"
|
||||
License: "GPL-2.0-or-later"
|
||||
Name: "TestBrassAppearance"
|
||||
Description: "Defines the Brass appearance properties"
|
||||
AppearanceModels:
|
||||
BasicRendering:
|
||||
UUID: 'f006c7e4-35b7-43d5-bbf9-c5d572309e6e'
|
||||
AmbientColor: "(0.3294, 0.2235, 0.0275, 1.0)"
|
||||
DiffuseColor: "(0.7804, 0.5686, 0.1137, 1.0)"
|
||||
EmissiveColor: "(0.0000, 0.0000, 0.0000, 1.0)"
|
||||
Shininess: "0.2179"
|
||||
SpecularColor: "(0.9922, 0.9412, 0.8078, 1.0)"
|
||||
Transparency: "0.0"
|
||||
199
tests/src/Mod/Material/App/TestMaterialCards.cpp
Normal file
199
tests/src/Mod/Material/App/TestMaterialCards.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
// 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 <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include <Gui/MetaTypes.h>
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include <Mod/Material/App/MaterialLibrary.h>
|
||||
#include <Mod/Material/App/MaterialManager.h>
|
||||
#include <Mod/Material/App/MaterialValue.h>
|
||||
#include <Mod/Material/App/Model.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
#include <Mod/Material/App/ModelUuids.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
class TestMaterialCards : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
if (App::Application::GetARGC() == 0) {
|
||||
tests::initApplication();
|
||||
}
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
// Create a temporary library
|
||||
QString libPath = QDir::tempPath() + QStringLiteral("/TestMaterialCards");
|
||||
QDir libDir(libPath);
|
||||
libDir.removeRecursively(); // Clear old run data
|
||||
libDir.mkdir(libPath);
|
||||
_library = std::make_shared<Materials::MaterialLibraryLocal>(QStringLiteral("Testing"),
|
||||
libPath,
|
||||
QStringLiteral(":/icons/preferences-general.svg"),
|
||||
false);
|
||||
_modelManager = &(Materials::ModelManager::getManager());
|
||||
_materialManager = &(Materials::MaterialManager::getManager());
|
||||
|
||||
_testMaterialUUID = QStringLiteral("c6c64159-19c1-40b5-859c-10561f20f979");
|
||||
}
|
||||
|
||||
// void TearDown() override {}
|
||||
Materials::ModelManager* _modelManager;
|
||||
Materials::MaterialManager* _materialManager;
|
||||
std::shared_ptr<Materials::MaterialLibraryLocal> _library;
|
||||
QString _testMaterialUUID;
|
||||
};
|
||||
|
||||
TEST_F(TestMaterialCards, TestCopy)
|
||||
{
|
||||
ASSERT_NE(_modelManager, nullptr);
|
||||
ASSERT_TRUE(_library);
|
||||
// FAIL() << "Test library " << _library->getDirectoryPath().toStdString() << "\n";
|
||||
|
||||
auto testMaterial = _materialManager->getMaterial(_testMaterialUUID);
|
||||
auto newMaterial = std::make_shared<Materials::Material>(*testMaterial);
|
||||
|
||||
EXPECT_EQ(testMaterial->getUUID(), _testMaterialUUID);
|
||||
EXPECT_EQ(newMaterial->getUUID(), _testMaterialUUID);
|
||||
|
||||
// Save the material
|
||||
_materialManager->saveMaterial(_library,
|
||||
newMaterial,
|
||||
QStringLiteral("/Test Material2.FCMat"),
|
||||
false, // overwrite
|
||||
true, // saveAsCopy
|
||||
false); // saveInherited
|
||||
EXPECT_EQ(newMaterial->getUUID(), _testMaterialUUID);
|
||||
EXPECT_EQ(newMaterial->getName(), QStringLiteral("Test Material2"));
|
||||
|
||||
// Save it when it already exists throwing an error
|
||||
EXPECT_THROW(_materialManager->saveMaterial(_library,
|
||||
newMaterial,
|
||||
QStringLiteral("/Test Material2.FCMat"),
|
||||
false, // overwrite
|
||||
true, // saveAsCopy
|
||||
false) // saveInherited
|
||||
, Materials::MaterialExists);
|
||||
EXPECT_EQ(newMaterial->getUUID(), _testMaterialUUID);
|
||||
EXPECT_EQ(newMaterial->getName(), QStringLiteral("Test Material2"));
|
||||
|
||||
// Overwrite the existing file
|
||||
_materialManager->saveMaterial(_library,
|
||||
newMaterial,
|
||||
QStringLiteral("/Test Material2.FCMat"),
|
||||
true, // overwrite
|
||||
true, // saveAsCopy
|
||||
false);// saveInherited
|
||||
EXPECT_EQ(newMaterial->getUUID(), _testMaterialUUID);
|
||||
EXPECT_EQ(newMaterial->getName(), QStringLiteral("Test Material2"));
|
||||
|
||||
// Save to a new file, inheritance mode
|
||||
_materialManager->saveMaterial(_library,
|
||||
newMaterial,
|
||||
QStringLiteral("/Test Material3.FCMat"),
|
||||
false, // overwrite
|
||||
true, // saveAsCopy
|
||||
true);// saveInherited
|
||||
EXPECT_EQ(newMaterial->getUUID(), _testMaterialUUID);
|
||||
EXPECT_EQ(newMaterial->getName(), QStringLiteral("Test Material3"));
|
||||
|
||||
// Save to a new file, inheritance mode. no copy
|
||||
_materialManager->saveMaterial(_library,
|
||||
newMaterial,
|
||||
QStringLiteral("/Test Material4.FCMat"),
|
||||
false, // overwrite
|
||||
false, // saveAsCopy
|
||||
true);// saveInherited
|
||||
EXPECT_NE(newMaterial->getUUID(), _testMaterialUUID);
|
||||
EXPECT_EQ(newMaterial->getName(), QStringLiteral("Test Material4"));
|
||||
QString uuid1 = newMaterial->getUUID();
|
||||
|
||||
// Save to a new file, inheritance mode, testing overwrite, new copy
|
||||
_materialManager->saveMaterial(_library,
|
||||
newMaterial,
|
||||
QStringLiteral("/Test Material5.FCMat"),
|
||||
false, // overwrite
|
||||
true, // saveAsCopy
|
||||
true);// saveInherited
|
||||
EXPECT_EQ(newMaterial->getUUID(), uuid1);
|
||||
EXPECT_EQ(newMaterial->getName(), QStringLiteral("Test Material5"));
|
||||
|
||||
_materialManager->saveMaterial(_library,
|
||||
newMaterial,
|
||||
QStringLiteral("/Test Material5.FCMat"),
|
||||
true, // overwrite
|
||||
true, // saveAsCopy
|
||||
true);// saveInherited
|
||||
EXPECT_EQ(newMaterial->getUUID(), uuid1);
|
||||
EXPECT_EQ(newMaterial->getName(), QStringLiteral("Test Material5"));
|
||||
|
||||
// Save to a new file, inheritance mode, testing overwrite as no copy, new copy
|
||||
_materialManager->saveMaterial(_library,
|
||||
newMaterial,
|
||||
QStringLiteral("/Test Material6.FCMat"),
|
||||
false, // overwrite
|
||||
true, // saveAsCopy
|
||||
true);// saveInherited
|
||||
EXPECT_EQ(newMaterial->getUUID(), uuid1);
|
||||
EXPECT_EQ(newMaterial->getName(), QStringLiteral("Test Material6"));
|
||||
|
||||
_materialManager->saveMaterial(_library,
|
||||
newMaterial,
|
||||
QStringLiteral("/Test Material6.FCMat"),
|
||||
true, // overwrite
|
||||
false, // saveAsCopy
|
||||
true);// saveInherited
|
||||
EXPECT_EQ(newMaterial->getUUID(), uuid1);
|
||||
EXPECT_EQ(newMaterial->getName(), QStringLiteral("Test Material6"));
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialCards, TestColumns)
|
||||
{
|
||||
ASSERT_NE(_modelManager, nullptr);
|
||||
ASSERT_TRUE(_library);
|
||||
|
||||
auto testMaterial = _materialManager->getMaterial(_testMaterialUUID);
|
||||
|
||||
EXPECT_TRUE(testMaterial->hasPhysicalProperty(QStringLiteral("TestArray2D")));
|
||||
auto array2d = testMaterial->getPhysicalProperty(QStringLiteral("TestArray2D"))->getMaterialValue();
|
||||
EXPECT_TRUE(array2d);
|
||||
EXPECT_EQ(dynamic_cast<Materials::Array2D &>(*array2d).columns(), 2);
|
||||
|
||||
EXPECT_TRUE(testMaterial->hasPhysicalProperty(QStringLiteral("TestArray2D3Column")));
|
||||
auto array2d3Column = testMaterial->getPhysicalProperty(QStringLiteral("TestArray2D3Column"))->getMaterialValue();
|
||||
EXPECT_TRUE(array2d3Column);
|
||||
EXPECT_EQ(dynamic_cast<Materials::Array2D &>(*array2d3Column).columns(), 3);
|
||||
|
||||
EXPECT_TRUE(testMaterial->hasPhysicalProperty(QStringLiteral("TestArray3D")));
|
||||
auto array3d = testMaterial->getPhysicalProperty(QStringLiteral("TestArray3D"))->getMaterialValue();
|
||||
EXPECT_TRUE(array3d);
|
||||
EXPECT_EQ(dynamic_cast<Materials::Array3D &>(*array3d).columns(), 2);
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
261
tests/src/Mod/Material/App/TestMaterialFilter.cpp
Normal file
261
tests/src/Mod/Material/App/TestMaterialFilter.cpp
Normal file
@@ -0,0 +1,261 @@
|
||||
// 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 <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include <Gui/MetaTypes.h>
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include <Mod/Material/App/MaterialLibrary.h>
|
||||
#include <Mod/Material/App/MaterialManager.h>
|
||||
#include <Mod/Material/App/MaterialValue.h>
|
||||
#include <Mod/Material/App/Model.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
#include <Mod/Material/App/ModelUuids.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
class TestMaterialFilter : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
_modelManager = &(Materials::ModelManager::getManager());
|
||||
_materialManager = &(Materials::MaterialManager::getManager());
|
||||
|
||||
// Use our test files as a custom directory
|
||||
ParameterGrp::handle hGrp =
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Material/Resources");
|
||||
|
||||
_customDir = hGrp->GetASCII("CustomMaterialsDir", "");
|
||||
_useBuiltInDir = hGrp->GetBool("UseBuiltInMaterials", true);
|
||||
_useWorkbenchDir = hGrp->GetBool("UseMaterialsFromWorkbenches", true);
|
||||
_useUserDir = hGrp->GetBool("UseMaterialsFromConfigDir", true);
|
||||
_useCustomDir = hGrp->GetBool("UseMaterialsFromCustomDir", false);
|
||||
|
||||
std::string testPath = App::Application::getHomePath() + "/tests/Materials/";
|
||||
hGrp->SetASCII("CustomMaterialsDir", testPath);
|
||||
hGrp->SetBool("UseBuiltInMaterials", false);
|
||||
hGrp->SetBool("UseMaterialsFromWorkbenches", false);
|
||||
hGrp->SetBool("UseMaterialsFromConfigDir", false);
|
||||
hGrp->SetBool("UseMaterialsFromCustomDir", true);
|
||||
|
||||
auto param = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Material/Editor");
|
||||
param->SetBool("ShowFavorites", true);
|
||||
param->SetBool("ShowRecent", true);
|
||||
param->SetBool("ShowEmptyFolders", false);
|
||||
param->SetBool("ShowEmptyLibraries", true);
|
||||
param->SetBool("ShowLegacy", false);
|
||||
|
||||
_materialManager->refresh();
|
||||
|
||||
_library = _materialManager->getLibrary(QStringLiteral("Custom"));
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
ParameterGrp::handle hGrp =
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Material/Resources");
|
||||
|
||||
// Restore preferences
|
||||
hGrp->SetASCII("CustomMaterialsDir", _customDir);
|
||||
hGrp->SetBool("UseBuiltInMaterials", _useBuiltInDir);
|
||||
hGrp->SetBool("UseMaterialsFromWorkbenches", _useWorkbenchDir);
|
||||
hGrp->SetBool("UseMaterialsFromConfigDir", _useUserDir);
|
||||
hGrp->SetBool("UseMaterialsFromCustomDir", _useCustomDir);
|
||||
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Material/Editor");
|
||||
hGrp->SetBool("ShowFavorites", _includeFavorites);
|
||||
hGrp->SetBool("ShowRecent", _includeRecent);
|
||||
hGrp->SetBool("ShowEmptyFolders", _includeFolders);
|
||||
hGrp->SetBool("ShowEmptyLibraries", _includeLibraries);
|
||||
hGrp->SetBool("ShowLegacy", _includeLegacy);
|
||||
|
||||
_materialManager->refresh();
|
||||
}
|
||||
|
||||
Materials::ModelManager* _modelManager {};
|
||||
Materials::MaterialManager* _materialManager {};
|
||||
std::shared_ptr<Materials::MaterialLibrary> _library;
|
||||
QString _testMaterialUUID;
|
||||
|
||||
std::string _customDir;
|
||||
bool _useBuiltInDir {};
|
||||
bool _useWorkbenchDir {};
|
||||
bool _useUserDir {};
|
||||
bool _useCustomDir {};
|
||||
|
||||
bool _includeFavorites {};
|
||||
bool _includeRecent {};
|
||||
bool _includeFolders {};
|
||||
bool _includeLibraries {};
|
||||
bool _includeLegacy {};
|
||||
|
||||
const char* UUIDAcrylicLegacy = ""; // This can't be known until it is loaded
|
||||
const char* UUIDAluminumAppearance = "3c6d0407-66b3-48ea-a2e8-ee843edf0311";
|
||||
const char* UUIDAluminumMixed = "5f546608-fcbb-40db-98d7-d8e104eb33ce";
|
||||
const char* UUIDAluminumPhysical = "a8e60089-550d-4370-8e7e-1734db12a3a9";
|
||||
const char* UUIDBrassAppearance = "fff3d5c8-98c3-4ee2-8fe5-7e17403c48fcc";
|
||||
};
|
||||
|
||||
TEST_F(TestMaterialFilter, TestFilters)
|
||||
{
|
||||
ASSERT_NE(_modelManager, nullptr);
|
||||
|
||||
// First check that our materials are loading
|
||||
auto material = _materialManager->getMaterial(QString::fromLatin1(UUIDAluminumAppearance));
|
||||
ASSERT_TRUE(material);
|
||||
ASSERT_EQ(material->getName(), QStringLiteral("TestAluminumAppearance"));
|
||||
ASSERT_EQ(material->getUUID(), QString::fromLatin1(UUIDAluminumAppearance));
|
||||
|
||||
material = _materialManager->getMaterial(QString::fromLatin1(UUIDAluminumMixed));
|
||||
ASSERT_TRUE(material);
|
||||
ASSERT_EQ(material->getName(), QStringLiteral("TestAluminumMixed"));
|
||||
ASSERT_EQ(material->getUUID(), QString::fromLatin1(UUIDAluminumMixed));
|
||||
|
||||
material = _materialManager->getMaterial(QString::fromLatin1(UUIDAluminumPhysical));
|
||||
ASSERT_TRUE(material);
|
||||
ASSERT_EQ(material->getName(), QStringLiteral("TestAluminumPhysical"));
|
||||
ASSERT_EQ(material->getUUID(), QString::fromLatin1(UUIDAluminumPhysical));
|
||||
|
||||
material = _materialManager->getMaterial(QString::fromLatin1(UUIDBrassAppearance));
|
||||
ASSERT_TRUE(material);
|
||||
ASSERT_EQ(material->getName(), QStringLiteral("TestBrassAppearance"));
|
||||
ASSERT_EQ(material->getUUID(), QString::fromLatin1(UUIDBrassAppearance));
|
||||
|
||||
material = _materialManager->getMaterialByPath(QStringLiteral("TestAcrylicLegacy.FCMat"),
|
||||
QStringLiteral("Custom"));
|
||||
ASSERT_TRUE(material);
|
||||
ASSERT_EQ(material->getName(), QStringLiteral("TestAcrylicLegacy"));
|
||||
ASSERT_EQ(material->getUUID().size(), 36); // We don't know the UUID
|
||||
|
||||
// Create an empty filter
|
||||
Materials::MaterialFilter filter;
|
||||
Materials::MaterialFilterOptions options;
|
||||
ASSERT_TRUE(_library);
|
||||
|
||||
auto tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 4);
|
||||
|
||||
options.setIncludeLegacy(true);
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 5);
|
||||
|
||||
// Create a basic rendering filter
|
||||
filter.setName(QStringLiteral("Basic Appearance"));
|
||||
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Basic);
|
||||
options.setIncludeLegacy(false);
|
||||
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 3);
|
||||
|
||||
options.setIncludeLegacy(true);
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 3);
|
||||
|
||||
// Create an advanced rendering filter
|
||||
filter.clear();
|
||||
filter.setName(QStringLiteral("Advanced Appearance"));
|
||||
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Advanced);
|
||||
options.setIncludeLegacy(false);
|
||||
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 0);
|
||||
|
||||
options.setIncludeLegacy(true);
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 0);
|
||||
|
||||
// Create a Density filter
|
||||
filter.clear();
|
||||
filter.setName(QStringLiteral("Density"));
|
||||
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Density);
|
||||
options.setIncludeLegacy(false);
|
||||
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 2);
|
||||
|
||||
options.setIncludeLegacy(true);
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 3);
|
||||
|
||||
// Create a Hardness filter
|
||||
filter.clear();
|
||||
filter.setName(QStringLiteral("Hardness"));
|
||||
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Hardness);
|
||||
options.setIncludeLegacy(false);
|
||||
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 0);
|
||||
|
||||
options.setIncludeLegacy(true);
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 0);
|
||||
|
||||
// Create a Density and Basic Rendering filter
|
||||
filter.clear();
|
||||
filter.setName(QStringLiteral("Density and Basic Rendering"));
|
||||
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Basic);
|
||||
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Density);
|
||||
options.setIncludeLegacy(false);
|
||||
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 1);
|
||||
|
||||
options.setIncludeLegacy(true);
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 1);
|
||||
|
||||
// Create a Linear Elastic filter
|
||||
filter.clear();
|
||||
filter.setName(QStringLiteral("Linear Elastic"));
|
||||
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic);
|
||||
options.setIncludeLegacy(false);
|
||||
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 0);
|
||||
|
||||
options.setIncludeLegacy(true);
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 0);
|
||||
|
||||
filter.clear();
|
||||
filter.setName(QStringLiteral("Linear Elastic"));
|
||||
filter.addRequired(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic);
|
||||
options.setIncludeLegacy(false);
|
||||
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 2);
|
||||
|
||||
options.setIncludeLegacy(true);
|
||||
tree = _materialManager->getMaterialTree(*_library, filter, options);
|
||||
ASSERT_EQ(tree->size(), 2);
|
||||
}
|
||||
236
tests/src/Mod/Material/App/TestMaterialProperties.cpp
Normal file
236
tests/src/Mod/Material/App/TestMaterialProperties.cpp
Normal file
@@ -0,0 +1,236 @@
|
||||
// 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 <memory>
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Gui/MetaTypes.h>
|
||||
|
||||
#include <Mod/Material/App/MaterialManager.h>
|
||||
#include <Mod/Material/App/Model.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
#include <Mod/Material/App/ModelUuids.h>
|
||||
|
||||
class TestMaterialProperties: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
// 2D Properties
|
||||
modelProp = Materials::ModelProperty(
|
||||
QStringLiteral("Density"), // Name
|
||||
QStringLiteral("D"), // Header
|
||||
QStringLiteral("2DArray"), // Type
|
||||
QStringLiteral(""), // Units
|
||||
QStringLiteral(""), // URL
|
||||
QStringLiteral("desc")
|
||||
); // Description
|
||||
modelProp1 = Materials::ModelProperty(
|
||||
QStringLiteral("Temperature"),
|
||||
QStringLiteral("T"),
|
||||
QStringLiteral("Quantity"),
|
||||
QStringLiteral("C"),
|
||||
QStringLiteral(""),
|
||||
QStringLiteral("desc1")
|
||||
);
|
||||
modelProp2 = Materials::ModelProperty(
|
||||
QStringLiteral("Density"),
|
||||
QStringLiteral("D"),
|
||||
QStringLiteral("Quantity"),
|
||||
QStringLiteral("kg/m^3"),
|
||||
QStringLiteral("https://en.wikipedia.org/wiki/Density"),
|
||||
QStringLiteral("desc2")
|
||||
);
|
||||
|
||||
modelProp.addColumn(modelProp1);
|
||||
modelProp.addColumn(modelProp2);
|
||||
|
||||
// 3D properties
|
||||
model3DProp = Materials::ModelProperty(
|
||||
QStringLiteral("StressStrain"), // Name
|
||||
QStringLiteral("Stress / Strain"), // Header
|
||||
QStringLiteral("3DArray"), // Type
|
||||
QStringLiteral(""), // Units
|
||||
QStringLiteral(""), // URL
|
||||
QStringLiteral(
|
||||
"3 Dimensional array showing stress and strain as a function of "
|
||||
"temperature"
|
||||
)
|
||||
); // Description
|
||||
model3DProp1 = Materials::ModelProperty(
|
||||
QStringLiteral("Temperature"),
|
||||
QStringLiteral("T"),
|
||||
QStringLiteral("Quantity"),
|
||||
QStringLiteral("C"),
|
||||
QStringLiteral(""),
|
||||
QStringLiteral("desc1")
|
||||
);
|
||||
model3DProp2 = Materials::ModelProperty(
|
||||
QStringLiteral("Stress"),
|
||||
QStringLiteral("Stress"),
|
||||
QStringLiteral("Quantity"),
|
||||
QStringLiteral("MPa"),
|
||||
QStringLiteral(""),
|
||||
QStringLiteral("desc2")
|
||||
);
|
||||
model3DProp3 = Materials::ModelProperty(
|
||||
QStringLiteral("Strain"),
|
||||
QStringLiteral("Strain"),
|
||||
QStringLiteral("Quantity"),
|
||||
QStringLiteral("MPa"),
|
||||
QStringLiteral(""),
|
||||
QStringLiteral("desc3")
|
||||
);
|
||||
|
||||
model3DProp.addColumn(model3DProp1);
|
||||
model3DProp.addColumn(model3DProp2);
|
||||
model3DProp.addColumn(model3DProp3);
|
||||
}
|
||||
|
||||
// void TearDown() override {}
|
||||
|
||||
Materials::ModelProperty modelProp;
|
||||
Materials::ModelProperty modelProp1;
|
||||
Materials::ModelProperty modelProp2;
|
||||
Materials::ModelProperty model3DProp;
|
||||
Materials::ModelProperty model3DProp1;
|
||||
Materials::ModelProperty model3DProp2;
|
||||
Materials::ModelProperty model3DProp3;
|
||||
};
|
||||
|
||||
TEST_F(TestMaterialProperties, TestEmpty)
|
||||
{
|
||||
Materials::MaterialProperty prop;
|
||||
EXPECT_EQ(prop.getType(), Materials::MaterialValue::None);
|
||||
EXPECT_TRUE(prop.isNull());
|
||||
auto variant = prop.getValue();
|
||||
EXPECT_TRUE(variant.isNull());
|
||||
EXPECT_FALSE(variant.canConvert<QString>());
|
||||
EXPECT_TRUE(variant.toString().isNull());
|
||||
EXPECT_TRUE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialProperties, TestSingle)
|
||||
{
|
||||
Materials::MaterialProperty prop(modelProp1, QStringLiteral("sampleUUID"));
|
||||
EXPECT_EQ(prop.getType(), Materials::MaterialValue::Quantity);
|
||||
EXPECT_EQ(prop.getModelUUID(), QStringLiteral("sampleUUID"));
|
||||
EXPECT_TRUE(prop.isNull());
|
||||
auto variant = prop.getValue();
|
||||
EXPECT_TRUE(variant.canConvert<Base::Quantity>());
|
||||
EXPECT_FALSE(variant.value<Base::Quantity>().isValid());
|
||||
EXPECT_FALSE(variant.canConvert<QString>());
|
||||
EXPECT_TRUE(variant.toString().isNull());
|
||||
EXPECT_TRUE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 0);
|
||||
}
|
||||
|
||||
void check2DArray(Materials::MaterialProperty& prop)
|
||||
{
|
||||
EXPECT_EQ(prop.getType(), Materials::MaterialValue::Array2D);
|
||||
EXPECT_EQ(prop.getModelUUID(), QStringLiteral("sampleUUID"));
|
||||
EXPECT_TRUE(prop.isNull());
|
||||
auto array = std::static_pointer_cast<Materials::Array2D>(prop.getMaterialValue());
|
||||
EXPECT_EQ(array->rows(), 0);
|
||||
auto variant = prop.getValue(); // Throw an error?
|
||||
EXPECT_FALSE(variant.canConvert<QString>());
|
||||
EXPECT_TRUE(variant.toString().isNull());
|
||||
EXPECT_TRUE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 0);
|
||||
|
||||
// Check the columns
|
||||
EXPECT_EQ(prop.columns(), 2);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialProperties, Test2DArray)
|
||||
{
|
||||
Materials::MaterialProperty prop(modelProp, QStringLiteral("sampleUUID"));
|
||||
check2DArray(prop);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialProperties, Test2DArrayCopy)
|
||||
{
|
||||
Materials::MaterialProperty propBase(modelProp, QStringLiteral("sampleUUID"));
|
||||
Materials::MaterialProperty prop(propBase);
|
||||
check2DArray(prop);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialProperties, Test2DArrayAssignment)
|
||||
{
|
||||
Materials::MaterialProperty propBase(modelProp, QStringLiteral("sampleUUID"));
|
||||
Materials::MaterialProperty prop;
|
||||
|
||||
prop = propBase;
|
||||
check2DArray(prop);
|
||||
}
|
||||
|
||||
void check3DArray(Materials::MaterialProperty& prop)
|
||||
{
|
||||
EXPECT_EQ(prop.getType(), Materials::MaterialValue::Array3D);
|
||||
EXPECT_EQ(prop.getModelUUID(), QStringLiteral("sampleUUID"));
|
||||
EXPECT_TRUE(prop.isNull());
|
||||
auto array = std::static_pointer_cast<Materials::Array3D>(prop.getMaterialValue());
|
||||
EXPECT_EQ(array->depth(), 0);
|
||||
auto variant = prop.getValue(); // Throw an error?
|
||||
EXPECT_FALSE(variant.canConvert<QString>());
|
||||
EXPECT_TRUE(variant.toString().isNull());
|
||||
EXPECT_TRUE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 0);
|
||||
|
||||
// Check the columns
|
||||
EXPECT_EQ(prop.columns(), 3);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialProperties, Test3DArray)
|
||||
{
|
||||
Materials::MaterialProperty prop(model3DProp, QStringLiteral("sampleUUID"));
|
||||
check3DArray(prop);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialProperties, Test3DArrayCopy)
|
||||
{
|
||||
Materials::MaterialProperty propBase(model3DProp, QStringLiteral("sampleUUID"));
|
||||
Materials::MaterialProperty prop(propBase);
|
||||
check3DArray(prop);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialProperties, Test3DArrayAssignment)
|
||||
{
|
||||
Materials::MaterialProperty propBase(model3DProp, QStringLiteral("sampleUUID"));
|
||||
Materials::MaterialProperty prop;
|
||||
|
||||
prop = propBase;
|
||||
check3DArray(prop);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
|
||||
// clang-format on
|
||||
281
tests/src/Mod/Material/App/TestMaterialValue.cpp
Normal file
281
tests/src/Mod/Material/App/TestMaterialValue.cpp
Normal file
@@ -0,0 +1,281 @@
|
||||
// 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 <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Gui/MetaTypes.h>
|
||||
|
||||
#include <Mod/Material/App/MaterialManager.h>
|
||||
#include <Mod/Material/App/Model.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
#include <Mod/Material/App/ModelUuids.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
class TestMaterialValue : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TestMaterialValue, TestNoneType)
|
||||
{
|
||||
auto mat1 = Materials::MaterialValue();
|
||||
EXPECT_EQ(mat1.getType(), Materials::MaterialValue::None);
|
||||
EXPECT_TRUE(mat1.isNull());
|
||||
auto variant = mat1.getValue();
|
||||
EXPECT_TRUE(variant.isNull());
|
||||
EXPECT_FALSE(variant.canConvert<QString>());
|
||||
EXPECT_TRUE(variant.toString().isNull());
|
||||
EXPECT_TRUE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialValue, TestStringType)
|
||||
{
|
||||
auto mat1 = Materials::MaterialValue(Materials::MaterialValue::String);
|
||||
EXPECT_EQ(mat1.getType(), Materials::MaterialValue::String);
|
||||
EXPECT_TRUE(mat1.isNull());
|
||||
auto variant = mat1.getValue();
|
||||
EXPECT_TRUE(variant.isNull());
|
||||
EXPECT_TRUE(variant.canConvert<QString>());
|
||||
EXPECT_TRUE(variant.toString().isNull());
|
||||
EXPECT_TRUE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialValue, TestBooleanType)
|
||||
{
|
||||
auto mat1 = Materials::MaterialValue(Materials::MaterialValue::Boolean);
|
||||
EXPECT_EQ(mat1.getType(), Materials::MaterialValue::Boolean);
|
||||
EXPECT_TRUE(mat1.isNull());
|
||||
auto variant = mat1.getValue();
|
||||
EXPECT_TRUE(variant.isNull());
|
||||
EXPECT_TRUE(variant.canConvert<bool>());
|
||||
EXPECT_FALSE(variant.toString().isNull());
|
||||
EXPECT_FALSE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 5);
|
||||
EXPECT_EQ(variant.toString(), QStringLiteral("false"));
|
||||
EXPECT_EQ(variant.toBool(), false);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialValue, TestIntegerType)
|
||||
{
|
||||
auto mat1 = Materials::MaterialValue(Materials::MaterialValue::Integer);
|
||||
EXPECT_EQ(mat1.getType(), Materials::MaterialValue::Integer);
|
||||
EXPECT_TRUE(mat1.isNull());
|
||||
auto variant = mat1.getValue();
|
||||
EXPECT_TRUE(variant.isNull());
|
||||
EXPECT_TRUE(variant.canConvert<int>());
|
||||
EXPECT_FALSE(variant.toString().isNull());
|
||||
EXPECT_FALSE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 1);
|
||||
EXPECT_EQ(variant.toString(), QStringLiteral("0"));
|
||||
EXPECT_EQ(variant.toInt(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialValue, TestFloatType)
|
||||
{
|
||||
auto mat1 = Materials::MaterialValue(Materials::MaterialValue::Float);
|
||||
EXPECT_EQ(mat1.getType(), Materials::MaterialValue::Float);
|
||||
EXPECT_TRUE(mat1.isNull());
|
||||
auto variant = mat1.getValue();
|
||||
EXPECT_TRUE(variant.isNull());
|
||||
EXPECT_TRUE(variant.canConvert<float>());
|
||||
EXPECT_FALSE(variant.toString().isNull());
|
||||
EXPECT_FALSE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 1);
|
||||
EXPECT_EQ(variant.toString(), QStringLiteral("0"));
|
||||
EXPECT_EQ(variant.toFloat(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialValue, TestQuantityType)
|
||||
{
|
||||
auto mat1 = Materials::MaterialValue(Materials::MaterialValue::Quantity);
|
||||
EXPECT_EQ(mat1.getType(), Materials::MaterialValue::Quantity);
|
||||
EXPECT_TRUE(mat1.isNull());
|
||||
|
||||
auto variant = mat1.getValue();
|
||||
EXPECT_FALSE(variant.isNull());
|
||||
EXPECT_TRUE(variant.canConvert<Base::Quantity>());
|
||||
EXPECT_TRUE(variant.toString().isNull());
|
||||
EXPECT_TRUE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 0);
|
||||
auto quantity = variant.value<Base::Quantity>();
|
||||
EXPECT_FALSE(quantity.isValid());
|
||||
EXPECT_EQ(quantity.getUserString(), "nan");
|
||||
EXPECT_TRUE(std::isnan(quantity.getValue()));
|
||||
|
||||
// Test a copy
|
||||
auto mat2 = Materials::MaterialValue(mat1);
|
||||
EXPECT_EQ(mat2.getType(), Materials::MaterialValue::Quantity);
|
||||
EXPECT_TRUE(mat2.isNull());
|
||||
|
||||
variant = mat2.getValue();
|
||||
EXPECT_FALSE(variant.isNull());
|
||||
EXPECT_TRUE(variant.canConvert<Base::Quantity>());
|
||||
EXPECT_TRUE(variant.toString().isNull());
|
||||
EXPECT_TRUE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 0);
|
||||
quantity = variant.value<Base::Quantity>();
|
||||
EXPECT_FALSE(quantity.isValid());
|
||||
EXPECT_EQ(quantity.getUserString(), "nan");
|
||||
EXPECT_TRUE(std::isnan(quantity.getValue()));
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialValue, TestListType)
|
||||
{
|
||||
auto mat1 = Materials::MaterialValue(Materials::MaterialValue::List);
|
||||
EXPECT_EQ(mat1.getType(), Materials::MaterialValue::List);
|
||||
EXPECT_TRUE(mat1.isNull());
|
||||
auto variant = mat1.getValue();
|
||||
EXPECT_TRUE(variant.value<QList<QVariant>>().isEmpty());
|
||||
EXPECT_EQ(variant.value<QList<QVariant>>().size(), 0);
|
||||
EXPECT_FALSE(variant.isNull());
|
||||
EXPECT_FALSE(variant.canConvert<QVariant>());
|
||||
EXPECT_TRUE(variant.toString().isNull());
|
||||
EXPECT_TRUE(variant.toString().isEmpty());
|
||||
EXPECT_EQ(variant.toString().size(), 0);
|
||||
auto list = mat1.getList();
|
||||
EXPECT_TRUE(list.isEmpty());
|
||||
EXPECT_EQ(list.size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialValue, TestArray2DType)
|
||||
{
|
||||
EXPECT_THROW(auto mat1 = Materials::MaterialValue(Materials::MaterialValue::Array2D), Materials::InvalidMaterialType);
|
||||
|
||||
auto mat2 = Materials::Array2D();
|
||||
EXPECT_EQ(mat2.getType(), Materials::MaterialValue::Array2D);
|
||||
EXPECT_TRUE(mat2.isNull());
|
||||
EXPECT_EQ(mat2.rows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterialValue, TestArray3DType)
|
||||
{
|
||||
EXPECT_THROW(auto mat1 = Materials::MaterialValue(Materials::MaterialValue::Array3D), Materials::InvalidMaterialType);
|
||||
|
||||
auto mat2 = Materials::Array3D();
|
||||
mat2.setColumns(2);
|
||||
EXPECT_EQ(mat2.getType(), Materials::MaterialValue::Array3D);
|
||||
EXPECT_TRUE(mat2.isNull());
|
||||
|
||||
EXPECT_EQ(mat2.depth(), 0);
|
||||
EXPECT_EQ(mat2.rows(), 0);
|
||||
EXPECT_EQ(mat2.rows(0), 0);
|
||||
EXPECT_THROW(mat2.rows(1), Materials::InvalidIndex);
|
||||
|
||||
Base::Quantity quantity;
|
||||
quantity.setInvalid();
|
||||
|
||||
EXPECT_EQ(mat2.addDepth(0, quantity), 0);
|
||||
EXPECT_EQ(mat2.depth(), 1);
|
||||
EXPECT_EQ(mat2.rows(0), 0);
|
||||
EXPECT_THROW(mat2.rows(1), Materials::InvalidIndex);
|
||||
|
||||
EXPECT_EQ(mat2.addDepth(quantity), 1);
|
||||
EXPECT_EQ(mat2.depth(), 2);
|
||||
EXPECT_EQ(mat2.rows(1), 0);
|
||||
|
||||
EXPECT_THROW(mat2.addDepth(99, quantity), Materials::InvalidIndex);
|
||||
EXPECT_EQ(mat2.addDepth(2, quantity), 2);
|
||||
EXPECT_EQ(mat2.depth(), 3);
|
||||
EXPECT_EQ(mat2.rows(2), 0);
|
||||
|
||||
// Add rows
|
||||
auto row = std::make_shared<QList<Base::Quantity>>();
|
||||
row->push_back(quantity);
|
||||
row->push_back(quantity);
|
||||
|
||||
EXPECT_EQ(mat2.rows(0), 0);
|
||||
EXPECT_EQ(mat2.rows(1), 0);
|
||||
EXPECT_EQ(mat2.rows(2), 0);
|
||||
|
||||
mat2.addRow(0, row);
|
||||
EXPECT_EQ(mat2.rows(0), 1);
|
||||
EXPECT_EQ(mat2.rows(1), 0);
|
||||
EXPECT_EQ(mat2.rows(2), 0);
|
||||
|
||||
mat2.addRow(1, row);
|
||||
EXPECT_EQ(mat2.rows(0), 1);
|
||||
EXPECT_EQ(mat2.rows(1), 1);
|
||||
EXPECT_EQ(mat2.rows(2), 0);
|
||||
|
||||
mat2.addRow(2, row);
|
||||
EXPECT_EQ(mat2.rows(0), 1);
|
||||
EXPECT_EQ(mat2.rows(1), 1);
|
||||
EXPECT_EQ(mat2.rows(2), 1);
|
||||
|
||||
EXPECT_EQ(mat2.currentDepth(), 0);
|
||||
mat2.addRow(row);
|
||||
EXPECT_EQ(mat2.rows(0), 2);
|
||||
EXPECT_EQ(mat2.rows(1), 1);
|
||||
EXPECT_EQ(mat2.rows(2), 1);
|
||||
|
||||
mat2.setCurrentDepth(2);
|
||||
EXPECT_EQ(mat2.currentDepth(), 2);
|
||||
mat2.addRow(row);
|
||||
EXPECT_EQ(mat2.rows(0), 2);
|
||||
EXPECT_EQ(mat2.rows(1), 1);
|
||||
EXPECT_EQ(mat2.rows(2), 2);
|
||||
|
||||
quantity = Base::Quantity::parse("32 C");
|
||||
mat2.setDepthValue(quantity);
|
||||
EXPECT_FALSE(mat2.getDepthValue(0).isValid());
|
||||
EXPECT_FALSE(mat2.getDepthValue(1).isValid());
|
||||
EXPECT_TRUE(mat2.getDepthValue(2).isValid());
|
||||
EXPECT_EQ(mat2.getDepthValue(2), Base::Quantity::parse("32 C"));
|
||||
|
||||
mat2.setDepthValue(0, Base::Quantity::parse("9.8 m/s/s"));
|
||||
EXPECT_TRUE(mat2.getDepthValue(0).isValid());
|
||||
EXPECT_FALSE(mat2.getDepthValue(1).isValid());
|
||||
EXPECT_TRUE(mat2.getDepthValue(2).isValid());
|
||||
EXPECT_EQ(mat2.getDepthValue(0), Base::Quantity::parse("9.8 m/s/s"));
|
||||
EXPECT_EQ(mat2.getDepthValue(2), Base::Quantity::parse("32 C"));
|
||||
|
||||
mat2.setDepthValue(1, Base::Quantity::parse("120 MPa"));
|
||||
EXPECT_TRUE(mat2.getDepthValue(0).isValid());
|
||||
EXPECT_TRUE(mat2.getDepthValue(1).isValid());
|
||||
EXPECT_TRUE(mat2.getDepthValue(2).isValid());
|
||||
EXPECT_EQ(mat2.getDepthValue(0), Base::Quantity::parse("9.8 m/s/s"));
|
||||
EXPECT_EQ(mat2.getDepthValue(1), Base::Quantity::parse("120 MPa"));
|
||||
EXPECT_EQ(mat2.getDepthValue(2), Base::Quantity::parse("32 C"));
|
||||
|
||||
// Rows are currently empty
|
||||
EXPECT_THROW(mat2.getValue(2, 0), Materials::InvalidIndex);
|
||||
EXPECT_NO_THROW(mat2.getValue(0, 0));
|
||||
EXPECT_FALSE(mat2.getValue(0, 0).isValid());
|
||||
EXPECT_FALSE(mat2.getValue(0, 1).isValid());
|
||||
|
||||
// set to a valid quantity
|
||||
mat2.setValue(0, 0, Base::Quantity::parse("120 MPa"));
|
||||
EXPECT_TRUE(mat2.getValue(0, 0).isValid());
|
||||
mat2.setValue(0, 1, Base::Quantity::parse("9.8 m/s/s"));
|
||||
EXPECT_TRUE(mat2.getValue(0, 1).isValid());
|
||||
EXPECT_THROW(mat2.setValue(0, 2, Base::Quantity::parse("32 C")), Materials::InvalidIndex);
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
377
tests/src/Mod/Material/App/TestMaterials.cpp
Normal file
377
tests/src/Mod/Material/App/TestMaterials.cpp
Normal file
@@ -0,0 +1,377 @@
|
||||
// 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 <QLocale>
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include <Gui/MetaTypes.h>
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include <Mod/Material/App/MaterialManager.h>
|
||||
#include <Mod/Material/App/MaterialValue.h>
|
||||
#include <Mod/Material/App/Model.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
#include <Mod/Material/App/ModelUuids.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(disable : 4834)
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
|
||||
class TestMaterial : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
if (App::Application::GetARGC() == 0) {
|
||||
tests::initApplication();
|
||||
}
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
Base::Interpreter().runString("import Part");
|
||||
_modelManager = &(Materials::ModelManager::getManager());
|
||||
_materialManager = &(Materials::MaterialManager::getManager());
|
||||
}
|
||||
|
||||
// void TearDown() override {}
|
||||
Materials::ModelManager* _modelManager;
|
||||
Materials::MaterialManager* _materialManager;
|
||||
};
|
||||
|
||||
TEST_F(TestMaterial, TestInstallation)
|
||||
{
|
||||
ASSERT_NE(_modelManager, nullptr);
|
||||
|
||||
// We should have loaded at least the system library
|
||||
auto libraries = _materialManager->getLibraries();
|
||||
ASSERT_GT(libraries->size(), 0);
|
||||
|
||||
// We should have at least one material
|
||||
auto materials = _materialManager->getLocalMaterials();
|
||||
ASSERT_GT(materials->size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterial, TestMaterialsWithModel)
|
||||
{
|
||||
ASSERT_NE(_materialManager, nullptr);
|
||||
|
||||
auto materials = _materialManager->materialsWithModel(
|
||||
QStringLiteral("f6f9e48c-b116-4e82-ad7f-3659a9219c50")); // IsotropicLinearElastic
|
||||
EXPECT_GT(materials->size(), 0);
|
||||
|
||||
auto materialsComplete = _materialManager->materialsWithModelComplete(
|
||||
QStringLiteral("f6f9e48c-b116-4e82-ad7f-3659a9219c50")); // IsotropicLinearElastic
|
||||
EXPECT_LE(materialsComplete->size(), materials->size());
|
||||
|
||||
auto materialsLinearElastic = _materialManager->materialsWithModel(
|
||||
QStringLiteral("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) {
|
||||
auto mat = itp.first;
|
||||
EXPECT_NO_THROW(materials->at(mat));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TestMaterial, TestMaterialByPath)
|
||||
{
|
||||
ASSERT_NE(_materialManager, nullptr);
|
||||
|
||||
auto steel = _materialManager->getMaterialByPath(
|
||||
QStringLiteral("Standard/Metal/Steel/CalculiX-Steel.FCMat"),
|
||||
QStringLiteral("System"));
|
||||
EXPECT_NE(&steel, nullptr);
|
||||
EXPECT_EQ(steel->getName(), QStringLiteral("CalculiX-Steel"));
|
||||
EXPECT_EQ(steel->getUUID(), QStringLiteral("92589471-a6cb-4bbc-b748-d425a17dea7d"));
|
||||
|
||||
// The same but with a leading '/'
|
||||
auto steel2 = _materialManager->getMaterialByPath(
|
||||
QStringLiteral("/Standard/Metal/Steel/CalculiX-Steel.FCMat"),
|
||||
QStringLiteral("System"));
|
||||
EXPECT_NE(&steel2, nullptr);
|
||||
EXPECT_EQ(steel2->getName(), QStringLiteral("CalculiX-Steel"));
|
||||
EXPECT_EQ(steel2->getUUID(), QStringLiteral("92589471-a6cb-4bbc-b748-d425a17dea7d"));
|
||||
|
||||
// Same with the library name as a prefix
|
||||
auto steel3 = _materialManager->getMaterialByPath(
|
||||
QStringLiteral("/System/Standard/Metal/Steel/CalculiX-Steel.FCMat"),
|
||||
QStringLiteral("System"));
|
||||
EXPECT_NE(&steel3, nullptr);
|
||||
EXPECT_EQ(steel3->getName(), QStringLiteral("CalculiX-Steel"));
|
||||
EXPECT_EQ(steel3->getUUID(), QStringLiteral("92589471-a6cb-4bbc-b748-d425a17dea7d"));
|
||||
}
|
||||
|
||||
TEST_F(TestMaterial, TestAddPhysicalModel)
|
||||
{
|
||||
// Start with an empty material
|
||||
Materials::Material material;
|
||||
auto models = material.getPhysicalModels();
|
||||
EXPECT_NE(&models, nullptr);
|
||||
EXPECT_EQ(models->size(), 0);
|
||||
|
||||
// Add a model
|
||||
material.addPhysical(Materials::ModelUUIDs::ModelUUID_Electromagnetic_Default);
|
||||
models = material.getPhysicalModels();
|
||||
EXPECT_EQ(models->size(), 1);
|
||||
|
||||
// Add a second model
|
||||
material.addPhysical(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic);
|
||||
models = material.getPhysicalModels();
|
||||
EXPECT_EQ(models->size(), 2);
|
||||
|
||||
// Add an inherited model
|
||||
material.addPhysical(Materials::ModelUUIDs::ModelUUID_Mechanical_IsotropicLinearElastic);
|
||||
models = material.getPhysicalModels();
|
||||
EXPECT_EQ(models->size(), 2);
|
||||
|
||||
// Add a super model
|
||||
material.clearModels();
|
||||
EXPECT_EQ(models->size(), 0);
|
||||
|
||||
material.addPhysical(Materials::ModelUUIDs::ModelUUID_Mechanical_IsotropicLinearElastic);
|
||||
models = material.getPhysicalModels();
|
||||
EXPECT_EQ(models->size(), 1);
|
||||
material.addPhysical(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic);
|
||||
models = material.getPhysicalModels();
|
||||
EXPECT_EQ(models->size(), 1);
|
||||
|
||||
// Remove the inherited model
|
||||
material.removePhysical(Materials::ModelUUIDs::ModelUUID_Mechanical_IsotropicLinearElastic);
|
||||
models = material.getPhysicalModels();
|
||||
EXPECT_EQ(models->size(), 1);
|
||||
|
||||
// Remove the super model
|
||||
material.removePhysical(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic);
|
||||
models = material.getPhysicalModels();
|
||||
EXPECT_EQ(models->size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestMaterial, TestAddAppearanceModel)
|
||||
{
|
||||
// Start with an empty material
|
||||
Materials::Material material;
|
||||
auto models = material.getAppearanceModels();
|
||||
EXPECT_NE(models, nullptr);
|
||||
EXPECT_EQ(models->size(), 0);
|
||||
|
||||
// Add a model
|
||||
material.addAppearance(Materials::ModelUUIDs::ModelUUID_Rendering_Vector);
|
||||
models = material.getAppearanceModels();
|
||||
EXPECT_EQ(models->size(), 1);
|
||||
|
||||
// Add a second model
|
||||
material.addAppearance(Materials::ModelUUIDs::ModelUUID_Rendering_Advanced);
|
||||
models = material.getAppearanceModels();
|
||||
EXPECT_EQ(models->size(), 2);
|
||||
|
||||
// Add an inherited model
|
||||
material.addAppearance(Materials::ModelUUIDs::ModelUUID_Rendering_Basic);
|
||||
models = material.getAppearanceModels();
|
||||
EXPECT_EQ(models->size(), 2);
|
||||
|
||||
// Add a super model
|
||||
material.clearModels();
|
||||
EXPECT_EQ(models->size(), 0);
|
||||
|
||||
material.addAppearance(Materials::ModelUUIDs::ModelUUID_Rendering_Basic);
|
||||
models = material.getAppearanceModels();
|
||||
EXPECT_EQ(models->size(), 1);
|
||||
material.addAppearance(Materials::ModelUUIDs::ModelUUID_Rendering_Advanced);
|
||||
models = material.getAppearanceModels();
|
||||
EXPECT_EQ(models->size(), 1);
|
||||
|
||||
// Remove the inherited model
|
||||
material.removeAppearance(Materials::ModelUUIDs::ModelUUID_Rendering_Basic);
|
||||
models = material.getAppearanceModels();
|
||||
EXPECT_EQ(models->size(), 1);
|
||||
|
||||
// Remove the super model
|
||||
material.removeAppearance(Materials::ModelUUIDs::ModelUUID_Rendering_Advanced);
|
||||
models = material.getAppearanceModels();
|
||||
EXPECT_EQ(models->size(), 0);
|
||||
}
|
||||
|
||||
QString parseQuantity(const std::string& value)
|
||||
{
|
||||
auto quantity = Base::Quantity::parse(value);
|
||||
quantity.setFormat(Materials::MaterialValue::getQuantityFormat());
|
||||
return QString::fromStdString(quantity.getUserString());
|
||||
}
|
||||
|
||||
TEST_F(TestMaterial, TestCalculiXSteel)
|
||||
{
|
||||
ASSERT_NE(_materialManager, nullptr);
|
||||
|
||||
auto steel = _materialManager->getMaterial(QStringLiteral("92589471-a6cb-4bbc-b748-d425a17dea7d"));
|
||||
EXPECT_EQ(steel->getName(), QStringLiteral("CalculiX-Steel"));
|
||||
EXPECT_EQ(steel->getUUID(), QStringLiteral("92589471-a6cb-4bbc-b748-d425a17dea7d"));
|
||||
|
||||
EXPECT_TRUE(steel->hasPhysicalModel(Materials::ModelUUIDs::ModelUUID_Mechanical_Density)); // Density
|
||||
EXPECT_TRUE(steel->hasPhysicalModel(Materials::ModelUUIDs::ModelUUID_Mechanical_IsotropicLinearElastic)); // IsotropicLinearElastic
|
||||
EXPECT_TRUE(steel->hasPhysicalModel(Materials::ModelUUIDs::ModelUUID_Thermal_Default)); // Thermal
|
||||
EXPECT_FALSE(steel->hasPhysicalModel(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic)); // Legacy linear elastic - Not in the model
|
||||
EXPECT_TRUE(steel->hasAppearanceModel(Materials::ModelUUIDs::ModelUUID_Rendering_Basic)); // BasicRendering - inherited from Steel.FCMat
|
||||
|
||||
EXPECT_TRUE(steel->isPhysicalModelComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Density)); // Density
|
||||
EXPECT_FALSE(steel->isPhysicalModelComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_IsotropicLinearElastic)); // IsotropicLinearElastic - incomplete
|
||||
EXPECT_FALSE(steel->isPhysicalModelComplete(Materials::ModelUUIDs::ModelUUID_Thermal_Default)); // Thermal
|
||||
EXPECT_FALSE(steel->isPhysicalModelComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic)); // Legacy linear elastic - Not in the model
|
||||
EXPECT_TRUE(steel->isAppearanceModelComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Basic)); // BasicRendering - inherited from Steel.FCMat
|
||||
|
||||
EXPECT_TRUE(steel->hasPhysicalProperty(QStringLiteral("Density")));
|
||||
EXPECT_TRUE(steel->hasPhysicalProperty(QStringLiteral("BulkModulus")));
|
||||
EXPECT_TRUE(steel->hasPhysicalProperty(QStringLiteral("PoissonRatio")));
|
||||
EXPECT_TRUE(steel->hasPhysicalProperty(QStringLiteral("YoungsModulus")));
|
||||
EXPECT_TRUE(steel->hasPhysicalProperty(QStringLiteral("ShearModulus")));
|
||||
EXPECT_TRUE(steel->hasPhysicalProperty(QStringLiteral("SpecificHeat")));
|
||||
EXPECT_TRUE(steel->hasPhysicalProperty(QStringLiteral("ThermalConductivity")));
|
||||
EXPECT_TRUE(steel->hasPhysicalProperty(QStringLiteral("ThermalExpansionCoefficient")));
|
||||
EXPECT_TRUE(steel->hasAppearanceProperty(QStringLiteral("AmbientColor")));
|
||||
EXPECT_TRUE(steel->hasAppearanceProperty(QStringLiteral("DiffuseColor")));
|
||||
EXPECT_TRUE(steel->hasAppearanceProperty(QStringLiteral("EmissiveColor")));
|
||||
EXPECT_TRUE(steel->hasAppearanceProperty(QStringLiteral("Shininess")));
|
||||
EXPECT_TRUE(steel->hasAppearanceProperty(QStringLiteral("SpecularColor")));
|
||||
EXPECT_TRUE(steel->hasAppearanceProperty(QStringLiteral("Transparency")));
|
||||
|
||||
auto& properties = steel->getPhysicalProperties();
|
||||
EXPECT_NO_THROW(properties.at(QStringLiteral("Density")));
|
||||
EXPECT_NO_THROW(properties.at(QStringLiteral("BulkModulus"))); // This is different from the Python behaviour
|
||||
EXPECT_NO_THROW(properties.at(QStringLiteral("PoissonRatio")));
|
||||
EXPECT_NO_THROW(properties.at(QStringLiteral("YoungsModulus")));
|
||||
EXPECT_NO_THROW(properties.at(QStringLiteral("ShearModulus")));
|
||||
EXPECT_NO_THROW(properties.at(QStringLiteral("SpecificHeat")));
|
||||
EXPECT_NO_THROW(properties.at(QStringLiteral("ThermalConductivity")));
|
||||
EXPECT_NO_THROW(properties.at(QStringLiteral("ThermalExpansionCoefficient")));
|
||||
EXPECT_THROW(properties.at(QStringLiteral("AmbientColor")), std::out_of_range);
|
||||
EXPECT_THROW(properties.at(QStringLiteral("DiffuseColor")), std::out_of_range);
|
||||
EXPECT_THROW(properties.at(QStringLiteral("EmissiveColor")), std::out_of_range);
|
||||
EXPECT_THROW(properties.at(QStringLiteral("Shininess")), std::out_of_range);
|
||||
EXPECT_THROW(properties.at(QStringLiteral("SpecularColor")), std::out_of_range);
|
||||
EXPECT_THROW(properties.at(QStringLiteral("Transparency")), std::out_of_range);
|
||||
|
||||
auto& properties1 = steel->getAppearanceProperties();
|
||||
EXPECT_THROW(properties1.at(QStringLiteral("Density")), std::out_of_range);
|
||||
EXPECT_THROW(properties1.at(QStringLiteral("BulkModulus")), std::out_of_range);
|
||||
EXPECT_THROW(properties1.at(QStringLiteral("PoissonRatio")), std::out_of_range);
|
||||
EXPECT_THROW(properties1.at(QStringLiteral("YoungsModulus")), std::out_of_range);
|
||||
EXPECT_THROW(properties1.at(QStringLiteral("ShearModulus")), std::out_of_range);
|
||||
EXPECT_THROW(properties1.at(QStringLiteral("SpecificHeat")), std::out_of_range);
|
||||
EXPECT_THROW(properties1.at(QStringLiteral("ThermalConductivity")), std::out_of_range);
|
||||
EXPECT_THROW(properties1.at(QStringLiteral("ThermalExpansionCoefficient")), std::out_of_range);
|
||||
EXPECT_NO_THROW(properties1.at(QStringLiteral("AmbientColor")));
|
||||
EXPECT_NO_THROW(properties1.at(QStringLiteral("DiffuseColor")));
|
||||
EXPECT_NO_THROW(properties1.at(QStringLiteral("EmissiveColor")));
|
||||
EXPECT_NO_THROW(properties1.at(QStringLiteral("Shininess")));
|
||||
EXPECT_NO_THROW(properties1.at(QStringLiteral("SpecularColor")));
|
||||
EXPECT_NO_THROW(properties1.at(QStringLiteral("Transparency")));
|
||||
|
||||
EXPECT_FALSE(properties[QStringLiteral("Density")]->isNull());
|
||||
EXPECT_TRUE(properties[QStringLiteral("BulkModulus")]->isNull());
|
||||
EXPECT_FALSE(properties[QStringLiteral("PoissonRatio")]->isNull());
|
||||
EXPECT_FALSE(properties[QStringLiteral("YoungsModulus")]->isNull());
|
||||
EXPECT_TRUE(properties[QStringLiteral("ShearModulus")]->isNull());
|
||||
EXPECT_FALSE(properties[QStringLiteral("SpecificHeat")]->isNull());
|
||||
EXPECT_FALSE(properties[QStringLiteral("ThermalConductivity")]->isNull());
|
||||
EXPECT_FALSE(properties[QStringLiteral("ThermalExpansionCoefficient")]->isNull());
|
||||
EXPECT_FALSE(properties1[QStringLiteral("AmbientColor")]->isNull());
|
||||
EXPECT_FALSE(properties1[QStringLiteral("DiffuseColor")]->isNull());
|
||||
EXPECT_FALSE(properties1[QStringLiteral("EmissiveColor")]->isNull());
|
||||
EXPECT_FALSE(properties1[QStringLiteral("Shininess")]->isNull());
|
||||
EXPECT_FALSE(properties1[QStringLiteral("SpecularColor")]->isNull());
|
||||
EXPECT_FALSE(properties1[QStringLiteral("Transparency")]->isNull());
|
||||
|
||||
QLocale locale;
|
||||
EXPECT_EQ(properties[QStringLiteral("Density")]->getString(), parseQuantity("7900.00 kg/m^3"));
|
||||
EXPECT_EQ(properties[QStringLiteral("PoissonRatio")]->getString(), locale.toString(0.3));
|
||||
EXPECT_EQ(properties[QStringLiteral("YoungsModulus")]->getString(), parseQuantity("210.00 GPa"));
|
||||
EXPECT_EQ(properties[QStringLiteral("SpecificHeat")]->getString(), parseQuantity("590.00 J/kg/K"));
|
||||
EXPECT_EQ(properties[QStringLiteral("ThermalConductivity")]->getString(), parseQuantity("43.00 W/m/K"));
|
||||
EXPECT_EQ(properties[QStringLiteral("ThermalExpansionCoefficient")]->getString(), parseQuantity("12.00 µm/m/K"));
|
||||
EXPECT_EQ(properties1[QStringLiteral("AmbientColor")]->getString(), QStringLiteral("(0.0020, 0.0020, 0.0020, 1.0)"));
|
||||
EXPECT_EQ(properties1[QStringLiteral("DiffuseColor")]->getString(), QStringLiteral("(0.0000, 0.0000, 0.0000, 1.0)"));
|
||||
EXPECT_EQ(properties1[QStringLiteral("EmissiveColor")]->getString(), QStringLiteral("(0.0000, 0.0000, 0.0000, 1.0)"));
|
||||
EXPECT_EQ(properties1[QStringLiteral("Shininess")]->getString(), locale.toString(0.06));
|
||||
EXPECT_EQ(properties1[QStringLiteral("SpecularColor")]->getString(), QStringLiteral("(0.9800, 0.9800, 0.9800, 1.0)"));
|
||||
EXPECT_EQ(properties1[QStringLiteral("Transparency")]->getString(), QStringLiteral("0"));
|
||||
|
||||
EXPECT_TRUE(properties[QStringLiteral("BulkModulus")]->getString().isEmpty());
|
||||
EXPECT_TRUE(properties[QStringLiteral("ShearModulus")]->getString().isEmpty());
|
||||
|
||||
// These are the preferred method of access
|
||||
//
|
||||
EXPECT_DOUBLE_EQ(steel->getPhysicalQuantity(QStringLiteral("Density")).getValue(), 7.9e-06);
|
||||
EXPECT_NEAR(steel->getPhysicalValue(QStringLiteral("PoissonRatio")).toDouble(), 0.3, 1e-6);
|
||||
EXPECT_DOUBLE_EQ(steel->getPhysicalQuantity(QStringLiteral("YoungsModulus")).getValue(), 210000000.0);
|
||||
EXPECT_DOUBLE_EQ(steel->getPhysicalQuantity(QStringLiteral("SpecificHeat")).getValue(), 590000000.0);
|
||||
EXPECT_DOUBLE_EQ(steel->getPhysicalQuantity(QStringLiteral("ThermalConductivity")).getValue(), 43000.0);
|
||||
EXPECT_DOUBLE_EQ(steel->getPhysicalQuantity(QStringLiteral("ThermalExpansionCoefficient")).getValue(), 1.2e-05);
|
||||
EXPECT_EQ(steel->getAppearanceValue(QStringLiteral("AmbientColor")), QStringLiteral("(0.0020, 0.0020, 0.0020, 1.0)"));
|
||||
EXPECT_EQ(steel->getAppearanceValue(QStringLiteral("DiffuseColor")), QStringLiteral("(0.0000, 0.0000, 0.0000, 1.0)"));
|
||||
EXPECT_EQ(steel->getAppearanceValue(QStringLiteral("EmissiveColor")), QStringLiteral("(0.0000, 0.0000, 0.0000, 1.0)"));
|
||||
EXPECT_NEAR(steel->getAppearanceValue(QStringLiteral("Shininess")).toDouble(), 0.06, 1e-6);
|
||||
EXPECT_EQ(steel->getAppearanceValue(QStringLiteral("SpecularColor")), QStringLiteral("(0.9800, 0.9800, 0.9800, 1.0)"));
|
||||
EXPECT_DOUBLE_EQ(steel->getAppearanceValue(QStringLiteral("Transparency")).toDouble(), 0.0);
|
||||
|
||||
EXPECT_EQ(steel->getPhysicalQuantity(QStringLiteral("Density")).getUserString(), parseQuantity("7900.00 kg/m^3").toStdString());
|
||||
EXPECT_EQ(steel->getPhysicalQuantity(QStringLiteral("YoungsModulus")).getUserString(), parseQuantity("210.00 GPa").toStdString());
|
||||
EXPECT_EQ(steel->getPhysicalQuantity(QStringLiteral("SpecificHeat")).getUserString(), parseQuantity("590.00 J/kg/K").toStdString());
|
||||
EXPECT_EQ(steel->getPhysicalQuantity(QStringLiteral("ThermalConductivity")).getUserString(), parseQuantity("43.00 W/m/K").toStdString());
|
||||
EXPECT_EQ(steel->getPhysicalQuantity(QStringLiteral("ThermalExpansionCoefficient")).getUserString(), parseQuantity("12.00 µm/m/K").toStdString());
|
||||
}
|
||||
|
||||
TEST_F(TestMaterial, TestColumns)
|
||||
{
|
||||
// Start with an empty material
|
||||
Materials::Material testMaterial;
|
||||
auto models = testMaterial.getPhysicalModels();
|
||||
EXPECT_NE(&models, nullptr);
|
||||
EXPECT_EQ(models->size(), 0);
|
||||
|
||||
// Add a model
|
||||
testMaterial.addPhysical(Materials::ModelUUIDs::ModelUUID_Test_Model);
|
||||
models = testMaterial.getPhysicalModels();
|
||||
EXPECT_EQ(models->size(), 1);
|
||||
|
||||
EXPECT_TRUE(testMaterial.hasPhysicalProperty(QStringLiteral("TestArray2D")));
|
||||
auto array2d = testMaterial.getPhysicalProperty(QStringLiteral("TestArray2D"))->getMaterialValue();
|
||||
EXPECT_TRUE(array2d);
|
||||
EXPECT_EQ(dynamic_cast<Materials::Array2D &>(*array2d).columns(), 2);
|
||||
|
||||
EXPECT_TRUE(testMaterial.hasPhysicalProperty(QStringLiteral("TestArray2D3Column")));
|
||||
auto array2d3Column = testMaterial.getPhysicalProperty(QStringLiteral("TestArray2D3Column"))->getMaterialValue();
|
||||
EXPECT_TRUE(array2d3Column);
|
||||
EXPECT_EQ(dynamic_cast<Materials::Array2D &>(*array2d3Column).columns(), 3);
|
||||
|
||||
EXPECT_TRUE(testMaterial.hasPhysicalProperty(QStringLiteral("TestArray3D")));
|
||||
auto array3d = testMaterial.getPhysicalProperty(QStringLiteral("TestArray3D"))->getMaterialValue();
|
||||
EXPECT_TRUE(array3d);
|
||||
EXPECT_EQ(dynamic_cast<Materials::Array3D &>(*array3d).columns(), 2);
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
136
tests/src/Mod/Material/App/TestModel.cpp
Normal file
136
tests/src/Mod/Material/App/TestModel.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
// 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 <QString>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include <Mod/Material/App/MaterialManager.h>
|
||||
#include <Mod/Material/App/Model.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
class TestModel : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
if (App::Application::GetARGC() == 0) {
|
||||
tests::initApplication();
|
||||
}
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
_modelManager = &(Materials::ModelManager::getManager());
|
||||
}
|
||||
|
||||
// void TearDown() override {}
|
||||
Materials::ModelManager* _modelManager;
|
||||
};
|
||||
|
||||
TEST_F(TestModel, TestApplication)
|
||||
{
|
||||
ASSERT_NO_THROW(App::GetApplication());
|
||||
}
|
||||
|
||||
TEST_F(TestModel, 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(TestModel, TestInstallation)
|
||||
{
|
||||
ASSERT_NE(_modelManager, nullptr);
|
||||
|
||||
// We should have loaded at least the system library
|
||||
auto libraries = _modelManager->getLibraries();
|
||||
ASSERT_GT(libraries->size(), 0);
|
||||
|
||||
// We should have at least one model
|
||||
auto models = _modelManager->getModels();
|
||||
ASSERT_GT(models->size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestModel, TestModelLoad)
|
||||
{
|
||||
ASSERT_NE(_modelManager, nullptr);
|
||||
|
||||
auto density = _modelManager->getModel(QStringLiteral("454661e5-265b-4320-8e6f-fcf6223ac3af"));
|
||||
EXPECT_EQ(density->getName(), QStringLiteral("Density"));
|
||||
EXPECT_EQ(density->getUUID(), QStringLiteral("454661e5-265b-4320-8e6f-fcf6223ac3af"));
|
||||
|
||||
auto& prop = (*density)[QStringLiteral("Density")];
|
||||
EXPECT_EQ(prop.getName(), QStringLiteral("Density"));
|
||||
}
|
||||
|
||||
TEST_F(TestModel, TestModelByPath)
|
||||
{
|
||||
ASSERT_NE(_modelManager, nullptr);
|
||||
|
||||
auto linearElastic = _modelManager->getModelByPath(
|
||||
QStringLiteral("Mechanical/LinearElastic.yml"),
|
||||
QStringLiteral("System"));
|
||||
EXPECT_NE(&linearElastic, nullptr);
|
||||
EXPECT_EQ(linearElastic->getName(), QStringLiteral("Linear Elastic"));
|
||||
EXPECT_EQ(linearElastic->getUUID(), QStringLiteral("7b561d1d-fb9b-44f6-9da9-56a4f74d7536"));
|
||||
|
||||
// The same but with a leading '/'
|
||||
auto linearElastic2 = _modelManager->getModelByPath(
|
||||
QStringLiteral("/Mechanical/LinearElastic.yml"),
|
||||
QStringLiteral("System"));
|
||||
EXPECT_NE(&linearElastic2, nullptr);
|
||||
EXPECT_EQ(linearElastic2->getName(), QStringLiteral("Linear Elastic"));
|
||||
EXPECT_EQ(linearElastic2->getUUID(), QStringLiteral("7b561d1d-fb9b-44f6-9da9-56a4f74d7536"));
|
||||
|
||||
// Same with the library name as a prefix
|
||||
auto linearElastic3 = _modelManager->getModelByPath(
|
||||
QStringLiteral("/System/Mechanical/LinearElastic.yml"),
|
||||
QStringLiteral("System"));
|
||||
EXPECT_NE(&linearElastic3, nullptr);
|
||||
EXPECT_EQ(linearElastic3->getName(), QStringLiteral("Linear Elastic"));
|
||||
EXPECT_EQ(linearElastic3->getUUID(), QStringLiteral("7b561d1d-fb9b-44f6-9da9-56a4f74d7536"));
|
||||
|
||||
// Test with the file system path
|
||||
ASSERT_NO_THROW(linearElastic->getLibrary());
|
||||
ASSERT_NO_THROW(linearElastic->getLibrary()->getName());
|
||||
ASSERT_NO_THROW(linearElastic->getLibrary()->getDirectoryPath());
|
||||
EXPECT_EQ(linearElastic->getLibrary()->getName(), QStringLiteral("System"));
|
||||
QString path = linearElastic->getLibrary()->getDirectoryPath() + QStringLiteral("/Mechanical/LinearElastic.yml");
|
||||
|
||||
ASSERT_NO_THROW(_modelManager->getModelByPath(path));
|
||||
auto linearElastic4 = _modelManager->getModelByPath(path);
|
||||
EXPECT_NE(&linearElastic4, nullptr);
|
||||
EXPECT_EQ(linearElastic4->getName(), QStringLiteral("Linear Elastic"));
|
||||
EXPECT_EQ(linearElastic4->getUUID(), QStringLiteral("7b561d1d-fb9b-44f6-9da9-56a4f74d7536"));
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
132
tests/src/Mod/Material/App/TestModelProperties.cpp
Normal file
132
tests/src/Mod/Material/App/TestModelProperties.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
// 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 <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Gui/MetaTypes.h>
|
||||
|
||||
#include <Mod/Material/App/MaterialManager.h>
|
||||
#include <Mod/Material/App/Model.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
#include <Mod/Material/App/ModelUuids.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
class TestModelProperties : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TestModelProperties, TestEmpty)
|
||||
{
|
||||
auto prop = Materials::ModelProperty();
|
||||
EXPECT_TRUE(prop.getName().isNull());
|
||||
EXPECT_TRUE(prop.getPropertyType().isNull());
|
||||
EXPECT_TRUE(prop.getUnits().isNull());
|
||||
EXPECT_TRUE(prop.getURL().isNull());
|
||||
EXPECT_TRUE(prop.getDescription().isNull());
|
||||
EXPECT_TRUE(prop.getInheritance().isNull());
|
||||
EXPECT_FALSE(prop.isInherited());
|
||||
EXPECT_EQ(prop.columns(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TestModelProperties, TestBasic)
|
||||
{
|
||||
auto prop = Materials::ModelProperty(QStringLiteral("1"),
|
||||
QStringLiteral("2"),
|
||||
QStringLiteral("3"),
|
||||
QStringLiteral("4"),
|
||||
QStringLiteral("5"),
|
||||
QStringLiteral("6"));
|
||||
EXPECT_EQ(prop.getName(), QStringLiteral("1"));
|
||||
EXPECT_EQ(prop.getDisplayName(), QStringLiteral("2"));
|
||||
EXPECT_EQ(prop.getPropertyType(), QStringLiteral("3"));
|
||||
EXPECT_EQ(prop.getUnits(), QStringLiteral("4"));
|
||||
EXPECT_EQ(prop.getURL(), QStringLiteral("5"));
|
||||
EXPECT_EQ(prop.getDescription(), QStringLiteral("6"));
|
||||
EXPECT_TRUE(prop.getInheritance().isNull());
|
||||
EXPECT_FALSE(prop.isInherited());
|
||||
EXPECT_EQ(prop.columns(), 0);
|
||||
|
||||
prop.setInheritance(QStringLiteral("12345"));
|
||||
EXPECT_EQ(prop.getInheritance(), QStringLiteral("12345"));
|
||||
EXPECT_TRUE(prop.isInherited());
|
||||
}
|
||||
|
||||
TEST_F(TestModelProperties, TestAddColumns)
|
||||
{
|
||||
auto prop = Materials::ModelProperty(QStringLiteral("1"),
|
||||
QStringLiteral("2"),
|
||||
QStringLiteral("3"),
|
||||
QStringLiteral("4"),
|
||||
QStringLiteral("5"),
|
||||
QStringLiteral("6"));
|
||||
auto prop1 = Materials::ModelProperty(QStringLiteral("10"),
|
||||
QStringLiteral("9"),
|
||||
QStringLiteral("8"),
|
||||
QStringLiteral("7"),
|
||||
QStringLiteral("6"),
|
||||
QStringLiteral("5"));
|
||||
auto prop2 = Materials::ModelProperty(QStringLiteral("a"),
|
||||
QStringLiteral("b"),
|
||||
QStringLiteral("c"),
|
||||
QStringLiteral("d"),
|
||||
QStringLiteral("e"),
|
||||
QStringLiteral("f"));
|
||||
|
||||
EXPECT_EQ(prop.columns(), 0);
|
||||
prop.addColumn(prop1);
|
||||
EXPECT_EQ(prop.columns(), 1);
|
||||
prop.addColumn(prop2);
|
||||
EXPECT_EQ(prop.columns(), 2);
|
||||
|
||||
auto columns = prop.getColumns();
|
||||
auto entry1 = columns.at(0);
|
||||
EXPECT_EQ(entry1.getName(), QStringLiteral("10"));
|
||||
EXPECT_EQ(entry1.getDisplayName(), QStringLiteral("9"));
|
||||
EXPECT_EQ(entry1.getPropertyType(), QStringLiteral("8"));
|
||||
EXPECT_EQ(entry1.getUnits(), QStringLiteral("7"));
|
||||
EXPECT_EQ(entry1.getURL(), QStringLiteral("6"));
|
||||
EXPECT_EQ(entry1.getDescription(), QStringLiteral("5"));
|
||||
EXPECT_TRUE(entry1.getInheritance().isNull());
|
||||
EXPECT_FALSE(entry1.isInherited());
|
||||
EXPECT_EQ(entry1.columns(), 0);
|
||||
|
||||
auto entry2 = columns.at(1);
|
||||
EXPECT_EQ(entry2.getName(), QStringLiteral("a"));
|
||||
EXPECT_EQ(entry2.getDisplayName(), QStringLiteral("b"));
|
||||
EXPECT_EQ(entry2.getPropertyType(), QStringLiteral("c"));
|
||||
EXPECT_EQ(entry2.getUnits(), QStringLiteral("d"));
|
||||
EXPECT_EQ(entry2.getURL(), QStringLiteral("e"));
|
||||
EXPECT_EQ(entry2.getDescription(), QStringLiteral("f"));
|
||||
EXPECT_TRUE(entry2.getInheritance().isNull());
|
||||
EXPECT_FALSE(entry2.isInherited());
|
||||
EXPECT_EQ(entry2.columns(), 0);
|
||||
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
9
tests/src/Mod/Material/CMakeLists.txt
Normal file
9
tests/src/Mod/Material/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_link_libraries(Material_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Materials
|
||||
)
|
||||
9
tests/src/Mod/Measure/App/CMakeLists.txt
Normal file
9
tests/src/Mod/Measure/App/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(Measure_tests_run
|
||||
MeasureDistance.cpp
|
||||
)
|
||||
|
||||
target_include_directories(Measure_tests_run PUBLIC
|
||||
${CMAKE_BINARY_DIR}
|
||||
)
|
||||
71
tests/src/Mod/Measure/App/MeasureDistance.cpp
Normal file
71
tests/src/Mod/Measure/App/MeasureDistance.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <App/Document.h>
|
||||
#include <Mod/Measure/App/MeasureDistance.h>
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <gp_Circ.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Wire.hxx>
|
||||
|
||||
class MeasureDistance: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
document = App::GetApplication().newDocument("Measure");
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(document->getName());
|
||||
}
|
||||
|
||||
App::Document* getDocument() const
|
||||
{
|
||||
return document;
|
||||
}
|
||||
|
||||
TopoDS_Edge makeCircle(const gp_Pnt& pnt) const
|
||||
{
|
||||
gp_Circ circle;
|
||||
circle.SetLocation(pnt);
|
||||
circle.SetRadius(1.0);
|
||||
BRepBuilderAPI_MakeEdge mkEdge(circle);
|
||||
return mkEdge.Edge();
|
||||
}
|
||||
|
||||
private:
|
||||
App::Document* document {};
|
||||
};
|
||||
|
||||
// NOLINTBEGIN
|
||||
TEST_F(MeasureDistance, testCircleCircle)
|
||||
{
|
||||
App::Document* doc = getDocument();
|
||||
auto p1 = doc->addObject<Part::Feature>("Shape1");
|
||||
p1->Shape.setValue(makeCircle(gp_Pnt(0.0, 0.0, 0.0)));
|
||||
auto p2 = doc->addObject<Part::Feature>("Shape2");
|
||||
p2->Shape.setValue(makeCircle(gp_Pnt(3.0, 4.0, 0.0)));
|
||||
|
||||
auto md = doc->addObject<Measure::MeasureDistance>("Distance");
|
||||
md->Element1.setValue(p1, {"Edge1"});
|
||||
md->Element2.setValue(p2, {"Edge1"});
|
||||
|
||||
doc->recompute();
|
||||
|
||||
EXPECT_DOUBLE_EQ(md->Distance.getValue(), 5.0);
|
||||
EXPECT_DOUBLE_EQ(md->DistanceX.getValue(), 3.0);
|
||||
EXPECT_DOUBLE_EQ(md->DistanceY.getValue(), 4.0);
|
||||
EXPECT_DOUBLE_EQ(md->DistanceZ.getValue(), 0.0);
|
||||
EXPECT_EQ(md->Position1.getValue(), Base::Vector3d(0.0, 0.0, 0.0));
|
||||
EXPECT_EQ(md->Position2.getValue(), Base::Vector3d(3.0, 4.0, 0.0));
|
||||
}
|
||||
// NOLINTEND
|
||||
9
tests/src/Mod/Measure/CMakeLists.txt
Normal file
9
tests/src/Mod/Measure/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_link_libraries(Measure_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Measure
|
||||
)
|
||||
11
tests/src/Mod/Mesh/App/CMakeLists.txt
Normal file
11
tests/src/Mod/Mesh/App/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(Mesh_tests_run
|
||||
Core/KDTree.cpp
|
||||
Exporter.cpp
|
||||
Importer.cpp
|
||||
Mesh.cpp
|
||||
MeshFeature.cpp
|
||||
)
|
||||
|
||||
target_compile_definitions(Mesh_tests_run PRIVATE DATADIR="${CMAKE_SOURCE_DIR}/data")
|
||||
95
tests/src/Mod/Mesh/App/Core/KDTree.cpp
Normal file
95
tests/src/Mod/Mesh/App/Core/KDTree.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <Mod/Mesh/App/Core/KDTree.h>
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-*,readability-*)
|
||||
|
||||
class KDTreeTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
points.emplace_back(0.F, 0.F, 0.F);
|
||||
points.emplace_back(0.F, 0.F, 1.F);
|
||||
points.emplace_back(0.F, 1.F, 0.F);
|
||||
points.emplace_back(0.F, 1.F, 1.F);
|
||||
points.emplace_back(1.F, 0.F, 0.F);
|
||||
points.emplace_back(1.F, 0.F, 1.F);
|
||||
points.emplace_back(1.F, 1.F, 0.F);
|
||||
points.emplace_back(1.F, 1.F, 1.F);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
const std::vector<Base::Vector3f>& GetPoints() const
|
||||
{
|
||||
return points;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Base::Vector3f> points;
|
||||
};
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeEmpty)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
EXPECT_EQ(tree.IsEmpty(), true);
|
||||
}
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeNearestEmpty)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
|
||||
Base::Vector3f pnt;
|
||||
Base::Vector3f nor;
|
||||
float dist;
|
||||
EXPECT_EQ(tree.FindNearest(pnt, nor, dist), MeshCore::POINT_INDEX_MAX);
|
||||
}
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeNearest)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
tree.AddPoints(GetPoints());
|
||||
EXPECT_EQ(tree.IsEmpty(), false);
|
||||
|
||||
Base::Vector3f nor;
|
||||
float dist;
|
||||
EXPECT_EQ(tree.FindNearest(Base::Vector3f(0.9F, 0.1F, 0.1F), nor, dist), 4);
|
||||
}
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeNearestMaxDist)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
tree.AddPoints(GetPoints());
|
||||
EXPECT_EQ(tree.IsEmpty(), false);
|
||||
|
||||
Base::Vector3f nor;
|
||||
float dist;
|
||||
EXPECT_EQ(
|
||||
tree.FindNearest(Base::Vector3f(0.9F, 0.1F, 0.1F), 0.0F, nor, dist),
|
||||
MeshCore::POINT_INDEX_MAX
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeFindExact)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
tree.AddPoints(GetPoints());
|
||||
|
||||
EXPECT_EQ(tree.FindExact(Base::Vector3f(0.1F, 0, 0)), MeshCore::POINT_INDEX_MAX);
|
||||
EXPECT_EQ(tree.FindExact(Base::Vector3f(0, 0, 0)), 0);
|
||||
}
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeFindRange)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
tree.AddPoints(GetPoints());
|
||||
|
||||
std::vector<MeshCore::PointIndex> index;
|
||||
std::vector<MeshCore::PointIndex> result = {0, 4};
|
||||
tree.FindInRange(Base::Vector3f(0.5F, 0, 0), 0.6F, index);
|
||||
EXPECT_EQ(index, result);
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-*,readability-*)
|
||||
152
tests/src/Mod/Mesh/App/Exporter.cpp
Normal file
152
tests/src/Mod/Mesh/App/Exporter.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/Part.h>
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <Mod/Mesh/App/Exporter.h>
|
||||
#include <Mod/Mesh/App/FeatureMeshSolid.h>
|
||||
#include <Mod/Mesh/App/Mesh.h>
|
||||
|
||||
class ExporterTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
document = App::GetApplication().newDocument("MeshExport");
|
||||
fileInfo.setFile(Base::FileInfo::getTempFileName() + ".stl");
|
||||
|
||||
const double value = 10.0;
|
||||
cube1 = document->addObject<Mesh::Cube>("Cube1");
|
||||
cube1->Length.setValue(value);
|
||||
cube1->Width.setValue(value);
|
||||
cube1->Height.setValue(value);
|
||||
cube2 = document->addObject<Mesh::Cube>("Cube2");
|
||||
cube2->Length.setValue(value);
|
||||
cube2->Width.setValue(value);
|
||||
cube2->Height.setValue(value);
|
||||
|
||||
document->recompute();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(document->getName());
|
||||
fileInfo.deleteFile();
|
||||
}
|
||||
|
||||
App::Document* getDocument() const
|
||||
{
|
||||
return document;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> getObjects() const
|
||||
{
|
||||
return {cube1, cube2};
|
||||
}
|
||||
|
||||
App::DocumentObject* getMesh2() const
|
||||
{
|
||||
return cube2;
|
||||
}
|
||||
|
||||
void setPlacementTo2ndCube(const Base::Placement& plm)
|
||||
{
|
||||
cube2->Placement.setValue(plm);
|
||||
}
|
||||
|
||||
std::string getFileName() const
|
||||
{
|
||||
return fileInfo.filePath();
|
||||
}
|
||||
|
||||
private:
|
||||
Base::FileInfo fileInfo;
|
||||
App::Document* document {};
|
||||
Mesh::Cube* cube1 {};
|
||||
Mesh::Cube* cube2 {};
|
||||
};
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-*,readability-*)
|
||||
TEST_F(ExporterTest, TestSingleMesh)
|
||||
{
|
||||
Base::Placement plm;
|
||||
plm.setPosition(Base::Vector3d(10, 5, 2));
|
||||
setPlacementTo2ndCube(plm);
|
||||
|
||||
// add extra scope because the file will be written when destroying the exporter
|
||||
{
|
||||
Mesh::MergeExporter exporter(getFileName(), MeshCore::MeshIO::Format::STL);
|
||||
exporter.addObject(getMesh2(), 0.1F);
|
||||
}
|
||||
|
||||
Mesh::MeshObject kernel;
|
||||
EXPECT_TRUE(kernel.load(getFileName().c_str()));
|
||||
auto bbox = kernel.getBoundBox();
|
||||
EXPECT_DOUBLE_EQ(bbox.MinX, 5.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxX, 15.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxY, 10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinZ, -3.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxZ, 7.0);
|
||||
}
|
||||
|
||||
// Test for https://github.com/FreeCAD/FreeCAD/pull/11539
|
||||
TEST_F(ExporterTest, TestMultipleMeshes)
|
||||
{
|
||||
Base::Placement plm;
|
||||
plm.setPosition(Base::Vector3d(10, 5, 2));
|
||||
setPlacementTo2ndCube(plm);
|
||||
|
||||
// add extra scope because the file will be written when destroying the exporter
|
||||
{
|
||||
Mesh::MergeExporter exporter(getFileName(), MeshCore::MeshIO::Format::STL);
|
||||
for (auto obj : getObjects()) {
|
||||
exporter.addObject(obj, 0.1F);
|
||||
}
|
||||
}
|
||||
|
||||
Mesh::MeshObject kernel;
|
||||
EXPECT_TRUE(kernel.load(getFileName().c_str()));
|
||||
auto bbox = kernel.getBoundBox();
|
||||
EXPECT_DOUBLE_EQ(bbox.MinX, -5.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxX, 15.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinY, -5.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxY, 10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinZ, -5.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxZ, 7.0);
|
||||
}
|
||||
|
||||
TEST_F(ExporterTest, TestMeshesInPart)
|
||||
{
|
||||
Base::Placement plm;
|
||||
plm.setPosition(Base::Vector3d(10, 5, 2));
|
||||
setPlacementTo2ndCube(plm);
|
||||
|
||||
// add extra scope because the file will be written when destroying the exporter
|
||||
{
|
||||
auto part = getDocument()->addObject<App::Part>("Part");
|
||||
part->placement().setValue(plm);
|
||||
part->addObjects(getObjects());
|
||||
Mesh::MergeExporter exporter(getFileName(), MeshCore::MeshIO::Format::STL);
|
||||
exporter.addObject(part, 0.1F);
|
||||
}
|
||||
|
||||
Mesh::MeshObject kernel;
|
||||
EXPECT_TRUE(kernel.load(getFileName().c_str()));
|
||||
auto bbox = kernel.getBoundBox();
|
||||
EXPECT_DOUBLE_EQ(bbox.MinX, 5.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxX, 25.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxY, 15.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinZ, -3.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxZ, 9.0);
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-*,readability-*)
|
||||
56
tests/src/Mod/Mesh/App/Importer.cpp
Normal file
56
tests/src/Mod/Mesh/App/Importer.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Mod/Mesh/App/Core/IO/Reader3MF.h>
|
||||
#include <Mod/Mesh/App/Core/IO/ReaderOBJ.h>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <zipios++/fcoll.h>
|
||||
|
||||
class ImporterTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
XERCES_CPP_NAMESPACE::XMLPlatformUtils::Initialize();
|
||||
}
|
||||
};
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-*,readability-*)
|
||||
TEST_F(ImporterTest, Test3MF)
|
||||
{
|
||||
std::string file(DATADIR);
|
||||
file.append("/tests/mesh.3mf");
|
||||
|
||||
MeshCore::Reader3MF reader(file);
|
||||
EXPECT_EQ(reader.Load(), true);
|
||||
|
||||
std::vector<int> ids = reader.GetMeshIds();
|
||||
std::sort(ids.begin(), ids.end());
|
||||
|
||||
EXPECT_EQ(ids.size(), 2);
|
||||
|
||||
const MeshCore::MeshKernel& mesh1 = reader.GetMesh(ids[0]);
|
||||
EXPECT_EQ(mesh1.CountPoints(), 8);
|
||||
EXPECT_EQ(mesh1.CountEdges(), 18);
|
||||
EXPECT_EQ(mesh1.CountFacets(), 12);
|
||||
|
||||
const MeshCore::MeshKernel& mesh2 = reader.GetMesh(ids[1]);
|
||||
EXPECT_EQ(mesh2.CountPoints(), 652);
|
||||
EXPECT_EQ(mesh2.CountEdges(), 1950);
|
||||
EXPECT_EQ(mesh2.CountFacets(), 1300);
|
||||
}
|
||||
|
||||
TEST_F(ImporterTest, TestOBJ)
|
||||
{
|
||||
std::string file(DATADIR);
|
||||
file.append("/tests/mesh.obj");
|
||||
|
||||
MeshCore::MeshKernel kernel;
|
||||
MeshCore::ReaderOBJ reader(kernel, nullptr);
|
||||
EXPECT_EQ(reader.Load(file), true);
|
||||
|
||||
EXPECT_EQ(kernel.CountPoints(), 8);
|
||||
EXPECT_EQ(kernel.CountFacets(), 12);
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-*,readability-*)
|
||||
111
tests/src/Mod/Mesh/App/Mesh.cpp
Normal file
111
tests/src/Mod/Mesh/App/Mesh.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <Mod/Mesh/App/Mesh.h>
|
||||
#include <Mod/Mesh/App/Core/Grid.h>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
class MeshTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
};
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-*,readability-*)
|
||||
TEST_F(MeshTest, TestDefault)
|
||||
{
|
||||
MeshCore::MeshKernel kernel;
|
||||
Base::Vector3f p1 {0, 0, 0};
|
||||
Base::Vector3f p2 {0, 0, 1};
|
||||
Base::Vector3f p3 {0, 1, 0};
|
||||
kernel.AddFacet(MeshCore::MeshGeomFacet(p1, p2, p3));
|
||||
|
||||
EXPECT_EQ(kernel.CountPoints(), 3);
|
||||
EXPECT_EQ(kernel.CountEdges(), 3);
|
||||
EXPECT_EQ(kernel.CountFacets(), 1);
|
||||
}
|
||||
|
||||
TEST_F(MeshTest, TestGrid1OfPlanarMesh)
|
||||
{
|
||||
MeshCore::MeshKernel kernel;
|
||||
Base::Vector3f p1 {0, 0, 0};
|
||||
Base::Vector3f p2 {1, 0, 0};
|
||||
Base::Vector3f p3 {0, 1, 0};
|
||||
Base::Vector3f p4 {1, 1, 0};
|
||||
kernel.AddFacet(MeshCore::MeshGeomFacet(p1, p2, p3));
|
||||
kernel.AddFacet(MeshCore::MeshGeomFacet(p3, p2, p4));
|
||||
|
||||
MeshCore::MeshFacetGrid grid(kernel, 10);
|
||||
unsigned long countX {};
|
||||
unsigned long countY {};
|
||||
unsigned long countZ {};
|
||||
grid.GetCtGrids(countX, countY, countZ);
|
||||
EXPECT_EQ(countX, 1);
|
||||
EXPECT_EQ(countY, 1);
|
||||
EXPECT_EQ(countZ, 1);
|
||||
}
|
||||
|
||||
TEST_F(MeshTest, TestGrid2OfPlanarMesh)
|
||||
{
|
||||
MeshCore::MeshKernel kernel;
|
||||
Base::Vector3f p1 {0, 0, 0};
|
||||
Base::Vector3f p2 {1, 0, 0};
|
||||
Base::Vector3f p3 {0, 1, 0};
|
||||
Base::Vector3f p4 {1, 1, 0};
|
||||
kernel.AddFacet(MeshCore::MeshGeomFacet(p1, p2, p3));
|
||||
kernel.AddFacet(MeshCore::MeshGeomFacet(p3, p2, p4));
|
||||
|
||||
MeshCore::MeshFacetGrid grid(kernel);
|
||||
unsigned long countX {};
|
||||
unsigned long countY {};
|
||||
unsigned long countZ {};
|
||||
grid.GetCtGrids(countX, countY, countZ);
|
||||
EXPECT_EQ(countX, 1);
|
||||
EXPECT_EQ(countY, 1);
|
||||
EXPECT_EQ(countZ, 1);
|
||||
}
|
||||
|
||||
TEST_F(MeshTest, TestGrid1OfAlmostPlanarMesh)
|
||||
{
|
||||
MeshCore::MeshKernel kernel;
|
||||
Base::Vector3f p1 {0, 0, 0};
|
||||
Base::Vector3f p2 {1, 0, 0};
|
||||
Base::Vector3f p3 {0, 1, 0};
|
||||
Base::Vector3f p4 {1, 1, 1.0e-18F};
|
||||
kernel.AddFacet(MeshCore::MeshGeomFacet(p1, p2, p3));
|
||||
kernel.AddFacet(MeshCore::MeshGeomFacet(p3, p2, p4));
|
||||
|
||||
MeshCore::MeshFacetGrid grid(kernel, 10);
|
||||
unsigned long countX {};
|
||||
unsigned long countY {};
|
||||
unsigned long countZ {};
|
||||
grid.GetCtGrids(countX, countY, countZ);
|
||||
EXPECT_EQ(countX, 1);
|
||||
EXPECT_EQ(countY, 1);
|
||||
EXPECT_EQ(countZ, 1);
|
||||
}
|
||||
|
||||
TEST_F(MeshTest, TestGrid2OfAlmostPlanarMesh)
|
||||
{
|
||||
MeshCore::MeshKernel kernel;
|
||||
Base::Vector3f p1 {0, 0, 0};
|
||||
Base::Vector3f p2 {1, 0, 0};
|
||||
Base::Vector3f p3 {0, 1, 0};
|
||||
Base::Vector3f p4 {1, 1, 1.0e-18F};
|
||||
kernel.AddFacet(MeshCore::MeshGeomFacet(p1, p2, p3));
|
||||
kernel.AddFacet(MeshCore::MeshGeomFacet(p3, p2, p4));
|
||||
|
||||
MeshCore::MeshFacetGrid grid(kernel);
|
||||
unsigned long countX {};
|
||||
unsigned long countY {};
|
||||
unsigned long countZ {};
|
||||
grid.GetCtGrids(countX, countY, countZ);
|
||||
EXPECT_EQ(countX, 1);
|
||||
EXPECT_EQ(countY, 1);
|
||||
EXPECT_EQ(countZ, 1);
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-*,readability-*)
|
||||
42
tests/src/Mod/Mesh/App/MeshFeature.cpp
Normal file
42
tests/src/Mod/Mesh/App/MeshFeature.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <Mod/Mesh/App/MeshFeature.h>
|
||||
|
||||
class MeshFeatureTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
};
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-*,readability-*)
|
||||
TEST_F(MeshFeatureTest, getElementTypes)
|
||||
{
|
||||
Mesh::Feature mf;
|
||||
std::vector<const char*> types = mf.getElementTypes();
|
||||
|
||||
EXPECT_EQ(types.size(), 2);
|
||||
EXPECT_STREQ(types[0], "Mesh");
|
||||
EXPECT_STREQ(types[1], "Segment");
|
||||
}
|
||||
|
||||
TEST_F(MeshFeatureTest, getComplexElementTypes)
|
||||
{
|
||||
Mesh::MeshObject mf;
|
||||
std::vector<const char*> types = mf.getElementTypes();
|
||||
|
||||
EXPECT_EQ(types.size(), 2);
|
||||
EXPECT_STREQ(types[0], "Mesh");
|
||||
EXPECT_STREQ(types[1], "Segment");
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-*,readability-*)
|
||||
9
tests/src/Mod/Mesh/CMakeLists.txt
Normal file
9
tests/src/Mod/Mesh/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_link_libraries(Mesh_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Mesh
|
||||
)
|
||||
9
tests/src/Mod/MeshPart/App/CMakeLists.txt
Normal file
9
tests/src/Mod/MeshPart/App/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(MeshPart_tests_run
|
||||
MeshPart.cpp
|
||||
)
|
||||
|
||||
target_include_directories(MeshPart_tests_run PUBLIC
|
||||
${CMAKE_BINARY_DIR}
|
||||
)
|
||||
116
tests/src/Mod/MeshPart/App/MeshPart.cpp
Normal file
116
tests/src/Mod/MeshPart/App/MeshPart.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <TopoDS_Solid.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopAbs_ShapeEnum.hxx>
|
||||
#include <QObject>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_CLANG("-Wextra-semi")
|
||||
QT_WARNING_DISABLE_CLANG("-Woverloaded-virtual")
|
||||
#include <SMESH_Version.h>
|
||||
#include <SMESH_Gen.hxx>
|
||||
#include <SMESH_Mesh.hxx>
|
||||
#include <StdMeshers_LocalLength.hxx>
|
||||
#include <StdMeshers_Regular_1D.hxx>
|
||||
#include <StdMeshers_MEFISTO_2D.hxx>
|
||||
#include <StdMeshers_QuadranglePreference.hxx>
|
||||
QT_WARNING_POP
|
||||
|
||||
class SMesh: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
};
|
||||
// NOLINTBEGIN
|
||||
TEST_F(SMesh, testMefisto)
|
||||
{
|
||||
TopoDS_Solid box = BRepPrimAPI_MakeBox(10.0, 10.0, 10.0).Solid();
|
||||
|
||||
SMESH_Gen* gen = new SMESH_Gen();
|
||||
#if SMESH_VERSION_MAJOR >= 9
|
||||
SMESH_Mesh* mesh = gen->CreateMesh(true);
|
||||
|
||||
StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(0, gen);
|
||||
hyp1d->SetLength(1.0);
|
||||
StdMeshers_Regular_1D* algo1d = new StdMeshers_Regular_1D(1, gen);
|
||||
|
||||
StdMeshers_QuadranglePreference* hyp2d = new StdMeshers_QuadranglePreference(2, gen);
|
||||
StdMeshers_MEFISTO_2D* algo2d = new StdMeshers_MEFISTO_2D(3, gen);
|
||||
#else
|
||||
SMESH_Mesh* mesh = gen->CreateMesh(0, true);
|
||||
|
||||
StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(0, 0, gen);
|
||||
hyp1d->SetLength(1.0);
|
||||
StdMeshers_Regular_1D* algo1d = new StdMeshers_Regular_1D(1, 0, gen);
|
||||
|
||||
StdMeshers_QuadranglePreference* hyp2d = new StdMeshers_QuadranglePreference(2, 0, gen);
|
||||
StdMeshers_MEFISTO_2D* algo2d = new StdMeshers_MEFISTO_2D(3, 0, gen);
|
||||
#endif
|
||||
|
||||
mesh->ShapeToMesh(box);
|
||||
mesh->AddHypothesis(box, 0);
|
||||
mesh->AddHypothesis(box, 1);
|
||||
mesh->AddHypothesis(box, 2);
|
||||
mesh->AddHypothesis(box, 3);
|
||||
|
||||
bool success = gen->Compute(*mesh, box);
|
||||
EXPECT_EQ(success, true);
|
||||
|
||||
EXPECT_EQ(mesh->NbNodes(), 1244);
|
||||
EXPECT_EQ(mesh->NbTriangles(), 2484);
|
||||
EXPECT_EQ(mesh->NbQuadrangles(), 0);
|
||||
|
||||
delete hyp1d;
|
||||
delete algo1d;
|
||||
delete hyp2d;
|
||||
delete algo2d;
|
||||
delete mesh;
|
||||
delete gen;
|
||||
}
|
||||
|
||||
TEST_F(SMesh, testStdMeshers)
|
||||
{
|
||||
TopoDS_Solid box = BRepPrimAPI_MakeBox(10.0, 10.0, 10.0).Solid();
|
||||
|
||||
TopExp_Explorer exp = TopExp_Explorer(box, TopAbs_EDGE);
|
||||
const TopoDS_Shape& edge = exp.Current();
|
||||
|
||||
SMESH_Gen* gen = new SMESH_Gen();
|
||||
#if SMESH_VERSION_MAJOR >= 9
|
||||
SMESH_Mesh* mesh = gen->CreateMesh(true);
|
||||
|
||||
StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(0, gen);
|
||||
hyp1d->SetLength(0.1);
|
||||
StdMeshers_Regular_1D* algo1d = new StdMeshers_Regular_1D(1, gen);
|
||||
#else
|
||||
SMESH_Mesh* mesh = gen->CreateMesh(0, true);
|
||||
|
||||
StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(0, 0, gen);
|
||||
hyp1d->SetLength(0.1);
|
||||
StdMeshers_Regular_1D* algo1d = new StdMeshers_Regular_1D(1, 0, gen);
|
||||
#endif
|
||||
|
||||
mesh->ShapeToMesh(box);
|
||||
mesh->AddHypothesis(edge, 0);
|
||||
mesh->AddHypothesis(edge, 1);
|
||||
|
||||
bool success = gen->Compute(*mesh, box);
|
||||
EXPECT_EQ(success, true);
|
||||
|
||||
EXPECT_EQ(mesh->NbNodes(), 107);
|
||||
|
||||
delete hyp1d;
|
||||
delete algo1d;
|
||||
delete mesh;
|
||||
delete gen;
|
||||
}
|
||||
// NOLINTEND
|
||||
9
tests/src/Mod/MeshPart/CMakeLists.txt
Normal file
9
tests/src/Mod/MeshPart/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_link_libraries(MeshPart_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
MeshPart
|
||||
)
|
||||
98
tests/src/Mod/Part/App/AttachExtension.cpp
Normal file
98
tests/src/Mod/Part/App/AttachExtension.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <App/Document.h>
|
||||
#include <Mod/Part/App/PrimitiveFeature.h>
|
||||
|
||||
|
||||
class AttachExtensionTest: 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* getDocument() const
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _docName;
|
||||
App::Document* _doc = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(AttachExtensionTest, testPlanePlane)
|
||||
{
|
||||
auto plane1 = getDocument()->addObject<Part::Plane>("Plane1");
|
||||
auto plane2 = getDocument()->addObject<Part::Plane>("Plane2");
|
||||
|
||||
ASSERT_TRUE(plane1);
|
||||
ASSERT_TRUE(plane2);
|
||||
|
||||
getDocument()->recompute();
|
||||
|
||||
plane2->MapReversed.setValue(false);
|
||||
plane2->AttachmentSupport.setValue(plane1);
|
||||
plane2->MapPathParameter.setValue(0.0);
|
||||
plane2->MapMode.setValue("FlatFace");
|
||||
|
||||
getDocument()->recompute();
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST_F(AttachExtensionTest, testAttacherEngineType)
|
||||
{
|
||||
auto plane = getDocument()->addObject<Part::Plane>("Plane");
|
||||
EXPECT_STREQ(plane->AttacherType.getValue(), "Attacher::AttachEngine3D");
|
||||
EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine 3D");
|
||||
|
||||
plane->AttacherEngine.setValue(1L);
|
||||
EXPECT_STREQ(plane->AttacherType.getValue(), "Attacher::AttachEnginePlane");
|
||||
EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine Plane");
|
||||
|
||||
plane->AttacherEngine.setValue(2L);
|
||||
EXPECT_STREQ(plane->AttacherType.getValue(), "Attacher::AttachEngineLine");
|
||||
EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine Line");
|
||||
|
||||
plane->AttacherEngine.setValue(3L);
|
||||
EXPECT_STREQ(plane->AttacherType.getValue(), "Attacher::AttachEnginePoint");
|
||||
EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine Point");
|
||||
}
|
||||
|
||||
TEST_F(AttachExtensionTest, testAttacherTypeEngine)
|
||||
{
|
||||
auto plane = getDocument()->addObject<Part::Plane>("Plane");
|
||||
EXPECT_STREQ(plane->AttacherType.getValue(), "Attacher::AttachEngine3D");
|
||||
EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine 3D");
|
||||
|
||||
plane->AttacherType.setValue("Attacher::AttachEnginePlane");
|
||||
plane->onExtendedDocumentRestored();
|
||||
EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine Plane");
|
||||
|
||||
plane->AttacherType.setValue("Attacher::AttachEngineLine");
|
||||
plane->onExtendedDocumentRestored();
|
||||
EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine Line");
|
||||
|
||||
plane->AttacherType.setValue("Attacher::AttachEnginePoint");
|
||||
plane->onExtendedDocumentRestored();
|
||||
EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine Point");
|
||||
|
||||
plane->AttacherType.setValue("Attacher::AttachEngine3D");
|
||||
plane->onExtendedDocumentRestored();
|
||||
EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine 3D");
|
||||
}
|
||||
366
tests/src/Mod/Part/App/Attacher.cpp
Normal file
366
tests/src/Mod/Part/App/Attacher.cpp
Normal file
@@ -0,0 +1,366 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <App/Document.h>
|
||||
#include <Mod/Part/App/Attacher.h>
|
||||
|
||||
using namespace Part;
|
||||
using namespace Attacher;
|
||||
using namespace PartTestHelpers;
|
||||
|
||||
/*
|
||||
* Testing note: It looks like there are about 45 different attachment modes, and these tests
|
||||
* mostly only look at some of them - to prove that adding elementMap code doesn't break anything.
|
||||
* While a trivial bounding box test is used to ensure no hard crashes in any of the modes, any
|
||||
* mode that requires additional shapes beyond a couple of boxes would need a more comprehensive
|
||||
* test.
|
||||
*/
|
||||
|
||||
class AttacherTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_boxes[1]->MapReversed.setValue(false);
|
||||
_boxes[1]->AttachmentSupport.setValue(_boxes[0]);
|
||||
_boxes[1]->MapPathParameter.setValue(0.0);
|
||||
_boxes[1]->MapMode.setValue("ObjectXY"); // There are lots of attachment modes!
|
||||
_boxes[1]->recomputeFeature();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
App::Document* getDocument() const
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
TEST_F(AttacherTest, TestSetReferences)
|
||||
{
|
||||
auto& attacher = _boxes[1]->attacher();
|
||||
EXPECT_EQ(attacher.getRefObjects().size(), 1);
|
||||
}
|
||||
|
||||
TEST_F(AttacherTest, TestSuggestMapModes)
|
||||
{
|
||||
auto& attacher = _boxes[1]->attacher();
|
||||
SuggestResult result;
|
||||
attacher.suggestMapModes(result);
|
||||
EXPECT_EQ(result.allApplicableModes.size(), 4);
|
||||
EXPECT_EQ(result.allApplicableModes[0], mmObjectXY);
|
||||
EXPECT_EQ(result.allApplicableModes[1], mmObjectXZ);
|
||||
EXPECT_EQ(result.allApplicableModes[2], mmObjectYZ);
|
||||
EXPECT_EQ(result.allApplicableModes[3], mmInertialCS);
|
||||
}
|
||||
|
||||
TEST_F(AttacherTest, TestGetShapeType)
|
||||
{
|
||||
auto& attacher = _boxes[1]->attacher();
|
||||
auto subObjects = _boxes[1]->getSubObjects();
|
||||
auto shapeType = attacher.getShapeType(_boxes[1], "Vertex2");
|
||||
EXPECT_EQ(shapeType, TopAbs_COMPSOLID);
|
||||
}
|
||||
|
||||
TEST_F(AttacherTest, TestGetInertialPropsOfShape)
|
||||
{
|
||||
auto& attacher = _boxes[1]->attacher();
|
||||
std::vector<const TopoShape*> result;
|
||||
auto faces = _boxes[1]->Shape.getShape().getSubTopoShapes(TopAbs_FACE);
|
||||
result.emplace_back(&faces[0]);
|
||||
auto shapeType = attacher.getInertialPropsOfShape(result);
|
||||
EXPECT_EQ(result.size(), 1);
|
||||
EXPECT_EQ(shapeType.Mass(), 6.0);
|
||||
}
|
||||
|
||||
TEST_F(AttacherTest, TestGetRefObjects)
|
||||
{
|
||||
auto& attacher = _boxes[1]->attacher();
|
||||
auto docObjects = attacher.getRefObjects();
|
||||
EXPECT_EQ(docObjects.size(), 1);
|
||||
EXPECT_STREQ(docObjects.front()->getNameInDocument(), "Part__Box");
|
||||
}
|
||||
|
||||
TEST_F(AttacherTest, TestCalculateAttachedPlacement)
|
||||
{
|
||||
auto& attacher = _boxes[1]->attacher();
|
||||
const Base::Placement orig;
|
||||
auto placement = attacher.calculateAttachedPlacement(orig);
|
||||
EXPECT_EQ(orig.getPosition().x, 0);
|
||||
EXPECT_EQ(orig.getPosition().y, 0);
|
||||
EXPECT_EQ(orig.getPosition().z, 0);
|
||||
EXPECT_EQ(placement.getPosition().x, 0);
|
||||
EXPECT_EQ(placement.getPosition().y, 0);
|
||||
EXPECT_EQ(placement.getPosition().z, 0);
|
||||
}
|
||||
|
||||
TEST_F(AttacherTest, TestAllStringModesValid)
|
||||
{
|
||||
// Arrange
|
||||
const char* modes[] = {
|
||||
"Deactivated",
|
||||
"Translate",
|
||||
"ObjectXY",
|
||||
"ObjectXZ",
|
||||
"ObjectYZ",
|
||||
"FlatFace",
|
||||
"TangentPlane",
|
||||
"NormalToEdge",
|
||||
"FrenetNB",
|
||||
"FrenetTN",
|
||||
"FrenetTB",
|
||||
"Concentric",
|
||||
"SectionOfRevolution",
|
||||
"ThreePointsPlane",
|
||||
"ThreePointsNormal",
|
||||
"Folding",
|
||||
|
||||
"ObjectX",
|
||||
"ObjectY",
|
||||
"ObjectZ",
|
||||
"AxisOfCurvature",
|
||||
"Directrix1",
|
||||
"Directrix2",
|
||||
"Asymptote1",
|
||||
"Asymptote2",
|
||||
"Tangent",
|
||||
"Normal",
|
||||
"Binormal",
|
||||
"TangentU",
|
||||
"TangentV",
|
||||
"TwoPointLine",
|
||||
"IntersectionLine",
|
||||
"ProximityLine",
|
||||
|
||||
"ObjectOrigin",
|
||||
"Focus1",
|
||||
"Focus2",
|
||||
"OnEdge",
|
||||
"CenterOfCurvature",
|
||||
"CenterOfMass",
|
||||
"IntersectionPoint",
|
||||
"Vertex",
|
||||
"ProximityPoint1",
|
||||
"ProximityPoint2",
|
||||
|
||||
"AxisOfInertia1",
|
||||
"AxisOfInertia2",
|
||||
"AxisOfInertia3",
|
||||
|
||||
"InertialCS",
|
||||
|
||||
"FaceNormal",
|
||||
|
||||
"OZX",
|
||||
"OZY",
|
||||
"OXY",
|
||||
"OXZ",
|
||||
"OYZ",
|
||||
"OYX",
|
||||
|
||||
"ParallelPlane",
|
||||
};
|
||||
int index = 0;
|
||||
for (auto mode : modes) {
|
||||
_boxes[1]->MapMode.setValue(mode); // There are lots of attachment modes!
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_STREQ(_boxes[1]->MapMode.getValueAsString(), mode);
|
||||
EXPECT_EQ(_boxes[1]->MapMode.getValue(), index);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(AttacherTest, TestAllModesBoundaries)
|
||||
{
|
||||
_boxes[1]->MapMode.setValue(mmTranslate);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 1, 2, 3)));
|
||||
_boxes[1]->MapMode.setValue(mmObjectXY);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 1, 2, 3)));
|
||||
_boxes[1]->MapMode.setValue(mmObjectXZ);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, -3, 0, 1, 0, 2)));
|
||||
_boxes[1]->MapMode.setValue(mmObjectYZ);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
|
||||
_boxes[1]->MapMode.setValue(mmParallelPlane);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mmFlatFace);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mmTangentPlane);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1Normal);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
|
||||
_boxes[1]->MapMode.setValue(mmFrenetNB);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mmFrenetTN);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mmFrenetTB);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mmConcentric);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mmRevolutionSection);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mmThreePointsNormal);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mmThreePointsPlane);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mmFolding);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
|
||||
_boxes[1]->MapMode.setValue(mm1AxisX);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1AxisY);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1AxisZ);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1AxisCurv);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1Directrix1);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1Directrix2);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1Asymptote1);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1Asymptote2);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1Tangent);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1TangentU);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1TangentV);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1TwoPoints);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1Intersection);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1Proximity);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
|
||||
_boxes[1]->MapMode.setValue(mm0Origin);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm0Focus1);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm0Focus2);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm0OnEdge);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm0CenterOfCurvature);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm0CenterOfMass);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1Intersection);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm0Vertex);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm0ProximityPoint1);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm0ProximityPoint2);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
|
||||
_boxes[1]->MapMode.setValue(mm1AxisInertia1);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1AxisInertia2);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
_boxes[1]->MapMode.setValue(mm1AxisInertia3);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2)));
|
||||
|
||||
_boxes[1]->MapMode.setValue(mmInertialCS);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(
|
||||
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
|
||||
);
|
||||
|
||||
_boxes[1]->MapMode.setValue(mm1FaceNormal);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(
|
||||
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
|
||||
);
|
||||
|
||||
_boxes[1]->MapMode.setValue(mmOZX);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(
|
||||
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
|
||||
);
|
||||
_boxes[1]->MapMode.setValue(mmOZY);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(
|
||||
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
|
||||
);
|
||||
_boxes[1]->MapMode.setValue(mmOXY);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(
|
||||
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
|
||||
);
|
||||
_boxes[1]->MapMode.setValue(mmOXZ);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(
|
||||
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
|
||||
);
|
||||
_boxes[1]->MapMode.setValue(mmOYZ);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(
|
||||
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
|
||||
);
|
||||
_boxes[1]->MapMode.setValue(mmOYX);
|
||||
_boxes[1]->recomputeFeature();
|
||||
EXPECT_TRUE(
|
||||
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
|
||||
);
|
||||
}
|
||||
176
tests/src/Mod/Part/App/BRepMesh.cpp
Normal file
176
tests/src/Mod/Part/App/BRepMesh.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "Mod/Part/App/BRepMesh.h"
|
||||
|
||||
// NOLINTBEGIN
|
||||
class BRepMeshTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
std::vector<Part::BRepMesh::Domain> getNoDomains() const
|
||||
{
|
||||
std::vector<Part::BRepMesh::Domain> domains;
|
||||
return domains;
|
||||
}
|
||||
|
||||
std::vector<Part::BRepMesh::Domain> getEmptyDomains() const
|
||||
{
|
||||
Part::BRepMesh::Domain domain;
|
||||
std::vector<Part::BRepMesh::Domain> domains;
|
||||
domains.push_back(domain);
|
||||
domains.push_back(domain);
|
||||
return domains;
|
||||
}
|
||||
|
||||
std::vector<Part::BRepMesh::Domain> getConnectedDomains() const
|
||||
{
|
||||
Part::BRepMesh::Domain domain1;
|
||||
domain1.points.emplace_back(0, 0, 0);
|
||||
domain1.points.emplace_back(10, 0, 0);
|
||||
domain1.points.emplace_back(10, 10, 0);
|
||||
domain1.points.emplace_back(0, 10, 0);
|
||||
|
||||
{
|
||||
Part::BRepMesh::Facet f1;
|
||||
f1.I1 = 0;
|
||||
f1.I2 = 1;
|
||||
f1.I3 = 2;
|
||||
domain1.facets.emplace_back(f1);
|
||||
}
|
||||
{
|
||||
Part::BRepMesh::Facet f2;
|
||||
f2.I1 = 0;
|
||||
f2.I2 = 2;
|
||||
f2.I3 = 3;
|
||||
domain1.facets.emplace_back(f2);
|
||||
}
|
||||
|
||||
Part::BRepMesh::Domain domain2;
|
||||
domain2.points.emplace_back(0, 0, 0);
|
||||
domain2.points.emplace_back(0, 10, 0);
|
||||
domain2.points.emplace_back(0, 10, 10);
|
||||
domain2.points.emplace_back(0, 0, 10);
|
||||
|
||||
{
|
||||
Part::BRepMesh::Facet f1;
|
||||
f1.I1 = 0;
|
||||
f1.I2 = 1;
|
||||
f1.I3 = 2;
|
||||
domain2.facets.emplace_back(f1);
|
||||
}
|
||||
{
|
||||
Part::BRepMesh::Facet f2;
|
||||
f2.I1 = 0;
|
||||
f2.I2 = 2;
|
||||
f2.I3 = 3;
|
||||
domain2.facets.emplace_back(f2);
|
||||
}
|
||||
|
||||
std::vector<Part::BRepMesh::Domain> domains;
|
||||
domains.push_back(domain1);
|
||||
domains.push_back(domain2);
|
||||
return domains;
|
||||
}
|
||||
|
||||
std::vector<Part::BRepMesh::Domain> getUnconnectedDomains() const
|
||||
{
|
||||
double eps = 1.0e-10;
|
||||
Part::BRepMesh::Domain domain1;
|
||||
domain1.points.emplace_back(eps, eps, eps);
|
||||
domain1.points.emplace_back(10, 0, 0);
|
||||
domain1.points.emplace_back(10, 10, 0);
|
||||
domain1.points.emplace_back(eps, 10, eps);
|
||||
|
||||
{
|
||||
Part::BRepMesh::Facet f1;
|
||||
f1.I1 = 0;
|
||||
f1.I2 = 1;
|
||||
f1.I3 = 2;
|
||||
domain1.facets.emplace_back(f1);
|
||||
}
|
||||
{
|
||||
Part::BRepMesh::Facet f2;
|
||||
f2.I1 = 0;
|
||||
f2.I2 = 2;
|
||||
f2.I3 = 3;
|
||||
domain1.facets.emplace_back(f2);
|
||||
}
|
||||
|
||||
Part::BRepMesh::Domain domain2;
|
||||
domain2.points.emplace_back(0, 0, 0);
|
||||
domain2.points.emplace_back(0, 10, 0);
|
||||
domain2.points.emplace_back(0, 10, 10);
|
||||
domain2.points.emplace_back(0, 0, 10);
|
||||
|
||||
{
|
||||
Part::BRepMesh::Facet f1;
|
||||
f1.I1 = 0;
|
||||
f1.I2 = 1;
|
||||
f1.I3 = 2;
|
||||
domain2.facets.emplace_back(f1);
|
||||
}
|
||||
{
|
||||
Part::BRepMesh::Facet f2;
|
||||
f2.I1 = 0;
|
||||
f2.I2 = 2;
|
||||
f2.I3 = 3;
|
||||
domain2.facets.emplace_back(f2);
|
||||
}
|
||||
|
||||
std::vector<Part::BRepMesh::Domain> domains;
|
||||
domains.push_back(domain1);
|
||||
domains.push_back(domain2);
|
||||
return domains;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(BRepMeshTest, testNoDomains)
|
||||
{
|
||||
std::vector<Base::Vector3d> points;
|
||||
std::vector<Part::BRepMesh::Facet> faces;
|
||||
Part::BRepMesh brepMesh;
|
||||
brepMesh.getFacesFromDomains(getNoDomains(), points, faces);
|
||||
|
||||
EXPECT_TRUE(points.empty());
|
||||
EXPECT_TRUE(faces.empty());
|
||||
}
|
||||
|
||||
TEST_F(BRepMeshTest, testEmptyDomains)
|
||||
{
|
||||
std::vector<Base::Vector3d> points;
|
||||
std::vector<Part::BRepMesh::Facet> faces;
|
||||
Part::BRepMesh brepMesh;
|
||||
brepMesh.getFacesFromDomains(getEmptyDomains(), points, faces);
|
||||
|
||||
EXPECT_TRUE(points.empty());
|
||||
EXPECT_TRUE(faces.empty());
|
||||
}
|
||||
|
||||
TEST_F(BRepMeshTest, testConnectedDomains)
|
||||
{
|
||||
std::vector<Base::Vector3d> points;
|
||||
std::vector<Part::BRepMesh::Facet> faces;
|
||||
Part::BRepMesh brepMesh;
|
||||
brepMesh.getFacesFromDomains(getConnectedDomains(), points, faces);
|
||||
|
||||
EXPECT_EQ(points.size(), 6);
|
||||
EXPECT_EQ(faces.size(), 4);
|
||||
}
|
||||
|
||||
TEST_F(BRepMeshTest, testUnconnectedDomains)
|
||||
{
|
||||
std::vector<Base::Vector3d> points;
|
||||
std::vector<Part::BRepMesh::Facet> faces;
|
||||
Part::BRepMesh brepMesh;
|
||||
brepMesh.getFacesFromDomains(getUnconnectedDomains(), points, faces);
|
||||
|
||||
EXPECT_EQ(points.size(), 6);
|
||||
EXPECT_EQ(faces.size(), 4);
|
||||
}
|
||||
// NOLINTEND
|
||||
47
tests/src/Mod/Part/App/CMakeLists.txt
Normal file
47
tests/src/Mod/Part/App/CMakeLists.txt
Normal file
@@ -0,0 +1,47 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(Part_tests_run
|
||||
Attacher.cpp
|
||||
AttachExtension.cpp
|
||||
BRepMesh.cpp
|
||||
FeatureChamfer.cpp
|
||||
FeatureCompound.cpp
|
||||
FeatureExtrusion.cpp
|
||||
FeatureFillet.cpp
|
||||
FeatureMirroring.cpp
|
||||
FeatureOffset.cpp
|
||||
FeaturePartBoolean.cpp
|
||||
FeaturePartCommon.cpp
|
||||
FeaturePartCut.cpp
|
||||
FeaturePartFuse.cpp
|
||||
FeatureRevolution.cpp
|
||||
FuzzyBoolean.cpp
|
||||
Geometry.cpp
|
||||
PartFeature.cpp
|
||||
PartFeatures.cpp
|
||||
PartTestHelpers.cpp
|
||||
PropertyTopoShape.cpp
|
||||
TopoDS_Shape.cpp
|
||||
TopoShape.cpp
|
||||
TopoShapeCache.cpp
|
||||
TopoShapeExpansion.cpp
|
||||
TopoShapeMakeElementRefine.cpp
|
||||
TopoShapeMakeShapeWithElementMap.cpp
|
||||
TopoShapeMapper.cpp
|
||||
TopoShapeMakeShape.cpp
|
||||
WireJoiner.cpp
|
||||
)
|
||||
|
||||
set(PartTestData_Files
|
||||
brepfiles/cylinder1.brep
|
||||
brepfiles/helix1.brep
|
||||
)
|
||||
|
||||
ADD_CUSTOM_TARGET(PartTestData ALL
|
||||
SOURCES ${PartTestData_Files}
|
||||
)
|
||||
|
||||
fc_target_copy_resource(PartTestData
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR}/tests
|
||||
${PartTestData_Files})
|
||||
141
tests/src/Mod/Part/App/FeatureChamfer.cpp
Normal file
141
tests/src/Mod/Part/App/FeatureChamfer.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
#include "Mod/Part/App/FeatureChamfer.h"
|
||||
|
||||
class FeatureChamferTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_boxes[0]->Length.setValue(length);
|
||||
_boxes[0]->Width.setValue(width);
|
||||
_boxes[0]->Height.setValue(height);
|
||||
_boxes[0]->Placement.setValue(
|
||||
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())
|
||||
);
|
||||
_boxes[1]->Placement.setValue(
|
||||
Base::Placement(Base::Vector3d(0, 1, height), Base::Rotation(), Base::Vector3d())
|
||||
);
|
||||
_boxes[1]->Length.setValue(1);
|
||||
_boxes[1]->Width.setValue(2);
|
||||
_boxes[1]->Height.setValue(3);
|
||||
_fused = _doc->addObject<Part::Fuse>();
|
||||
_fused->Base.setValue(_boxes[0]);
|
||||
_fused->Tool.setValue(_boxes[1]);
|
||||
_fused->Refine.setValue(false);
|
||||
_fused->execute();
|
||||
_chamfer = _doc->addObject<Part::Chamfer>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
const double length = 4.0;
|
||||
const double width = 5.0;
|
||||
const double height = 6.0;
|
||||
const double chamfer = 0.5;
|
||||
Part::Fuse* _fused = nullptr;
|
||||
Part::Chamfer* _chamfer = nullptr;
|
||||
// NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
};
|
||||
|
||||
// Unfortunately for these next two tests, there are upstream errors in OCCT
|
||||
// at least until 7.5.2 that cause some chamfers that intersect each other to
|
||||
// fail. Until that's fixed, test subsets of the complete chamfer list.
|
||||
|
||||
TEST_F(FeatureChamferTest, testOther)
|
||||
{
|
||||
const double baseVolume = _boxes[0]->Length.getValue() * _boxes[0]->Width.getValue()
|
||||
* _boxes[0]->Height.getValue()
|
||||
+ _boxes[1]->Length.getValue() * _boxes[1]->Width.getValue() * _boxes[1]->Height.getValue();
|
||||
// Arrange
|
||||
_chamfer->Base.setValue(_fused);
|
||||
Part::TopoShape ts = _fused->Shape.getValue();
|
||||
unsigned long sec = ts.countSubElements("Edge");
|
||||
// Assert
|
||||
EXPECT_EQ(sec, 25);
|
||||
// Act
|
||||
_fused->Refine.setValue(true);
|
||||
_fused->execute();
|
||||
ts = _fused->Shape.getValue();
|
||||
sec = ts.countSubElements("Edge");
|
||||
// Assert
|
||||
EXPECT_EQ(sec, 24);
|
||||
// Act
|
||||
_chamfer->Edges.setValues(PartTestHelpers::_getFilletEdges({1, 2}, chamfer, chamfer));
|
||||
double fusedVolume = PartTestHelpers::getVolume(_fused->Shape.getValue());
|
||||
double chamferVolume = PartTestHelpers::getVolume(_chamfer->Shape.getValue());
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(fusedVolume, baseVolume);
|
||||
EXPECT_DOUBLE_EQ(chamferVolume, 0.0);
|
||||
// Act
|
||||
_chamfer->execute();
|
||||
chamferVolume = PartTestHelpers::getVolume(_chamfer->Shape.getValue());
|
||||
double cv = (_boxes[0]->Length.getValue()) * chamfer * chamfer / 2
|
||||
+ (_boxes[0]->Height.getValue()) * chamfer * chamfer / 2 - chamfer * chamfer * chamfer / 3;
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(chamferVolume, baseVolume - cv);
|
||||
}
|
||||
|
||||
TEST_F(FeatureChamferTest, testMost)
|
||||
{
|
||||
// Arrange
|
||||
_fused->Refine.setValue(true);
|
||||
_fused->execute();
|
||||
_chamfer->Base.setValue(_fused);
|
||||
_chamfer->Edges.setValues(
|
||||
PartTestHelpers::_getFilletEdges(
|
||||
{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // NOLINT magic number
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, // NOLINT magic number
|
||||
0.4, // NOLINT magic number
|
||||
0.4
|
||||
)
|
||||
); // NOLINT magic number
|
||||
// Act
|
||||
_chamfer->execute();
|
||||
double chamferVolume = PartTestHelpers::getVolume(_chamfer->Shape.getValue());
|
||||
// Assert
|
||||
EXPECT_NEAR(chamferVolume, 121.46667, 1e-5); // This is calculable, but painful.
|
||||
}
|
||||
|
||||
// Worth noting that FeaturePartCommon with insufficient parameters says MustExecute false,
|
||||
// but FeatureChamfer says MustExecute true. Not a condition that should ever really be hit.
|
||||
|
||||
TEST_F(FeatureChamferTest, testMustExecute)
|
||||
{
|
||||
// Assert
|
||||
EXPECT_TRUE(_chamfer->mustExecute());
|
||||
// Act
|
||||
_chamfer->Base.setValue(_boxes[0]);
|
||||
// Assert
|
||||
EXPECT_TRUE(_chamfer->mustExecute());
|
||||
// Act
|
||||
_chamfer->Edges.setValues(PartTestHelpers::_getFilletEdges({1}, chamfer, chamfer));
|
||||
// Assert
|
||||
EXPECT_TRUE(_chamfer->mustExecute());
|
||||
// Act
|
||||
_doc->recompute();
|
||||
// Assert
|
||||
EXPECT_FALSE(_chamfer->mustExecute());
|
||||
}
|
||||
|
||||
TEST_F(FeatureChamferTest, testGetProviderName)
|
||||
{
|
||||
// Act
|
||||
_chamfer->execute();
|
||||
const char* name = _chamfer->getViewProviderName();
|
||||
// Assert
|
||||
EXPECT_STREQ(name, "PartGui::ViewProviderChamfer");
|
||||
}
|
||||
59
tests/src/Mod/Part/App/FeatureCompound.cpp
Normal file
59
tests/src/Mod/Part/App/FeatureCompound.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Mod/Part/App/FeatureCompound.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
class FeatureCompoundTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_compound = _doc->addObject<Part::Compound>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
Part::Compound* _compound = nullptr; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
TEST_F(FeatureCompoundTest, testIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_compound->Links.setValues({_boxes[0], _boxes[1]});
|
||||
// Act
|
||||
_compound->execute();
|
||||
Part::TopoShape ts = _compound->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 12.0);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0.0, 0.0, 0.0, 1.0, 3.0, 3.0)));
|
||||
EXPECT_EQ(ts.countSubShapes(TopAbs_SHAPE), 2);
|
||||
}
|
||||
|
||||
TEST_F(FeatureCompoundTest, testNonIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_compound->Links.setValues({_boxes[0], _boxes[2]});
|
||||
// Act
|
||||
_compound->execute();
|
||||
Part::TopoShape ts = _compound->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 12.0);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0.0, 0.0, 0.0, 1.0, 5.0, 3.0)));
|
||||
EXPECT_EQ(ts.countSubShapes(TopAbs_SHAPE), 2);
|
||||
}
|
||||
333
tests/src/Mod/Part/App/FeatureExtrusion.cpp
Normal file
333
tests/src/Mod/Part/App/FeatureExtrusion.cpp
Normal file
@@ -0,0 +1,333 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <cmath>
|
||||
#include <Base/Tools.h>
|
||||
#include "Mod/Part/App/FeatureExtrusion.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "BRepBuilderAPI_MakeEdge.hxx"
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
class FeatureExtrusionTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_extrusion = _doc->addObject<Part::Extrusion>();
|
||||
PartTestHelpers::rectangle(len, wid, "Rect1");
|
||||
_extrusion->Base.setValue(_doc->getObjects().back());
|
||||
_extrusion->LengthFwd.setValue(ext1);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
Part::Extrusion* _extrusion = nullptr;
|
||||
// Arbtitrary constants for testing. Named here for clarity.
|
||||
const double len = 3.0;
|
||||
const double wid = 4.0;
|
||||
const double ext1 = 10.0;
|
||||
// NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
};
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testMustExecute)
|
||||
{
|
||||
// Assert
|
||||
EXPECT_TRUE(_extrusion->mustExecute());
|
||||
// Act
|
||||
_doc->recompute();
|
||||
// Assert
|
||||
EXPECT_FALSE(_extrusion->mustExecute());
|
||||
// Act
|
||||
_extrusion->Base.setValue(_extrusion->Base.getValue());
|
||||
// Assert
|
||||
EXPECT_TRUE(_extrusion->mustExecute());
|
||||
// Act
|
||||
_doc->recompute();
|
||||
// Assert
|
||||
EXPECT_FALSE(_extrusion->mustExecute());
|
||||
// Act
|
||||
_extrusion->Solid.setValue(Standard_True);
|
||||
// Assert
|
||||
EXPECT_TRUE(_extrusion->mustExecute());
|
||||
// Act
|
||||
_doc->recompute();
|
||||
// Assert
|
||||
EXPECT_FALSE(_extrusion->mustExecute());
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testGetProviderName)
|
||||
{
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
const char* name = _extrusion->getViewProviderName();
|
||||
// Assert
|
||||
EXPECT_STREQ(name, "PartGui::ViewProviderExtrusion");
|
||||
}
|
||||
|
||||
// Not clear if there is test value in this one.
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testFetchAxisLink)
|
||||
{
|
||||
// static bool fetchAxisLink(const App::PropertyLinkSub& axisLink,
|
||||
// Base::Vector3d& basepoint,
|
||||
// Base::Vector3d& dir);
|
||||
}
|
||||
|
||||
// Filling in these next two tests seems very redundant, since they are used in execute()
|
||||
// and thus tested by the results there. In the event that ever went funny, then maybe
|
||||
// implementation here would make sense.
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExtrudeShape)
|
||||
{
|
||||
// static TopoShape extrudeShape(const TopoShape& source, const ExtrusionParameters& params);
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testComputeFinalParameters)
|
||||
{
|
||||
// ExtrusionParameters computeFinalParameters();
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExecuteSimple)
|
||||
{
|
||||
// Arrange
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, len * wid * ext1);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, len, wid, ext1)));
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExecuteSimpleRev)
|
||||
{
|
||||
const double ext2 = 9;
|
||||
// Arrange
|
||||
_extrusion->LengthFwd.setValue(0);
|
||||
_extrusion->LengthRev.setValue(ext2);
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, len * wid * ext2);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -ext2, len, wid, 0)));
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExecuteSolid)
|
||||
{
|
||||
// Arrange
|
||||
_extrusion->Solid.setValue(true);
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, len * wid * ext1);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, len, wid, ext1)));
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExecuteReverse)
|
||||
{
|
||||
// Arrange
|
||||
_extrusion->Reversed.setValue(true);
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, len * wid * ext1);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -ext1, len, wid, 0)));
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExecuteSymmetric)
|
||||
{
|
||||
// Arrange
|
||||
_extrusion->Symmetric.setValue(true);
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, len * wid * ext1);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -ext1 / 2, len, wid, ext1 / 2)));
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExecuteAngled)
|
||||
{
|
||||
// Arrange
|
||||
const double ang = 30;
|
||||
const double tangent = tan(Base::toRadians(ang));
|
||||
|
||||
// The shape is a truncated pyramid elongated by a truncated triangular prism in the middle.
|
||||
// Calc the volume of full size pyramid and prism, and subtract top volumes to truncate.
|
||||
const double shorterSide = len > wid ? wid : len;
|
||||
const double longerSide = len < wid ? wid : len;
|
||||
const double centerWidth = longerSide - shorterSide; // Width of the triang prism.
|
||||
const double topHeight = shorterSide / tangent / 2; // Height of the truncation
|
||||
const double fullHeight = ext1 + topHeight;
|
||||
const double fullPrismVol = fullHeight * (shorterSide + ext1 * tangent * 2.0) / 2.0 * centerWidth;
|
||||
const double fullPyrVol = pow(shorterSide + ext1 * tangent * 2.0, 2.0) / 3.0 * fullHeight;
|
||||
const double topPrismVol = topHeight * shorterSide / 2.0 * centerWidth;
|
||||
const double topPyrVol = pow(shorterSide, 2.0) / 3.0 * topHeight;
|
||||
const double targetVol = (fullPyrVol + fullPrismVol) - (topPyrVol + topPrismVol);
|
||||
_extrusion->Solid.setValue(true);
|
||||
_extrusion->TaperAngle.setValue(ang);
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, targetVol);
|
||||
EXPECT_TRUE(
|
||||
PartTestHelpers::boxesMatch(
|
||||
bb,
|
||||
Base::BoundBox3d(-ext1 * tangent, -ext1 * tangent, 0, len + ext1 * tangent, wid + ext1 * tangent, ext1)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExecuteAngledRev)
|
||||
{
|
||||
// Arrange
|
||||
const double ang = 30;
|
||||
const double tangent = tan(Base::toRadians(ang));
|
||||
// The shape is a truncated pyramid elongated by a truncated triangular prism in the middle,
|
||||
// plus a rectangular prism.
|
||||
// Calc the volume of full size pyramid and prism, and subtract top volumes to truncate.
|
||||
const double shorterSide = len > wid ? wid : len;
|
||||
const double longerSide = len < wid ? wid : len;
|
||||
const double centerWidth = longerSide - shorterSide; // Width of the triang prism.
|
||||
const double topHeight = shorterSide / tangent / 2; // Height of the truncation
|
||||
const double fullHeight = ext1 / 2 + topHeight;
|
||||
const double fullPrismVol = fullHeight * (shorterSide + ext1 / 2 * tangent * 2.0) / 2.0
|
||||
* centerWidth;
|
||||
const double fullPyrVol = pow(shorterSide + ext1 / 2 * tangent * 2.0, 2.0) / 3.0 * fullHeight;
|
||||
const double topPrismVol = topHeight * shorterSide / 2.0 * centerWidth;
|
||||
const double topPyrVol = pow(shorterSide, 2.0) / 3.0 * topHeight;
|
||||
const double targetVol = (fullPyrVol + fullPrismVol) - (topPyrVol + topPrismVol)
|
||||
+ len * wid * ext1 / 2;
|
||||
|
||||
_extrusion->Solid.setValue(true);
|
||||
_extrusion->Symmetric.setValue(true);
|
||||
_extrusion->TaperAngleRev.setValue(ang);
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, targetVol);
|
||||
EXPECT_TRUE(
|
||||
PartTestHelpers::boxesMatch(
|
||||
bb,
|
||||
Base::BoundBox3d(
|
||||
-ext1 * tangent / 2,
|
||||
-ext1 * tangent / 2,
|
||||
-ext1 / 2,
|
||||
len + ext1 * tangent / 2,
|
||||
wid + ext1 * tangent / 2,
|
||||
ext1 / 2
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExecuteEdge)
|
||||
{
|
||||
// Arrange
|
||||
const double ang = 30;
|
||||
const double tangent = tan(Base::toRadians(ang));
|
||||
BRepBuilderAPI_MakeEdge e1(gp_Pnt(0, 0, 0), gp_Pnt(ext1, ext1, ext1));
|
||||
auto edge = _doc->addObject<Part::Feature>("Edge");
|
||||
edge->Shape.setValue(e1);
|
||||
_extrusion->DirLink.setValue(edge);
|
||||
_extrusion->DirMode.setValue(1);
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, len * wid * ext1 * tangent);
|
||||
EXPECT_TRUE(
|
||||
PartTestHelpers::boxesMatch(
|
||||
bb,
|
||||
Base::BoundBox3d(0, 0, 0, len + ext1 * tangent, wid + ext1 * tangent, ext1 * tangent)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExecuteDir)
|
||||
{
|
||||
// Arrange
|
||||
const double sin45 = sin(Base::toRadians(45.0));
|
||||
_extrusion->Dir.setValue(Base::Vector3d(0, 1, 1));
|
||||
_extrusion->DirMode.setValue((long)0);
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, len * wid * ext1 * sin45);
|
||||
EXPECT_TRUE(
|
||||
PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, len, wid + ext1 * sin45, ext1 * sin45))
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testExecuteFaceMaker)
|
||||
{
|
||||
// Arrange
|
||||
_extrusion->FaceMakerClass.setValue("Part::FaceMakerCheese");
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, len * wid * ext1);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, len, wid, ext1)));
|
||||
}
|
||||
|
||||
TEST_F(FeatureExtrusionTest, testFaceWithHoles)
|
||||
{
|
||||
// Arrange
|
||||
float radius = 0.75;
|
||||
auto [face1, wire1, wire2] = PartTestHelpers::CreateFaceWithRoundHole(len, wid, radius);
|
||||
// face1 is the sum of the outside (wire1) and the internal hole (wire2).
|
||||
Part::TopoShape newFace = Part::TopoShape(face1).makeElementFace(nullptr);
|
||||
// newFace cleans that up and is the outside minus the internal hole.
|
||||
auto face2 = newFace.getShape();
|
||||
|
||||
auto partFeature = _doc->addObject<Part::Feature>();
|
||||
partFeature->Shape.setValue(face2);
|
||||
_extrusion->Base.setValue(_doc->getObjects().back());
|
||||
_extrusion->FaceMakerClass.setValue("Part::FaceMakerCheese");
|
||||
// Act
|
||||
_extrusion->execute();
|
||||
Part::TopoShape ts = _extrusion->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, len * wid * ext1 - radius * radius * std::numbers::pi * ext1);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, len, wid, ext1)));
|
||||
EXPECT_FLOAT_EQ(PartTestHelpers::getArea(face1), len * wid + radius * radius * std::numbers::pi);
|
||||
EXPECT_FLOAT_EQ(PartTestHelpers::getArea(face2), len * wid - radius * radius * std::numbers::pi);
|
||||
}
|
||||
165
tests/src/Mod/Part/App/FeatureFillet.cpp
Normal file
165
tests/src/Mod/Part/App/FeatureFillet.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
class FeatureFilletTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_boxes[0]->Length.setValue(4);
|
||||
_boxes[0]->Width.setValue(5);
|
||||
_boxes[0]->Height.setValue(6);
|
||||
_boxes[0]->Placement.setValue(
|
||||
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())
|
||||
);
|
||||
_boxes[1]->Placement.setValue(
|
||||
Base::Placement(Base::Vector3d(0, 1, 6), Base::Rotation(), Base::Vector3d())
|
||||
);
|
||||
_boxes[1]->Length.setValue(1);
|
||||
_boxes[1]->Width.setValue(2);
|
||||
_boxes[1]->Height.setValue(3);
|
||||
_fused = _doc->addObject<Part::Fuse>();
|
||||
_fused->Base.setValue(_boxes[0]);
|
||||
_fused->Tool.setValue(_boxes[1]);
|
||||
_fused->Refine.setValue(false);
|
||||
_fused->execute();
|
||||
_fillet = _doc->addObject<Part::Fillet>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
Part::Fuse* _fused = nullptr; // NOLINT Can't be private in a test framework
|
||||
Part::Fillet* _fillet = nullptr; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
// Unfortunately for these next two tests, there are upstream errors in OCCT
|
||||
// at least until 7.5.2 that cause some fillets that intersect each other to
|
||||
// fail. Until that's fixed, test subsets of the complete fillet list.
|
||||
|
||||
TEST_F(FeatureFilletTest, testOtherEdges)
|
||||
{
|
||||
const double baseVolume = _boxes[0]->Length.getValue() * _boxes[0]->Width.getValue()
|
||||
* _boxes[0]->Height.getValue()
|
||||
+ _boxes[1]->Length.getValue() * _boxes[1]->Width.getValue() * _boxes[1]->Height.getValue();
|
||||
// Arrange
|
||||
_fillet->Base.setValue(_fused);
|
||||
Part::TopoShape ts = _fused->Shape.getValue();
|
||||
unsigned long sec = ts.countSubElements("Edge");
|
||||
// Assert
|
||||
EXPECT_EQ(sec, 25);
|
||||
// Act
|
||||
_fused->Refine.setValue(true);
|
||||
_fused->execute();
|
||||
ts = _fused->Shape.getValue();
|
||||
sec = ts.countSubElements("Edge");
|
||||
// Assert
|
||||
EXPECT_EQ(sec, 24);
|
||||
|
||||
// Act
|
||||
_fillet->Edges.setValues(PartTestHelpers::_getFilletEdges({15, 17}, 0.5, 0.5));
|
||||
double fusedVolume = PartTestHelpers::getVolume(_fused->Shape.getValue());
|
||||
double filletVolume = PartTestHelpers::getVolume(_fillet->Shape.getValue());
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(fusedVolume, baseVolume);
|
||||
EXPECT_DOUBLE_EQ(filletVolume, 0.0);
|
||||
// Act
|
||||
_fillet->execute();
|
||||
filletVolume = PartTestHelpers::getVolume(_fillet->Shape.getValue());
|
||||
// Assert
|
||||
EXPECT_NEAR(filletVolume, 125.57079, 1e-5);
|
||||
}
|
||||
|
||||
TEST_F(FeatureFilletTest, testMostEdges)
|
||||
{
|
||||
// Arrange
|
||||
_fused->Refine.setValue(true);
|
||||
// _fused->execute();
|
||||
_fillet->Base.setValue(_fused);
|
||||
_fillet->Edges.setValues(
|
||||
PartTestHelpers::_getFilletEdges(
|
||||
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 19, 20, 22, 23, 24},
|
||||
0.4,
|
||||
0.4
|
||||
)
|
||||
);
|
||||
// Act
|
||||
_fillet->execute();
|
||||
double filletVolume = PartTestHelpers::getVolume(_fillet->Shape.getValue());
|
||||
// Assert
|
||||
EXPECT_NEAR(filletVolume, 118.38763, 1e-5);
|
||||
}
|
||||
|
||||
// Worth noting that FeaturePartCommon with insufficient parameters says MustExecute false,
|
||||
// but FeatureFillet says MustExecute true. Not a condition that should ever really be hit.
|
||||
|
||||
TEST_F(FeatureFilletTest, testMustExecute)
|
||||
{
|
||||
// Assert
|
||||
EXPECT_TRUE(_fillet->mustExecute());
|
||||
// Act
|
||||
_fillet->Base.setValue(_boxes[0]);
|
||||
// Assert
|
||||
EXPECT_TRUE(_fillet->mustExecute());
|
||||
// Act
|
||||
_fillet->Edges.setValues(PartTestHelpers::_getFilletEdges({1}, 0.5, 0.5));
|
||||
// Assert
|
||||
EXPECT_TRUE(_fillet->mustExecute());
|
||||
// Act
|
||||
_doc->recompute();
|
||||
// Assert
|
||||
EXPECT_FALSE(_fillet->mustExecute());
|
||||
}
|
||||
|
||||
TEST_F(FeatureFilletTest, testGetProviderName)
|
||||
{
|
||||
// Act
|
||||
_fillet->execute();
|
||||
const char* name = _fillet->getViewProviderName();
|
||||
// Assert
|
||||
EXPECT_STREQ(name, "PartGui::ViewProviderFillet");
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
// void PrintTo(const TopoDS_Shape& ds, std::ostream* os)
|
||||
// {
|
||||
// *os << "TopoDS_Shape ";
|
||||
// for (TopExp_Explorer ex(ds, TopAbs_VERTEX); ex.More(); ex.Next()) {
|
||||
// gp_Pnt point = BRep_Tool::Pnt(TopoDS::Vertex(ex.Current()));
|
||||
// *os << "(" << point.X() << "," << point.Y() << "," << point.Z() << ") ";
|
||||
// }
|
||||
// *os << std::endl;
|
||||
// }
|
||||
|
||||
// void edgesAtBusyVertexes(Part::TopoShape ts)
|
||||
// {
|
||||
// const char* categories[] = { "Face", "Wire", "Edge", "Vertex" };
|
||||
|
||||
// for (auto category : categories ) {
|
||||
// int count = ts.countSubShapes(category);
|
||||
// for ( int index=1; index <= count; index++ ) {
|
||||
// std::string name = category + std::to_string(index);
|
||||
// const char * cname = name.c_str();
|
||||
// TopoDS_Shape ss = ts.getSubShape(cname);
|
||||
// os << cname << ": ";
|
||||
// for (TopExp_Explorer ex(ss, TopAbs_VERTEX); ex.More(); ex.Next()) {
|
||||
// gp_Pnt point = BRep_Tool::Pnt(TopoDS::Vertex(ex.Current()));
|
||||
// os << "(" << point.X() << "," << point.Y() << "," << point.Z() << ") ";
|
||||
// }
|
||||
// os << std::endl;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
146
tests/src/Mod/Part/App/FeatureMirroring.cpp
Normal file
146
tests/src/Mod/Part/App/FeatureMirroring.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <Mod/Part/App/FeatureMirroring.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
using namespace PartTestHelpers;
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
class FeatureMirroringTest: public ::testing::Test, public PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_mirror = _doc->addObject<Part::Mirroring>();
|
||||
_mirror->Source.setValue(_boxes[0]);
|
||||
_mirror->Base.setValue(1, 0, 0);
|
||||
_mirror->execute();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
Part::Mirroring* _mirror = nullptr; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
TEST_F(FeatureMirroringTest, testXMirror)
|
||||
{
|
||||
// Arrange
|
||||
Base::BoundBox3d bb = _mirror->Shape.getShape().getBoundBox();
|
||||
// Assert size and position
|
||||
EXPECT_EQ(getVolume(_mirror->Shape.getShape().getShape()), 6);
|
||||
// Mirrored it around X from 0,0,0 -> 1,2,3 to 0,0,-3 -> 1,2,0
|
||||
EXPECT_TRUE(boxesMatch(bb, Base::BoundBox3d(0, 0, -3, 1, 2, 0)));
|
||||
// Assert correct element Map
|
||||
EXPECT_TRUE(allElementsMatch(
|
||||
_mirror->Shape.getShape(),
|
||||
{
|
||||
"Edge10;:M;MIR;:H70c:7,E", "Edge11;:M;MIR;:H70c:7,E", "Edge12;:M;MIR;:H70c:7,E",
|
||||
"Edge1;:M;MIR;:H70c:7,E", "Edge2;:M;MIR;:H70c:7,E", "Edge3;:M;MIR;:H70c:7,E",
|
||||
"Edge4;:M;MIR;:H70c:7,E", "Edge5;:M;MIR;:H70c:7,E", "Edge6;:M;MIR;:H70c:7,E",
|
||||
"Edge7;:M;MIR;:H70c:7,E", "Edge8;:M;MIR;:H70c:7,E", "Edge9;:M;MIR;:H70c:7,E",
|
||||
"Face1;:M;MIR;:H70c:7,F", "Face2;:M;MIR;:H70c:7,F", "Face3;:M;MIR;:H70c:7,F",
|
||||
"Face4;:M;MIR;:H70c:7,F", "Face5;:M;MIR;:H70c:7,F", "Face6;:M;MIR;:H70c:7,F",
|
||||
"Vertex1;:M;MIR;:H70c:7,V", "Vertex2;:M;MIR;:H70c:7,V", "Vertex3;:M;MIR;:H70c:7,V",
|
||||
"Vertex4;:M;MIR;:H70c:7,V", "Vertex5;:M;MIR;:H70c:7,V", "Vertex6;:M;MIR;:H70c:7,V",
|
||||
"Vertex7;:M;MIR;:H70c:7,V", "Vertex8;:M;MIR;:H70c:7,V",
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
TEST_F(FeatureMirroringTest, testYMirrorWithExistingElementMap)
|
||||
{
|
||||
// Arrange
|
||||
Part::Fuse* _fuse = nullptr; // NOLINT Can't be private in a test framework
|
||||
_fuse = _doc->addObject<Part::Fuse>();
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
_fuse->Tool.setValue(_boxes[1]);
|
||||
_fuse->Refine.setValue(false);
|
||||
// Act
|
||||
_fuse->execute();
|
||||
_mirror->Source.setValue(_fuse);
|
||||
_mirror->Base.setValue(0, 1, 0); // Y Axis
|
||||
Part::TopoShape ts = _fuse->Shape.getValue();
|
||||
double volume = getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = _mirror->Shape.getShape().getBoundBox();
|
||||
// Assert size and position
|
||||
EXPECT_EQ(getVolume(_mirror->Shape.getShape().getShape()), volume);
|
||||
// Mirrored it around X from 0,0,0 -> 1,2,3 to 0,0,-3 -> 1,2,0
|
||||
EXPECT_TRUE(boxesMatch(bb, Base::BoundBox3d(0, 0, -3, 1, 3, 0)));
|
||||
// Assert correct element Map
|
||||
EXPECT_TRUE(elementsMatch(
|
||||
_mirror->Shape.getShape(),
|
||||
{
|
||||
"Edge10;:H11c3,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge10;:H11c4,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge11;:H11c3,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge11;:H11c4,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge12;:H11c3,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge12;:H11c4,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge1;:H11c3,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge1;:H11c4,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge2;:M2(Edge2;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge2;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge2;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge3;:H11c3,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge3;:H11c4,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge4;:M2(Edge4;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge4;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge4;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge5;:H11c3,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge5;:H11c4,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge6;:M2(Edge6;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge6;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge6;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge7;:H11c3,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge7;:H11c4,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge8;:M2(Edge8;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge8;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge8;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge9;:H11c3,E;:M;MIR;:H11ca:7,E",
|
||||
"Edge9;:H11c4,E;:M;MIR;:H11ca:7,E",
|
||||
"Face1;:M2(Face1;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
|
||||
"Face1;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
|
||||
"Face1;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
|
||||
"Face2;:M2(Face2;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
|
||||
"Face2;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
|
||||
"Face2;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
|
||||
"Face3;:H11c3,F;:M;MIR;:H11ca:7,F",
|
||||
"Face4;:H11c4,F;:M;MIR;:H11ca:7,F",
|
||||
"Face5;:M2(Face5;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
|
||||
"Face5;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
|
||||
"Face5;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
|
||||
"Face6;:M2(Face6;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
|
||||
"Face6;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
|
||||
"Face6;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
|
||||
"Vertex1;:H11c3,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex1;:H11c4,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex2;:H11c3,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex2;:H11c4,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex3;:H11c3,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex3;:H11c4,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex4;:H11c3,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex4;:H11c4,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex5;:H11c3,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex5;:H11c4,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex6;:H11c3,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex6;:H11c4,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex7;:H11c3,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex7;:H11c4,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex8;:H11c3,V;:M;MIR;:H11ca:7,V",
|
||||
"Vertex8;:H11c4,V;:M;MIR;:H11ca:7,V",
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
97
tests/src/Mod/Part/App/FeatureOffset.cpp
Normal file
97
tests/src/Mod/Part/App/FeatureOffset.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
#include "Mod/Part/App/FeatureOffset.h"
|
||||
|
||||
using namespace PartTestHelpers;
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
class FeatureOffsetTest: public ::testing::Test, public PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_offset = _doc->addObject<Part::Offset>();
|
||||
_offset->Source.setValue(_boxes[0]);
|
||||
_offset->Value.setValue(1);
|
||||
_offset->Join.setValue((int)JoinType::intersection);
|
||||
_offset->execute();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
Part::Offset* _offset = nullptr; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
TEST_F(FeatureOffsetTest, testOffset3D)
|
||||
{
|
||||
// Arrange
|
||||
Base::BoundBox3d bb = _offset->Shape.getShape().getBoundBox();
|
||||
// Assert size and position
|
||||
// a 1x2x3 box 3doffset by 1 becomes a 3x4x5 box, so volume is 60.
|
||||
EXPECT_EQ(getVolume(_offset->Shape.getShape().getShape()), 60);
|
||||
EXPECT_TRUE(boxesMatch(bb, Base::BoundBox3d(-1, -1, -1, 2, 3, 4)));
|
||||
// Assert correct element Map
|
||||
EXPECT_EQ(_offset->Shape.getShape().countSubElements("Vertex"), 8);
|
||||
EXPECT_EQ(_offset->Shape.getShape().countSubElements("Edge"), 12);
|
||||
EXPECT_EQ(_offset->Shape.getShape().countSubElements("Face"), 6);
|
||||
}
|
||||
|
||||
TEST_F(FeatureOffsetTest, testOffset3DWithExistingElementMap)
|
||||
{
|
||||
// Arrange
|
||||
Part::Fuse* _fuse = nullptr; // NOLINT Can't be private in a test framework
|
||||
_fuse = _doc->addObject<Part::Fuse>();
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
_fuse->Tool.setValue(_boxes[1]);
|
||||
_fuse->Refine.setValue(true);
|
||||
// Act
|
||||
_fuse->execute();
|
||||
_offset->Source.setValue(_fuse);
|
||||
_offset->Value.setValue(2);
|
||||
_offset->execute();
|
||||
Base::BoundBox3d bb = _offset->Shape.getShape().getBoundBox();
|
||||
// Assert size and position
|
||||
// A 1x3x3 box 3doffset by 2 becomes a 5x7x7 box with volume of 245
|
||||
EXPECT_EQ(getVolume(_fuse->Shape.getShape().getShape()), 9);
|
||||
EXPECT_EQ(getVolume(_offset->Shape.getShape().getShape()), 245);
|
||||
EXPECT_TRUE(boxesMatch(bb, Base::BoundBox3d(-2, -2, -2, 3, 5, 5)));
|
||||
// Assert correct element Map
|
||||
EXPECT_EQ(_offset->Shape.getShape().countSubElements("Vertex"), 8);
|
||||
EXPECT_EQ(_offset->Shape.getShape().countSubElements("Edge"), 12);
|
||||
EXPECT_EQ(_offset->Shape.getShape().countSubElements("Face"), 6);
|
||||
}
|
||||
|
||||
TEST_F(FeatureOffsetTest, testOffset2D)
|
||||
{
|
||||
// Arrange
|
||||
Part::Offset2D* _offset2 = _doc->addObject<Part::Offset2D>();
|
||||
Part::Plane* _pln = _doc->addObject<Part::Plane>();
|
||||
_pln->Length.setValue(2);
|
||||
_pln->Width.setValue(3);
|
||||
_offset2->Source.setValue(_pln);
|
||||
_offset2->Value.setValue(1);
|
||||
_offset2->Join.setValue((int)JoinType::intersection);
|
||||
// Act
|
||||
_offset2->execute();
|
||||
Base::BoundBox3d bb = _offset2->Shape.getShape().getBoundBox();
|
||||
// Assert size and position
|
||||
// a 2x3 face 2doffset by 1 becomes a 4x5 face, so area is 20.
|
||||
EXPECT_EQ(getArea(_offset2->Shape.getShape().getShape()), 20);
|
||||
EXPECT_TRUE(boxesMatch(bb, Base::BoundBox3d(-1, -1, 0, 3, 4, 0)));
|
||||
// Assert correct element Map
|
||||
EXPECT_EQ(_offset2->Shape.getShape().getElementMapSize(), 9);
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
33
tests/src/Mod/Part/App/FeaturePartBoolean.cpp
Normal file
33
tests/src/Mod/Part/App/FeaturePartBoolean.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Mod/Part/App/FeaturePartBoolean.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
class FeaturePartBooleanTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
// createTestDoc();
|
||||
// _boolean = _doc->addObject<Part::Boolean>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
Part::Boolean* _boolean; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
// This is completely tested in the FeaturePartCommon, FeaturePartCut, FeaturePartFuse and
|
||||
// FeaturePartSection subclasses. This class is unfortunately not usable unless initialized in one
|
||||
// of those forms, so no testing at this level.
|
||||
209
tests/src/Mod/Part/App/FeaturePartCommon.cpp
Normal file
209
tests/src/Mod/Part/App/FeaturePartCommon.cpp
Normal file
@@ -0,0 +1,209 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Mod/Part/App/FeaturePartCommon.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
class FeaturePartCommonTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_common = _doc->addObject<Part::Common>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
Part::Common* _common = nullptr; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
TEST_F(FeaturePartCommonTest, testIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
|
||||
// Act
|
||||
_common->execute();
|
||||
Part::TopoShape ts = _common->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 3.0);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 2.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCommonTest, testNonIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[2]);
|
||||
|
||||
// Act
|
||||
_common->execute();
|
||||
Part::TopoShape ts = _common->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_FALSE(bb.IsValid());
|
||||
EXPECT_DOUBLE_EQ(volume, 0.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCommonTest, testTouching)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[3]);
|
||||
|
||||
// Act
|
||||
_common->execute();
|
||||
Part::TopoShape ts = _common->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_FALSE(bb.IsValid());
|
||||
EXPECT_DOUBLE_EQ(volume, 0.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCommonTest, testAlmostTouching)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[4]);
|
||||
|
||||
// Act
|
||||
_common->execute();
|
||||
Part::TopoShape ts = _common->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_FALSE(bb.IsValid());
|
||||
EXPECT_DOUBLE_EQ(volume, 0.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCommonTest, testBarelyIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[5]); // NOLINT magic number
|
||||
|
||||
// Act
|
||||
_common->execute();
|
||||
Part::TopoShape ts = _common->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
double target = PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
// Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07
|
||||
// rather than 1e15 See
|
||||
// https://google.github.io/googletest/reference/assertions.html#floating-point
|
||||
EXPECT_FLOAT_EQ(volume, target); // Should be approximately 0.00029999999999996696
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 2.0 - PartTestHelpers::minimalDistance);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 2.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCommonTest, testMustExecute)
|
||||
{
|
||||
// Assert initially we don't need to execute
|
||||
EXPECT_FALSE(_common->mustExecute());
|
||||
// Act to change one property
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
// Assert we still can't execute
|
||||
EXPECT_FALSE(_common->mustExecute());
|
||||
// Act to complete the properties we need
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
// Assert that we now must execute
|
||||
EXPECT_TRUE(_common->mustExecute());
|
||||
// Act to execute
|
||||
_doc->recompute();
|
||||
// Assert we don't need to execute anymore
|
||||
EXPECT_FALSE(_common->mustExecute());
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCommonTest, testGetProviderName)
|
||||
{
|
||||
// Act
|
||||
_common->execute();
|
||||
const char* name = _common->getViewProviderName();
|
||||
// Assert
|
||||
EXPECT_STREQ(name, "PartGui::ViewProviderBoolean");
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCommonTest, testHistory)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
// Manually create the histories classically generated by FreeCAD for comparison
|
||||
using MapList = std::map<int, std::vector<int>>;
|
||||
using List = std::vector<int>;
|
||||
MapList compare1 = {
|
||||
{0, List {0}},
|
||||
{1, List {5}}, // NOLINT magic number
|
||||
{2, List()},
|
||||
{3, List {2}},
|
||||
{4, List {3}},
|
||||
{5, List {1}}
|
||||
}; // NOLINT magic number
|
||||
MapList compare2 = {
|
||||
{0, List {0}},
|
||||
{1, List {5}}, // NOLINT magic number
|
||||
{2, List {4}},
|
||||
{3, List()},
|
||||
{4, List {3}},
|
||||
{5, List {1}}
|
||||
}; // NOLINT magic number
|
||||
|
||||
// Act and Assert no histories yet
|
||||
std::vector<Part::ShapeHistory> hist = _common->History.getValues();
|
||||
EXPECT_EQ(hist.size(), 0);
|
||||
|
||||
// Act to generate histories
|
||||
_common->execute();
|
||||
hist = _common->History.getValues();
|
||||
// Assert
|
||||
ASSERT_EQ(
|
||||
hist.size(),
|
||||
0
|
||||
); // TODO: with TNP enabled, this becomes 0, matches the code. Correct?
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCommonTest, testMapping)
|
||||
{
|
||||
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
// Act
|
||||
_common->execute();
|
||||
const Part::TopoShape& ts1 = _common->Shape.getShape();
|
||||
// Assert
|
||||
EXPECT_EQ(ts1.getElementMap().size(), 26);
|
||||
}
|
||||
189
tests/src/Mod/Part/App/FeaturePartCut.cpp
Normal file
189
tests/src/Mod/Part/App/FeaturePartCut.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Mod/Part/App/FeaturePartCut.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
class FeaturePartCutTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_cut = _doc->addObject<Part::Cut>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
Part::Cut* _cut = nullptr; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
TEST_F(FeaturePartCutTest, testIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_cut->Base.setValue(_boxes[0]);
|
||||
_cut->Tool.setValue(_boxes[1]);
|
||||
|
||||
// Act
|
||||
_cut->execute();
|
||||
Part::TopoShape ts = _cut->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 3.0);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCutTest, testNonIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_cut->Base.setValue(_boxes[0]);
|
||||
_cut->Tool.setValue(_boxes[2]);
|
||||
|
||||
// Act
|
||||
_cut->execute();
|
||||
Part::TopoShape ts = _cut->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 6.0);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 2.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCutTest, testTouching)
|
||||
{
|
||||
// Arrange
|
||||
_cut->Base.setValue(_boxes[0]);
|
||||
_cut->Tool.setValue(_boxes[3]);
|
||||
|
||||
// Act
|
||||
_cut->execute();
|
||||
Part::TopoShape ts = _cut->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 6.0);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 2.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCutTest, testAlmostTouching)
|
||||
{
|
||||
// Arrange
|
||||
_cut->Base.setValue(_boxes[0]);
|
||||
_cut->Tool.setValue(_boxes[4]);
|
||||
|
||||
// Act
|
||||
_cut->execute();
|
||||
Part::TopoShape ts = _cut->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 6.0);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 2.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCutTest, testBarelyIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_cut->Base.setValue(_boxes[0]);
|
||||
_cut->Tool.setValue(_boxes[5]); // NOLINT magic number
|
||||
|
||||
// Act
|
||||
_cut->execute();
|
||||
Part::TopoShape ts = _cut->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
double target = 6 - PartTestHelpers::minimalDistance * 3; // NOLINT 3 dimensions in a Volume
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
// Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07
|
||||
// rather than 1e15 See
|
||||
// https://google.github.io/googletest/reference/assertions.html#floating-point
|
||||
EXPECT_FLOAT_EQ(volume, target);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 2.0 - PartTestHelpers::minimalDistance);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCutTest, testMustExecute)
|
||||
{
|
||||
// Assert initially we don't need to execute
|
||||
EXPECT_FALSE(_cut->mustExecute());
|
||||
// Act to change one property
|
||||
_cut->Base.setValue(_boxes[0]);
|
||||
// Assert we still can't execute
|
||||
EXPECT_FALSE(_cut->mustExecute());
|
||||
// Act to complete the properties we need
|
||||
_cut->Tool.setValue(_boxes[1]);
|
||||
// Assert that we now must execute
|
||||
EXPECT_TRUE(_cut->mustExecute());
|
||||
// Act to execute
|
||||
_doc->recompute();
|
||||
// Assert we don't need to execute anymore
|
||||
EXPECT_FALSE(_cut->mustExecute());
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCutTest, testGetProviderName)
|
||||
{
|
||||
// Act
|
||||
_cut->execute();
|
||||
const char* name = _cut->getViewProviderName();
|
||||
// Assert
|
||||
EXPECT_STREQ(name, "PartGui::ViewProviderBoolean");
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartCutTest, testMapping)
|
||||
{
|
||||
|
||||
// Arrange
|
||||
_cut->Base.setValue(_boxes[0]);
|
||||
_cut->Tool.setValue(_boxes[1]);
|
||||
// Act
|
||||
_cut->execute();
|
||||
const Part::TopoShape& ts1 = _cut->Shape.getShape();
|
||||
// Assert
|
||||
EXPECT_EQ(ts1.getElementMap().size(), 26);
|
||||
}
|
||||
|
||||
// See FeaturePartCommon.cpp for a history test. It would be exactly the same and redundant here.
|
||||
272
tests/src/Mod/Part/App/FeaturePartFuse.cpp
Normal file
272
tests/src/Mod/Part/App/FeaturePartFuse.cpp
Normal file
@@ -0,0 +1,272 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Mod/Part/App/FeaturePartFuse.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
#include "Mod/Part/App/FeatureCompound.h"
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
|
||||
class FeaturePartFuseTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_fuse = _doc->addObject<Part::Fuse>();
|
||||
_multiFuse = _doc->addObject<Part::MultiFuse>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
Part::Fuse* _fuse = nullptr; // NOLINT Can't be private in a test framework
|
||||
Part::MultiFuse* _multiFuse = nullptr; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
TEST_F(FeaturePartFuseTest, testIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
_fuse->Tool.setValue(_boxes[1]);
|
||||
|
||||
// Act
|
||||
_fuse->execute();
|
||||
Part::TopoShape ts = _fuse->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 9.0);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 3.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartFuseTest, testCompound)
|
||||
{
|
||||
// Arrange
|
||||
Part::Compound* _compound = nullptr;
|
||||
_compound = _doc->addObject<Part::Compound>();
|
||||
_compound->Links.setValues({_boxes[0], _boxes[1]});
|
||||
_multiFuse->Shapes.setValues({_compound});
|
||||
|
||||
// Act
|
||||
_compound->execute();
|
||||
_multiFuse->execute();
|
||||
Part::TopoShape ts = _multiFuse->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 9.0);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 3.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
TEST_F(FeaturePartFuseTest, testRecursiveCompound)
|
||||
{
|
||||
// Arrange
|
||||
Part::Compound* _compound[3] = {nullptr};
|
||||
int t;
|
||||
for (t = 0; t < 3; t++) {
|
||||
_compound[t] = _doc->addObject<Part::Compound>();
|
||||
}
|
||||
_compound[0]->Links.setValues({_boxes[0], _boxes[1]});
|
||||
_compound[1]->Links.setValues({_compound[0]});
|
||||
_compound[2]->Links.setValues({_compound[1]});
|
||||
_multiFuse->Shapes.setValues({_compound[2]});
|
||||
|
||||
// Act
|
||||
for (t = 0; t < 3; t++) {
|
||||
_compound[t]->execute();
|
||||
}
|
||||
_multiFuse->execute();
|
||||
Part::TopoShape ts = _multiFuse->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 9.0);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 3.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartFuseTest, testNonIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
_fuse->Tool.setValue(_boxes[2]);
|
||||
|
||||
// Act
|
||||
_fuse->execute();
|
||||
Part::TopoShape ts = _fuse->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 12.0);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 5.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartFuseTest, testTouching)
|
||||
{
|
||||
// Arrange
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
_fuse->Tool.setValue(_boxes[3]);
|
||||
|
||||
// Act
|
||||
_fuse->execute();
|
||||
Part::TopoShape ts = _fuse->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(volume, 12.0);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 4.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartFuseTest, testAlmostTouching)
|
||||
{
|
||||
// Arrange
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
_fuse->Tool.setValue(_boxes[4]);
|
||||
|
||||
// Act
|
||||
_fuse->execute();
|
||||
Part::TopoShape ts = _fuse->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, 12.0); // Use FLOAT to limit precision to 1E07 rather than 1E15
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_FLOAT_EQ(bb.MaxY, 4.0); // Use FLOAT to limit precision to 1E07 rather than 1E15
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartFuseTest, testBarelyIntersecting)
|
||||
{
|
||||
// Arrange
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
_fuse->Tool.setValue(_boxes[5]); // NOLINT magic number
|
||||
|
||||
// Act
|
||||
_fuse->execute();
|
||||
Part::TopoShape ts = _fuse->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
double target = 12 - PartTestHelpers::minimalDistance * 3; // NOLINT 3 dimensions in a Volume
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
|
||||
// Assert
|
||||
// Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07
|
||||
// rather than 1e15 See
|
||||
// https://google.github.io/googletest/reference/assertions.html#floating-point
|
||||
EXPECT_FLOAT_EQ(volume, target);
|
||||
// double check using bounds:
|
||||
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxY, 4.0 - PartTestHelpers::minimalDistance);
|
||||
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartFuseTest, testMustExecute)
|
||||
{
|
||||
// Assert initially we don't need to execute
|
||||
EXPECT_FALSE(_fuse->mustExecute());
|
||||
// Act to change one property
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
// Assert we still can't execute
|
||||
EXPECT_FALSE(_fuse->mustExecute());
|
||||
// Act to complete the properties we need
|
||||
_fuse->Tool.setValue(_boxes[1]);
|
||||
// Assert that we now must execute
|
||||
EXPECT_TRUE(_fuse->mustExecute());
|
||||
// Act to execute
|
||||
_doc->recompute();
|
||||
// Assert we don't need to execute anymore
|
||||
EXPECT_FALSE(_fuse->mustExecute());
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartFuseTest, testGetProviderName)
|
||||
{
|
||||
// Act
|
||||
_fuse->execute();
|
||||
const char* name = _fuse->getViewProviderName();
|
||||
// Assert
|
||||
EXPECT_STREQ(name, "PartGui::ViewProviderBoolean");
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartFuseTest, testRefine)
|
||||
{
|
||||
// Arrange
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
_fuse->Tool.setValue(_boxes[1]);
|
||||
_fuse->Refine.setValue(false);
|
||||
// Act
|
||||
_fuse->execute();
|
||||
Part::TopoShape ts = _fuse->Shape.getValue();
|
||||
std::vector<Part::TopoShape> subs = ts.getSubTopoShapes(TopAbs_FACE); // TopAbs_WIRE alternate
|
||||
// approach
|
||||
// Assert two boxes, plus redundant faces at the joint.
|
||||
EXPECT_EQ(subs.size(), 14);
|
||||
// 14 Faces
|
||||
// 28 Edges
|
||||
// 16 Vertices
|
||||
// -----------
|
||||
// 58 Elements
|
||||
EXPECT_EQ(_fuse->Shape.getShape().getElementMapSize(), 58);
|
||||
// Act
|
||||
_fuse->Refine.setValue(true);
|
||||
_fuse->execute();
|
||||
ts = _fuse->Shape.getValue();
|
||||
subs = ts.getSubTopoShapes(TopAbs_FACE);
|
||||
// Assert we now just have one big box
|
||||
EXPECT_EQ(subs.size(), 6);
|
||||
// 6 Faces
|
||||
// 12 Edges
|
||||
// 8 Vertices
|
||||
// -----------
|
||||
// 58 Elements
|
||||
EXPECT_EQ(_fuse->Shape.getShape().getElementMapSize(), 26);
|
||||
}
|
||||
|
||||
// See FeaturePartCommon.cpp for a history test. It would be exactly the same and redundant here.
|
||||
192
tests/src/Mod/Part/App/FeatureRevolution.cpp
Normal file
192
tests/src/Mod/Part/App/FeatureRevolution.cpp
Normal file
@@ -0,0 +1,192 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Mod/Part/App/FeatureRevolution.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "Base/Interpreter.h"
|
||||
|
||||
#include "BRepBuilderAPI_MakeEdge.hxx"
|
||||
|
||||
#include "TopoDS_Iterator.hxx"
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
class FeatureRevolutionTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_revolution = _doc->addObject<Part::Revolution>();
|
||||
PartTestHelpers::rectangle(len, wid, "Rect1");
|
||||
_revolution->Source.setValue(_doc->getObjects().back());
|
||||
_revolution->Axis.setValue(0, 1, 0);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
Part::Revolution* _revolution = nullptr;
|
||||
// Arbtitrary constants for testing. Named here for clarity.
|
||||
const double len = 3;
|
||||
const double wid = 4;
|
||||
const double ext1 = 10;
|
||||
// NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
};
|
||||
|
||||
TEST_F(FeatureRevolutionTest, testExecute)
|
||||
{
|
||||
// Arrange
|
||||
double puckVolume = len * len * std::numbers::pi * wid; // Area is PIr2; apply height
|
||||
// Act
|
||||
_revolution->execute();
|
||||
Part::TopoShape ts = _revolution->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, puckVolume);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-len, 0, -len, len, wid, len)));
|
||||
}
|
||||
|
||||
TEST_F(FeatureRevolutionTest, testExecuteBase)
|
||||
{
|
||||
// Arrange
|
||||
double rad = len + 1.0;
|
||||
double rad2 = 1.0;
|
||||
double outerPuckVolume = rad * rad * std::numbers::pi * wid; // Area is PIr2; apply height
|
||||
double innerPuckVolume = rad2 * rad2 * std::numbers::pi * wid; // Area is PIr2; apply height
|
||||
_revolution->Base.setValue(Base::Vector3d(len + 1, 0, 0));
|
||||
// Act
|
||||
_revolution->execute();
|
||||
Part::TopoShape ts = _revolution->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, outerPuckVolume - innerPuckVolume);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -wid, wid * 2, wid, wid)));
|
||||
}
|
||||
|
||||
|
||||
TEST_F(FeatureRevolutionTest, testAxis)
|
||||
{
|
||||
// Arrange
|
||||
double puckVolume = wid * wid * std::numbers::pi * len; // Area is PIr2 times height
|
||||
_revolution->Axis.setValue(Base::Vector3d(1, 0, 0));
|
||||
// Act
|
||||
_revolution->execute();
|
||||
Part::TopoShape ts = _revolution->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, puckVolume);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, -wid, -wid, len, wid, wid)));
|
||||
}
|
||||
|
||||
TEST_F(FeatureRevolutionTest, testAxisLink)
|
||||
{
|
||||
// Arrange
|
||||
BRepBuilderAPI_MakeEdge e1(gp_Pnt(0, 0, 0), gp_Pnt(0, 0, ext1));
|
||||
auto edge = _doc->addObject<Part::Feature>("Edge");
|
||||
edge->Shape.setValue(e1);
|
||||
_revolution->AxisLink.setValue(edge);
|
||||
// double puckVolume = wid * wid * std::numbers::pi * len; // Area is PIr2; apply height
|
||||
// Act
|
||||
_revolution->execute();
|
||||
Part::TopoShape ts = _revolution->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
double puckVolume = 0; // Someday make this test use a more interesting edge angle
|
||||
EXPECT_FLOAT_EQ(volume, puckVolume);
|
||||
EXPECT_TRUE(
|
||||
PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-ext1 / 2, -ext1 / 2, 0, ext1 / 2, ext1 / 2, 0))
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(FeatureRevolutionTest, testSymmetric)
|
||||
{
|
||||
// Arrange
|
||||
double puckVolume = len * len * std::numbers::pi * wid; // Area is PIr2 times height
|
||||
_revolution->Symmetric.setValue(true);
|
||||
// Act
|
||||
_revolution->execute();
|
||||
Part::TopoShape ts = _revolution->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, puckVolume);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-len, 0, -len, len, wid, len)));
|
||||
}
|
||||
|
||||
TEST_F(FeatureRevolutionTest, testAngle)
|
||||
{
|
||||
// Arrange
|
||||
double puckVolume = len * len * std::numbers::pi * wid; // Area is PIr2 times height
|
||||
_revolution->Angle.setValue(90); // NOLINT magic number
|
||||
// Act
|
||||
_revolution->execute();
|
||||
Part::TopoShape ts = _revolution->Shape.getValue();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_FLOAT_EQ(volume, puckVolume / 4);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -len, len, wid, 0)));
|
||||
}
|
||||
|
||||
TEST_F(FeatureRevolutionTest, testMustExecute)
|
||||
{
|
||||
// Assert
|
||||
EXPECT_TRUE(_revolution->mustExecute());
|
||||
// Act
|
||||
_doc->recompute();
|
||||
// Assert
|
||||
EXPECT_FALSE(_revolution->mustExecute());
|
||||
// Act
|
||||
_revolution->Base.setValue(_revolution->Base.getValue());
|
||||
// Assert
|
||||
EXPECT_TRUE(_revolution->mustExecute());
|
||||
// Act
|
||||
_doc->recompute();
|
||||
// Assert
|
||||
EXPECT_FALSE(_revolution->mustExecute());
|
||||
// Act
|
||||
_revolution->Solid.setValue(Standard_True);
|
||||
// Assert
|
||||
EXPECT_TRUE(_revolution->mustExecute());
|
||||
// Act
|
||||
_doc->recompute();
|
||||
// Assert
|
||||
EXPECT_FALSE(_revolution->mustExecute());
|
||||
}
|
||||
|
||||
// TEST_F(FeatureRevolutionTest, testOnChanged)
|
||||
// {
|
||||
// // void onChanged(const App::Property* prop) override;
|
||||
// }
|
||||
|
||||
TEST_F(FeatureRevolutionTest, testGetProviderName)
|
||||
{
|
||||
// Act
|
||||
_revolution->execute();
|
||||
const char* name = _revolution->getViewProviderName();
|
||||
// Assert
|
||||
EXPECT_STREQ(name, "PartGui::ViewProviderRevolution");
|
||||
}
|
||||
|
||||
// Tested by execute above
|
||||
// TEST_F(FeatureRevolutionTest, testFetchAxisLink)
|
||||
// {
|
||||
// // static bool fetchAxisLink(const App::PropertyLinkSub& axisLink,
|
||||
// // Base::Vector3d ¢er,
|
||||
// // Base::Vector3d &dir,
|
||||
// // double &angle);
|
||||
// }
|
||||
174
tests/src/Mod/Part/App/FuzzyBoolean.cpp
Normal file
174
tests/src/Mod/Part/App/FuzzyBoolean.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Mod/Part/App/FuzzyHelper.h"
|
||||
#include "Mod/Part/App/FeaturePartImportBrep.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <BRepBuilderAPI_Copy.hxx>
|
||||
#include <BOPAlgo_ArgumentAnalyzer.hxx>
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
|
||||
class FuzzyBooleanTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
std::string testPath = App::Application::getHomePath() + "/tests/brepfiles/";
|
||||
_fuse = _doc->addObject<Part::Fuse>();
|
||||
_cylinder1 = _doc->addObject<Part::ImportBrep>();
|
||||
_cylinder1->FileName.setValue(testPath + "cylinder1.brep");
|
||||
_helix1 = _doc->addObject<Part::ImportBrep>();
|
||||
_helix1->FileName.setValue(testPath + "helix1.brep");
|
||||
|
||||
// Load
|
||||
_cylinder1->execute();
|
||||
_helix1->execute();
|
||||
|
||||
// Arrange
|
||||
_fuse->Base.setValue(_cylinder1);
|
||||
_fuse->Tool.setValue(_helix1);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
Part::Fuse* _fuse = nullptr; // NOLINT Can't be private in a test framework
|
||||
Part::ImportBrep* _cylinder1 = nullptr; // NOLINT Can't be private in a test framework
|
||||
Part::ImportBrep* _helix1 = nullptr; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
TEST_F(FuzzyBooleanTest, testLoadedCorrectly)
|
||||
{
|
||||
|
||||
EXPECT_NEAR(PartTestHelpers::getVolume(_cylinder1->Shape.getValue()), 125.6, 1.0);
|
||||
EXPECT_NEAR(PartTestHelpers::getVolume(_helix1->Shape.getValue()), 33.32, 1.0);
|
||||
}
|
||||
|
||||
TEST_F(FuzzyBooleanTest, testDefaultFuzzy)
|
||||
{
|
||||
|
||||
// Act
|
||||
_fuse->execute();
|
||||
|
||||
// Verify
|
||||
EXPECT_NEAR(
|
||||
PartTestHelpers::getVolume(_fuse->Shape.getValue()),
|
||||
PartTestHelpers::getVolume(_helix1->Shape.getValue())
|
||||
+ PartTestHelpers::getVolume(_cylinder1->Shape.getValue()),
|
||||
0.1
|
||||
);
|
||||
|
||||
// Analyse
|
||||
Part::TopoShape ts = _fuse->Shape.getValue();
|
||||
ASSERT_FALSE(ts.isNull());
|
||||
TopoDS_Shape BOPCopy = BRepBuilderAPI_Copy(ts.getShape()).Shape();
|
||||
BOPAlgo_ArgumentAnalyzer BOPCheck;
|
||||
BOPCheck.SetShape1(BOPCopy);
|
||||
BOPCheck.SelfInterMode() = Standard_True;
|
||||
|
||||
BOPCheck.Perform();
|
||||
// Assert
|
||||
EXPECT_FALSE(BOPCheck.HasFaulty());
|
||||
}
|
||||
|
||||
TEST_F(FuzzyBooleanTest, testGoodFuzzy)
|
||||
{
|
||||
|
||||
// Act
|
||||
double oldFuzzy = Part::FuzzyHelper::getBooleanFuzzy();
|
||||
Part::FuzzyHelper::setBooleanFuzzy(10.0);
|
||||
_fuse->execute();
|
||||
EXPECT_FLOAT_EQ(Part::FuzzyHelper::getBooleanFuzzy(), 10.0);
|
||||
Part::FuzzyHelper::setBooleanFuzzy(oldFuzzy);
|
||||
|
||||
// Verify
|
||||
EXPECT_NEAR(
|
||||
PartTestHelpers::getVolume(_fuse->Shape.getValue()),
|
||||
PartTestHelpers::getVolume(_helix1->Shape.getValue())
|
||||
+ PartTestHelpers::getVolume(_cylinder1->Shape.getValue()),
|
||||
0.1
|
||||
);
|
||||
|
||||
// Analyse
|
||||
Part::TopoShape ts = _fuse->Shape.getValue();
|
||||
ASSERT_FALSE(ts.isNull());
|
||||
TopoDS_Shape BOPCopy = BRepBuilderAPI_Copy(ts.getShape()).Shape();
|
||||
BOPAlgo_ArgumentAnalyzer BOPCheck;
|
||||
BOPCheck.SetShape1(BOPCopy);
|
||||
BOPCheck.SelfInterMode() = Standard_True;
|
||||
|
||||
BOPCheck.Perform();
|
||||
// Assert
|
||||
int result = BOPCheck.HasFaulty();
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
TEST_F(FuzzyBooleanTest, testFailsTooSmallFuzzy)
|
||||
{
|
||||
|
||||
// Act
|
||||
double oldFuzzy = Part::FuzzyHelper::getBooleanFuzzy();
|
||||
Part::FuzzyHelper::setBooleanFuzzy(0.01);
|
||||
_fuse->execute();
|
||||
EXPECT_DOUBLE_EQ(Part::FuzzyHelper::getBooleanFuzzy(), 0.01);
|
||||
Part::FuzzyHelper::setBooleanFuzzy(oldFuzzy);
|
||||
|
||||
// Verify
|
||||
// EXPECT_NEAR(PartTestHelpers::getVolume(_fuse->Shape.getValue()),PartTestHelpers::getVolume(_helix1->Shape.getValue())+PartTestHelpers::getVolume(_cylinder1->Shape.getValue()),0.1);
|
||||
// // fails on OCCT 7.3 - ignore
|
||||
|
||||
// Analyse
|
||||
Part::TopoShape ts = _fuse->Shape.getValue();
|
||||
ASSERT_FALSE(ts.isNull());
|
||||
TopoDS_Shape BOPCopy = BRepBuilderAPI_Copy(ts.getShape()).Shape();
|
||||
BOPAlgo_ArgumentAnalyzer BOPCheck;
|
||||
BOPCheck.SetShape1(BOPCopy);
|
||||
BOPCheck.SelfInterMode() = Standard_True;
|
||||
|
||||
BOPCheck.Perform();
|
||||
// Assert
|
||||
int result = BOPCheck.HasFaulty();
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
TEST_F(FuzzyBooleanTest, testCompletelyFailsTooBigFuzzy)
|
||||
{
|
||||
|
||||
// Act
|
||||
double oldFuzzy = Part::FuzzyHelper::getBooleanFuzzy();
|
||||
Part::FuzzyHelper::setBooleanFuzzy(1e10);
|
||||
int failed = 0;
|
||||
Part::TopoShape ts;
|
||||
try {
|
||||
_fuse->execute();
|
||||
ts = _fuse->Shape.getValue();
|
||||
if (ts.isNull()) {
|
||||
failed = 1;
|
||||
}
|
||||
else {
|
||||
TopoDS_Shape BOPCopy = BRepBuilderAPI_Copy(ts.getShape()).Shape();
|
||||
BOPAlgo_ArgumentAnalyzer BOPCheck;
|
||||
BOPCheck.SetShape1(BOPCopy);
|
||||
BOPCheck.SelfInterMode() = Standard_True;
|
||||
|
||||
BOPCheck.Perform();
|
||||
// Assert
|
||||
if (BOPCheck.HasFaulty()) {
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
failed = 1;
|
||||
}
|
||||
Part::FuzzyHelper::setBooleanFuzzy(oldFuzzy);
|
||||
EXPECT_EQ(failed, 1);
|
||||
}
|
||||
88
tests/src/Mod/Part/App/Geometry.cpp
Normal file
88
tests/src/Mod/Part/App/Geometry.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include "Mod/Part/App/Geometry.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <BRepBuilderAPI_MakeVertex.hxx>
|
||||
#include "PartTestHelpers.h"
|
||||
#include "App/MappedElement.h"
|
||||
|
||||
// using namespace Part;
|
||||
// using namespace PartTestHelpers;
|
||||
|
||||
class GeometryTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
};
|
||||
|
||||
TEST_F(GeometryTest, testTrimBSpline)
|
||||
{
|
||||
// Arrange
|
||||
// create arbitrary B-splines periodic and non-periodic, with arbitrary knots
|
||||
// NOTE: Avoid B-spline with typical knots like those ranging from [0,1] or [-1,1]
|
||||
int degree = 3;
|
||||
std::vector<Base::Vector3d> poles;
|
||||
poles.emplace_back(1, 0, 0);
|
||||
poles.emplace_back(1, 1, 0);
|
||||
poles.emplace_back(1, 0.5, 0);
|
||||
poles.emplace_back(0, 1, 0);
|
||||
poles.emplace_back(0, 0, 0);
|
||||
std::vector<double> weights(5, 1.0);
|
||||
std::vector<double> knotsNonPeriodic = {0.0, 1.0, 2.0};
|
||||
std::vector<int> multiplicitiesNonPeriodic = {degree + 1, 1, degree + 1};
|
||||
Part::GeomBSplineCurve nonPeriodicBSpline1(
|
||||
poles,
|
||||
weights,
|
||||
knotsNonPeriodic,
|
||||
multiplicitiesNonPeriodic,
|
||||
degree,
|
||||
false
|
||||
);
|
||||
Part::GeomBSplineCurve nonPeriodicBSpline2(
|
||||
poles,
|
||||
weights,
|
||||
knotsNonPeriodic,
|
||||
multiplicitiesNonPeriodic,
|
||||
degree,
|
||||
false
|
||||
);
|
||||
std::vector<double> knotsPeriodic = {0.0, 0.3, 1.0, 1.5, 1.8, 2.0};
|
||||
double period = knotsPeriodic.back() - knotsPeriodic.front();
|
||||
std::vector<int> multiplicitiesPeriodic(6, 1);
|
||||
Part::GeomBSplineCurve
|
||||
periodicBSpline1(poles, weights, knotsPeriodic, multiplicitiesPeriodic, degree, true);
|
||||
Part::GeomBSplineCurve
|
||||
periodicBSpline2(poles, weights, knotsPeriodic, multiplicitiesPeriodic, degree, true);
|
||||
// NOTE: These should be within the knot range, with param1 < param2
|
||||
double param1 = 0.5, param2 = 1.4;
|
||||
// TODO: Decide what to do if params are outside the range
|
||||
|
||||
// Act
|
||||
periodicBSpline1.Trim(param1, param2);
|
||||
periodicBSpline2.Trim(param2, param1);
|
||||
nonPeriodicBSpline1.Trim(param1, param2);
|
||||
// TODO: What happens when a non-periodic B-spline is trimmed this way?
|
||||
nonPeriodicBSpline2.Trim(param2, param1);
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(periodicBSpline1.getFirstParameter(), param1);
|
||||
EXPECT_DOUBLE_EQ(periodicBSpline1.getLastParameter(), param2);
|
||||
EXPECT_DOUBLE_EQ(periodicBSpline2.getFirstParameter(), param2);
|
||||
EXPECT_DOUBLE_EQ(periodicBSpline2.getLastParameter(), param1 + period);
|
||||
EXPECT_DOUBLE_EQ(nonPeriodicBSpline1.getFirstParameter(), param1);
|
||||
EXPECT_DOUBLE_EQ(nonPeriodicBSpline1.getLastParameter(), param2);
|
||||
}
|
||||
238
tests/src/Mod/Part/App/PartFeature.cpp
Normal file
238
tests/src/Mod/Part/App/PartFeature.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include "Mod/Part/App/FeaturePartCommon.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <BRepBuilderAPI_MakeVertex.hxx>
|
||||
#include "PartTestHelpers.h"
|
||||
#include "App/MappedElement.h"
|
||||
|
||||
using namespace Part;
|
||||
using namespace PartTestHelpers;
|
||||
|
||||
class FeaturePartTest: public ::testing::Test, public PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_common = _doc->addObject<Common>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
Common* _common = nullptr; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
TEST_F(FeaturePartTest, testGetElementName)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
|
||||
// Act
|
||||
_common->execute();
|
||||
const TopoShape& ts = _common->Shape.getShape();
|
||||
|
||||
auto namePair = _common->getElementName("test");
|
||||
auto namePairExport = _common->getElementName("test", App::GeoFeature::Export);
|
||||
auto namePairSelf = _common->getElementName(nullptr);
|
||||
// Assert
|
||||
EXPECT_STREQ(namePair.newName.c_str(), "");
|
||||
EXPECT_STREQ(namePair.oldName.c_str(), "test");
|
||||
EXPECT_STREQ(namePairExport.newName.c_str(), "");
|
||||
EXPECT_STREQ(namePairExport.oldName.c_str(), "test");
|
||||
EXPECT_STREQ(namePairSelf.newName.c_str(), "");
|
||||
EXPECT_STREQ(namePairSelf.oldName.c_str(), "");
|
||||
EXPECT_EQ(ts.getElementMap().size(), 26);
|
||||
// TBD
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartTest, create)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// A shape that will be passed to the various calls of Feature::create
|
||||
auto shape {TopoShape(BRepBuilderAPI_MakeVertex(gp_Pnt(1.0, 1.0, 1.0)).Vertex(), 1)};
|
||||
|
||||
auto otherDocName {App::GetApplication().getUniqueDocumentName("otherDoc")};
|
||||
// Another document where it will be created a shape
|
||||
auto otherDoc {App::GetApplication().newDocument(otherDocName.c_str(), "otherDocUser")};
|
||||
|
||||
// _doc is populated by PartTestHelperClass::createTestDoc. Making it an empty document
|
||||
_doc->clearDocument();
|
||||
|
||||
// Setting the active document back to _doc otherwise the first 3 calls to Feature::create will
|
||||
// act on otherDoc
|
||||
App::GetApplication().setActiveDocument(_doc);
|
||||
|
||||
// Act
|
||||
|
||||
// A feature with an empty TopoShape
|
||||
auto featureNoShape {Feature::create(TopoShape())};
|
||||
|
||||
// A feature with a TopoShape
|
||||
auto featureNoName {Feature::create(shape)};
|
||||
|
||||
// A feature with a TopoShape and a name
|
||||
auto featureNoDoc {Feature::create(shape, "Vertex")};
|
||||
|
||||
// A feature with a TopoShape and a name in the document otherDoc
|
||||
auto feature {Feature::create(shape, "Vertex", otherDoc)};
|
||||
|
||||
// Assert
|
||||
|
||||
// Check that the shapes have been added. Only featureNoShape should return an empty shape, the
|
||||
// others should have it as TopoShape shape is passed as argument
|
||||
EXPECT_TRUE(featureNoShape->Shape.getValue().IsNull());
|
||||
EXPECT_FALSE(featureNoName->Shape.getValue().IsNull());
|
||||
EXPECT_FALSE(featureNoDoc->Shape.getValue().IsNull());
|
||||
EXPECT_FALSE(feature->Shape.getValue().IsNull());
|
||||
|
||||
// Check the features names
|
||||
|
||||
// Without a name the feature's name will be set to "Shape"
|
||||
EXPECT_STREQ(_doc->getObjectName(featureNoShape), "Shape");
|
||||
|
||||
// In _doc there's already a shape with name "Shape" and, as there can't be duplicated names in
|
||||
// the same document, the other feature will get an unique name that will still contain "Shape"
|
||||
EXPECT_STREQ(_doc->getObjectName(featureNoName), "Shape001");
|
||||
|
||||
// There aren't other features with name "Vertex" in _doc, therefore that name will be assigned
|
||||
// without modifications
|
||||
EXPECT_STREQ(_doc->getObjectName(featureNoDoc), "Vertex");
|
||||
|
||||
// The feature is created in otherDoc, which doesn't have other features and thertherefore the
|
||||
// feature's name will be assigned without modifications
|
||||
EXPECT_STREQ(otherDoc->getObjectName(feature), "Vertex");
|
||||
|
||||
// Check that the features have been created in the correct document
|
||||
|
||||
// The first 3 calls to Feature::create acts on _doc, which is empty, and therefore the number
|
||||
// of features in that document is the same of the features created with Feature::create
|
||||
EXPECT_EQ(_doc->getObjects().size(), 3);
|
||||
|
||||
// The last call to Feature::create acts on otherDoc, which is empty, and therefore that
|
||||
// document will have only 1 feature
|
||||
EXPECT_EQ(otherDoc->getObjects().size(), 1);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartTest, getElementHistory)
|
||||
{
|
||||
// Arrange
|
||||
const char* name2 = "Edge2"; // Edge, Vertex, or Face. will work here.
|
||||
// Act
|
||||
auto result = Feature::getElementHistory(_boxes[0], name2, true, false);
|
||||
Data::HistoryItem histItem = result.front();
|
||||
// Assert
|
||||
EXPECT_EQ(result.size(), 1);
|
||||
EXPECT_NE(histItem.tag, 0); // Make sure we have one. It will vary.
|
||||
EXPECT_EQ(histItem.index.getIndex(), 2);
|
||||
EXPECT_STREQ(histItem.index.getType(), "Edge");
|
||||
EXPECT_STREQ(histItem.element.toString().c_str(), name2);
|
||||
EXPECT_EQ(histItem.obj, _boxes[0]);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartTest, getRelatedElements)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
// Act
|
||||
_common->execute();
|
||||
auto label1 = _common->Label.getValue();
|
||||
auto label2 = _boxes[1]->Label.getValue();
|
||||
const TopoShape& ts = _common->Shape.getShape();
|
||||
boost::ignore_unused(ts);
|
||||
auto result = Feature::getRelatedElements(
|
||||
_doc->getObject(label1),
|
||||
"Edge2",
|
||||
HistoryTraceType::followTypeChange,
|
||||
true
|
||||
);
|
||||
auto result2 = Feature::getRelatedElements(
|
||||
_doc->getObject(label2),
|
||||
"Edge1",
|
||||
HistoryTraceType::followTypeChange,
|
||||
true
|
||||
);
|
||||
// Assert
|
||||
EXPECT_EQ(result.size(), 1); // Found the one.
|
||||
EXPECT_EQ(result2.size(), 0); // No element map, so no related elements
|
||||
// The results are always going to vary, so we can't test for specific values:
|
||||
// EXPECT_STREQ(result.front().name.toString().c_str(),"Edge3;:M;CMN;:H38d:7,E");
|
||||
}
|
||||
|
||||
// Note that this test is pretty trivial and useless .. but the method in question is never
|
||||
// called in the codebase.
|
||||
TEST_F(FeaturePartTest, getElementFromSource)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
App::DocumentObject sourceObject;
|
||||
// const char *sourceSubElement;
|
||||
// Act
|
||||
_common->execute();
|
||||
auto label1 = _common->Label.getValue();
|
||||
auto label2 = _boxes[1]->Label.getValue();
|
||||
const TopoShape& ts = _common->Shape.getShape();
|
||||
boost::ignore_unused(label1);
|
||||
boost::ignore_unused(label2);
|
||||
boost::ignore_unused(ts);
|
||||
auto element = Feature::getElementFromSource(
|
||||
_common,
|
||||
"Part__Box001", // "Edge1",
|
||||
_boxes[0],
|
||||
"Face1", // "Edge1",
|
||||
false
|
||||
);
|
||||
// Assert
|
||||
EXPECT_EQ(element.size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartTest, getSubObject)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
App::DocumentObject sourceObject;
|
||||
PyObject* pyObj;
|
||||
// Act
|
||||
_common->execute();
|
||||
auto result = _boxes[1]->getSubObject("Face5", &pyObj, nullptr, false, 10);
|
||||
// Assert
|
||||
ASSERT_NE(result, nullptr);
|
||||
EXPECT_STREQ(result->getNameInDocument(), "Part__Box001");
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartTest, getElementTypes)
|
||||
{
|
||||
Part::Feature pf;
|
||||
std::vector<const char*> types = pf.getElementTypes();
|
||||
|
||||
EXPECT_EQ(types.size(), 3);
|
||||
EXPECT_STREQ(types[0], "Face");
|
||||
EXPECT_STREQ(types[1], "Edge");
|
||||
EXPECT_STREQ(types[2], "Vertex");
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartTest, getComplexElementTypes)
|
||||
{
|
||||
Part::TopoShape shape;
|
||||
std::vector<const char*> types = shape.getElementTypes();
|
||||
|
||||
EXPECT_EQ(types.size(), 3);
|
||||
EXPECT_STREQ(types[0], "Face");
|
||||
EXPECT_STREQ(types[1], "Edge");
|
||||
EXPECT_STREQ(types[2], "Vertex");
|
||||
}
|
||||
209
tests/src/Mod/Part/App/PartFeatures.cpp
Normal file
209
tests/src/Mod/Part/App/PartFeatures.cpp
Normal file
@@ -0,0 +1,209 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Mod/Part/App/PartFeatures.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
using namespace Part;
|
||||
using namespace PartTestHelpers;
|
||||
|
||||
class PartFeaturesTest: public ::testing::Test, public PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
};
|
||||
|
||||
TEST_F(PartFeaturesTest, testRuledSurface)
|
||||
{
|
||||
// Arrange
|
||||
auto _edge1 = _doc->addObject<Line>();
|
||||
auto _edge2 = _doc->addObject<Line>();
|
||||
_edge1->X1.setValue(0);
|
||||
_edge1->Y1.setValue(0);
|
||||
_edge1->Z1.setValue(0);
|
||||
_edge1->X2.setValue(2);
|
||||
_edge1->Y2.setValue(0);
|
||||
_edge1->Z2.setValue(0);
|
||||
_edge2->X1.setValue(0);
|
||||
_edge2->Y1.setValue(2);
|
||||
_edge2->Z1.setValue(0);
|
||||
_edge2->X2.setValue(2);
|
||||
_edge2->Y2.setValue(2);
|
||||
_edge2->Z2.setValue(0);
|
||||
auto _ruled = _doc->addObject<RuledSurface>();
|
||||
_ruled->Curve1.setValue(_edge1);
|
||||
_ruled->Curve2.setValue(_edge2);
|
||||
// Act
|
||||
_ruled->execute();
|
||||
TopoShape ts = _ruled->Shape.getShape();
|
||||
double volume = getVolume(ts.getShape());
|
||||
double area = getArea(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
auto elementMap = ts.getElementMap();
|
||||
// Assert shape is correct
|
||||
EXPECT_DOUBLE_EQ(volume, 0.0);
|
||||
EXPECT_DOUBLE_EQ(area, 4.0);
|
||||
EXPECT_TRUE(boxesMatch(bb, Base::BoundBox3d(0, 0, 0, 2, 2, 0)));
|
||||
// Assert element map is correct
|
||||
EXPECT_EQ(9, elementMap.size());
|
||||
}
|
||||
|
||||
TEST_F(PartFeaturesTest, testLoft)
|
||||
{
|
||||
// Arrange
|
||||
auto _plane1 = _doc->addObject<Plane>();
|
||||
_plane1->Length.setValue(4);
|
||||
_plane1->Width.setValue(4);
|
||||
auto _plane2 = _doc->addObject<Plane>();
|
||||
_plane2->Length.setValue(4);
|
||||
_plane2->Width.setValue(4);
|
||||
_plane2->Placement.setValue(Base::Placement(Base::Vector3d(0, 0, 2), Base::Rotation()));
|
||||
auto _loft = _doc->addObject<Loft>();
|
||||
_loft->Sections.setValues({_plane1, _plane2});
|
||||
_loft->Solid.setValue((true));
|
||||
// Act
|
||||
_loft->execute();
|
||||
TopoShape ts = _loft->Shape.getShape();
|
||||
double volume = getVolume(ts.getShape());
|
||||
double area = getArea(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
auto elementMap = ts.getElementMap();
|
||||
// Assert shape is correct
|
||||
EXPECT_DOUBLE_EQ(volume, 32.0);
|
||||
EXPECT_DOUBLE_EQ(area, 64.0);
|
||||
EXPECT_TRUE(boxesMatch(bb, Base::BoundBox3d(0, 0, 0, 4, 4, 2)));
|
||||
// Assert element map is correct
|
||||
EXPECT_EQ(26, elementMap.size());
|
||||
}
|
||||
|
||||
TEST_F(PartFeaturesTest, testSweep)
|
||||
{
|
||||
// Arrange
|
||||
auto _edge1 = _doc->addObject<Line>();
|
||||
_edge1->X1.setValue(0);
|
||||
_edge1->Y1.setValue(0);
|
||||
_edge1->Z1.setValue(0);
|
||||
_edge1->X2.setValue(0);
|
||||
_edge1->Y2.setValue(0);
|
||||
_edge1->Z2.setValue(3);
|
||||
auto _plane1 = _doc->addObject<Plane>();
|
||||
_plane1->Length.setValue(4);
|
||||
_plane1->Width.setValue(4);
|
||||
auto _sweep = _doc->addObject<Sweep>();
|
||||
_sweep->Sections.setValues({_plane1});
|
||||
_sweep->Spine.setValue(_edge1);
|
||||
_sweep->Solid.setValue((false));
|
||||
// Act
|
||||
_sweep->execute();
|
||||
TopoShape ts = _sweep->Shape.getShape();
|
||||
double volume = getVolume(ts.getShape());
|
||||
double area = getArea(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
auto elementMap = ts.getElementMap();
|
||||
// Assert shape is correct
|
||||
EXPECT_DOUBLE_EQ(volume, 32.0);
|
||||
EXPECT_DOUBLE_EQ(area, 48.0);
|
||||
EXPECT_TRUE(boxesMatch(bb, Base::BoundBox3d(0, 0, 0, 4, 4, 3)));
|
||||
// Assert element map is correct
|
||||
EXPECT_EQ(24, elementMap.size());
|
||||
}
|
||||
|
||||
TEST_F(PartFeaturesTest, testThickness)
|
||||
{
|
||||
// Arrange
|
||||
auto _thickness = _doc->addObject<Thickness>();
|
||||
_thickness->Faces.setValue(_boxes[0], {"Face1"});
|
||||
_thickness->Value.setValue(0.25);
|
||||
_thickness->Join.setValue("Intersection");
|
||||
// Act
|
||||
_thickness->execute();
|
||||
TopoShape ts = _thickness->Shape.getShape();
|
||||
double volume = getVolume(ts.getShape());
|
||||
double area = getArea(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
auto elementMap = ts.getElementMap();
|
||||
// Assert shape is correct
|
||||
EXPECT_DOUBLE_EQ(volume, 4.9375);
|
||||
EXPECT_DOUBLE_EQ(area, 42.5);
|
||||
EXPECT_TRUE(boxesMatch(bb, Base::BoundBox3d(0, -0.25, -0.25, 1.25, 2.25, 3.25)));
|
||||
// Assert element map is correct
|
||||
EXPECT_EQ(51, elementMap.size());
|
||||
}
|
||||
|
||||
TEST_F(PartFeaturesTest, testRefine)
|
||||
{
|
||||
// Arrange
|
||||
auto _fuse = _doc->addObject<Part::Fuse>();
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
_fuse->Tool.setValue(_boxes[3]);
|
||||
_fuse->Refine.setValue(false);
|
||||
_fuse->execute();
|
||||
Part::TopoShape fusedts = _fuse->Shape.getShape();
|
||||
auto _refine = _doc->addObject<Refine>();
|
||||
_refine->Source.setValue(_fuse);
|
||||
// Act
|
||||
_refine->execute();
|
||||
TopoShape ts = _refine->Shape.getShape();
|
||||
double volume = getVolume(ts.getShape());
|
||||
double area = getArea(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
auto elementMap = ts.getElementMap();
|
||||
auto edges = fusedts.getSubTopoShapes(TopAbs_EDGE);
|
||||
auto refinedEdges = ts.getSubTopoShapes(TopAbs_EDGE);
|
||||
// Assert shape is correct
|
||||
EXPECT_EQ(edges.size(), 20);
|
||||
EXPECT_EQ(refinedEdges.size(), 12);
|
||||
EXPECT_DOUBLE_EQ(volume, 12.0);
|
||||
EXPECT_DOUBLE_EQ(area, 38.0);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, 1, 4, 3)));
|
||||
// Assert element map is correct
|
||||
EXPECT_EQ(0, elementMap.size()); // TODO: Expect this to be non-zero.
|
||||
}
|
||||
|
||||
TEST_F(PartFeaturesTest, testReverse)
|
||||
{
|
||||
// Arrange
|
||||
auto _reverse = _doc->addObject<Reverse>();
|
||||
_reverse->Source.setValue(_boxes[0]);
|
||||
// Act
|
||||
_reverse->execute();
|
||||
TopoShape ts = _reverse->Shape.getShape();
|
||||
double volume = getVolume(ts.getShape());
|
||||
double area = getArea(ts.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
auto elementMap = ts.getElementMap();
|
||||
auto faces = ts.getSubTopoShapes(TopAbs_FACE);
|
||||
auto originalFaces = _boxes[0]->Shape.getShape().getSubTopoShapes(TopAbs_FACE);
|
||||
// Assert shape is correct
|
||||
EXPECT_EQ(faces[0].getShape().Orientation(), TopAbs_FORWARD);
|
||||
EXPECT_EQ(faces[1].getShape().Orientation(), TopAbs_REVERSED);
|
||||
EXPECT_EQ(faces[2].getShape().Orientation(), TopAbs_FORWARD);
|
||||
EXPECT_EQ(faces[3].getShape().Orientation(), TopAbs_REVERSED);
|
||||
EXPECT_EQ(faces[4].getShape().Orientation(), TopAbs_FORWARD);
|
||||
EXPECT_EQ(faces[5].getShape().Orientation(), TopAbs_REVERSED);
|
||||
EXPECT_EQ(originalFaces[0].getShape().Orientation(), TopAbs_REVERSED);
|
||||
EXPECT_EQ(originalFaces[1].getShape().Orientation(), TopAbs_FORWARD);
|
||||
EXPECT_EQ(originalFaces[2].getShape().Orientation(), TopAbs_REVERSED);
|
||||
EXPECT_EQ(originalFaces[3].getShape().Orientation(), TopAbs_FORWARD);
|
||||
EXPECT_EQ(originalFaces[4].getShape().Orientation(), TopAbs_REVERSED);
|
||||
EXPECT_EQ(originalFaces[5].getShape().Orientation(), TopAbs_FORWARD);
|
||||
EXPECT_DOUBLE_EQ(volume, 6.0);
|
||||
EXPECT_DOUBLE_EQ(area, 22.0);
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, 1, 2, 3)));
|
||||
// Assert element map is correct
|
||||
EXPECT_EQ(0, elementMap.size()); // TODO: Expect this to be non-zero.
|
||||
}
|
||||
257
tests/src/Mod/Part/App/PartTestHelpers.cpp
Normal file
257
tests/src/Mod/Part/App/PartTestHelpers.cpp
Normal file
@@ -0,0 +1,257 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <regex>
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
namespace PartTestHelpers
|
||||
{
|
||||
|
||||
double getVolume(const TopoDS_Shape& shape)
|
||||
{
|
||||
GProp_GProps prop;
|
||||
BRepGProp::VolumeProperties(shape, prop);
|
||||
return abs(prop.Mass());
|
||||
}
|
||||
|
||||
double getArea(const TopoDS_Shape& shape)
|
||||
{
|
||||
GProp_GProps prop;
|
||||
BRepGProp::SurfaceProperties(shape, prop);
|
||||
return abs(prop.Mass());
|
||||
}
|
||||
|
||||
double getLength(const TopoDS_Shape& shape)
|
||||
{
|
||||
GProp_GProps prop;
|
||||
BRepGProp::LinearProperties(shape, prop);
|
||||
return abs(prop.Mass());
|
||||
}
|
||||
|
||||
|
||||
void PartTestHelperClass::createTestDoc()
|
||||
{
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
_doc = App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
std::array<Base::Vector3d, 6> box_origins = {
|
||||
Base::Vector3d(), // First box at 0,0,0
|
||||
Base::Vector3d(0, 1, 0), // Overlap with first box
|
||||
Base::Vector3d(0, 3, 0), // Don't Overlap with first box
|
||||
Base::Vector3d(0, 2, 0), // Touch the first box
|
||||
Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), // Just Outside of touching
|
||||
// For the Just Inside Of Touching case, go enough that we exceed precision rounding
|
||||
Base::Vector3d(0, 2 - minimalDistance, 0)
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < _boxes.size(); i++) {
|
||||
auto box = _boxes[i] = _doc->addObject<Part::Box>(); // NOLINT
|
||||
box->Length.setValue(1);
|
||||
box->Width.setValue(2);
|
||||
box->Height.setValue(3);
|
||||
box->Placement.setValue(
|
||||
Base::Placement(box_origins[i], Base::Rotation(), Base::Vector3d())
|
||||
); // NOLINT
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Part::FilletElement> _getFilletEdges(
|
||||
const std::vector<int>& edges,
|
||||
double startRadius,
|
||||
double endRadius
|
||||
)
|
||||
{
|
||||
std::vector<Part::FilletElement> filletElements;
|
||||
for (auto edge : edges) {
|
||||
Part::FilletElement fe = {edge, startRadius, endRadius};
|
||||
filletElements.push_back(fe);
|
||||
}
|
||||
return filletElements;
|
||||
}
|
||||
|
||||
|
||||
void ExecutePython(const std::vector<std::string>& python)
|
||||
{
|
||||
Base::InterpreterSingleton is = Base::InterpreterSingleton();
|
||||
|
||||
for (auto const& line : python) {
|
||||
is.runInteractiveString(line.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void rectangle(double height, double width, const char* name)
|
||||
{
|
||||
std::vector<std::string> rectstring {
|
||||
"import FreeCAD, Part",
|
||||
"V1 = FreeCAD.Vector(0, 0, 0)",
|
||||
boost::str(boost::format("V2 = FreeCAD.Vector(%d, 0, 0)") % height),
|
||||
boost::str(boost::format("V3 = FreeCAD.Vector(%d, %d, 0)") % height % width),
|
||||
boost::str(boost::format("V4 = FreeCAD.Vector(0, %d, 0)") % width),
|
||||
"P1 = Part.makePolygon([V1, V2, V3, V4],True)",
|
||||
"F1 = Part.Face(P1)", // Make the face or the volume calc won't work right.
|
||||
boost::str(boost::format("Part.show(F1,'%s')") % name),
|
||||
};
|
||||
ExecutePython(rectstring);
|
||||
}
|
||||
|
||||
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge> CreateRectFace(
|
||||
float len,
|
||||
float wid
|
||||
)
|
||||
{
|
||||
auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(len, 0.0, 0.0)).Edge();
|
||||
auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(len, 0.0, 0.0), gp_Pnt(len, wid, 0.0)).Edge();
|
||||
auto edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(len, wid, 0.0), gp_Pnt(0.0, wid, 0.0)).Edge();
|
||||
auto edge4 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, wid, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge();
|
||||
auto wire1 = BRepBuilderAPI_MakeWire({edge1, edge2, edge3, edge4}).Wire();
|
||||
auto face1 = BRepBuilderAPI_MakeFace(wire1).Face();
|
||||
return {face1, wire1, edge1, edge2, edge3, edge4};
|
||||
}
|
||||
|
||||
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Wire> CreateFaceWithRoundHole(float len, float wid, float radius)
|
||||
{
|
||||
auto [face1, wire1, edge1, edge2, edge3, edge4] = CreateRectFace(len, wid);
|
||||
auto circ1 = GC_MakeCircle(gp_Pnt(len / 2.0, wid / 2.0, 0), gp_Dir(0.0, 0.0, 1.0), radius).Value();
|
||||
auto edge5 = BRepBuilderAPI_MakeEdge(circ1).Edge();
|
||||
auto wire2 = BRepBuilderAPI_MakeWire(edge5).Wire();
|
||||
auto face2 = BRepBuilderAPI_MakeFace(face1, wire2).Face();
|
||||
// Beware: somewhat counterintuitively, face2 is the sum of face1 and the area inside wire2,
|
||||
// not the difference.
|
||||
return {face2, wire1, wire2};
|
||||
}
|
||||
|
||||
testing::AssertionResult boxesMatch(const Base::BoundBox3d& b1, const Base::BoundBox3d& b2, double prec)
|
||||
{
|
||||
if (abs(b1.MinX - b2.MinX) < prec && abs(b1.MinY - b2.MinY) < prec
|
||||
&& abs(b1.MinZ - b2.MinZ) < prec && abs(b1.MaxX - b2.MaxX) < prec
|
||||
&& abs(b1.MaxY - b2.MaxY) < prec && abs(b1.MaxZ - b2.MaxZ) < prec) {
|
||||
return testing::AssertionSuccess();
|
||||
}
|
||||
return testing::AssertionFailure()
|
||||
<< "(" << b1.MinX << "," << b1.MinY << "," << b1.MinZ << " ; "
|
||||
<< "(" << b1.MaxX << "," << b1.MaxY << "," << b1.MaxZ << ") != (" << b2.MinX << ","
|
||||
<< b2.MinY << "," << b2.MinZ << " ; " << b2.MaxX << "," << b2.MaxY << "," << b2.MaxZ << ")";
|
||||
}
|
||||
|
||||
std::map<IndexedName, MappedName> elementMap(const TopoShape& shape)
|
||||
{
|
||||
std::map<IndexedName, MappedName> result {};
|
||||
auto elements = shape.getElementMap();
|
||||
for (auto const& entry : elements) {
|
||||
result[entry.index] = entry.name;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string mappedElementVectorToString(std::vector<MappedElement>& elements)
|
||||
{
|
||||
std::stringstream output;
|
||||
output << "{";
|
||||
for (const auto& element : elements) {
|
||||
output << "\"" << element.name.toString() << "\", ";
|
||||
}
|
||||
output << "}";
|
||||
return output.str();
|
||||
}
|
||||
|
||||
bool matchStringsWithoutClause(std::string first, std::string second, const std::string& regex)
|
||||
{
|
||||
first = std::regex_replace(first, std::regex(regex), "");
|
||||
second = std::regex_replace(second, std::regex(regex), "");
|
||||
return first == second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the elementMap in a shape contains all the names in a list
|
||||
* There are some sections of the name that can vary due to random numbers or
|
||||
* memory addresses, so we use a regex to exclude those sections while still
|
||||
* validating that the name exists and is the correct type.
|
||||
* @param shape The Shape
|
||||
* @param names The vector of names
|
||||
* @return An assertion usable by the gtest framework
|
||||
*/
|
||||
testing::AssertionResult elementsMatch(const TopoShape& shape, const std::vector<std::string>& names)
|
||||
{
|
||||
auto elements = shape.getElementMap();
|
||||
if (!elements.empty() || !names.empty()) {
|
||||
for (const auto& name : names) {
|
||||
if (std::find_if(
|
||||
elements.begin(),
|
||||
elements.end(),
|
||||
[&, name](const Data::MappedElement& element) {
|
||||
return matchStringsWithoutClause(
|
||||
element.name.toString(),
|
||||
name,
|
||||
"(;D|;:H|;K)-?[a-fA-F0-9]+(:[0-9]+)?|(\\(.*?\\))?"
|
||||
);
|
||||
// ;D ;:H and ;K are the sections of an encoded name for
|
||||
// Duplicate, Tag and a Face name in slices. All three of these
|
||||
// can vary from run to run or platform to platform, as they are
|
||||
// based on either explicit random numbers or memory addresses.
|
||||
// Thus we remove the value from comparisons and just check that
|
||||
// they exist. The full form could be something like ;:He59:53
|
||||
// which is what we match and remove. We also pull out any
|
||||
// subexpressions wrapped in parens to keep the parse from
|
||||
// becoming too complex.
|
||||
}
|
||||
)
|
||||
== elements.end()) {
|
||||
return testing::AssertionFailure() << mappedElementVectorToString(elements);
|
||||
}
|
||||
}
|
||||
}
|
||||
return testing::AssertionSuccess();
|
||||
}
|
||||
|
||||
testing::AssertionResult allElementsMatch(const TopoShape& shape, const std::vector<std::string>& names)
|
||||
{
|
||||
auto elements = shape.getElementMap();
|
||||
if (elements.size() != names.size()) {
|
||||
return testing::AssertionFailure() << elements.size() << " != " << names.size()
|
||||
<< " elements: " << mappedElementVectorToString(elements);
|
||||
}
|
||||
return elementsMatch(shape, names);
|
||||
}
|
||||
|
||||
std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes()
|
||||
{
|
||||
auto boxMaker1 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
|
||||
boxMaker1.Build();
|
||||
auto box1 = boxMaker1.Shape();
|
||||
|
||||
auto boxMaker2 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
|
||||
boxMaker2.Build();
|
||||
auto box2 = boxMaker2.Shape();
|
||||
auto transform = gp_Trsf();
|
||||
transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0));
|
||||
box2.Location(TopLoc_Location(transform));
|
||||
|
||||
return {box1, box2};
|
||||
}
|
||||
|
||||
std::pair<TopoShape, TopoShape> CreateTwoTopoShapeCubes()
|
||||
{
|
||||
auto [box1, box2] = CreateTwoCubes();
|
||||
std::vector<TopoShape> vec;
|
||||
long tag = 1L;
|
||||
for (TopExp_Explorer exp(box1, TopAbs_FACE); exp.More(); exp.Next()) {
|
||||
vec.emplace_back(TopoShape(exp.Current(), tag++));
|
||||
}
|
||||
TopoShape box1ts;
|
||||
box1ts.makeElementCompound(vec);
|
||||
box1ts.Tag = tag++;
|
||||
vec.clear();
|
||||
for (TopExp_Explorer exp(box2, TopAbs_FACE); exp.More(); exp.Next()) {
|
||||
vec.emplace_back(TopoShape(exp.Current(), tag++));
|
||||
}
|
||||
TopoShape box2ts;
|
||||
box2ts.Tag = tag++;
|
||||
box2ts.makeElementCompound(vec);
|
||||
|
||||
return {box1ts, box2ts};
|
||||
}
|
||||
|
||||
} // namespace PartTestHelpers
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
101
tests/src/Mod/Part/App/PartTestHelpers.h
Normal file
101
tests/src/Mod/Part/App/PartTestHelpers.h
Normal file
@@ -0,0 +1,101 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <boost/format.hpp>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include "Base/Interpreter.h"
|
||||
#include <Base/Precision.h>
|
||||
#include "Mod/Part/App/FeaturePartBox.h"
|
||||
#include "Mod/Part/App/FeaturePartFuse.h"
|
||||
#include "Mod/Part/App/FeatureFillet.h"
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepBuilderAPI_MakeFace.hxx>
|
||||
#include <BRepBuilderAPI_MakeVertex.hxx>
|
||||
#include <BRepBuilderAPI_MakeWire.hxx>
|
||||
#include <BRepGProp.hxx>
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <GC_MakeCircle.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
|
||||
namespace PartTestHelpers
|
||||
{
|
||||
|
||||
using namespace Data;
|
||||
using namespace Part;
|
||||
|
||||
double getVolume(const TopoDS_Shape& shape);
|
||||
|
||||
double getArea(const TopoDS_Shape& shape);
|
||||
|
||||
double getLength(const TopoDS_Shape& shape);
|
||||
|
||||
std::vector<Part::FilletElement> _getFilletEdges(
|
||||
const std::vector<int>& edges,
|
||||
double startRadius,
|
||||
double endRadius
|
||||
);
|
||||
|
||||
class PartTestHelperClass
|
||||
{
|
||||
public:
|
||||
App::Document* _doc;
|
||||
std::string _docName;
|
||||
std::array<Part::Box*, 6> _boxes; // NOLINT magic number
|
||||
void createTestDoc();
|
||||
};
|
||||
|
||||
const double minimalDistance = Base::Precision::Confusion() * 1000;
|
||||
|
||||
void executePython(const std::vector<std::string>& python);
|
||||
|
||||
void rectangle(double height, double width, const char* name);
|
||||
|
||||
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge> CreateRectFace(
|
||||
float len = 2.0,
|
||||
float wid = 3.0
|
||||
);
|
||||
|
||||
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Wire> CreateFaceWithRoundHole(
|
||||
float len = 2.0,
|
||||
float wid = 3.0,
|
||||
float radius = 1.0
|
||||
);
|
||||
|
||||
testing::AssertionResult boxesMatch(
|
||||
const Base::BoundBox3d& b1,
|
||||
const Base::BoundBox3d& b2,
|
||||
double prec = 1e-05
|
||||
); // NOLINT
|
||||
|
||||
std::map<IndexedName, MappedName> elementMap(const TopoShape& shape);
|
||||
|
||||
/**
|
||||
* Checks that all the names occur in the shape's element map. Map can contain additional names
|
||||
* @param shape The Shape
|
||||
* @param names The Names
|
||||
* @return A test result, suitable for display by the gtest framework
|
||||
*/
|
||||
testing::AssertionResult elementsMatch(const TopoShape& shape, const std::vector<std::string>& names);
|
||||
|
||||
/**
|
||||
* Checks that all the names occur in the shape's element map and that there are no additional names
|
||||
* @param shape The Shape
|
||||
* @param names The Names
|
||||
* @return A test result, suitable for display by the gtest framework
|
||||
*/
|
||||
testing::AssertionResult allElementsMatch(const TopoShape& shape, const std::vector<std::string>& names);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Two raw shape cubes without element maps
|
||||
*/
|
||||
std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Two TopoShape cubes with elementMaps
|
||||
*/
|
||||
std::pair<TopoShape, TopoShape> CreateTwoTopoShapeCubes();
|
||||
} // namespace PartTestHelpers
|
||||
271
tests/src/Mod/Part/App/PropertyTopoShape.cpp
Normal file
271
tests/src/Mod/Part/App/PropertyTopoShape.cpp
Normal file
@@ -0,0 +1,271 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <BRepFilletAPI_MakeFillet.hxx>
|
||||
#include "Mod/Part/App/FeaturePartCommon.h"
|
||||
#include "Mod/Part/App/PropertyTopoShape.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
#include "PartTestHelpers.h"
|
||||
#include "Mod/Part/App/TopoShapeCompoundPy.h"
|
||||
|
||||
using namespace Part;
|
||||
using namespace PartTestHelpers;
|
||||
|
||||
class PropertyTopoShapeTest: public ::testing::Test, public PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
_common = _doc->addObject<Common>();
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
_common->execute(); // We should now have an elementMap with 26 entries.
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
std::string getDocumentXml() const
|
||||
{
|
||||
return R"x(<?xml version='1.0' encoding='utf-8'?>
|
||||
<Document SchemaVersion="4" ProgramVersion="0.22R35485 +5758 (Git)" FileVersion="1" Uid="2795701f-8074-4bb6-b707-b2c97acf4128" StringHasher="1">
|
||||
<StringHasher saveall="0" threshold="0" count="0" new="1"/>
|
||||
<StringHasher2 count="1">
|
||||
<![CDATA[
|
||||
-1.0 0:Shape cache
|
||||
]]>
|
||||
</StringHasher2>
|
||||
<Properties Count="1" TransientCount="0">
|
||||
<Property name="Uid" type="App::PropertyUUID" status="16777217">
|
||||
<Uuid value="2795701f-8074-4bb6-b707-b2c97acf4128"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Objects Count="1" Dependencies="1">
|
||||
<ObjectDeps Name="Sketch" Count="0"/>
|
||||
<Object type="Sketcher::SketchObject" name="Sketch" id="11" revision="16711878" />
|
||||
</Objects>
|
||||
<ObjectData Count="1">
|
||||
<Object name="Sketch" Extensions="True">
|
||||
<Properties Count="1" TransientCount="0">
|
||||
<Property name="Shape" type="Part::PropertyPartShape">
|
||||
<Part HasherIndex="0" ElementMap="1.15.70200.4" file="Sketch.Shape.brp"/>
|
||||
<ElementMap new="1" count="1"><Element key="Dummy" value="Dummy"/></ElementMap>
|
||||
<ElementMap2 count="8">
|
||||
<![CDATA[
|
||||
1 PostfixCount 3
|
||||
Edge
|
||||
Vertex
|
||||
;SKT
|
||||
|
||||
MapCount 1
|
||||
|
||||
ElementMap 1 1 2
|
||||
|
||||
Edge
|
||||
|
||||
ChildCount 0
|
||||
|
||||
NameCount 5
|
||||
0
|
||||
;g1.3 0
|
||||
;g2.3 0
|
||||
;g3.3 0
|
||||
;g4.3 0
|
||||
|
||||
Vertex
|
||||
|
||||
ChildCount 0
|
||||
|
||||
NameCount 5
|
||||
0
|
||||
;g1v1.3 0
|
||||
;g1v2.3 0
|
||||
;g2v2.3 0
|
||||
;g3v2.3 0
|
||||
|
||||
EndMap
|
||||
]]>
|
||||
</ElementMap2>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Object>
|
||||
</ObjectData>
|
||||
</Document>
|
||||
)x";
|
||||
}
|
||||
|
||||
Common* _common = nullptr; // NOLINT Can't be private in a test framework
|
||||
};
|
||||
|
||||
TEST_F(PropertyTopoShapeTest, testPropertyPartShapeTopoShape)
|
||||
{
|
||||
// Arrange
|
||||
auto partShape = PropertyPartShape();
|
||||
auto topoShapeIn = _common->Shape.getShape();
|
||||
auto topoDsShapeIn = _common->Shape.getShape().getShape();
|
||||
// Act
|
||||
partShape.setValue(topoShapeIn);
|
||||
auto topoShapeOut = partShape.getShape();
|
||||
auto topoDsShapeOut = partShape.getValue();
|
||||
// Assert
|
||||
EXPECT_TRUE(topoShapeOut.isSame(topoShapeIn));
|
||||
EXPECT_TRUE(topoDsShapeOut.IsSame(topoDsShapeIn));
|
||||
EXPECT_EQ(getVolume(topoDsShapeOut), 3);
|
||||
EXPECT_EQ(topoShapeOut.getElementMapSize(), 26);
|
||||
}
|
||||
|
||||
TEST_F(PropertyTopoShapeTest, testPropertyPartShapeTopoDSShape)
|
||||
{
|
||||
// Arrange
|
||||
auto property = _boxes[0]->addDynamicProperty("Part::PropertyPartShape", "test");
|
||||
auto partShape = dynamic_cast<PropertyPartShape*>(property);
|
||||
auto topoShapeIn = _common->Shape.getShape();
|
||||
auto topoDsShapeIn = _common->Shape.getShape().getShape();
|
||||
// Act
|
||||
// The second parameter of setValue, whether to resetElementMap is never called and irrelevant.
|
||||
// It appears to exist only to pass to the lower level setShape call.
|
||||
partShape->setValue(topoDsShapeIn);
|
||||
auto topoShapeOut = partShape->getShape();
|
||||
auto topoDsShapeOut = partShape->getValue();
|
||||
// Assert
|
||||
EXPECT_FALSE(topoShapeOut.isSame(topoShapeIn));
|
||||
EXPECT_TRUE(topoDsShapeOut.IsSame(topoDsShapeIn));
|
||||
EXPECT_EQ(getVolume(topoDsShapeOut), 3);
|
||||
EXPECT_EQ(topoShapeOut.getElementMapSize(), 0); // We passed in a TopoDS_Shape so lost the map
|
||||
}
|
||||
|
||||
TEST_F(PropertyTopoShapeTest, testPropertyPartShapeGetPyObject)
|
||||
{
|
||||
// Arrange
|
||||
Py_Initialize();
|
||||
Base::PyGILStateLocker lock;
|
||||
auto partShape = PropertyPartShape();
|
||||
auto topoDsShapeIn = _common->Shape.getShape().getShape();
|
||||
auto topoDsShapeIn2 = _boxes[3]->Shape.getShape().getShape();
|
||||
// Act
|
||||
partShape.setValue(topoDsShapeIn);
|
||||
auto pyObj = partShape.getPyObject();
|
||||
// Assert
|
||||
EXPECT_TRUE(PyObject_TypeCheck(pyObj, &TopoShapeCompoundPy::Type)); // _common is a compound.
|
||||
// We can't build a TopoShapeCompoundPy directly ( protected destructor ), so we'll flip
|
||||
// the compound out and in to prove setPyObject works as expected.
|
||||
// Act
|
||||
partShape.setValue(topoDsShapeIn2);
|
||||
auto pyObj2 = partShape.getPyObject();
|
||||
// Assert the shape is no longer a compound
|
||||
EXPECT_FALSE(PyObject_TypeCheck(pyObj2, &TopoShapeCompoundPy::Type)); // _boxes[3] is not a
|
||||
// compound.
|
||||
Py_XDECREF(pyObj2);
|
||||
// Act
|
||||
partShape.setPyObject(pyObj);
|
||||
auto pyObj3 = partShape.getPyObject();
|
||||
// Assert the shape returns to a compound if we setPyObject
|
||||
EXPECT_TRUE(PyObject_TypeCheck(pyObj3, &TopoShapeCompoundPy::Type)); // _common is a compound.
|
||||
Py_XDECREF(pyObj3);
|
||||
Py_XDECREF(pyObj);
|
||||
}
|
||||
|
||||
// Possible future PropertyPartShape tests:
|
||||
// Copy, Paste, getMemSize, beforeSave, Save. Restore
|
||||
|
||||
|
||||
TEST_F(PropertyTopoShapeTest, testShapeHistory)
|
||||
{
|
||||
// Arrange
|
||||
TopoDS_Shape baseShape = _boxes[0]->Shape.getShape().getShape();
|
||||
BRepFilletAPI_MakeFillet mkFillet(baseShape);
|
||||
auto edges = _boxes[0]->Shape.getShape().getSubTopoShapes(TopAbs_EDGE);
|
||||
mkFillet.Add(0.1, 0.1, TopoDS::Edge(edges[0].getShape()));
|
||||
TopoDS_Shape newShape = mkFillet.Shape();
|
||||
// Act to test the constructor
|
||||
auto hist = ShapeHistory(mkFillet, TopAbs_EDGE, newShape, baseShape);
|
||||
// Assert
|
||||
EXPECT_EQ(hist.type, TopAbs_EDGE);
|
||||
EXPECT_EQ(hist.shapeMap.size(), 11); // We filleted away one of the cubes 12 Edges
|
||||
// Act to test the join operation
|
||||
hist.join(hist);
|
||||
// Assert
|
||||
EXPECT_EQ(hist.type, TopAbs_EDGE);
|
||||
EXPECT_EQ(hist.shapeMap.size(), 9); // TODO: Is this correct?
|
||||
// Act to test the reset operation
|
||||
hist.reset(mkFillet, TopAbs_VERTEX, newShape, baseShape);
|
||||
// Assert
|
||||
EXPECT_EQ(hist.type, TopAbs_VERTEX);
|
||||
EXPECT_EQ(hist.shapeMap.size(), 8); // Vertexes on a cube.
|
||||
}
|
||||
|
||||
TEST_F(PropertyTopoShapeTest, testPropertyShapeHistory)
|
||||
{
|
||||
// N/A nothing to really test
|
||||
}
|
||||
|
||||
TEST_F(PropertyTopoShapeTest, testPropertyShapeCache)
|
||||
{
|
||||
// Arrange
|
||||
PropertyShapeCache propertyShapeCache;
|
||||
TopoShape topoShapeIn {_boxes[0]->Shape.getShape()}; // Any TopoShape to test with
|
||||
TopoShape topoShapeOut;
|
||||
const char* subName = "Face1"; // Cache key
|
||||
// Act
|
||||
auto gotShapeNotYet = propertyShapeCache.getShape(_boxes[0], topoShapeOut, subName);
|
||||
propertyShapeCache.setShape(_boxes[0], topoShapeIn, subName);
|
||||
auto gotShapeGood = propertyShapeCache.getShape(_boxes[0], topoShapeOut, subName);
|
||||
// Assert
|
||||
ASSERT_FALSE(gotShapeNotYet);
|
||||
ASSERT_TRUE(gotShapeGood);
|
||||
EXPECT_EQ(getVolume(topoShapeIn.getShape()), 6);
|
||||
EXPECT_EQ(getVolume(topoShapeOut.getShape()), 6);
|
||||
EXPECT_TRUE(topoShapeIn.isSame(topoShapeOut));
|
||||
}
|
||||
|
||||
TEST_F(PropertyTopoShapeTest, testPropertyShapeCachePyObj)
|
||||
{
|
||||
// Arrange
|
||||
Py_Initialize();
|
||||
Base::PyGILStateLocker lock;
|
||||
PropertyShapeCache catalyst;
|
||||
auto propertyShapeCache = catalyst.get(_boxes[1], true);
|
||||
auto faces = _boxes[1]->Shape.getShape().getSubTopoShapes(TopAbs_FACE);
|
||||
propertyShapeCache->setShape(_boxes[1], faces[0], "Face1");
|
||||
propertyShapeCache->setShape(_boxes[1], faces[1], "Face2");
|
||||
propertyShapeCache->setShape(_boxes[1], faces[2], "Face3");
|
||||
propertyShapeCache->setShape(_boxes[1], faces[3], "Face4");
|
||||
auto eraseList = PyList_New(2);
|
||||
PyList_SetItem(eraseList, 0, PyUnicode_FromString("Face2"));
|
||||
PyList_SetItem(eraseList, 1, PyUnicode_FromString("Face3"));
|
||||
// Act
|
||||
auto pyObjOut = propertyShapeCache->getPyObject();
|
||||
propertyShapeCache->setPyObject(eraseList); // pyObjInRepr);
|
||||
auto pyObjOutErased = propertyShapeCache->getPyObject();
|
||||
// The faces that come back from python are in a random order compared to what was passed in
|
||||
// so testing them individually is difficult. We'll just make sure the counts are right.
|
||||
EXPECT_EQ(PyList_Size(pyObjOut), 4); // All four faces we added to the cache
|
||||
EXPECT_EQ(PyList_Size(pyObjOutErased), 2); // setPyObject removed Face2 and Face3
|
||||
Py_XDECREF(pyObjOut);
|
||||
Py_XDECREF(pyObjOutErased);
|
||||
}
|
||||
|
||||
TEST_F(PropertyTopoShapeTest, testRestore)
|
||||
{
|
||||
// Test case for https://github.com/FreeCAD/FreeCAD/pull/16576
|
||||
std::stringstream str(getDocumentXml());
|
||||
Base::XMLReader reader("Document.xml", str);
|
||||
App::StringHasher hasher;
|
||||
hasher.Restore(reader);
|
||||
|
||||
Part::PropertyPartShape prop;
|
||||
prop.Restore(reader);
|
||||
|
||||
EXPECT_STREQ(reader.localName(), "ElementMap2");
|
||||
EXPECT_EQ(reader.level(), 5);
|
||||
EXPECT_EQ(reader.getAttributeCount(), 1);
|
||||
EXPECT_TRUE(reader.isValid());
|
||||
EXPECT_TRUE(reader.isEndOfElement());
|
||||
}
|
||||
58
tests/src/Mod/Part/App/TopoDS_Shape.cpp
Normal file
58
tests/src/Mod/Part/App/TopoDS_Shape.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <Standard_TypeMismatch.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <TopoDS_Vertex.hxx>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
class TestTopoDS_Shape: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
};
|
||||
|
||||
// NOLINTBEGIN
|
||||
// clang-format off
|
||||
TEST_F(TestTopoDS_Shape, TestCastEdgeToVertex)
|
||||
{
|
||||
BRepBuilderAPI_MakeEdge mkEdge(gp_Pnt(0, 0, 0), gp_Pnt(10, 0, 0));
|
||||
TopoDS_Edge edge = mkEdge.Edge();
|
||||
TopoDS_Vertex vertex;
|
||||
EXPECT_THROW(vertex = TopoDS::Vertex(edge), Standard_TypeMismatch);
|
||||
EXPECT_TRUE(vertex.IsNull());
|
||||
}
|
||||
|
||||
TEST_F(TestTopoDS_Shape, TestCastNullVertex)
|
||||
{
|
||||
TopoDS_Vertex vertex1;
|
||||
TopoDS_Vertex vertex2;
|
||||
EXPECT_NO_THROW(vertex2 = TopoDS::Vertex(vertex1));
|
||||
EXPECT_TRUE(vertex2.IsNull());
|
||||
}
|
||||
|
||||
TEST_F(TestTopoDS_Shape, TestCastNullEdge)
|
||||
{
|
||||
TopoDS_Edge edge;
|
||||
TopoDS_Vertex vertex;
|
||||
EXPECT_NO_THROW(vertex = TopoDS::Vertex(edge));
|
||||
EXPECT_TRUE(vertex.IsNull());
|
||||
}
|
||||
|
||||
TEST_F(TestTopoDS_Shape, TestExploreNullShape)
|
||||
{
|
||||
TopoDS_Face face;
|
||||
TopExp_Explorer xp(face, TopAbs_FACE);
|
||||
EXPECT_FALSE(xp.More());
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
// NOLINTEND
|
||||
160
tests/src/Mod/Part/App/TopoShape.cpp
Normal file
160
tests/src/Mod/Part/App/TopoShape.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "PartTestHelpers.h"
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
|
||||
|
||||
class TopoShapeTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
Base::Interpreter().runString("import Part");
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
_hasher = Base::Reference<App::StringHasher>(new App::StringHasher);
|
||||
ASSERT_EQ(_hasher.getRefCount(), 1);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::string _docName;
|
||||
Data::ElementIDRefs _sid;
|
||||
App::StringHasherRef _hasher;
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
TEST_F(TopoShapeTest, TestElementTypeFace1)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Face1"),
|
||||
std::make_pair(std::string("Face"), 1UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeEdge12)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Edge12"),
|
||||
std::make_pair(std::string("Edge"), 12UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeVertex3)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Vertex3"),
|
||||
std::make_pair(std::string("Vertex"), 3UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeFacer)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Facer"),
|
||||
std::make_pair(std::string(), 0UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeVertex)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Vertex"),
|
||||
std::make_pair(std::string(), 0UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeEmpty)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex(""),
|
||||
std::make_pair(std::string(), 0UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeNull)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex(nullptr),
|
||||
std::make_pair(std::string(), 0UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeWithHash)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex(";#7:1;:G0;XTR;:H11a6:8,F.Face3"),
|
||||
std::make_pair(std::string("Face"), 3UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeWithSubelements)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Part.Body.Pad.Face3"),
|
||||
std::make_pair(std::string(), 0UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeNonMatching)
|
||||
{
|
||||
for (std::array elements = {"Face0", "Face01", "XFace3", "Face3extra"};
|
||||
const auto& element : elements) {
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex(element),
|
||||
std::make_pair(std::string(), 0UL));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestTypeFace1)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Face1"),
|
||||
std::make_pair(std::string("Face"), 1UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestTypeEdge12)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Edge12"),
|
||||
std::make_pair(std::string("Edge"), 12UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestTypeVertex3)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Vertex3"),
|
||||
std::make_pair(std::string("Vertex"), 3UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestTypeFacer)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Facer"),
|
||||
std::make_pair(std::string("Facer"), 0UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestTypeVertex)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Vertex"),
|
||||
std::make_pair(std::string("Vertex"), 0UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestTypeEmpty)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getTypeAndIndex(""),
|
||||
std::make_pair(std::string(), 0UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestTypeNull)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getTypeAndIndex(nullptr),
|
||||
std::make_pair(std::string(), 0UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestGetSubshape)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = PartTestHelpers::CreateTwoTopoShapeCubes();
|
||||
// Act
|
||||
auto face = cube1.getSubShape("Face2");
|
||||
auto vertex = cube2.getSubShape(TopAbs_VERTEX,2);
|
||||
auto silentFail = cube1.getSubShape("NotThere", true);
|
||||
// Assert
|
||||
EXPECT_EQ(face.ShapeType(), TopAbs_FACE);
|
||||
EXPECT_EQ(vertex.ShapeType(), TopAbs_VERTEX);
|
||||
EXPECT_TRUE(silentFail.IsNull());
|
||||
EXPECT_THROW(cube1.getSubShape("Face7"), Base::IndexError); // Out of range
|
||||
EXPECT_THROW(cube1.getSubShape("WOOHOO", false), Base::ValueError); // Invalid
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
292
tests/src/Mod/Part/App/TopoShapeCache.cpp
Normal file
292
tests/src/Mod/Part/App/TopoShapeCache.cpp
Normal file
@@ -0,0 +1,292 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
#include <Mod/Part/App/TopoShapeCache.h>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <gp_Quaternion.hxx>
|
||||
#include <TopoDS_TVertex.hxx>
|
||||
#include <BRep_TVertex.hxx>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepAlgoAPI_Fuse.hxx>
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
class ShapeRelationKey: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ShapeRelationKey, HistoryTraceTypeComparison)
|
||||
{
|
||||
// Arrange
|
||||
Data::MappedName mappedName {"mappedName"};
|
||||
Part::HistoryTraceType htt1 {Part::HistoryTraceType::stopOnTypeChange};
|
||||
Part::HistoryTraceType htt2 {Part::HistoryTraceType::followTypeChange};
|
||||
Part::ShapeRelationKey key1 {mappedName, htt1};
|
||||
Part::ShapeRelationKey key2 {mappedName, htt2};
|
||||
|
||||
// Act
|
||||
bool key1LessThanKey2 = key1 < key2;
|
||||
|
||||
// Assert
|
||||
ASSERT_TRUE(key1LessThanKey2);
|
||||
}
|
||||
|
||||
class TopoShapeCacheTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
_sids = &_sid;
|
||||
_hasher = Base::Reference<App::StringHasher>(new App::StringHasher);
|
||||
ASSERT_EQ(_hasher.getRefCount(), 1);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _docName;
|
||||
Data::ElementIDRefs _sid;
|
||||
QVector<App::StringIDRef>* _sids = nullptr;
|
||||
App::StringHasherRef _hasher;
|
||||
};
|
||||
|
||||
TEST_F(TopoShapeCacheTest, ConstructionFromTopoDS_Shape)
|
||||
{
|
||||
// Arrange - create a TopoDS shape with some location transformation applied
|
||||
TopoDS_Vertex vertex;
|
||||
gp_Quaternion quaternion(1.0, 2.0, 3.0, 4.0);
|
||||
gp_Trsf transform;
|
||||
transform.SetRotation(quaternion);
|
||||
auto location = TopLoc_Location(transform);
|
||||
vertex.Location(location);
|
||||
|
||||
// Act
|
||||
auto cache = Part::TopoShapeCache(vertex);
|
||||
|
||||
// Assert - ensure the location of the cached shape was zeroed out
|
||||
EXPECT_NE(cache.shape.Location(), vertex.Location());
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, InsertRelationIntoEmptyTableCompacts)
|
||||
{
|
||||
// Arrange
|
||||
Data::IndexedName indexedName {"EDGE1"};
|
||||
auto mappedName = Data::MappedName::fromRawData("#94;:G0;XTR;:H19:8,F;:H1a,F;BND:-1:0;:H1b:10,F");
|
||||
ASSERT_TRUE(mappedName.isRaw());
|
||||
Data::MappedElement mappedElement1 {indexedName, mappedName};
|
||||
QVector<Data::MappedElement> vectorOfElements {mappedElement1};
|
||||
TopoDS_Vertex vertex;
|
||||
Part::TopoShapeCache cache(vertex);
|
||||
Part::ShapeRelationKey key {mappedName, Part::HistoryTraceType::followTypeChange};
|
||||
|
||||
// Act
|
||||
cache.insertRelation(key, vectorOfElements);
|
||||
|
||||
// Assert
|
||||
auto foundIterator = cache.relations.find(key);
|
||||
EXPECT_NE(foundIterator, cache.relations.end());
|
||||
EXPECT_FALSE(foundIterator->first.name.isRaw()); // compact() was called
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, InsertAlreadyExistsUpdatesExisting)
|
||||
{
|
||||
// Arrange
|
||||
Data::IndexedName indexedName {"EDGE1"};
|
||||
Data::MappedName mappedName("#94;:G0;XTR;:H19:8,F;:H1a,F;BND:-1:0;:H1b:10,F");
|
||||
Data::MappedElement mappedElement1 {indexedName, mappedName};
|
||||
QVector<Data::MappedElement> vectorOfElements {mappedElement1};
|
||||
TopoDS_Vertex vertex;
|
||||
Part::TopoShapeCache cache(vertex);
|
||||
Part::ShapeRelationKey key {mappedName, Part::HistoryTraceType::followTypeChange};
|
||||
|
||||
// Act
|
||||
cache.insertRelation(key, vectorOfElements);
|
||||
QVector<Data::MappedElement> emptyVector;
|
||||
cache.insertRelation(key, emptyVector);
|
||||
|
||||
// Assert
|
||||
EXPECT_TRUE(cache.relations.find(key)->second.empty());
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, IsTouchedNotPartners)
|
||||
{
|
||||
// Arrange
|
||||
BRep_TVertex* vertex1 = new BRep_TVertex;
|
||||
vertex1->Pnt(gp_Pnt(1.0, 1.0, 1.0));
|
||||
BRep_TVertex* vertex2 = new BRep_TVertex;
|
||||
vertex2->Pnt(gp_Pnt(2.0, 2.0, 2.0));
|
||||
opencascade::handle<TopoDS_TShape> handle1(vertex1);
|
||||
opencascade::handle<TopoDS_TShape> handle2(vertex2);
|
||||
TopoDS_Vertex tds1;
|
||||
TopoDS_Vertex tds2;
|
||||
tds1.TShape(handle1);
|
||||
tds2.TShape(handle2);
|
||||
ASSERT_FALSE(tds1.IsPartner(tds2));
|
||||
Part::TopoShapeCache cache(tds1);
|
||||
|
||||
// Act & Assert
|
||||
EXPECT_TRUE(cache.isTouched(tds2));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, IsTouchedArePartners)
|
||||
{
|
||||
// Arrange
|
||||
BRep_TVertex* vertex1 = new BRep_TVertex;
|
||||
vertex1->Pnt(gp_Pnt(1.0, 1.0, 1.0));
|
||||
opencascade::handle<TopoDS_TShape> handle1(vertex1);
|
||||
TopoDS_Vertex tds1;
|
||||
TopoDS_Vertex tds2;
|
||||
tds1.TShape(handle1);
|
||||
tds2.TShape(handle1);
|
||||
ASSERT_TRUE(tds1.IsPartner(tds2));
|
||||
Part::TopoShapeCache cache(tds1);
|
||||
|
||||
// Act & Assert
|
||||
EXPECT_FALSE(cache.isTouched(tds2));
|
||||
}
|
||||
|
||||
std::tuple<TopoDS_Shape, std::pair<TopoDS_Shape, TopoDS_Shape>> CreateShapeWithSubshapes()
|
||||
{
|
||||
auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge();
|
||||
auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(2.0, 0.0, 0.0)).Edge();
|
||||
auto fuse = BRepAlgoAPI_Fuse(edge1, edge2);
|
||||
fuse.Build();
|
||||
return {fuse.Shape(), {edge1, edge2}};
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, GetAncestrySHAPE)
|
||||
{
|
||||
// Arrange
|
||||
auto shape = std::get<0>(CreateShapeWithSubshapes());
|
||||
Part::TopoShapeCache cache(shape);
|
||||
|
||||
// Act
|
||||
auto ancestry = cache.getAncestry(TopAbs_SHAPE);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(2, ancestry.count());
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, GetAncestryEDGE)
|
||||
{
|
||||
// Arrange
|
||||
auto shape = std::get<0>(CreateShapeWithSubshapes());
|
||||
Part::TopoShapeCache cache(shape);
|
||||
|
||||
// Act
|
||||
auto ancestry = cache.getAncestry(TopAbs_EDGE);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(2, ancestry.count());
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, GetAncestryFACE)
|
||||
{
|
||||
// Arrange
|
||||
auto shape = std::get<0>(CreateShapeWithSubshapes());
|
||||
Part::TopoShapeCache cache(shape);
|
||||
|
||||
// Act
|
||||
auto ancestry = cache.getAncestry(TopAbs_FACE);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(0, ancestry.count());
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, CountShape)
|
||||
{
|
||||
// Arrange
|
||||
auto shape = std::get<0>(CreateShapeWithSubshapes());
|
||||
Part::TopoShapeCache cache(shape);
|
||||
|
||||
// Act
|
||||
int countOfEdges = cache.countShape(TopAbs_EDGE);
|
||||
int countOfFaces = cache.countShape(TopAbs_FACE);
|
||||
int countOfShapes = cache.countShape(TopAbs_SHAPE);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(2, countOfEdges);
|
||||
EXPECT_EQ(0, countOfFaces);
|
||||
EXPECT_EQ(2, countOfShapes);
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, FindShapeGivenSubshape)
|
||||
{
|
||||
// Arrange
|
||||
const auto [shape, ancestors] = CreateShapeWithSubshapes();
|
||||
Part::TopoShapeCache cache(shape);
|
||||
|
||||
// Act
|
||||
auto shapeResult1 = cache.findShape(ancestors.first, shape);
|
||||
auto shapeResult2 = cache.findShape(ancestors.second, shape);
|
||||
|
||||
// Assert
|
||||
EXPECT_NE(0, shapeResult1);
|
||||
EXPECT_NE(0, shapeResult2);
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, FindShapeGivenTypeAndIndex)
|
||||
{
|
||||
// Arrange
|
||||
const auto [shape, ancestors] = CreateShapeWithSubshapes();
|
||||
Part::TopoShapeCache cache(shape);
|
||||
|
||||
// Act
|
||||
auto shapeResult = cache.findShape(ancestors.first, TopAbs_EDGE, 1); // NOT zero-indexed!
|
||||
|
||||
// Assert
|
||||
EXPECT_FALSE(shapeResult.IsNull());
|
||||
}
|
||||
|
||||
std::tuple<TopoDS_Shape, std::pair<TopoDS_Shape, TopoDS_Shape>> CreateFusedCubes()
|
||||
{
|
||||
auto boxMaker1 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
|
||||
boxMaker1.Build();
|
||||
auto box1 = boxMaker1.Shape();
|
||||
|
||||
auto boxMaker2 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
|
||||
boxMaker2.Build();
|
||||
auto box2 = boxMaker2.Shape();
|
||||
auto transform = gp_Trsf();
|
||||
transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0));
|
||||
box2.Location(TopLoc_Location(transform));
|
||||
|
||||
auto fuse = BRepAlgoAPI_Fuse(box1, box2);
|
||||
fuse.Build();
|
||||
|
||||
return {fuse, {box1, box2}};
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeCacheTest, FindAncestor)
|
||||
{
|
||||
// Arrange
|
||||
const auto [shape, ancestors] = CreateFusedCubes();
|
||||
Part::TopoShapeCache cache(shape);
|
||||
|
||||
// Act
|
||||
auto ancestorResultCompound = cache.findAncestor(ancestors.first, shape, TopAbs_COMPOUND);
|
||||
|
||||
// Assert
|
||||
EXPECT_FALSE(ancestorResultCompound.IsNull());
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
3364
tests/src/Mod/Part/App/TopoShapeExpansion.cpp
Normal file
3364
tests/src/Mod/Part/App/TopoShapeExpansion.cpp
Normal file
File diff suppressed because it is too large
Load Diff
56
tests/src/Mod/Part/App/TopoShapeMakeElementRefine.cpp
Normal file
56
tests/src/Mod/Part/App/TopoShapeMakeElementRefine.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
class FeaturePartMakeElementRefineTest: public ::testing::Test,
|
||||
public PartTestHelpers::PartTestHelperClass
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
createTestDoc();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
};
|
||||
|
||||
TEST_F(FeaturePartMakeElementRefineTest, makeElementRefineBoxes)
|
||||
{
|
||||
// Arrange
|
||||
auto _doc = App::GetApplication().getActiveDocument();
|
||||
auto _fuse = _doc->addObject<Part::Fuse>();
|
||||
_fuse->Base.setValue(_boxes[0]);
|
||||
_fuse->Tool.setValue(_boxes[3]);
|
||||
_fuse->Refine.setValue(false);
|
||||
// Act
|
||||
_fuse->execute();
|
||||
Part::TopoShape ts = _fuse->Shape.getShape();
|
||||
Part::TopoShape refined = ts.makeElementRefine();
|
||||
double volume = PartTestHelpers::getVolume(ts.getShape());
|
||||
double refinedVolume = PartTestHelpers::getVolume(refined.getShape());
|
||||
Base::BoundBox3d bb = ts.getBoundBox();
|
||||
// Assert
|
||||
EXPECT_TRUE(bb.IsValid());
|
||||
EXPECT_DOUBLE_EQ(volume, 12.0);
|
||||
EXPECT_DOUBLE_EQ(refinedVolume, 12.0); // Refine shouldn't change the volume
|
||||
EXPECT_EQ(ts.countSubElements("Face"), 10); // Two boxes touching each loose one face
|
||||
EXPECT_EQ(ts.countSubElements("Edge"), 20); // Two boxes touching loose 4 edges
|
||||
EXPECT_EQ(refined.countSubElements("Face"), 6); // After refining it is one box
|
||||
EXPECT_EQ(refined.countSubElements("Edge"), 12); // 12 edges in a box
|
||||
// Make sure that the number of elements in the elementMaps is correct.
|
||||
EXPECT_EQ(ts.getElementMapSize(), 42);
|
||||
EXPECT_EQ(refined.getElementMapSize(), 26);
|
||||
// TODO: Refine doesn't work on compounds, so we're going to need a binary operation or the
|
||||
// like, and those don't exist yet. Once they do, this test can be expanded
|
||||
}
|
||||
172
tests/src/Mod/Part/App/TopoShapeMakeShape.cpp
Normal file
172
tests/src/Mod/Part/App/TopoShapeMakeShape.cpp
Normal file
@@ -0,0 +1,172 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
// Tests for the makeShape methods, extracted from the main set of tests for TopoShape
|
||||
// due to length and complexity.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
#include "PartTestHelpers.h"
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
#include <Mod/Part/App/TopoShapeOpCode.h>
|
||||
|
||||
using namespace Data;
|
||||
using namespace Part;
|
||||
using namespace PartTestHelpers;
|
||||
|
||||
class TopoShapeMakeShapeTests: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
_sids = &_sid;
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
Part::TopoShape* Shape()
|
||||
{
|
||||
return &_shape;
|
||||
}
|
||||
|
||||
Part::TopoShape::Mapper* Mapper()
|
||||
{
|
||||
return &_mapper;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _docName;
|
||||
Data::ElementIDRefs _sid;
|
||||
QVector<App::StringIDRef>* _sids = nullptr;
|
||||
Part::TopoShape _shape;
|
||||
Part::TopoShape::Mapper _mapper;
|
||||
};
|
||||
|
||||
TEST_F(TopoShapeMakeShapeTests, nullShapeThrows)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = CreateTwoCubes();
|
||||
std::vector<Part::TopoShape> sources {cube1, cube2};
|
||||
TopoDS_Vertex nullShape;
|
||||
|
||||
// Act and assert
|
||||
EXPECT_THROW(
|
||||
Shape()->makeShapeWithElementMap(nullShape, *Mapper(), sources),
|
||||
Part::NullShapeException
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMakeShapeTests, shapeVertex)
|
||||
{
|
||||
// Arrange
|
||||
BRepBuilderAPI_MakeVertex vertexMaker = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 10, 10));
|
||||
TopoShape topoShape(vertexMaker.Vertex(), 1L);
|
||||
// Act
|
||||
TopoShape& result = topoShape.makeElementShape(vertexMaker, topoShape);
|
||||
// Assert
|
||||
EXPECT_EQ(result.getElementMap().size(), 1); // Changed with PR#12471. Probably will change
|
||||
// again after importing other TopoNaming logics
|
||||
EXPECT_EQ(result.countSubElements("Vertex"), 1);
|
||||
EXPECT_EQ(result.countSubShapes("Vertex"), 1);
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMakeShapeTests, thruSections)
|
||||
{
|
||||
// Arrange
|
||||
auto [face1, wire1, edge1, edge2, edge3, edge4] = CreateRectFace();
|
||||
TopoDS_Wire wire2 = wire1;
|
||||
auto transform {gp_Trsf()};
|
||||
transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(0.0, 0.5, 1.0));
|
||||
wire2.Move(TopLoc_Location(transform));
|
||||
TopoShape wire1ts {wire1, 1L};
|
||||
TopoShape wire2ts {wire2, 2L};
|
||||
BRepOffsetAPI_ThruSections thruMaker;
|
||||
thruMaker.AddWire(wire1);
|
||||
thruMaker.AddWire(wire2);
|
||||
TopoShape topoShape {};
|
||||
// Act
|
||||
TopoShape& result
|
||||
= topoShape.makeElementShape(thruMaker, {wire1ts, wire2ts}, OpCodes::ThruSections);
|
||||
auto elements = elementMap(result);
|
||||
// Assert
|
||||
EXPECT_EQ(elements.size(), 24);
|
||||
EXPECT_EQ(elements.count(IndexedName("Vertex", 1)), 1);
|
||||
EXPECT_EQ(getVolume(result.getShape()), 4);
|
||||
EXPECT_TRUE(allElementsMatch(
|
||||
topoShape,
|
||||
{
|
||||
"Edge1;:G(Edge1;K-1;:H2:4,E);TRU;:H1:1a,F", "Edge1;:H1,E", "Edge1;:H2,E",
|
||||
"Edge2;:G(Edge2;K-1;:H2:4,E);TRU;:H1:1a,F", "Edge2;:H1,E", "Edge2;:H2,E",
|
||||
"Edge3;:G(Edge3;K-1;:H2:4,E);TRU;:H1:1a,F", "Edge3;:H1,E", "Edge3;:H2,E",
|
||||
"Edge4;:G(Edge4;K-1;:H2:4,E);TRU;:H1:1a,F", "Edge4;:H1,E", "Edge4;:H2,E",
|
||||
"Vertex1;:G(Vertex1;K-1;:H2:4,V);TRU;:H1:1c,E", "Vertex1;:H1,V", "Vertex1;:H2,V",
|
||||
"Vertex2;:G(Vertex2;K-1;:H2:4,V);TRU;:H1:1c,E", "Vertex2;:H1,V", "Vertex2;:H2,V",
|
||||
"Vertex3;:G(Vertex3;K-1;:H2:4,V);TRU;:H1:1c,E", "Vertex3;:H1,V", "Vertex3;:H2,V",
|
||||
"Vertex4;:G(Vertex4;K-1;:H2:4,V);TRU;:H1:1c,E", "Vertex4;:H1,V", "Vertex4;:H2,V",
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMakeShapeTests, sewing)
|
||||
{
|
||||
// Arrange
|
||||
auto [face1, wire1, edge1, edge2, edge3, edge4] = CreateRectFace();
|
||||
auto face2 = face1;
|
||||
auto transform {gp_Trsf()};
|
||||
transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(0.5, 0.5, 0.0));
|
||||
face2.Move(TopLoc_Location(transform));
|
||||
BRepBuilderAPI_Sewing sewer;
|
||||
sewer.Add(face1);
|
||||
sewer.Add(face2);
|
||||
sewer.Perform();
|
||||
std::vector<TopoShape> sources {{face1, 1L}, {face2, 2L}};
|
||||
TopoShape topoShape {};
|
||||
// Act
|
||||
TopoShape& result = topoShape.makeShapeWithElementMap(
|
||||
sewer.SewedShape(),
|
||||
MapperSewing(sewer),
|
||||
sources,
|
||||
OpCodes::Sewing
|
||||
);
|
||||
|
||||
auto elements = elementMap(result);
|
||||
// Assert
|
||||
EXPECT_EQ(&result, &topoShape);
|
||||
EXPECT_EQ(elements.size(), 18); // Now a single cube
|
||||
EXPECT_EQ(elements.count(IndexedName("Vertex", 1)), 1);
|
||||
EXPECT_EQ(getArea(result.getShape()), 12);
|
||||
// TODO: This element map is suspiciously devoid of anything OpCodes::Sewing (SEW). Is that
|
||||
// right?
|
||||
EXPECT_TRUE(allElementsMatch(
|
||||
topoShape,
|
||||
{
|
||||
"Face1;:H1,F",
|
||||
"Face1;:H2,F",
|
||||
"Edge1;:H2,E",
|
||||
"Edge2;:H2,E",
|
||||
"Edge3;:H2,E",
|
||||
"Edge4;:H2,E",
|
||||
"Edge1;:H1,E",
|
||||
"Edge2;:H1,E",
|
||||
"Edge3;:H1,E",
|
||||
"Edge4;:H1,E",
|
||||
"Vertex1;:H2,V",
|
||||
"Vertex2;:H2,V",
|
||||
"Vertex3;:H2,V",
|
||||
"Vertex4;:H2,V",
|
||||
"Vertex1;:H1,V",
|
||||
"Vertex2;:H1,V",
|
||||
"Vertex3;:H1,V",
|
||||
"Vertex4;:H1,V",
|
||||
}
|
||||
));
|
||||
}
|
||||
367
tests/src/Mod/Part/App/TopoShapeMakeShapeWithElementMap.cpp
Normal file
367
tests/src/Mod/Part/App/TopoShapeMakeShapeWithElementMap.cpp
Normal file
@@ -0,0 +1,367 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
// Tests for the makeShapeWithElementMap method, extracted from the main set of tests for TopoShape
|
||||
// due to length and complexity.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
#include "PartTestHelpers.h"
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
#include <Mod/Part/App/TopoShapeOpCode.h>
|
||||
|
||||
#include <TopoDS_Vertex.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Wire.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <TopoDS_Shell.hxx>
|
||||
#include <TopoDS_Solid.hxx>
|
||||
#include <TopoDS_CompSolid.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
|
||||
using namespace Part;
|
||||
using namespace Data;
|
||||
|
||||
class TopoShapeMakeShapeWithElementMapTests: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
Part::TopoShape* Shape()
|
||||
{
|
||||
return &_shape;
|
||||
}
|
||||
|
||||
Part::TopoShape::Mapper* Mapper()
|
||||
{
|
||||
return &_mapper;
|
||||
}
|
||||
|
||||
void testFindSourceSubShapesInElementMapForSource(
|
||||
const std::vector<TopoShape>& sources,
|
||||
const TopoShape& source
|
||||
);
|
||||
|
||||
private:
|
||||
std::string _docName;
|
||||
Data::ElementIDRefs _sid;
|
||||
Part::TopoShape _shape;
|
||||
Part::TopoShape::Mapper _mapper;
|
||||
};
|
||||
|
||||
TEST_F(TopoShapeMakeShapeWithElementMapTests, nullShapeThrows)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
|
||||
std::vector<Part::TopoShape> sources {cube1, cube2};
|
||||
TopoDS_Vertex nullVertex;
|
||||
TopoDS_Edge nullEdge;
|
||||
TopoDS_Wire nullWire;
|
||||
TopoDS_Face nullFace;
|
||||
TopoDS_Shell nullShell;
|
||||
TopoDS_Solid nullSolid;
|
||||
TopoDS_CompSolid nullCompSolid;
|
||||
TopoDS_Compound nullCompound;
|
||||
|
||||
// Act and assert
|
||||
EXPECT_THROW(
|
||||
Shape()->makeShapeWithElementMap(nullVertex, *Mapper(), sources),
|
||||
Part::NullShapeException
|
||||
);
|
||||
EXPECT_THROW(
|
||||
Shape()->makeShapeWithElementMap(nullEdge, *Mapper(), sources),
|
||||
Part::NullShapeException
|
||||
);
|
||||
EXPECT_THROW(
|
||||
Shape()->makeShapeWithElementMap(nullWire, *Mapper(), sources),
|
||||
Part::NullShapeException
|
||||
);
|
||||
EXPECT_THROW(
|
||||
Shape()->makeShapeWithElementMap(nullFace, *Mapper(), sources),
|
||||
Part::NullShapeException
|
||||
);
|
||||
EXPECT_THROW(
|
||||
Shape()->makeShapeWithElementMap(nullShell, *Mapper(), sources),
|
||||
Part::NullShapeException
|
||||
);
|
||||
EXPECT_THROW(
|
||||
Shape()->makeShapeWithElementMap(nullSolid, *Mapper(), sources),
|
||||
Part::NullShapeException
|
||||
);
|
||||
EXPECT_THROW(
|
||||
Shape()->makeShapeWithElementMap(nullCompSolid, *Mapper(), sources),
|
||||
Part::NullShapeException
|
||||
);
|
||||
EXPECT_THROW(
|
||||
Shape()->makeShapeWithElementMap(nullCompound, *Mapper(), sources),
|
||||
Part::NullShapeException
|
||||
);
|
||||
}
|
||||
|
||||
std::map<IndexedName, MappedName> elementMap(const TopoShape& shape)
|
||||
{
|
||||
std::map<IndexedName, MappedName> result {};
|
||||
auto elements = shape.getElementMap();
|
||||
for (auto const& entry : elements) {
|
||||
result[entry.index] = entry.name;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// TEST_F(TopoShapeMakeShapeWithElementMapTests, mapVertex)
|
||||
// TEST_F(TopoShapeMakeShapeWithElementMapTests, mapEdge)
|
||||
// TEST_F(TopoShapeMakeShapeWithElementMapTests, mapWire)
|
||||
// TEST_F(TopoShapeMakeShapeWithElementMapTests, mapFace)
|
||||
// TEST_F(TopoShapeMakeShapeWithElementMapTests, mapShell)
|
||||
// TEST_F(TopoShapeMakeShapeWithElementMapTests, mapSolid)
|
||||
|
||||
TEST_F(TopoShapeMakeShapeWithElementMapTests, mapCompoundCount)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1TS, cube2TS] = PartTestHelpers::CreateTwoTopoShapeCubes();
|
||||
std::vector<TopoShape> sources {cube1TS, cube2TS};
|
||||
TopoShape compound {3L};
|
||||
compound.makeElementCompound(sources);
|
||||
auto preElements = elementMap(compound); // Map before mapping.
|
||||
// Act
|
||||
compound.makeShapeWithElementMap(compound.getShape(), *Mapper(), sources);
|
||||
auto postElements = elementMap(compound); // Map after mapping
|
||||
// Assert
|
||||
EXPECT_EQ(preElements.size(), 52); // Check the before map.
|
||||
EXPECT_EQ(postElements.size(), 52); // 12 Edges, 8 Vertexes, 6 Faces per each Cube
|
||||
EXPECT_EQ(postElements.count(IndexedName("Edge", 24)), 1);
|
||||
EXPECT_EQ(postElements.count(IndexedName("Edge", 25)), 0);
|
||||
EXPECT_EQ(postElements.count(IndexedName("Vertex", 16)), 1);
|
||||
EXPECT_EQ(postElements.count(IndexedName("Vertex", 17)), 0);
|
||||
EXPECT_EQ(postElements.count(IndexedName("Face", 12)), 1);
|
||||
EXPECT_EQ(postElements.count(IndexedName("Face", 13)), 0);
|
||||
EXPECT_STREQ(sources[0].shapeName().c_str(), "Compound");
|
||||
EXPECT_STREQ(sources[1].shapeName().c_str(), "Compound");
|
||||
EXPECT_STREQ(compound.shapeName().c_str(), "Compound");
|
||||
EXPECT_EQ(
|
||||
22,
|
||||
compound.getMappedChildElements().size()
|
||||
); // Changed with PR#12471. Probably will change
|
||||
// again after importing other TopoNaming logics
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMakeShapeWithElementMapTests, emptySourceShapes)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
|
||||
std::vector<Part::TopoShape> emptySources;
|
||||
std::vector<Part::TopoShape> nonEmptySources {cube1, cube2};
|
||||
|
||||
// Act and assert
|
||||
for (auto& source : nonEmptySources) {
|
||||
Part::TopoShape& modifiedShape = source;
|
||||
Part::TopoShape& originalShape = source;
|
||||
|
||||
EXPECT_EQ(
|
||||
&originalShape,
|
||||
&modifiedShape.makeShapeWithElementMap(source.getShape(), *Mapper(), emptySources)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMakeShapeWithElementMapTests, nonMappableSources)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
|
||||
std::vector<Part::TopoShape> sources {cube1, cube2};
|
||||
|
||||
// Act and assert
|
||||
for (auto& source : sources) {
|
||||
size_t canMap = 0;
|
||||
for (const auto& mappableSource : sources) {
|
||||
if (source.canMapElement(mappableSource)) {
|
||||
++canMap;
|
||||
}
|
||||
}
|
||||
|
||||
if (canMap == 0U) {
|
||||
EXPECT_EQ(&source, &source.makeShapeWithElementMap(source.getShape(), *Mapper(), sources));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testFindSourceShapesInSingleShape(
|
||||
const Part::TopoShape& cmpdShape,
|
||||
const Part::TopoShape& source,
|
||||
const std::vector<Part::TopoShape>& sources,
|
||||
const TopoShape::Mapper& mapper
|
||||
)
|
||||
{
|
||||
std::vector<Part::TopoShape> tmpSources {source};
|
||||
for (const auto& subSource : sources) {
|
||||
Part::TopoShape tmpShape {source.getShape()};
|
||||
tmpShape.makeShapeWithElementMap(source.getShape(), mapper, tmpSources);
|
||||
if (&source == &subSource) {
|
||||
EXPECT_NE(
|
||||
tmpShape.findShape(subSource.getShape()),
|
||||
0
|
||||
); // if tmpShape uses, for example, cube1 and we search for cube1 than
|
||||
// we should find it
|
||||
}
|
||||
else {
|
||||
EXPECT_EQ(
|
||||
tmpShape.findShape(subSource.getShape()),
|
||||
0
|
||||
); // if tmpShape uses, for example, cube1 and we search for cube2 than
|
||||
// we shouldn't find it
|
||||
}
|
||||
}
|
||||
EXPECT_NE(
|
||||
cmpdShape.findShape(source.getShape()),
|
||||
0
|
||||
); // as cmpdShape is made with cube1 and cube2 we should find both of them
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMakeShapeWithElementMapTests, findSourceShapesInShape)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
|
||||
std::vector<Part::TopoShape> sources {cube1, cube2};
|
||||
sources[0].Tag = 1; // setting Tag explicitly otherwise it is likely that this test will be
|
||||
// more or less the same of nonMappableSources
|
||||
sources[1].Tag = 2; // setting Tag explicitly otherwise it is likely that this test will be
|
||||
// more or less the same of nonMappableSources
|
||||
Part::TopoShape cmpdShape;
|
||||
cmpdShape.makeElementCompound(sources);
|
||||
|
||||
// Act and assert
|
||||
for (const auto& source : sources) {
|
||||
testFindSourceShapesInSingleShape(cmpdShape, source, sources, *Mapper());
|
||||
}
|
||||
}
|
||||
|
||||
void testFindSubShapesForSourceWithTypeAndIndex(
|
||||
const std::string& shapeTypeStr,
|
||||
std::map<IndexedName, MappedName>& elementStdMap,
|
||||
unsigned long shapeIndex
|
||||
)
|
||||
{
|
||||
std::string shapeIndexStr = std::to_string(shapeIndex);
|
||||
std::string shapeName {shapeTypeStr + shapeIndexStr};
|
||||
|
||||
IndexedName indexedName {shapeTypeStr.c_str(), (int)shapeIndex};
|
||||
MappedName mappedName {elementStdMap[indexedName]};
|
||||
const char shapeTypePrefix {indexedName.toString()[0]};
|
||||
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_MSVC(4834) // Discarding a [[nodiscard]], which we are about to do...
|
||||
// We check that the IndexedName is one of the keys...
|
||||
EXPECT_NO_THROW(elementStdMap.at(indexedName));
|
||||
// ... that the element name is in the MappedName...
|
||||
EXPECT_NE(mappedName.find(shapeName.c_str()), -1);
|
||||
EXPECT_EQ(mappedName.toString().back(), shapeTypePrefix);
|
||||
QT_WARNING_POP
|
||||
}
|
||||
|
||||
void testFindSubShapesForSourceWithType(
|
||||
const TopoShape& source,
|
||||
const char* shapeType,
|
||||
std::map<IndexedName, MappedName>& elementStdMap
|
||||
)
|
||||
{
|
||||
std::string shapeTypeStr {shapeType};
|
||||
|
||||
// ... and all the elements of the various types in the source TopoShape ...
|
||||
for (unsigned long shapeIndex = 1U; shapeIndex <= source.countSubElements(shapeType);
|
||||
shapeIndex++) {
|
||||
testFindSubShapesForSourceWithTypeAndIndex(shapeTypeStr, elementStdMap, shapeIndex);
|
||||
}
|
||||
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_MSVC(4834) // Discarding a [[nodiscard]], which we are about to do...
|
||||
// ... we also check that we don't find shapes that don't exist and therefore don't
|
||||
// have either an IndexedName or a MappedName
|
||||
IndexedName fakeIndexedName {shapeTypeStr.c_str(), (int)source.countSubElements(shapeType) + 1};
|
||||
EXPECT_THROW(elementStdMap.at(fakeIndexedName), std::out_of_range);
|
||||
QT_WARNING_POP
|
||||
}
|
||||
|
||||
void TopoShapeMakeShapeWithElementMapTests::testFindSourceSubShapesInElementMapForSource(
|
||||
const std::vector<TopoShape>& sources,
|
||||
const TopoShape& source
|
||||
)
|
||||
{
|
||||
TopoShape tmpShape {source.getShape()};
|
||||
tmpShape.makeShapeWithElementMap(source.getShape(), *Mapper(), sources);
|
||||
|
||||
// First we create a map with the IndexedNames and MappedNames
|
||||
std::map<IndexedName, MappedName> elementStdMap;
|
||||
for (const auto& mappedElement : tmpShape.getElementMap()) {
|
||||
elementStdMap.emplace(mappedElement.index, mappedElement.name);
|
||||
}
|
||||
|
||||
// Then for all the elements types (Vertex, Edge, Face) ...
|
||||
for (const auto& shapeType : source.getElementTypes()) {
|
||||
testFindSubShapesForSourceWithType(source, shapeType, elementStdMap);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMakeShapeWithElementMapTests, findSourceSubShapesInElementMap)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
|
||||
std::vector<TopoShape> sources {cube1, cube2};
|
||||
sources[0].Tag = 1; // setting Tag explicitly otherwise it is likely that this test will be
|
||||
// more or less the same of nonMappableSources
|
||||
sources[1].Tag = 2; // setting Tag explicitly otherwise it is likely that this test will be
|
||||
// more or less the same of nonMappableSources
|
||||
|
||||
// Act and assert
|
||||
// Testing with all the source TopoShapes
|
||||
for (const auto& source : sources) {
|
||||
testFindSourceSubShapesInElementMapForSource(sources, source);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMakeShapeWithElementMapTests, findMakerOpInElementMap)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
|
||||
std::vector<TopoShape> sources {cube1, cube2};
|
||||
sources[0].Tag = 1; // setting Tag explicitly otherwise it is likely that this test will be
|
||||
// more or less the same of nonMappableSources
|
||||
sources[1].Tag = 2; // setting Tag explicitly otherwise it is likely that this test will be
|
||||
// more or less the same of nonMappableSources
|
||||
|
||||
// Act and assert
|
||||
// Testing with all the source TopoShapes
|
||||
for (const auto& source : sources) {
|
||||
TopoShape tmpShape {source.getShape()};
|
||||
tmpShape.makeShapeWithElementMap(source.getShape(), *Mapper(), sources);
|
||||
EXPECT_EQ(tmpShape.getElementMapSize(), 26);
|
||||
|
||||
// For all the mappedElements ...
|
||||
// for (const auto& mappedElement : tmpShape.getElementMap()) {
|
||||
// TODO: This no longer works, it needs a different check. We don't set MAK
|
||||
// EXPECT_NE(mappedElement.name.find(OpCodes::Maker),
|
||||
// -1); // ... we check that there's the "MAK" OpCode
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
std::string composeTagInfo(const MappedElement& element, const TopoShape& shape)
|
||||
{
|
||||
std::string elementNameStr {element.name.constPostfix()};
|
||||
std::string tagInfo = POSTFIX_TAG + std::to_string(shape.Tag);
|
||||
tagInfo += ":" + std::to_string(elementNameStr.substr(0, elementNameStr.find(tagInfo)).length());
|
||||
|
||||
return tagInfo;
|
||||
}
|
||||
158
tests/src/Mod/Part/App/TopoShapeMapper.cpp
Normal file
158
tests/src/Mod/Part/App/TopoShapeMapper.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
#include "Mod/Part/App/TopoShapeMapper.h"
|
||||
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepBuilderAPI_MakeShape.hxx>
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <BRepTools_History.hxx>
|
||||
#include <BRepTools_ReShape.hxx>
|
||||
#include <TopTools_ListOfShape.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
class TopoShapeMapperTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _docName;
|
||||
};
|
||||
|
||||
TEST_F(TopoShapeMapperTest, shapeHasherSingle)
|
||||
{
|
||||
// Arrange
|
||||
auto edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge();
|
||||
Part::TopoShape topoShape {edge};
|
||||
auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge();
|
||||
Part::TopoShape topoShape2 {edge2};
|
||||
struct Part::ShapeHasher hasher;
|
||||
|
||||
// Act
|
||||
size_t hash1 = hasher(topoShape);
|
||||
size_t hash2 = hasher(topoShape2);
|
||||
size_t hash3 = hasher(edge);
|
||||
size_t hash4 = hasher(edge2);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(hash1, hash3);
|
||||
EXPECT_EQ(hash2, hash4);
|
||||
EXPECT_NE(hash1, hash2);
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMapperTest, shapeHasherDual)
|
||||
{
|
||||
// Arrange
|
||||
auto edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge();
|
||||
Part::TopoShape topoShape {edge};
|
||||
auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge();
|
||||
Part::TopoShape topoShape2 {edge2};
|
||||
struct Part::ShapeHasher hasher;
|
||||
|
||||
// Act
|
||||
size_t hash5 = hasher(topoShape, topoShape);
|
||||
size_t hash6 = hasher(topoShape, topoShape2);
|
||||
size_t hash7 = hasher(edge, edge);
|
||||
size_t hash8 = hasher(edge, edge2);
|
||||
|
||||
// Assert
|
||||
EXPECT_TRUE(hash5);
|
||||
EXPECT_FALSE(hash6);
|
||||
EXPECT_TRUE(hash7);
|
||||
EXPECT_FALSE(hash8);
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMapperTest, shapeHasherPair)
|
||||
{
|
||||
// Arrange
|
||||
auto edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge();
|
||||
Part::TopoShape topoShape {edge};
|
||||
auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge();
|
||||
Part::TopoShape topoShape2 {edge2};
|
||||
std::pair<Part::TopoShape, Part::TopoShape> pair1(topoShape, topoShape2);
|
||||
std::pair<Part::TopoShape, Part::TopoShape> pair2(topoShape, topoShape);
|
||||
std::pair<TopoDS_Shape, TopoDS_Shape> pair3(edge, edge2);
|
||||
std::pair<TopoDS_Shape, TopoDS_Shape> pair4(edge, edge);
|
||||
struct Part::ShapeHasher hasher;
|
||||
|
||||
// Act
|
||||
size_t hash9 = hasher(pair1);
|
||||
size_t hash10 = hasher(pair2);
|
||||
size_t hash11 = hasher(pair3);
|
||||
size_t hash12 = hasher(pair4);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(hash9, hash11);
|
||||
EXPECT_EQ(hash10, hash12);
|
||||
EXPECT_NE(hash9, hash10);
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeMapperTest, shapeHasherPairs)
|
||||
{
|
||||
// Arrange
|
||||
auto edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge();
|
||||
Part::TopoShape topoShape {edge};
|
||||
auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge();
|
||||
Part::TopoShape topoShape2 {edge2};
|
||||
std::pair<Part::TopoShape, Part::TopoShape> pair1(topoShape, topoShape2);
|
||||
std::pair<Part::TopoShape, Part::TopoShape> pair2(topoShape, topoShape);
|
||||
std::pair<TopoDS_Shape, TopoDS_Shape> pair3(edge, edge2);
|
||||
std::pair<TopoDS_Shape, TopoDS_Shape> pair4(edge, edge);
|
||||
struct Part::ShapeHasher hasher;
|
||||
|
||||
// Act
|
||||
size_t hash13 = hasher(pair1, pair1);
|
||||
size_t hash14 = hasher(pair1, pair2);
|
||||
size_t hash15 = hasher(pair3, pair3);
|
||||
size_t hash16 = hasher(pair3, pair4);
|
||||
|
||||
// Assert
|
||||
EXPECT_TRUE(hash13);
|
||||
EXPECT_FALSE(hash14);
|
||||
EXPECT_TRUE(hash15);
|
||||
EXPECT_FALSE(hash16);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(TopoShapeMapperTest, shapeMapperTests)
|
||||
{
|
||||
// Arrange
|
||||
auto mapper = Part::ShapeMapper();
|
||||
auto boxMaker1 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
|
||||
boxMaker1.Build();
|
||||
auto box1 = boxMaker1.Shape();
|
||||
Part::TopoShape topoShape1 {box1};
|
||||
|
||||
// Act
|
||||
auto e = topoShape1.getSubTopoShapes(TopAbs_EDGE);
|
||||
mapper.populate(Part::MappingStatus::Modified, box1, {e[0], e[1], e[2], e[3]});
|
||||
mapper.populate(Part::MappingStatus::Generated, box1, {e[4], e[5], e[6]});
|
||||
std::vector<TopoDS_Shape> vec1 = mapper.modified(box1);
|
||||
std::vector<TopoDS_Shape> vec2 = mapper.generated(box1);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(vec1.size(), 4);
|
||||
EXPECT_EQ(vec2.size(), 3);
|
||||
}
|
||||
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
931
tests/src/Mod/Part/App/WireJoiner.cpp
Normal file
931
tests/src/Mod/Part/App/WireJoiner.cpp
Normal file
@@ -0,0 +1,931 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
#include "Mod/Part/App/WireJoiner.h"
|
||||
#include <Mod/Part/App/TopoShapeOpCode.h>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
#include <BRepBuilderAPI_MakeShape.hxx>
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
using namespace Part;
|
||||
using namespace PartTestHelpers;
|
||||
|
||||
class WireJoinerTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
_hasher = Base::Reference<App::StringHasher>(new App::StringHasher);
|
||||
ASSERT_EQ(_hasher.getRefCount(), 1);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::string _docName;
|
||||
Data::ElementIDRefs _sid;
|
||||
App::StringHasherRef _hasher;
|
||||
};
|
||||
|
||||
TEST_F(WireJoinerTest, addShape)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used to define the arguments of the various
|
||||
// WireJoiner::addShape() calls
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 1.0, 0.0)).Edge()};
|
||||
auto edge4 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 1.0, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge()};
|
||||
|
||||
// A vector of TopoDS_Shape used as argument for wjvTDS.addShape()
|
||||
std::vector<TopoDS_Shape> edges {edge1, edge2, edge3, edge4};
|
||||
|
||||
// Create various TopoShapes used as arguments for wjvTS.addShape()
|
||||
|
||||
auto edge1TS {TopoShape(edge1, 1)};
|
||||
auto edge2TS {TopoShape(edge2, 2)};
|
||||
|
||||
// A wire TopoShape used as argument for wjTS.addShape()
|
||||
auto wireTS {TopoShape(BRepBuilderAPI_MakeWire(edge1, edge2, edge3).Wire(), 3)};
|
||||
// An empty TopoShape that will contain the shapes added by wjvTS.addShape()
|
||||
auto wirevTS {TopoShape(4)};
|
||||
// An empty TopoShape that will contain the shapes added by wjvTDS.addShape()
|
||||
auto wirevTDS {TopoShape(5)};
|
||||
|
||||
// Create 3 WireJoiner objects, one for every definition of WireJoiner::addShape()
|
||||
|
||||
// A WireJoiner object where it will be added a TopoShape without calling WireJoiner::Build()
|
||||
// afterwards
|
||||
auto wjTSNotDone {WireJoiner()};
|
||||
// A WireJoiner object where it will be added a TopoShape
|
||||
auto wjTS {WireJoiner()};
|
||||
// A WireJoiner object where it will be added a vector of TopoShapes
|
||||
auto wjvTS {WireJoiner()};
|
||||
// A WireJoiner object where it will be added a vector of TopoDS_Shapes
|
||||
auto wjvTDS {WireJoiner()};
|
||||
|
||||
// Act
|
||||
|
||||
// Calling only WireJoiner::addShape(). Expected result is that wjTSNotDone.Done() is false
|
||||
wjTSNotDone.addShape(wireTS);
|
||||
|
||||
// Calling WireJoiner::addShape() and then WireJoiner::Build().
|
||||
// If we don't call WireJoiner::Build() we can't see the effect of WireJoiner::addShape() as it
|
||||
// adds the shapes in the private member WireJoinerP::sourceEdgeArray
|
||||
|
||||
wjTS.addShape(wireTS);
|
||||
wjTS.Build();
|
||||
// The wire in wjTS is open, therefore to see the effect of wjTS.addShape() we must call
|
||||
// wjTS.getOpenWires() and put the result in wireTS
|
||||
wjTS.getOpenWires(wireTS, nullptr, false);
|
||||
|
||||
wjvTS.addShape({edge1TS, edge2TS});
|
||||
wjvTS.Build();
|
||||
// The wire in wjvTS is open, therefore to see the effect of wjvTS.addShape() we must call
|
||||
// wjvTS.getOpenWires() and put the result in wirevTS
|
||||
wjvTS.getOpenWires(wirevTS, nullptr, false);
|
||||
|
||||
wjvTDS.addShape(edges);
|
||||
wjvTDS.Build();
|
||||
// The wire in wjvTDS is closed, therefore to see the effect of wjvTDS.addShape() we can simply
|
||||
// call wjvTDS.Shape() to replace the shape in wirevTDS
|
||||
wirevTDS.setShape(wjvTDS.Shape());
|
||||
|
||||
// Assert
|
||||
|
||||
// Check the output of WireJoiner::IsDone().
|
||||
// It should be true for all the objects that executed also WireJoiner::Build()
|
||||
// (All except wjTSNotDone)
|
||||
EXPECT_FALSE(wjTSNotDone.IsDone());
|
||||
EXPECT_TRUE(wjTS.IsDone());
|
||||
EXPECT_TRUE(wjvTS.IsDone());
|
||||
EXPECT_TRUE(wjvTDS.IsDone());
|
||||
|
||||
// wireTS is build with 3 edges. The same quantity should be in the shape built
|
||||
EXPECT_EQ(wireTS.getSubTopoShapes(TopAbs_EDGE).size(), 3);
|
||||
// wirevTS is build with 2 edges. The same quantity should be in the shape built
|
||||
EXPECT_EQ(wirevTS.getSubTopoShapes(TopAbs_EDGE).size(), 2);
|
||||
// wirevTDS is build with 4 edges. The same quantity should be in the shape built
|
||||
EXPECT_EQ(wirevTDS.getSubTopoShapes(TopAbs_EDGE).size(), 4);
|
||||
}
|
||||
|
||||
TEST_F(WireJoinerTest, setOutline)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge()};
|
||||
|
||||
auto edge4 {BRepBuilderAPI_MakeEdge(gp_Pnt(-0.1, -0.1, 0.0), gp_Pnt(-0.1, 1.1, 0.0)).Edge()};
|
||||
auto edge5 {BRepBuilderAPI_MakeEdge(gp_Pnt(-0.1, 1.1, 0.0), gp_Pnt(1.1, 1.1, 0.0)).Edge()};
|
||||
auto edge6 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.1, 1.1, 0.0), gp_Pnt(-0.1, -0.1, 0.0)).Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjNoOutline.addShape()
|
||||
std::vector<TopoDS_Shape> edgesNoOutline {edge1, edge2, edge3, edge4, edge5, edge6};
|
||||
// A vector of edges used as argument for wjOutline.addShape()
|
||||
std::vector<TopoDS_Shape> edgesOutline {edge1, edge2, edge3, edge4, edge5, edge6};
|
||||
|
||||
// To see the effect of setOutline() it is necessary to set the user parameter "Iteration"
|
||||
// to a value, in this case, less than zero before the WireObjects are initialized.
|
||||
// To see the correct value for this parameter refer to method WireJoinerP::canShowShape()
|
||||
|
||||
auto hParam {App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/WireJoiner"
|
||||
)};
|
||||
auto catchIteration {hParam->GetInt("Iteration", 0)};
|
||||
hParam->SetInt("Iteration", -1);
|
||||
|
||||
// A document where there will WireJoiner.Build() will be called having setOutline() set to
|
||||
// false
|
||||
auto docNoOutline {App::GetApplication().getActiveDocument()};
|
||||
|
||||
auto _docNameOutline {App::GetApplication().getUniqueDocumentName("docOutline")};
|
||||
App::GetApplication().newDocument(_docNameOutline.c_str(), "docOutlineUser");
|
||||
// A document where there will WireJoiner.Build() will be called having setOutline() set to true
|
||||
auto docOutline {App::GetApplication().getActiveDocument()};
|
||||
|
||||
// A WireJoiner object where the value of setOutline() will be changed but no shapes will be
|
||||
// built
|
||||
auto wjNoBuild {WireJoiner()};
|
||||
// A WireJoiner object where setOutline() will be set to false
|
||||
auto wjNoOutline {WireJoiner()};
|
||||
// A WireJoiner object where setOutline() will be set to true
|
||||
auto wjOutline {WireJoiner()};
|
||||
|
||||
// Reset the parameter to its previous value.
|
||||
hParam->SetInt("Iteration", catchIteration);
|
||||
|
||||
// Act
|
||||
|
||||
// Changing only the value of setOutline(). This should set wjNoBuild.IsDone() to false
|
||||
wjNoBuild.setOutline(true);
|
||||
|
||||
// We can see the effect of setOutline by searching, among all the DocumentObjects created by
|
||||
// the logic, if there are any with a label containing "removed"
|
||||
|
||||
// Testing first the Document where WireJoiner::Build() will be executed with setOutline set to
|
||||
// false
|
||||
|
||||
App::GetApplication().setActiveDocument(docNoOutline);
|
||||
|
||||
wjNoOutline.addShape(edgesNoOutline);
|
||||
wjNoOutline.setOutline(false);
|
||||
wjNoOutline.Build();
|
||||
|
||||
auto objsInDoc {docNoOutline->getObjects()};
|
||||
|
||||
auto foundRemovedNoOutline {false};
|
||||
for (const auto& obj : objsInDoc) {
|
||||
foundRemovedNoOutline
|
||||
= (std::string(obj->Label.getValue()).find("removed") != std::string::npos);
|
||||
if (foundRemovedNoOutline) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Then testing the Document where WireJoiner::Build() will be executed with setOutline set to
|
||||
// true
|
||||
|
||||
App::GetApplication().setActiveDocument(docOutline);
|
||||
|
||||
wjOutline.addShape(edgesOutline);
|
||||
// same as wjOutline.setOutline(true);
|
||||
wjOutline.setOutline();
|
||||
wjOutline.Build();
|
||||
|
||||
objsInDoc = docOutline->getObjects();
|
||||
|
||||
auto foundRemovedOutline {false};
|
||||
for (const auto& obj : objsInDoc) {
|
||||
foundRemovedOutline = (std::string(obj->Label.getValue()).find("removed") != std::string::npos);
|
||||
if (foundRemovedOutline) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
|
||||
// Without calling wjNoBuild.Build() the value of wjNoBuild.IsDone() should be false even if we
|
||||
// only changed the value of setOutline()
|
||||
EXPECT_FALSE(wjNoBuild.IsDone());
|
||||
|
||||
// In a document where WireJoiner::Build() is executed with setOutline() set to false there
|
||||
// shouldn't be DocumentObjects with "removed" in their label
|
||||
EXPECT_FALSE(foundRemovedNoOutline);
|
||||
|
||||
// In a document where WireJoiner::Build() is executed with setOutline() set to true there
|
||||
// should be at least a DocumentObject with "removed" in its label
|
||||
EXPECT_TRUE(foundRemovedOutline);
|
||||
}
|
||||
|
||||
TEST_F(WireJoinerTest, setTightBound)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge()};
|
||||
auto edge4 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 1.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjNoTightBound.addShape()
|
||||
std::vector<TopoDS_Shape> edgesNoTightBound {edge1, edge2, edge3, edge4};
|
||||
// A vector of edges used as argument for wjTightBound.addShape()
|
||||
std::vector<TopoDS_Shape> edgesTightBound {edge1, edge2, edge3, edge4};
|
||||
|
||||
// A WireJoiner object where the value of setTightBound() will be changed but no shapes will be
|
||||
// built
|
||||
auto wjNoBuild {WireJoiner()};
|
||||
// A WireJoiner object where setTightBound() will be set to false
|
||||
auto wjNoTightBound {WireJoiner()};
|
||||
// A WireJoiner object where setTightBound() will be set to true
|
||||
auto wjTightBound {WireJoiner()};
|
||||
|
||||
// An empty TopoShape that will contain the shapes returned by wjNoTightBound.getOpenWires()
|
||||
auto wireNoTightBound {TopoShape(1)};
|
||||
// An empty TopoShape that will contain the shapes returned by wjTightBound.getOpenWires()
|
||||
auto wireTightBound {TopoShape(2)};
|
||||
|
||||
// Act
|
||||
|
||||
// Changing only the value of setTightBound(). This should set wjNoBuild.IsDone() to false
|
||||
wjNoBuild.setTightBound(false);
|
||||
|
||||
// To see the effect of setTightBound() we call WireJoiner::Build() and then
|
||||
// WireJoiner::getOpenWires()
|
||||
|
||||
wjNoTightBound.addShape(edgesNoTightBound);
|
||||
wjNoTightBound.setTightBound(false);
|
||||
// Calling wjNoTightBound.Build() will put all the edges inside the private object
|
||||
// WireJoiner::WireJoinerP::openWireCompound.
|
||||
wjNoTightBound.Build();
|
||||
wjNoTightBound.getOpenWires(wireNoTightBound, nullptr, false);
|
||||
|
||||
wjTightBound.addShape(edgesTightBound);
|
||||
// same as wjTightBound.setTightBound(true);
|
||||
wjTightBound.setTightBound();
|
||||
// Calling wjTightBound.Build() will put inside the private object
|
||||
// WireJoiner::WireJoinerP::openWireCompound only the edges that don't contribute to the
|
||||
// creation of any closed wire.
|
||||
wjTightBound.Build();
|
||||
wjTightBound.getOpenWires(wireTightBound, nullptr, false);
|
||||
|
||||
// Assert
|
||||
|
||||
// Without calling wjNoBuild.Build() the value of wjNoBuild.IsDone() should be false even if we
|
||||
// only changed the value of setTightBound()
|
||||
EXPECT_FALSE(wjNoBuild.IsDone());
|
||||
|
||||
// In this case the number of edges is equal to 6 because:
|
||||
// edge1 and edge2 aren't modified => 2 edges
|
||||
// edge3 and edge4 are both split in 2 edges => 4 edges
|
||||
// The split is made at the intersection point (0.5, 0.5, 0.0)
|
||||
EXPECT_EQ(wireNoTightBound.getSubTopoShapes(TopAbs_EDGE).size(), 6);
|
||||
|
||||
// In this case the number of those edges is equal to 1 and that edge is the one with vertexes
|
||||
// at the coordinates (0.5, 0.5, 0.0) - (0.0, 1.0, 0.0)
|
||||
EXPECT_EQ(wireTightBound.getSubTopoShapes(TopAbs_EDGE).size(), 1);
|
||||
}
|
||||
|
||||
TEST_F(WireJoinerTest, setSplitEdges)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 1.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjNoSplitEdges.addShape()
|
||||
std::vector<TopoDS_Shape> edgesNoSplitEdges {edge1, edge2};
|
||||
// A vector of edges used as argument for wjSplitEdges.addShape()
|
||||
std::vector<TopoDS_Shape> edgesSplitEdges {edge1, edge2};
|
||||
|
||||
// A WireJoiner object where the value of setSplitEdges() will be changed but no shapes will be
|
||||
// built
|
||||
auto wjNoBuild {WireJoiner()};
|
||||
|
||||
// A WireJoiner object where setSplitEdges() will be set to false
|
||||
auto wjNoSplitEdges {WireJoiner()};
|
||||
// To see it's effect it's necessary also to call setTightBound(false) otherwise
|
||||
// WireJoiner::WireJoinerP::splitEdges() will be called in any case
|
||||
wjNoSplitEdges.setTightBound(false);
|
||||
|
||||
// A WireJoiner object where setSplitEdges() will be set to true
|
||||
auto wjSplitEdges {WireJoiner()};
|
||||
// To see it's effect it's necessary also to call setTightBound(false) otherwise
|
||||
// WireJoiner::WireJoinerP::splitEdges() will be called in any case
|
||||
wjSplitEdges.setTightBound(false);
|
||||
|
||||
// An empty TopoShape that will contain the shapes returned by wjNoSplitEdges.getOpenWires()
|
||||
auto wireNoSplitEdges {TopoShape(1)};
|
||||
// An empty TopoShape that will contain the shapes returned by wjSplitEdges.getOpenWires()
|
||||
auto wireSplitEdges {TopoShape(2)};
|
||||
|
||||
// Act
|
||||
|
||||
// Changing only the value of setSplitEdges(). This should set wjNoBuild.IsDone() to false
|
||||
wjNoBuild.setSplitEdges(false);
|
||||
|
||||
// To see the effect of setSplitEdges() we call WireJoiner::Build() and then
|
||||
// WireJoiner::getOpenWires()
|
||||
|
||||
wjNoSplitEdges.addShape(edgesNoSplitEdges);
|
||||
wjNoSplitEdges.setSplitEdges(false);
|
||||
// Calling wjNoSplitEdges.Build() will put all the edges that don't contribute to the creation
|
||||
// of a closed wire inside the private object WireJoiner::WireJoinerP::openWireCompound.
|
||||
wjNoSplitEdges.Build();
|
||||
wjNoSplitEdges.getOpenWires(wireNoSplitEdges, nullptr, false);
|
||||
|
||||
wjSplitEdges.addShape(edgesSplitEdges);
|
||||
// same as wjSplitEdges.setSplitEdges(true);
|
||||
wjSplitEdges.setSplitEdges();
|
||||
// Calling wjSplitEdges.Build() will put inside the private object
|
||||
// WireJoiner::WireJoinerP::openWireCompound all the edges processed by
|
||||
// WireJoiner::WireJoinerP::splitEdges().
|
||||
wjSplitEdges.Build();
|
||||
wjSplitEdges.getOpenWires(wireSplitEdges, nullptr, false);
|
||||
|
||||
// Assert
|
||||
|
||||
// Without calling wjNoBuild.Build() the value of wjNoBuild.IsDone() should be false even if we
|
||||
// only changed the value of setSplitEdges()
|
||||
EXPECT_FALSE(wjNoBuild.IsDone());
|
||||
|
||||
// In this case the number of edges is equal to the number of edges added with
|
||||
// wjNoSplitEdges.addShape() because none of them is used for the creation of a closed wire.
|
||||
EXPECT_EQ(wireNoSplitEdges.getSubTopoShapes(TopAbs_EDGE).size(), 2);
|
||||
|
||||
// In this case the number of those edges is equal to 4 because both the edges added with
|
||||
// wjSplitEdges.addShape() have been split at the intersection point (0.5, 0.5, 0.0)
|
||||
EXPECT_EQ(wireSplitEdges.getSubTopoShapes(TopAbs_EDGE).size(), 4);
|
||||
}
|
||||
|
||||
TEST_F(WireJoinerTest, setMergeEdges)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(-0.1, 0.0, 0.0), gp_Pnt(1.1, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, -0.1, 0.0), gp_Pnt(1.0, 1.1, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.1, 1.1, 0.0), gp_Pnt(-0.1, -0.1, 0.0)).Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjNoMergeEdges.addShape()
|
||||
std::vector<TopoDS_Shape> edgesNoMergeEdges {edge1, edge2, edge3};
|
||||
// A vector of edges used as argument for wjMergeEdges.addShape()
|
||||
std::vector<TopoDS_Shape> edgesMergeEdges {edge1, edge2, edge3};
|
||||
|
||||
// A WireJoiner object where the value of setMergeEdges() will be changed but no shapes will be
|
||||
// built
|
||||
auto wjNoBuild {WireJoiner()};
|
||||
|
||||
// A WireJoiner object where setMergeEdges() will be set to false
|
||||
auto wjNoMergeEdges {WireJoiner()};
|
||||
// To see it's effect it's necessary also to call setTightBound(false) otherwise
|
||||
// WireJoiner::WireJoinerP::MergeEdges() will be called in any case
|
||||
wjNoMergeEdges.setTightBound(false);
|
||||
|
||||
// A WireJoiner object where setMergeEdges() will be set to true
|
||||
auto wjMergeEdges {WireJoiner()};
|
||||
// To see it's effect it's necessary also to call setTightBound(false) otherwise
|
||||
// WireJoiner::WireJoinerP::MergeEdges() will be called in any case
|
||||
wjMergeEdges.setTightBound(false);
|
||||
|
||||
// An empty TopoShape that will contain the shapes returned by wjNoMergeEdges.getOpenWires()
|
||||
auto wireNoMergeEdges {TopoShape(1)};
|
||||
// An empty TopoShape that will contain the shapes returned by wjMergeEdges.getOpenWires()
|
||||
auto wireMergeEdges {TopoShape(2)};
|
||||
|
||||
// Act
|
||||
|
||||
// Changing only the value of setMergeEdges(). This should set wjNoBuild.IsDone() to false
|
||||
wjNoBuild.setMergeEdges(false);
|
||||
|
||||
// To see the effect of setMergeEdges() we call WireJoiner::Build() and then
|
||||
// WireJoiner::getOpenWires()
|
||||
|
||||
wjNoMergeEdges.addShape(edgesNoMergeEdges);
|
||||
wjNoMergeEdges.setMergeEdges(false);
|
||||
// Calling wjNoMergeEdges.Build() will put all the edges produced by
|
||||
// WireJoiner::WireJoinerP::splitEdges() in the private object
|
||||
// WireJoiner::WireJoinerP::openWireCompound.
|
||||
wjNoMergeEdges.Build();
|
||||
wjNoMergeEdges.getOpenWires(wireNoMergeEdges, nullptr, false);
|
||||
|
||||
wjMergeEdges.addShape(edgesMergeEdges);
|
||||
// same as wjMergeEdges.setMergeEdges(true);
|
||||
wjMergeEdges.setMergeEdges();
|
||||
// Calling wjMergeEdges.Build() will put, among the edges produced by
|
||||
// WireJoiner::WireJoinerP::splitEdges(), only the edges that are connected to only one of the
|
||||
// others by a single vertex in the private object WireJoiner::WireJoinerP::openWireCompound.
|
||||
// In the code those are called SuperEdges and are
|
||||
// processed by WireJoiner::WireJoinerP::findSuperEdges().
|
||||
wjMergeEdges.Build();
|
||||
wjMergeEdges.getOpenWires(wireMergeEdges, nullptr, false);
|
||||
|
||||
// Assert
|
||||
|
||||
// Without calling wjNoBuild.Build() the value of wjNoBuild.IsDone() should be false even if we
|
||||
// only changed the value of setMergeEdges()
|
||||
EXPECT_FALSE(wjNoBuild.IsDone());
|
||||
|
||||
// In this case the number of edges is equal to 9 because all the 3 edges intersect the other 2
|
||||
// and are therefore split in 3 edges each.
|
||||
EXPECT_EQ(wireNoMergeEdges.getSubTopoShapes(TopAbs_EDGE).size(), 9);
|
||||
|
||||
// In this case the number of edges is equal to 6 because, among the 9 produced by
|
||||
// WireJoiner::WireJoinerP::splitEdges(), 3 of them are connected to more than one other edge
|
||||
// and therefore aren't added by WireJoiner::WireJoinerP::findSuperEdges()
|
||||
EXPECT_EQ(wireMergeEdges.getSubTopoShapes(TopAbs_EDGE).size(), 6);
|
||||
}
|
||||
|
||||
TEST_F(WireJoinerTest, setTolerance)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
|
||||
auto pi {acos(-1)};
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.1, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge()};
|
||||
auto edge4 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(0.9, 0.0, 0.0)).Edge()};
|
||||
auto edge5 {BRepBuilderAPI_MakeEdge(
|
||||
gp_Pnt(0.0, 0.0, 0.0),
|
||||
gp_Pnt(0.9 * std::cos(pi / 18), 0.9 * std::sin(pi / 18), 0.0)
|
||||
)
|
||||
.Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjNegtol.addShape()
|
||||
std::vector<TopoDS_Shape> edgesNegtol {edge1, edge2, edge3};
|
||||
// A vector of edges used as argument for wjtol.addShape()
|
||||
std::vector<TopoDS_Shape> edgestol {edge1, edge2, edge3};
|
||||
// A vector of edges used as argument for wjNegatol.addShape()
|
||||
std::vector<TopoDS_Shape> edgesNegatol {edge2, edge3, edge4, edge5};
|
||||
// A vector of edges used as argument for wjatol.addShape()
|
||||
std::vector<TopoDS_Shape> edgesatol {edge2, edge3, edge4, edge5};
|
||||
|
||||
// A WireJoiner object where the value of setTolerance() will be changed but no shapes will be
|
||||
// built
|
||||
auto wjNoBuild {WireJoiner()};
|
||||
|
||||
// A WireJoiner object where setTolerance() will be called passing to the argument tol a
|
||||
// negative value.
|
||||
auto wjNegtol {WireJoiner()};
|
||||
// A WireJoiner object where setTolerance() will be called passing to the argument tol a
|
||||
// value both positive and not equal to WireJoiner::WireJoinerP::myTol
|
||||
auto wjtol {WireJoiner()};
|
||||
|
||||
// A WireJoiner object where setTolerance() will be called passing to the argument atol a
|
||||
// negative value.
|
||||
auto wjNegatol {WireJoiner()};
|
||||
// A WireJoiner object where setTolerance() will be called passing to the argument atol a
|
||||
// value both positive and not equal to WireJoiner::WireJoinerP::myAngularTol
|
||||
auto wjatol {WireJoiner()};
|
||||
|
||||
// An empty TopoShape that will contain the shapes returned by wjNegtol.getOpenWires()
|
||||
auto wireNegtol {TopoShape(1)};
|
||||
// An empty TopoShape that will contain the shapes returned by wjtol.getOpenWires()
|
||||
auto wiretol {TopoShape(2)};
|
||||
|
||||
// An empty TopoShape that will contain the shapes returned by wjNegatol.getOpenWires()
|
||||
auto wireNegatol {TopoShape(3)};
|
||||
// An empty TopoShape that will contain the shapes returned by wjatol.getOpenWires()
|
||||
auto wireatol {TopoShape(4)};
|
||||
|
||||
// Act
|
||||
|
||||
// Changing only the value of setTolerance(). This should set wjNoBuild.IsDone() to false
|
||||
wjNoBuild.setTolerance(0.1);
|
||||
|
||||
// To see the effect of setTolerance() we call WireJoiner::Build() and then
|
||||
// WireJoiner::getOpenWires() to get the edges, if any, that aren't used to create a closed wire
|
||||
|
||||
wjNegtol.addShape(edgesNegtol);
|
||||
// Setting tol to a negative value won't have effect and therefore wjNegtol.pimpl->myTol will
|
||||
// keep the default value.
|
||||
// It's better also to give a negative value for the argument atol otherwise setTolerance()
|
||||
// will set it to 0.0
|
||||
wjNegtol.setTolerance(-0.1, -pi);
|
||||
wjNegtol.Build();
|
||||
wjNegtol.getOpenWires(wireNegtol, nullptr, false);
|
||||
|
||||
wjtol.addShape(edgestol);
|
||||
// Setting tol to a value that will change wjNegtol.pimpl->myTol.
|
||||
// It's better also to give a negative value for the argument atol otherwise setTolerance()
|
||||
// will set it to 0.0
|
||||
wjtol.setTolerance(0.2, -pi);
|
||||
wjtol.Build();
|
||||
wjtol.getOpenWires(wiretol, nullptr, false);
|
||||
|
||||
wjNegatol.addShape(edgesNegatol);
|
||||
// Setting atol to a negative value won't have effect and therefore
|
||||
// wjNegatol.pimpl->myAngularTol will keep the default value. The tol value must be given in any
|
||||
// case.
|
||||
wjNegatol.setTolerance(-0.1, -pi);
|
||||
wjNegatol.Build();
|
||||
wjNegatol.getOpenWires(wireNegatol, nullptr, false);
|
||||
|
||||
wjatol.addShape(edgesatol);
|
||||
// Setting atol to a negative value won't have effect and therefore
|
||||
// wjNegatol.pimpl->myAngularTol will keep the default value. We give also the tol value so that
|
||||
// a closed wire can be created.
|
||||
wjatol.setTolerance(0.2, pi / 9);
|
||||
wjatol.Build();
|
||||
wjatol.getOpenWires(wireatol, nullptr, false);
|
||||
|
||||
// Assert
|
||||
|
||||
// Without calling wjNoBuild.Build() the value of wjNoBuild.IsDone() should be false even if we
|
||||
// only changed the value of setTolerance()
|
||||
EXPECT_FALSE(wjNoBuild.IsDone());
|
||||
|
||||
// In this case, as there's a gap between edge1 and edge3, no closed wires are created.
|
||||
EXPECT_TRUE(wjNegtol.Shape().IsNull());
|
||||
// All the edges added with wjNegtol.addShape() can be extracted with wjNegtol.getOpenWires()
|
||||
EXPECT_EQ(wireNegtol.getSubTopoShapes(TopAbs_EDGE).size(), 3);
|
||||
|
||||
// In this case, as the gap between edge1 and edge3 is smaller than tol, a closed wire can be
|
||||
// created and it contains all the edges added with wjtol.addShape().
|
||||
EXPECT_EQ(TopoShape(wjtol.Shape()).getSubTopoShapes(TopAbs_EDGE).size(), 3);
|
||||
// There are no open wires and therefore no edges that create them
|
||||
EXPECT_EQ(wiretol.getSubTopoShapes(TopAbs_EDGE).size(), 0);
|
||||
|
||||
// In this case, as there's a gap between edge2, edge4 and edge5, no closed wires are created.
|
||||
EXPECT_TRUE(wjNegatol.Shape().IsNull());
|
||||
// All the edges added with wjNegtol.addShape() can be extracted with wjNegatol.getOpenWires()
|
||||
EXPECT_EQ(wireNegatol.getSubTopoShapes(TopAbs_EDGE).size(), 4);
|
||||
|
||||
// In this case, as the gap between edge2, edge4 and edge5 is smaller than tol, a closed wire
|
||||
// can be created.
|
||||
// Because of atol, edge4 and edge5 are considerated as duplicates and therefore one of them is
|
||||
// removed by WireJoiner::WireJoinerP::add().
|
||||
// The closed wire is then created using all the edges added with wjatol.addShape() except the
|
||||
// removed one
|
||||
EXPECT_EQ(TopoShape(wjatol.Shape()).getSubTopoShapes(TopAbs_EDGE).size(), 3);
|
||||
// There are no open wires and therefore no edges that create them
|
||||
EXPECT_EQ(wireatol.getSubTopoShapes(TopAbs_EDGE).size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(WireJoinerTest, getOpenWires)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge()};
|
||||
auto edge4 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.5, 0.5, 0.0), gp_Pnt(1.5, 1.5, 0.0)).Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjNoOpenWires.addShape()
|
||||
std::vector<TopoDS_Shape> edgesNoOpenWires {edge1, edge2, edge3};
|
||||
// A vector of edges used as argument for wjOriginal.addShape()
|
||||
std::vector<TopoDS_Shape> edgesOriginal {edge1, edge2, edge4};
|
||||
// A vector of edges used as argument for wjNoOriginal.addShape()
|
||||
std::vector<TopoDS_Shape> edgesNoOriginal {edge1, edge2, edge4};
|
||||
// A vector of TopoShape edges used as argument for wjNoOp.addShape(). A Tag is needed for every
|
||||
// TopoShape, otherwise no element map will be created and no op can be found
|
||||
std::vector<TopoShape> edgesNoOp {TopoShape(edge2, 6), TopoShape(edge4, 7)};
|
||||
// A vector of TopoShape edges used as argument for wjOp.addShape(). A Tag is needed for every
|
||||
// TopoShape, otherwise no element map will be created and no op can be found
|
||||
std::vector<TopoShape> edgesOp {TopoShape(edge2, 8), TopoShape(edge4, 9)};
|
||||
|
||||
// A WireJoiner object that will create a closed wire and no open wires
|
||||
auto wjNoOpenWires {WireJoiner()};
|
||||
|
||||
// A WireJoiner object where the argument noOriginal will be set to false and that will create
|
||||
// an open wire
|
||||
auto wjOriginal {WireJoiner()};
|
||||
// A WireJoiner object where the argument noOriginal will be set to true and that will create an
|
||||
// open wire
|
||||
auto wjNoOriginal {WireJoiner()};
|
||||
|
||||
// A WireJoiner object where the argument op won't be set and that will create an open wire
|
||||
auto wjNoOp {WireJoiner()};
|
||||
// A WireJoiner object where the argument op will be set and that will create an open wire
|
||||
auto wjOp {WireJoiner()};
|
||||
|
||||
// An empty TopoShape that will contain the shapes returned by wjNoOpenWires.getOpenWires()
|
||||
auto wireNoOpenWires {TopoShape(1)};
|
||||
|
||||
// An empty TopoShape that will contain the shapes returned by wjOriginal.getOpenWires()
|
||||
auto wireOriginal {TopoShape(2)};
|
||||
// An empty TopoShape that will contain the shapes returned by wjNoOriginal.getOpenWires()
|
||||
auto wireNoOriginal {TopoShape(3)};
|
||||
|
||||
// An empty TopoShape that will contain the shapes returned by wjNoOp.getOpenWires()
|
||||
auto wireNoOp {TopoShape(4)};
|
||||
// An empty TopoShape that will contain the shapes returned by wjOp.getOpenWires()
|
||||
auto wireOp {TopoShape(5)};
|
||||
|
||||
// Act
|
||||
|
||||
wjNoOpenWires.addShape(edgesNoOpenWires);
|
||||
// wjNoOpenWires.Build() is called by wjNoOpenWires.getOpenWires()
|
||||
wjNoOpenWires.getOpenWires(wireNoOpenWires);
|
||||
|
||||
wjOriginal.addShape(edgesOriginal);
|
||||
// wjOriginal.Build() is called by wjOriginal.getOpenWires()
|
||||
wjOriginal.getOpenWires(wireOriginal, nullptr, false);
|
||||
|
||||
wjNoOriginal.addShape(edgesNoOriginal);
|
||||
// wjNoOriginal.Build() is called by wjNoOriginal.getOpenWires()
|
||||
wjNoOriginal.getOpenWires(wireNoOriginal);
|
||||
|
||||
wjNoOp.addShape(edgesNoOp);
|
||||
// wjNoOp.Build() is called by wjNoOp.getOpenWires()
|
||||
wjNoOp.getOpenWires(wireNoOp, nullptr, false);
|
||||
|
||||
wjOp.addShape(edgesOp);
|
||||
// wjOp.Build() is called by wjOp.getOpenWires()
|
||||
wjOp.getOpenWires(wireOp, "getOpenWires", false);
|
||||
|
||||
// Assert
|
||||
|
||||
// All the edges added with wjNoOpenWires.addShape() are used to create a closed wire, therefore
|
||||
// wireNoOpenWires should be null
|
||||
EXPECT_TRUE(wireNoOpenWires.isNull());
|
||||
|
||||
// In this case wireOriginal should contain all the edges added with wjOriginal.addShape(),
|
||||
// except those ones that are split, and all the edges generated by splitting an edge with
|
||||
// another one.
|
||||
// edge1 and edge2 are left untouched, while edge4 is split in two at the intersection point
|
||||
// (1.0, 1.0, 0.0), therefore 4 edges.
|
||||
EXPECT_EQ(wireOriginal.getSubTopoShapes(TopAbs_EDGE).size(), 4);
|
||||
|
||||
// In this case wireNoOriginal should contain only the edges generated by splitting one of them
|
||||
// with another one.
|
||||
// As edge1 and edge2 are left untouched, the only edges we should find are the ones generated
|
||||
// by splitting edge4 in two at the intersection point (1.0, 1.0, 0.0)
|
||||
EXPECT_EQ(wireNoOriginal.getSubTopoShapes(TopAbs_EDGE).size(), 2);
|
||||
|
||||
// In this case, as we haven't set a value for op, WireJoiner::WireJoinerP::getOpenWires() will
|
||||
// call TopoShape::makeShapeWithElementMap() which, without a value for op, will use
|
||||
// Part::OpCodes::Maker as value for the various element maps
|
||||
// TODO no longer works
|
||||
// EXPECT_NE(wireNoOp.getElementMap()[0].name.find(Part::OpCodes::Maker), -1);
|
||||
// In this case WireJoiner::WireJoinerP::getOpenWires() will call
|
||||
// TopoShape::makeShapeWithElementMap() giving "getOpenWires" as value for the op argument.
|
||||
// That value should be found in the various element maps instead of Part::OpCodes::Maker
|
||||
EXPECT_EQ(wireOp.getElementMap()[0].name.find(Part::OpCodes::Maker), -1);
|
||||
// TODO no longer works
|
||||
// EXPECT_NE(wireOp.getElementMap()[0].name.find("getOpenWires"), -1);
|
||||
}
|
||||
|
||||
TEST_F(WireJoinerTest, getResultWires)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
// Unlike calling WireJoiner::Build(), WireJoiner::getResultWires() returns a shape with edges
|
||||
// only if those given as inputs crosses each others
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(-0.1, 0.0, 0.0), gp_Pnt(1.1, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, -0.1, 0.0), gp_Pnt(1.0, 1.1, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.1, 1.1, 0.0), gp_Pnt(0.1, 0.1, 0.0)).Edge()};
|
||||
auto edge4 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.1, 1.1, 0.0), gp_Pnt(-0.1, -0.1, 0.0)).Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjNoResultWires.addShape()
|
||||
std::vector<TopoDS_Shape> edgesNoResultWires {edge1, edge2, edge3};
|
||||
// A vector of TopoShape edges used as argument for wjNoOp.addShape(). A Tag is needed for every
|
||||
// TopoShape, otherwise no element map will be created and no op can be found
|
||||
std::vector<TopoShape> edgesNoOp {TopoShape(edge1, 4), TopoShape(edge2, 5), TopoShape(edge4, 6)};
|
||||
// A vector of TopoShape edges used as argument for wjOp.addShape(). A Tag is needed for every
|
||||
// TopoShape, otherwise no element map will be created and no op can be found
|
||||
std::vector<TopoShape> edgesOp {TopoShape(edge1, 7), TopoShape(edge2, 8), TopoShape(edge4, 9)};
|
||||
|
||||
// A WireJoiner object that will create no closed wires
|
||||
auto wjNoResultWires {WireJoiner()};
|
||||
|
||||
// A WireJoiner object where the argument op won't be set and that will create a closed wire
|
||||
auto wjNoOp {WireJoiner()};
|
||||
// A WireJoiner object where the argument op will be set and that will create a closed wire
|
||||
auto wjOp {WireJoiner()};
|
||||
|
||||
// An empty TopoShape that will contain the shapes returned by
|
||||
// wireNoResultWires.getResultWires()
|
||||
auto wireNoResultWires {TopoShape(1)};
|
||||
|
||||
// An empty TopoShape that will contain the shapes returned by wjNoOp.getResultWires()
|
||||
auto wireNoOp {TopoShape(2)};
|
||||
// An empty TopoShape that will contain the shapes returned by wjOp.getResultWires()
|
||||
auto wireOp {TopoShape(3)};
|
||||
|
||||
|
||||
// Act
|
||||
|
||||
wjNoResultWires.addShape(edgesNoResultWires);
|
||||
// wjNoResultWires.Build() is called by wjNoResultWires.getResultWires()
|
||||
wjNoResultWires.getResultWires(wireNoResultWires);
|
||||
|
||||
wjNoOp.addShape(edgesNoOp);
|
||||
// wjNoOp.Build() is called by wjNoOp.getResultWires()
|
||||
wjNoOp.getResultWires(wireNoOp, nullptr);
|
||||
|
||||
wjOp.addShape(edgesOp);
|
||||
// wjOp.Build() is called by wjOp.getResultWires()
|
||||
wjOp.getResultWires(wireOp, "getResultWires");
|
||||
|
||||
// Assert
|
||||
|
||||
// All the edges added with wjNoResultWires.addShape() can't create a closed wire, therefore
|
||||
// wireNoResultWires shouldn't have any edges
|
||||
// It's not possible to get an useful result from wireNoResultWires.isNull() because
|
||||
// WireJoiner::WireJoinerP::compound is always created by
|
||||
// WireJoiner::WireJoinerP::builder.MakeCompound(), which doesn't create a null compound
|
||||
EXPECT_EQ(wireNoResultWires.getSubTopoShapes(TopAbs_EDGE).size(), 0);
|
||||
|
||||
// In this case, as we haven't set a value for op, WireJoiner::WireJoinerP::getResultWires()
|
||||
// will call TopoShape::makeShapeWithElementMap() which, without a value for op, will use
|
||||
// Part::OpCodes::Maker as value for the various element maps
|
||||
EXPECT_NE(wireNoOp.getElementMap()[0].name.find(Part::OpCodes::Maker), -1);
|
||||
|
||||
// In this case WireJoiner::WireJoinerP::getResultWires() will call
|
||||
// TopoShape::makeShapeWithElementMap() giving "getResultWires" as value for the op argument.
|
||||
// That value should be found in the various element maps instead of Part::OpCodes::Maker
|
||||
EXPECT_EQ(wireOp.getElementMap()[0].name.find(Part::OpCodes::Maker), -1);
|
||||
EXPECT_NE(wireOp.getElementMap()[0].name.find("getResultWires"), -1);
|
||||
}
|
||||
|
||||
#if OCC_VERSION_HEX >= 0x070600
|
||||
// WireJoiner::Build() has already been tested indirectly in the other tests.
|
||||
// Here we check only the difference with OCCT versions >= 7.6.0 that add the parameter theRange
|
||||
TEST_F(WireJoinerTest, Build)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(-0.1, 0.0, 0.0), gp_Pnt(1.1, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, -0.1, 0.0), gp_Pnt(1.0, 1.1, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.1, 1.1, 0.0), gp_Pnt(-0.1, -0.1, 0.0)).Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjtheRange.addShape()
|
||||
std::vector<TopoDS_Shape> edgestheRange {edge1, edge2, edge3};
|
||||
|
||||
// A WireJoiner object that will create no closed wires
|
||||
auto wjtheRange {WireJoiner()};
|
||||
|
||||
// A Message_ProgressRange object that will be used as argument for wjtheRange.Build()
|
||||
auto mpr {Message_ProgressRange()};
|
||||
|
||||
// Act
|
||||
|
||||
wjtheRange.addShape(edgestheRange);
|
||||
wjtheRange.Build(mpr);
|
||||
|
||||
// Assert
|
||||
|
||||
// theRange isn't used in WireJoiner::Build() and therefore not attached to any indicator.
|
||||
// For more reference see
|
||||
// https://dev.opencascade.org/doc/occt-7.6.0/refman/html/class_message___progress_range.html
|
||||
// and
|
||||
// https://dev.opencascade.org/doc/occt-7.6.0/refman/html/class_message___progress_indicator.html
|
||||
EXPECT_FALSE(mpr.IsActive());
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(WireJoinerTest, Modified)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(-0.1, 0.0, 0.0), gp_Pnt(1.1, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, -0.1, 0.0), gp_Pnt(1.0, 1.1, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.1, 1.1, 0.0), gp_Pnt(-0.1, -0.1, 0.0)).Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjModified.addShape()
|
||||
std::vector<TopoDS_Shape> edges {edge1, edge2, edge3};
|
||||
|
||||
// A WireJoiner object that will have shapes modified by the added edges
|
||||
auto wjModified {WireJoiner()};
|
||||
|
||||
// Act
|
||||
|
||||
wjModified.addShape(edges);
|
||||
wjModified.Build();
|
||||
|
||||
// Assert
|
||||
|
||||
// In this case, every edge added with wjModified.addShape() modifies other shapes 3 times
|
||||
|
||||
// edge1 modifies the edges with vertexes:
|
||||
// (0.0, 0.0, 0.0) - (1.0, 1.0, 0.0)
|
||||
// (-0.1, -0.1, 0.0) - (0.0, 0.0, 0.0)
|
||||
// (1.0, -0.1, 0.0) - (1.0, 0.0, 0.0)
|
||||
EXPECT_EQ(wjModified.Modified(edge1).Size(), 3);
|
||||
|
||||
// edge2 modifies the edges with vertexes:
|
||||
// (1.0, 1.0, 0.0) - (1.1, 1.1, 0.0)
|
||||
// (0.0, 0.0, 0.0) - (1.0, 0.0, 0.0)
|
||||
// (1.0, 0.0, 0.0) - (1.1, 0.0, 0.0)
|
||||
EXPECT_EQ(wjModified.Modified(edge2).Size(), 3);
|
||||
|
||||
// edge3 modifies the edges with vertexes:
|
||||
// (1.0, 0.0, 0.0) - (1.0, 1.0, 0.0)
|
||||
// (1.0, 1.0, 0.0) - (1.0, 1.1, 0.0)
|
||||
// (-0.1, 0.0, 0.0) - (0.0, 0.0, 0.0)
|
||||
EXPECT_EQ(wjModified.Modified(edge3).Size(), 3);
|
||||
}
|
||||
|
||||
TEST_F(WireJoinerTest, Generated)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(-0.1, 0.0, 0.0), gp_Pnt(1.1, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, -0.1, 0.0), gp_Pnt(1.0, 1.1, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.1, 1.1, 0.0), gp_Pnt(-0.1, -0.1, 0.0)).Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjGenerated.addShape()
|
||||
std::vector<TopoDS_Shape> edges {edge1, edge2, edge3};
|
||||
|
||||
// A WireJoiner object that will have shapes generated by the added edges
|
||||
auto wjGenerated {WireJoiner()};
|
||||
|
||||
// Act
|
||||
|
||||
wjGenerated.addShape(edges);
|
||||
wjGenerated.Build();
|
||||
|
||||
// Assert
|
||||
|
||||
// There aren't calls to WireJoiner::WireJoinerP::aHistory->AddGenerated() or similar methods in
|
||||
// WireJoiner::WireJoinerP, therefore nothing is returned by calling
|
||||
// WireJoiner::WireJoinerP::aHistory->Generated().
|
||||
// There's a call to WireJoiner::WireJoinerP::aHistory->Merge() that uses the history produced
|
||||
// by a ShapeFix_Wire object in WireJoiner::WireJoinerP::makeCleanWire() that however looks
|
||||
// always empty as no methods in ShapeFix_Wire call AddGenerated() or similar methods
|
||||
// (checked in OCCT 7.3.0 source
|
||||
// https://git.dev.opencascade.org/gitweb/?p=occt.git;a=snapshot;h=42da0d5115bff683c6b596e66cdeaff957f81e7d;sf=tgz)
|
||||
EXPECT_EQ(wjGenerated.Generated(edge1).Size(), 0);
|
||||
EXPECT_EQ(wjGenerated.Generated(edge2).Size(), 0);
|
||||
EXPECT_EQ(wjGenerated.Generated(edge3).Size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(WireJoinerTest, IsDeleted)
|
||||
{
|
||||
|
||||
// Create various edges that will be used for the WireJoiner objects tests
|
||||
|
||||
auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge()};
|
||||
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge()};
|
||||
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge()};
|
||||
auto edge4 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge()};
|
||||
auto edge5 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.49, 0.0, 0.0), gp_Pnt(0.51, 0.0, 0.0)).Edge()};
|
||||
|
||||
// A vector of edges used as argument for wjIsDeleted.addShape()
|
||||
std::vector<TopoDS_Shape> edges {edge1, edge2, edge3, edge4, edge5};
|
||||
|
||||
// A WireJoiner object that will have shapes deleted by the added edges
|
||||
auto wjIsDeleted {WireJoiner()};
|
||||
// To get all the deleted shapes in this case we also need to set the tolerance value
|
||||
wjIsDeleted.setTolerance(0.03);
|
||||
|
||||
// Act
|
||||
|
||||
wjIsDeleted.addShape(edges);
|
||||
wjIsDeleted.Build();
|
||||
|
||||
// Assert
|
||||
|
||||
// In this case, edge1, edge2 and edge3 don't meet the conditions for deletion
|
||||
EXPECT_FALSE(wjIsDeleted.IsDeleted(edge1));
|
||||
EXPECT_FALSE(wjIsDeleted.IsDeleted(edge2));
|
||||
EXPECT_FALSE(wjIsDeleted.IsDeleted(edge3));
|
||||
|
||||
// edge4 is a duplicate of edge3 and therefore deleted
|
||||
EXPECT_TRUE(wjIsDeleted.IsDeleted(edge4));
|
||||
|
||||
// edge5 is smaller that the smallest shape that can be considered with the given value of
|
||||
// tolerance and therefore deleted
|
||||
EXPECT_TRUE(wjIsDeleted.IsDeleted(edge5));
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
137
tests/src/Mod/Part/App/brepfiles/cylinder1.brep
Normal file
137
tests/src/Mod/Part/App/brepfiles/cylinder1.brep
Normal file
@@ -0,0 +1,137 @@
|
||||
DBRep_DrawableShape
|
||||
|
||||
CASCADE Topology V1, (c) Matra-Datavision
|
||||
Locations 2
|
||||
1
|
||||
1 0 0 0
|
||||
0 1 0 0
|
||||
0 0 1 0
|
||||
2 1 -1 0
|
||||
Curve2ds 6
|
||||
1 0 10 1 0
|
||||
2 0 0 1 0 -0 1 2
|
||||
1 6.2831853071795862 -0 0 1
|
||||
1 0 -0 0 1
|
||||
1 0 0 1 0
|
||||
2 0 0 1 0 -0 1 2
|
||||
Curves 3
|
||||
2 0 0 10 0 0 1 1 0 -0 -0 1 0 2
|
||||
1 2 -4.898425415289509e-16 0 0 0 1
|
||||
2 0 0 0 0 0 1 1 0 -0 -0 1 0 2
|
||||
Polygon3D 0
|
||||
PolygonOnTriangulations 6
|
||||
26 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2
|
||||
p 0.0310985626705653 1 0 0.251327412287184 0.502654824574367 0.753982236861551 1.00530964914873 1.25663706143592 1.5079644737231 1.75929188601029 2.01061929829747 2.26194671058465 2.51327412287184 2.76460153515902 3.0159289474462 3.26725635973339 3.51858377202057 3.76991118430776 4.02123859659494 4.27256600888212 4.52389342116931 4.77522083345649 5.02654824574367 5.27787565803086 5.52920307031804 5.78053048260523 6.03185789489241 6.28318530717959
|
||||
26 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1
|
||||
p 0.0310985626705653 1 0 0.251327412287184 0.502654824574367 0.753982236861551 1.00530964914873 1.25663706143592 1.5079644737231 1.75929188601029 2.01061929829747 2.26194671058465 2.51327412287184 2.76460153515902 3.0159289474462 3.26725635973339 3.51858377202057 3.76991118430776 4.02123859659494 4.27256600888212 4.52389342116931 4.77522083345649 5.02654824574367 5.27787565803086 5.52920307031804 5.78053048260523 6.03185789489241 6.28318530717959
|
||||
2 27 2
|
||||
p 0.0310985626705653 1 0 10
|
||||
2 28 1
|
||||
p 0.0310985626705653 1 0 10
|
||||
26 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 27
|
||||
p 0.0310985626705653 1 0 0.251327412287184 0.502654824574367 0.753982236861551 1.00530964914873 1.25663706143592 1.5079644737231 1.75929188601029 2.01061929829747 2.26194671058465 2.51327412287184 2.76460153515902 3.0159289474462 3.26725635973339 3.51858377202057 3.76991118430776 4.02123859659494 4.27256600888212 4.52389342116931 4.77522083345649 5.02654824574367 5.27787565803086 5.52920307031804 5.78053048260523 6.03185789489241 6.28318530717959
|
||||
26 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1
|
||||
p 0.0310985626705653 1 0 0.251327412287184 0.502654824574367 0.753982236861551 1.00530964914873 1.25663706143592 1.5079644737231 1.75929188601029 2.01061929829747 2.26194671058465 2.51327412287184 2.76460153515902 3.0159289474462 3.26725635973339 3.51858377202057 3.76991118430776 4.02123859659494 4.27256600888212 4.52389342116931 4.77522083345649 5.02654824574367 5.27787565803086 5.52920307031804 5.78053048260523 6.03185789489241 6.28318530717959
|
||||
Surfaces 3
|
||||
2 0 0 0 0 0 1 1 0 -0 -0 1 0 2
|
||||
1 0 0 10 0 0 1 1 0 -0 -0 1 0
|
||||
1 0 0 0 0 0 1 1 0 -0 -0 1 0
|
||||
Triangulations 3
|
||||
52 50 1 0.0157705973710445
|
||||
2 -4.89842541528951e-16 10 2 -4.89842541528951e-16 10 1.93716632225726 0.49737977432971 10 1.75261336008773 0.963507348203431 10 1.45793725484282 1.36909421185738 10 1.07165358995799 1.68865585100403 10 0.618033988749894 1.90211303259031 10 0.125581039058625 1.99605345685654 10 -0.374762629171451 1.96457450145738 10 -0.851558583130147 1.80965410493204 10 -1.27484797949738 1.54102648555158 10 -1.6180339887499 1.17557050458494 10 -1.8595529717765 0.736249105369352 10 -1.98422940262896 0.250666467128604 10 -1.98422940262896 -0.250666467128614 10 -1.8595529717765 -0.736249105369362 10 -1.61803398874989 -1.17557050458495 10 -1.27484797949737 -1.54102648555158 10 -0.851558583130138 -1.80965410493204 10 -0.374762629171441 -1.96457450145738 10 0.125581039058636 -1.99605345685654 10 0.618033988749905 -1.9021130325903 10 1.071653589958 -1.68865585100402 10 1.45793725484283 -1.36909421185737 10 1.75261336008773 -0.96350734820342 10 1.93716632225727 -0.497379774329697 10 2 -4.89842541528951e-16 0 2 -4.89842541528951e-16 0 1.93716632225726 0.49737977432971 0 1.75261336008773 0.963507348203431 0 1.45793725484282 1.36909421185738 0 1.07165358995799 1.68865585100403 0 0.618033988749894 1.90211303259031 0 0.125581039058625 1.99605345685654 0 -0.374762629171451 1.96457450145738 0 -0.851558583130147 1.80965410493204 0 -1.27484797949738 1.54102648555158 0 -1.6180339887499 1.17557050458494 0 -1.8595529717765 0.736249105369352 0 -1.98422940262896 0.250666467128604 0 -1.98422940262896 -0.250666467128614 0 -1.8595529717765 -0.736249105369362 0 -1.61803398874989 -1.17557050458495 0 -1.27484797949737 -1.54102648555158 0 -0.851558583130138 -1.80965410493204 0 -0.374762629171441 -1.96457450145738 0 0.125581039058636 -1.99605345685654 0 0.618033988749905 -1.9021130325903 0 1.071653589958 -1.68865585100402 0 1.45793725484283 -1.36909421185737 0 1.75261336008773 -0.96350734820342 0 1.93716632225727 -0.497379774329697 0 0 10 6.28318530717959 10 0.251327412287184 10 0.502654824574367 10 0.753982236861551 10 1.00530964914873 10 1.25663706143592 10 1.5079644737231 10 1.75929188601029 10 2.01061929829747 10 2.26194671058465 10 2.51327412287184 10 2.76460153515902 10 3.0159289474462 10 3.26725635973339 10 3.51858377202057 10 3.76991118430776 10 4.02123859659494 10 4.27256600888212 10 4.52389342116931 10 4.77522083345649 10 5.02654824574367 10 5.27787565803086 10 5.52920307031804 10 5.78053048260523 10 6.03185789489241 10 6.28318530717959 0 0 0 0.251327412287184 0 0.502654824574367 0 0.753982236861551 0 1.00530964914873 0 1.25663706143592 0 1.5079644737231 0 1.75929188601029 0 2.01061929829747 0 2.26194671058465 0 2.51327412287184 0 2.76460153515902 0 3.0159289474462 0 3.26725635973339 0 3.51858377202057 0 3.76991118430776 0 4.02123859659494 0 4.27256600888212 0 4.52389342116931 0 4.77522083345649 0 5.02654824574367 0 5.27787565803086 0 5.52920307031804 0 5.78053048260523 0 6.03185789489241 0 22 21 47 22 47 48 22 48 49 23 22 49 3 28 29 3 1 28 24 23 49 24 49 50 24 50 51 4 29 30 4 3 29 25 24 51 5 30 31 26 51 52 5 4 30 26 25 51 26 52 27 2 26 27 6 31 32 6 32 33 6 5 31 7 6 33 8 33 34 8 34 35 8 7 33 9 8 35 10 35 36 10 9 35 11 36 37 11 10 36 12 37 38 12 11 37 13 38 39 13 12 38 14 13 39 14 39 40 15 14 40 15 40 41 16 15 41 16 41 42 17 16 42 17 42 43 18 17 43 18 43 44 19 18 44 19 44 45 19 45 46 20 19 46 20 46 47 21 20 47
|
||||
26 25 1 2.22044604925031e-16
|
||||
2 -4.89842541528951e-16 10 1.93716632225726 0.49737977432971 10 1.75261336008773 0.963507348203431 10 1.45793725484282 1.36909421185738 10 1.07165358995799 1.68865585100403 10 0.618033988749894 1.90211303259031 10 0.125581039058625 1.99605345685654 10 -0.374762629171451 1.96457450145738 10 -0.851558583130147 1.80965410493204 10 -1.27484797949738 1.54102648555158 10 -1.6180339887499 1.17557050458494 10 -1.8595529717765 0.736249105369352 10 -1.98422940262896 0.250666467128604 10 -1.98422940262896 -0.250666467128614 10 -1.8595529717765 -0.736249105369362 10 -1.61803398874989 -1.17557050458495 10 -1.27484797949737 -1.54102648555158 10 -0.851558583130138 -1.80965410493204 10 -0.374762629171441 -1.96457450145738 10 0.125581039058636 -1.99605345685654 10 0.618033988749905 -1.9021130325903 10 1.071653589958 -1.68865585100402 10 1.45793725484283 -1.36909421185737 10 1.75261336008773 -0.96350734820342 10 1.93716632225727 -0.497379774329697 10 0.0078852986855219 3.33066907387547e-16 10 2 0 1.93716632225726 0.49737977432971 1.75261336008773 0.963507348203431 1.45793725484282 1.36909421185738 1.07165358995799 1.68865585100403 0.618033988749894 1.90211303259031 0.125581039058625 1.99605345685654 -0.374762629171451 1.96457450145738 -0.851558583130147 1.80965410493204 -1.27484797949738 1.54102648555158 -1.6180339887499 1.17557050458494 -1.8595529717765 0.736249105369352 -1.98422940262896 0.250666467128604 -1.98422940262896 -0.250666467128614 -1.8595529717765 -0.736249105369362 -1.61803398874989 -1.17557050458495 -1.27484797949737 -1.54102648555158 -0.851558583130138 -1.80965410493204 -0.374762629171441 -1.96457450145738 0.125581039058636 -1.99605345685654 0.618033988749904 -1.9021130325903 1.071653589958 -1.68865585100402 1.45793725484283 -1.36909421185737 1.75261336008773 -0.96350734820342 1.93716632225727 -0.497379774329697 0.00788529868552179 2.22044604925031e-16 26 1 2 26 2 3 26 3 4 26 4 5 26 5 6 26 6 7 26 7 8 26 8 9 26 9 10 26 10 11 26 11 12 26 12 13 26 13 14 26 14 15 26 15 16 26 16 17 26 17 18 26 18 19 26 19 20 26 20 21 26 21 22 26 22 23 26 23 24 26 24 25 26 25 1
|
||||
26 25 1 2.22044604925031e-16
|
||||
2 -4.89842541528951e-16 0 1.93716632225726 0.49737977432971 0 1.75261336008773 0.963507348203431 0 1.45793725484282 1.36909421185738 0 1.07165358995799 1.68865585100403 0 0.618033988749894 1.90211303259031 0 0.125581039058625 1.99605345685654 0 -0.374762629171451 1.96457450145738 0 -0.851558583130147 1.80965410493204 0 -1.27484797949738 1.54102648555158 0 -1.6180339887499 1.17557050458494 0 -1.8595529717765 0.736249105369352 0 -1.98422940262896 0.250666467128604 0 -1.98422940262896 -0.250666467128614 0 -1.8595529717765 -0.736249105369362 0 -1.61803398874989 -1.17557050458495 0 -1.27484797949737 -1.54102648555158 0 -0.851558583130138 -1.80965410493204 0 -0.374762629171441 -1.96457450145738 0 0.125581039058636 -1.99605345685654 0 0.618033988749905 -1.9021130325903 0 1.071653589958 -1.68865585100402 0 1.45793725484283 -1.36909421185737 0 1.75261336008773 -0.96350734820342 0 1.93716632225727 -0.497379774329697 0 0.0078852986855219 3.33066907387547e-16 0 2 0 1.93716632225726 0.49737977432971 1.75261336008773 0.963507348203431 1.45793725484282 1.36909421185738 1.07165358995799 1.68865585100403 0.618033988749894 1.90211303259031 0.125581039058625 1.99605345685654 -0.374762629171451 1.96457450145738 -0.851558583130147 1.80965410493204 -1.27484797949738 1.54102648555158 -1.6180339887499 1.17557050458494 -1.8595529717765 0.736249105369352 -1.98422940262896 0.250666467128604 -1.98422940262896 -0.250666467128614 -1.8595529717765 -0.736249105369362 -1.61803398874989 -1.17557050458495 -1.27484797949737 -1.54102648555158 -0.851558583130138 -1.80965410493204 -0.374762629171441 -1.96457450145738 0.125581039058636 -1.99605345685654 0.618033988749904 -1.9021130325903 1.071653589958 -1.68865585100402 1.45793725484283 -1.36909421185737 1.75261336008773 -0.96350734820342 1.93716632225727 -0.497379774329697 0.00788529868552179 2.22044604925031e-16 26 1 2 26 2 3 26 3 4 26 4 5 26 5 6 26 6 7 26 7 8 26 8 9 26 9 10 26 10 11 26 11 12 26 12 13 26 13 14 26 14 15 26 15 16 26 16 17 26 17 18 26 18 19 26 19 20 26 20 21 26 21 22 26 22 23 26 23 24 26 24 25 26 25 1
|
||||
|
||||
TShapes 15
|
||||
Ve
|
||||
1e-07
|
||||
2 -4.89842541528951e-16 10
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 1 0 0 6.28318530717959
|
||||
2 1 1 0 0 6.28318530717959
|
||||
2 2 2 0 0 6.28318530717959
|
||||
6 1 1 0
|
||||
6 2 2 0
|
||||
0
|
||||
|
||||
0101100
|
||||
+15 2 -15 2 *
|
||||
Ve
|
||||
1e-07
|
||||
2 -4.89842541528951e-16 0
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 2 0 0 10
|
||||
3 3 4CN 1 0 0 10
|
||||
7 3 4 1 0
|
||||
0
|
||||
|
||||
0101000
|
||||
-15 2 +13 2 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 3 0 0 6.28318530717959
|
||||
2 5 1 0 0 6.28318530717959
|
||||
2 6 3 0 0 6.28318530717959
|
||||
6 5 1 0
|
||||
6 6 3 0
|
||||
0
|
||||
|
||||
0101100
|
||||
+13 2 -13 2 *
|
||||
Wi
|
||||
|
||||
0101000
|
||||
-14 0 +12 0 +11 0 -12 0 *
|
||||
Fa
|
||||
0 1e-07 1 0
|
||||
2 1
|
||||
0101000
|
||||
+10 0 *
|
||||
Wi
|
||||
|
||||
0101000
|
||||
+14 0 *
|
||||
Fa
|
||||
0 1e-07 2 0
|
||||
2 2
|
||||
0101000
|
||||
+8 0 *
|
||||
Wi
|
||||
|
||||
0101000
|
||||
-11 0 *
|
||||
Fa
|
||||
0 1e-07 3 0
|
||||
2 3
|
||||
0101000
|
||||
-6 0 *
|
||||
Sh
|
||||
|
||||
0101100
|
||||
+9 0 +7 0 -5 0 *
|
||||
So
|
||||
|
||||
0100100
|
||||
+4 0 *
|
||||
Co
|
||||
|
||||
0100000
|
||||
+3 1 *
|
||||
Co
|
||||
|
||||
1100000
|
||||
+2 0 *
|
||||
|
||||
+1 0
|
||||
903
tests/src/Mod/Part/App/brepfiles/helix1.brep
Normal file
903
tests/src/Mod/Part/App/brepfiles/helix1.brep
Normal file
@@ -0,0 +1,903 @@
|
||||
DBRep_DrawableShape
|
||||
|
||||
CASCADE Topology V1, (c) Matra-Datavision
|
||||
Locations 1
|
||||
1
|
||||
1 0 0 0
|
||||
0 -2.22044604925031e-16 -1 0
|
||||
0 1 -2.22044604925031e-16 0
|
||||
Curve2ds 60
|
||||
1 0 0 1 0
|
||||
1 0 0 1 0
|
||||
1 0 0 1 0
|
||||
1 0 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 1.1180339887492663 0 0 1
|
||||
1 0.99999999999999989 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 0 0 0 1
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 0.99999999999999989
|
||||
1 0 0 1 0
|
||||
1 0 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 1.1180339887492663 0 0 1
|
||||
1 0.99999999999999989 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 0 0 0 1
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 0.99999999999999989
|
||||
1 0 0 1 0
|
||||
1 0 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 1.1180339887492663 0 0 1
|
||||
1 0.99999999999999989 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 0 0 0 1
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 0.99999999999999989
|
||||
1 0 0 1 0
|
||||
1 0 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 1.1180339887492663 0 0 1
|
||||
1 0.99999999999999989 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 0 0 0 1
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 0.99999999999999989
|
||||
1 0 0 1 0
|
||||
1 0 0 0 1
|
||||
8 0 3.4292921874756512
|
||||
1 1.1180339887492663 0 0 1
|
||||
1 0.99999999999999989 0 0 1
|
||||
8 0 3.4292921874756512
|
||||
1 0 0 0 1
|
||||
1 0 3.4292921874756512 1 0
|
||||
1 1.1180339887505235 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 0 0 0 1
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 1.1180339887505235
|
||||
1 0 0 1 0
|
||||
1 1.1180339887505235 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 0 0 0 1
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 1.1180339887505235
|
||||
1 0 0 1 0
|
||||
1 1.1180339887505235 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 0 0 0 1
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 1.1180339887505235
|
||||
1 0 0 1 0
|
||||
1 1.1180339887505235 0 0 1
|
||||
8 0 6.2870356770386975
|
||||
1 0 0 0 1
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 1.1180339887505235
|
||||
1 0 0 1 0
|
||||
1 1.1180339887505235 0 0 1
|
||||
8 0 3.4292921874756512
|
||||
1 0 0 0 1
|
||||
1 0 3.4292921874756512 1 0
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 1.1180339887492663
|
||||
1 0 0 1 0
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 1.1180339887492663
|
||||
1 0 0 1 0
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 1.1180339887492663
|
||||
1 0 0 1 0
|
||||
1 0 6.2870356770386975 1 0
|
||||
8 0 1.1180339887492663
|
||||
1 0 0 1 0
|
||||
1 0 3.4292921874756512 1 0
|
||||
Curves 33
|
||||
7 0 0 1 2 2 2.0000000000000306 9.0938367947046572e-13 1.6684810553702823e-15 2.0000000000000284 1.0000000000009095 1.8067860570396971e-15
|
||||
0 2 0.99999999999999989 2
|
||||
7 0 0 1 2 2 2.0000000000000275 0.99999999999999989 1.2482846049280778e-15 3.0000000000000262 0.49999999999909028 2.64590224776542e-15
|
||||
0 2 1.1180339887505235 2
|
||||
7 0 0 1 2 2 3.0000000000000262 0.49999999999909028 2.64590224776542e-15 2.0000000000000266 -1.1102230246251565e-16 1.735593475076781e-15
|
||||
0 2 1.1180339887492663 2
|
||||
7 0 0 10 11 2 2.0000000000000306 9.0938367947046572e-13 1.6684810553702823e-15 1.999999959939065 0.11000000199007182 -1.2566338554788934 1.1228905917351018 0.21999999529312889 -2.5142965052784554 -0.63337553221942444 0.33000000849324884 -3.074762622374831 -2.6388940263357452 0.43999999335094497 -2.2895691041051509 -3.7012392763888831 0.5500000002214146 -2.6799449770464936e-08 -2.6388942634676984 0.66000000729935382 2.289569143296684 -0.6333752369905884 0.76999999205562586 3.0747626064836964 1.122890401259464 0.88000000523279343 2.5142965081779178 2.0000000280573076 0.98999999860754562 1.2566338556980587 1.9999999889437008 1.1000000005496986 7.9688529331130179e-11
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 10 11 2 2.0000000000000284 1.0000000000009095 1.8067860570396971e-15 1.9999999599470493 1.1100000019901159 -1.2566338554796066 1.1228905917164054 1.2199999952962788 -2.5142965052802975 -0.6333755321888157 1.3300000084765569 -3.0747626223748288 -2.6388940263641505 1.4399999933898993 -2.2895691041104191 -3.7012392763868704 1.5500000001715462 -2.6794308105593292e-08 -2.6388942634487753 1.6600000073384424 2.2895691432943206 -0.6333752370187804 1.7699999920387648 3.0747626064869191 1.1228904012785821 1.8800000052360488 2.5142965081790924 2.0000000280516921 1.9899999986075592 1.2566338556987795 1.9999999889459432 2.1000000005496986 7.9688667636131848e-11
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 1 2 2 1.9999999889437008 1.1000000005496986 7.9688529331130179e-11 1.9999999889459432 2.1000000005496986 7.9688667636131848e-11
|
||||
0 2 0.99999999999999989 2
|
||||
7 0 0 10 11 2 1.9999999889438393 1.1000000005506081 7.9573322520480816e-11 1.9999999504327597 1.2100000024638651 -1.2566338485000579 1.1228905841713051 1.3199999958902204 -2.5142964936684566 -0.63337552679389553 1.4300000089461606 -3.0747626022633292 -2.6388940137391041 1.5399999939296962 -2.2895690975066207 -3.7012392571699686 1.6500000007173401 -2.1274036754448425e-08 -2.6388942480372157 1.7600000078276066 2.2895691263877964 -0.63337523498080051 1.8699999925830786 3.0747625936187082 1.1228903958652039 1.9800000057520644 2.514296493179764 2.0000000172065762 2.0899999991450695 1.2566338495544689 1.9999999786182334 2.2000000010621084 1.498650320469746e-10
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 10 11 2 1.9999999889460875 2.1000000005506076 7.9569716671940351e-11 1.9999999504427557 2.2100000024638762 -1.2566338485020818 1.1228905841539827 2.3199999958947446 -2.5142964936729517 -0.63337552676433961 2.4300000089179838 -3.0747626022660426 -2.6388940137698809 2.5399999939944702 -2.2895690975160075 -3.7012392571715007 2.6500000006299165 -2.1266290062271801e-08 -2.6388942480221624 2.7600000079011782 2.2895691263853917 -0.63337523500900739 2.8699999925487942 3.0747625936265219 1.1228903958853254 2.9800000057580278 2.5142964931831826 2.0000000172031585 3.0899999991450615 1.256633849556545 1.9999999786225262 3.2000000010621079 1.4986675526895234e-10
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 1 2 2 1.9999999786182334 2.2000000010621084 1.498650320469746e-10 1.9999999786225262 3.2000000010621079 1.4986675526895234e-10
|
||||
0 2 0.99999999999999989 2
|
||||
7 0 0 10 11 2 1.9999999786181786 2.2000000010621079 1.4993260157095021e-10 1.9999999400738631 2.3100000029808276 -1.2566338420167411 1.1228905772510862 2.4199999964632046 -2.5142964794265734 -0.63337552098851213 2.5300000094244859 -3.0747625870472812 -2.6388940021707605 2.6399999943919257 -2.2895690849360779 -3.7012392363085422 2.7500000014736909 -2.2093992413374548e-08 -2.638894233520348 2.8600000080243344 2.2895691152357105 -0.63337523368614168 2.9699999933701364 3.0747625761742614 1.1228903911008323 3.0800000061624324 2.5142964805065611 2.0000000063123959 3.1899999996821689 1.2566338429759571 1.9999999678044289 3.300000001599074 2.0309046120301625e-10
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 10 11 2 1.9999999786224718 3.2000000010621079 1.4993245955643687e-10 1.9999999400858754 3.3100000029809165 -1.2566338420201038 1.1228905772354529 3.4199999964662728 -2.5142964794336784 -0.63337552096141658 3.530000009400982 -3.0747625870539368 -2.6388940022006375 3.6399999944497425 -2.2895690849458434 -3.7012392363187367 3.7500000013920904 -2.2089328588492702e-08 -2.638894233504244 3.8600000080946613 2.2895691152386886 -0.63337523371668869 3.9699999933346248 3.0747625761836828 1.1228903911224484 4.0800000061691435 2.5142964805130732 2.0000000063110868 4.1899999996822723 1.2566338429793282 1.999999967810852 4.3000000015990736 2.0308943101008321e-10
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 1 2 2 1.9999999678044289 3.300000001599074 2.0309046120301625e-10 1.999999967810852 4.3000000015990736 2.0308943101008321e-10
|
||||
0 2 0.99999999999999989 2
|
||||
7 0 0 10 11 2 1.9999999678044258 3.3000000015990736 2.0309866472500391e-10 1.9999999279238478 3.4100000035856528 -1.2566338351063444 1.1228905729919101 3.5199999969246787 -2.5142964646674235 -0.63337551712705942 3.6300000099194438 -3.074762572896566 -2.6388939950858141 3.7399999954130898 -2.2895690671737792 -3.701239199025594 3.8500000010453497 -2.8316819999929571e-08 -2.638894240086211 3.9600000097382408 2.289569107254986 -0.63337521336332525 4.0699999930152293 3.0747625569284258 1.1228903762540163 4.1800000071518646 2.5142964672592112 1.9999999975765625 4.2900000001133263 1.2566338359369953 1.9999999567633309 4.4000000021460446 3.4089193414872246e-10
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 10 11 2 1.9999999678108487 4.3000000015990727 2.0310001286277759e-10 1.9999999279383043 4.4100000035856688 -1.2566338351111224 1.122890572977371 4.5199999969270834 -2.5142964646772947 -0.63337551710101136 4.6300000099037906 -3.0747625729062196 -2.6388939951173178 4.7399999954404937 -2.2895690671867799 -3.7012391990426692 4.8500000010168538 -2.8311815114534561e-08 -2.6388942400694013 4.9600000097581329 2.28956910726074 -0.63337521339745995 5.0699999930075235 3.0747625569407111 1.1228903762783815 5.1800000071517864 2.5142964672688786 1.999999997577024 5.2900000001133138 1.2566338359416902 1.9999999567719706 5.4000000021460428 3.4087463053968244e-10
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 1 2 2 1.9999999567633309 4.4000000021460446 3.4089193414872246e-10 1.9999999567719706 5.4000000021460428 3.4087463053968244e-10
|
||||
0 2 0.99999999999999989 2
|
||||
7 0 0 7 8 2 1.9999999567634459 4.4000000021451351 3.4084246536281171e-10 2.0000002640696679 4.4857142726286385 -0.97919124939730628 1.4406779014824571 4.5714286200977545 -1.9568429588808502 0.32256706838431459 4.65714278042977 -2.5610970658126595 -1.0310446917849259 4.7428572231265349 -2.3664775333082049 -1.9336277920152993 4.8285713826164374 -1.4716907680536384 -2.1948556793096836 4.914285730957423 -0.37606210629261111 -1.9189859268982161 5.0000000010577432 0.5634651072808482
|
||||
0 8 3.4292921874756512 8
|
||||
7 0 0 7 8 2 1.9999999567720863 5.4000000021451333 3.4082825450809651e-10 2.0000002640168799 5.4857142726286572 -0.97919124940054725 1.440677901603262 5.5714286201005256 -1.956842958876841 0.32256706831810533 5.6571427804273915 -2.561097065856611 -1.0310446918474518 5.7428572231258039 -2.3664775332620946 -1.9336277919102527 5.8285713826187129 -1.4716907681020224 -2.1948556793750762 5.9142857309574053 -0.37606210627671594 -1.91898592690228 6.0000000010577423 0.56346510728208499
|
||||
0 8 3.4292921874756512 8
|
||||
7 0 0 1 2 2 -1.9189859268982161 5.0000000010577432 0.5634651072808482 -1.91898592690228 6.0000000010577423 0.56346510728208499
|
||||
0 2 0.99999999999999989 2
|
||||
7 0 0 10 11 2 3.0000000000000262 0.49999999999909028 2.64590224776542e-15 2.9999999599430494 0.61000000198025983 -1.8849523991101589 1.6843358541807412 0.71999999532856152 -3.7714388372926861 -0.95006329236532527 0.83000000838478272 -4.6121543037994446 -3.9583409408894639 0.9399999935088923 -3.4343447840084473 -5.5518591362037464 1.0500000000726892 -2.6801831864986571e-08 -3.9583411779967386 1.1600000073662897 3.4343448232057008 -0.95006299716576159 1.2699999920433398 4.6121542879044508 1.6843356637246436 1.3800000052181578 3.771438840193881 3.000000028054711 1.4899999986117534 1.8849523993284072 2.9999999889448357 1.6000000005460604 7.9366400412257482e-11
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 1 2 2 1.9999999889459439 2.1000000005487891 7.9688997313099437e-11 2.9999999889448357 1.6000000005460604 7.9366400412257482e-11
|
||||
0 2 1.1180339887505235 2
|
||||
7 0 0 10 11 2 2.999999988944976 1.6000000005460602 7.9250740617934832e-11 2.9999999504375432 1.7100000024516238 -1.8849523921333624 1.6843358466169605 1.8199999959049489 -3.7714388256798435 -0.95006328694068609 1.9300000089020084 -4.6121542837014822 -3.95834092829466 2.0399999939710258 -3.4343447773886919 -5.5518591169866616 2.1500000006882662 -2.1303298680663866e-08 -3.9583411625671245 2.2600000078083955 3.4343448063231747 -0.95006299515631087 2.3699999926109152 4.6121542750259197 1.6843356583319962 2.4800000057243063 3.7714388252032625 3.0000000172052164 2.5899999991464546 1.8849523931834573 2.9999999786203655 2.7000000010557414 1.4926020001166973e-10
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 1 2 2 1.9999999786225262 3.2000000010611984 1.4986436523883961e-10 2.9999999786203655 2.7000000010557414 1.4926020001166973e-10
|
||||
0 2 1.1180339887505235 2
|
||||
7 0 0 10 11 2 2.9999999786203113 2.7000000010557414 1.493250228982142e-10 2.9999999400794013 2.8100000029668268 -1.8849523856500396 1.6843358396979533 2.9199999964709473 -3.7714388114427502 -0.95006328113862848 3.0300000093814292 -4.6121542684796086 -3.9583409167230954 3.1399999944454362 -3.4343447648292291 -5.5518590961329659 3.250000001403254 -2.211391869622052e-08 -3.9583411480468893 3.3600000080552288 3.4343447951676214 -0.95006299386368853 3.469999993355684 4.6121542575846384 1.6843356535689435 3.5800000061467721 3.7714388125311884 3.0000000063121735 3.6899999996808979 1.8849523866053275 2.9999999678076414 3.8000000015899791 2.0226724577899886e-10
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 1 2 2 1.9999999678108524 4.3000000015981641 2.0308942781058091e-10 2.9999999678076414 3.8000000015899791 2.0226724577899886e-10
|
||||
0 2 1.1180339887505235 2
|
||||
7 0 0 10 11 2 2.9999999678076419 3.8000000015899786 2.0228197919908545e-10 2.9999999279305172 3.9100000035685993 -1.8849523787403486 1.6843358354390539 4.0199999969387505 -3.7714387966862271 -0.95006327727783102 4.130000009847369 -4.6121542543265557 -3.9583409096400803 4.2399999955134353 -3.4343447470762434 -5.5518590588514121 4.3500000009162774 -2.8324961931502962e-08 -3.9583411546147409 4.4600000098022869 3.4343447871776691 -0.95006297354057856 4.569999992988012 4.612154238347574 1.6843356387230635 4.6800000071346206 3.7714387992820004 2.9999999975774561 4.7900000001106369 1.8849523795677556 2.9999999567676552 4.9000000021351298 3.3978766941952692e-10
|
||||
0 11 6.2870356770386975 11
|
||||
7 0 0 1 2 2 1.9999999567719688 5.4000000021451333 3.4087654078806909e-10 2.9999999567676552 4.9000000021351298 3.3978766941952692e-10
|
||||
0 2 1.1180339887505235 2
|
||||
7 0 0 8 9 2 2.9999999567677649 4.9000000021351298 3.397406800331737e-10 3.0000002256333747 4.9749999888619385 -1.2851913641367954 2.3705073010240469 5.0500000328942178 -2.5704115958869975 1.1136055593857705 5.1249999710601237 -3.4960865104568501 -0.53250205740685397 5.2000000008716958 -3.7036172149772306 -2.0534544967400987 5.2750000334473137 -3.0407322012228404 -2.9986555539519255 5.3499999696162943 -1.7984423363377851 -3.2405588854226228 5.4250000146594397 -0.38793449825195131 -2.8784789005144367 5.5000000010522854 0.84519766412397335
|
||||
0 9 3.4292921874756512 9
|
||||
7 0 0 1 2 2 -1.9189859269022804 6.000000001056832 0.56346510728208465 -2.8784789005144367 5.5000000010522854 0.84519766412397335
|
||||
0 2 1.1180339887505235 2
|
||||
7 0 0 1 2 2 2.9999999889448357 1.6000000005460604 7.9366400412257482e-11 1.9999999889436957 1.1000000005487891 7.9689484621969586e-11
|
||||
0 2 1.1180339887492663 2
|
||||
7 0 0 1 2 2 2.9999999786203655 2.7000000010557414 1.4926020001166973e-10 1.9999999786182339 2.2000000010611989 1.4986414387580778e-10
|
||||
0 2 1.1180339887492663 2
|
||||
7 0 0 1 2 2 2.9999999678076414 3.8000000015899791 2.0226724577899886e-10 1.9999999678044273 3.3000000015981645 2.030895970084515e-10
|
||||
0 2 1.1180339887492663 2
|
||||
7 0 0 1 2 2 2.9999999567676552 4.9000000021351298 3.3978766941952692e-10 1.9999999567633331 4.4000000021451351 3.4089091691064752e-10
|
||||
0 2 1.1180339887492663 2
|
||||
7 0 0 1 2 2 -2.8784789005144367 5.5000000010522854 0.84519766412397335 -1.9189859268982157 5.0000000010568328 0.56346510728084809
|
||||
0 2 1.1180339887492663 2
|
||||
Polygon3D 0
|
||||
PolygonOnTriangulations 0
|
||||
Surfaces 17
|
||||
1 2.3454915028125551 0.49999999999961142 2.2204460492560777e-16 9.2179164606366873e-45 -4.4408920985006262e-16 -1 -2.0756902568627873e-29 1 -4.4408920985006262e-16 1 -2.0756902568627873e-29 0
|
||||
9 0 0 0 0 1 10 2 11 2 2 2.0000000000000306 9.0938367947046572e-13 1.6684810553702823e-15 1.999999959939065 0.11000000199007182 -1.2566338554788934 1.1228905917351018 0.21999999529312889 -2.5142965052784554 -0.63337553221942444 0.33000000849324884 -3.074762622374831 -2.6388940263357452 0.43999999335094497 -2.2895691041051509 -3.7012392763888831 0.5500000002214146 -2.6799449770464936e-08 -2.6388942634676984 0.66000000729935382 2.289569143296684 -0.6333752369905884 0.76999999205562586 3.0747626064836964 1.122890401259464 0.88000000523279343 2.5142965081779178 2.0000000280573076 0.98999999860754562 1.2566338556980587 1.9999999889437008 1.1000000005496986 7.9688529331130179e-11
|
||||
2.0000000000000284 1.0000000000009095 1.8067860570396971e-15 1.9999999599470493 1.1100000019901159 -1.2566338554796066 1.1228905917164054 1.2199999952962788 -2.5142965052802975 -0.6333755321888157 1.3300000084765569 -3.0747626223748288 -2.6388940263641505 1.4399999933898993 -2.2895691041104191 -3.7012392763868704 1.5500000001715462 -2.6794308105593292e-08 -2.6388942634487753 1.6600000073384424 2.2895691432943206 -0.6333752370187804 1.7699999920387648 3.0747626064869191 1.1228904012785821 1.8800000052360488 2.5142965081790924 2.0000000280516921 1.9899999986075592 1.2566338556987795 1.9999999889459432 2.1000000005496986 7.9688667636131848e-11
|
||||
|
||||
0 2
|
||||
0.99999999999999989 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 2.0000000000000275 0.99999999999999989 1.2482846049280778e-15 1.9999999599470515 1.1100000019892178 -1.2566338554796033 1.122890591716257 1.2199999952953255 -2.5142965052803392 -0.63337553218827447 1.3300000084757466 -3.0747626223746574 -2.6388940263652154 1.4399999933888332 -2.289569104110813 -3.7012392763855941 1.5500000001708156 -2.6793766316757275e-08 -2.6388942634497043 1.66000000733738 2.2895691432938867 -0.63337523701841136 1.7699999920379506 3.0747626064871429 1.1228904012785161 1.8800000052350989 2.5142965081790125 2.0000000280516912 1.9899999986066599 1.2566338556987984 1.9999999889459439 2.1000000005487891 7.9688997313099437e-11
|
||||
3.0000000000000262 0.49999999999909028 2.64590224776542e-15 2.9999999599430494 0.61000000198025983 -1.8849523991101589 1.6843358541807412 0.71999999532856152 -3.7714388372926861 -0.95006329236532527 0.83000000838478272 -4.6121543037994446 -3.9583409408894639 0.9399999935088923 -3.4343447840084473 -5.5518591362037464 1.0500000000726892 -2.6801831864986571e-08 -3.9583411779967386 1.1600000073662897 3.4343448232057008 -0.95006299716576159 1.2699999920433398 4.6121542879044508 1.6843356637246436 1.3800000052181578 3.771438840193881 3.000000028054711 1.4899999986117534 1.8849523993284072 2.9999999889448357 1.6000000005460604 7.9366400412257482e-11
|
||||
|
||||
0 2
|
||||
1.1180339887505235 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 3.0000000000000262 0.49999999999909028 2.64590224776542e-15 2.9999999599430494 0.61000000198025983 -1.8849523991101589 1.6843358541807412 0.71999999532856152 -3.7714388372926861 -0.95006329236532527 0.83000000838478272 -4.6121543037994446 -3.9583409408894639 0.9399999935088923 -3.4343447840084473 -5.5518591362037464 1.0500000000726892 -2.6801831864986571e-08 -3.9583411779967386 1.1600000073662897 3.4343448232057008 -0.95006299716576159 1.2699999920433398 4.6121542879044508 1.6843356637246436 1.3800000052181578 3.771438840193881 3.000000028054711 1.4899999986117534 1.8849523993284072 2.9999999889448357 1.6000000005460604 7.9366400412257482e-11
|
||||
2.0000000000000266 -1.1102230246251565e-16 1.735593475076781e-15 1.9999999599390308 0.11000000198916553 -1.2566338554788903 1.122890591735237 0.2199999952922061 -2.5142965052784754 -0.63337553221974396 0.33000000849237049 -3.0747626223747639 -2.6388940263352585 0.43999999334998541 -2.2895691041053015 -3.7012392763894 0.55000000022056506 -2.6799223284967912e-08 -2.6388942634673 0.66000000729838948 2.2895691432964478 -0.63337523699080889 0.76999999205475389 3.074762606483866 1.1228904012595493 0.88000000523186561 2.5142965081778392 2.0000000280572845 0.98999999860664134 1.2566338556980781 1.9999999889436957 1.1000000005487891 7.9689484621969586e-11
|
||||
|
||||
0 2
|
||||
1.1180339887492663 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 1.9999999889438393 1.1000000005506081 7.9573322520480816e-11 1.9999999504327597 1.2100000024638651 -1.2566338485000579 1.1228905841713051 1.3199999958902204 -2.5142964936684566 -0.63337552679389553 1.4300000089461606 -3.0747626022633292 -2.6388940137391041 1.5399999939296962 -2.2895690975066207 -3.7012392571699686 1.6500000007173401 -2.1274036754448425e-08 -2.6388942480372157 1.7600000078276066 2.2895691263877964 -0.63337523498080051 1.8699999925830786 3.0747625936187082 1.1228903958652039 1.9800000057520644 2.514296493179764 2.0000000172065762 2.0899999991450695 1.2566338495544689 1.9999999786182334 2.2000000010621084 1.498650320469746e-10
|
||||
1.9999999889460875 2.1000000005506076 7.9569716671940351e-11 1.9999999504427557 2.2100000024638762 -1.2566338485020818 1.1228905841539827 2.3199999958947446 -2.5142964936729517 -0.63337552676433961 2.4300000089179838 -3.0747626022660426 -2.6388940137698809 2.5399999939944702 -2.2895690975160075 -3.7012392571715007 2.6500000006299165 -2.1266290062271801e-08 -2.6388942480221624 2.7600000079011782 2.2895691263853917 -0.63337523500900739 2.8699999925487942 3.0747625936265219 1.1228903958853254 2.9800000057580278 2.5142964931831826 2.0000000172031585 3.0899999991450615 1.256633849556545 1.9999999786225262 3.2000000010621079 1.4986675526895234e-10
|
||||
|
||||
0 2
|
||||
0.99999999999999989 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 2.999999988944976 1.6000000005460602 7.9250740617934832e-11 2.9999999504375432 1.7100000024516238 -1.8849523921333624 1.6843358466169605 1.8199999959049489 -3.7714388256798435 -0.95006328694068609 1.9300000089020084 -4.6121542837014822 -3.95834092829466 2.0399999939710258 -3.4343447773886919 -5.5518591169866616 2.1500000006882662 -2.1303298680663866e-08 -3.9583411625671245 2.2600000078083955 3.4343448063231747 -0.95006299515631087 2.3699999926109152 4.6121542750259197 1.6843356583319962 2.4800000057243063 3.7714388252032625 3.0000000172052164 2.5899999991464546 1.8849523931834573 2.9999999786203655 2.7000000010557414 1.4926020001166973e-10
|
||||
1.9999999889438407 1.1000000005496986 7.957332252773369e-11 1.9999999504327932 1.2100000024629605 -1.2566338485000514 1.1228905841711276 1.319999995889297 -2.5142964936684877 -0.63337552679335152 1.4300000089452689 -3.0747626022632453 -2.6388940137400763 1.5399999939287836 -2.2895690975067469 -3.7012392571688522 1.6500000007164088 -2.1273940831179098e-08 -2.6388942480380755 1.760000007826731 2.2895691263877631 -0.6333752349803482 1.8699999925821442 3.0747625936187144 1.1228903958650478 1.9800000057511637 2.5142964931797618 2.0000000172066046 2.0899999991441587 1.2566338495544667 1.9999999786182339 2.2000000010611989 1.4986414387580778e-10
|
||||
|
||||
0 2
|
||||
1.1180339887492663 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 1.9999999889460875 2.1000000005496982 7.957176753392612e-11 1.9999999504427557 2.2100000024630013 -1.2566338485020756 1.1228905841539827 2.3199999958936943 -2.5142964936730134 -0.63337552676433961 2.4300000089174172 -3.0747626022659365 -2.6388940137698809 2.5399999939929776 -2.289569097516214 -3.7012392571715007 2.6500000006297264 -2.126587883566348e-08 -2.6388942480221624 2.760000007899631 2.2895691263849041 -0.63337523500900739 2.8699999925482822 3.0747625936267986 1.1228903958853254 2.9800000057569522 2.5142964931831022 2.0000000172031585 3.089999999144192 1.2566338495565548 1.9999999786225262 3.2000000010611984 1.4986436523883961e-10
|
||||
2.999999988944976 1.6000000005460602 7.9250740617934832e-11 2.9999999504375432 1.7100000024516238 -1.8849523921333624 1.6843358466169605 1.8199999959049489 -3.7714388256798435 -0.95006328694068609 1.9300000089020084 -4.6121542837014822 -3.95834092829466 2.0399999939710258 -3.4343447773886919 -5.5518591169866616 2.1500000006882662 -2.1303298680663866e-08 -3.9583411625671245 2.2600000078083955 3.4343448063231747 -0.95006299515631087 2.3699999926109152 4.6121542750259197 1.6843356583319962 2.4800000057243063 3.7714388252032625 3.0000000172052164 2.5899999991464546 1.8849523931834573 2.9999999786203655 2.7000000010557414 1.4926020001166973e-10
|
||||
|
||||
0 2
|
||||
1.1180339887505235 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 1.9999999786181786 2.2000000010621079 1.4993260157095021e-10 1.9999999400738631 2.3100000029808276 -1.2566338420167411 1.1228905772510862 2.4199999964632046 -2.5142964794265734 -0.63337552098851213 2.5300000094244859 -3.0747625870472812 -2.6388940021707605 2.6399999943919257 -2.2895690849360779 -3.7012392363085422 2.7500000014736909 -2.2093992413374548e-08 -2.638894233520348 2.8600000080243344 2.2895691152357105 -0.63337523368614168 2.9699999933701364 3.0747625761742614 1.1228903911008323 3.0800000061624324 2.5142964805065611 2.0000000063123959 3.1899999996821689 1.2566338429759571 1.9999999678044289 3.300000001599074 2.0309046120301625e-10
|
||||
1.9999999786224718 3.2000000010621079 1.4993245955643687e-10 1.9999999400858754 3.3100000029809165 -1.2566338420201038 1.1228905772354529 3.4199999964662728 -2.5142964794336784 -0.63337552096141658 3.530000009400982 -3.0747625870539368 -2.6388940022006375 3.6399999944497425 -2.2895690849458434 -3.7012392363187367 3.7500000013920904 -2.2089328588492702e-08 -2.638894233504244 3.8600000080946613 2.2895691152386886 -0.63337523371668869 3.9699999933346248 3.0747625761836828 1.1228903911224484 4.0800000061691435 2.5142964805130732 2.0000000063110868 4.1899999996822723 1.2566338429793282 1.999999967810852 4.3000000015990736 2.0308943101008321e-10
|
||||
|
||||
0 2
|
||||
0.99999999999999989 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 2.9999999786203113 2.7000000010557414 1.493250228982142e-10 2.9999999400794013 2.8100000029668268 -1.8849523856500396 1.6843358396979533 2.9199999964709473 -3.7714388114427502 -0.95006328113862848 3.0300000093814292 -4.6121542684796086 -3.9583409167230954 3.1399999944454362 -3.4343447648292291 -5.5518590961329659 3.250000001403254 -2.211391869622052e-08 -3.9583411480468893 3.3600000080552288 3.4343447951676214 -0.95006299386368853 3.469999993355684 4.6121542575846384 1.6843356535689435 3.5800000061467721 3.7714388125311884 3.0000000063121735 3.6899999996808979 1.8849523866053275 2.9999999678076414 3.8000000015899791 2.0226724577899886e-10
|
||||
1.9999999786181779 2.2000000010611984 1.4993262555480516e-10 1.999999940073848 2.3100000029799634 -1.2566338420167473 1.1228905772511177 2.4199999964621095 -2.5142964794265605 -0.63337552098855121 2.5300000094240174 -3.0747625870473176 -2.6388940021707392 2.6399999943902857 -2.28956908493599 -3.70123923630852 2.7500000014736599 -2.2094124751959083e-08 -2.6388942335204049 2.8600000080226584 2.2895691152358406 -0.6333752336860754 2.9699999933697065 3.074762576174181 1.1228903911007879 3.0800000061613169 2.5142964805065904 2.0000000063124097 3.1899999996813118 1.2566338429759545 1.9999999678044273 3.3000000015981645 2.030895970084515e-10
|
||||
|
||||
0 2
|
||||
1.1180339887492663 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 1.9999999786224714 3.2000000010611984 1.4993156817851488e-10 1.9999999400858832 3.3100000029800039 -1.2566338420200993 1.1228905772354258 3.4199999964653824 -2.5142964794336957 -0.63337552096137206 3.5300000094000121 -3.0747625870538924 -2.6388940022006326 3.6399999944489672 -2.2895690849459234 -3.7012392363188105 3.7500000013909731 -2.2089225559796017e-08 -2.6388942335041543 3.8600000080939694 2.2895691152385909 -0.63337523371675097 3.9699999933335639 3.0747625761837516 1.122890391122479 4.0800000061683024 2.5142964805130394 2.0000000063110819 4.189999999681346 1.2566338429793371 1.9999999678108524 4.3000000015981641 2.0308942781058091e-10
|
||||
2.9999999786203113 2.7000000010557414 1.493250228982142e-10 2.9999999400794013 2.8100000029668268 -1.8849523856500396 1.6843358396979533 2.9199999964709473 -3.7714388114427502 -0.95006328113862848 3.0300000093814292 -4.6121542684796086 -3.9583409167230954 3.1399999944454362 -3.4343447648292291 -5.5518590961329659 3.250000001403254 -2.211391869622052e-08 -3.9583411480468893 3.3600000080552288 3.4343447951676214 -0.95006299386368853 3.469999993355684 4.6121542575846384 1.6843356535689435 3.5800000061467721 3.7714388125311884 3.0000000063121735 3.6899999996808979 1.8849523866053275 2.9999999678076414 3.8000000015899791 2.0226724577899886e-10
|
||||
|
||||
0 2
|
||||
1.1180339887505235 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 1.9999999678044258 3.3000000015990736 2.0309866472500391e-10 1.9999999279238478 3.4100000035856528 -1.2566338351063444 1.1228905729919101 3.5199999969246787 -2.5142964646674235 -0.63337551712705942 3.6300000099194438 -3.074762572896566 -2.6388939950858141 3.7399999954130898 -2.2895690671737792 -3.701239199025594 3.8500000010453497 -2.8316819999929571e-08 -2.638894240086211 3.9600000097382408 2.289569107254986 -0.63337521336332525 4.0699999930152293 3.0747625569284258 1.1228903762540163 4.1800000071518646 2.5142964672592112 1.9999999975765625 4.2900000001133263 1.2566338359369953 1.9999999567633309 4.4000000021460446 3.4089193414872246e-10
|
||||
1.9999999678108487 4.3000000015990727 2.0310001286277759e-10 1.9999999279383043 4.4100000035856688 -1.2566338351111224 1.122890572977371 4.5199999969270834 -2.5142964646772947 -0.63337551710101136 4.6300000099037906 -3.0747625729062196 -2.6388939951173178 4.7399999954404937 -2.2895690671867799 -3.7012391990426692 4.8500000010168538 -2.8311815114534561e-08 -2.6388942400694013 4.9600000097581329 2.28956910726074 -0.63337521339745995 5.0699999930075235 3.0747625569407111 1.1228903762783815 5.1800000071517864 2.5142964672688786 1.999999997577024 5.2900000001133138 1.2566338359416902 1.9999999567719706 5.4000000021460428 3.4087463053968244e-10
|
||||
|
||||
0 2
|
||||
0.99999999999999989 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 2.9999999678076419 3.8000000015899786 2.0228197919908545e-10 2.9999999279305172 3.9100000035685993 -1.8849523787403486 1.6843358354390539 4.0199999969387505 -3.7714387966862271 -0.95006327727783102 4.130000009847369 -4.6121542543265557 -3.9583409096400803 4.2399999955134353 -3.4343447470762434 -5.5518590588514121 4.3500000009162774 -2.8324961931502962e-08 -3.9583411546147409 4.4600000098022869 3.4343447871776691 -0.95006297354057856 4.569999992988012 4.612154238347574 1.6843356387230635 4.6800000071346206 3.7714387992820004 2.9999999975774561 4.7900000001106369 1.8849523795677556 2.9999999567676552 4.9000000021351298 3.3978766941952692e-10
|
||||
1.999999967804428 3.3000000015981641 2.0309853566534866e-10 1.9999999279238589 3.4100000035847855 -1.2566338351063564 1.122890572991863 3.5199999969235889 -2.514296464667352 -0.63337551712694962 3.6300000099189784 -3.0747625728967702 -2.6388939950860215 3.7399999954114338 -2.289569067173399 -3.7012391990253026 3.8500000010453213 -2.8317314715309344e-08 -2.6388942400864956 3.9600000097365959 2.2895691072554576 -0.63337521336314628 4.0699999930147435 3.074762556928099 1.1228903762539559 4.1800000071507961 2.5142964672593644 1.9999999975765703 4.2900000001124514 1.2566338359369555 1.9999999567633331 4.4000000021451351 3.4089091691064752e-10
|
||||
|
||||
0 2
|
||||
1.1180339887492663 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 10 2 11 2 2 1.9999999678108487 4.3000000015981632 2.0309837039748544e-10 1.9999999279382952 4.4100000035848472 -1.2566338351111233 1.1228905729774059 4.5199999969258062 -2.5142964646773036 -0.6333755171011064 4.6300000099037781 -3.0747625729061858 -2.6388939951171726 4.7399999954380565 -2.2895690671868656 -3.7012391990428237 4.8500000010178805 -2.8311673005987409e-08 -2.6388942400692912 4.9600000097554044 2.2895691072605815 -0.63337521339751135 5.0699999930078441 3.0747625569408297 1.1228903762783933 5.1800000071503085 2.5142964672688248 1.9999999975770228 5.2900000001125544 1.2566338359417017 1.9999999567719688 5.4000000021451333 3.4087654078806909e-10
|
||||
2.9999999678076419 3.8000000015899786 2.0228197919908545e-10 2.9999999279305172 3.9100000035685993 -1.8849523787403486 1.6843358354390539 4.0199999969387505 -3.7714387966862271 -0.95006327727783102 4.130000009847369 -4.6121542543265557 -3.9583409096400803 4.2399999955134353 -3.4343447470762434 -5.5518590588514121 4.3500000009162774 -2.8324961931502962e-08 -3.9583411546147409 4.4600000098022869 3.4343447871776691 -0.95006297354057856 4.569999992988012 4.612154238347574 1.6843356387230635 4.6800000071346206 3.7714387992820004 2.9999999975774561 4.7900000001106369 1.8849523795677556 2.9999999567676552 4.9000000021351298 3.3978766941952692e-10
|
||||
|
||||
0 2
|
||||
1.1180339887505235 2
|
||||
|
||||
0 11
|
||||
6.2870356770386975 11
|
||||
|
||||
9 0 0 0 0 1 7 2 8 2 2 1.9999999567634459 4.4000000021451351 3.4084246536281171e-10 2.0000002640696679 4.4857142726286385 -0.97919124939730628 1.4406779014824571 4.5714286200977545 -1.9568429588808502 0.32256706838431459 4.65714278042977 -2.5610970658126595 -1.0310446917849259 4.7428572231265349 -2.3664775333082049 -1.9336277920152993 4.8285713826164374 -1.4716907680536384 -2.1948556793096836 4.914285730957423 -0.37606210629261111 -1.9189859268982161 5.0000000010577432 0.5634651072808482
|
||||
1.9999999567720863 5.4000000021451333 3.4082825450809651e-10 2.0000002640168799 5.4857142726286572 -0.97919124940054725 1.440677901603262 5.5714286201005256 -1.956842958876841 0.32256706831810533 5.6571427804273915 -2.561097065856611 -1.0310446918474518 5.7428572231258039 -2.3664775332620946 -1.9336277919102527 5.8285713826187129 -1.4716907681020224 -2.1948556793750762 5.9142857309574053 -0.37606210627671594 -1.91898592690228 6.0000000010577423 0.56346510728208499
|
||||
|
||||
0 2
|
||||
0.99999999999999989 2
|
||||
|
||||
0 8
|
||||
3.4292921874756512 8
|
||||
|
||||
9 0 0 0 0 1 8 2 9 2 2 2.9999999567677649 4.9000000021351298 3.397406800331737e-10 3.0000002256333747 4.9749999888619385 -1.2851913641367954 2.3705073010240469 5.0500000328942178 -2.5704115958869975 1.1136055593857705 5.1249999710601237 -3.4960865104568501 -0.53250205740685397 5.2000000008716958 -3.7036172149772306 -2.0534544967400987 5.2750000334473137 -3.0407322012228404 -2.9986555539519255 5.3499999696162943 -1.7984423363377851 -3.2405588854226228 5.4250000146594397 -0.38793449825195131 -2.8784789005144367 5.5000000010522854 0.84519766412397335
|
||||
1.9999999567634457 4.4000000021442256 3.4084202127360186e-10 2.0000002256563998 4.4749999888172907 -0.85679234318003406 1.5803375282327812 4.5500000330297086 -1.7136150504501024 0.74240571526481458 4.6249999709439429 -2.330709715104784 -0.35500472995647414 4.7000000008817722 -2.4690961844122525 -1.3689662699026173 4.7750000335740017 -2.0271404357293186 -1.9991057277353734 4.8499999695008489 -1.1989686215534909 -2.1603719602582432 4.9250000147190747 -0.25862120459594551 -1.9189859268982157 5.0000000010568328 0.56346510728084809
|
||||
|
||||
0 2
|
||||
1.1180339887492663 2
|
||||
|
||||
0 9
|
||||
3.4292921874756512 9
|
||||
|
||||
9 0 0 0 0 1 8 2 9 2 2 1.9999999567720863 5.4000000021442247 3.4082736632967681e-10 2.0000002256112897 5.4749999888172809 -0.856792343182876 1.5803375284244827 5.550000033033113 -1.7136150504645526 0.74240571490299379 5.6249999709394025 -2.3307097150774951 -0.35500472950880069 5.700000000885872 -2.4690961844857102 -1.3689662702680536 5.7750000335703762 -2.0271404356654052 -1.9991057275586339 5.8499999695038181 -1.1989686216024464 -2.1603719603159743 5.9250000147190507 -0.25862120458187643 -1.9189859269022804 6.000000001056832 0.56346510728208465
|
||||
2.9999999567677649 4.9000000021351298 3.397406800331737e-10 3.0000002256333747 4.9749999888619385 -1.2851913641367954 2.3705073010240469 5.0500000328942178 -2.5704115958869975 1.1136055593857705 5.1249999710601237 -3.4960865104568501 -0.53250205740685397 5.2000000008716958 -3.7036172149772306 -2.0534544967400987 5.2750000334473137 -3.0407322012228404 -2.9986555539519255 5.3499999696162943 -1.7984423363377851 -3.2405588854226228 5.4250000146594397 -0.38793449825195131 -2.8784789005144367 5.5000000010522854 0.84519766412397335
|
||||
|
||||
0 2
|
||||
1.1180339887505235 2
|
||||
|
||||
0 9
|
||||
3.4292921874756512 9
|
||||
|
||||
1 -2.2504825962919797 5.5000000010564518 0.66080131173616696 0.28173255684250664 -2.6696418513327818e-14 0.95949297361418118 -4.0819749136223607e-12 1 1.2263993079777387e-12 -0.95949297361418118 -4.2621429146702262e-12 0.2817325568425067
|
||||
Triangulations 0
|
||||
|
||||
TShapes 88
|
||||
Ve
|
||||
4.39810635581078e-05
|
||||
2.00000000000003 -1.11022302462516e-16 1.73559347507678e-15
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ve
|
||||
2.94018437871922e-05
|
||||
2.00000000000003 1 1.24828460492808e-15
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1.00005e-07 1 1 0
|
||||
1 1 0 0 1
|
||||
2 1 2 0 0 1
|
||||
0
|
||||
|
||||
0101000
|
||||
+88 0 -87 0 *
|
||||
Ve
|
||||
4.3981062235277e-05
|
||||
3.00000000000003 0.49999999999909 2.64590224776542e-15
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1.00005e-07 1 1 0
|
||||
1 2 0 0 1.11803398875052
|
||||
2 2 3 0 0 1.11803398875052
|
||||
0
|
||||
|
||||
0101000
|
||||
+87 0 -85 0 *
|
||||
Ed
|
||||
1.00005e-07 1 1 0
|
||||
1 3 0 0 1.11803398874927
|
||||
2 3 4 0 0 1.11803398874927
|
||||
0
|
||||
|
||||
0101000
|
||||
+85 0 -88 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
+86 0 +84 0 +83 0 *
|
||||
Fa
|
||||
0 1e-07 1 0
|
||||
|
||||
0101000
|
||||
+82 0 *
|
||||
Ve
|
||||
2.94018442477067e-05
|
||||
1.99999998894377 1.10000000055015 7.95973845452051e-11
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 4 0 0 6.2870356770387
|
||||
2 4 2 0 0 6.2870356770387
|
||||
2 5 4 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+88 0 -80 0 *
|
||||
Ve
|
||||
2.94018442477067e-05
|
||||
1.99999998894602 2.10000000054924 7.95969404559953e-11
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 5 0 0 6.2870356770387
|
||||
2 6 2 0 0 6.2870356770387
|
||||
2 7 3 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+87 0 -78 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 6 0 0 1
|
||||
2 8 2 0 0 1
|
||||
2 9 5 0 0 1
|
||||
4 C1 5 0 2 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+80 0 -78 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-79 0 +86 0 +77 0 -76 0 *
|
||||
Fa
|
||||
0 1e-07 2 0
|
||||
|
||||
0101000
|
||||
+75 0 *
|
||||
Ve
|
||||
2.94018604988986e-05
|
||||
1.99999997861821 2.20000000106211 1.49914425623943e-10
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 7 0 0 6.2870356770387
|
||||
2 10 5 0 0 6.2870356770387
|
||||
2 11 6 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+80 0 -73 0 *
|
||||
Ve
|
||||
2.94018604988986e-05
|
||||
1.9999999786225 3.2000000010612 1.49913981534733e-10
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 8 0 0 6.2870356770387
|
||||
2 12 5 0 0 6.2870356770387
|
||||
2 13 7 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+78 0 -71 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 9 0 0 1
|
||||
2 14 5 0 0 1
|
||||
2 15 8 0 0 1
|
||||
4 C1 8 0 5 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+73 0 -71 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-72 0 +76 0 +70 0 -69 0 *
|
||||
Fa
|
||||
0 1e-07 5 0
|
||||
|
||||
0101000
|
||||
+68 0 *
|
||||
Ve
|
||||
2.94018662885789e-05
|
||||
1.99999996780443 3.30000000159907 2.03096284540616e-10
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 10 0 0 6.2870356770387
|
||||
2 16 8 0 0 6.2870356770387
|
||||
2 17 9 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+73 0 -66 0 *
|
||||
Ve
|
||||
2.94018662885789e-05
|
||||
1.99999996781085 4.30000000159816 2.03095840451406e-10
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 11 0 0 6.2870356770387
|
||||
2 18 8 0 0 6.2870356770387
|
||||
2 19 10 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+71 0 -64 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 12 0 0 1
|
||||
2 20 8 0 0 1
|
||||
2 21 11 0 0 1
|
||||
4 C1 11 0 8 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+66 0 -64 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-65 0 +69 0 +63 0 -62 0 *
|
||||
Fa
|
||||
0 1e-07 8 0
|
||||
|
||||
0101000
|
||||
+61 0 *
|
||||
Ve
|
||||
2.94018603423369e-05
|
||||
1.99999995676339 4.40000000214559 3.4086781206032e-10
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 13 0 0 6.2870356770387
|
||||
2 22 11 0 0 6.2870356770387
|
||||
2 23 12 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+66 0 -59 0 *
|
||||
Ve
|
||||
2.94018603423493e-05
|
||||
1.99999995677203 5.40000000214468 3.40853379161e-10
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 14 0 0 6.2870356770387
|
||||
2 24 11 0 0 6.2870356770387
|
||||
2 25 13 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+64 0 -57 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 15 0 0 1
|
||||
2 26 11 0 0 1
|
||||
2 27 14 0 0 1
|
||||
4 G1 14 0 11 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+59 0 -57 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-58 0 +62 0 +56 0 -55 0 *
|
||||
Fa
|
||||
0 1e-07 11 0
|
||||
|
||||
0101000
|
||||
+54 0 *
|
||||
Ve
|
||||
7.75115104411493e-05
|
||||
-1.91898592689822 5.00000000105683 0.563465107280848
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
0.00014709836519379 1 1 0
|
||||
1 16 0 0 3.42929218747565
|
||||
2 28 14 0 0 3.42929218747565
|
||||
2 29 15 0 0 3.42929218747565
|
||||
0
|
||||
|
||||
0101000
|
||||
+59 0 -52 0 *
|
||||
Ve
|
||||
7.75115113493296e-05
|
||||
-1.91898592690228 6.00000000105683 0.563465107282085
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
0.000147098365210656 1 1 0
|
||||
1 17 0 0 3.42929218747565
|
||||
2 30 14 0 0 3.42929218747565
|
||||
2 31 16 0 0 3.42929218747565
|
||||
0
|
||||
|
||||
0101000
|
||||
+57 0 -50 0 *
|
||||
Ed
|
||||
1.00005e-07 1 1 0
|
||||
1 18 0 0 1
|
||||
2 32 14 0 0 1
|
||||
0
|
||||
|
||||
0101000
|
||||
+52 0 -50 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-51 0 +55 0 +49 0 -48 0 *
|
||||
Fa
|
||||
0 1e-07 14 0
|
||||
|
||||
0101000
|
||||
+47 0 *
|
||||
Ve
|
||||
4.39810618145432e-05
|
||||
2.99999998894491 1.60000000054606 7.92760860018786e-11
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 19 0 0 6.2870356770387
|
||||
2 33 3 0 0 6.2870356770387
|
||||
2 34 4 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+85 0 -45 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 20 0 0 1.11803398875052
|
||||
2 35 3 0 0 1.11803398875052
|
||||
2 36 7 0 0 1.11803398875052
|
||||
4 C1 7 0 3 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+78 0 -45 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-77 0 +84 0 +44 0 -43 0 *
|
||||
Fa
|
||||
0 1e-07 3 0
|
||||
|
||||
0101000
|
||||
+42 0 *
|
||||
Ve
|
||||
4.39810783756164e-05
|
||||
2.99999997862034 2.70000000105574 1.49308687941708e-10
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 21 0 0 6.2870356770387
|
||||
2 37 7 0 0 6.2870356770387
|
||||
2 38 6 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+45 0 -40 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 22 0 0 1.11803398875052
|
||||
2 39 7 0 0 1.11803398875052
|
||||
2 40 10 0 0 1.11803398875052
|
||||
4 C1 10 0 7 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+71 0 -40 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-70 0 +43 0 +39 0 -38 0 *
|
||||
Fa
|
||||
0 1e-07 7 0
|
||||
|
||||
0101000
|
||||
+37 0 *
|
||||
Ve
|
||||
4.39810841886954e-05
|
||||
2.99999996780764 3.80000000158998 2.02276051770023e-10
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 23 0 0 6.2870356770387
|
||||
2 41 10 0 0 6.2870356770387
|
||||
2 42 9 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+40 0 -35 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 24 0 0 1.11803398875052
|
||||
2 43 10 0 0 1.11803398875052
|
||||
2 44 13 0 0 1.11803398875052
|
||||
4 C1 13 0 10 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+64 0 -35 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-63 0 +38 0 +34 0 -33 0 *
|
||||
Fa
|
||||
0 1e-07 10 0
|
||||
|
||||
0101000
|
||||
+32 0 *
|
||||
Ve
|
||||
4.39810778551053e-05
|
||||
2.99999995676771 4.90000000213513 3.39765582641472e-10
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 25 0 0 6.2870356770387
|
||||
2 45 13 0 0 6.2870356770387
|
||||
2 46 12 0 0 6.2870356770387
|
||||
0
|
||||
|
||||
0101000
|
||||
+35 0 -30 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 26 0 0 1.11803398875052
|
||||
2 47 13 0 0 1.11803398875052
|
||||
2 48 16 0 0 1.11803398875052
|
||||
4 G1 16 0 13 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+57 0 -30 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-56 0 +33 0 +29 0 -28 0 *
|
||||
Fa
|
||||
0 1e-07 13 0
|
||||
|
||||
0101000
|
||||
+27 0 *
|
||||
Ve
|
||||
1.0602117875223e-05
|
||||
-2.87847890051444 5.50000000105229 0.845197664123973
|
||||
0 0
|
||||
|
||||
0101101
|
||||
*
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 27 0 0 3.42929218747565
|
||||
2 49 16 0 0 3.42929218747565
|
||||
2 50 15 0 0 3.42929218747565
|
||||
0
|
||||
|
||||
0101000
|
||||
+30 0 -25 0 *
|
||||
Ed
|
||||
1.00005e-07 1 1 0
|
||||
1 28 0 0 1.11803398875052
|
||||
2 51 16 0 0 1.11803398875052
|
||||
0
|
||||
|
||||
0101000
|
||||
+50 0 -25 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-49 0 +28 0 +24 0 -23 0 *
|
||||
Fa
|
||||
0 1e-07 16 0
|
||||
|
||||
0101000
|
||||
+22 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 29 0 0 1.11803398874927
|
||||
2 52 4 0 0 1.11803398874927
|
||||
2 53 6 0 0 1.11803398874927
|
||||
4 C1 6 0 4 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+45 0 -80 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-44 0 +83 0 +79 0 -20 0 *
|
||||
Fa
|
||||
0 1e-07 4 0
|
||||
|
||||
0101000
|
||||
+19 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 30 0 0 1.11803398874927
|
||||
2 54 6 0 0 1.11803398874927
|
||||
2 55 9 0 0 1.11803398874927
|
||||
4 C1 9 0 6 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+40 0 -73 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-39 0 +20 0 +72 0 -17 0 *
|
||||
Fa
|
||||
0 1e-07 6 0
|
||||
|
||||
0101000
|
||||
+16 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 31 0 0 1.11803398874927
|
||||
2 56 9 0 0 1.11803398874927
|
||||
2 57 12 0 0 1.11803398874927
|
||||
4 C1 12 0 9 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+35 0 -66 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-34 0 +17 0 +65 0 -14 0 *
|
||||
Fa
|
||||
0 1e-07 9 0
|
||||
|
||||
0101000
|
||||
+13 0 *
|
||||
Ed
|
||||
1e-07 1 1 0
|
||||
1 32 0 0 1.11803398874927
|
||||
2 58 12 0 0 1.11803398874927
|
||||
2 59 15 0 0 1.11803398874927
|
||||
4 G1 15 0 12 0
|
||||
0
|
||||
|
||||
0101000
|
||||
+30 0 -59 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-29 0 +14 0 +58 0 -11 0 *
|
||||
Fa
|
||||
0 1e-07 12 0
|
||||
|
||||
0101000
|
||||
+10 0 *
|
||||
Ed
|
||||
1.00005e-07 1 1 0
|
||||
1 33 0 0 1.11803398874927
|
||||
2 60 15 0 0 1.11803398874927
|
||||
0
|
||||
|
||||
0101000
|
||||
+25 0 -52 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
-24 0 +11 0 +51 0 -8 0 *
|
||||
Fa
|
||||
0 1e-07 15 0
|
||||
|
||||
0101000
|
||||
+7 0 *
|
||||
Wi
|
||||
|
||||
0101100
|
||||
+48 0 +23 0 +8 0 *
|
||||
Fa
|
||||
0 1e-07 17 0
|
||||
|
||||
0101000
|
||||
+5 0 *
|
||||
Sh
|
||||
|
||||
0101100
|
||||
-81 0 +74 0 +67 0 +60 0 +53 0 +46 0 +41 0 +36 0 +31 0 +26 0
|
||||
+21 0 +18 0 +15 0 +12 0 +9 0 +6 0 +4 0 *
|
||||
So
|
||||
|
||||
0100000
|
||||
+3 0 *
|
||||
Co
|
||||
|
||||
1100000
|
||||
+2 1 *
|
||||
|
||||
+1 0
|
||||
9
tests/src/Mod/Part/CMakeLists.txt
Normal file
9
tests/src/Mod/Part/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_link_libraries(Part_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Part
|
||||
)
|
||||
129
tests/src/Mod/PartDesign/App/BackwardCompatibility.cpp
Normal file
129
tests/src/Mod/PartDesign/App/BackwardCompatibility.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include "src/App/InitApplication.h"
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <Mod/PartDesign/App/FeatureChamfer.h>
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
class BackwardCompatibilityTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_testPath = App::Application::getHomePath() + "tests/TestModels/";
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_doc->getName());
|
||||
}
|
||||
|
||||
const App::Document* getDocument() const
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
void setDocument(App::Document* doc)
|
||||
{
|
||||
_doc = doc;
|
||||
}
|
||||
|
||||
std::string getTestPath() const
|
||||
{
|
||||
return _testPath;
|
||||
}
|
||||
|
||||
private:
|
||||
App::Document* _doc = nullptr;
|
||||
std::string _testPath;
|
||||
};
|
||||
|
||||
TEST_F(BackwardCompatibilityTest, TestOpenV021Model)
|
||||
{
|
||||
|
||||
// arrange
|
||||
|
||||
auto doc = App::GetApplication().openDocument(
|
||||
std::string(getTestPath() + "ModelFromV021.FCStd").c_str()
|
||||
);
|
||||
setDocument(doc);
|
||||
|
||||
auto chamfer = dynamic_cast<PartDesign::Chamfer*>(doc->getObject("Chamfer"));
|
||||
auto chamferEdgesNames = chamfer->Base.getSubValues();
|
||||
|
||||
std::vector<TopoDS_Shape> chamferOriginalEdges {};
|
||||
for (const auto& chamferEdgesName : chamferEdgesNames) {
|
||||
chamferOriginalEdges.push_back(
|
||||
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesName.c_str()).getShape()
|
||||
);
|
||||
}
|
||||
|
||||
// act
|
||||
|
||||
doc->recompute();
|
||||
chamfer = dynamic_cast<PartDesign::Chamfer*>(doc->getObject("Chamfer"));
|
||||
chamferEdgesNames = chamfer->Base.getSubValues();
|
||||
|
||||
// assert
|
||||
|
||||
auto checkSameVertexes = [](const TopoDS_Shape& e1, const TopoDS_Shape& e2) {
|
||||
TopExp_Explorer e1Vertexes(e1, TopAbs_VERTEX);
|
||||
TopExp_Explorer e2Vertexes(e2, TopAbs_VERTEX);
|
||||
|
||||
bool sameCoords {true};
|
||||
bool moreToCheck {e1Vertexes.More() && e2Vertexes.More()};
|
||||
|
||||
// If one of the vertexes doesn't have the same coordinates of the other one then it'll be
|
||||
// useless to continue
|
||||
while (moreToCheck && sameCoords) {
|
||||
auto p1 = BRep_Tool::Pnt(TopoDS::Vertex(e1Vertexes.Current()));
|
||||
auto p2 = BRep_Tool::Pnt(TopoDS::Vertex(e2Vertexes.Current()));
|
||||
|
||||
sameCoords &= (p1.X() == p2.X() && p1.Y() == p2.Y() && p1.Z() == p2.Z());
|
||||
e1Vertexes.Next();
|
||||
e2Vertexes.Next();
|
||||
|
||||
moreToCheck = (e1Vertexes.More() && e2Vertexes.More());
|
||||
|
||||
// Extra check: both edges should have the same number of vertexes (e*Vertexes.More()
|
||||
// should be true or false at the same time for both the edges).
|
||||
// If this doesn't happen then one of the edges won't have enough vertexes to perform a
|
||||
// full coordinates comparison.
|
||||
// This shouldn't happen, so it's here just in case
|
||||
sameCoords &= (e1Vertexes.More() == e2Vertexes.More());
|
||||
}
|
||||
|
||||
return sameCoords;
|
||||
};
|
||||
|
||||
EXPECT_TRUE(checkSameVertexes(
|
||||
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[0].c_str()).getShape(),
|
||||
chamferOriginalEdges[0]
|
||||
));
|
||||
EXPECT_TRUE(checkSameVertexes(
|
||||
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[1].c_str()).getShape(),
|
||||
chamferOriginalEdges[1]
|
||||
));
|
||||
EXPECT_TRUE(checkSameVertexes(
|
||||
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[2].c_str()).getShape(),
|
||||
chamferOriginalEdges[2]
|
||||
));
|
||||
EXPECT_TRUE(checkSameVertexes(
|
||||
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[3].c_str()).getShape(),
|
||||
chamferOriginalEdges[3]
|
||||
));
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
22
tests/src/Mod/PartDesign/App/CMakeLists.txt
Normal file
22
tests/src/Mod/PartDesign/App/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(PartDesign_tests_run
|
||||
BackwardCompatibility.cpp
|
||||
DatumPlane.cpp
|
||||
ShapeBinder.cpp
|
||||
Pad.cpp
|
||||
)
|
||||
|
||||
set(PartDesignTestData_Files
|
||||
TestModels/ModelFromV021.FCStd
|
||||
)
|
||||
|
||||
ADD_CUSTOM_TARGET(PartDesignTestData ALL
|
||||
SOURCES ${PartDesignTestData_Files}
|
||||
)
|
||||
|
||||
fc_target_copy_resource(PartDesignTestData
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR}/tests
|
||||
${PartDesignTestData_Files}
|
||||
)
|
||||
68
tests/src/Mod/PartDesign/App/DatumPlane.cpp
Normal file
68
tests/src/Mod/PartDesign/App/DatumPlane.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/Origin.h>
|
||||
#include "Mod/Part/App/Attacher.h"
|
||||
#include "Mod/PartDesign/App/Body.h"
|
||||
#include "Mod/PartDesign/App/DatumPlane.h"
|
||||
|
||||
class DatumPlaneTest: 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");
|
||||
_body = _doc->addObject<PartDesign::Body>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
App::Document* getDocument() const
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
PartDesign::Body* getBody() const
|
||||
{
|
||||
return _body;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _docName;
|
||||
App::Document* _doc = nullptr;
|
||||
PartDesign::Body* _body = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(DatumPlaneTest, attachDatumPlane)
|
||||
{
|
||||
auto datumPlane = getDocument()->addObject<PartDesign::Plane>("Plane");
|
||||
ASSERT_TRUE(datumPlane);
|
||||
getBody()->addObject(datumPlane);
|
||||
auto origin = getBody()->getOrigin();
|
||||
|
||||
App::PropertyLinkSubList support;
|
||||
std::vector<App::DocumentObject*> objs;
|
||||
std::vector<std::string> subs;
|
||||
objs.push_back(origin->getXY());
|
||||
subs.emplace_back();
|
||||
support.setValues(objs, subs);
|
||||
|
||||
auto attach = datumPlane->getExtensionByType<Part::AttachExtension>();
|
||||
attach->attacher().setReferences(support);
|
||||
Attacher::SuggestResult sugr;
|
||||
attach->attacher().suggestMapModes(sugr);
|
||||
EXPECT_EQ(sugr.message, Attacher::SuggestResult::srOK);
|
||||
}
|
||||
93
tests/src/Mod/PartDesign/App/Pad.cpp
Normal file
93
tests/src/Mod/PartDesign/App/Pad.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <Mod/Part/App/Geometry.h>
|
||||
#include <Mod/PartDesign/App/Body.h>
|
||||
#include <Mod/PartDesign/App/FeaturePad.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
class PadTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_doc = App::GetApplication().newDocument("Pad_test", "testUser");
|
||||
_body = _doc->addObject<PartDesign::Body>();
|
||||
_sketch = _doc->addObject<Sketcher::SketchObject>("Sketch");
|
||||
_body->addObject(_sketch);
|
||||
|
||||
_sketch->AttachmentSupport.setValue(_doc->getObject("XY_Plane"), "");
|
||||
_sketch->MapMode.setValue("FlatFace");
|
||||
Part::GeomCircle circle;
|
||||
circle.setRadius(10.0);
|
||||
_sketch->addGeometry(&circle, false);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_doc->getName());
|
||||
}
|
||||
|
||||
App::Document* getDocument() const
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
PartDesign::Body* getBody() const
|
||||
{
|
||||
return _body;
|
||||
}
|
||||
|
||||
Sketcher::SketchObject* getSketch() const
|
||||
{
|
||||
return _sketch;
|
||||
}
|
||||
|
||||
private:
|
||||
App::Document* _doc = nullptr;
|
||||
PartDesign::Body* _body = nullptr;
|
||||
Sketcher::SketchObject* _sketch = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(PadTest, TestMidPlaneTwoLength)
|
||||
{
|
||||
auto doc = getDocument();
|
||||
auto body = getBody();
|
||||
auto sketch = getSketch();
|
||||
|
||||
doc->recompute();
|
||||
|
||||
auto pad = doc->addObject<PartDesign::Pad>("Pad");
|
||||
body->addObject(pad);
|
||||
pad->Profile.setValue(sketch, {""});
|
||||
pad->Direction.setValue(0.0, 0.0, 1.0);
|
||||
pad->Midplane.setValue(true);
|
||||
pad->Length.setValue(10.0);
|
||||
pad->Length2.setValue(20.0);
|
||||
|
||||
pad->SideType.setValue("Two sides");
|
||||
|
||||
doc->recompute();
|
||||
|
||||
auto bbox = pad->Shape.getBoundingBox();
|
||||
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxX, 10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinX, -10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxY, 10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinY, -10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxZ, 10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinZ, -20.0);
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
81
tests/src/Mod/PartDesign/App/ShapeBinder.cpp
Normal file
81
tests/src/Mod/PartDesign/App/ShapeBinder.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include "Mod/Part/App/FeaturePartBox.h"
|
||||
#include "Mod/PartDesign/App/Body.h"
|
||||
#include "Mod/PartDesign/App/ShapeBinder.h"
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
class ShapeBinderTest: 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");
|
||||
_body = _doc->addObject<PartDesign::Body>();
|
||||
_box = _doc->addObject<Part::Box>();
|
||||
_box->Length.setValue(1);
|
||||
_box->Width.setValue(2);
|
||||
_box->Height.setValue(3);
|
||||
_box->Placement.setValue(
|
||||
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())
|
||||
); // NOLINT
|
||||
// _body->addObject(_box); // Invalid, Part::Features can't go in a PartDesign::Body,
|
||||
// but we can bind them.
|
||||
_binder = _doc->addObject<PartDesign::ShapeBinder>("ShapeBinderFoo");
|
||||
_subbinder = _doc->addObject<PartDesign::SubShapeBinder>("SubShapeBinderBar");
|
||||
_binder->Shape.setValue(_box->Shape.getShape());
|
||||
_subbinder->setLinks({{_box, {"Face1", "Face2"}}}, false);
|
||||
_body->addObject(_binder);
|
||||
_body->addObject(_subbinder);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
|
||||
App::Document* _doc = nullptr;
|
||||
std::string _docName = "";
|
||||
Part::Box* _box = nullptr;
|
||||
PartDesign::Body* _body = nullptr;
|
||||
PartDesign::ShapeBinder* _binder = nullptr;
|
||||
PartDesign::SubShapeBinder* _subbinder = nullptr;
|
||||
|
||||
// NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
};
|
||||
|
||||
TEST_F(ShapeBinderTest, shapeBinderExists)
|
||||
{
|
||||
// Arrange
|
||||
// Act
|
||||
auto binder = _doc->getObject("ShapeBinderFoo");
|
||||
// Assert the object is correct
|
||||
EXPECT_NE(binder, nullptr);
|
||||
// Assert the elementMap is correct
|
||||
}
|
||||
|
||||
TEST_F(ShapeBinderTest, subShapeBinderExists)
|
||||
{
|
||||
// Arrange
|
||||
// Act
|
||||
auto subbinder = _doc->getObject("SubShapeBinderBar");
|
||||
// Assert the object is correct
|
||||
EXPECT_NE(subbinder, nullptr);
|
||||
// Assert the elementMap is correct
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
BIN
tests/src/Mod/PartDesign/App/TestModels/ModelFromV021.FCStd
Normal file
BIN
tests/src/Mod/PartDesign/App/TestModels/ModelFromV021.FCStd
Normal file
Binary file not shown.
10
tests/src/Mod/PartDesign/CMakeLists.txt
Normal file
10
tests/src/Mod/PartDesign/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_link_libraries(PartDesign_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
PartDesign
|
||||
Sketcher
|
||||
)
|
||||
6
tests/src/Mod/Points/App/CMakeLists.txt
Normal file
6
tests/src/Mod/Points/App/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(Points_tests_run
|
||||
Points.cpp
|
||||
PointsFeature.cpp
|
||||
)
|
||||
243
tests/src/Mod/Points/App/Points.cpp
Normal file
243
tests/src/Mod/Points/App/Points.cpp
Normal file
@@ -0,0 +1,243 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Mod/Points/App/Points.h>
|
||||
#include <Mod/Points/App/PointsAlgos.h>
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-*,readability-*)
|
||||
|
||||
class PointsTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
std::vector<Base::Vector3f> points;
|
||||
points.emplace_back(0, 0, 0);
|
||||
points.emplace_back(0, 0, 1);
|
||||
points.emplace_back(0, 1, 0);
|
||||
points.emplace_back(0, 1, 1);
|
||||
points.emplace_back(1, 0, 0);
|
||||
points.emplace_back(1, 0, 1);
|
||||
points.emplace_back(1, 1, 0);
|
||||
points.emplace_back(1, 1, 1);
|
||||
kernel.setBasicPoints(points);
|
||||
|
||||
tmp.setFile(Base::FileInfo::getTempFileName());
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
tmp.deleteFile();
|
||||
}
|
||||
|
||||
const Points::PointKernel& getKernel() const
|
||||
{
|
||||
return kernel;
|
||||
}
|
||||
std::string getFileName() const
|
||||
{
|
||||
return tmp.filePath();
|
||||
}
|
||||
std::vector<float> getIntensity() const
|
||||
{
|
||||
return {0.1F, 0.2F, 0.3F, 0.4F, 0.3F, 0.2F, 0.3F, 0.1F};
|
||||
}
|
||||
std::vector<Base::Vector3f> getNormals() const
|
||||
{
|
||||
std::vector<Base::Vector3f> vec(8, Base::Vector3f(0, 0, 1));
|
||||
return vec;
|
||||
}
|
||||
std::vector<Base::Color> getColors() const
|
||||
{
|
||||
std::vector<Base::Color> col(8);
|
||||
col[0].set(0, 0, 0);
|
||||
col[1].set(0, 0, 1);
|
||||
col[2].set(0, 1, 0);
|
||||
col[3].set(0, 1, 1);
|
||||
col[4].set(1, 0, 0);
|
||||
col[5].set(1, 0, 1);
|
||||
col[6].set(1, 1, 0);
|
||||
col[7].set(1, 1, 1);
|
||||
return col;
|
||||
}
|
||||
|
||||
private:
|
||||
Points::PointKernel kernel;
|
||||
Base::FileInfo tmp;
|
||||
};
|
||||
|
||||
TEST_F(PointsTest, TestDefault)
|
||||
{
|
||||
Points::PointKernel kernel;
|
||||
std::vector<Points::PointKernel::value_type> points;
|
||||
kernel.setBasicPoints(points);
|
||||
EXPECT_EQ(kernel.size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestSize)
|
||||
{
|
||||
Points::PointKernel kernel(20);
|
||||
EXPECT_EQ(kernel.size(), 20);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestCopy)
|
||||
{
|
||||
Points::PointKernel kernel(20);
|
||||
Points::PointKernel copy(kernel); // NOLINT
|
||||
EXPECT_EQ(copy.size(), 20);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestMove)
|
||||
{
|
||||
Points::PointKernel kernel(20);
|
||||
Points::PointKernel move(std::move(kernel));
|
||||
EXPECT_EQ(move.size(), 20);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestAssign)
|
||||
{
|
||||
Points::PointKernel kernel(20);
|
||||
Points::PointKernel copy;
|
||||
copy = kernel;
|
||||
EXPECT_EQ(copy.size(), 20);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestMoveAssign)
|
||||
{
|
||||
Points::PointKernel kernel(20);
|
||||
Points::PointKernel copy;
|
||||
copy = std::move(kernel);
|
||||
EXPECT_EQ(copy.size(), 20);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestSwap)
|
||||
{
|
||||
Points::PointKernel kernel;
|
||||
std::vector<Points::PointKernel::value_type> points(20);
|
||||
kernel.swap(points);
|
||||
EXPECT_EQ(kernel.size(), 20);
|
||||
EXPECT_EQ(points.size(), 0);
|
||||
EXPECT_EQ(kernel.countValid(), 20);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestASCII)
|
||||
{
|
||||
std::string name = getFileName() + ".asc";
|
||||
Points::AscWriter writer(getKernel());
|
||||
writer.setIntensities(getIntensity());
|
||||
writer.write(name);
|
||||
|
||||
Points::AscReader reader;
|
||||
reader.read(name);
|
||||
|
||||
EXPECT_FALSE(reader.hasProperties());
|
||||
EXPECT_FALSE(reader.hasIntensities());
|
||||
EXPECT_FALSE(reader.hasColors());
|
||||
EXPECT_FALSE(reader.hasNormals());
|
||||
EXPECT_FALSE(reader.isStructured());
|
||||
EXPECT_EQ(reader.getWidth(), 8);
|
||||
EXPECT_EQ(reader.getHeight(), 1);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestPlainPLY)
|
||||
{
|
||||
std::string name = getFileName();
|
||||
Points::PlyWriter writer(getKernel());
|
||||
writer.write(name);
|
||||
|
||||
Points::PlyReader reader;
|
||||
reader.read(name);
|
||||
|
||||
EXPECT_FALSE(reader.hasProperties());
|
||||
EXPECT_FALSE(reader.hasIntensities());
|
||||
EXPECT_FALSE(reader.hasColors());
|
||||
EXPECT_FALSE(reader.hasNormals());
|
||||
EXPECT_FALSE(reader.isStructured());
|
||||
EXPECT_EQ(reader.getWidth(), 8);
|
||||
EXPECT_EQ(reader.getHeight(), 1);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestPLYWithProperties)
|
||||
{
|
||||
std::string name = getFileName();
|
||||
Points::PlyWriter writer(getKernel());
|
||||
writer.setIntensities(getIntensity());
|
||||
writer.setColors(getColors());
|
||||
writer.setNormals(getNormals());
|
||||
writer.write(name);
|
||||
|
||||
Points::PlyReader reader;
|
||||
reader.read(name);
|
||||
|
||||
EXPECT_TRUE(reader.hasProperties());
|
||||
EXPECT_TRUE(reader.hasIntensities());
|
||||
EXPECT_TRUE(reader.hasColors());
|
||||
EXPECT_TRUE(reader.hasNormals());
|
||||
EXPECT_FALSE(reader.isStructured());
|
||||
EXPECT_EQ(reader.getWidth(), 8);
|
||||
EXPECT_EQ(reader.getHeight(), 1);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestPlainPCD)
|
||||
{
|
||||
std::string name = getFileName();
|
||||
Points::PcdWriter writer(getKernel());
|
||||
writer.write(name);
|
||||
|
||||
Points::PcdReader reader;
|
||||
reader.read(name);
|
||||
|
||||
EXPECT_FALSE(reader.hasProperties());
|
||||
EXPECT_FALSE(reader.hasIntensities());
|
||||
EXPECT_FALSE(reader.hasColors());
|
||||
EXPECT_FALSE(reader.hasNormals());
|
||||
EXPECT_FALSE(reader.isStructured());
|
||||
EXPECT_EQ(reader.getWidth(), 8);
|
||||
EXPECT_EQ(reader.getHeight(), 1);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestPCDWithProperties)
|
||||
{
|
||||
std::string name = getFileName();
|
||||
Points::PcdWriter writer(getKernel());
|
||||
writer.setIntensities(getIntensity());
|
||||
writer.setColors(getColors());
|
||||
writer.setNormals(getNormals());
|
||||
writer.write(name);
|
||||
|
||||
Points::PcdReader reader;
|
||||
reader.read(name);
|
||||
|
||||
EXPECT_TRUE(reader.hasProperties());
|
||||
EXPECT_TRUE(reader.hasIntensities());
|
||||
EXPECT_TRUE(reader.hasColors());
|
||||
EXPECT_TRUE(reader.hasNormals());
|
||||
EXPECT_FALSE(reader.isStructured());
|
||||
EXPECT_EQ(reader.getWidth(), 8);
|
||||
EXPECT_EQ(reader.getHeight(), 1);
|
||||
}
|
||||
|
||||
TEST_F(PointsTest, TestPCDStructured)
|
||||
{
|
||||
std::string name = getFileName();
|
||||
Points::PcdWriter writer(getKernel());
|
||||
writer.setIntensities(getIntensity());
|
||||
writer.setColors(getColors());
|
||||
writer.setNormals(getNormals());
|
||||
writer.setWidth(4);
|
||||
writer.setHeight(2);
|
||||
writer.write(name);
|
||||
|
||||
Points::PcdReader reader;
|
||||
reader.read(name);
|
||||
|
||||
EXPECT_TRUE(reader.hasProperties());
|
||||
EXPECT_TRUE(reader.hasIntensities());
|
||||
EXPECT_TRUE(reader.hasColors());
|
||||
EXPECT_TRUE(reader.hasNormals());
|
||||
EXPECT_TRUE(reader.isStructured());
|
||||
EXPECT_EQ(reader.getWidth(), 4);
|
||||
EXPECT_EQ(reader.getHeight(), 2);
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-*,readability-*)
|
||||
38
tests/src/Mod/Points/App/PointsFeature.cpp
Normal file
38
tests/src/Mod/Points/App/PointsFeature.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <Mod/Points/App/PointsFeature.h>
|
||||
|
||||
class PointsFeatureTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
};
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-*,readability-*)
|
||||
TEST_F(PointsFeatureTest, getElementTypes)
|
||||
{
|
||||
Points::Feature pf;
|
||||
std::vector<const char*> types = pf.getElementTypes();
|
||||
|
||||
EXPECT_EQ(types.size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(PointsFeatureTest, getComplexElementTypes)
|
||||
{
|
||||
Points::PointKernel pk;
|
||||
std::vector<const char*> types = pk.getElementTypes();
|
||||
|
||||
EXPECT_EQ(types.size(), 0);
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-*,readability-*)
|
||||
9
tests/src/Mod/Points/CMakeLists.txt
Normal file
9
tests/src/Mod/Points/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_link_libraries(Points_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Points
|
||||
)
|
||||
10
tests/src/Mod/Sketcher/App/CMakeLists.txt
Normal file
10
tests/src/Mod/Sketcher/App/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(Sketcher_tests_run
|
||||
Constraint.cpp
|
||||
SketcherTestHelpers.cpp
|
||||
SketchObject.cpp
|
||||
SketchObjectChanges.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(planegcs)
|
||||
587
tests/src/Mod/Sketcher/App/Constraint.cpp
Normal file
587
tests/src/Mod/Sketcher/App/Constraint.cpp
Normal file
@@ -0,0 +1,587 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <FCConfig.h>
|
||||
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Writer.h>
|
||||
#include <Mod/Sketcher/App/Constraint.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#include <src/App/InitApplication.h>
|
||||
|
||||
|
||||
// Ensure Xerces is initialized before running tests which uses xml
|
||||
class XercesEnvironment: public ::testing::Environment
|
||||
{
|
||||
public:
|
||||
void SetUp() override
|
||||
{
|
||||
try {
|
||||
xercesc::XMLPlatformUtils::Initialize();
|
||||
}
|
||||
catch (const xercesc::XMLException& e) {
|
||||
FAIL() << "Xerces init failed: " << xercesc::XMLString::transcode(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
xercesc::XMLPlatformUtils::Terminate();
|
||||
}
|
||||
};
|
||||
|
||||
::testing::Environment* const xercesEnv = ::testing::AddGlobalTestEnvironment(new XercesEnvironment);
|
||||
|
||||
class ConstraintPointsAccess: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testDefaultGeoElementIdsAreSane) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
auto constraint = Sketcher::Constraint();
|
||||
|
||||
// Act - no action needed, we are testing the default state
|
||||
|
||||
// Assert
|
||||
#if SKETCHER_CONSTRAINT_USE_LEGACY_ELEMENTS
|
||||
// Old way of accessing elements
|
||||
EXPECT_EQ(constraint.First, Sketcher::GeoEnum::GeoUndef);
|
||||
EXPECT_EQ(constraint.FirstPos, Sketcher::PointPos::none);
|
||||
|
||||
EXPECT_EQ(constraint.Second, Sketcher::GeoEnum::GeoUndef);
|
||||
EXPECT_EQ(constraint.SecondPos, Sketcher::PointPos::none);
|
||||
|
||||
EXPECT_EQ(constraint.Third, Sketcher::GeoEnum::GeoUndef);
|
||||
EXPECT_EQ(constraint.ThirdPos, Sketcher::PointPos::none);
|
||||
|
||||
// New way of accessing elements
|
||||
#endif
|
||||
EXPECT_EQ(
|
||||
constraint.getElement(0),
|
||||
Sketcher::GeoElementId(Sketcher::GeoEnum::GeoUndef, Sketcher::PointPos::none)
|
||||
);
|
||||
EXPECT_EQ(
|
||||
constraint.getElement(1),
|
||||
Sketcher::GeoElementId(Sketcher::GeoEnum::GeoUndef, Sketcher::PointPos::none)
|
||||
);
|
||||
EXPECT_EQ(
|
||||
constraint.getElement(2),
|
||||
Sketcher::GeoElementId(Sketcher::GeoEnum::GeoUndef, Sketcher::PointPos::none)
|
||||
);
|
||||
}
|
||||
|
||||
#if SKETCHER_CONSTRAINT_USE_LEGACY_ELEMENTS
|
||||
TEST_F(ConstraintPointsAccess, testOldWriteIsReadByNew) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
auto constraint = Sketcher::Constraint();
|
||||
|
||||
// Act
|
||||
constraint.First = 23;
|
||||
constraint.FirstPos = Sketcher::PointPos::start;
|
||||
constraint.Second = 34;
|
||||
constraint.SecondPos = Sketcher::PointPos::end;
|
||||
constraint.Third = 45;
|
||||
constraint.ThirdPos = Sketcher::PointPos::mid;
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(
|
||||
constraint.getElement(0),
|
||||
Sketcher::GeoElementId(Sketcher::GeoElementId(23, Sketcher::PointPos::start))
|
||||
);
|
||||
EXPECT_EQ(
|
||||
constraint.getElement(1),
|
||||
Sketcher::GeoElementId(Sketcher::GeoElementId(34, Sketcher::PointPos::end))
|
||||
);
|
||||
EXPECT_EQ(
|
||||
constraint.getElement(2),
|
||||
Sketcher::GeoElementId(Sketcher::GeoElementId(45, Sketcher::PointPos::mid))
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testNewWriteIsReadByOld) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
auto constraint = Sketcher::Constraint();
|
||||
|
||||
// Act
|
||||
constraint.setElement(0, Sketcher::GeoElementId(23, Sketcher::PointPos::start));
|
||||
constraint.setElement(1, Sketcher::GeoElementId(34, Sketcher::PointPos::end));
|
||||
constraint.setElement(2, Sketcher::GeoElementId(45, Sketcher::PointPos::mid));
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(constraint.First, 23);
|
||||
EXPECT_EQ(constraint.FirstPos, Sketcher::PointPos::start);
|
||||
EXPECT_EQ(constraint.Second, 34);
|
||||
EXPECT_EQ(constraint.SecondPos, Sketcher::PointPos::end);
|
||||
EXPECT_EQ(constraint.Third, 45);
|
||||
EXPECT_EQ(constraint.ThirdPos, Sketcher::PointPos::mid);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testThreeElementsByDefault) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
auto constraint = Sketcher::Constraint();
|
||||
|
||||
// Act - no action needed, we are testing the default state
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(constraint.getElementsSize(), 3);
|
||||
}
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testFourElementsWhenAddingOne) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
auto constraint = Sketcher::Constraint();
|
||||
|
||||
// Act
|
||||
constraint.addElement(Sketcher::GeoElementId(1, Sketcher::PointPos::start));
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(constraint.getElementsSize(), 4);
|
||||
}
|
||||
|
||||
#if SKETCHER_CONSTRAINT_USE_LEGACY_ELEMENTS
|
||||
TEST_F(ConstraintPointsAccess, testElementSerializationWhenAccessingOldWay) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
auto constraint = Sketcher::Constraint();
|
||||
|
||||
// Act
|
||||
constraint.First = 23;
|
||||
constraint.FirstPos = Sketcher::PointPos::start;
|
||||
constraint.Second = 34;
|
||||
constraint.SecondPos = Sketcher::PointPos::end;
|
||||
constraint.Third = 45;
|
||||
constraint.ThirdPos = Sketcher::PointPos::mid;
|
||||
|
||||
Base::StringWriter writer = {};
|
||||
constraint.Save(writer);
|
||||
|
||||
// Assert
|
||||
std::string serialized = writer.getString();
|
||||
EXPECT_TRUE(serialized.find("First=\"23\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("FirstPos=\"1\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("Second=\"34\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("SecondPos=\"2\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("Third=\"45\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("ThirdPos=\"3\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("ElementIds=\"23 34 45\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("ElementPositions=\"1 2 3\"") != std::string::npos);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testElementSerializationWhenAccessingNewWay) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
auto constraint = Sketcher::Constraint();
|
||||
|
||||
// Act
|
||||
constraint.setElement(0, Sketcher::GeoElementId(23, Sketcher::PointPos::start));
|
||||
constraint.setElement(1, Sketcher::GeoElementId(34, Sketcher::PointPos::end));
|
||||
constraint.setElement(2, Sketcher::GeoElementId(45, Sketcher::PointPos::mid));
|
||||
|
||||
Base::StringWriter writer = {};
|
||||
constraint.Save(writer);
|
||||
|
||||
// Assert
|
||||
std::string serialized = writer.getString();
|
||||
EXPECT_TRUE(serialized.find("First=\"23\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("FirstPos=\"1\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("Second=\"34\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("SecondPos=\"2\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("Third=\"45\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("ThirdPos=\"3\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("ElementIds=\"23 34 45\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("ElementPositions=\"1 2 3\"") != std::string::npos);
|
||||
}
|
||||
|
||||
#if SKETCHER_CONSTRAINT_USE_LEGACY_ELEMENTS
|
||||
TEST_F(ConstraintPointsAccess, testElementSerializationWhenMixingOldAndNew) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
auto constraint = Sketcher::Constraint();
|
||||
|
||||
// Act
|
||||
constraint.setElement(0, Sketcher::GeoElementId(23, Sketcher::PointPos::start));
|
||||
constraint.setElement(1, Sketcher::GeoElementId(34, Sketcher::PointPos::end));
|
||||
constraint.Second = 45; // Old way
|
||||
constraint.SecondPos = Sketcher::PointPos::mid;
|
||||
|
||||
Base::StringWriter writer = {};
|
||||
constraint.Save(writer);
|
||||
|
||||
// Assert
|
||||
std::string serialized = writer.getString();
|
||||
EXPECT_TRUE(serialized.find("First=\"23\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("FirstPos=\"1\"") != std::string::npos);
|
||||
|
||||
// Old way wrote this data
|
||||
// ensure mid is 3 for next test
|
||||
EXPECT_EQ(Sketcher::PointPos::mid, static_cast<Sketcher::PointPos>(3));
|
||||
EXPECT_TRUE(serialized.find("SecondPos=\"3\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("Second=\"45\"") != std::string::npos);
|
||||
|
||||
EXPECT_TRUE(serialized.find("Third=\"-2000\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("ThirdPos=\"0\"") != std::string::npos);
|
||||
|
||||
// Second and SecondPos is reflected in the elements data too
|
||||
EXPECT_TRUE(serialized.find("ElementIds=\"23 45 -2000\"") != std::string::npos);
|
||||
EXPECT_TRUE(serialized.find("ElementPositions=\"1 3 0\"") != std::string::npos);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testElementsRestoredFromSerialization) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
Sketcher::Constraint constraint;
|
||||
constraint.setElement(0, Sketcher::GeoElementId(23, Sketcher::PointPos::start));
|
||||
constraint.setElement(1, Sketcher::GeoElementId(34, Sketcher::PointPos::end));
|
||||
constraint.setElement(2, Sketcher::GeoElementId(45, Sketcher::PointPos::mid));
|
||||
|
||||
Base::StringWriter writer;
|
||||
writer.Stream() << "<root>\n"; // Wrap in a root element to make constraint.Save happy
|
||||
constraint.Save(writer);
|
||||
writer.Stream() << "</root>";
|
||||
|
||||
// Write to temporary file
|
||||
QTemporaryFile tempFile;
|
||||
tempFile.setAutoRemove(true);
|
||||
ASSERT_TRUE(tempFile.open());
|
||||
tempFile.write(writer.getString().c_str(), writer.getString().size());
|
||||
tempFile.flush();
|
||||
|
||||
// Open with std::ifstream and parse
|
||||
std::string filename = tempFile.fileName().toStdString();
|
||||
std::ifstream inputFile(filename);
|
||||
ASSERT_TRUE(inputFile.is_open());
|
||||
|
||||
Base::XMLReader reader(tempFile.fileName().toStdString().c_str(), inputFile);
|
||||
Sketcher::Constraint restoredConstraint;
|
||||
restoredConstraint.Restore(reader);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(restoredConstraint.getElement(0), Sketcher::GeoElementId(23, Sketcher::PointPos::start));
|
||||
EXPECT_EQ(restoredConstraint.getElement(1), Sketcher::GeoElementId(34, Sketcher::PointPos::end));
|
||||
EXPECT_EQ(restoredConstraint.getElement(2), Sketcher::GeoElementId(45, Sketcher::PointPos::mid));
|
||||
|
||||
inputFile.close();
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
ConstraintPointsAccess,
|
||||
testElementsRestoredFromSerializationWithoutNewElementStorage
|
||||
) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Manually craft a serialized version, only parts in "{}" are important.
|
||||
// New way of storing elements is not present, like if it is an older file.
|
||||
std::string serializedConstraint = fmt::format(
|
||||
"<Constrain "
|
||||
R"(Name="" )"
|
||||
R"(Type="0" )"
|
||||
R"(Value="0" )"
|
||||
R"(LabelDistance="10" )"
|
||||
R"(LabelPosition="0" )"
|
||||
R"(IsDriving="1" )"
|
||||
R"(IsInVirtualSpace="0" )"
|
||||
R"(IsActive="1" )"
|
||||
|
||||
R"(First="{}" )"
|
||||
R"(Second="{}" )"
|
||||
R"(Third="{}" )"
|
||||
R"(FirstPos="{}" )"
|
||||
R"(SecondPos="{}" )"
|
||||
R"(ThirdPos="{}" )"
|
||||
|
||||
"/>",
|
||||
|
||||
67,
|
||||
78,
|
||||
89,
|
||||
static_cast<int>(Sketcher::PointPos::mid),
|
||||
static_cast<int>(Sketcher::PointPos::start),
|
||||
static_cast<int>(Sketcher::PointPos::end)
|
||||
);
|
||||
|
||||
Base::StringWriter writer;
|
||||
auto& stream {writer.Stream()};
|
||||
stream << "<root>\n"; // Wrap in a root element to make constraint.
|
||||
stream << serializedConstraint;
|
||||
stream << "</root>";
|
||||
|
||||
// Write to temporary file
|
||||
QTemporaryFile tempFile;
|
||||
tempFile.setAutoRemove(true);
|
||||
ASSERT_TRUE(tempFile.open());
|
||||
tempFile.write(writer.getString().c_str(), writer.getString().size());
|
||||
tempFile.flush();
|
||||
|
||||
// Open with std::ifstream and parse
|
||||
std::string filename = tempFile.fileName().toStdString();
|
||||
std::ifstream inputFile(filename);
|
||||
ASSERT_TRUE(inputFile.is_open());
|
||||
|
||||
Base::XMLReader reader(tempFile.fileName().toStdString().c_str(), inputFile);
|
||||
Sketcher::Constraint restoredConstraint;
|
||||
restoredConstraint.Restore(reader);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(restoredConstraint.getElement(0), Sketcher::GeoElementId(67, Sketcher::PointPos::mid));
|
||||
EXPECT_EQ(restoredConstraint.getElement(1), Sketcher::GeoElementId(78, Sketcher::PointPos::start));
|
||||
EXPECT_EQ(restoredConstraint.getElement(2), Sketcher::GeoElementId(89, Sketcher::PointPos::end));
|
||||
|
||||
inputFile.close();
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
ConstraintPointsAccess,
|
||||
testLegacyIsPreferedDuringSerializationWithoutLegacyElementStorage
|
||||
) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Manually craft a serialized version, only parts in "{}" are important.
|
||||
// Only new way of storing elements is present.
|
||||
std::string serializedConstraint = fmt::format(
|
||||
"<Constrain "
|
||||
R"(Name="" )"
|
||||
R"(Type="0" )"
|
||||
R"(Value="0" )"
|
||||
R"(LabelDistance="10" )"
|
||||
R"(LabelPosition="0" )"
|
||||
R"(IsDriving="1" )"
|
||||
R"(IsInVirtualSpace="0" )"
|
||||
R"(IsActive="1" )"
|
||||
|
||||
// New way
|
||||
R"(ElementIds="{} {} {}" )"
|
||||
R"(ElementPositions="{} {} {}" )"
|
||||
|
||||
"/>",
|
||||
// New way data
|
||||
23,
|
||||
34,
|
||||
45,
|
||||
static_cast<int>(Sketcher::PointPos::start),
|
||||
static_cast<int>(Sketcher::PointPos::end),
|
||||
static_cast<int>(Sketcher::PointPos::mid)
|
||||
);
|
||||
|
||||
Base::StringWriter writer;
|
||||
auto& stream {writer.Stream()};
|
||||
stream << "<root>\n"; // Wrap in a root element to make constraint.
|
||||
stream << serializedConstraint;
|
||||
stream << "</root>";
|
||||
|
||||
// Write to temporary file
|
||||
QTemporaryFile tempFile;
|
||||
tempFile.setAutoRemove(true);
|
||||
ASSERT_TRUE(tempFile.open());
|
||||
tempFile.write(writer.getString().c_str(), writer.getString().size());
|
||||
tempFile.flush();
|
||||
|
||||
// Open with std::ifstream and parse
|
||||
std::string filename = tempFile.fileName().toStdString();
|
||||
std::ifstream inputFile(filename);
|
||||
ASSERT_TRUE(inputFile.is_open());
|
||||
|
||||
Base::XMLReader reader(tempFile.fileName().toStdString().c_str(), inputFile);
|
||||
Sketcher::Constraint restoredConstraint;
|
||||
restoredConstraint.Restore(reader);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(restoredConstraint.getElement(0), Sketcher::GeoElementId(23, Sketcher::PointPos::start));
|
||||
EXPECT_EQ(restoredConstraint.getElement(1), Sketcher::GeoElementId(34, Sketcher::PointPos::end));
|
||||
EXPECT_EQ(restoredConstraint.getElement(2), Sketcher::GeoElementId(45, Sketcher::PointPos::mid));
|
||||
|
||||
inputFile.close();
|
||||
}
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testLegacyIsPreferedDuringSerializationIfContradicting) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Manually craft a serialized version, only parts in "{}" are important.
|
||||
// It is not important if legacy is included before or after, legacy should always be preferred.
|
||||
std::string serializedConstraint = fmt::format(
|
||||
"<Constrain "
|
||||
R"(Name="" )"
|
||||
R"(Type="0" )"
|
||||
R"(Value="0" )"
|
||||
R"(LabelDistance="10" )"
|
||||
R"(LabelPosition="0" )"
|
||||
R"(IsDriving="1" )"
|
||||
R"(IsInVirtualSpace="0" )"
|
||||
R"(IsActive="1" )"
|
||||
|
||||
// New way
|
||||
R"(ElementIds="{} {} {}" )"
|
||||
R"(ElementPositions="{} {} {}" )"
|
||||
|
||||
// Legacy
|
||||
R"(First="{}" )"
|
||||
R"(Second="{}" )"
|
||||
R"(Third="{}" )"
|
||||
R"(FirstPos="{}" )"
|
||||
R"(SecondPos="{}" )"
|
||||
R"(ThirdPos="{}" )"
|
||||
|
||||
"/>",
|
||||
// New way data
|
||||
23,
|
||||
34,
|
||||
45,
|
||||
static_cast<int>(Sketcher::PointPos::start),
|
||||
static_cast<int>(Sketcher::PointPos::end),
|
||||
static_cast<int>(Sketcher::PointPos::mid),
|
||||
|
||||
// Contradicting legacy data, this should be preferred if available
|
||||
67,
|
||||
78,
|
||||
89,
|
||||
static_cast<int>(Sketcher::PointPos::mid),
|
||||
static_cast<int>(Sketcher::PointPos::start),
|
||||
static_cast<int>(Sketcher::PointPos::end)
|
||||
);
|
||||
|
||||
Base::StringWriter writer;
|
||||
auto& stream {writer.Stream()};
|
||||
stream << "<root>\n"; // Wrap in a root element to make constraint.
|
||||
stream << serializedConstraint;
|
||||
stream << "</root>";
|
||||
|
||||
// Write to temporary file
|
||||
QTemporaryFile tempFile;
|
||||
tempFile.setAutoRemove(true);
|
||||
ASSERT_TRUE(tempFile.open());
|
||||
tempFile.write(writer.getString().c_str(), writer.getString().size());
|
||||
tempFile.flush();
|
||||
|
||||
// Open with std::ifstream and parse
|
||||
std::string filename = tempFile.fileName().toStdString();
|
||||
std::ifstream inputFile(filename);
|
||||
ASSERT_TRUE(inputFile.is_open());
|
||||
|
||||
Base::XMLReader reader(tempFile.fileName().toStdString().c_str(), inputFile);
|
||||
Sketcher::Constraint restoredConstraint;
|
||||
restoredConstraint.Restore(reader);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(restoredConstraint.getElement(0), Sketcher::GeoElementId(67, Sketcher::PointPos::mid));
|
||||
EXPECT_EQ(restoredConstraint.getElement(1), Sketcher::GeoElementId(78, Sketcher::PointPos::start));
|
||||
EXPECT_EQ(restoredConstraint.getElement(2), Sketcher::GeoElementId(89, Sketcher::PointPos::end));
|
||||
|
||||
inputFile.close();
|
||||
}
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testSubstituteIndex) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
Sketcher::Constraint constraint;
|
||||
constraint.setElement(0, Sketcher::GeoElementId(10, Sketcher::PointPos::start));
|
||||
constraint.setElement(1, Sketcher::GeoElementId(20, Sketcher::PointPos::end));
|
||||
constraint.setElement(2, Sketcher::GeoElementId(10, Sketcher::PointPos::mid)); // same GeoId as 0
|
||||
|
||||
// Act
|
||||
constraint.substituteIndex(10, 99);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(constraint.getElement(0), Sketcher::GeoElementId(99, Sketcher::PointPos::start));
|
||||
EXPECT_EQ(constraint.getElement(1), Sketcher::GeoElementId(20, Sketcher::PointPos::end));
|
||||
EXPECT_EQ(constraint.getElement(2), Sketcher::GeoElementId(99, Sketcher::PointPos::mid));
|
||||
}
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testSubstituteIndexAndPos) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
Sketcher::Constraint constraint;
|
||||
constraint.setElement(0, Sketcher::GeoElementId(10, Sketcher::PointPos::start));
|
||||
constraint.setElement(1, Sketcher::GeoElementId(20, Sketcher::PointPos::start));
|
||||
constraint.setElement(2, Sketcher::GeoElementId(10, Sketcher::PointPos::mid));
|
||||
|
||||
// Act
|
||||
constraint.substituteIndexAndPos(10, Sketcher::PointPos::start, 42, Sketcher::PointPos::end);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(constraint.getElement(0), Sketcher::GeoElementId(42, Sketcher::PointPos::end));
|
||||
EXPECT_EQ(constraint.getElement(1), Sketcher::GeoElementId(20, Sketcher::PointPos::start));
|
||||
EXPECT_EQ(constraint.getElement(2), Sketcher::GeoElementId(10, Sketcher::PointPos::mid)); // unchanged
|
||||
}
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testInvolvesGeoId) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
Sketcher::Constraint constraint;
|
||||
constraint.setElement(0, Sketcher::GeoElementId(10, Sketcher::PointPos::start));
|
||||
constraint.setElement(1, Sketcher::GeoElementId(20, Sketcher::PointPos::end));
|
||||
|
||||
// Act & Assert
|
||||
EXPECT_TRUE(constraint.involvesGeoId(10));
|
||||
EXPECT_TRUE(constraint.involvesGeoId(20));
|
||||
EXPECT_FALSE(constraint.involvesGeoId(99));
|
||||
}
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testInvolvesGeoIdAndPosId) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
Sketcher::Constraint constraint;
|
||||
constraint.setElement(0, Sketcher::GeoElementId(10, Sketcher::PointPos::start));
|
||||
constraint.setElement(1, Sketcher::GeoElementId(20, Sketcher::PointPos::mid));
|
||||
constraint.setElement(2, Sketcher::GeoElementId(30, Sketcher::PointPos::end));
|
||||
|
||||
// Act & Assert
|
||||
EXPECT_TRUE(constraint.involvesGeoIdAndPosId(10, Sketcher::PointPos::start));
|
||||
EXPECT_TRUE(constraint.involvesGeoIdAndPosId(20, Sketcher::PointPos::mid));
|
||||
EXPECT_FALSE(constraint.involvesGeoIdAndPosId(20, Sketcher::PointPos::start));
|
||||
EXPECT_FALSE(constraint.involvesGeoIdAndPosId(99, Sketcher::PointPos::end));
|
||||
}
|
||||
|
||||
#if SKETCHER_CONSTRAINT_USE_LEGACY_ELEMENTS
|
||||
TEST_F(ConstraintPointsAccess, testLegacyWriteReflectedInInvolvesAndSubstitute) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
Sketcher::Constraint constraint;
|
||||
constraint.First = 10;
|
||||
constraint.FirstPos = Sketcher::PointPos::start;
|
||||
constraint.Second = 20;
|
||||
constraint.SecondPos = Sketcher::PointPos::end;
|
||||
|
||||
// Act & Assert
|
||||
EXPECT_TRUE(constraint.involvesGeoId(10));
|
||||
EXPECT_TRUE(constraint.involvesGeoIdAndPosId(20, Sketcher::PointPos::end));
|
||||
|
||||
// Substitute the legacy-indexed element
|
||||
constraint.substituteIndex(10, 99);
|
||||
|
||||
// Should now reflect the substituted value
|
||||
EXPECT_TRUE(constraint.involvesGeoId(99));
|
||||
EXPECT_FALSE(constraint.involvesGeoId(10));
|
||||
}
|
||||
|
||||
TEST_F(ConstraintPointsAccess, testSubstituteUpdatesLegacyFieldsToo) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
Sketcher::Constraint constraint;
|
||||
constraint.setElement(0, Sketcher::GeoElementId(10, Sketcher::PointPos::start));
|
||||
|
||||
// Act
|
||||
constraint.substituteIndex(10, 42);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(constraint.getElement(0), Sketcher::GeoElementId(42, Sketcher::PointPos::start));
|
||||
EXPECT_EQ(constraint.First, 42);
|
||||
EXPECT_EQ(constraint.FirstPos, Sketcher::PointPos::start);
|
||||
}
|
||||
#endif
|
||||
858
tests/src/Mod/Sketcher/App/SketchObject.cpp
Normal file
858
tests/src/Mod/Sketcher/App/SketchObject.cpp
Normal file
@@ -0,0 +1,858 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <FCConfig.h>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/Expression.h>
|
||||
#include <App/ObjectIdentifier.h>
|
||||
#include <Mod/Sketcher/App/GeoEnum.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
#include "SketcherTestHelpers.h"
|
||||
|
||||
using namespace SketcherTestHelpers;
|
||||
|
||||
|
||||
TEST_F(SketchObjectTest, createSketchObject) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
|
||||
// Assert
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGeoIdFromShapeTypeEdge)
|
||||
{
|
||||
// Arrange
|
||||
// TODO: Do we need to separate existing vs non-existing?
|
||||
// It would need to be implemented in code as well.
|
||||
Data::IndexedName name("Edge", 1);
|
||||
int geoId;
|
||||
Sketcher::PointPos posId;
|
||||
|
||||
// Act
|
||||
getObject()->geoIdFromShapeType(name, geoId, posId);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(geoId, 0);
|
||||
EXPECT_EQ(posId, Sketcher::PointPos::none);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGeoIdFromShapeTypeVertex)
|
||||
{
|
||||
// Arrange
|
||||
// For operating on vertices, there is newName a check if the vertex exists.
|
||||
Base::Vector3d p1(0.0, 0.0, 0.0), p2(1.0, 0.0, 0.0);
|
||||
std::unique_ptr<Part::Geometry> geoline(new Part::GeomLineSegment());
|
||||
static_cast<Part::GeomLineSegment*>(geoline.get())->setPoints(p1, p2);
|
||||
getObject()->addGeometry(geoline.get());
|
||||
// TODO: Do we need to separate existing vs non-existing?
|
||||
// It would need to be implemented in code as well.
|
||||
Data::IndexedName name("Vertex", 1);
|
||||
int geoId;
|
||||
Sketcher::PointPos posId;
|
||||
|
||||
// Act
|
||||
getObject()->geoIdFromShapeType(name, geoId, posId);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(geoId, 0);
|
||||
EXPECT_EQ(posId, Sketcher::PointPos::start);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGeoIdFromShapeTypeExternalEdge)
|
||||
{
|
||||
// Arrange
|
||||
// TODO: Do we need to separate existing vs non-existing?
|
||||
// It would need to be implemented in code as well.
|
||||
Data::IndexedName name("ExternalEdge", 1);
|
||||
int geoId;
|
||||
Sketcher::PointPos posId;
|
||||
|
||||
// Act
|
||||
getObject()->geoIdFromShapeType(name, geoId, posId);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(geoId, Sketcher::GeoEnum::RefExt);
|
||||
EXPECT_EQ(posId, Sketcher::PointPos::none);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGeoIdFromShapeTypeHAxis)
|
||||
{
|
||||
// Arrange
|
||||
Data::IndexedName name("H_Axis");
|
||||
int geoId;
|
||||
Sketcher::PointPos posId;
|
||||
|
||||
// Act
|
||||
getObject()->geoIdFromShapeType(name, geoId, posId);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(geoId, Sketcher::GeoEnum::HAxis);
|
||||
EXPECT_EQ(posId, Sketcher::PointPos::none);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGeoIdFromShapeTypeVAxis)
|
||||
{
|
||||
// Arrange
|
||||
Data::IndexedName name("V_Axis");
|
||||
int geoId;
|
||||
Sketcher::PointPos posId;
|
||||
|
||||
// Act
|
||||
getObject()->geoIdFromShapeType(name, geoId, posId);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(geoId, Sketcher::GeoEnum::VAxis);
|
||||
EXPECT_EQ(posId, Sketcher::PointPos::none);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGeoIdFromShapeTypeRootPoint)
|
||||
{
|
||||
// Arrange
|
||||
Data::IndexedName name("RootPoint");
|
||||
int geoId;
|
||||
Sketcher::PointPos posId;
|
||||
|
||||
// Act
|
||||
getObject()->geoIdFromShapeType(name, geoId, posId);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(geoId, Sketcher::GeoEnum::RtPnt);
|
||||
EXPECT_EQ(posId, Sketcher::PointPos::start);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetPointFromGeomPoint)
|
||||
{
|
||||
// Arrange
|
||||
Base::Vector3d coords(1.0, 2.0, 0.0);
|
||||
Part::GeomPoint point(coords);
|
||||
|
||||
// Act
|
||||
auto ptStart = Sketcher::SketchObject::getPoint(&point, Sketcher::PointPos::start);
|
||||
auto ptMid = Sketcher::SketchObject::getPoint(&point, Sketcher::PointPos::mid);
|
||||
auto ptEnd = Sketcher::SketchObject::getPoint(&point, Sketcher::PointPos::end);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptNone = Sketcher::SketchObject::getPoint(&point, Sketcher::PointPos::none);
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(ptStart[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(ptStart[1], 2.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[1], 2.0);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[1], 2.0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetPointFromGeomLineSegment)
|
||||
{
|
||||
// Arrange
|
||||
Base::Vector3d coords1(1.0, 2.0, 0.0);
|
||||
Base::Vector3d coords2(3.0, 4.0, 0.0);
|
||||
Part::GeomLineSegment lineSeg;
|
||||
lineSeg.setPoints(coords1, coords2);
|
||||
|
||||
// Act
|
||||
auto ptStart = Sketcher::SketchObject::getPoint(&lineSeg, Sketcher::PointPos::start);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptMid = Sketcher::SketchObject::getPoint(&lineSeg, Sketcher::PointPos::mid);
|
||||
auto ptEnd = Sketcher::SketchObject::getPoint(&lineSeg, Sketcher::PointPos::end);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptNone = Sketcher::SketchObject::getPoint(&lineSeg, Sketcher::PointPos::none);
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(ptStart[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(ptStart[1], 2.0);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[0], 3.0);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[1], 4.0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetPointFromGeomCircle)
|
||||
{
|
||||
// Arrange
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double radius = 3.0;
|
||||
Part::GeomCircle circle;
|
||||
circle.setCenter(coordsCenter);
|
||||
circle.setRadius(radius);
|
||||
|
||||
// Act
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
auto ptStart = Sketcher::SketchObject::getPoint(&circle, Sketcher::PointPos::start);
|
||||
auto ptMid = Sketcher::SketchObject::getPoint(&circle, Sketcher::PointPos::mid);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
auto ptEnd = Sketcher::SketchObject::getPoint(&circle, Sketcher::PointPos::end);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptNone = Sketcher::SketchObject::getPoint(&circle, Sketcher::PointPos::none);
|
||||
|
||||
// Assert
|
||||
// NOTE: Presently, start/end points of a circle are defined as the point on circle right of the
|
||||
// the center
|
||||
EXPECT_DOUBLE_EQ(ptStart[0], 1.0 + radius);
|
||||
EXPECT_DOUBLE_EQ(ptStart[1], 2.0);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[0], 1.0 + radius);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[1], 2.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[1], 2.0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetPointFromGeomEllipse)
|
||||
{
|
||||
// Arrange
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double majorRadius = 4.0;
|
||||
double minorRadius = 3.0;
|
||||
Part::GeomEllipse ellipse;
|
||||
ellipse.setCenter(coordsCenter);
|
||||
ellipse.setMajorRadius(majorRadius);
|
||||
ellipse.setMinorRadius(minorRadius);
|
||||
|
||||
// Act
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
auto ptStart = Sketcher::SketchObject::getPoint(&ellipse, Sketcher::PointPos::start);
|
||||
auto ptMid = Sketcher::SketchObject::getPoint(&ellipse, Sketcher::PointPos::mid);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
auto ptEnd = Sketcher::SketchObject::getPoint(&ellipse, Sketcher::PointPos::end);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptNone = Sketcher::SketchObject::getPoint(&ellipse, Sketcher::PointPos::none);
|
||||
|
||||
// Assert
|
||||
// NOTE: Presently, start/end points of an ellipse are defined as the point on the major axis in
|
||||
// it's "positive" direction
|
||||
EXPECT_DOUBLE_EQ(ptStart[0], 1.0 + majorRadius);
|
||||
EXPECT_DOUBLE_EQ(ptStart[1], 2.0);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[0], 1.0 + majorRadius);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[1], 2.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[1], 2.0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetPointFromGeomArcOfCircle)
|
||||
{
|
||||
// Arrange
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double radius = 3.0, startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5;
|
||||
Part::GeomArcOfCircle arcOfCircle;
|
||||
arcOfCircle.setCenter(coordsCenter);
|
||||
arcOfCircle.setRadius(radius);
|
||||
arcOfCircle.setRange(startParam, endParam, true);
|
||||
|
||||
// Act
|
||||
auto ptStart = Sketcher::SketchObject::getPoint(&arcOfCircle, Sketcher::PointPos::start);
|
||||
auto ptMid = Sketcher::SketchObject::getPoint(&arcOfCircle, Sketcher::PointPos::mid);
|
||||
auto ptEnd = Sketcher::SketchObject::getPoint(&arcOfCircle, Sketcher::PointPos::end);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptNone
|
||||
= Sketcher::SketchObject::getPoint(&arcOfCircle, Sketcher::PointPos::none);
|
||||
|
||||
// Assert
|
||||
// NOTE: parameters for arc of circle are CCW angles from positive x-axis
|
||||
EXPECT_DOUBLE_EQ(ptStart[0], 1.0 + cos(startParam) * radius);
|
||||
EXPECT_DOUBLE_EQ(ptStart[1], 2.0 + sin(startParam) * radius);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[0], 1.0 + cos(endParam) * radius);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[1], 2.0 + sin(endParam) * radius);
|
||||
EXPECT_DOUBLE_EQ(ptMid[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[1], 2.0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetPointFromGeomArcOfEllipse)
|
||||
{
|
||||
// Arrange
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double majorRadius = 4.0;
|
||||
double minorRadius = 3.0;
|
||||
double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5;
|
||||
Part::GeomArcOfEllipse arcOfEllipse;
|
||||
arcOfEllipse.setCenter(coordsCenter);
|
||||
arcOfEllipse.setMajorRadius(majorRadius);
|
||||
arcOfEllipse.setMinorRadius(minorRadius);
|
||||
arcOfEllipse.setRange(startParam, endParam, true);
|
||||
|
||||
// Act
|
||||
auto ptStart = Sketcher::SketchObject::getPoint(&arcOfEllipse, Sketcher::PointPos::start);
|
||||
auto ptMid = Sketcher::SketchObject::getPoint(&arcOfEllipse, Sketcher::PointPos::mid);
|
||||
auto ptEnd = Sketcher::SketchObject::getPoint(&arcOfEllipse, Sketcher::PointPos::end);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptNone
|
||||
= Sketcher::SketchObject::getPoint(&arcOfEllipse, Sketcher::PointPos::none);
|
||||
|
||||
// Assert
|
||||
// NOTE: parameters for arc of ellipse are CCW angles from positive x-axis
|
||||
EXPECT_DOUBLE_EQ(ptStart[0], 1.0 + cos(startParam) * majorRadius);
|
||||
EXPECT_DOUBLE_EQ(ptStart[1], 2.0 + sin(startParam) * minorRadius);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[0], 1.0 + cos(endParam) * majorRadius);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[1], 2.0 + sin(endParam) * minorRadius);
|
||||
EXPECT_DOUBLE_EQ(ptMid[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[1], 2.0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetPointFromGeomArcOfHyperbola)
|
||||
{
|
||||
// Arrange
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double majorRadius = 4.0;
|
||||
double minorRadius = 3.0;
|
||||
double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5;
|
||||
Part::GeomArcOfHyperbola arcOfHyperbola;
|
||||
arcOfHyperbola.setCenter(coordsCenter);
|
||||
arcOfHyperbola.setMajorRadius(majorRadius);
|
||||
arcOfHyperbola.setMinorRadius(minorRadius);
|
||||
arcOfHyperbola.setRange(startParam, endParam, true);
|
||||
|
||||
// Act
|
||||
[[maybe_unused]] auto ptStart
|
||||
= Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::start);
|
||||
auto ptMid = Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::mid);
|
||||
[[maybe_unused]] auto ptEnd
|
||||
= Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::end);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptNone
|
||||
= Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::none);
|
||||
|
||||
// Assert
|
||||
// FIXME: Figure out how this is defined
|
||||
// EXPECT_DOUBLE_EQ(ptStart[0], 1.0);
|
||||
// EXPECT_DOUBLE_EQ(ptStart[1], 2.0);
|
||||
// EXPECT_DOUBLE_EQ(ptEnd[0], 1.0);
|
||||
// EXPECT_DOUBLE_EQ(ptEnd[1], 2.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[1], 2.0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetPointFromGeomArcOfParabola)
|
||||
{
|
||||
// Arrange
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double focal = 3.0;
|
||||
double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5;
|
||||
Part::GeomArcOfParabola arcOfParabola;
|
||||
arcOfParabola.setCenter(coordsCenter);
|
||||
arcOfParabola.setFocal(focal);
|
||||
arcOfParabola.setRange(startParam, endParam, true);
|
||||
|
||||
// Act
|
||||
[[maybe_unused]] auto ptStart
|
||||
= Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::start);
|
||||
auto ptMid = Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::mid);
|
||||
[[maybe_unused]] auto ptEnd
|
||||
= Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::end);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptNone
|
||||
= Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::none);
|
||||
|
||||
// Assert
|
||||
// FIXME: Figure out how this is defined
|
||||
// EXPECT_DOUBLE_EQ(ptStart[0], 1.0);
|
||||
// EXPECT_DOUBLE_EQ(ptStart[1], 2.0);
|
||||
// EXPECT_DOUBLE_EQ(ptEnd[0], 1.0);
|
||||
// EXPECT_DOUBLE_EQ(ptEnd[1], 2.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(ptMid[1], 2.0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetPointFromGeomBSplineCurveNonPeriodic)
|
||||
{
|
||||
// Arrange
|
||||
int degree = 3;
|
||||
std::vector<Base::Vector3d> poles;
|
||||
poles.emplace_back(1, 0, 0);
|
||||
poles.emplace_back(1, 1, 0);
|
||||
poles.emplace_back(1, 0.5, 0);
|
||||
poles.emplace_back(0, 1, 0);
|
||||
poles.emplace_back(0, 0, 0);
|
||||
std::vector<double> weights(5, 1.0);
|
||||
std::vector<double> knotsNonPeriodic = {0.0, 1.0, 2.0};
|
||||
std::vector<int> multiplicitiesNonPeriodic = {degree + 1, 1, degree + 1};
|
||||
Part::GeomBSplineCurve
|
||||
nonPeriodicBSpline(poles, weights, knotsNonPeriodic, multiplicitiesNonPeriodic, degree, false);
|
||||
|
||||
// Act
|
||||
auto ptStart = Sketcher::SketchObject::getPoint(&nonPeriodicBSpline, Sketcher::PointPos::start);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptMid
|
||||
= Sketcher::SketchObject::getPoint(&nonPeriodicBSpline, Sketcher::PointPos::mid);
|
||||
auto ptEnd = Sketcher::SketchObject::getPoint(&nonPeriodicBSpline, Sketcher::PointPos::end);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptNone
|
||||
= Sketcher::SketchObject::getPoint(&nonPeriodicBSpline, Sketcher::PointPos::none);
|
||||
|
||||
// Assert
|
||||
EXPECT_DOUBLE_EQ(ptStart[0], poles.front()[0]);
|
||||
EXPECT_DOUBLE_EQ(ptStart[1], poles.front()[1]);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[0], poles.back()[0]);
|
||||
EXPECT_DOUBLE_EQ(ptEnd[1], poles.back()[1]);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetPointFromGeomBSplineCurvePeriodic)
|
||||
{
|
||||
// Arrange
|
||||
int degree = 3;
|
||||
std::vector<Base::Vector3d> poles;
|
||||
poles.emplace_back(1, 0, 0);
|
||||
poles.emplace_back(1, 1, 0);
|
||||
poles.emplace_back(1, 0.5, 0);
|
||||
poles.emplace_back(0, 1, 0);
|
||||
poles.emplace_back(0, 0, 0);
|
||||
std::vector<double> weights(5, 1.0);
|
||||
std::vector<double> knotsPeriodic = {0.0, 0.3, 1.0, 1.5, 1.8, 2.0};
|
||||
std::vector<int> multiplicitiesPeriodic(6, 1);
|
||||
Part::GeomBSplineCurve
|
||||
periodicBSpline(poles, weights, knotsPeriodic, multiplicitiesPeriodic, degree, true);
|
||||
|
||||
// Act
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
auto ptStart = Sketcher::SketchObject::getPoint(&periodicBSpline, Sketcher::PointPos::start);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptMid
|
||||
= Sketcher::SketchObject::getPoint(&periodicBSpline, Sketcher::PointPos::mid);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
auto ptEnd = Sketcher::SketchObject::getPoint(&periodicBSpline, Sketcher::PointPos::end);
|
||||
// TODO: Maybe we want this to give an error instead of some default value
|
||||
[[maybe_unused]] auto ptNone
|
||||
= Sketcher::SketchObject::getPoint(&periodicBSpline, Sketcher::PointPos::none);
|
||||
|
||||
// Assert
|
||||
// With non-trivial values for weights, knots, mults, etc, getting the coordinates is
|
||||
// non-trivial as well. This is the best we can do.
|
||||
EXPECT_DOUBLE_EQ(ptStart[0], ptEnd[0]);
|
||||
EXPECT_DOUBLE_EQ(ptStart[1], ptEnd[1]);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testConstraintAfterDeletingGeo)
|
||||
{
|
||||
// Arrange
|
||||
int geoId1 = 42, geoId2 = 10, geoId3 = 0, geoId4 = -8;
|
||||
|
||||
Sketcher::Constraint* nullConstr = nullptr;
|
||||
|
||||
Sketcher::Constraint constr1;
|
||||
constr1.Type = Sketcher::ConstraintType::Coincident;
|
||||
constr1.First = geoId1;
|
||||
constr1.FirstPos = Sketcher::PointPos::start;
|
||||
constr1.Second = geoId2;
|
||||
constr1.SecondPos = Sketcher::PointPos::end;
|
||||
|
||||
Sketcher::Constraint constr2;
|
||||
constr2.Type = Sketcher::ConstraintType::Tangent;
|
||||
constr2.First = geoId4;
|
||||
constr2.FirstPos = Sketcher::PointPos::none;
|
||||
constr2.Second = geoId3;
|
||||
constr2.SecondPos = Sketcher::PointPos::none;
|
||||
constr2.Third = geoId1;
|
||||
constr2.ThirdPos = Sketcher::PointPos::start;
|
||||
|
||||
// Act
|
||||
auto nullConstrAfter = getObject()->getConstraintAfterDeletingGeo(nullConstr, 5);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(nullConstrAfter, nullptr);
|
||||
|
||||
// Act
|
||||
getObject()->changeConstraintAfterDeletingGeo(nullConstr, 5);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(nullConstr, nullptr);
|
||||
|
||||
// Act
|
||||
// delete typical in-sketch geo
|
||||
auto constr1PtrAfter1 = getObject()->getConstraintAfterDeletingGeo(&constr1, 5);
|
||||
// delete external geo (negative id)
|
||||
auto constr1PtrAfter2 = getObject()->getConstraintAfterDeletingGeo(&constr1, -5);
|
||||
// Delete a geo involved in the constraint
|
||||
auto constr1PtrAfter3 = getObject()->getConstraintAfterDeletingGeo(&constr1, 10);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(constr1.Type, Sketcher::ConstraintType::Coincident);
|
||||
EXPECT_EQ(constr1.First, geoId1);
|
||||
EXPECT_EQ(constr1.Second, geoId2);
|
||||
EXPECT_EQ(constr1PtrAfter1->First, geoId1 - 1);
|
||||
EXPECT_EQ(constr1PtrAfter1->Second, geoId2 - 1);
|
||||
EXPECT_EQ(constr1PtrAfter2->Third, Sketcher::GeoEnum::GeoUndef);
|
||||
EXPECT_EQ(constr1PtrAfter3.get(), nullptr);
|
||||
|
||||
// Act
|
||||
getObject()->changeConstraintAfterDeletingGeo(&constr2, -3);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(constr2.Type, Sketcher::ConstraintType::Tangent);
|
||||
EXPECT_EQ(constr2.First, geoId4 + 1);
|
||||
EXPECT_EQ(constr2.Second, geoId3);
|
||||
EXPECT_EQ(constr2.Third, geoId1);
|
||||
|
||||
// Act
|
||||
// Delete a geo involved in the constraint
|
||||
getObject()->changeConstraintAfterDeletingGeo(&constr2, 0);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(constr2.Type, Sketcher::ConstraintType::None);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testDeleteExposeInternalGeometryOfEllipse)
|
||||
{
|
||||
// Arrange
|
||||
Part::GeomEllipse ellipse;
|
||||
setupEllipse(ellipse);
|
||||
int geoId = getObject()->addGeometry(&ellipse);
|
||||
|
||||
// Act
|
||||
getObject()->deleteUnusedInternalGeometryAndUpdateGeoId(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure there's only one curve
|
||||
EXPECT_EQ(getObject()->getHighestCurveIndex(), 0);
|
||||
|
||||
// Act
|
||||
// "Expose" internal geometry
|
||||
getObject()->exposeInternalGeometry(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure all internal geometry is satisfied
|
||||
// TODO: Also try to ensure types of geometries that have this type
|
||||
const auto constraints = getObject()->Constraints.getValues();
|
||||
for (auto alignmentType :
|
||||
{Sketcher::InternalAlignmentType::EllipseMajorDiameter,
|
||||
Sketcher::InternalAlignmentType::EllipseMinorDiameter,
|
||||
Sketcher::InternalAlignmentType::EllipseFocus1,
|
||||
Sketcher::InternalAlignmentType::EllipseFocus2}) {
|
||||
// TODO: Ensure there exists one and only one curve with this type
|
||||
int numConstraintsOfThisType = std::count_if(
|
||||
constraints.begin(),
|
||||
constraints.end(),
|
||||
[&geoId, &alignmentType](const auto* constr) {
|
||||
return constr->Type == Sketcher::ConstraintType::InternalAlignment
|
||||
&& constr->AlignmentType == alignmentType && constr->Second == geoId;
|
||||
}
|
||||
);
|
||||
EXPECT_EQ(numConstraintsOfThisType, 1);
|
||||
}
|
||||
|
||||
// Act
|
||||
// Delete internal geometry (again)
|
||||
getObject()->deleteUnusedInternalGeometryAndUpdateGeoId(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure there's only one curve
|
||||
EXPECT_EQ(getObject()->getHighestCurveIndex(), 0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testDeleteExposeInternalGeometryOfHyperbola)
|
||||
{
|
||||
// Arrange
|
||||
Part::GeomArcOfHyperbola aoh;
|
||||
setupArcOfHyperbola(aoh);
|
||||
int geoId = getObject()->addGeometry(&aoh);
|
||||
|
||||
// Act
|
||||
getObject()->deleteUnusedInternalGeometryAndUpdateGeoId(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure there's only one curve
|
||||
EXPECT_EQ(getObject()->getHighestCurveIndex(), 0);
|
||||
|
||||
// Act
|
||||
// "Expose" internal geometry
|
||||
getObject()->exposeInternalGeometry(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure all internal geometry is satisfied
|
||||
// TODO: Also try to ensure types of geometries that have this type
|
||||
const auto constraints = getObject()->Constraints.getValues();
|
||||
for (auto alignmentType :
|
||||
{Sketcher::InternalAlignmentType::HyperbolaMajor,
|
||||
Sketcher::InternalAlignmentType::HyperbolaMinor,
|
||||
Sketcher::InternalAlignmentType::HyperbolaFocus}) {
|
||||
// TODO: Ensure there exists one and only one curve with this type
|
||||
int numConstraintsOfThisType = std::count_if(
|
||||
constraints.begin(),
|
||||
constraints.end(),
|
||||
[&geoId, &alignmentType](const auto* constr) {
|
||||
return constr->Type == Sketcher::ConstraintType::InternalAlignment
|
||||
&& constr->AlignmentType == alignmentType && constr->Second == geoId;
|
||||
}
|
||||
);
|
||||
EXPECT_EQ(numConstraintsOfThisType, 1);
|
||||
}
|
||||
|
||||
// Act
|
||||
// Delete internal geometry (again)
|
||||
getObject()->deleteUnusedInternalGeometryAndUpdateGeoId(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure there's only one curve
|
||||
EXPECT_EQ(getObject()->getHighestCurveIndex(), 0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testDeleteExposeInternalGeometryOfParabola)
|
||||
{
|
||||
// Arrange
|
||||
Part::GeomArcOfParabola aoh;
|
||||
setupArcOfParabola(aoh);
|
||||
int geoId = getObject()->addGeometry(&aoh);
|
||||
|
||||
// Act
|
||||
getObject()->deleteUnusedInternalGeometryAndUpdateGeoId(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure there's only one curve
|
||||
EXPECT_EQ(getObject()->getHighestCurveIndex(), 0);
|
||||
|
||||
// Act
|
||||
// "Expose" internal geometry
|
||||
getObject()->exposeInternalGeometry(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure all internal geometry is satisfied
|
||||
// TODO: Also try to ensure types of geometries that have this type
|
||||
const auto constraints = getObject()->Constraints.getValues();
|
||||
for (auto alignmentType :
|
||||
{Sketcher::InternalAlignmentType::ParabolaFocalAxis,
|
||||
Sketcher::InternalAlignmentType::ParabolaFocus}) {
|
||||
// TODO: Ensure there exists one and only one curve with this type
|
||||
int numConstraintsOfThisType = std::count_if(
|
||||
constraints.begin(),
|
||||
constraints.end(),
|
||||
[&geoId, &alignmentType](const auto* constr) {
|
||||
return constr->Type == Sketcher::ConstraintType::InternalAlignment
|
||||
&& constr->AlignmentType == alignmentType && constr->Second == geoId;
|
||||
}
|
||||
);
|
||||
EXPECT_EQ(numConstraintsOfThisType, 1);
|
||||
}
|
||||
|
||||
// Act
|
||||
// Delete internal geometry (again)
|
||||
getObject()->deleteUnusedInternalGeometryAndUpdateGeoId(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure there's only one curve
|
||||
EXPECT_EQ(getObject()->getHighestCurveIndex(), 0);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testDeleteExposeInternalGeometryOfBSpline)
|
||||
{
|
||||
// NOTE: We test only non-periodic B-spline here. Periodic B-spline should behave exactly the
|
||||
// same.
|
||||
|
||||
// Arrange
|
||||
auto nonPeriodicBSpline = createTypicalNonPeriodicBSpline();
|
||||
int geoId = getObject()->addGeometry(nonPeriodicBSpline.get());
|
||||
|
||||
// Act
|
||||
getObject()->deleteUnusedInternalGeometryAndUpdateGeoId(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure there's only one curve
|
||||
EXPECT_EQ(getObject()->getHighestCurveIndex(), 0);
|
||||
|
||||
// Act
|
||||
// "Expose" internal geometry
|
||||
getObject()->exposeInternalGeometry(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure all internal geometry is satisfied
|
||||
// TODO: Also try to ensure types of geometries that have this type
|
||||
const auto constraints = getObject()->Constraints.getValues();
|
||||
std::map<Sketcher::InternalAlignmentType, int> numConstraintsOfThisType;
|
||||
for (auto alignmentType :
|
||||
{Sketcher::InternalAlignmentType::BSplineControlPoint,
|
||||
Sketcher::InternalAlignmentType::BSplineKnotPoint}) {
|
||||
// TODO: Ensure there exists one and only one curve with this type
|
||||
numConstraintsOfThisType[alignmentType] = std::count_if(
|
||||
constraints.begin(),
|
||||
constraints.end(),
|
||||
[&geoId, &alignmentType](const auto* constr) {
|
||||
return constr->Type == Sketcher::ConstraintType::InternalAlignment
|
||||
&& constr->AlignmentType == alignmentType && constr->Second == geoId;
|
||||
}
|
||||
);
|
||||
}
|
||||
EXPECT_EQ(
|
||||
numConstraintsOfThisType[Sketcher::InternalAlignmentType::BSplineControlPoint],
|
||||
nonPeriodicBSpline->countPoles()
|
||||
);
|
||||
EXPECT_EQ(
|
||||
numConstraintsOfThisType[Sketcher::InternalAlignmentType::BSplineKnotPoint],
|
||||
nonPeriodicBSpline->countKnots()
|
||||
);
|
||||
|
||||
// Act
|
||||
// Delete internal geometry (again)
|
||||
getObject()->deleteUnusedInternalGeometryAndUpdateGeoId(geoId);
|
||||
|
||||
// Assert
|
||||
// Ensure there's only one curve
|
||||
EXPECT_EQ(getObject()->getHighestCurveIndex(), 0);
|
||||
}
|
||||
|
||||
// TODO: Needs to be done for other curves too but currently they are working as intended
|
||||
TEST_F(SketchObjectTest, testDeleteOnlyUnusedInternalGeometryOfBSpline)
|
||||
{
|
||||
// NOTE: We test only non-periodic B-spline here. Periodic B-spline should behave exactly the
|
||||
// same.
|
||||
|
||||
// Arrange
|
||||
auto nonPeriodicBSpline = createTypicalNonPeriodicBSpline();
|
||||
int geoIdBsp = getObject()->addGeometry(nonPeriodicBSpline.get());
|
||||
// Ensure "exposed" internal geometry
|
||||
getObject()->exposeInternalGeometry(geoIdBsp);
|
||||
Base::Vector3d coords(1.0, 1.0, 0.0);
|
||||
Part::GeomPoint point(coords);
|
||||
int geoIdPnt = getObject()->addGeometry(&point);
|
||||
const auto constraints = getObject()->Constraints.getValues();
|
||||
auto it = std::find_if(constraints.begin(), constraints.end(), [&geoIdBsp](const auto* constr) {
|
||||
return constr->Type == Sketcher::ConstraintType::InternalAlignment
|
||||
&& constr->AlignmentType == Sketcher::InternalAlignmentType::BSplineControlPoint
|
||||
&& constr->Second == geoIdBsp && constr->InternalAlignmentIndex == 1;
|
||||
});
|
||||
// One Assert to avoid
|
||||
EXPECT_NE(it, constraints.end());
|
||||
auto constraint = new Sketcher::Constraint(); // Ownership will be transferred to the sketch
|
||||
constraint->Type = Sketcher::ConstraintType::Coincident;
|
||||
constraint->First = geoIdPnt;
|
||||
constraint->FirstPos = Sketcher::PointPos::start;
|
||||
constraint->Second = (*it)->First;
|
||||
constraint->SecondPos = Sketcher::PointPos::mid;
|
||||
getObject()->addConstraint(constraint);
|
||||
|
||||
// Act
|
||||
getObject()->deleteUnusedInternalGeometryAndUpdateGeoId(geoIdBsp);
|
||||
|
||||
// Assert
|
||||
// Ensure there are 3 curves: the B-spline, its pole, and the point coincident on the pole
|
||||
EXPECT_EQ(getObject()->getHighestCurveIndex(), 2);
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testReverseAngleConstraintToSupplementaryExpressionNoUnits1)
|
||||
{
|
||||
std::string expr = Sketcher::SketchObject::reverseAngleConstraintExpression("180 - 60");
|
||||
EXPECT_EQ(expr, std::string("60"));
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testReverseAngleConstraintToSupplementaryExpressionNoUnits2)
|
||||
{
|
||||
std::string expr = Sketcher::SketchObject::reverseAngleConstraintExpression("60");
|
||||
EXPECT_EQ(expr, std::string("180 - (60)"));
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testReverseAngleConstraintToSupplementaryExpressionWithUnits1)
|
||||
{
|
||||
std::string expr = Sketcher::SketchObject::reverseAngleConstraintExpression("180 ° - 60 °");
|
||||
EXPECT_EQ(expr, std::string("60 °"));
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testReverseAngleConstraintToSupplementaryExpressionWithUnits2)
|
||||
{
|
||||
std::string expr = Sketcher::SketchObject::reverseAngleConstraintExpression("60 °");
|
||||
EXPECT_EQ(expr, std::string("180 ° - (60 °)"));
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testReverseAngleConstraintToSupplementaryExpressionWithUnits3)
|
||||
{
|
||||
std::string expr = Sketcher::SketchObject::reverseAngleConstraintExpression("60 deg");
|
||||
EXPECT_EQ(expr, std::string("180 ° - (60 deg)"));
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testReverseAngleConstraintToSupplementaryExpressionWithUnits4)
|
||||
{
|
||||
std::string expr = Sketcher::SketchObject::reverseAngleConstraintExpression("1rad");
|
||||
EXPECT_EQ(expr, std::string("180 ° - (1rad)"));
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testReverseAngleConstraintToSupplementaryExpressionApplyAndReverse1)
|
||||
{
|
||||
std::string expr = "180";
|
||||
expr = Sketcher::SketchObject::reverseAngleConstraintExpression(expr);
|
||||
expr = Sketcher::SketchObject::reverseAngleConstraintExpression(expr);
|
||||
EXPECT_EQ(expr, std::string("(180)"));
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testReverseAngleConstraintToSupplementaryExpressionApplyAndReverse2)
|
||||
{
|
||||
std::string expr = "(30 + 15) * 2 / 3";
|
||||
expr = Sketcher::SketchObject::reverseAngleConstraintExpression(expr);
|
||||
expr = Sketcher::SketchObject::reverseAngleConstraintExpression(expr);
|
||||
EXPECT_EQ(expr, std::string("((30 + 15) * 2 / 3)"));
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testReverseAngleConstraintToSupplementaryExpressionSimple)
|
||||
{
|
||||
// Arrange
|
||||
auto constraint = new Sketcher::Constraint(); // Ownership will be transferred to the sketch
|
||||
constraint->Type = Sketcher::ConstraintType::Angle;
|
||||
auto id = getObject()->addConstraint(constraint);
|
||||
|
||||
App::ObjectIdentifier path(App::ObjectIdentifier::parse(getObject(), "Constraints[0]"));
|
||||
std::shared_ptr<App::Expression> shared_expr(App::Expression::parse(getObject(), "0"));
|
||||
getObject()->setExpression(path, shared_expr);
|
||||
|
||||
getObject()->setConstraintExpression(id, "180 - (60)");
|
||||
|
||||
// Act
|
||||
getObject()->reverseAngleConstraintToSupplementary(constraint, id);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(std::string("60"), getObject()->getConstraintExpression(id));
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testReverseAngleConstraintToSupplementaryExpressionApplyAndReverse)
|
||||
{
|
||||
// Arrange
|
||||
auto constraint = new Sketcher::Constraint(); // Ownership will be transferred to the sketch
|
||||
constraint->Type = Sketcher::ConstraintType::Angle;
|
||||
auto id = getObject()->addConstraint(constraint);
|
||||
|
||||
App::ObjectIdentifier path(App::ObjectIdentifier::parse(getObject(), "Constraints[0]"));
|
||||
std::shared_ptr<App::Expression> shared_expr(App::Expression::parse(getObject(), "0"));
|
||||
getObject()->setExpression(path, shared_expr);
|
||||
|
||||
getObject()->setConstraintExpression(id, "32 °");
|
||||
|
||||
// Act
|
||||
getObject()->reverseAngleConstraintToSupplementary(constraint, id);
|
||||
getObject()->reverseAngleConstraintToSupplementary(constraint, id);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(std::string("32 °"), getObject()->getConstraintExpression(id));
|
||||
}
|
||||
|
||||
TEST_F(SketchObjectTest, testGetElementName)
|
||||
{
|
||||
// Arrange
|
||||
Base::Vector3d p1(0.0, 0.0, 0.0), p2(1.0, 0.0, 0.0);
|
||||
std::unique_ptr<Part::Geometry> geoline(new Part::GeomLineSegment());
|
||||
static_cast<Part::GeomLineSegment*>(geoline.get())->setPoints(p1, p2);
|
||||
auto id = getObject()->addGeometry(geoline.get());
|
||||
long tag;
|
||||
getObject()->getGeometryId(id, tag); // We need to look up the tag that got assigned
|
||||
std::ostringstream oss;
|
||||
oss << "g" << tag;
|
||||
auto tagName = oss.str();
|
||||
getObject()->recomputeFeature(); // or ->execute()
|
||||
// Act
|
||||
// unless it's Export, we are really just testing the superclass App::GeoFeature::getElementName
|
||||
// call.
|
||||
auto forward_normal_name = getObject()->getElementName(
|
||||
(tagName + ";SKT").c_str(),
|
||||
App::GeoFeature::ElementNameType::Normal
|
||||
);
|
||||
auto reverse_normal_name
|
||||
= getObject()->getElementName("Vertex2", App::GeoFeature::ElementNameType::Normal);
|
||||
auto reverse_export_name
|
||||
= getObject()->getElementName("Vertex1", App::GeoFeature::ElementNameType::Export);
|
||||
auto map = getObject()->Shape.getShape().getElementMap();
|
||||
ASSERT_EQ(map.size(), 3);
|
||||
EXPECT_STREQ(map[0].name.toString().c_str(), (tagName + ";SKT").c_str());
|
||||
EXPECT_EQ(map[0].index.toString(), "Edge1");
|
||||
EXPECT_STREQ(map[1].name.toString().c_str(), (tagName + "v1;SKT").c_str());
|
||||
EXPECT_EQ(map[1].index.toString(), "Vertex1");
|
||||
EXPECT_STREQ(map[2].name.toString().c_str(), (tagName + "v2;SKT").c_str());
|
||||
EXPECT_EQ(map[2].index.toString(), "Vertex2");
|
||||
// Assert
|
||||
EXPECT_STREQ(forward_normal_name.newName.c_str(), (";" + tagName + ";SKT.Edge1").c_str());
|
||||
EXPECT_STREQ(forward_normal_name.oldName.c_str(), "Edge1");
|
||||
EXPECT_STREQ(reverse_normal_name.newName.c_str(), (";" + tagName + "v2;SKT.Vertex2").c_str());
|
||||
EXPECT_STREQ(reverse_normal_name.oldName.c_str(), "Vertex2");
|
||||
EXPECT_STREQ(reverse_export_name.newName.c_str(), (";" + tagName + "v1;SKT.Vertex1").c_str());
|
||||
EXPECT_STREQ(reverse_export_name.oldName.c_str(), "Vertex1");
|
||||
}
|
||||
1212
tests/src/Mod/Sketcher/App/SketchObjectChanges.cpp
Normal file
1212
tests/src/Mod/Sketcher/App/SketchObjectChanges.cpp
Normal file
File diff suppressed because it is too large
Load Diff
157
tests/src/Mod/Sketcher/App/SketcherTestHelpers.cpp
Normal file
157
tests/src/Mod/Sketcher/App/SketcherTestHelpers.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/Expression.h>
|
||||
#include <App/ObjectIdentifier.h>
|
||||
#include <Mod/Sketcher/App/GeoEnum.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
#include <src/App/InitApplication.h>
|
||||
#include "SketcherTestHelpers.h"
|
||||
|
||||
|
||||
void SketchObjectTest::SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SketchObjectTest::SetUp()
|
||||
{
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
auto _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
// TODO: Do we add a body newName, or is just adding sketch sufficient for this test?
|
||||
_sketchobj = static_cast<Sketcher::SketchObject*>(_doc->addObject("Sketcher::SketchObject"));
|
||||
}
|
||||
|
||||
void SketchObjectTest::TearDown()
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
Sketcher::SketchObject* SketchObjectTest::getObject()
|
||||
{
|
||||
return _sketchobj;
|
||||
}
|
||||
|
||||
namespace SketcherTestHelpers
|
||||
{
|
||||
|
||||
using namespace Sketcher;
|
||||
|
||||
void setupLineSegment(Part::GeomLineSegment& lineSeg)
|
||||
{
|
||||
Base::Vector3d coords1(1.0, 2.0, 0.0);
|
||||
Base::Vector3d coords2(3.0, 4.0, 0.0);
|
||||
lineSeg.setPoints(coords1, coords2);
|
||||
}
|
||||
|
||||
void setupCircle(Part::GeomCircle& circle)
|
||||
{
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double radius = 3.0;
|
||||
circle.setCenter(coordsCenter);
|
||||
circle.setRadius(radius);
|
||||
}
|
||||
|
||||
void setupArcOfCircle(Part::GeomArcOfCircle& arcOfCircle)
|
||||
{
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double radius = 3.0;
|
||||
double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5;
|
||||
arcOfCircle.setCenter(coordsCenter);
|
||||
arcOfCircle.setRadius(radius);
|
||||
arcOfCircle.setRange(startParam, endParam, true);
|
||||
}
|
||||
|
||||
void setupEllipse(Part::GeomEllipse& ellipse)
|
||||
{
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double majorRadius = 4.0;
|
||||
double minorRadius = 3.0;
|
||||
ellipse.setCenter(coordsCenter);
|
||||
ellipse.setMajorRadius(majorRadius);
|
||||
ellipse.setMinorRadius(minorRadius);
|
||||
}
|
||||
|
||||
void setupArcOfHyperbola(Part::GeomArcOfHyperbola& arcOfHyperbola)
|
||||
{
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double majorRadius = 4.0;
|
||||
double minorRadius = 3.0;
|
||||
double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5;
|
||||
arcOfHyperbola.setCenter(coordsCenter);
|
||||
arcOfHyperbola.setMajorRadius(majorRadius);
|
||||
arcOfHyperbola.setMinorRadius(minorRadius);
|
||||
arcOfHyperbola.setRange(startParam, endParam, true);
|
||||
}
|
||||
|
||||
void setupArcOfParabola(Part::GeomArcOfParabola& aop)
|
||||
{
|
||||
Base::Vector3d coordsCenter(1.0, 2.0, 0.0);
|
||||
double focal = 3.0;
|
||||
double startParam = -std::numbers::pi * 1.5, endParam = std::numbers::pi * 1.5;
|
||||
aop.setCenter(coordsCenter);
|
||||
aop.setFocal(focal);
|
||||
aop.setRange(startParam, endParam, true);
|
||||
}
|
||||
|
||||
std::unique_ptr<Part::GeomBSplineCurve> createTypicalNonPeriodicBSpline()
|
||||
{
|
||||
int degree = 3;
|
||||
std::vector<Base::Vector3d> poles;
|
||||
poles.emplace_back(1, 0, 0);
|
||||
poles.emplace_back(1, 1, 0);
|
||||
poles.emplace_back(1, 0.5, 0);
|
||||
poles.emplace_back(0, 1, 0);
|
||||
poles.emplace_back(0, 0, 0);
|
||||
std::vector<double> weights(5, 1.0);
|
||||
std::vector<double> knotsNonPeriodic = {0.0, 1.0, 2.0};
|
||||
std::vector<int> multiplicitiesNonPeriodic = {degree + 1, 1, degree + 1};
|
||||
return std::make_unique<Part::GeomBSplineCurve>(
|
||||
poles,
|
||||
weights,
|
||||
knotsNonPeriodic,
|
||||
multiplicitiesNonPeriodic,
|
||||
degree,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
std::unique_ptr<Part::GeomBSplineCurve> createTypicalPeriodicBSpline()
|
||||
{
|
||||
int degree = 3;
|
||||
std::vector<Base::Vector3d> poles;
|
||||
poles.emplace_back(1, 0, 0);
|
||||
poles.emplace_back(1, 1, 0);
|
||||
poles.emplace_back(1, 0.5, 0);
|
||||
poles.emplace_back(0, 1, 0);
|
||||
poles.emplace_back(0, 0, 0);
|
||||
std::vector<double> weights(5, 1.0);
|
||||
std::vector<double> knotsPeriodic = {0.0, 0.3, 1.0, 1.5, 1.8, 2.0};
|
||||
std::vector<int> multiplicitiesPeriodic(6, 1);
|
||||
return std::make_unique<Part::GeomBSplineCurve>(
|
||||
poles,
|
||||
weights,
|
||||
knotsPeriodic,
|
||||
multiplicitiesPeriodic,
|
||||
degree,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
int countConstraintsOfType(const Sketcher::SketchObject* obj, const Sketcher::ConstraintType cType)
|
||||
{
|
||||
const std::vector<Sketcher::Constraint*>& constraints = obj->Constraints.getValues();
|
||||
|
||||
int result = std::ranges::count(constraints, cType, &Constraint::Type);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Base::Vector3d getPointAtNormalizedParameter(const Part::GeomCurve& curve, double param)
|
||||
{
|
||||
return curve.pointAtParameter(
|
||||
curve.getFirstParameter() + (curve.getLastParameter() - curve.getFirstParameter()) * param
|
||||
);
|
||||
}
|
||||
} // namespace SketcherTestHelpers
|
||||
60
tests/src/Mod/Sketcher/App/SketcherTestHelpers.h
Normal file
60
tests/src/Mod/Sketcher/App/SketcherTestHelpers.h
Normal file
@@ -0,0 +1,60 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <FCConfig.h>
|
||||
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/Expression.h>
|
||||
#include <App/ObjectIdentifier.h>
|
||||
#include <Mod/Sketcher/App/GeoEnum.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
|
||||
|
||||
class SketchObjectTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
Sketcher::SketchObject* getObject();
|
||||
|
||||
private:
|
||||
// TODO: use shared_ptr or something else here?
|
||||
Sketcher::SketchObject* _sketchobj;
|
||||
std::string _docName;
|
||||
std::vector<const char*>
|
||||
allowedTypes {"Vertex", "Edge", "ExternalEdge", "H_Axis", "V_Axis", "RootPoint"};
|
||||
};
|
||||
|
||||
namespace SketcherTestHelpers
|
||||
{
|
||||
|
||||
using namespace Sketcher;
|
||||
|
||||
void setupLineSegment(Part::GeomLineSegment& lineSeg);
|
||||
|
||||
void setupCircle(Part::GeomCircle& circle);
|
||||
|
||||
void setupArcOfCircle(Part::GeomArcOfCircle& arcOfCircle);
|
||||
|
||||
void setupEllipse(Part::GeomEllipse& ellipse);
|
||||
|
||||
void setupArcOfHyperbola(Part::GeomArcOfHyperbola& arcOfHyperbola);
|
||||
|
||||
void setupArcOfParabola(Part::GeomArcOfParabola& aop);
|
||||
|
||||
std::unique_ptr<Part::GeomBSplineCurve> createTypicalNonPeriodicBSpline();
|
||||
|
||||
std::unique_ptr<Part::GeomBSplineCurve> createTypicalPeriodicBSpline();
|
||||
|
||||
int countConstraintsOfType(const Sketcher::SketchObject* obj, const Sketcher::ConstraintType cType);
|
||||
|
||||
// Get point at the parameter after scaling the range to [0, 1].
|
||||
Base::Vector3d getPointAtNormalizedParameter(const Part::GeomCurve& curve, double param);
|
||||
|
||||
// TODO: How to set up B-splines here?
|
||||
// It's not straightforward to change everything from a "default" one.
|
||||
} // namespace SketcherTestHelpers
|
||||
9
tests/src/Mod/Sketcher/App/planegcs/CMakeLists.txt
Normal file
9
tests/src/Mod/Sketcher/App/planegcs/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
target_sources(Sketcher_tests_run PRIVATE
|
||||
GCS.cpp
|
||||
)
|
||||
|
||||
target_sources(Sketcher_tests_run PRIVATE
|
||||
Constraints.cpp
|
||||
)
|
||||
180
tests/src/Mod/Sketcher/App/planegcs/Constraints.cpp
Normal file
180
tests/src/Mod/Sketcher/App/planegcs/Constraints.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <cmath>
|
||||
#include <numbers>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Mod/Sketcher/App/planegcs/GCS.h"
|
||||
#include "Mod/Sketcher/App/planegcs/Geo.h"
|
||||
#include "Mod/Sketcher/App/planegcs/Constraints.h"
|
||||
|
||||
class SystemTest: public GCS::System
|
||||
{
|
||||
public:
|
||||
size_t getNumberOfConstraints(int tagID = -1)
|
||||
{
|
||||
return _getNumberOfConstraints(tagID);
|
||||
}
|
||||
};
|
||||
|
||||
class ConstraintsTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
_system = std::make_unique<SystemTest>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
_system.reset();
|
||||
}
|
||||
|
||||
SystemTest* System()
|
||||
{
|
||||
return _system.get();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<SystemTest> _system;
|
||||
};
|
||||
|
||||
TEST_F(ConstraintsTest, tangentBSplineAndArc) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
// TODO: Add arc, B-spline, and point
|
||||
double pointX = 3.5, arcStartX = 5.0, arcEndX = 0.0, arcCenterX = 0.0;
|
||||
double pointY = 3.5, arcStartY = 0.0, arcEndY = 5.0, arcCenterY = 0.0;
|
||||
GCS::Point point, arcStart, arcEnd, arcCenter;
|
||||
point.x = &pointX;
|
||||
point.y = &pointY;
|
||||
arcStart.x = &arcStartX;
|
||||
arcStart.y = &arcStartY;
|
||||
arcEnd.x = &arcEndX;
|
||||
arcEnd.y = &arcEndY;
|
||||
arcCenter.x = &arcCenterX;
|
||||
arcCenter.y = &arcCenterY;
|
||||
double arcRadius = 5.0, arcStartAngle = 0.0, arcEndAngle = std::numbers::pi / 2;
|
||||
double desiredAngle = std::numbers::pi;
|
||||
double bSplineStartX = 0.0, bSplineEndX = 16.0;
|
||||
double bSplineStartY = 10.0, bSplineEndY = -10.0;
|
||||
GCS::Point bSplineStart, bSplineEnd;
|
||||
bSplineStart.x = &bSplineStartX;
|
||||
bSplineStart.y = &bSplineStartY;
|
||||
bSplineEnd.x = &bSplineEndX;
|
||||
bSplineEnd.y = &bSplineEndY;
|
||||
std::vector<double> bSplineControlPointsX(5);
|
||||
std::vector<double> bSplineControlPointsY(5);
|
||||
bSplineControlPointsX[0] = 0.0;
|
||||
bSplineControlPointsY[0] = 10.0;
|
||||
bSplineControlPointsX[1] = 0.0;
|
||||
bSplineControlPointsY[1] = 6.0;
|
||||
bSplineControlPointsX[2] = 6.0;
|
||||
bSplineControlPointsY[2] = 0.5;
|
||||
bSplineControlPointsX[3] = 16.0;
|
||||
bSplineControlPointsY[3] = 0.5;
|
||||
bSplineControlPointsX[4] = 16.0;
|
||||
bSplineControlPointsY[4] = -10.0;
|
||||
std::vector<GCS::Point> bSplineControlPoints(5);
|
||||
for (size_t i = 0; i < bSplineControlPoints.size(); ++i) {
|
||||
bSplineControlPoints[i].x = &bSplineControlPointsX[i];
|
||||
bSplineControlPoints[i].y = &bSplineControlPointsY[i];
|
||||
}
|
||||
std::vector<double> weights(bSplineControlPoints.size(), 1.0);
|
||||
std::vector<double*> weightsAsPtr;
|
||||
std::vector<double> knots(bSplineControlPoints.size() - 2); // Hardcoded for cubic
|
||||
std::vector<double*> knotsAsPtr;
|
||||
std::vector<int> mult(bSplineControlPoints.size() - 2, 1); // Hardcoded for cubic
|
||||
mult.front() = 4; // Hardcoded for cubic
|
||||
mult.back() = 4; // Hardcoded for cubic
|
||||
for (size_t i = 0; i < bSplineControlPoints.size(); ++i) {
|
||||
weightsAsPtr.push_back(&weights[i]);
|
||||
}
|
||||
for (size_t i = 0; i < knots.size(); ++i) {
|
||||
knots[i] = static_cast<double>(i);
|
||||
knotsAsPtr.push_back(&knots[i]);
|
||||
}
|
||||
GCS::Arc arc;
|
||||
arc.start = arcStart;
|
||||
arc.end = arcEnd;
|
||||
arc.center = arcCenter;
|
||||
arc.rad = &arcRadius;
|
||||
arc.startAngle = &arcStartAngle;
|
||||
arc.endAngle = &arcEndAngle;
|
||||
GCS::BSpline bspline;
|
||||
bspline.start = bSplineStart;
|
||||
bspline.end = bSplineEnd;
|
||||
bspline.poles = bSplineControlPoints;
|
||||
bspline.weights = weightsAsPtr;
|
||||
bspline.knots = knotsAsPtr;
|
||||
bspline.mult = mult;
|
||||
bspline.degree = 3;
|
||||
bspline.periodic = false;
|
||||
double bsplineParam = 0.35;
|
||||
|
||||
std::vector<double*> params = {
|
||||
point.x,
|
||||
point.y,
|
||||
arcStart.x,
|
||||
arcStart.y,
|
||||
arcEnd.x,
|
||||
arcEnd.y,
|
||||
arcCenter.x,
|
||||
arcCenter.y,
|
||||
&arcRadius,
|
||||
bSplineStart.x,
|
||||
bSplineStart.y,
|
||||
bSplineEnd.x,
|
||||
bSplineEnd.y,
|
||||
&bSplineControlPointsX[0],
|
||||
&bSplineControlPointsY[0],
|
||||
&bSplineControlPointsX[1],
|
||||
&bSplineControlPointsY[1],
|
||||
&bSplineControlPointsX[2],
|
||||
&bSplineControlPointsY[2],
|
||||
&bSplineControlPointsX[3],
|
||||
&bSplineControlPointsY[3],
|
||||
&bSplineControlPointsX[4],
|
||||
&bSplineControlPointsY[4],
|
||||
&desiredAngle,
|
||||
&bsplineParam
|
||||
};
|
||||
params.insert(params.end(), weightsAsPtr.begin(), weightsAsPtr.end());
|
||||
params.insert(params.end(), knotsAsPtr.begin(), knotsAsPtr.end());
|
||||
|
||||
// Act
|
||||
// TODO: Apply constraint and solve
|
||||
System()->addConstraintArcRules(arc);
|
||||
System()->addConstraintPointOnArc(point, arc, 0, true);
|
||||
System()->addConstraintPointOnBSpline(point, bspline, &bsplineParam, 0, true);
|
||||
System()->addConstraintAngleViaPointAndParam(bspline, arc, point, &bsplineParam, &desiredAngle, 0, true);
|
||||
int solveResult = System()->solve(params);
|
||||
if (solveResult == GCS::Success) {
|
||||
System()->applySolution();
|
||||
}
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(solveResult, GCS::Success);
|
||||
// is point on arc?
|
||||
EXPECT_DOUBLE_EQ(
|
||||
(arcRadius) * (arcRadius),
|
||||
(pointX - arcCenterX) * (pointX - arcCenterX) + (pointY - arcCenterY) * (pointY - arcCenterY)
|
||||
);
|
||||
// is point on B-spline?
|
||||
GCS::DeriVector2 pointAtBSplineParam = bspline.Value(bsplineParam, 1.0);
|
||||
EXPECT_DOUBLE_EQ(pointAtBSplineParam.x, pointX);
|
||||
EXPECT_DOUBLE_EQ(pointAtBSplineParam.y, pointY);
|
||||
// TODO: are tangents at relevant parameter equal?
|
||||
GCS::DeriVector2 centerToPoint((pointX - arcCenterX), (pointY - arcCenterY));
|
||||
GCS::DeriVector2 tangentBSplineAtPoint(pointAtBSplineParam.dx, pointAtBSplineParam.dy);
|
||||
double dprd;
|
||||
// FIXME: This error is probably too high. Fixing this may require improving the solver,
|
||||
// however.
|
||||
EXPECT_NEAR(
|
||||
std::fabs(centerToPoint.crossProdZ(tangentBSplineAtPoint, dprd))
|
||||
/ (centerToPoint.length() * tangentBSplineAtPoint.length()),
|
||||
1.0,
|
||||
0.005
|
||||
);
|
||||
}
|
||||
52
tests/src/Mod/Sketcher/App/planegcs/GCS.cpp
Normal file
52
tests/src/Mod/Sketcher/App/planegcs/GCS.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Mod/Sketcher/App/planegcs/GCS.h"
|
||||
|
||||
class SystemTest: public GCS::System
|
||||
{
|
||||
public:
|
||||
size_t getNumberOfConstraints(int tagID = -1)
|
||||
{
|
||||
return _getNumberOfConstraints(tagID);
|
||||
}
|
||||
};
|
||||
|
||||
class GCSTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
_system = std::make_unique<SystemTest>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
_system.reset();
|
||||
}
|
||||
|
||||
SystemTest* System()
|
||||
{
|
||||
return _system.get();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<SystemTest> _system;
|
||||
};
|
||||
|
||||
TEST_F(GCSTest, clearConstraints) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
const size_t numConstraints {100};
|
||||
for (size_t i = 0; i < numConstraints; ++i) {
|
||||
System()->addConstraint(new GCS::Constraint());
|
||||
}
|
||||
ASSERT_EQ(numConstraints, System()->getNumberOfConstraints());
|
||||
|
||||
// Act
|
||||
System()->clear();
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(0, System()->getNumberOfConstraints());
|
||||
}
|
||||
9
tests/src/Mod/Sketcher/CMakeLists.txt
Normal file
9
tests/src/Mod/Sketcher/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_link_libraries(Sketcher_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Sketcher
|
||||
)
|
||||
10
tests/src/Mod/Spreadsheet/App/CMakeLists.txt
Normal file
10
tests/src/Mod/Spreadsheet/App/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(Spreadsheet_tests_run
|
||||
PropertySheet.cpp
|
||||
RenameProperty.cpp
|
||||
)
|
||||
|
||||
target_include_directories(Spreadsheet_tests_run PUBLIC
|
||||
${CMAKE_BINARY_DIR}
|
||||
)
|
||||
88
tests/src/Mod/Spreadsheet/App/PropertySheet.cpp
Normal file
88
tests/src/Mod/Spreadsheet/App/PropertySheet.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <Mod/Spreadsheet/App/Sheet.h>
|
||||
#include <Mod/Spreadsheet/App/PropertySheet.h>
|
||||
|
||||
class PropertySheetTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
void SetUp() override
|
||||
{
|
||||
_sheet = std::make_unique<Spreadsheet::Sheet>();
|
||||
_propertySheet = std::make_unique<Spreadsheet::PropertySheet>(_sheet.get());
|
||||
}
|
||||
void TearDown() override
|
||||
{
|
||||
_sheet.reset();
|
||||
_propertySheet.reset();
|
||||
}
|
||||
|
||||
/// Get a non-owning pointer to the internal PropertySheet for this test
|
||||
Spreadsheet::PropertySheet* propertySheet()
|
||||
{
|
||||
return _propertySheet.get();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<Spreadsheet::Sheet> _sheet;
|
||||
std::unique_ptr<Spreadsheet::PropertySheet> _propertySheet;
|
||||
};
|
||||
|
||||
TEST_F(PropertySheetTest, isValidCellAddressNameValidNames) // NOLINT
|
||||
{
|
||||
std::vector<std::string> validAddressNames {"A1", "Z1024", "AA42", "ZZ4096"};
|
||||
for (const auto& name : validAddressNames) {
|
||||
EXPECT_TRUE(propertySheet()->isValidCellAddressName(name))
|
||||
<< "\"" << name << "\" was not accepted as a cell name, and should be";
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PropertySheetTest, isValidCellAddressNameInvalidNames) // NOLINT
|
||||
{
|
||||
std::vector<std::string> invalidAddressNames {
|
||||
"Bork",
|
||||
"Bork_de_bork",
|
||||
"A",
|
||||
"42",
|
||||
"AAA1", // Too many characters to start, AAA is not a valid column
|
||||
"ZZ123456" // Too large a number to end, 123456 is not a valid row
|
||||
};
|
||||
for (const auto& name : invalidAddressNames) {
|
||||
EXPECT_FALSE(propertySheet()->isValidCellAddressName(name))
|
||||
<< "\"" << name << "\" was accepted as a cell name, and should not be";
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PropertySheetTest, validAliases) // NOLINT
|
||||
{
|
||||
std::vector<std::string> validAliases {
|
||||
"Bork",
|
||||
"Bork_de_bork"
|
||||
"A",
|
||||
"AA123456"
|
||||
};
|
||||
for (const auto& name : validAliases) {
|
||||
EXPECT_TRUE(propertySheet()->isValidAlias(name))
|
||||
<< "\"" << name << "\" was not accepted as an alias name, and should be";
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PropertySheetTest, invalidAliases) // NOLINT
|
||||
{
|
||||
std::vector<std::string>
|
||||
invalidAliases {"A1", "ZZ1234", "mm", "no spaces allowed", "\'NoLeadingQuotes"};
|
||||
|
||||
for (const auto& name : invalidAliases) {
|
||||
EXPECT_FALSE(propertySheet()->isValidAlias(name))
|
||||
<< "\"" << name << "\" was accepted as an alias name, and should not be";
|
||||
}
|
||||
}
|
||||
81
tests/src/Mod/Spreadsheet/App/RenameProperty.cpp
Normal file
81
tests/src/Mod/Spreadsheet/App/RenameProperty.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2025 Pieter Hijma <info@pieterhijma.net> *
|
||||
* *
|
||||
* 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 <Mod/Spreadsheet/App/Sheet.h>
|
||||
|
||||
#include "src/App/Property.h"
|
||||
|
||||
class SpreadsheetRenameProperty: public RenameProperty
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
RenameProperty::SetUp();
|
||||
sheet = freecad_cast<Spreadsheet::Sheet*>(_doc->addObject("Spreadsheet::Sheet", "Sheet"));
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
_doc->removeObject(sheet->getNameInDocument());
|
||||
RenameProperty::TearDown();
|
||||
}
|
||||
|
||||
Spreadsheet::Sheet* sheet {};
|
||||
};
|
||||
|
||||
std::string RenameProperty::_docName;
|
||||
App::Document* RenameProperty::_doc {nullptr};
|
||||
|
||||
// Tests whether we can rename a property that is used in a spreadsheet
|
||||
TEST_F(SpreadsheetRenameProperty, renameProperty)
|
||||
{
|
||||
// Arrange
|
||||
sheet->setCell("A1", "=VarSet.Variable");
|
||||
_doc->recompute();
|
||||
auto* propSpreadsheet = static_cast<App::PropertyInteger*>(sheet->getPropertyByName("A1"));
|
||||
|
||||
// Assert before the rename
|
||||
EXPECT_EQ(prop->getValue(), Value);
|
||||
EXPECT_EQ(propSpreadsheet->getValue(), Value);
|
||||
|
||||
// Act
|
||||
bool isRenamed = varSet->renameDynamicProperty(prop, "NewName");
|
||||
_doc->recompute();
|
||||
|
||||
// Assert after the rename
|
||||
EXPECT_TRUE(isRenamed);
|
||||
EXPECT_STREQ(varSet->getPropertyName(prop), "NewName");
|
||||
EXPECT_EQ(prop->getValue(), Value);
|
||||
|
||||
EXPECT_EQ(varSet->getDynamicPropertyByName("Variable"), nullptr);
|
||||
EXPECT_EQ(varSet->getDynamicPropertyByName("NewName"), prop);
|
||||
|
||||
std::string cellContent;
|
||||
sheet->getCell(App::CellAddress("A1"))->getStringContent(cellContent);
|
||||
|
||||
EXPECT_EQ(cellContent, "=VarSet.NewName");
|
||||
EXPECT_EQ(propSpreadsheet->getValue(), Value);
|
||||
}
|
||||
9
tests/src/Mod/Spreadsheet/CMakeLists.txt
Normal file
9
tests/src/Mod/Spreadsheet/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_link_libraries(Spreadsheet_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Spreadsheet
|
||||
)
|
||||
12
tests/src/Mod/Start/App/CMakeLists.txt
Normal file
12
tests/src/Mod/Start/App/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(Start_tests_run
|
||||
FileUtilities.cpp
|
||||
ThumbnailSource.cpp
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
Start_tests_run
|
||||
PUBLIC
|
||||
${CMAKE_BINARY_DIR}
|
||||
)
|
||||
96
tests/src/Mod/Start/App/FileUtilities.cpp
Normal file
96
tests/src/Mod/Start/App/FileUtilities.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <Mod/Start/App/FileUtilities.h>
|
||||
|
||||
|
||||
class FileUtilitiesTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizeZeroBytes)
|
||||
{
|
||||
auto result = Start::humanReadableSize(0);
|
||||
EXPECT_EQ(result, "0 B");
|
||||
}
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizeBytesHasNoDecimal)
|
||||
{
|
||||
constexpr uint64_t smallNumberOfBytes {512};
|
||||
auto result = Start::humanReadableSize(smallNumberOfBytes);
|
||||
EXPECT_EQ(result.find('.'), std::string::npos);
|
||||
}
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizeOthersHaveDecimal)
|
||||
{
|
||||
constexpr std::array<uint64_t, 6> testSizes {
|
||||
1000,
|
||||
123456,
|
||||
123456789,
|
||||
123456789013,
|
||||
100000000000000,
|
||||
std::numeric_limits<uint64_t>::max()
|
||||
};
|
||||
for (const auto size : testSizes) {
|
||||
auto result = Start::humanReadableSize(size);
|
||||
EXPECT_NE(result.find('.'), std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizeB)
|
||||
{
|
||||
EXPECT_EQ("999 B", Start::humanReadableSize(999));
|
||||
}
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizekB)
|
||||
{
|
||||
EXPECT_EQ("1.0 kB", Start::humanReadableSize(1000));
|
||||
}
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizekBSignificantDigits)
|
||||
{
|
||||
EXPECT_EQ(Start::humanReadableSize(1000), Start::humanReadableSize(1001));
|
||||
}
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizeMB)
|
||||
{
|
||||
EXPECT_EQ("2.5 MB", Start::humanReadableSize(2.5e6));
|
||||
}
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizeGB)
|
||||
{
|
||||
EXPECT_EQ("3.7 GB", Start::humanReadableSize(3.7e9));
|
||||
}
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizeTB)
|
||||
{
|
||||
EXPECT_EQ("444.8 TB", Start::humanReadableSize(444.823e12));
|
||||
}
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizePB)
|
||||
{
|
||||
EXPECT_EQ("1.2 PB", Start::humanReadableSize(1.2e15));
|
||||
}
|
||||
|
||||
TEST_F(FileUtilitiesTest, humanReadableSizeEB)
|
||||
{
|
||||
EXPECT_EQ("7.3 EB", Start::humanReadableSize(7.3e18));
|
||||
}
|
||||
26
tests/src/Mod/Start/App/ThumbnailSource.cpp
Normal file
26
tests/src/Mod/Start/App/ThumbnailSource.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "src/App/InitApplication.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <Mod/Start/App/ThumbnailSource.h>
|
||||
|
||||
class ThumbnailSourceTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
|
||||
private:
|
||||
};
|
||||
13
tests/src/Mod/Start/CMakeLists.txt
Normal file
13
tests/src/Mod/Start/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_include_directories(Start_tests_run PUBLIC
|
||||
${Python3_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(Start_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Start
|
||||
)
|
||||
Reference in New Issue
Block a user