Skip to content

Commit

Permalink
Add selection modes
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorus committed Oct 13, 2022
1 parent b73d41b commit 8b2a71d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
41 changes: 33 additions & 8 deletions operators/select.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from bpy.types import Operator, Context
from bpy.props import IntProperty, BoolProperty
from bpy.props import IntProperty, BoolProperty, EnumProperty
from bpy.utils import register_classes_factory

from .utilities import select_all, deselect_all, select_extend, select_invert
Expand All @@ -10,8 +10,6 @@

class View3D_OT_slvs_select(Operator, HighlightElement):
"""
TODO: Add selection modes
Select an entity
Either the entity specified by the index property or the hovered index
Expand All @@ -20,21 +18,48 @@ class View3D_OT_slvs_select(Operator, HighlightElement):
"""

bl_idname = Operators.Select
bl_label = "Select Solvespace Entities"
bl_label = "Select Sketch Entities"

index: IntProperty(name="Index", default=-1)
mode: EnumProperty(
name="Mode",
items=[
("SET", "Set", "Set new selection", "SELECT_SET", 1),
("EXTEND", "Extend", "Add to existing selection", "SELECT_EXTEND", 2),
(
"SUBTRACT",
"Subtract",
"Subtract from existing selection",
"SELECT_SUBTRACT",
3,
),
("TOGGLE", "Toggle", "Toggle selection", "RADIOBUT_OFF", 4),
],
)

def execute(self, context: Context):
index = (
self.index
if self.properties.is_property_set("index")
else global_data.hover
)
if index != -1:
entity = context.scene.sketcher.entities.get(index)
entity.selected = not entity.selected
else:
hit = index != -1
mode = self.mode

if self.mode == "SET" or not hit:
deselect_all(context)

if hit:
entity = context.scene.sketcher.entities.get(index)

value = True
if mode == "SUBTRACT":
value = False
if mode == "TOGGLE":
value = not entity.selected

entity.selected = value

context.area.tag_redraw()
return {"FINISHED"}

Expand Down
1 change: 1 addition & 0 deletions workspacetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class VIEW3D_T_slvs_select(WorkSpaceTool):

def draw_settings(context, layout, tool):
props = tool.operator_properties(Operators.Select)
layout.prop(props, "mode", text="", expand=True, icon_only=True)


tool_keymap = (
Expand Down

0 comments on commit 8b2a71d

Please sign in to comment.