Skip to content

Commit fa791ad

Browse files
committed
Add test_trou_oblong
Add coord_comp module to find point, curve and surface correspondences between 2 versions of magix3d (with a subsequent impact on ids)
1 parent 51985fd commit fa791ad

File tree

2 files changed

+205
-0
lines changed

2 files changed

+205
-0
lines changed

test_link/coord_comp.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import math
2+
import csv
3+
import itertools
4+
5+
def ecrire_points(gm, fichier):
6+
points = gm.getVertices()
7+
8+
with open(fichier + "_points.csv", "w", encoding="utf-8") as f:
9+
# Écriture d'un en-tête
10+
f.write("Nom_Point;X;Y;Z\n")
11+
12+
# Parcours de tous les points
13+
for nom_point in points:
14+
coord = gm.getCoord(nom_point)
15+
x = coord.getX()
16+
y = coord.getY()
17+
z = coord.getZ()
18+
19+
# Écriture de la ligne correspondante
20+
f.write(f"{nom_point};{x};{y};{z}\n")
21+
22+
23+
def distance(p1, p2):
24+
"""Calcule la distance euclidienne entre deux points 3D."""
25+
return math.sqrt((p1[0] - p2[0])**2 +
26+
(p1[1] - p2[1])**2 +
27+
(p1[2] - p2[2])**2)
28+
29+
30+
def lire_points(fichier):
31+
"""Lit un fichier de points et retourne un dict {nom: (x, y, z)}"""
32+
points = {}
33+
with open(fichier + "_points.csv", newline='', encoding='utf-8') as f:
34+
lecteur = csv.DictReader(f, delimiter=';')
35+
for ligne in lecteur:
36+
nom = ligne['Nom_Point']
37+
x = float(ligne['X'])
38+
y = float(ligne['Y'])
39+
z = float(ligne['Z'])
40+
points[nom] = (x, y, z)
41+
return points
42+
43+
44+
def ecrire_courbes(gm, fichier):
45+
with open(fichier + "_courbes.csv", "w", encoding="utf-8", newline='') as f:
46+
writer = csv.writer(f, delimiter=';')
47+
writer.writerow(["Nom_Courbe", "Points"])
48+
49+
for curve_name in gm.getCurves():
50+
# Récupération de la liste des points de la courbe
51+
pts = gm.getInfos(curve_name, 1).vertices()
52+
writer.writerow([curve_name] + pts)
53+
54+
55+
def ecrire_surfaces(gm, fichier):
56+
"""
57+
Exporte les surfaces d'un objet gm dans un fichier texte.
58+
Chaque ligne contient : Nom_Surface;Point1;Point2;Point3;...
59+
"""
60+
61+
ecrire_points(gm, fichier)
62+
ecrire_courbes(gm, fichier)
63+
64+
with open(fichier + "_surfaces.csv", "w", encoding="utf-8", newline='') as f:
65+
writer = csv.writer(f, delimiter=';')
66+
writer.writerow(["Nom_Surface", "Points"])
67+
68+
for surf_name in gm.getSurfaces():
69+
# Récupération de la liste des points de la surface
70+
pts = gm.getInfos(surf_name, 2).vertices()
71+
writer.writerow([surf_name] + pts)
72+
73+
74+
def lire_courbes(fichier):
75+
courbes = {}
76+
with open(fichier + "_courbes.csv", newline='', encoding='utf-8') as f:
77+
lecteur = csv.reader(f, delimiter=';')
78+
next(lecteur) # ignorer l'en-tête
79+
for ligne in lecteur:
80+
nom_courbe = ligne[0]
81+
points = ligne[1:]
82+
courbes[nom_courbe] = points
83+
return courbes
84+
85+
86+
def lire_surfaces(fichier):
87+
"""
88+
Lit un fichier de surfaces et retourne un dict :
89+
{nom_surface: [liste_points]}
90+
"""
91+
surfaces = {}
92+
with open(fichier + "_surfaces.csv", newline='', encoding='utf-8') as f:
93+
lecteur = csv.reader(f, delimiter=';')
94+
next(lecteur) # ignorer l'en-tête
95+
for ligne in lecteur:
96+
nom_surface = ligne[0]
97+
points = ligne[1:]
98+
surfaces[nom_surface] = points
99+
return surfaces
100+
101+
102+
def ecrire_correspondances(fichier1, fichier2, epsilon=1e-8):
103+
# Trouve les correspondances entre deux fichiers de points.
104+
pts1 = lire_points(fichier1)
105+
pts2 = lire_points(fichier2)
106+
corr_pts = {}
107+
for nom1, coord1 in pts1.items():
108+
candidats = []
109+
for nom2, coord2 in pts2.items():
110+
if math.dist(coord1, coord2) <= epsilon:
111+
candidats.append(nom2)
112+
corr_pts[nom1] = candidats
113+
print(corr_pts)
114+
115+
# Trouve les correspondances entre les courbes.
116+
cvr1 = lire_courbes(fichier1)
117+
cvr2 = lire_courbes(fichier2)
118+
119+
corr_crvs = []
120+
for nom1, pts1 in cvr1.items():
121+
# Liste de candidats pour chaque point
122+
candidats_par_point = [corr_pts[p] for p in pts1]
123+
# Test de toutes les combinaisons possibles
124+
for combinaison in itertools.product(*candidats_par_point):
125+
if set(combinaison) in [set(s) for s in cvr2.values()]:
126+
# Récupérer le nom de la courbe correspondante dans cvr2
127+
for nom2, pts2 in cvr2.items():
128+
if set(combinaison) == set(pts2):
129+
corr_crvs.append((nom1, nom2))
130+
break
131+
break
132+
print(corr_crvs)
133+
134+
# Trouve les correspondances entre les surfaces
135+
surf1 = lire_surfaces(fichier1)
136+
surf2 = lire_surfaces(fichier2)
137+
138+
corr_surfs = []
139+
for nom1, pts1 in surf1.items():
140+
# Liste de candidats pour chaque point
141+
candidats_par_point = [corr_pts[p] for p in pts1]
142+
# Test de toutes les combinaisons possibles
143+
for combinaison in itertools.product(*candidats_par_point):
144+
if set(combinaison) in [set(s) for s in surf2.values()]:
145+
# Récupérer le nom de la surface correspondante dans surf2
146+
for nom2, pts2 in surf2.items():
147+
if set(combinaison) == set(pts2):
148+
corr_surfs.append((nom1, nom2))
149+
break
150+
break
151+
print(corr_surfs)

test_link/test_extrusion.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,57 @@ def test_makeRevol_groups():
164164
assert sorted(grm.getGeomCurves("PLAN", 1)) == ['Crb0004', 'Crb0005']
165165
assert sorted(grm.getGeomCurves("PZ0_PLAN", 1)) == ['Crb0006', 'Crb0007', 'Crb0008', 'Crb0009', 'Crb0010', 'Crb0011', 'Crb0012']
166166
assert grm.getGeomVertices("PLAN", 0) == []
167+
168+
def test_trou_oblong(capfd):
169+
ctx = Mgx3D.getStdContext()
170+
ctx.clearSession() # Clean the session after the previous test
171+
gm = ctx.getGeomManager()
172+
173+
# Changement d'unité de longueur
174+
ctx.setLengthUnit(Mgx3D.Unit.micron)
175+
# Création du sommet Pt0000
176+
gm.newVertex (Mgx3D.Point(0, 0, 0))
177+
# Création du sommet Pt0001
178+
gm.newVertex (Mgx3D.Point(-30, 0, 0))
179+
# Création du sommet Pt0002
180+
gm.newVertex (Mgx3D.Point(-30, 415, 0))
181+
# Création du sommet Pt0003
182+
gm.newVertex (Mgx3D.Point(0, 415, 0))
183+
# Création du sommet Pt0004
184+
gm.newVertex (Mgx3D.Point(-15, 415, 0))
185+
# Création du segment Crb0000
186+
gm.newSegment("Pt0003", "Pt0000")
187+
# Création du segment Crb0001
188+
gm.newSegment("Pt0000", "Pt0001")
189+
# Création du segment Crb0002
190+
gm.newSegment("Pt0001", "Pt0002")
191+
# Création de l'arc de cercle Crb0003
192+
gm.newArcCircle("Pt0004", "Pt0003", "Pt0002", False)
193+
# Création de la surface Surf0000
194+
gm.newPlanarSurface (["Crb0000","Crb0001","Crb0002","Crb0003"], "")
195+
# Modifie le groupe TROU
196+
gm.addToGroup (["Surf0000"], 2, "TROU")
197+
# Révolution de Surf0000
198+
gm.makeRevol (["Surf0000"], Mgx3D.RotX(180), False)
199+
# Extrusion de Surf0004
200+
gm.makeExtrude (["Surf0004"], Mgx3D.Vector(0, 0, -700), False)
201+
# Modifie le groupe TROU
202+
gm.addToGroup (["Vol0001"], 3, "TROU")
203+
# Copie de Vol0000 Vol0001
204+
gm.copy (["Vol0000","Vol0001"], False,"B")
205+
# Rotation de Vol0003 Vol0002 suivant [ [ 0, 0, 0] , [ 1, 0, 0] , 180]
206+
gm.rotate (["Vol0003","Vol0002"], Mgx3D.RotX(180))
207+
# Translation de Vol0003 Vol0002 suivant [ 0, 0, -700]
208+
gm.translate (["Vol0003","Vol0002"], Mgx3D.Vector(0, 0, -700))
209+
# Collage entre Vol0000 Vol0001 Vol0002 Vol0003
210+
gm.glue (["Vol0000","Vol0001","Vol0002","Vol0003"])
211+
# Fusion Booléenne de Vol0000 Vol0001 Vol0002 Vol0003
212+
gm.fuse (["Vol0000","Vol0001","Vol0002","Vol0003"])
213+
214+
assert gm.getNbVertices() == 13
215+
assert gm.getNbCurves() == 22
216+
assert gm.getNbSurfaces() == 12
217+
assert gm.getNbVolumes() == 1
218+
219+
out, err = capfd.readouterr()
220+
assert len(err) == 0

0 commit comments

Comments
 (0)