Source code for wolfhece._simtools2d_manager

"""
Companion manager for Tools 2D (CPU/Fortran Wolf2D) menus and actions.
Extracted from PyDraw.WolfMapViewer.
"""
from __future__ import annotations

import logging
from typing import TYPE_CHECKING

import wx

from .PyTranslate import _

if TYPE_CHECKING:
    from .PyDraw import WolfMapViewer


[docs] class SimTools2DManager: """Manages the Tools 2D (CPU) menu and associated actions.""" def __init__(self, viewer: 'WolfMapViewer') -> None:
[docs] self._viewer = viewer
[docs] self._menu: wx.Menu | None = None
# ------------------------------------------------------------------ # Menu build # ------------------------------------------------------------------
[docs] def menu_build(self) -> None: v = self._viewer if self._menu is None: self._menu = wx.Menu() v.menubar.Append(self._menu, _('Tools 2D')) item_parameters = self._menu.Append(wx.ID_ANY, _("Parameters..."), _("Parameters")) item_zbin2hbin = self._menu.Append(wx.ID_ANY, _("Convert zbin to hbin"), _("Convert zbin to hbin")) item_hbin2zbin = self._menu.Append(wx.ID_ANY, _("Convert hbin to zbin"), _("Convert hbin to zbin")) item_zbinb2hbinb = self._menu.Append(wx.ID_ANY, _("Convert zbinb to hbinb"), _("Convert zbinb to hbinb")) item_hbinb2zbinb = self._menu.Append(wx.ID_ANY, _("Convert hbinb to zbinb"), _("Convert hbinb to zbinb")) item_reset_mask = self._menu.Append(wx.ID_ANY, _("Reset mask of all arrays"), _("Reset mask")) self._menu.Bind(wx.EVT_MENU, self._on_parameters, item_parameters) self._menu.Bind(wx.EVT_MENU, self._on_zbin2hbin, item_zbin2hbin) self._menu.Bind(wx.EVT_MENU, self._on_hbin2zbin, item_hbin2zbin) self._menu.Bind(wx.EVT_MENU, self._on_zbinb2hbinb, item_zbinb2hbinb) self._menu.Bind(wx.EVT_MENU, self._on_hbinb2zbinb, item_hbinb2zbinb) self._menu.Bind(wx.EVT_MENU, self._on_reset_mask, item_reset_mask)
# ------------------------------------------------------------------ # Action handlers # ------------------------------------------------------------------
[docs] def _wolf2d_model(self): """Return wolfparent cast as Wolf2DModel, or None with error log if wrong type.""" from .PyGui import Wolf2DModel v = self._viewer if not isinstance(v.wolfparent, Wolf2DModel): logging.error(_('This is not a 2D model')) return None return v.wolfparent
[docs] def _on_parameters(self, event: wx.MenuEvent) -> None: model = self._wolf2d_model() if model is not None: model.show_properties()
[docs] def _on_reset_mask(self, event: wx.MenuEvent) -> None: model = self._wolf2d_model() if model is not None: model.sim.force_mask()
[docs] def _on_zbin2hbin(self, event: wx.MenuEvent) -> None: model = self._wolf2d_model() if model is not None and model.sim._zbin is not None: model.sim.zbin2hbin() model.sim.hbin.reset_plot()
[docs] def _on_hbin2zbin(self, event: wx.MenuEvent) -> None: model = self._wolf2d_model() if model is not None and model.sim._hbin is not None: model.sim.hbin2zbin() model.sim.zbin.reset_plot()
[docs] def _on_zbinb2hbinb(self, event: wx.MenuEvent) -> None: model = self._wolf2d_model() if model is not None and model.sim._zbinb is not None: model.sim.zbinb2hbinb() model.sim.hbinb.reset_plot()
[docs] def _on_hbinb2zbinb(self, event: wx.MenuEvent) -> None: model = self._wolf2d_model() if model is not None and model.sim._hbinb is not None: model.sim.hbinb2zbinb() model.sim.zbinb.reset_plot()