File size: 7,214 Bytes
985c397 | 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 26 27 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | // 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.
}
|