forked from hlorus/CAD_Sketcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.py
114 lines (89 loc) · 3.24 KB
/
sketch.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import logging
from typing import List
import bpy
from bpy.types import PropertyGroup
from bpy.props import EnumProperty, BoolProperty, IntProperty, PointerProperty
from bpy.utils import register_classes_factory
from .. import global_data
from ..solver import Solver, solve_system
from .base_entity import SlvsGenericEntity
from .utilities import slvs_entity_pointer
from ..utilities.bpy import unique_attribute_setter, bpyEnum
logger = logging.getLogger(__name__)
convert_items = [
("NONE", "None", "", 1),
("BEZIER", "Bezier", "", 2),
("MESH", "Mesh", "", 3),
]
# TODO: draw sketches and allow selecting
class SlvsSketch(SlvsGenericEntity, PropertyGroup):
"""A sketch groups 2 dimensional entities together and is used to later
convert geometry to native blender types.
Entities that belong to a sketch can only be edited as long as the sketch is active.
Arguments:
wp (SlvsWorkplane): The base workplane of the sketch
"""
unique_names = ["name"]
def hide_sketch(self, context):
if self.convert_type != "NONE":
self.visible = False
convert_type: EnumProperty(
name="Convert Type",
items=convert_items,
description="Define how the sketch should be converted in order to be usable in native blender",
update=hide_sketch,
)
fill_shape: BoolProperty(
name="Fill Shape",
description="Fill the resulting shape if it's closed",
default=True,
)
solver_state: EnumProperty(
name="Solver Status", items=global_data.solver_state_items
)
dof: IntProperty(name="Degrees of Freedom", max=6)
target_curve: PointerProperty(type=bpy.types.Curve)
target_curve_object: PointerProperty(type=bpy.types.Object)
target_mesh: PointerProperty(type=bpy.types.Mesh)
target_object: PointerProperty(type=bpy.types.Object)
curve_resolution: IntProperty(
name="Mesh Curve Resolution", default=12, min=1, soft_max=25
)
def dependencies(self) -> List[SlvsGenericEntity]:
return [
self.wp,
]
def sketch_entities(self, context):
for e in context.scene.sketcher.entities.all:
if not hasattr(e, "sketch"):
continue
if e.sketch != self:
continue
yield e
def update(self):
self.is_dirty = False
def draw(self, context):
pass
def draw_id(self, context):
pass
def create_slvs_data(self, solvesys, group=Solver.group_fixed):
pass
def remove_objects(self):
for ob in (self.target_object, self.target_curve_object):
if not ob:
continue
bpy.data.objects.remove(ob)
def is_visible(self, context):
if context.scene.sketcher.active_sketch_i == self.slvs_index:
return True
return self.visible
def get_solver_state(self):
return bpyEnum(global_data.solver_state_items, identifier=self.solver_state)
def solve(self, context):
return solve_system(context, sketch=self)
@classmethod
def is_sketch(cls):
return True
slvs_entity_pointer(SlvsSketch, "wp")
SlvsSketch.__setattr__ = unique_attribute_setter
register, unregister = register_classes_factory((SlvsSketch,))