@@ -36,6 +36,12 @@ def __post_init__(self):
3636
3737 self .__uuid = uuid .uuid4 ().int
3838
39+ def __getstate__ (self ):
40+ return self .__dict__
41+
42+ def __setstate__ (self , state : typing .Dict ):
43+ self .__dict__ .update (state )
44+
3945 def __repr__ (self ):
4046 return f"Vertex: X={ self .x } , Y={ self .y } , Z={ self .z } "
4147
@@ -94,13 +100,29 @@ def __post_init__(self):
94100
95101 def __getstate__ (self ):
96102 state = self .__dict__ .copy ()
103+ if "all_loops" in state and state ["all_loops" ] is not None :
104+ state ["all_loops" ] = [[vertex .__getstate__ () for vertex in loop ] for loop in state ["all_loops" ]]
105+ # note: rg.BrepFaces cannot be serialized, so we need to convert it to a Surface >> JSON >> brep >> brepface (and vice versa)
97106 if "_rh_brepface" in state and state ["_rh_brepface" ] is not None :
98- state ["_rh_brepface" ] = self ._rh_brepface .ToJSON (SerializationOptions ())
107+ state ["_rh_brepface" ] = self .to_brep_face ().DuplicateFace (True ).ToJSON (SerializationOptions ())
108+ return state
99109
100110 def __setstate__ (self , state : typing .Dict ):
111+ if "all_loops" in state and state ["all_loops" ] is not None :
112+ all_loops = []
113+ for loop_state in state ["all_loops" ]:
114+ loop = [DFVertex .__new__ (DFVertex ) for _ in loop_state ]
115+ for vertex , vertex_state in zip (loop , loop_state ):
116+ vertex .__setstate__ (vertex_state )
117+ all_loops .append (loop )
118+ state ["all_loops" ] = all_loops
119+ # note: rg.BrepFaces cannot be serialized, so we need to convert it to a Surface >> JSON >> brep >> brepface (and vice versa)
101120 if "_rh_brepface" in state and state ["_rh_brepface" ] is not None :
102- state ["_rh_brepface" ] = rg .BrepFace .FromJSON (state ["_rh_brepface" ])
121+ state ["_rh_brepface" ] = rg .Surface .FromJSON (state ["_rh_brepface" ]). Faces [ 0 ]
103122 self .__dict__ .update (state )
123+ if self ._rh_brepface is not None :
124+ self .from_brep_face (self ._rh_brepface , self .joint_id )
125+
104126
105127 def __repr__ (self ):
106128 return f"Face id: { (self .id )} , IsJoint: { self .is_joint } Loops: { len (self .all_loops )} "
@@ -235,6 +257,22 @@ def __post_init__(self):
235257 # this is an automatic identifier
236258 self .__uuid = uuid .uuid4 ().int
237259
260+ def __getstate__ (self ):
261+ state = self .__dict__ .copy ()
262+ if "faces" in state and state ["faces" ] is not None :
263+ state ["faces" ] = [face .__getstate__ () for face in self .faces ]
264+ return state
265+
266+ def __setstate__ (self , state : typing .Dict ):
267+ if "faces" in state and state ["faces" ] is not None :
268+ faces = []
269+ for face_state in state ["faces" ]:
270+ face = DFFace .__new__ (DFFace )
271+ face .__setstate__ (face_state )
272+ faces .append (face )
273+ state ["faces" ] = faces
274+ self .__dict__ .update (state )
275+
238276 def __repr__ (self ):
239277 return f"Joint id: { self .id } , Faces: { len (self .faces )} "
240278
@@ -305,11 +343,56 @@ def __post_init__(self):
305343
306344 def __getstate__ (self ):
307345 state = self .__dict__ .copy ()
346+ if "faces" in state and state ["faces" ] is not None :
347+ state ["faces" ] = [face .__getstate__ () for face in self .faces ]
348+ if "_joint_faces" in state and state ["_joint_faces" ] is not None :
349+ state ["_joint_faces" ] = [face .__getstate__ () for face in state ["_joint_faces" ]]
350+ if "_side_faces" in state and state ["_side_faces" ] is not None :
351+ state ["_side_faces" ] = [face .__getstate__ () for face in state ["_side_faces" ]]
352+ if "_vertices" in state and state ["_vertices" ] is not None :
353+ state ["_vertices" ] = [vertex .__getstate__ () for vertex in state ["_vertices" ]]
354+ if "_joints" in state and state ["_joints" ] is not None :
355+ state ["_joints" ] = [joint .__getstate__ () for joint in state ["_joints" ]]
308356 if "_center" in state and state ["_center" ] is not None :
309357 state ["_center" ] = self ._center .ToJSON (SerializationOptions ())
310358 return state
311359
312360 def __setstate__ (self , state : typing .Dict ):
361+ if "faces" in state and state ["faces" ] is not None :
362+ faces = []
363+ for face_state in state ["faces" ]:
364+ face = DFFace .__new__ (DFFace )
365+ face .__setstate__ (face_state )
366+ faces .append (face )
367+ state ["faces" ] = faces
368+ if "_joint_faces" in state and state ["_joint_faces" ] is not None :
369+ joint_faces = []
370+ for face_state in state ["_joint_faces" ]:
371+ face = DFFace .__new__ (DFFace )
372+ face .__setstate__ (face_state )
373+ joint_faces .append (face )
374+ state ["_joint_faces" ] = joint_faces
375+ if "_side_faces" in state and state ["_side_faces" ] is not None :
376+ side_faces = []
377+ for face_state in state ["_side_faces" ]:
378+ face = DFFace .__new__ (DFFace )
379+ face .__setstate__ (face_state )
380+ side_faces .append (face )
381+ state ["_side_faces" ] = side_faces
382+ if "_vertices" in state and state ["_vertices" ] is not None :
383+ vertices = []
384+ for vertex_state in state ["_vertices" ]:
385+ vertex = DFVertex .__new__ (DFVertex )
386+ vertex .__setstate__ (vertex_state )
387+ vertices .append (vertex )
388+ state ["_vertices" ] = vertices
389+ if "_joints" in state and state ["_joints" ] is not None :
390+ joints = []
391+ for joint_state in state ["_joints" ]:
392+ joint = DFJoint .__new__ (DFJoint )
393+ joint .__setstate__ (joint_state )
394+ joints .append (joint )
395+ state ["_joints" ] = joints
313396 if "_center" in state and state ["_center" ] is not None :
314397 state ["_center" ] = rg .Point3d .FromJSON (state ["_center" ])
315398 self .__dict__ .update (state )
@@ -445,13 +528,58 @@ def __post_init__(self):
445528
446529 def __getstate__ (self ):
447530 state = self .__dict__ .copy ()
531+ if "beams" in state and state ["beams" ] is not None :
532+ state ["beams" ] = [beam .__getstate__ () for beam in self .beams ]
448533 if "_mass_center" in state and state ["_mass_center" ] is not None :
449534 state ["_mass_center" ] = self ._mass_center .ToJSON (SerializationOptions ())
535+ if "_all_jointfaces" in state and state ["_all_jointfaces" ] is not None :
536+ state ["_all_jointfaces" ] = [face .__getstate__ () for face in state ["_all_jointfaces" ]]
537+ if "_all_sidefaces" in state and state ["_all_sidefaces" ] is not None :
538+ state ["_all_sidefaces" ] = [face .__getstate__ () for face in state ["_all_sidefaces" ]]
539+ if "_all_vertices" in state and state ["_all_vertices" ] is not None :
540+ state ["_all_vertices" ] = [vertex .__getstate__ () for vertex in state ["_all_vertices" ]]
541+ if "_all_joints" in state and state ["_all_joints" ] is not None :
542+ state ["_all_joints" ] = [joint .__getstate__ () for joint in state ["_all_joints" ]]
450543 return state
451544
452545 def __setstate__ (self , state : typing .Dict ):
546+ if "beams" in state and state ["beams" ] is not None :
547+ beams = []
548+ for beam_state in state ["beams" ]:
549+ beam = DFBeam .__new__ (DFBeam )
550+ beam .__setstate__ (beam_state )
551+ beams .append (beam )
552+ state ["beams" ] = beams
453553 if "_mass_center" in state and state ["_mass_center" ] is not None :
454554 state ["_mass_center" ] = rg .Point3d .FromJSON (state ["_mass_center" ])
555+ if "_all_jointfaces" in state and state ["_all_jointfaces" ] is not None :
556+ joint_faces = []
557+ for face_state in state ["_all_jointfaces" ]:
558+ face = DFFace .__new__ (DFFace )
559+ face .__setstate__ (face_state )
560+ joint_faces .append (face )
561+ state ["_all_jointfaces" ] = joint_faces
562+ if "_all_sidefaces" in state and state ["_all_sidefaces" ] is not None :
563+ side_faces = []
564+ for face_state in state ["_all_sidefaces" ]:
565+ face = DFFace .__new__ (DFFace )
566+ face .__setstate__ (face_state )
567+ side_faces .append (face )
568+ state ["_all_sidefaces" ] = side_faces
569+ if "_all_vertices" in state and state ["_all_vertices" ] is not None :
570+ vertices = []
571+ for vertex_state in state ["_all_vertices" ]:
572+ vertex = DFVertex .__new__ (DFVertex )
573+ vertex .__setstate__ (vertex_state )
574+ vertices .append (vertex )
575+ state ["_all_vertices" ] = vertices
576+ if "_all_joints" in state and state ["_all_joints" ] is not None :
577+ joints = []
578+ for joint_state in state ["_all_joints" ]:
579+ joint = DFJoint .__new__ (DFJoint )
580+ joint .__setstate__ (joint_state )
581+ joints .append (joint )
582+ state ["_all_joints" ] = joints
455583 self .__dict__ .update (state )
456584
457585 def __repr__ (self ):
0 commit comments