Skip to content

Commit

Permalink
Restore reference constraints in the menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
amrsoll committed Sep 11, 2022
1 parent 45325da commit bb294b1
Showing 1 changed file with 49 additions and 18 deletions.
67 changes: 49 additions & 18 deletions ui.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import bpy
from bpy.types import Panel, Menu, UIList, Context, UILayout
from bpy.types import Panel, Menu, UIList, Context, UILayout, PropertyGroup

from . import functions
from .declarations import Menus, Operators, Panels, ConstraintOperators
from .stateful_operator.constants import Operators as StatefulOperators

from .model.types import GenericConstraint, DimensionalConstraint

class VIEW3D_UL_sketches(UIList):
"""Creates UI list of available Sketches"""
def draw_item(
self, context, layout, data, item, icon, active_data, active_propname, index=0
self,
context: Context,
layout: UILayout,
data: PropertyGroup,
item: PropertyGroup,
icon: int,
active_data: PropertyGroup,
active_propname: str,
index: int=0
):
if self.layout_type in {"DEFAULT", "COMPACT"}:
if item:
Expand Down Expand Up @@ -70,6 +79,7 @@ class VIEW3D_PT_sketcher_base(Panel):


class VIEW3D_PT_sketcher(VIEW3D_PT_sketcher_base):
"""Menu for selecting the sketch you want to enter into"""
bl_label = "Sketcher"
bl_idname = Panels.Sketcher

Expand All @@ -82,6 +92,7 @@ def draw(self, context: Context):
layout.use_property_decorate = False

if sketch:
# Sketch is selected, show info about the sketch itself
row = layout.row()
row.alignment = "CENTER"
row.scale_y = 1.2
Expand Down Expand Up @@ -123,6 +134,7 @@ def draw(self, context: Context):
).index = sketch.slvs_index

else:
# No active Sketch , show list of available sketches
layout.template_list(
"VIEW3D_UL_sketches",
"",
Expand All @@ -134,6 +146,7 @@ def draw(self, context: Context):


class VIEW3D_PT_sketcher_debug(VIEW3D_PT_sketcher_base):
"""Debug Menu"""
bl_label = "Debug Settings"
bl_idname = Panels.SketcherDebugPanel

Expand All @@ -160,6 +173,7 @@ def poll(cls, context: Context):


class VIEW3D_PT_sketcher_add_constraints(VIEW3D_PT_sketcher_base):
"""Add Constraint Menu: List of buttons with the constraint you want to create."""
bl_label = "Add Constraints"
bl_idname = Panels.SketcherAddContraint
bl_options = {"DEFAULT_CLOSED"}
Expand All @@ -173,6 +187,10 @@ def draw(self, context: Context):


class VIEW3D_PT_sketcher_entities(VIEW3D_PT_sketcher_base):
"""
Entities Menu: List of entities in the sketch.
Interactive
"""
bl_label = "Entities"
bl_idname = Panels.SketcherEntities
bl_options = {"DEFAULT_CLOSED"}
Expand Down Expand Up @@ -255,15 +273,21 @@ def draw(self, context: Context):
col.separator()


def draw_constraint_listitem(context, layout, constraint):
def draw_constraint_listitem(
context: Context,
layout: UILayout,
constraint: GenericConstraint
):
"""Creates a single row inside the ``layout`` describing the ``constraint``."""
index = context.scene.sketcher.constraints.get_index(constraint)
row = layout.row()

left_sub = row.row(align=True)

# Left part
sub = row.row(align=True)
sub.alignment = "LEFT"
left_sub.alignment = "LEFT"

sub.prop(
left_sub.prop(
constraint,
"visible",
icon_only=True,
Expand All @@ -272,28 +296,31 @@ def draw_constraint_listitem(context, layout, constraint):
)

# Failed hint
sub.label(
left_sub.label(
text="",
icon=("ERROR" if constraint.failed else "CHECKMARK"),
)
# Label
left_sub.prop(constraint, "name", text="")

# Middle Part
sub = row.row()
sub.alignment = "LEFT"
center_sub = row.row()
center_sub.alignment = "LEFT"

# Label
sub.prop(constraint, "name", text="")

# Dimensional Constraint Values
for constraint_prop in constraint.props:
sub.prop(constraint, constraint_prop, text="")
center_sub.prop(constraint, constraint_prop, text="")

# Disable interaction with element if it is "readonly"
center_sub.enabled = isinstance(constraint, DimensionalConstraint) and constraint.is_reference

# Right part
sub = row.row()
sub.alignment = "RIGHT"
right_sub = row.row()
right_sub.alignment = "RIGHT"

# Context menu, shows constraint name
props = sub.operator(
props = right_sub.operator(
Operators.ContextMenu, text="", icon="OUTLINER_DATA_GP_LAYER", emboss=False
)
props.type = constraint.type
Expand All @@ -303,7 +330,7 @@ def draw_constraint_listitem(context, layout, constraint):
props.highlight_members = True

# Delete operator
props = sub.operator(
props = right_sub.operator(
Operators.DeleteConstraint,
text="",
icon="X",
Expand All @@ -316,6 +343,10 @@ def draw_constraint_listitem(context, layout, constraint):


class VIEW3D_PT_sketcher_constraints(VIEW3D_PT_sketcher_base):
"""
Constraints Menu: List of entities in the sketch.
Interactive
"""
bl_label = "Constraints"
bl_idname = Panels.SketcherContraints
bl_options = {"DEFAULT_CLOSED"}
Expand All @@ -335,7 +366,7 @@ def draw(self, context: Context):

sketch = context.scene.sketcher.active_sketch
for c in context.scene.sketcher.constraints.dimensional:
if not c.is_active(sketch) or c.is_reference:
if not c.is_active(sketch):
continue
draw_constraint_listitem(context, col, c)

Expand Down

0 comments on commit bb294b1

Please sign in to comment.