@@ -43,20 +43,16 @@ def set_model(self, model):
43
43
self ._reverse_glyphs = []
44
44
self ._glyph_fields = []
45
45
46
+ self ._initialise_materials ()
47
+
46
48
region = model .get_projection_plane_region ()
47
49
field_module = region .getFieldmodule ()
48
50
scene = region .getScene ()
49
- self ._glyph_fields .append (field_module .createFieldConstant ([0 , 0 , 0 ]))
50
- self ._glyph_fields .append (field_module .createFieldConstant ([0 , 0 , 0 ]))
51
- self ._glyph_fields .append (field_module .createFieldConstant ([0 , 0 , 0 ]))
52
- self ._glyphs .append (create_plane_manipulation_arrow (scene , self ._glyph_fields [0 ], size = AXIS_ARROW_SIZE ))
53
- self ._glyphs .append (create_plane_manipulation_arrow (scene , self ._glyph_fields [1 ], size = AXIS_ARROW_SIZE ))
54
- self ._glyphs .append (create_plane_manipulation_arrow (scene , self ._glyph_fields [2 ], size = AXIS_ARROW_SIZE ))
55
- self ._reverse_glyphs .append (create_plane_manipulation_arrow (scene , self ._glyph_fields [0 ], size = - AXIS_ARROW_SIZE ))
56
- self ._reverse_glyphs .append (create_plane_manipulation_arrow (scene , self ._glyph_fields [1 ], size = - AXIS_ARROW_SIZE ))
57
- self ._reverse_glyphs .append (create_plane_manipulation_arrow (scene , self ._glyph_fields [2 ], size = - AXIS_ARROW_SIZE ))
58
51
59
- self ._initialise_materials ()
52
+ for i in range (3 ):
53
+ self ._glyph_fields .append (field_module .createFieldConstant ([0 , 0 , 0 ]))
54
+ self ._glyphs .append (create_plane_manipulation_arrow (scene , self ._glyph_fields [i ], size = AXIS_ARROW_SIZE , material = self ._default_material ))
55
+ self ._reverse_glyphs .append (create_plane_manipulation_arrow (scene , self ._glyph_fields [i ], size = - AXIS_ARROW_SIZE , material = self ._default_material ))
60
56
61
57
else :
62
58
raise HandlerError ('Given model does not have the required API for handling translation.' )
@@ -71,17 +67,13 @@ def enter(self):
71
67
x_vector , y_vector = _calculate_orthogonal_vectors (self ._model .plane_nodes_coordinates ())
72
68
normal = self ._model .get_plane_normal ()
73
69
74
- x_field_cache = self ._glyph_fields [0 ].getFieldmodule ().createFieldcache ()
75
- y_field_cache = self ._glyph_fields [1 ].getFieldmodule ().createFieldcache ()
76
- normal_field_cache = self ._glyph_fields [2 ].getFieldmodule ().createFieldcache ()
77
- self ._glyph_fields [0 ].assignReal (x_field_cache , x_vector .tolist ())
78
- self ._glyph_fields [1 ].assignReal (y_field_cache , y_vector .tolist ())
79
- self ._glyph_fields [2 ].assignReal (normal_field_cache , normal )
70
+ field_cache = self ._glyph_fields [0 ].getFieldmodule ().createFieldcache ()
71
+ for i , vector in enumerate ([x_vector , y_vector , normal ]):
72
+ self ._glyph_fields [i ].assignReal (field_cache , vector )
80
73
81
74
centroid = calculate_centroid (self ._model .plane_nodes_coordinates ())
82
75
for glyph in (self ._glyphs + self ._reverse_glyphs ):
83
76
glyph .setVisibilityFlag (True )
84
- glyph .setMaterial (self ._default_material )
85
77
set_glyph_position (glyph , centroid )
86
78
87
79
def leave (self ):
@@ -105,6 +97,7 @@ def mouse_press_event(self, event):
105
97
self ._selected_index = i
106
98
self ._glyphs [i ].setMaterial (self ._selected_material )
107
99
self ._reverse_glyphs [i ].setMaterial (self ._selected_material )
100
+ break
108
101
109
102
def mouse_move_event (self , event ):
110
103
if self ._selected_index is not None :
@@ -139,8 +132,9 @@ def mouse_move_event(self, event):
139
132
def mouse_release_event (self , event ):
140
133
super ().mouse_release_event (event )
141
134
142
- for glyph in (self ._glyphs + self ._reverse_glyphs ):
143
- glyph .setMaterial (self ._default_material )
135
+ if self ._selected_index is not None :
136
+ self ._glyphs [self ._selected_index ].setMaterial (self ._default_material )
137
+ self ._reverse_glyphs [self ._selected_index ].setMaterial (self ._default_material )
144
138
145
139
self ._start_position = None
146
140
self ._selected_index = None
@@ -153,4 +147,6 @@ def _calculate_orthogonal_vectors(points):
153
147
vectors .pop (max_index )
154
148
lengths .pop (max_index )
155
149
156
- return (vectors [0 ] / lengths [0 ]), (vectors [1 ] / lengths [1 ])
150
+ x_vector = vectors [0 ] / lengths [0 ]
151
+ y_vector = vectors [1 ] / lengths [1 ]
152
+ return x_vector .tolist (), y_vector .tolist ()
0 commit comments