Skip to content

Commit f92e745

Browse files
authored
New section test (#159)
* Remove inoperative code for section of surfaces * New section test * test_sectionbyplane enhanced
1 parent 72d0bfb commit f92e745

File tree

6 files changed

+124
-65
lines changed

6 files changed

+124
-65
lines changed

src/Core/Geom/CommandSection.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@ CommandSection::~CommandSection()
4444
void CommandSection::validate()
4545
{
4646
for(unsigned int i=0;i<m_entities.size();i++){
47-
if(m_entities[i]->getDim()<2)
47+
if(m_entities[i]->getDim()<=2)
4848
throw TkUtil::Exception(TkUtil::UTF8String ("Seuls des volumes géométriques peuvent être découpés", TkUtil::Charset::UTF_8));
4949
}
5050

5151
int dim_tool = m_tool->getDim();
5252
if(dim_tool!=2)
5353
throw TkUtil::Exception(TkUtil::UTF8String ("L'outil de découpe doit être une surface", TkUtil::Charset::UTF_8));
54-
5554
}
5655
/*----------------------------------------------------------------------------*/
5756
void CommandSection::internalSpecificPreExecute()

src/Core/Geom/GeomSectionImplementation.cpp

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <BRepAlgoAPI_BuilderAlgo.hxx>
1313
#include <BRepAlgoAPI_Fuse.hxx>
1414
#include <BRepAlgoAPI_Common.hxx>
15+
#include <BRepAlgoAPI_Cut.hxx>
1516
#include <BRepFeat_Gluer.hxx>
1617
#include <TopTools_ListOfShape.hxx>
1718
/*----------------------------------------------------------------------------*/
@@ -67,10 +68,8 @@ void GeomSectionImplementation::perform(std::vector<GeomEntity*>& res)
6768
if(dim_ref==3){
6869
sectionVolumes(res);
6970
}
70-
else if(dim_ref==2)
71-
sectionSurfaces(res);
7271
else
73-
throw TkUtil::Exception (TkUtil::UTF8String ("La section géométrique ne s'applique qu'aux volumes ou surfaces", TkUtil::Charset::UTF_8));
72+
throw TkUtil::Exception (TkUtil::UTF8String ("La section géométrique ne s'applique qu'aux volumes", TkUtil::Charset::UTF_8));
7473

7574
}
7675
/*----------------------------------------------------------------------------*/
@@ -124,61 +123,6 @@ void GeomSectionImplementation::sectionVolumes(std::vector<GeomEntity*>& res)
124123
res.insert(res.end(), entities_new.begin(), entities_new.end());
125124
}
126125
/*----------------------------------------------------------------------------*/
127-
void GeomSectionImplementation::sectionSurfaces(std::vector<GeomEntity*>& res)
128-
{
129-
//========================================================================
130-
//1 - Recuperation de la surface de coupe
131-
//========================================================================
132-
TopoDS_Face tool_face = checkSurface(m_tool);
133-
134-
//========================================================================
135-
// 2 - Conservation du plan de coupe réduit aux objets coupés
136-
//========================================================================
137-
// On commence par fusionner toutes les entites a couper
138-
139-
GeomEntity* e1 = m_init_entities[0];
140-
// TopoDS_Shape s_fuse;
141-
// getOCCShape(e1, s_fuse);
142-
// for(unsigned int i=1;i<m_init_entities.size();i++){
143-
// GeomEntity* e2 = m_init_entities[i];
144-
// TopoDS_Shape s2;
145-
// getOCCShape(e2, s2);
146-
//
147-
// BRepAlgoAPI_Fuse fuse_operator(s_fuse,s2);
148-
// if(fuse_operator.IsDone())
149-
// s_fuse = fuse_operator.Shape();
150-
// else
151-
// throw TkUtil::Exception (TkUtil::UTF8String ("Problème OCC lors de l'union avant coupe", TkUtil::Charset::UTF_8);
152-
// }
153-
// // On recupere l'intersection de la surface wf et de l'union des entites à
154-
// // couper
155-
// BRepAlgoAPI_Common common_operator(s_fuse,tool_face);
156-
// if(common_operator.IsDone())
157-
// m_restricted_section_tool = common_operator.Shape();
158-
// else
159-
// throw TkUtil::Exception (TkUtil::UTF8String ("Problème OCC lors de l'intersection avant coupe", TkUtil::Charset::UTF_8);
160-
161-
//========================================================================
162-
//3 - Decoupe des entités
163-
//========================================================================
164-
TopoDS_Shape s;
165-
BRepAlgoAPI_BuilderAlgo splitter;
166-
TopTools_ListOfShape list_of_arguments;
167-
for (unsigned int i = 0; i < m_init_entities.size(); i++) {
168-
TopoDS_Shape si = checkSurface(m_init_entities[i]);
169-
list_of_arguments.Append(si);
170-
}
171-
list_of_arguments.Append(tool_face);
172-
splitter.Build();
173-
s = splitter.Shape();
174-
175-
176-
//createGeomEntitiesBut(s,tool_shape);
177-
createGeomEntities(s,true);
178-
179-
res.insert(res.end(), entities_new.begin(), entities_new.end());
180-
}
181-
/*----------------------------------------------------------------------------*/
182126
TopoDS_Face GeomSectionImplementation::
183127
checkSurface(GeomEntity* ge) const
184128
{

src/Core/protected/Geom/GeomSectionImplementation.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ class GeomSectionImplementation: public GeomModificationBaseClass{
6868
*/
6969
void sectionVolumes(std::vector<GeomEntity*>& res);
7070

71-
/*------------------------------------------------------------------------*/
72-
/** \brief réalisation de la coupe par m_tool
73-
*/
74-
void sectionSurfaces(std::vector<GeomEntity*>& res);
75-
7671
private:
7772
TopoDS_Face checkSurface(GeomEntity* ge) const;
7873
TopoDS_Shape checkVolume(GeomEntity* ge) const;

test_link/test_align_vertices.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def test_align_vertices(capfd):
1717
tm.alignVertices(Mgx3D.Point(0, 0, 1), Mgx3D.Point(0, 0, 0), ["Som0008"])
1818
assertPoint(tm, 0, 0, 0.5)
1919

20+
out, err = capfd.readouterr()
21+
assert len(err) == 0
22+
2023
def assertPoint(tm, x, y, z):
2124
p = tm.getCoord("Som0008")
2225
assert p.getX() == x

test_link/test_section.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import os
2+
import pyMagix3D as Mgx3D
3+
4+
def test_section_box1(capfd):
5+
ctx = Mgx3D.getStdContext()
6+
gm = ctx.getGeomManager()
7+
tm = ctx.getTopoManager()
8+
mm = ctx.getMeshManager()
9+
ctx.clearSession() # Clean the session after the previous test
10+
11+
# Création de la boite Vol0000
12+
gm.newBox (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), "A")
13+
# Création de la boite Vol0001
14+
gm.newBox (Mgx3D.Point(1, 0, 0), Mgx3D.Point(2, 1, 1), "B")
15+
# Collage entre Vol0000 Vol0001
16+
gm.glue (["Vol0000","Vol0001"])
17+
# Création d'un bloc topologique structuré sur une géométrie (Vol0000)
18+
ctx.getTopoManager().newStructuredTopoOnGeometry ("Vol0000")
19+
# Création d'un bloc topologique structuré sur une géométrie (Vol0001)
20+
ctx.getTopoManager().newStructuredTopoOnGeometry ("Vol0001")
21+
22+
# Création du sommet Pt0016 sur la courbe Crb0001
23+
gm.newVertex ("Crb0001", 5.000000e-01, "C")
24+
# Création du sommet Pt0017 sur la courbe Crb0003
25+
gm.newVertex ("Crb0003", 5.000000e-01, "C")
26+
# Création du sommet Pt0018 sur la courbe Crb0007
27+
gm.newVertex ("Crb0007", 5.000000e-01, "C")
28+
# Création du sommet Pt0019 sur la courbe Crb0005
29+
gm.newVertex ("Crb0005", 5.000000e-01, "C")
30+
31+
# Création du segment Crb0024
32+
gm.newSegment("Pt0016", "Pt0017", "C")
33+
# Création du segment Crb0025
34+
gm.newSegment("Pt0018", "Pt0017", "C")
35+
# Création du segment Crb0026
36+
gm.newSegment("Pt0019", "Pt0018", "C")
37+
# Création du segment Crb0027
38+
gm.newSegment("Pt0016", "Pt0019", "C")
39+
# Création de la surface Surf0012
40+
gm.newPlanarSurface (["Crb0024","Crb0025","Crb0026","Crb0027"], "C")
41+
42+
# Découpage suivant Ar0008 des blocs Bl0000
43+
tm.splitBlocks (["Bl0000"],"Ar0008", .5)
44+
# Section par un plan entre géométries avec topologies
45+
gm.section (["Vol0000"], "Surf0012")
46+
# Création du maillage pour tous les blocs
47+
mm.newAllBlocksMesh()
48+
# Sauvegarde du maillage (mli)
49+
filename = "section.mli2"
50+
mm.writeMli(filename)
51+
52+
assert os.path.exists(filename)
53+
assert os.path.getsize(filename) > 0
54+
assert gm.getNbVolumes() == 3
55+
assert gm.getNbSurfaces() == 17
56+
assert tm.getNbBlocks() == 3
57+
assert tm.getNbFaces() == 16
58+
assert mm.getNbFaces() == 1200
59+
60+
out, err = capfd.readouterr()
61+
assert len(err) == 0
62+
63+
64+
def test_section_box2(capfd):
65+
ctx = Mgx3D.getStdContext()
66+
gm = ctx.getGeomManager()
67+
ctx.clearSession() # Clean the session after the previous test
68+
69+
# Création de la boite Vol0000
70+
gm.newBox (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), "A")
71+
# Création de la boite Vol0001
72+
gm.newBox (Mgx3D.Point(1, 0, 0), Mgx3D.Point(2, 1, 1), "B")
73+
# Collage entre Vol0000 Vol0001
74+
gm.glue (["Vol0000","Vol0001"])
75+
# Création de la boite Vol0002
76+
gm.newBox (Mgx3D.Point(0, .9, 0), Mgx3D.Point(2, 1.3, 1), "C")
77+
# Section entre géométries
78+
gm.section (["Vol0000","Vol0001"], "Surf0014")
79+
80+
assert gm.getNbVolumes() == 5
81+
assert gm.getNbSurfaces() == 26
82+
83+
out, err = capfd.readouterr()
84+
assert len(err) == 0
85+
86+
87+
def test_section_box_by_cylinder(capfd):
88+
ctx = Mgx3D.getStdContext()
89+
gm = ctx.getGeomManager()
90+
ctx.clearSession() # Clean the session after the previous test
91+
92+
# Création de la boite Vol0000
93+
gm.newBox (Mgx3D.Point(-.1, -.25, -.1), Mgx3D.Point(.1, .25, .1), "A")
94+
# Création du cylindre Vol0001
95+
gm.newCylinder (Mgx3D.Point(-.25, 0, 0), 0.05, Mgx3D.Vector(.5, 0, 0), 3.600000e+02, "B")
96+
# Section suivant Surf0006 des entités Vol0000
97+
gm.section (["Vol0000"], "Surf0006")
98+
99+
assert gm.getNbVolumes() == 3
100+
assert gm.getNbSurfaces() == 12
101+
102+
out, err = capfd.readouterr()
103+
assert len(err) == 0

test_link/test_sectionbyplane.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
# pour laquelle un certain nombres de bug a été trouvé
55
# (cf. Issue#208)
66

7+
def test_cylinder(capfd):
8+
ctx = Mgx3D.getStdContext()
9+
ctx.clearSession() # Clean the session after the previous test
10+
gm = ctx.getGeomManager()
11+
12+
# Création du cylindre Vol0000
13+
gm.newCylinder (Mgx3D.Point(0, 0, 0), .1, Mgx3D.Vector(0, 0, 1), 180, "CYL")
14+
# Section par un plan de Vol0000 suivant [ [ 0, 0, .31833] , [ 0, 0, 1] ]
15+
gm.sectionByPlane (["Vol0000"], Mgx3D.Plane(Mgx3D.Point(0, 0, .31833), Mgx3D.Vector(0, 0, 1)), "XY")
16+
17+
assert gm.getNbVolumes() == 2
18+
assert gm.getNbSurfaces() == 9
19+
out, err = capfd.readouterr()
20+
assert len(err) == 0
21+
722
def test_3_boxes():
823
ctx = Mgx3D.getStdContext()
924
ctx.clearSession() # Clean the session after the previous test

0 commit comments

Comments
 (0)