@@ -72,7 +72,9 @@ class ShapePlot:
7272 attachment_point_mark = marks .Cross (name = "attachment_point" , rotation = np .pi / 4 )
7373
7474 config : ShapePlotConfig | None = None
75+
7576 shapes : tuple [Shape , Shape ] | None = None
77+ shapes_rot : tuple [Shape , Shape ] | None = None
7678
7779 def __init__ (self , project : GliderProject , drawing : Layout | None = None ):
7880 super ().__init__ ()
@@ -84,37 +86,46 @@ def __init__(self, project: GliderProject, drawing: Layout | None=None):
8486 self .reference_area = self .glider_2d .shape .area
8587 self .reference_span = self .glider_2d .shape .span
8688
87- def _get_shapes (self , config : ShapePlotConfig , force : bool = False ) -> tuple [Shape , Shape ]:
88- if force or self . config is None or self . shapes is None or config . apply_zrot != self . config . apply_zrot :
89- if config . apply_zrot :
90- zrot = [ rib . zrot for rib in self .glider_3d . ribs ]
89+ def _get_shapes (self , config : ShapePlotConfig | None = None , force : bool = False ) -> tuple [Shape , Shape ]:
90+ if config is None :
91+ if self . config is not None :
92+ config = self .config
9193 else :
92- zrot = None
93- shape_r = self .glider_2d .shape .get_half_shape (zrot = zrot )
94- shape_l = shape_r .copy ().scale (x = - 1 )
95- self .shapes = (shape_r , shape_l )
94+ config = ShapePlotConfig ()
95+
96+ if config .apply_zrot :
97+ if force or self .shapes_rot is None :
98+ zrot = [rib .zrot for rib in self .glider_3d .ribs ]
99+ shape_r = self .glider_2d .shape .get_half_shape (zrot = zrot )
100+ shape_l = shape_r .copy ().scale (x = - 1 )
101+ self .shapes_rot = (shape_r , shape_l )
102+
103+ return self .shapes_rot
96104
97- return self .shapes
105+ else :
106+ if force or self .shapes is None :
107+ shape_r = self .glider_2d .shape .get_half_shape (zrot = None )
108+ shape_l = shape_r .copy ().scale (x = - 1 )
109+ self .shapes = (shape_r , shape_l )
98110
111+ return self .shapes
99112
100113 def redraw (self , config : ShapePlotConfig , force : bool = False ) -> Layout :
101- shapes = self ._get_shapes (config , force )
102-
103114 if config != self .config or force :
115+ self .config = config
104116 self .drawing = Layout ()
105117
106118 for layer_name , show_layer in config .view_layers ().items ():
107119 if show_layer :
108120 f = getattr (self , f"draw_{ layer_name } " )
109- f (shapes , left = True )
110- f (shapes , left = False )
121+ f (left = True )
122+ f (left = False )
111123
112124 if config .scale_area :
113125 self .drawing .scale (math .sqrt (config .scale_area / self .reference_area ))
114126 elif config .scale_span :
115127 self .drawing .scale (config .scale_span / self .reference_span )
116128
117- self .config = config
118129
119130 return self .drawing
120131
@@ -140,13 +151,14 @@ def _get_cell_range(self, left_side: bool) -> range:
140151
141152 return range (start , end )
142153
143- def draw_design_lower (self , shapes : tuple [ Shape , Shape ], left : bool = False ) -> ShapePlot :
144- return self .draw_design (shapes , True , left )
154+ def draw_design_lower (self , left : bool = False ) -> ShapePlot :
155+ return self .draw_design (True , left )
145156
146- def draw_design_upper (self , shapes : tuple [ Shape , Shape ], left : bool = False ) -> ShapePlot :
147- return self .draw_design (shapes , False , left )
157+ def draw_design_upper (self , left : bool = False ) -> ShapePlot :
158+ return self .draw_design (False , left )
148159
149- def draw_design (self , shapes : tuple [Shape , Shape ], lower : bool = True , left : bool = False ) -> ShapePlot :
160+ def draw_design (self , lower : bool = True , left : bool = False ) -> ShapePlot :
161+ shapes = self ._get_shapes ()
150162 shape = shapes [left ]
151163
152164 panels = self .glider_2d .get_panels ()
@@ -191,30 +203,32 @@ def get_cut_line(cut: PanelCut) -> euklid.vector.PolyLine2D:
191203
192204 return self
193205
194- def draw_baseline (self , shapes : tuple [Shape , Shape ], pct : float | None = None , left : bool = False ) -> None :
206+ def draw_baseline (self , pct : float | None = None , left : bool = False ) -> None :
207+ shapes = self ._get_shapes ()
195208 shape = shapes [left ]
196209
197210 if pct is None :
198- pct = self .glider_2d .shape . baseline_pos .si
211+ pct = self .glider_2d .config . baseline_pct .si
199212
200213 part = PlotPart ()
201214
202215 line = euklid .vector .PolyLine2D ([shape .get_point (rib , pct ) for rib in self ._get_rib_range (left )])
203216 part .layers ["marks" ].append (line )
204217 self .drawing .parts .append (part )
205218
206- def draw_grid (self , shapes : tuple [ Shape , Shape ], num : int = 11 , left : bool = False ) -> ShapePlot :
219+ def draw_grid (self , num : int = 11 , left : bool = False ) -> ShapePlot :
207220 import numpy as np
208221
209222 for x in np .linspace (0 , 1 , num ):
210223 self .draw_baseline (x , left = left )
211224
212- self .draw_cells (shapes , left = left )
225+ self .draw_cells (left = left )
213226 return self
214227
215- def _get_attachment_point_positions (self , shapes : tuple [ Shape , Shape ], left : bool = False ) -> dict [str , euklid .vector .Vector2D ]:
228+ def _get_attachment_point_positions (self , left : bool = False ) -> dict [str , euklid .vector .Vector2D ]:
216229
217230 points = {}
231+ shapes = self ._get_shapes ()
218232 shape = shapes [left ]
219233
220234 for rib_no , rib in enumerate (self .glider_3d .ribs ):
@@ -228,9 +242,9 @@ def _get_attachment_point_positions(self, shapes: tuple[Shape, Shape], left: boo
228242 return points
229243
230244
231- def draw_attachment_points (self , shapes : tuple [ Shape , Shape ], add_text : bool = True , left : bool = False ) -> None :
245+ def draw_attachment_points (self , add_text : bool = True , left : bool = False ) -> None :
232246 part = PlotPart ()
233- points = self ._get_attachment_point_positions (shapes , left = left )
247+ points = self ._get_attachment_point_positions (left = left )
234248
235249 for name , p1 in points .items ():
236250 p2 = p1 + euklid .vector .Vector2D ([0.1 , 0 ])
@@ -252,7 +266,8 @@ def draw_attachment_points(self, shapes: tuple[Shape, Shape], add_text: bool=Tru
252266
253267 self .drawing .parts .append (part )
254268
255- def draw_cells (self , shapes : tuple [Shape , Shape ], left : bool = False ) -> None :
269+ def draw_cells (self , left : bool = False ) -> None :
270+ shapes = self ._get_shapes ()
256271 shape = shapes [left ]
257272
258273 cells = []
@@ -269,7 +284,8 @@ def draw_cells(self, shapes: tuple[Shape, Shape], left: bool=False) -> None:
269284 material_code = "cell_numbers" )
270285 )
271286
272- def draw_cell_names (self , shapes : tuple [Shape , Shape ], left : bool = False ) -> None :
287+ def draw_cell_names (self , left : bool = False ) -> None :
288+ shapes = self ._get_shapes ()
273289 shape = shapes [left ]
274290 names = []
275291
@@ -287,7 +303,8 @@ def draw_cell_names(self, shapes: tuple[Shape, Shape], left: bool=False) -> None
287303 material_code = "cell_numbers" )
288304 )
289305
290- def draw_rib_names (self , shapes : tuple [Shape , Shape ], left : bool = False ) -> ShapePlot :
306+ def draw_rib_names (self , left : bool = False ) -> ShapePlot :
307+ shapes = self ._get_shapes ()
291308 shape = shapes [left ]
292309 names = []
293310
@@ -312,7 +329,8 @@ def draw_rib_names(self, shapes: tuple[Shape, Shape], left: bool=False) -> Shape
312329 )
313330 return self
314331
315- def draw_straps (self , shapes : tuple [Shape , Shape ], left : bool = False ) -> ShapePlot :
332+ def draw_straps (self , left : bool = False ) -> ShapePlot :
333+ shapes = self ._get_shapes ()
316334 shape = shapes [left ]
317335
318336 for cell_no in self ._get_cell_range (left ):
@@ -328,7 +346,8 @@ def draw_straps(self, shapes: tuple[Shape, Shape], left: bool=False) -> ShapePlo
328346
329347 return self
330348
331- def draw_diagonals (self , shapes : tuple [Shape , Shape ], left : bool = False ) -> ShapePlot :
349+ def draw_diagonals (self , left : bool = False ) -> ShapePlot :
350+ shapes = self ._get_shapes ()
332351 shape = shapes [left ]
333352
334353 for cell_no in self ._get_cell_range (left ):
@@ -344,14 +363,14 @@ def draw_diagonals(self, shapes: tuple[Shape, Shape], left: bool=False) -> Shape
344363
345364 return self
346365
347- def draw_lines (self , shapes : tuple [ Shape , Shape ], left : bool = True , add_text : bool = False ) -> ShapePlot :
366+ def draw_lines (self , left : bool = True , add_text : bool = False ) -> ShapePlot :
348367 #self.draw_design(lower=True)
349368 #self.draw_design(lower=True, left=True)
350369 #self.draw_attachment_points(True)
351370 #self.draw_attachment_points(True, left=True)
352371 lower = self .glider_3d .lineset .lower_attachment_points
353372
354- attachment_point_positions = self ._get_attachment_point_positions (shapes , left = False )
373+ attachment_point_positions = self ._get_attachment_point_positions (left = False )
355374 all_nodes = {}
356375 for node in self .glider_3d .lineset .nodes :
357376 if node .node_type == node .NODE_TYPE .UPPER :
0 commit comments