2727import blenderbim .tool as tool
2828import ifcopenshell .util .geolocation
2929from xml .dom import minidom
30+ from mathutils import Vector
31+
32+ VIEW_TITLE_OFFSET_Y = 5
33+ DEFAULT_POSITION = Vector ((30 , 30 ))
3034
3135
3236class SheetBuilder :
@@ -104,8 +108,8 @@ def add_drawing(self, reference, drawing, sheet):
104108 background = ET .SubElement (view , "image" )
105109 background .attrib ["data-type" ] = "background"
106110 background .attrib ["xlink:href" ] = os .path .relpath (underlay_path , layout_dir )
107- background .attrib ["x" ] = "30"
108- background .attrib ["y" ] = "30"
111+ background .attrib ["x" ] = str ( DEFAULT_POSITION . x )
112+ background .attrib ["y" ] = str ( DEFAULT_POSITION . y )
109113 background .attrib ["width" ] = str (view_width )
110114 background .attrib ["height" ] = str (view_height )
111115
@@ -114,12 +118,14 @@ def add_drawing(self, reference, drawing, sheet):
114118 foreground = ET .SubElement (view , "image" )
115119 foreground .attrib ["data-type" ] = "foreground"
116120 foreground .attrib ["xlink:href" ] = os .path .relpath (drawing_path , layout_dir )
117- foreground .attrib ["x" ] = "30"
118- foreground .attrib ["y" ] = "30"
121+ foreground .attrib ["x" ] = str ( DEFAULT_POSITION . x )
122+ foreground .attrib ["y" ] = str ( DEFAULT_POSITION . y )
119123 foreground .attrib ["width" ] = str (view_width )
120124 foreground .attrib ["height" ] = str (view_height )
121125
122- self .add_view_title (30 , view_height + 35 , view , layout_dir )
126+ self .add_view_title (
127+ DEFAULT_POSITION .x , view_height + DEFAULT_POSITION .y + VIEW_TITLE_OFFSET_Y , view , layout_dir
128+ )
123129 layout_tree .write (layout_path )
124130
125131 def update_sheet_drawing_sizes (self , sheet ):
@@ -143,10 +149,20 @@ def update_sheet_drawing_sizes(self, sheet):
143149 view_width = self .convert_to_mm (drawing_root .attrib .get ("width" ))
144150 view_height = self .convert_to_mm (drawing_root .attrib .get ("height" ))
145151
152+ foreground = drawing_view .find (f'.//{ SVG } image[@data-type="foreground"]' )
153+ height = float (foreground .attrib ["height" ])
154+ width = float (foreground .attrib ["width" ])
155+ readjust = Vector ((width - view_width , height - view_height )) / 2
156+
146157 for image in drawing_view .findall (f"{ SVG } image" ):
158+ x = float (image .attrib ["x" ])
159+ y = float (image .attrib ["y" ])
147160 if image .attrib ["data-type" ] == "view-title" :
148- image .attrib ["y" ] = str (view_height + 35 )
161+ image .attrib ["x" ] = str (x - readjust .x )
162+ image .attrib ["y" ] = str (y - readjust .y )
149163 else :
164+ image .attrib ["x" ] = str (x + readjust .x )
165+ image .attrib ["y" ] = str (y + readjust .y )
150166 image .attrib ["width" ] = str (view_width )
151167 image .attrib ["height" ] = str (view_height )
152168
@@ -193,12 +209,14 @@ def add_schedule(self, reference, schedule, sheet):
193209 foreground = ET .SubElement (view , "image" )
194210 foreground .attrib ["data-type" ] = "table"
195211 foreground .attrib ["xlink:href" ] = os .path .relpath (view_path , layout_dir )
196- foreground .attrib ["x" ] = "30"
197- foreground .attrib ["y" ] = "30"
212+ foreground .attrib ["x" ] = str ( DEFAULT_POSITION . x )
213+ foreground .attrib ["y" ] = str ( DEFAULT_POSITION . y )
198214 foreground .attrib ["width" ] = str (view_width )
199215 foreground .attrib ["height" ] = str (view_height )
200216
201- self .add_view_title (30 , view_height + 35 , view , layout_dir )
217+ self .add_view_title (
218+ DEFAULT_POSITION .x , view_height + DEFAULT_POSITION .y + VIEW_TITLE_OFFSET_Y , view , layout_dir
219+ )
202220 layout_tree .write (layout_path )
203221
204222 def add_view_title (self , x , y , parent , layout_dir ):
0 commit comments