@@ -673,7 +673,11 @@ def addSubcomponents(self, items, iA=[0], iB=[-1]):
673673 # Store them as subcomponents of this edge
674674 self .subcomponents = items # dict(enumerate(items))
675675 for item in items :
676- item .part_of = self
676+ if isinstance (item , list ):
677+ for subitem in item :
678+ subitem .part_of = self
679+ else :
680+ item .part_of = self
677681
678682 # Assign ends
679683 self .subcons_A = list ([items [0 ]]) # subcomponent for end A (can be multiple)
@@ -1089,10 +1093,42 @@ def assemble(items):
10891093
10901094 # >>> TODO: adjust this so it can connect parallel elements .eg. for bridles <<<
10911095
1096+ '''
1097+ # If the provided items isn't a list, there's nothing to assemble so return
1098+ if not isinstance(items[i], List):
1099+ print('Not a list - returning!')
1100+ return
1101+ '''
10921102 n = len (items )
10931103
10941104 for i in range (n - 1 ):
1095- if isinstance (items [i ], Node ) and isinstance (items [i + 1 ], Edge ):
1105+
1106+ if isinstance (items [i ], list ):
1107+ for subitem in items [i ]: # go through each parallel subitem
1108+
1109+ if isinstance (subitem , list ): # if it's a concatenation of multiple things
1110+ assemble (subitem ) # make sure that any sublist is assembled
1111+
1112+ # attach the end objects of the subitem to the nodes before and after
1113+ if i > 0 and isinstance (items [i - 1 ], Node ): # attach to previous node
1114+ items [i - 1 ].attach (subitem [0 ], end = 'a' )
1115+ if i < n - 1 and isinstance (items [i + 1 ], Node ): # attach to next node
1116+ items [i + 1 ].attach (subitem [- 1 ], end = 'b' )
1117+ # note: this requires the end objects to be edges
1118+
1119+ elif isinstance (subitem , Edge ): # if the subitem is just one edge
1120+ if i > 0 and isinstance (items [i - 1 ], Node ): # attach to previous node
1121+ items [i - 1 ].attach (subitem , end = 'a' )
1122+ if i < n - 1 and isinstance (items [i + 1 ], Node ): # attach to next node
1123+ items [i + 1 ].attach (subitem , end = 'b' )
1124+ else :
1125+ raise Exception ("Unsupported situation ... parallel subitems must be edges or concatenations" )
1126+
1127+ elif isinstance (items [i ], Node ) and isinstance (items [i + 1 ], list ):
1128+ pass # this node connects to a bridle or doubled section,
1129+ # so it will be hooked up in the next step
1130+
1131+ elif isinstance (items [i ], Node ) and isinstance (items [i + 1 ], Edge ):
10961132 items [i ].attach (items [i + 1 ], end = 'a' )
10971133
10981134 elif isinstance (items [i ], Edge ) and isinstance (items [i + 1 ], Node ):
@@ -1174,7 +1210,24 @@ def rotationMatrix(x3,x2,x1):
11741210
11751211 assemble ([A , E , B ])
11761212
1177- E .addSubcomponents ([e0 ,n0 ,e1 ,n1 ,e2 ])
1213+ E .addSubcomponents ([e0 ,n0 ,e1 ,n1 ,e2 ])
1214+
1215+
1216+ # ----- a test for bridles etc -----
1217+
1218+ e0 = Edge (id = 'e0' )
1219+ n0 = Node (id = 'n0' )
1220+ e1 = Edge (id = 'e1' )
1221+ n1 = Node (id = 'n1' )
1222+ e2a = Edge (id = 'e2a' )
1223+ e2b = Edge (id = 'e2b' )
1224+
1225+
1226+ thelist = [e0 , n0 , e1 , n1 , [e2a , e2b ]]
1227+
1228+ E = Edge (id = 'big edge' )
1229+
1230+ E .addSubcomponents (thelist )
11781231
11791232 # ----- try joining two nodes -----
11801233
@@ -1184,7 +1237,7 @@ def rotationMatrix(x3,x2,x1):
11841237
11851238
11861239 # ----- tests connecting multi-level node and edge objects ----
1187- '''
1240+
11881241 # --- Test 1 ---
11891242 # platform and fairlead
11901243 n1 = Node (id = 'n1' )
@@ -1254,7 +1307,7 @@ def rotationMatrix(x3,x2,x1):
12541307 e1_n2 .attach (e1_e1 , end = 'B' )
12551308 # attach mooring to platfrom (by lower objects, then upper will be automatic)
12561309 n2 .attach (e1_n2 )
1257- '''
1310+
12581311 # --- Test 6 ---
12591312 # platform and fairlead
12601313 n1 = Node (id = 'n1' )
0 commit comments