Toponaming/Part: clean and test attacher

This commit is contained in:
bgbsww
2024-03-12 11:20:56 -04:00
parent bb24c1554c
commit 72669ab6a6
5 changed files with 881 additions and 508 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -440,10 +440,10 @@ class PartExport AttachEngine3D : public AttachEngine
public:
AttachEngine3D();
AttachEngine3D* copy() const override;
virtual Base::Placement _calculateAttachedPlacement(
Base::Placement _calculateAttachedPlacement(
const std::vector<App::DocumentObject*> &objs,
const std::vector<std::string> &subs,
const Base::Placement &origPlacement) const;
const Base::Placement &origPlacement) const override;
private:
double calculateFoldAngle(gp_Vec axA, gp_Vec axB, gp_Vec edA, gp_Vec edB) const;
};
@@ -455,10 +455,10 @@ class PartExport AttachEnginePlane : public AttachEngine
public:
AttachEnginePlane();
AttachEnginePlane* copy() const override;
virtual Base::Placement _calculateAttachedPlacement(
Base::Placement _calculateAttachedPlacement(
const std::vector<App::DocumentObject*> &objs,
const std::vector<std::string> &subs,
const Base::Placement &origPlacement) const;
const Base::Placement &origPlacement) const override;
};
//attacher specialized for datum lines
@@ -468,10 +468,10 @@ class PartExport AttachEngineLine : public AttachEngine
public:
AttachEngineLine();
AttachEngineLine* copy() const override;
virtual Base::Placement _calculateAttachedPlacement(
Base::Placement _calculateAttachedPlacement(
const std::vector<App::DocumentObject*> &objs,
const std::vector<std::string> &subs,
const Base::Placement &origPlacement) const;
const Base::Placement &origPlacement) const override;
};
//attacher specialized for datum points
@@ -481,10 +481,10 @@ class PartExport AttachEnginePoint : public AttachEngine
public:
AttachEnginePoint();
AttachEnginePoint* copy() const override;
virtual Base::Placement _calculateAttachedPlacement(
Base::Placement _calculateAttachedPlacement(
const std::vector<App::DocumentObject*> &objs,
const std::vector<std::string> &subs,
const Base::Placement &origPlacement) const;
const Base::Placement &origPlacement) const override;
private:
gp_Pnt getProximityPoint(eMapMode mode, const TopoDS_Shape& s1, const TopoDS_Shape& s2) const;

View File

@@ -0,0 +1,104 @@
// 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 all
* only look at one of them - to prove that adding elementMap code doesn't break anything. A
* comprehensive test of the Attacher would definitely want to try many more code paths.
*/
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 TopoDS_Shape*> result;
auto faces = _boxes[1]->Shape.getShape().getSubShapes(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);
}

View File

@@ -2,6 +2,7 @@
target_sources(
Part_tests_run
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Attacher.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BRepMesh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/FeatureChamfer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/FeatureCompound.cpp

View File

@@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "gtest/gtest.h"
#include "PartTestHelpers.h"
#include <Mod/Part/App/TopoShape.h>
// clang-format off
@@ -87,4 +88,21 @@ TEST(TopoShape, TestTypeNull)
EXPECT_EQ(Part::TopoShape::getTypeAndIndex(nullptr),
std::make_pair(std::string(), 0UL));
}
TEST(TopoShape, 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