Skip to content

Commit

Permalink
use BatchEvaluate common for pyTFM
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerum committed Dec 28, 2023
1 parent cbd02a9 commit 1210caf
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 344 deletions.
60 changes: 37 additions & 23 deletions saenopy/gui/common/BatchEvaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from saenopy.gui.common.AddFilesDialog import FileExistsDialog
from saenopy.gui.spheroid.modules.result import ResultSpheroid
from saenopy.gui.tfm2d.modules.result import Result2D


class SharedProperties:
Expand Down Expand Up @@ -53,6 +54,28 @@ class BatchEvaluate(QtWidgets.QWidget):
def add_modules(self):
self.modules = []

def add_tabs(self):
layout = QtShortCuts.currentLayout()
with QtShortCuts.QTabWidget(layout) as self.tabs:
self.tabs.setMinimumWidth(500)
old_tab = None
cam_pos = None

def tab_changed(x):
nonlocal old_tab, cam_pos
tab = self.tabs.currentWidget()
if old_tab is not None and getattr(old_tab, "plotter", None):
cam_pos = old_tab.plotter.camera_position
if cam_pos is not None and getattr(tab, "plotter", None):
tab.plotter.camera_position = cam_pos
if old_tab is not None:
tab.t_slider.setValue(old_tab.t_slider.value())
old_tab = tab
self.tab_changed.emit(tab)

self.tabs.currentChanged.connect(tab_changed)
pass

def __init__(self, parent=None):
super().__init__(parent)

Expand All @@ -75,23 +98,7 @@ def __init__(self, parent=None):
self.progressbar.setOrientation(QtCore.Qt.Horizontal)
with QtShortCuts.QHBoxLayout() as layout:
layout.setContentsMargins(0, 0, 0, 0)
with QtShortCuts.QTabWidget(layout) as self.tabs:
self.tabs.setMinimumWidth(500)
old_tab = None
cam_pos = None
def tab_changed(x):
nonlocal old_tab, cam_pos
tab = self.tabs.currentWidget()
if old_tab is not None and getattr(old_tab, "plotter", None):
cam_pos = old_tab.plotter.camera_position
if cam_pos is not None and getattr(tab, "plotter", None):
tab.plotter.camera_position = cam_pos
if old_tab is not None:
tab.t_slider.setValue(old_tab.t_slider.value())
old_tab = tab
self.tab_changed.emit(tab)
self.tabs.currentChanged.connect(tab_changed)
pass
self.add_tabs()
with QtShortCuts.QVBoxLayout() as layout0:
layout0.parent().setMaximumWidth(420)
layout0.setContentsMargins(0, 0, 0, 0)
Expand All @@ -100,6 +107,8 @@ def tab_changed(x):
self.button_start_all = QtShortCuts.QPushButton(None, "run all", self.run_all)
with QtShortCuts.QHBoxLayout():
self.button_code = QtShortCuts.QPushButton(None, "export code", self.generate_code)
if getattr(self, "generate_data", None):
self.button_excel = QtShortCuts.QPushButton(None, "export data", self.generate_data)
if getattr(self, "sub_module_export", None):
self.button_export = QtShortCuts.QPushButton(None, "export images", lambda x: self.sub_module_export.export_window.show())

Expand Down Expand Up @@ -170,6 +179,12 @@ def progress(self, tup):
self.progressbar.setValue(n)

def generate_code(self):
try:
result = self.list.data[self.list.currentRow()][2]
if result is None:
return
except IndexError:
return
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Session as Script", os.getcwd(), "Python File (*.py)")
if new_path:
# ensure filename ends in .py
Expand All @@ -192,12 +207,9 @@ def run_all(self):
if not self.data[i][1]:
continue
result = self.data[i][2]
if self.sub_module_deformation.group.value() is True:
self.sub_module_deformation.start_process(result=result)
if self.sub_module_mesh.group.value() is True:
self.sub_module_mesh.start_process(result=result)
if self.sub_module_regularize.group.value() is True:
self.sub_module_regularize.start_process(result=result)
for module in self.modules:
if getattr(module, "group", None) and module.group.value() is True:
module.start_process(result=result)

def addTask(self, task, result, params, name):
self.tasks.append([task, result, params, name])
Expand Down Expand Up @@ -265,6 +277,8 @@ def load_from_path(self, paths):
if self.file_extension == ".saenopySpheroid":
self.add_data(ResultSpheroid.load(p))
pass
elif self.file_extension == ".saenopy2D":
self.add_data(Result2D.load(p))
else:
self.add_data(Result.load(p))
except Exception as err:
Expand Down
2 changes: 1 addition & 1 deletion saenopy/gui/solver/modules/BatchEvaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BatchEvaluate(BatchEvaluate):
settings_key = "Seanopy_deformation"
file_extension = ".saenopy"

result_params = params = ["piv_parameters", "mesh_parameters", "material_parameters", "solve_parameters"]
result_params = ["piv_parameters", "mesh_parameters", "material_parameters", "solve_parameters"]

def add_modules(self):
layout0 = QtShortCuts.currentLayout()
Expand Down
26 changes: 2 additions & 24 deletions saenopy/gui/spheroid/modules/BatchEvaluate.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
import json
import sys
import os

import qtawesome as qta
from qtpy import QtCore, QtWidgets, QtGui
import numpy as np
import glob
import threading
from pathlib import Path
import matplotlib as mpl

import traceback

from saenopy import get_stacks
from saenopy import Result
from saenopy.gui.common import QtShortCuts
from saenopy.gui.common.gui_classes import ListWidget
from saenopy.gui.common.stack_selector_tif import add_last_voxel_size, add_last_time_delta

from .AddFilesDialog import AddFilesDialog
from saenopy.gui.common.AddFilesDialog import do_overwrite
from .DeformationDetector import DeformationDetector
from saenopy.gui.solver.modules.exporter.Exporter import ExportViewer
#from .load_measurement_dialog import AddFilesDialog
from saenopy.gui.common.AddFilesDialog import FileExistsDialog
#from .path_editor import start_path_change
from saenopy.examples import get_examples
from saenopy.gui.common.BatchEvaluate import BatchEvaluate
from saenopy.examples import get_examples_spheroid
from saenopy.gui.spheroid.modules.result import ResultSpheroid, get_stacks_spheroid
from saenopy.gui.spheroid.modules.result import get_stacks_spheroid
from .ForceCalculator import ForceCalculator


class BatchEvaluate(BatchEvaluate):
settings_key = "Spheroid"
file_extension = ".saenopySpheroid"

result_params = params = ["piv_parameters", "force_parameters"]
result_params = ["piv_parameters", "force_parameters"]

def add_modules(self):
layout0 = QtShortCuts.currentLayout()
Expand Down
Loading

0 comments on commit 1210caf

Please sign in to comment.