mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Refactor - Update input options display in Polyline tool UI
This commit is contained in:
@@ -410,6 +410,7 @@ class PolylineDecorator:
|
||||
"X": "X coord: ",
|
||||
"Y": "Y coord: ",
|
||||
"Z": "Z coord:",
|
||||
"AREA": "Area:",
|
||||
}
|
||||
try:
|
||||
mouse_pos = self.event.mouse_region_x, self.event.mouse_region_y
|
||||
@@ -425,11 +426,14 @@ class PolylineDecorator:
|
||||
color = self.addon_prefs.decorations_colour
|
||||
color_highlight = self.addon_prefs.decorator_color_special
|
||||
offset = 20
|
||||
new_line = 20
|
||||
new_line = 0
|
||||
for i, (key, field_name) in enumerate(texts.items()):
|
||||
|
||||
formatted_value = None
|
||||
if self.input_ui:
|
||||
# Controls which options are displayed in the UI
|
||||
if key not in self.input_ui.input_options:
|
||||
continue
|
||||
new_line += 20
|
||||
if self.tool_state and key != self.tool_state.input_type:
|
||||
formatted_value = self.input_ui.get_formatted_value(key)
|
||||
else:
|
||||
@@ -441,7 +445,7 @@ class PolylineDecorator:
|
||||
blf.color(self.font_id, *color_highlight)
|
||||
else:
|
||||
blf.color(self.font_id, *color)
|
||||
blf.position(self.font_id, mouse_pos[0] + offset, mouse_pos[1] - (new_line * i), 0)
|
||||
blf.position(self.font_id, mouse_pos[0] + offset, mouse_pos[1] - (new_line), 0)
|
||||
blf.draw(self.font_id, field_name + formatted_value)
|
||||
blf.disable(self.font_id, blf.SHADOW)
|
||||
|
||||
|
||||
@@ -550,9 +550,6 @@ class PolylineOperator:
|
||||
# TODO Fill doc strings
|
||||
""" """
|
||||
|
||||
number_input: list[str]
|
||||
input_type: tool.Polyline.InputType
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context: bpy.types.Context) -> bool:
|
||||
return context.space_data.type == "VIEW_3D"
|
||||
@@ -589,7 +586,7 @@ class PolylineOperator:
|
||||
self.input_options = ["D", "A", "X", "Y"]
|
||||
self.input_type = None
|
||||
self.input_value_xy = [None, None]
|
||||
self.input_ui = tool.Polyline.create_input_ui()
|
||||
self.input_ui = tool.Polyline.create_input_ui(input_options=self.input_options)
|
||||
self.is_typing = False
|
||||
self.snap_angle = None
|
||||
self.snapping_points = []
|
||||
|
||||
@@ -1128,8 +1128,8 @@ class DrawPolylineProfile(bpy.types.Operator, PolylineOperator, tool.Ifc.Operato
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.input_ui = tool.Polyline.create_input_ui(init_z=True)
|
||||
self.input_options = ["D", "A", "X", "Y", "Z"]
|
||||
self.input_ui = tool.Polyline.create_input_ui(input_options=self.input_options)
|
||||
self.relating_type = None
|
||||
props = tool.Model.get_model_props()
|
||||
relating_type_id = props.relating_type_id
|
||||
|
||||
@@ -2600,11 +2600,8 @@ class MeasureTool(bpy.types.Operator, PolylineOperator):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
if self.measure_type == "AREA":
|
||||
self.input_ui = tool.Polyline.create_input_ui(init_z=True, init_area=True)
|
||||
else:
|
||||
self.input_ui = tool.Polyline.create_input_ui(init_z=True)
|
||||
self.input_options = ["D", "A", "X", "Y", "Z"]
|
||||
self.input_ui = tool.Polyline.create_input_ui(input_options=self.input_options)
|
||||
|
||||
def modal(self, context, event):
|
||||
PolylineDecorator.update(event, self.tool_state, self.input_ui, self.snapping_points[0])
|
||||
|
||||
@@ -24,7 +24,7 @@ import ifcopenshell.util.unit
|
||||
import bonsai.core.tool
|
||||
import bonsai.tool as tool
|
||||
from bonsai.bim.module.drawing.helper import format_distance
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import dataclass, field
|
||||
from lark import Lark, Transformer
|
||||
from math import degrees, radians, sin, cos, tan
|
||||
from mathutils import Vector, Matrix
|
||||
@@ -39,16 +39,9 @@ class Polyline(bonsai.core.tool.Polyline):
|
||||
_WORLD_ANGLE: str = "" # Relative to World Origin. Only used for specific operation. Not used on the UI.
|
||||
_X: str = ""
|
||||
_Y: str = ""
|
||||
_Z: Optional[str] = None
|
||||
_AREA: Optional[str] = None
|
||||
init_z: bool = False
|
||||
init_area: bool = False
|
||||
|
||||
def __post_init__(self):
|
||||
if self.init_z:
|
||||
self._Z = ""
|
||||
if self.init_area:
|
||||
self._AREA = "0"
|
||||
_Z: str = ""
|
||||
_AREA: str = "0"
|
||||
input_options: List[str] = field(default_factory=list)
|
||||
|
||||
def set_value(self, attribute_name, value):
|
||||
value = str(value)
|
||||
@@ -76,8 +69,6 @@ class Polyline(bonsai.core.tool.Polyline):
|
||||
else:
|
||||
return Polyline.format_input_ui_units(value)
|
||||
|
||||
InputType = Literal["D", "A", "X", "Y", None]
|
||||
|
||||
@dataclass
|
||||
class ToolState:
|
||||
use_default_container: bool = None
|
||||
@@ -101,8 +92,8 @@ class Polyline(bonsai.core.tool.Polyline):
|
||||
input_type: "Polyline.InputType" = None
|
||||
|
||||
@classmethod
|
||||
def create_input_ui(cls, init_z: bool = False, init_area: bool = False) -> PolylineUI:
|
||||
return cls.PolylineUI(init_z=init_z, init_area=init_area)
|
||||
def create_input_ui(cls, input_options: List[str] = []) -> PolylineUI:
|
||||
return cls.PolylineUI(input_options=input_options)
|
||||
|
||||
@classmethod
|
||||
def create_tool_state(cls) -> ToolState:
|
||||
@@ -343,7 +334,7 @@ class Polyline(bonsai.core.tool.Polyline):
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def validate_input(cls, input_number: str, input_type: InputType) -> tuple[bool, str]:
|
||||
def validate_input(cls, input_number: str, input_type: str) -> tuple[bool, str]:
|
||||
"""
|
||||
:return: Tuple with a boolean indicating if the input is valid
|
||||
and the final string output.
|
||||
|
||||
Reference in New Issue
Block a user