Toponaming: Additional element map changes to transform

This commit is contained in:
bgbsww
2024-08-06 21:29:42 -04:00
committed by Chris Hennes
parent f6c8850e80
commit 2b97b20a03
5 changed files with 34 additions and 78 deletions

View File

@@ -282,38 +282,15 @@ App::DocumentObjectExecReturn* Transformed::execute()
gp_Trsf trsfInv = supportShape.getShape().Location().Transformation().Inverted();
supportShape.setTransform(Base::Matrix4D());
TopoDS_Shape support = supportShape.getShape();
auto getTransformedCompShape = [&](const auto& origShape) {
TopTools_ListOfShape shapeTools;
std::vector<TopoDS_Shape> shapes;
std::vector<TopoShape> shapes;
TopoShape shape = origShape;
auto transformIter = transformations.cbegin();
// First transformation is skipped since it should not be part of the toolShape.
++transformIter;
for (; transformIter != transformations.end(); ++transformIter) {
// Make an explicit copy of the shape because the "true" parameter to
// BRepBuilderAPI_Transform seems to be pretty broken
BRepBuilderAPI_Copy copy(origShape);
TopoDS_Shape shape = copy.Shape();
BRepBuilderAPI_Transform mkTrf(shape, *transformIter, false); // No need to copy, now
if (!mkTrf.IsDone()) {
throw Base::CADKernelError(QT_TRANSLATE_NOOP("Exception", "Transformation failed"));
}
shape = mkTrf.Shape();
shapes.emplace_back(shape);
shapes.emplace_back(shape.makeElementTransform(*transformIter));
}
for (const auto& shape : shapes) {
shapeTools.Append(shape);
}
return shapeTools;
return shapes;
};
switch (mode) {
@@ -360,74 +337,41 @@ App::DocumentObjectExecReturn* Transformed::execute()
#endif
TopoDS_Shape current = support;
if (!fuseShape.isNull()) {
TopTools_ListOfShape shapeArguments;
shapeArguments.Append(current);
TopTools_ListOfShape shapeTools = getTransformedCompShape(fuseShape.getShape());
if (!shapeTools.IsEmpty()) {
BRepAlgoAPI_Fuse mkBool;
mkBool.SetArguments(shapeArguments);
mkBool.SetTools(shapeTools);
mkBool.Build();
if (!mkBool.IsDone()) {
return new App::DocumentObjectExecReturn(
QT_TRANSLATE_NOOP("Exception", "Boolean operation failed"));
}
current = mkBool.Shape();
}
supportShape = supportShape.makeElementFuse(getTransformedCompShape(fuseShape.getShape()));
}
if (!cutShape.isNull()) {
TopTools_ListOfShape shapeArguments;
shapeArguments.Append(current);
TopTools_ListOfShape shapeTools = getTransformedCompShape(cutShape.getShape());
if (!shapeTools.IsEmpty()) {
BRepAlgoAPI_Cut mkBool;
mkBool.SetArguments(shapeArguments);
mkBool.SetTools(shapeTools);
mkBool.Build();
if (!mkBool.IsDone()) {
return new App::DocumentObjectExecReturn(
QT_TRANSLATE_NOOP("Exception", "Boolean operation failed"));
}
current = mkBool.Shape();
}
supportShape = supportShape.makeElementCut(getTransformedCompShape(cutShape.getShape()));
}
support = current; // Use result of this operation for fuse/cut of next original
}
break;
case Mode::TransformBody: {
TopTools_ListOfShape shapeArguments;
shapeArguments.Append(support);
TopTools_ListOfShape shapeTools = getTransformedCompShape(support);
if (!shapeTools.IsEmpty()) {
BRepAlgoAPI_Fuse mkBool;
mkBool.SetArguments(shapeArguments);
mkBool.SetTools(shapeTools);
mkBool.Build();
if (!mkBool.IsDone()) {
return new App::DocumentObjectExecReturn(
QT_TRANSLATE_NOOP("Exception", "Boolean operation failed"));
}
support = mkBool.Shape();
}
supportShape = supportShape.makeElementFuse(getTransformedCompShape(supportShape));
break;
}
}
support = refineShapeIfActive(support);
if (!isSingleSolidRuleSatisfied(support)) {
supportShape = refineShapeIfActive((supportShape));
if (!isSingleSolidRuleSatisfied(supportShape.getShape())) {
Base::Console().Warning("Transformed: Result has multiple solids. Only keeping the first.\n");
}
this->Shape.setValue(getSolid(support)); // picking the first solid
rejected = getRemainingSolids(support);
this->Shape.setValue(getSolid(supportShape)); // picking the first solid
rejected = getRemainingSolids(supportShape.getShape());
return App::DocumentObject::StdReturn;
}
TopoShape Transformed::refineShapeIfActive(const TopoShape& oldShape) const
{
if (this->Refine.getValue()) {
return oldShape.makeElementRefine();
}
return oldShape;
}
// Deprecated, prefer the TopoShape method
TopoDS_Shape Transformed::refineShapeIfActive(const TopoDS_Shape& oldShape) const
{
if (this->Refine.getValue()) {

View File

@@ -106,6 +106,7 @@ protected:
App::Property* prop) override;
virtual void positionBySupport();
TopoShape refineShapeIfActive(const TopoShape&) const;
TopoDS_Shape refineShapeIfActive(const TopoDS_Shape&) const;
static TopoDS_Shape getRemainingSolids(const TopoDS_Shape&);

View File

@@ -44,6 +44,7 @@ class TestLinearPattern(unittest.TestCase):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
def testYAxisLinearPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
@@ -61,6 +62,7 @@ class TestLinearPattern(unittest.TestCase):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
def testZAxisLinearPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
@@ -78,6 +80,7 @@ class TestLinearPattern(unittest.TestCase):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
def testNormalSketchAxisLinearPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
@@ -98,6 +101,7 @@ class TestLinearPattern(unittest.TestCase):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
def testVerticalSketchAxisLinearPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
@@ -118,6 +122,7 @@ class TestLinearPattern(unittest.TestCase):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
def testHorizontalSketchAxisLinearPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
@@ -138,6 +143,7 @@ class TestLinearPattern(unittest.TestCase):
self.Body.addObject(self.LinearPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4)
self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26)
def tearDown(self):
#closing doc

View File

@@ -44,6 +44,7 @@ class TestPolarPattern(unittest.TestCase):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
def testYAxisPolarPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
@@ -61,6 +62,7 @@ class TestPolarPattern(unittest.TestCase):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
def testZAxisPolarPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
@@ -78,6 +80,7 @@ class TestPolarPattern(unittest.TestCase):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
def testNormalSketchAxisPolarPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
@@ -98,6 +101,7 @@ class TestPolarPattern(unittest.TestCase):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
def testVerticalSketchAxisPolarPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
@@ -118,6 +122,7 @@ class TestPolarPattern(unittest.TestCase):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
def testHorizontalSketchAxisPolarPattern(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
@@ -138,6 +143,7 @@ class TestPolarPattern(unittest.TestCase):
self.Body.addObject(self.PolarPattern)
self.Doc.recompute()
self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000)
self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26)
def tearDown(self):
#closing doc

View File

@@ -11384,7 +11384,6 @@ App::ElementNamePair SketchObject::getElementName(
index.appendToStringBuffer(ret.oldName);
if (auto realName = convertInternalName(ret.oldName.c_str())) {
Data::MappedElement mappedElement;
(void)realName;
if (mapped)
mappedElement = InternalShape.getShape().getElementName(name);
else if (type == ElementNameType::Export)