Skip to content

Commit

Permalink
Toponaming: Missing shape hasher line; fixed cleaned Transformed
Browse files Browse the repository at this point in the history
  • Loading branch information
bgbsww authored and chennes committed Aug 13, 2024
1 parent aef3bdf commit a1ce983
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/App/StringHasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ size_t StringHasher::count() const
{
size_t count = 0;
for (auto& hasher : _hashes->right) {
if (hasher.second->getRefCount() > 1) {
if (hasher.second->isMarked() || hasher.second->isPersistent() ) {
++count;
}
}
Expand Down
40 changes: 20 additions & 20 deletions src/Mod/PartDesign/App/FeatureTransformed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,22 @@ App::DocumentObjectExecReturn* Transformed::execute()
return App::DocumentObject::StdReturn;
}

std::vector<App::DocumentObject*> originals;
auto const mode = static_cast<Mode>(TransformMode.getValue());
if (mode == Mode::TransformBody) {
Originals.setValues({});
Originals.setStatus(App::Property::Status::Hidden, true);
} else {
Originals.setStatus(App::Property::Status::Hidden, false);
originals = Originals.getValues();
}

std::vector<App::DocumentObject*> originals = Originals.getValues();
// Remove suppressed features from the list so the transformations behave as if they are not
// there
{
auto eraseIter =
std::remove_if(originals.begin(), originals.end(), [](App::DocumentObject const* obj) {
auto feature = Base::freecad_dynamic_cast<PartDesign::Feature>(obj);
return feature != nullptr && feature->Suppressed.getValue();
});
originals.erase(eraseIter, originals.end());
}
auto eraseIter =
std::remove_if(originals.begin(), originals.end(), [](App::DocumentObject const* obj) {
auto feature = Base::freecad_dynamic_cast<PartDesign::Feature>(obj);
return feature != nullptr && feature->Suppressed.getValue();
});
originals.erase(eraseIter, originals.end());

if (mode == Mode::TransformToolShapes && originals.empty()) {
return App::DocumentObject::StdReturn;
Expand Down Expand Up @@ -284,14 +284,15 @@ App::DocumentObjectExecReturn* Transformed::execute()

supportShape.setTransform(Base::Matrix4D());

auto getTransformedCompShape = [&](const auto& origShape) {
std::vector<TopoShape> shapes;
auto getTransformedCompShape = [&](const auto& supportShape, const auto& origShape) {
std::vector<TopoShape> shapes = {supportShape};
TopoShape shape (origShape);
int idx=1;
for ( const auto& transformIter : transformations ) {
auto transformIter = transformations.cbegin();
transformIter++;
for ( ; transformIter != transformations.end(); transformIter++) {
auto opName = Data::indexSuffix(idx++);
auto transformed = shape.makeElementTransform(transformIter, opName.c_str());
shapes.emplace_back(transformed);
shapes.emplace_back(shape.makeElementTransform(*transformIter, opName.c_str()));
}
return shapes;
};
Expand Down Expand Up @@ -339,17 +340,16 @@ App::DocumentObjectExecReturn* Transformed::execute()
}

#endif

if (!fuseShape.isNull()) {
supportShape.makeElementFuse(getTransformedCompShape(fuseShape.getShape()));
supportShape.makeElementFuse(getTransformedCompShape(supportShape, fuseShape));
}
if (!cutShape.isNull()) {
supportShape.makeElementFuse(getTransformedCompShape(cutShape.getShape()));
supportShape.makeElementCut(getTransformedCompShape(supportShape, cutShape));
}
}
break;
case Mode::TransformBody: {
supportShape.makeElementFuse(getTransformedCompShape(supportShape));
supportShape.makeElementFuse(getTransformedCompShape(supportShape, supportShape));
break;
}
}
Expand Down
28 changes: 22 additions & 6 deletions src/Mod/PartDesign/PartDesignTests/TestLinearPattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ def testXAxisLinearPattern(self):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
# 44 + 84 + 42 = 170. 44 - 8 = 36 / 9 = 4. 84-12 = 72 / 9 = 8. 42 - 6 = 36 / 9 = 4
# We have the original 26 from the first shape, plus 4 more vertices, 8 more edges and
# 4 more faces for each additional copy. Since they have to touch ( single shape rule ),
# We're adding 4 points to define each additional prism's new points, 8 edges makes sense,
# and 4 faces makes sense since we're defining essentially a tube, not a box for each copy.
# self.assertNotEqual(self.LinearPattern.Shape.ElementReverseMap["Vertex44"], "")
# self.assertNotEqual(self.LinearPattern.Shape.ElementReverseMap["Edge84"], "")
# self.assertNotEqual(self.LinearPattern.Shape.ElementReverseMap["Face42"], "")
#
# self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 170) # TODO
self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 26)

def testYAxisLinearPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
Expand All @@ -62,7 +72,8 @@ def testYAxisLinearPattern(self):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
# self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 170) # TODO
self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 26)

def testZAxisLinearPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
Expand All @@ -80,7 +91,8 @@ def testZAxisLinearPattern(self):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
# self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 170) # TODO
self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 26)

def testNormalSketchAxisLinearPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
Expand All @@ -101,7 +113,8 @@ def testNormalSketchAxisLinearPattern(self):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
# self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 170) # TODO
self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 26)

def testVerticalSketchAxisLinearPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
Expand All @@ -122,7 +135,8 @@ def testVerticalSketchAxisLinearPattern(self):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
# self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 170) # TODO
self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 26)

def testHorizontalSketchAxisLinearPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
Expand All @@ -143,7 +157,9 @@ def testHorizontalSketchAxisLinearPattern(self):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
# self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 170) # TODO
# self.assertEqual(len(self.LinearPattern.Shape.ElementReverseMap), 170)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize, 26)

def tearDown(self):
#closing doc
Expand Down
22 changes: 16 additions & 6 deletions src/Mod/PartDesign/PartDesignTests/TestPolarPattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def testXAxisPolarPattern(self):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
# self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 66) # TODO
self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 26)

def testYAxisPolarPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
Expand All @@ -62,7 +63,8 @@ def testYAxisPolarPattern(self):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
# self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 66) # TODO
self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 26)

def testZAxisPolarPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
Expand All @@ -80,7 +82,8 @@ def testZAxisPolarPattern(self):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
# self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 66) # TODO
self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 26)

def testNormalSketchAxisPolarPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
Expand All @@ -101,7 +104,8 @@ def testNormalSketchAxisPolarPattern(self):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
# self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 66) # TODO
self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 26)

def testVerticalSketchAxisPolarPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
Expand All @@ -122,7 +126,8 @@ def testVerticalSketchAxisPolarPattern(self):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
# self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 66) # TODO
self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 26)

def testHorizontalSketchAxisPolarPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
Expand All @@ -143,7 +148,12 @@ def testHorizontalSketchAxisPolarPattern(self):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
# 26 original plus 3 new instances:
# First and second have 4 new vertexes, 8 new edges and 5 new faces
# Final one has 2 new vertexes, 5 new edges and original loses one face.
# That makes 40.
# self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 66) # TODO
self.assertEqual(self.PolarPattern.Shape.ElementMapSize, 26)

def tearDown(self):
#closing doc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,7 @@ def testPartDesignElementMapSubPipe(self):
self.assertAlmostEqual(body.Shape.BoundBox.ZMax, 10)
self.assertEqual(len(body.Shape.childShapes()), 1)
self.assertEqual(body.Shape.childShapes()[0].ElementMapSize, 44)
revMap = pipe.Shape.ElementReverseMap
self.assertEqual(revMap['Vertex1'],"Vertex1")
self.assertEqual(revMap['Vertex8'],"Vertex8")
self.assertEqual(revMap['Edge1'],"Edge1")
self.assertEqual(revMap['Edge12'],"Edge12")
self.assertEqual(revMap['Face1'],"Face1")
self.assertEqual(revMap['Face6'],"Face6")
revMap = body.Shape.ElementReverseMap #
self.assertEqual(self.countFacesEdgesVertexes(revMap),(9,21,14))

def testPartDesignElementMapSubHelix(self):
Expand Down
5 changes: 4 additions & 1 deletion tests/src/App/StringHasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,10 @@ class StringHasherTest: public ::testing::Test
const std::string postfix {";:M;FUS;:Hb:7,F"};
auto mappedName = givenMappedName(prefix.c_str(), postfix.c_str());
QVector<App::StringIDRef> sids;
return Hasher()->getID(mappedName, sids);
auto ID = Hasher()->getID(mappedName, sids);
ID.mark(); // For this to be included in the count, and thus the memsize in needs to be
// marked.
return ID;
}

private:
Expand Down

0 comments on commit a1ce983

Please sign in to comment.