forked from hlorus/CAD_Sketcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_3d.py
51 lines (40 loc) · 1.71 KB
/
base_3d.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
import bpy
from bpy.types import Context, Event
from ..model.types import SlvsPoint3D, SlvsLine3D, SlvsWorkplane
from ..utilities.view import get_placement_pos
from .base_stateful import GenericEntityOp
from .utilities import ignore_hover
class Operator3d(GenericEntityOp):
@classmethod
def poll(cls, context: Context):
return context.scene.sketcher.active_sketch_i == -1
def state_func(self, context: Context, coords):
state = self.state
pos = get_placement_pos(context, coords)
# Handle implicit properties based on state.types
if SlvsPoint3D in state.types:
return pos
return super().state_func(context, coords)
def create_element(self, context, values, state, state_data):
sse = context.scene.sketcher.entities
loc = values[0]
point = sse.add_point_3d(loc)
self.add_coincident(context, point, state, state_data)
ignore_hover(point)
state_data["type"] = type(point)
return point.slvs_index
# Check if hovered entity should be constrained
def _check_constrain(self, context, index):
type = context.scene.sketcher.entities.type_from_index(index)
return type in (SlvsLine3D, SlvsWorkplane)
def get_point(self, context, index):
states = self.get_states_definition()
state = states[index]
data = self._state_data[index]
type = data["type"]
sse = context.scene.sketcher.entities
if type == bpy.types.MeshVertex:
ob_name, v_index = self.get_state_pointer(index=index, implicit=True)
ob = bpy.data.objects[ob_name]
return sse.add_ref_vertex_3d(ob, v_index)
return getattr(self, state.pointer)