Fix shape color / materials issues in fuse

This commit is contained in:
bgbsww
2024-08-18 20:19:28 -04:00
committed by Chris Hennes
parent e020d9d5aa
commit 9de8fc9bec
2 changed files with 38 additions and 4 deletions

View File

@@ -251,10 +251,8 @@ App::DocumentObjectExecReturn *MultiFuse::execute()
throw Base::RuntimeError("MultiFusion failed");
}
// TopoDS_Shape resShape = mkFuse.Shape();
TopoShape res(0);
res.makeShapeWithElementMap(mkFuse.Shape(), MapperMaker(mkFuse), shapes, OpCodes::Fuse);
res = res.makeShapeWithElementMap(mkFuse.Shape(), MapperMaker(mkFuse), shapes, OpCodes::Fuse);
for (const auto& it2 : shapes) {
history.push_back(
buildHistory(mkFuse, TopAbs_FACE, res.getShape(), it2.getShape()));
@@ -276,7 +274,15 @@ App::DocumentObjectExecReturn *MultiFuse::execute()
}
if (this->Refine.getValue()) {
try {
res = res.makeElementRefine();
TopoDS_Shape oldShape = res.getShape();
BRepBuilderAPI_RefineModel mkRefine(oldShape);
// We just built an element map above for the fuse, don't erase it for a refine.
res.setShape(mkRefine.Shape(), false);
ShapeHistory hist =
buildHistory(mkRefine, TopAbs_FACE, res.getShape(), oldShape);
for (auto& jt : history) {
jt = joinHistory(jt, hist);
}
}
catch (Standard_Failure&) {
// do nothing

View File

@@ -136,6 +136,34 @@ class TestTopologicalNamingProblem(unittest.TestCase):
self.assertEqual(len(edges), 4)
self.assertEqual(len(vertexes), 4)
def testPartDesignBasicFusion(self):
""" Test that a basic fusion creates an element map, and refine retains it """
# Arrange
doc = self.Doc
box1 = doc.addObject("Part::Box","Box")
if App.GuiUp:
mat = App.Material()
mat.AmbientColor = (128,0,0)
box1.ViewObject.ShapeAppearance = mat # Change color ( material ) for at least one
box2 = doc.addObject("Part::Box","Box001")
box3 = doc.addObject("Part::Box","Box002")
cyl1 = doc.addObject("Part::Cylinder","Cylinder")
fuse1 = doc.addObject("Part::MultiFuse","Fusion")
doc.Fusion.Shapes = [box1, box2]
fuse2 = doc.addObject("Part::MultiFuse","Fusion001")
doc.Fusion001.Shapes = [box3, cyl1]
doc.recompute()
# Assert
self.assertEqual(fuse1.Shape.ElementMapSize,26)
self.assertEqual(fuse2.Shape.ElementMapSize,44)
# Act
doc.Fusion.Refine = True # activate refinement
doc.Fusion001.Refine = True # activate refinement
doc.recompute()
self.assertEqual(fuse1.Shape.ElementMapSize,26)
self.assertEqual(fuse2.Shape.ElementMapSize,44)
def testPartDesignElementMapPad(self):
""" Test that padding a sketch results in a correct element map. Note that comprehensive testing
of the geometric functionality of the Pad is in TestPad.py """