forked from hlorus/CAD_Sketcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_circle.py
81 lines (65 loc) · 2.3 KB
/
add_circle.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
76
77
78
79
80
81
import logging
from bpy.types import Operator, Context
from bpy.props import FloatProperty
from mathutils import Vector
from ..declarations import Operators
from ..stateful_operator.utilities.register import register_stateops_factory
from ..stateful_operator.state import state_from_args
from ..solver import solve_system
from .base_2d import Operator2d
from .constants import types_point_2d
from .utilities import ignore_hover
logger = logging.getLogger(__name__)
class View3D_OT_slvs_add_circle2d(Operator, Operator2d):
"""Add a circle to the active sketch"""
bl_idname = Operators.AddCircle2D
bl_label = "Add Solvespace 2D Circle"
bl_options = {"REGISTER", "UNDO"}
circle_state1_doc = ("Center", "Pick or place circle's center point.")
circle_state2_doc = ("Radius", "Set circle's radius.")
radius: FloatProperty(
name="Radius",
subtype="DISTANCE",
unit="LENGTH",
precision=5,
# precision=get_prefs().decimal_precision,
)
states = (
state_from_args(
circle_state1_doc[0],
description=circle_state1_doc[1],
pointer="ct",
types=types_point_2d,
),
state_from_args(
circle_state2_doc[0],
description=circle_state2_doc[1],
property="radius",
state_func="get_radius",
interactive=True,
allow_prefill=False,
),
)
def get_radius(self, context: Context, coords):
wp = self.sketch.wp
pos = self.state_func(context, coords)
if pos is None:
return None
delta = Vector(pos) - self.ct.co
radius = delta.length
return radius
def main(self, context: Context):
wp = self.sketch.wp
ct = self.get_point(context, 0)
self.target = context.scene.sketcher.entities.add_circle(
wp.nm, ct, self.radius, self.sketch
)
ignore_hover(self.target)
return True
def fini(self, context: Context, succeede: bool):
if hasattr(self, "target"):
logger.debug("Add: {}".format(self.target))
if succeede:
if self.has_coincident:
solve_system(context, sketch=self.sketch)
register, unregister = register_stateops_factory((View3D_OT_slvs_add_circle2d,))