/
polyline_shape.py
75 lines (50 loc) · 2.14 KB
/
polyline_shape.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from .shape import *
class Polyline_Shape(Shape):
def can_close(self):
return len(self._vertices) > 1
def close(self):
if self.can_close():
self._state = ShapeState.CREATED
return True
return False
def get_vertices_copy(self, mouse_pos = None):
result = self._vertices.copy()
if mouse_pos is not None and self.is_processing():
result.append(mouse_pos)
return result
def handle_mouse_press(self, mouse_pos_2d, mouse_pos_3d, event, context):
if mouse_pos_3d is None:
return False
if (self.is_none() and event.ctrl) or (self.is_processing() and not event.ctrl):
self.add_vertex(mouse_pos_3d)
self._vertices_2d.append(get_2d_vertex(context, mouse_pos_3d))
self.state = ShapeState.PROCESSING
return False
elif self.is_processing() and event.ctrl and self.can_close():
self.add_vertex(mouse_pos_3d)
self._vertices_2d.append(get_2d_vertex(context, mouse_pos_3d))
self.close()
return False
elif self.is_created() and event.ctrl:
return True
return False
def handle_mouse_move(self, mouse_pos_2d, mouse_pos_3d, event, context):
if self.is_processing():
return True
result = super().handle_mouse_move(mouse_pos_2d, mouse_pos_3d, event, context)
return result
def get_text(self, context):
text = "{0} | Mode (M): {1} | Primitive (P): {2} | {3}"
keyboard = "Esc: Exit"
mouse_action = "Add line: Ctrl + Left click"
p_type = "Polyline"
if self.is_created():
mouse_action = "Apply: Ctrl + Left Click"
keyboard = "Esc: Undo | G: Move | E: Extrude"
if self.is_processing():
keyboard = "Esc: Undo"
if self.can_close():
mouse_action = "Close Shape: Ctrl + Left Click"
else:
mouse_action = "Add line: Left Click"
return text.format(mouse_action, context.scene.bool_mode, p_type, keyboard)