22
33from __future__ import annotations
44
5- from typing import Any , Literal , TypedDict , Union , NotRequired
6- from enum import Enum
5+ from enum import IntEnum
6+ from typing import Any , Literal , NotRequired , TypedDict , Union
77
88from bot .core .spline import BEZIER_TYP , NURBS_TYP
99
1010
11- class SceneUpdateOp (str , Enum ):
11+ class SceneUpdateOp (IntEnum ):
1212 """
1313 Category 1: Geometric Update Flow (Parent -> Child)
1414 Heavy payloads used to synchronize 3D topology and geometry.
1515 """
16- ADD = "add" # Initializes or fully rebuilds the scene.
17- UPDATE = "update" # Applies a partial patch to existing geometries.
18- DELETE = "delete" # Removes one or multiple geometries from the scene.
1916
17+ ADD = 1 # Initializes or fully rebuilds the scene.
18+ UPDATE = 2 # Applies a partial patch to existing geometries.
19+ DELETE = 3 # Removes one or multiple geometries from the scene.
2020
21- class ViewerCommandType (str , Enum ):
21+
22+ class ViewerCommandType (IntEnum ):
2223 """
2324 Category 2: Display State Commands (Parent -> Child)
2425 Orders given to the GUI by the parent process.
2526 """
27+
2628 # FIXME Color changes on hover should be detected and applied locally by the child.
27- HIGHLIGHT_CURVE = "highlight_curve"
29+ HIGHLIGHT_CURVE = 10
2830
2931 # Legitimate: The parent sends domain-specific data (calculated by the kernel) that the child lacks.
30- UPDATE_HUD = "update_hud"
32+ UPDATE_HUD = 11
3133
3234 # Legitimate: The parent (script/kernel) forces the UI into edit mode programmatically.
33- SET_EDIT_MODE = "set_edit_mode"
35+ SET_EDIT_MODE = 12
3436
3537 # Legitimate: The parent targets a specific curve programmatically.
36- SET_ACTIVE_CURVE = "set_active_curve"
38+ SET_ACTIVE_CURVE = 13
3739
3840 # FIXME The child already has the math logic (ConstraintManager) to calculate axes locally.
39- SET_AXIS_CONSTRAINT = "set_axis_constraint"
41+ SET_AXIS_CONSTRAINT = 14
4042
4143 # Legitimate: The parent commands the child process to terminate gracefully.
42- EXIT = "exit"
44+ EXIT = 15
4345
46+ RELOAD_CONFIG = 16
4447
45- class ViewEventType (str , Enum ):
48+
49+ class ViewEventType (IntEnum ):
4650 """
4751 Category 3: User Interaction Events (Child -> Parent)
4852 Notifications of physical user actions occurring in the 3D window.
4953 """
54+
5055 # FIXME If no custom user callback is set, sending this just to trigger a HIGHLIGHT_CURVE is wasteful.
51- HOVER = "hover"
56+ HOVER = 100
5257
5358 # Legitimate: The parent needs to know which curve was clicked to update its internal state.
54- CURVE_SELECTED = "curve_selected"
59+ CURVE_SELECTED = 101
5560
5661 # Legitimate: Notifies the parent that a control point drag operation has started.
57- CP_PICK_START = "cp_pick_start"
62+ CP_PICK_START = 102
5863
5964 # FIXME Sending mouse position at 60 FPS clogs the IPC pipe.
6065 # The child should handle real-time visual updates locally via `preview_evaluate`.
61- CP_DRAG = "cp_drag"
66+ CP_DRAG = 103
6267
6368 # Legitimate (Crucial): The parent receives the final position to permanently update the math kernel.
64- CP_PICK_END = "cp_pick_end"
69+ CP_PICK_END = 104
6570
6671 # Legitimate: The parent receives an absolute 3D coordinate to instantiate a new free point.
67- PICK = "pick"
72+ PICK = 105
73+
74+
75+ ParentCommand = SceneUpdateOp | ViewerCommandType
76+ ParentMessage = tuple [ParentCommand , Any ]
77+ ChildMessage = tuple [ViewEventType , Any ]
6878
6979
7080class CurveGeometry (TypedDict ):
@@ -89,7 +99,7 @@ class CurveDelta(TypedDict):
8999class ScenePayload (TypedDict ):
90100 """Universal exchange format for incremental scene updates."""
91101
92- op : Literal [ "add" , "update" , "delete" ]
102+ op : SceneUpdateOp
93103 changed_curves : dict [str , CurveDelta ]
94104 deleted_curves : NotRequired [list [str ]]
95105 bounds : NotRequired [dict [str , Any ]]
@@ -98,45 +108,82 @@ class ScenePayload(TypedDict):
98108
99109
100110class EventHover (TypedDict ):
101- event_type : Literal ["hover" ]
111+ event_type : Literal [ViewEventType . HOVER ]
102112 tag : str | None
103113
114+
104115class EventCurveSelected (TypedDict ):
105- event_type : Literal ["curve_selected" ]
116+ event_type : Literal [ViewEventType . CURVE_SELECTED ]
106117 curve_tag : str
107118
108- class EventCPInteraction (TypedDict ):
109- event_type : Literal ["cp_pick_start" , "cp_drag" , "cp_pick_end" ]
119+
120+ class EventCPPickStart (TypedDict ):
121+ event_type : Literal [ViewEventType .CP_PICK_START ]
122+ curve_tag : str
123+ cp_index : int
124+ world_pos : list [float ]
125+
126+
127+ class EventCPDrag (TypedDict ):
128+ event_type : Literal [ViewEventType .CP_DRAG ]
110129 curve_tag : str
111130 cp_index : int
112131 world_pos : list [float ]
113132
133+
134+ class EventCPPickEnd (TypedDict ):
135+ event_type : Literal [ViewEventType .CP_PICK_END ]
136+ curve_tag : str
137+ cp_index : int
138+ world_pos : list [float ]
139+
140+
114141class EventPick (TypedDict ):
115- event_type : Literal ["pick" ]
142+ event_type : Literal [ViewEventType . PICK ]
116143 world_pos : list [float ]
117144
118- ViewEvent = Union [EventHover , EventCurveSelected , EventCPInteraction , EventPick ]
119145
146+ ViewEvent = Union [
147+ EventHover ,
148+ EventCurveSelected ,
149+ EventCPPickStart ,
150+ EventCPDrag ,
151+ EventCPPickEnd ,
152+ EventPick ,
153+ ]
120154
121155
122156class CmdHighlightCurve (TypedDict ):
123- cmd : Literal ["highlight_curve" ]
157+ cmd : Literal [ViewerCommandType . HIGHLIGHT_CURVE ]
124158 tag : str
125159 color : list [float ]
126160
161+
127162class CmdUpdateHud (TypedDict ):
128- cmd : Literal ["update_hud" ]
163+ cmd : Literal [ViewerCommandType . UPDATE_HUD ]
129164 text : str
130165
166+
131167class CmdSetEditMode (TypedDict ):
132- cmd : Literal ["set_edit_mode" ]
168+ cmd : Literal [ViewerCommandType . SET_EDIT_MODE ]
133169 enabled : bool
134170 curve_tag : str | None
135171
172+
136173class CmdSetActiveCurve (TypedDict ):
137- cmd : Literal ["set_active_curve" ]
174+ cmd : Literal [ViewerCommandType . SET_ACTIVE_CURVE ]
138175 curve_tag : str | None
139176
177+
178+ class CmdSetAxisConstraint (TypedDict ):
179+ cmd : Literal [ViewerCommandType .SET_AXIS_CONSTRAINT ]
180+ mask : int
181+
182+
140183ViewerCommand = Union [
141- CmdHighlightCurve , CmdUpdateHud , CmdSetEditMode , CmdSetActiveCurve
142- ]
184+ CmdHighlightCurve ,
185+ CmdUpdateHud ,
186+ CmdSetEditMode ,
187+ CmdSetActiveCurve ,
188+ CmdSetAxisConstraint ,
189+ ]
0 commit comments