Element_To_Draw & WolfMapViewer — Drawing architecture
This tutorial explains the object hierarchy used for rendering in the WOLF GUI.
Element_To_Draw— base class for all drawable objectsWolfMapViewer— the main OpenGL viewer (wxPythonwx.Frame)
Note —
WolfMapViewerrequires wxPython and an OpenGL context. This notebook focuses on the architecture and what can be done headless. For full GUI usage, see the GUI video tutorials.
Inheritance tree
All objects that can be displayed in WolfMapViewer inherit from Element_To_Draw:
Element_To_Draw
├── WolfArray / WolfArrayModel (raster grids)
├── WolfArrayMB (multi-block arrays)
├── Zones (vector data)
│ ├── PictureCollection (georeferenced photos)
│ └── ImagesTiles (tiled raster images)
├── Wolfresults_2D (2D simulation results)
├── Triangulation (triangulated meshes)
├── cloud_vertices (point clouds)
├── SyntheticDike (dike geometry)
├── crosssections (cross-sections)
└── ... (bridges, weirs, particle systems, ...)
[1]:
from wolfhece.drawing_obj import Element_To_Draw
Element_To_Draw — base interface
Every drawable object exposes these core attributes and methods:
[2]:
elem = Element_To_Draw(idx='my_layer', plotted=True)
print(f"Identifier : {elem.idx}")
print(f"Plotted? : {elem.plotted}")
print(f"Bounds : x=[{elem.xmin}, {elem.xmax}], y=[{elem.ymin}, {elem.ymax}]")
print(f"MapViewer : {elem.mapviewer}")
Identifier : my_layer
Plotted? : True
Bounds : x=[0.0, 0.0], y=[0.0, 0.0]
MapViewer : None
[3]:
# Toggle visibility
elem.check_plot() # plotted = True
elem.uncheck_plot() # plotted = False
print(f"After uncheck: plotted={elem.plotted}")
# Attach to a viewer (normally done automatically)
# elem.set_mapviewer(viewer)
# Compute spatial extent (overridden by subclasses)
elem.find_minmax(update=True)
After uncheck: plotted=False
Key methods to override in subclasses
When creating a new drawable class:
Method |
Purpose |
|---|---|
|
Render in OpenGL context |
|
Compute spatial bounding box |
|
Display properties dialog |
|
Visibility toggle hooks |
class MyCustomLayer(Element_To_Draw):
def __init__(self, data, **kwargs):
super().__init__(**kwargs)
self.data = data
def find_minmax(self, update=False):
self.xmin = self.data[:, 0].min()
self.xmax = self.data[:, 0].max()
self.ymin = self.data[:, 1].min()
self.ymax = self.data[:, 1].max()
def plot(self, sx=None, sy=None, **kwargs):
if not self.plotted:
return
# OpenGL rendering code here...
WolfMapViewer — the GUI viewer
WolfMapViewer is a wx.Frame that manages a list of Element_To_Draw objects and renders them in an OpenGL canvas. It handles:
Layer management: add/remove arrays, vectors, results, etc. via the tree panel
Pan & zoom: mouse-driven navigation
Querying: tooltip shows values under cursor
Actions: profile extraction, zone statistics, polygon analysis
Opening the viewer from Python
import wx
from wolfhece.PyDraw import WolfMapViewer
app = wx.App()
viewer = WolfMapViewer(title='My Viewer', w=1024, h=768)
# Add a WolfArray
from wolfhece.wolf_array import WolfArray
wa = WolfArray(fname='path/to/data.bin')
viewer.add_object('dem', newobj=wa)
viewer.Show()
app.MainLoop()
Main object lists in WolfMapViewer
Attribute |
Type stored |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Model / GUI pattern
Many wolfhece classes follow a Model/GUI split:
Model class (headless) |
GUI class (wx) |
Purpose |
|---|---|---|
|
|
Raster grids |
|
|
Color palettes |
|
— |
Spatial metadata |
Use Model classes for scripts, tests, and notebooks; GUI classes when running inside WolfMapViewer. See the architecture tutorial.