wolfhece._viewer_plugin_handlers ================================ .. py:module:: wolfhece._viewer_plugin_handlers .. autoapi-nested-parse:: Per-action mouse handlers for WolfMapViewer. Rationale --------- ``On_Mouse_Right_Down`` and ``On_Mouse_Motion`` were monolithic catch-all chains of ``if/elif`` blocks — one branch per action. This module extracts those branches into individual handler functions and exposes two dispatch tables: * ``ACTION_RDOWN_HANDLERS`` — called on right mouse-button press. * ``ACTION_MOTION_HANDLERS`` — called on mouse motion while an action is active. Usage (in WolfMapViewer):: ctx = MouseContext(x, y, x_snap, y_snap, x_pixel=0, y_pixel=0, keyboard=KeyboardSnapshot(alt=alt, ctrl=ctrl, shift=shift)) if self.action in ACTION_RDOWN_HANDLERS: ACTION_RDOWN_HANDLERS[self.action](self, ctx) Adding a new action ------------------- 1. Write ``_rdown_(viewer, ctx)`` and/or ``_motion_(viewer, ctx)``. 2. Register in ``ACTION_RDOWN_HANDLERS`` / ``ACTION_MOTION_HANDLERS``. 3. Add an ``ActionKind`` entry to ``_action_kind.py`` if not yet present. Each handler receives the viewer (``WolfMapViewer``) and a ``MouseContext``. Handlers must NOT import ``WolfMapViewer`` at module level to avoid circular imports — use ``TYPE_CHECKING`` for type hints only. Module Contents --------------- .. py:class:: KeyboardSnapshot Keyboard state snapshot — covers both polled and event-driven contexts. *When embedded in a* :class:`MouseContext` *(polled at mouse-event time)*: ``key_code = 0``, ``is_down = True``, ``held`` contains all non-modifier keys currently pressed. *When built from a* ``wx.KeyEvent`` *(key-down / key-up)*: ``key_code`` = triggering key, ``is_down`` = True/False, ``held`` = empty frozenset (not polled for key events). .. py:attribute:: ctrl :type: bool :value: False .. py:attribute:: shift :type: bool :value: False .. py:attribute:: alt :type: bool :value: False .. py:attribute:: key_code :type: int :value: 0 .. py:attribute:: is_down :type: bool :value: True .. py:attribute:: held :type: frozenset .. py:method:: is_key_down(key_code: int) -> bool Return ``True`` if *key_code* is currently held. .. py:class:: MouseContext Preprocessed mouse event data passed to every action handler. All coordinates are in *world* space (map units, not pixels). Keyboard modifier state is accessible via the :attr:`keyboard` attribute or the convenience properties :attr:`alt`, :attr:`ctrl`, :attr:`shift`. .. py:attribute:: x :type: float .. py:attribute:: y :type: float .. py:attribute:: x_snap :type: float .. py:attribute:: y_snap :type: float .. py:attribute:: x_pixel :type: int .. py:attribute:: y_pixel :type: int .. py:attribute:: keyboard :type: KeyboardSnapshot .. py:attribute:: left_down :type: bool :value: False .. py:attribute:: middle_down :type: bool :value: False .. py:attribute:: right_down :type: bool :value: False .. py:attribute:: pressure :type: float :value: 1.0 .. py:attribute:: wheel_rotation :type: int :value: 0 .. py:attribute:: wheel_delta :type: int :value: 120 .. py:property:: alt :type: bool Alt key held (delegates to ``keyboard.alt``). .. py:property:: ctrl :type: bool Ctrl key held (delegates to ``keyboard.ctrl``). .. py:property:: shift :type: bool Shift key held (delegates to ``keyboard.shift``). .. py:data:: _RightDownHandler .. py:data:: _LeftDownHandler .. py:data:: _KeyHandler .. py:data:: _PaintHandler .. py:function:: _rdown_move_vector(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Right-click handler for MOVE_VECTOR. First click records the start position; second click commits the move. Shift constrains vertical movement to zero; Alt constrains horizontal. .. py:function:: _rdown_rotate_vector(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Right-click handler for ROTATE_VECTOR. First click sets the rotation centre; second click commits the rotation. Shift+click sets a discrete rotation step; Shift+Ctrl+click clears it. .. py:function:: _rdown_move_triangles(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Right-click handler for MOVE_TRIANGLES. First click records the start; second click commits the move. Shift constrains vertical movement; Alt constrains horizontal. .. py:function:: _rdown_rotate_triangles(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Right-click handler for ROTATE_TRIANGLES. First click sets the rotation centre; second click commits the rotation. Shift+click sets a discrete step; Shift+Ctrl+click clears it. .. py:function:: _rdown_move_zone(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Right-click handler for MOVE_ZONE. First click records the start; second click commits the move. .. note:: The shift/alt constraints set ``delta_x``/``delta_y`` local variables that are **not** forwarded to ``zone.move()`` — this matches the original behaviour (preserved intentionally). .. py:function:: _rdown_rotate_zone(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Right-click handler for ROTATE_ZONE. First click sets the rotation centre; second click commits the rotation. .. py:function:: _rdown_add_points_to_cloud(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Shift: remove nearest vertex. Ctrl: remove last vertex. Else: add snapped vertex. .. py:function:: _rdown_move_point_in_cloud(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None First click picks nearest vertex; second click commits the final position. .. py:function:: _rdown_plot_alaro_xy(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_distance_along_vector(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_pick_pie_center(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_pick_bar_position(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_pick_curve_origin(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_pick_landmap(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_pick_municipality(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_pick_a_picture(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_pick_bridge(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_pick_weir(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_bridge_gltf(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Delegate to PyDraw._bridge_gltf_dialog() which owns the wx dialogs. .. py:function:: _rdown_plot_cross_section(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_set_1d_profile(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Delegate to PyDraw._set_1d_profile_rdown() which owns the notebook/wx logic. .. py:function:: _rdown_select_nearest_profile(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Delegate to PyDraw._select_nearest_profile_rdown() which owns the notebook/wx logic. .. py:function:: _rdown_select_active_tile(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_select_active_image_tile(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_pick_catchment_lidaxe(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_pick_path_lidaxe(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_select_active_vector(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Handler inspects v.action to differentiate inside/outside and single/all-zone. .. py:function:: _rdown_select_node(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_select_by_vector(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_laz_tmp_vector(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_create_polygon_tiles(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_capture_vertices(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Update the trailing preview vertex, append a new one, optionally sample Z. .. py:function:: _rdown_offset_scale_image(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None First click records start; second click commits the image offset. .. py:function:: _rdown_dynamic_parallel(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None .. py:function:: _rdown_modify_vertices(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None First click picks nearest vertex; second click confirms (optionally samples Z). .. py:function:: _rdown_insert_vertices(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None First click inserts vertex at nearest edge; second click confirms. .. py:function:: _motion_move_vector(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Motion handler for MOVE_VECTOR — live preview while the start is set. .. py:function:: _motion_rotate_vector(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Motion handler for ROTATE_VECTOR — live preview while centre is set. .. py:function:: _motion_move_triangles(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Motion handler for MOVE_TRIANGLES — live preview while start is set. .. py:function:: _motion_rotate_triangles(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Motion handler for ROTATE_TRIANGLES — live preview while centre is set. .. py:function:: _motion_move_zone(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Motion handler for MOVE_ZONE — live preview while start is set. .. py:function:: _motion_rotate_zone(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Motion handler for ROTATE_ZONE — live preview while centre is set. .. py:function:: _motion_move_point_in_cloud(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Live preview for MOVE_POINT_IN_CLOUD while vertex is picked. .. py:function:: _motion_dynamic_parallel(v: wolfhece.PyDraw.WolfMapViewer, ctx: MouseContext) -> None Recompute the parallel line on every mouse-move (no coords needed). .. py:data:: ACTION_RDOWN_HANDLERS :type: dict[wolfhece._action_kind.ActionKind, _RightDownHandler] .. py:data:: ACTION_MOTION_HANDLERS :type: dict[wolfhece._action_kind.ActionKind, _RightDownHandler]