Skip to content

Commit bfbb267

Browse files
committed
Fix bug on surfaces section
1 parent ff46b56 commit bfbb267

File tree

2 files changed

+56
-20
lines changed

2 files changed

+56
-20
lines changed

src/Core/Geom/GeomSectionByPlaneImplementation.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,35 @@ void GeomSectionByPlaneImplementation::split(std::vector<GeomEntity*>& res)
8787
#ifdef _DEBUG2
8888
std::cout<<"m_init_entities.size = "<<m_init_entities.size()<<std::endl;
8989
#endif
90-
GeomEntity* e1 = m_init_entities[0];
91-
TopoDS_Shape s_fuse;
92-
getUniqueOCCShape(e1, s_fuse);
93-
for(unsigned int i=1;i<m_init_entities.size();i++){
94-
GeomEntity* e2 = m_init_entities[i];
95-
TopoDS_Shape s2;
96-
getUniqueOCCShape(e2, s2);
90+
bool all_volumes = std::all_of(m_init_entities.begin(), m_init_entities.end(), [](GeomEntity* x) {
91+
return (x->getDim() == 3);
92+
});
9793

98-
BRepAlgoAPI_Fuse fuse_operator(s_fuse,s2);
99-
if(fuse_operator.IsDone())
100-
s_fuse = fuse_operator.Shape();
94+
if (all_volumes) {
95+
GeomEntity* e1 = m_init_entities[0];
96+
TopoDS_Shape s_fuse;
97+
getUniqueOCCShape(e1, s_fuse);
98+
for(unsigned int i=1;i<m_init_entities.size();i++){
99+
GeomEntity* e2 = m_init_entities[i];
100+
TopoDS_Shape s2;
101+
getUniqueOCCShape(e2, s2);
102+
103+
BRepAlgoAPI_Fuse fuse_operator(s_fuse,s2);
104+
if(fuse_operator.IsDone())
105+
s_fuse = fuse_operator.Shape();
106+
else
107+
throw TkUtil::Exception (TkUtil::UTF8String ("Problème OCC lors de l'union avant coupe", TkUtil::Charset::UTF_8));
108+
}
109+
// On recupere l'intersection de la surface wf et de l'union des entites à couper
110+
BRepAlgoAPI_Common common_operator(s_fuse, wf);
111+
if(common_operator.IsDone())
112+
m_restricted_section_tool = common_operator.Shape();
101113
else
102-
throw TkUtil::Exception (TkUtil::UTF8String ("Problème OCC lors de l'union avant coupe", TkUtil::Charset::UTF_8));
114+
throw TkUtil::Exception (TkUtil::UTF8String ("Problème OCC lors de l'intersection avant coupe", TkUtil::Charset::UTF_8));
115+
} else {
116+
// les opérations fuse + common ne fonctionnent pas s'il y a une surface
117+
m_restricted_section_tool = wf;
103118
}
104-
// On recupere l'intersection de la surface wf et de l'union des entites à couper
105-
BRepAlgoAPI_Common common_operator(s_fuse,wf);
106-
if(common_operator.IsDone())
107-
m_restricted_section_tool = common_operator.Shape();
108-
else
109-
throw TkUtil::Exception (TkUtil::UTF8String ("Problème OCC lors de l'intersection avant coupe", TkUtil::Charset::UTF_8));
110119

111120
//========================================================================
112121
// 3 - Decoupe des entités
Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import pyMagix3D as Mgx3D
22

3-
def test_issue208_2_sectionByPlane():
3+
# Tests de la fonction sectionByPlane du GeomManager
4+
# pour laquelle un certain nombres de bug a été trouvé
5+
# (cf. Issue#208)
6+
7+
def test_3_boxes():
48
ctx = Mgx3D.getStdContext()
59
ctx.clearSession() # Clean the session after the previous test
610
gm = ctx.getGeomManager()
@@ -34,7 +38,7 @@ def test_issue208_2_sectionByPlane():
3438
ctx.redo()
3539
assert gm.getNbVolumes() == 5
3640

37-
def test_issue208_single_sectionByPlane():
41+
def test_3_boxes_two_sections():
3842
ctx = Mgx3D.getStdContext()
3943
ctx.clearSession() # Clean the session after the previous test
4044
gm = ctx.getGeomManager()
@@ -58,7 +62,7 @@ def test_issue208_single_sectionByPlane():
5862
ctx.redo()
5963
assert gm.getNbVolumes() == 5
6064

61-
def test_issue208_nested_volumes():
65+
def test_nested_spheres():
6266
ctx = Mgx3D.getStdContext()
6367
ctx.clearSession() # Clean the session after the previous test
6468
gm = ctx.getGeomManager()
@@ -84,3 +88,26 @@ def test_issue208_nested_volumes():
8488
# Des volumes sont créés en double => 6 volumes au lieu de 4
8589
assert gm.getNbVolumes() == 4
8690
assert gm.getNbSurfaces() == 6
91+
92+
def test_nested_surfaces():
93+
ctx = Mgx3D.getStdContext()
94+
ctx.clearSession() # Clean the session after the previous test
95+
gm = ctx.getGeomManager()
96+
97+
# Création d'une boite avec une topologie
98+
gm.newBox(Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1))
99+
# Création d'une boite avec une topologie
100+
gm.newBox(Mgx3D.Point(-1, -1, -1), Mgx3D.Point(1, 2, 2))
101+
# Collage entre Vol0000 Vol0001
102+
gm.glue (["Vol0000","Vol0001"])
103+
# Destruction de Vol0002 Vol0000
104+
gm.destroy(["Vol0002", "Vol0000"], False)
105+
assert gm.getNbSurfaces() == 12
106+
107+
# Section par un plan de Surf0012 suivant [ [ 1, .5, 0] , [ 0, 1, 0] ]
108+
gm.sectionByPlane (["Surf0012"], Mgx3D.Plane(Mgx3D.Point(1, .5, 0), Mgx3D.Vector(0, 1, 0)), "")
109+
assert gm.getNbSurfaces() == 13
110+
ctx.undo()
111+
assert gm.getNbSurfaces() == 12
112+
gm.sectionByPlane (["Surf0012", "Surf0001"], Mgx3D.Plane(Mgx3D.Point(1, .5, 0), Mgx3D.Vector(0, 1, 0)), "")
113+
assert gm.getNbSurfaces() == 14

0 commit comments

Comments
 (0)