Skip to content

Commit 49afd57

Browse files
committed
WIP-FIX: solved circular import problem
1 parent dbe7d49 commit 49afd57

File tree

12 files changed

+1741
-379
lines changed

12 files changed

+1741
-379
lines changed

deps/eigen

Submodule eigen updated from 5226566 to 9099c5e

examples/exporter.ghx

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

src/gh/components/DF_xml_exporter/code.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! python3
2-
# requirements: diffCheck
2+
# r: diffCheck==0.0.8
33

44
import System
55
import typing
@@ -9,19 +9,16 @@
99

1010
from ghpythonlib.componentbase import executingcomponent as component
1111

12-
from diffCheck.df_geometries import DFVertex, DFFace, DFBeam, DFAssembly
13-
import diffCheck.df_transformations
14-
import diffCheck.df_joint_detector
15-
import diffCheck.df_util
12+
import diffCheck
13+
from diffCheck.df_geometries import DFBeam, DFAssembly
1614

1715

1816
class DFXMLExporter(component):
1917
def RunScript(self,
20-
i_dump : bool,
21-
i_assembly_name : str,
22-
i_export_dir : str,
23-
i_breps : typing.List[Rhino.Geometry.Brep]
24-
):
18+
i_dump: bool,
19+
i_assembly_name,
20+
i_export_dir,
21+
i_breps: System.Collections.Generic.IList[Rhino.Geometry.Brep]):
2522
"""
2623
This read breps from Rhino, converts them to DFBeams and DFAssemblies, and exports them to XML.
2724
@@ -30,7 +27,7 @@ def RunScript(self,
3027
:param i_breps: list of breps
3128
"""
3229
# beams
33-
beams : typing.List[DFBeam] = []
30+
beams: typing.List[DFBeam] = []
3431
for brep in i_breps:
3532
beam = DFBeam.from_brep(brep)
3633
beams.append(beam)
@@ -39,9 +36,9 @@ def RunScript(self,
3936
assembly1 = DFAssembly(beams, i_assembly_name)
4037

4138
# dump the xml
42-
xml : str = assembly1.to_xml()
39+
xml: str = assembly1.to_xml()
4340
if i_dump:
44-
assembly1.dump(xml, i_export_dir)
41+
assembly1.dump_xml(xml, i_export_dir)
4542
o_xml = xml
4643

4744
# show the joint/side faces
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.0.3'
1+
__version__ = "0.0.8"

src/gh/diffCheck/diffCheck/df_geometries.py

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ class DFVertex:
1818
"""
1919
This class represents a vertex, a simple container with 3 coordinates
2020
"""
21-
x : float
22-
y : float
23-
z : float
21+
22+
x: float
23+
y: float
24+
z: float
25+
2426
def __post_init__(self):
2527
self.x = self.x or 0.0
2628
self.y = self.y or 0.0
@@ -61,46 +63,41 @@ class DFFace:
6163
"""
6264
This class represents a face, in diffCheck, a face is a collection of vertices.
6365
"""
66+
6467
# just as breps a first outer loop and then inner loops of DFVertices
65-
all_loops : typing.List[typing.List[DFVertex]]
66-
joint_id : int
68+
all_loops: typing.List[typing.List[DFVertex]]
69+
joint_id: int = None
70+
6771
def __post_init__(self):
6872
if len(self.all_loops[0]) < 3:
6973
raise ValueError("A face must have at least 3 vertices")
70-
self.all_loops = self.all_loops or []
74+
self.all_loops = self.all_loops
7175

72-
self.joint_id = self.joint_id or None
76+
self.joint_id = self.joint_id
7377
self.__is_joint = False
7478
self.__id = uuid.uuid4().int
7579

7680
def __repr__(self):
7781
return f"Face id: {len(self.id)}, IsJoint: {self.is_joint} Loops: {len(self.all_loops)}"
7882

7983
def __hash__(self):
80-
outer_loop = tuple(tuple(vertex.__dict__.values()) for vertex in self.all_loops[0])
81-
inner_loops = tuple(tuple(vertex.__dict__.values()) for loop in self.all_loops[1:] for vertex in loop)
84+
outer_loop = tuple(
85+
tuple(vertex.__dict__.values()) for vertex in self.all_loops[0]
86+
)
87+
inner_loops = tuple(
88+
tuple(vertex.__dict__.values())
89+
for loop in self.all_loops[1:]
90+
for vertex in loop
91+
)
8292
return hash((outer_loop, inner_loops))
8393

8494
def __eq__(self, other):
8595
if isinstance(other, DFFace):
8696
return self.all_loops == other.all_loops
8797
return False
8898

89-
@staticmethod
90-
def compute_mass_center(face: rg.BrepFace) -> rg.Point3d:
91-
"""
92-
Compute the mass center of a face
93-
94-
:param face: The face to compute the mass center from
95-
:return mass_center: The mass center of the face
96-
"""
97-
amp = rg.AreaMassProperties.Compute(face)
98-
if amp:
99-
return amp.Centroid
100-
return None
101-
10299
@classmethod
103-
def from_brep(cls, brep_face: rg.BrepFace, joint_id: int=None):
100+
def from_brep(cls, brep_face: rg.BrepFace, joint_id: int = None):
104101
"""
105102
Create a DFFace from a Rhino Brep face
106103
@@ -135,12 +132,16 @@ def to_brep(self):
135132
brep_curves = []
136133

137134
for loop in self.all_loops:
138-
inner_vertices = [rg.Point3d(vertex.x, vertex.y, vertex.z) for vertex in loop]
135+
inner_vertices = [
136+
rg.Point3d(vertex.x, vertex.y, vertex.z) for vertex in loop
137+
]
139138
inner_polyline = rg.Polyline(inner_vertices)
140139
inner_curve = inner_polyline.ToNurbsCurve()
141140
brep_curves.append(inner_curve)
142141

143-
brep = rg.Brep.CreatePlanarBreps(brep_curves, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)[0]
142+
brep = rg.Brep.CreatePlanarBreps(
143+
brep_curves, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance
144+
)[0]
144145

145146
return brep
146147

@@ -171,8 +172,10 @@ class DFBeam:
171172
"""
172173
This class represents a beam, in diffCheck, a beam is a collection of faces
173174
"""
174-
name : str
175-
faces : typing.List[DFFace]
175+
176+
name: str
177+
faces: typing.List[DFFace]
178+
176179
def __post_init__(self):
177180
self.name = self.name or "Unnamed Beam"
178181
self.faces = self.faces or []
@@ -187,8 +190,11 @@ def from_brep(cls, brep):
187190
Create a DFBeam from a RhinoBrep object.
188191
It also removes duplicates and creates a list of unique faces.
189192
"""
190-
faces = diffCheck.df_joint_detector.JointDetector(brep).run()
191-
faces = list(set(faces))
193+
faces : typing.List[DFFace] = []
194+
data_faces = diffCheck.df_joint_detector.JointDetector(brep).run()
195+
for data in data_faces:
196+
face = DFFace.from_brep(data[0], data[1])
197+
faces.append(face)
192198
beam = cls("Beam", faces)
193199
return beam
194200

@@ -213,8 +219,10 @@ class DFAssembly:
213219
"""
214220
This class represents an assembly of beams
215221
"""
216-
beams : typing.List[DFBeam]
217-
name : str
222+
223+
beams: typing.List[DFBeam]
224+
name: str
225+
218226
def __post_init__(self):
219227
self.beams = self.beams
220228
self.name = self.name or "Unnamed Assembly"
@@ -256,7 +264,9 @@ def to_xml(self):
256264
mesh = face.to_mesh()
257265
mesh_vertices = mesh.Vertices
258266
for idx, vertex in enumerate(mesh_vertices):
259-
facerhmesh_vertex_elem = ET.SubElement(facerhmesh_elem, "RhMeshVertex")
267+
facerhmesh_vertex_elem = ET.SubElement(
268+
facerhmesh_elem, "RhMeshVertex"
269+
)
260270
facerhmesh_vertex_elem.set("x", str(vertex.X))
261271
facerhmesh_vertex_elem.set("y", str(vertex.Y))
262272
facerhmesh_vertex_elem.set("z", str(vertex.Z))
@@ -269,13 +279,13 @@ def to_xml(self):
269279
facerhmesh_face_elem.set("v4", str(face.D))
270280

271281
tree = ET.ElementTree(root)
272-
xml_string = ET.tostring(root, encoding='unicode')
282+
xml_string = ET.tostring(root, encoding="unicode")
273283
dom = parseString(xml_string)
274284
pretty_xml = dom.toprettyxml()
275285

276286
return pretty_xml
277287

278-
def dump_xml(self, pretty_xml : str, dir: str):
288+
def dump_xml(self, pretty_xml: str, dir: str):
279289
"""
280290
Dump the pretty XML to a file
281291
@@ -298,4 +308,4 @@ def all_joint_faces(self):
298308
def all_side_faces(self):
299309
for beam in self.beams:
300310
self._all_sidefaces.extend(beam.side_faces)
301-
return self._all_sidefaces
311+
return self._all_sidefaces

src/gh/diffCheck/diffCheck/df_joint_detector.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import typing
66
from dataclasses import dataclass
77

8-
import df_util
8+
import diffCheck.df_util
99
import diffCheck.df_transformations
10-
from diffCheck.df_geometries import DFFace
10+
1111

1212
@dataclass
13-
class JointDetector():
13+
class JointDetector:
1414
"""
1515
This class is responsible for detecting joints in a brep
1616
"""
@@ -25,9 +25,21 @@ def __post_init__(self):
2525
self._mix : typing.List[rg.Brep]= []
2626

2727
# list of DFFaces from joints and sides
28-
self._faces : typing.List[DFFace] = []
28+
self._faces = []
29+
30+
def _compute_mass_center(self, b_face: rg.BrepFace) -> rg.Point3d:
31+
"""
32+
Compute the mass center of a brep face
33+
34+
:param b_face: The brep face to compute the mass center from
35+
:return mass_center: The mass center of the brep face
36+
"""
37+
amp = rg.AreaMassProperties.Compute(b_face)
38+
if amp:
39+
return amp.Centroid
40+
return None
2941

30-
def run(self) -> typing.List[DFFace]:
42+
def run(self) :
3143
"""
3244
Run the joint detector
3345
@@ -73,7 +85,7 @@ def run(self) -> typing.List[DFFace]:
7385
is_cut = False
7486
is_hole = True
7587

76-
b_faces = df_util.explode_brep(b)
88+
b_faces = diffCheck.df_util.explode_brep(b)
7789
for b_face in b_faces:
7890
if b_face.Faces[0].IsPlanar():
7991
b_face_edges = b_face.Edges
@@ -109,7 +121,7 @@ def run(self) -> typing.List[DFFace]:
109121
# (5) check if closed, if it is
110122
# ----------------------
111123
# (1) explode
112-
faces_b = df_util.explode_brep(b)
124+
faces_b = diffCheck.df_util.explode_brep(b)
113125

114126
# (2) seperate in tow list flat surfaces (cuts + cylinder's bases) and non flat surfaces (cylinders)
115127
flat_faces_b = []
@@ -164,23 +176,23 @@ def run(self) -> typing.List[DFFace]:
164176
idx = idx + 1
165177
temp_face_centroids = []
166178
for f in b.Faces:
167-
centroid = DFFace.compute_mass_center(f)
179+
centroid = self._compute_mass_center(f)
168180
temp_face_centroids.append(centroid)
169181
cuts_faces_centroids[idx] = temp_face_centroids
170182

171183
# compare with the brep medians faces to get the joint/sides's faces
172184
for f in self.brep.Faces:
173-
centroid_2test = DFFace.compute_mass_center(f)
185+
centroid_2test = self._compute_mass_center(f)
174186
for key, centroids in cuts_faces_centroids.items():
175187
is_joint = False
176188
for centroid in centroids:
177189
if centroid_2test.DistanceTo(centroid) < sc.doc.ModelAbsoluteTolerance:
178-
self._faces.append(DFFace.from_brep(f, key))
190+
self._faces.append([f, key])
179191
is_joint = True
180192
break
181193
if is_joint:
182194
break
183195
if not is_joint:
184-
self._faces.append(DFFace.from_brep(f, None))
196+
self._faces.append([f, None])
185197

186198
return self._faces

0 commit comments

Comments
 (0)