3636
3737from os .path import basename , dirname
3838import json
39+ import collections
3940
4041
4142V = lambda * x : Vector ([float (i ) for i in x ])
@@ -55,16 +56,20 @@ def update_window_modifier_representation(context):
5556 "LiningOffset" : props .lining_offset ,
5657 "LiningToPanelOffsetX" : props .lining_to_panel_offset_x ,
5758 "LiningToPanelOffsetY" : props .lining_to_panel_offset_y ,
59+ "MullionThickness" : props .mullion_thickness ,
60+ "FirstMullionOffset" : props .first_mullion_offset ,
61+ "SecondMullionOffset" : props .second_mullion_offset ,
62+ "TransomThickness" : props .transom_thickness ,
63+ "FirstTransomOffset" : props .first_transom_offset ,
64+ "SecondTransomOffset" : props .second_transom_offset ,
5865 },
5966 "panel_properties" : [],
6067 }
61- number_of_panels = len ( props .window_types_panels [props .window_type ])
68+ number_of_panels , panels_data = props .window_types_panels [props .window_type ]
6269 for panel_i in range (number_of_panels ):
6370 panel_data = {
6471 "FrameDepth" : props .frame_depth [panel_i ],
6572 "FrameThickness" : props .frame_thickness [panel_i ],
66- "RelativeWidth" : props .relative_width [panel_i ],
67- "RelativeHeight" : props .relative_height [panel_i ],
6873 }
6974 representation_data ["panel_properties" ].append (panel_data )
7075
@@ -97,10 +102,8 @@ def update_window_modifier_representation(context):
97102def replace_representation_for_object (ifc_file , ifc_context , obj , new_representation ):
98103 ifc_element = tool .Ifc .get_entity (obj )
99104 old_representation = ifcopenshell .util .representation .get_representation (
100- ifc_element ,
101- ifc_context .ContextType ,
102- ifc_context .ContextIdentifier ,
103- ifc_context .TargetView )
105+ ifc_element , ifc_context .ContextType , ifc_context .ContextIdentifier , ifc_context .TargetView
106+ )
104107
105108 if old_representation :
106109 for inverse in ifc_file .get_inverse (old_representation ):
@@ -121,14 +124,24 @@ def replace_representation_for_object(ifc_file, ifc_context, obj, new_representa
121124 )
122125
123126
124- def create_bm_window_closed_profile (bm , size : Vector , thickness : float , position : Vector ):
127+ def create_bm_window_closed_profile (bm , size : Vector , thickness : Vector , position : Vector ):
128+ """thickness of the profile is defined as list in the following order: (LEFT, TOP, RIGHT, BOTTOM)
129+
130+ thickness can be also defined just as 1 float value.
131+ """
132+
133+ if not isinstance (thickness , collections .abc .Iterable ):
134+ thickness = [thickness ] * 4
135+
136+ th_left , th_up , th_right , th_bottom = thickness
137+
125138 width , depth , height = size
126139
127140 verts = [
128- (0 , [thickness , 0.0 , thickness ]),
129- (1 , [width - thickness , 0.0 , thickness ]),
130- (2 , [thickness , 0.0 , height - thickness ]),
131- (3 , [width - thickness , 0.0 , height - thickness ]),
141+ (0 , [th_left , 0.0 , th_bottom ]),
142+ (1 , [width - th_right , 0.0 , th_bottom ]),
143+ (2 , [th_left , 0.0 , height - th_up ]),
144+ (3 , [width - th_right , 0.0 , height - th_up ]),
132145 (4 , [0.0 , 0.0 , 0.0 ]),
133146 (5 , [0.0 , 0.0 , height ]),
134147 (6 , [width , 0.0 , 0.0 ]),
@@ -151,10 +164,10 @@ def create_bm_window_closed_profile(bm, size: Vector, thickness: float, position
151164 ]
152165
153166 faces = [
154- (0 , (2 , 3 , 7 , 5 )),
155- (1 , (5 , 4 , 0 , 2 )),
156- (2 , (1 , 0 , 4 , 6 )),
157- (3 , (7 , 3 , 1 , 6 )),
167+ (0 , (5 , 7 , 3 , 2 )),
168+ (1 , (2 , 0 , 4 , 5 )),
169+ (2 , (6 , 4 , 0 , 1 )),
170+ (3 , (6 , 1 , 3 , 7 )),
158171 ]
159172
160173 bm .verts .index_update ()
@@ -187,28 +200,79 @@ def update_window_modifier_bmesh(context):
187200 lining_depth = props .lining_depth * si_conversion
188201 overall_height = props .overall_height * si_conversion
189202 lining_to_panel_offset_x = props .lining_to_panel_offset_x * si_conversion
203+ lining_thickness = props .lining_thickness * si_conversion
204+
205+ mullion_thickness = props .mullion_thickness * si_conversion / 2
206+ first_mullion_offset = props .first_mullion_offset * si_conversion
207+ second_mullion_offset = props .second_mullion_offset * si_conversion
208+ transom_thickness = props .transom_thickness * si_conversion / 2
209+ first_transom_offset = props .first_transom_offset * si_conversion
210+ second_transom_offset = props .second_transom_offset * si_conversion
211+
212+ glass_thickness = 10 * si_conversion
190213
191214 bm = bmesh .new ()
215+ panel_schema = list (reversed (panel_schema ))
192216
193- for row_i , panel_row in enumerate (reversed (panel_schema )):
217+ # TODO: need more readable way to define panel width and height
218+ unique_rows_in_col = [len (set (row [column_i ] for row in panel_schema )) for column_i in range (len (panel_schema [0 ]))]
219+ for row_i , panel_row in enumerate (panel_schema ):
194220 accumulated_width = 0
221+ unique_cols = len (set (panel_row ))
222+
195223 for column_i , panel_i in enumerate (panel_row ):
224+ # calculate current panel dimensions
225+ if unique_cols > 1 :
226+ if column_i == 0 :
227+ panel_width = first_mullion_offset
228+ elif column_i == unique_cols - 1 :
229+ panel_width = overall_width - accumulated_width
230+ else :
231+ panel_width = second_mullion_offset - accumulated_width
232+ else :
233+ panel_width = overall_width
234+
235+ if unique_rows_in_col [column_i ] > 1 :
236+ if row_i == 0 :
237+ panel_height = first_transom_offset
238+ elif row_i == unique_rows_in_col [column_i ] - 1 :
239+ panel_height = overall_height - accumulated_height [column_i ]
240+ else :
241+ panel_height = second_transom_offset - accumulated_height [column_i ]
242+ else :
243+ panel_height = overall_height
244+
196245 if panel_i in built_panels :
197- accumulated_height [column_i ] += props . relative_height [ panel_i ]
198- accumulated_width += props . relative_width [ panel_i ]
246+ accumulated_height [column_i ] += panel_height
247+ accumulated_width += panel_width
199248 continue
200249
201250 frame_depth = props .frame_depth [panel_i ] * si_conversion
202251 frame_thickness = props .frame_thickness [panel_i ] * si_conversion
203- glass_thickness = 10 * si_conversion
204252
205253 # create lining
206254 lining_size = V (
207- overall_width * props . relative_width [ panel_i ] ,
255+ panel_width ,
208256 lining_depth ,
209- overall_height * props . relative_height [ panel_i ] ,
257+ panel_height ,
210258 )
211- thickness = props .lining_thickness * si_conversion
259+
260+ # calculate lining thickness
261+ # taking into account mullions and transoms
262+ thickness = [lining_thickness ] * 4
263+ # mullion thickness
264+ if unique_cols > 1 :
265+ if column_i != 0 :
266+ thickness [0 ] = mullion_thickness # left column
267+ if column_i != unique_cols - 1 :
268+ thickness [2 ] = mullion_thickness # right column
269+ # transom thickness
270+ if unique_rows_in_col [column_i ] > 1 :
271+ if row_i != 0 :
272+ thickness [3 ] = transom_thickness # bottom row
273+ if row_i != unique_rows_in_col [column_i ] - 1 :
274+ thickness [1 ] = transom_thickness # top row
275+
212276 lining_verts = create_bm_window_closed_profile (bm , lining_size , thickness , V (0 , 0 , 0 ))
213277
214278 # add panel
@@ -239,15 +303,13 @@ def update_window_modifier_bmesh(context):
239303 bmesh .ops .translate (bm , vec = glass_position , verts = glass_verts )
240304
241305 # translate panel
242- accumulated_offset = V (accumulated_width , 0 , accumulated_height [column_i ]) * V (
243- overall_width , 0 , overall_height
244- )
306+ accumulated_offset = V (accumulated_width , 0 , accumulated_height [column_i ])
245307 bmesh .ops .translate (bm , vec = accumulated_offset , verts = lining_verts + panel_verts + glass_verts )
246308
247309 built_panels .append (panel_i )
248310
249- accumulated_height [column_i ] += props . relative_height [ panel_i ]
250- accumulated_width += props . relative_width [ panel_i ]
311+ accumulated_height [column_i ] += panel_height
312+ accumulated_width += panel_width
251313
252314 bmesh .ops .translate (bm , vec = V (0 , props .lining_offset * si_conversion , 0 ), verts = bm .verts )
253315 bmesh .ops .remove_doubles (bm , verts = bm .verts , dist = 0.0001 )
0 commit comments