@@ -14,23 +14,12 @@ class Renderer:
14
14
15
15
scalar = None
16
16
17
- def __init__ (self , model ):
18
- self .model = model
19
-
20
- # Default settings for rendering
21
- self ._annotation_size = 5
22
- self ._deformed_shape = False
23
- self ._deformed_scale = 30
24
- self ._render_nodes = True
25
- self ._render_loads = True
26
- self ._color_map = None
27
- self ._combo_name = "Combo 1"
28
- self ._case = None
29
- self ._labels = True
30
- self ._scalar_bar = False
31
- self ._scalar_bar_text_size = 24
32
- self .theme = "default"
33
- self .colors = dict (
17
+ def __init__ (
18
+ self ,
19
+ model ,
20
+ combo_name : str ,
21
+ annotation_size : int = 5 ,
22
+ colors : dict = dict (
34
23
annotation_text = "black" ,
35
24
annotation_point = "grey" ,
36
25
point_label_text = "green" ,
@@ -42,22 +31,46 @@ def __init__(self, model):
42
31
dist_load = "green" ,
43
32
moment_load = "green" ,
44
33
area_load = "green" ,
45
- )
46
- self .line_widths = dict (
34
+ ),
35
+ deformed_scale : float = 30.0 ,
36
+ deformed_shape : bool = False ,
37
+ labels : bool = True ,
38
+ line_widths = dict (
47
39
member = 4 ,
48
40
loads = 2 ,
49
41
deformed_member = 2 ,
50
42
spring = 3
51
- )
43
+ ),
44
+ title : str = "Pynite - Simple Finite Element Analysis for Python" ,
45
+ window_height : int = 800 ,
46
+ window_width : int = 800 ,
47
+ ):
48
+ self .model = model
52
49
50
+ # Default settings for rendering
51
+ self ._annotation_size = annotation_size
52
+ self ._deformed_shape = deformed_shape
53
+ self ._deformed_scale = deformed_scale
54
+ self ._render_nodes = True
55
+ self ._render_loads = True
56
+ self ._color_map = None
57
+ self ._combo_name = combo_name
58
+ self ._case = None
59
+ self ._labels = labels
60
+ self ._scalar_bar = False
61
+ self ._scalar_bar_text_size = 24
62
+ self .theme = "default"
63
+ self .colors = colors
64
+ self .line_widths = line_widths
53
65
self ._title = "Pynite - Simple Finite Element Analysis for Python"
54
-
66
+ self ._window_width = window_width
67
+ self ._window_height = window_height
55
68
self .plotter = None
56
69
57
70
58
71
self ._layout = default_layout (self ._title )
59
- self .window_width = 800
60
- self .window_height = 800
72
+ self ._layout . width = window_width
73
+ self ._layout . height = window_height
61
74
62
75
# self.plotter.set_background('white') # Setting background color
63
76
# # self.plotter.add_logo_widget('./Resources/Full Logo No Buffer - Transparent.png')
@@ -72,6 +85,7 @@ def __init__(self, model):
72
85
# Initialize spring labels
73
86
self ._spring_label_points = []
74
87
self ._spring_labels = []
88
+ self ._annotations = []
75
89
76
90
## Get Figure Size
77
91
@@ -207,7 +221,6 @@ def render_model(self, reset_camera=True):
207
221
self .update (reset_camera )
208
222
209
223
# Render the model (code execution will pause here until the user closes the window)
210
- self .plotter .show ()
211
224
return self .plotter
212
225
213
226
def screenshot (
@@ -271,8 +284,7 @@ def update(self, reset_camera=True):
271
284
# Clear out the old plot (if any)
272
285
self .plotter = go .Figure ()
273
286
274
- layout = default_layout (self ._title )
275
- self ._layout = layout
287
+ layout = self ._layout
276
288
277
289
## Set the layout
278
290
self .plotter .layout = self ._layout
@@ -1671,6 +1683,8 @@ def add_point_labels(
1671
1683
point_size : int = 5 ,
1672
1684
shape : str = None ,
1673
1685
render_points_as_spheres = False ,
1686
+ x_shift = 0 ,
1687
+ y_shift = 0
1674
1688
):
1675
1689
assert len (points ) == len (labels )
1676
1690
# if show_points or render_points_as_spheres or shape:
@@ -1685,17 +1699,14 @@ def add_point_labels(
1685
1699
label = labels [idx ]
1686
1700
x , y , z = point
1687
1701
text_label = f"{ start_bold_tag } { label } { end_bold_tag } "
1688
- # annotations.append(
1689
- # dict(
1690
- # x=x,
1691
- # y=y,
1692
- # z=z,
1693
- # text=text_label,
1694
- # font=dict(
1695
- # color=self.colors['point_label_text']
1696
- # ),
1697
- # )
1698
- # )
1702
+ if render_points_as_spheres :
1703
+ ...
1704
+ self .plotter .add_trace (
1705
+ go .Scatter3d (
1706
+ x = [x ], y = [y ], z = [z ], marker = dict (color = point_color , size = self .annotation_size / 30 )
1707
+ )
1708
+ )
1709
+ # print(f"Annotation: {text_label=} | {point=}")
1699
1710
annotations .append (
1700
1711
dict (
1701
1712
x = x ,
@@ -1704,15 +1715,15 @@ def add_point_labels(
1704
1715
text = text_label ,
1705
1716
showarrow = False ,
1706
1717
font = dict (
1707
- color = self . colors [ 'point_label_text' ] ,
1718
+ color = text_color ,
1708
1719
size = 16
1709
1720
),
1710
- yshift = 5 ,
1711
- xshift = 5
1721
+ yshift = y_shift ,
1722
+ xshift = x_shift ,
1712
1723
)
1713
1724
)
1714
-
1715
- self .plotter .update_layout (scene = dict (annotations = annotations ))
1725
+ self . _annotations += annotations
1726
+ self .plotter .update_layout (scene = dict (annotations = self . _annotations ))
1716
1727
# TODO: Show points
1717
1728
1718
1729
0 commit comments