| | |
| |
|
| | #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 |
| | {} |
| |
|
| | |
| | Part::Extrusion* _extrusion = nullptr; |
| | |
| | const double len = 3.0; |
| | const double wid = 4.0; |
| | const double ext1 = 10.0; |
| | |
| | }; |
| |
|
| | TEST_F(FeatureExtrusionTest, testMustExecute) |
| | { |
| | |
| | EXPECT_TRUE(_extrusion->mustExecute()); |
| | |
| | _doc->recompute(); |
| | |
| | EXPECT_FALSE(_extrusion->mustExecute()); |
| | |
| | _extrusion->Base.setValue(_extrusion->Base.getValue()); |
| | |
| | EXPECT_TRUE(_extrusion->mustExecute()); |
| | |
| | _doc->recompute(); |
| | |
| | EXPECT_FALSE(_extrusion->mustExecute()); |
| | |
| | _extrusion->Solid.setValue(Standard_True); |
| | |
| | EXPECT_TRUE(_extrusion->mustExecute()); |
| | |
| | _doc->recompute(); |
| | |
| | EXPECT_FALSE(_extrusion->mustExecute()); |
| | } |
| |
|
| | TEST_F(FeatureExtrusionTest, testGetProviderName) |
| | { |
| | |
| | _extrusion->execute(); |
| | const char* name = _extrusion->getViewProviderName(); |
| | |
| | EXPECT_STREQ(name, "PartGui::ViewProviderExtrusion"); |
| | } |
| |
|
| | |
| |
|
| | TEST_F(FeatureExtrusionTest, testFetchAxisLink) |
| | { |
| | |
| | |
| | |
| | } |
| |
|
| | |
| | |
| | |
| |
|
| | TEST_F(FeatureExtrusionTest, testExtrudeShape) |
| | { |
| | |
| | } |
| |
|
| | TEST_F(FeatureExtrusionTest, testComputeFinalParameters) |
| | { |
| | |
| | } |
| |
|
| | TEST_F(FeatureExtrusionTest, testExecuteSimple) |
| | { |
| | |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | 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; |
| | |
| | _extrusion->LengthFwd.setValue(0); |
| | _extrusion->LengthRev.setValue(ext2); |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | EXPECT_FLOAT_EQ(volume, len * wid * ext2); |
| | EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -ext2, len, wid, 0))); |
| | } |
| |
|
| | TEST_F(FeatureExtrusionTest, testExecuteSolid) |
| | { |
| | |
| | _extrusion->Solid.setValue(true); |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | EXPECT_FLOAT_EQ(volume, len * wid * ext1); |
| | EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, len, wid, ext1))); |
| | } |
| |
|
| | TEST_F(FeatureExtrusionTest, testExecuteReverse) |
| | { |
| | |
| | _extrusion->Reversed.setValue(true); |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | EXPECT_FLOAT_EQ(volume, len * wid * ext1); |
| | EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -ext1, len, wid, 0))); |
| | } |
| |
|
| | TEST_F(FeatureExtrusionTest, testExecuteSymmetric) |
| | { |
| | |
| | _extrusion->Symmetric.setValue(true); |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | 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) |
| | { |
| | |
| | const double ang = 30; |
| | const double tangent = tan(Base::toRadians(ang)); |
| |
|
| | |
| | |
| | const double shorterSide = len > wid ? wid : len; |
| | const double longerSide = len < wid ? wid : len; |
| | const double centerWidth = longerSide - shorterSide; |
| | const double topHeight = shorterSide / tangent / 2; |
| | 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); |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | 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) |
| | { |
| | |
| | const double ang = 30; |
| | const double tangent = tan(Base::toRadians(ang)); |
| | |
| | |
| | |
| | const double shorterSide = len > wid ? wid : len; |
| | const double longerSide = len < wid ? wid : len; |
| | const double centerWidth = longerSide - shorterSide; |
| | const double topHeight = shorterSide / tangent / 2; |
| | 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); |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | 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) |
| | { |
| | |
| | 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); |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | 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) |
| | { |
| | |
| | const double sin45 = sin(Base::toRadians(45.0)); |
| | _extrusion->Dir.setValue(Base::Vector3d(0, 1, 1)); |
| | _extrusion->DirMode.setValue((long)0); |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | 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) |
| | { |
| | |
| | _extrusion->FaceMakerClass.setValue("Part::FaceMakerCheese"); |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | EXPECT_FLOAT_EQ(volume, len * wid * ext1); |
| | EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, len, wid, ext1))); |
| | } |
| |
|
| | TEST_F(FeatureExtrusionTest, testFaceWithHoles) |
| | { |
| | |
| | float radius = 0.75; |
| | auto [face1, wire1, wire2] = PartTestHelpers::CreateFaceWithRoundHole(len, wid, radius); |
| | |
| | Part::TopoShape newFace = Part::TopoShape(face1).makeElementFace(nullptr); |
| | |
| | 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"); |
| | |
| | _extrusion->execute(); |
| | Part::TopoShape ts = _extrusion->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| | |
| | 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); |
| | } |
| |
|