polyfoammesh.gui.viewer_widget

Functions

build_internal_volume_vtu(case_dir)

Run OpenFOAM's own foamToVTK to get the real internal volume cells.

detect_patch_type(name[, patch_type])

Auto-detected patch type: wall / inlet / outlet / symmetry / other.

read_openfoam_mesh_patches(case_dir)

read_openfoam_mesh_stats(case_dir)

Read mesh statistics from an OpenFOAM polyMesh directory.

Classes

ViewerWidget([parent])

polyfoammesh.gui.viewer_widget.detect_patch_type(name, patch_type='')[source]

Auto-detected patch type: wall / inlet / outlet / symmetry / other.

Reuses the project’s single wall-detection classifier (core.patch_roles.match_role — see its module docstring) and falls back to the type recorded in the case boundary file, which the mesher writes from meshdict_gen.infer_patch_type / case_setup. No new heuristic is introduced here.

Return type:

str

Parameters:
polyfoammesh.gui.viewer_widget.build_internal_volume_vtu(case_dir)[source]

Run OpenFOAM’s own foamToVTK to get the real internal volume cells.

The “Volume Mesh” view used to only ever show the boundary patches (constant/polyMesh/boundary) — the outer surface, never the actual internal cells — because that’s all read_openfoam_mesh_patches reads. cfMesh/cartesianMesh cells are polyhedral; meshio can’t parse OpenFOAM or polyhedral VTU at all, but PyVista (built on VTK directly) reads them fine, so foamToVTK -> PyVista is the reliable path here.

Cached under <case_dir>/VTK_view, regenerated only when polyMesh changed. Runs in a background task (the foamToVTK call takes 30-60s).

Return type:

Path | None

Parameters:

case_dir (Path)

polyfoammesh.gui.viewer_widget.read_openfoam_mesh_stats(case_dir)[source]

Read mesh statistics from an OpenFOAM polyMesh directory.

Uses nCells/nPoints/nFaces from the FoamFile header where available (fast path, reads only header bytes). Falls back to file-size-based estimation to avoid loading the full data on the GUI thread.

Return type:

dict

Parameters:

case_dir (Path)

polyfoammesh.gui.viewer_widget.read_openfoam_mesh_patches(case_dir)[source]
Return type:

dict[str, PolyData] | None

Parameters:

case_dir (Path | str)

class polyfoammesh.gui.viewer_widget.ViewerWidget(parent=None)[source]

Bases: QWidget

face_picked
patch_renamed

(old_name, new_name) — emitted when the user renames a CAD patch in the patch table. Additive: existing signals/consumers are unaffected.

mesh_patch_renamed

(old_name, new_name) — emitted when the user renames a patch of a GENERATED mesh in the patch table. The main window writes the new name back to constant/polyMesh/boundary (after backing it up) and refreshes the table/BC editor. Additive alongside patch_renamed.

distance_measured
measure_hint
refinement_point_picked
refinement_boxes_changed
resizeEvent(self, event: PySide6.QtGui.QResizeEvent, /) → None[source]
patch_panel()[source]

The BaramMesh-style patch panel, for the main window to embed.

Return type:

QWidget

save_background(s)[source]
restore_background(s)[source]
highlight_patch(patch_name)[source]

Highlight a picked patch with a bright, clearly outlined color.

Works in both representations: the CAD surface (per-patch _cad_meshes) and a loaded case mesh (per-patch boundary patches held in _mesh_patches). The camera is never reset — the call is a plain clear+redraw, so selecting a patch row leaves the view put.

Parameters:

patch_name (str)

revert_patch_name(current_name, original_name)[source]

Undo a generated-mesh rename the writer refused (table + tracking).

Called by the main window when writing the boundary file fails, so the Name cell never shows a name that is not on disk.

Return type:

None

Parameters:
  • current_name (str)

  • original_name (str)

apply_case_patch_rename(old_name, new_name)[source]

Remap an already-committed generated-mesh rename (table already has the new text). Keeps the 3D highlight/label maps consistent.

Return type:

None

Parameters:
  • old_name (str)

  • new_name (str)

start_refinement_pick()[source]

Enter refinement-pick mode: click a point on the mesh to set the centre of a manual refinement zone. Emits refinement_point_picked(x, y, z) on first pick, then automatically exits pick mode.

show_refinement_zones(zones)[source]

Display detected refinement zones as semi-transparent cyan spheres.

Parameters:

zones (list)

is_showing_cad()[source]

True while the CAD surface is the displayed geometry.

Return type:

bool

set_rendering_paused(paused)[source]

Pause the periodic 3D re-render while a meshing run saturates the CPU.

The viewer’s 30 FPS auto-update competes with the meshing workers for the GUI thread and makes interaction stutter; pausing it for the duration of a run (the log flood was the other, bigger source - fixed in the log panel) keeps the window responsive. The display itself is untouched and rendering resumes immediately when done.

Return type:

None

Parameters:

paused (bool)

cancel_vtk_process()[source]

Public alias used by the main window’s Cancel handler.

cancel_mesh_display()[source]

Stop any pending mesh-view retry/timeout. Called from main_window when the user cancels the meshing run.

Return type:

None

show_cad(meshes)[source]
Parameters:

meshes (list[Trimesh])

MAX_VIEWER_CELLS = 10000000
DECIMATE_THRESHOLD = 2000000
DECIMATE_TARGET = 0.2
show_mesh(case_dir)[source]

Show mesh — always regenerates VTU from current polyMesh.

Invalidates the VTU cache marker so foamToVTK always runs after meshing/conversion, ensuring the viewer shows the CURRENT mesh (poly after tet→poly conversion) and not a stale cached version.

Parameters:

case_dir (Path | str)

clear()[source]
REF_BOX_FACE_COLOR = 'darkorange'

High-contrast colours so a refinement box can never be mistaken for CAD geometry. Bright, solid, and deliberately different from the patch palette used for the part itself. Named colours (not hex) keep gui/ free of hardcoded hex values (tests/test_design_system.py).

REF_BOX_EDGE_COLOR = 'red'
REF_BOX_SELECTED_FACE_COLOR = 'gold'
REF_BOX_SELECTED_EDGE_COLOR = 'cyan'
REF_BOX_FACE_OPACITY = 0.18
REF_BOX_SELECTED_OPACITY = 0.32
show_refinement_boxes(boxes)[source]

Render refinement boxes as bright translucent cuboids with a label.

boxes is a list of {type:'box', xmin..zmax, level, cell_size}. Each is drawn as a translucent bright-orange volume plus a thick red wireframe and a “Box N - Lx” 3D label, so it is unmistakable in the viewport. Subsequent calls replace the previous rendering. Drag-sizing is entered separately via start_refinement_box_drag().

Parameters:

boxes (list)

set_refinement_box_selected(index)[source]

Emphasise box index (the selected panel row), or clear it.

Public API used by the main window: selecting a row in the refinement list highlights the matching box in the 3D view. None/negative clears the emphasis.

Return type:

None

Parameters:

index (int | None)

start_refinement_box_drag()[source]

Enable drag-sizing of the boxes with the vtk BoxWidget gizmo.

stop_refinement_box_drag()[source]
property plotter
staticMetaObject = PySide6.QtCore.QMetaObject("ViewerWidget" inherits "QWidget": Methods:   #33 type=Signal, signature=face_picked(QString), parameters=QString   #34 type=Signal, signature=patch_renamed(QString,QString), parameters=QString, QString   #35 type=Signal, signature=mesh_patch_renamed(QString,QString), parameters=QString, QString   #36 type=Signal, signature=distance_measured(QString), parameters=QString   #37 type=Signal, signature=measure_hint(QString), parameters=QString   #38 type=Signal, signature=refinement_point_picked(double,double,double), parameters=double, double, double   #39 type=Signal, signature=refinement_boxes_changed(PyObject), parameters=PyObject )