From bb294b12c3aa7690433d4668e79ea144a1dd7b73 Mon Sep 17 00:00:00 2001 From: amrsoll Date: Sun, 11 Sep 2022 10:16:02 +0200 Subject: [PATCH] Restore reference constraints in the menu. --- ui.py | 67 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/ui.py b/ui.py index fab59a21..2da0a2b1 100644 --- a/ui.py +++ b/ui.py @@ -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: @@ -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 @@ -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 @@ -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", "", @@ -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 @@ -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"} @@ -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"} @@ -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, @@ -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 @@ -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", @@ -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"} @@ -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)