mirror of
https://github.com/fatiando/moulder.git
synced 2025-12-21 02:23:46 +08:00
Continue writting
This commit is contained in:
@@ -15,19 +15,19 @@ from PyQt5.QtWidgets import QSlider, QHBoxLayout, QLabel, QDialog, QPushButton
|
||||
from PyQt5.QtWidgets import QDialogButtonBox, QGridLayout, QRadioButton, QLineEdit
|
||||
|
||||
|
||||
class NewModelDialog(QDialog):
|
||||
class ConfigureMeassurementDialog(QDialog):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.setModal(False)
|
||||
self.setWindowTitle("Create New Model")
|
||||
self.setWindowTitle("Configure Meassurement Points")
|
||||
self._completed = False
|
||||
self._init_ui()
|
||||
|
||||
self.regular_grid_btn.toggled.connect(self._radio_button_callback)
|
||||
self.custom_grid_btn.toggled.connect(self._radio_button_callback)
|
||||
self.cancel_btn.clicked.connect(self._button_pushed_callback)
|
||||
self.ok_btn.clicked.connect(self._button_pushed_callback)
|
||||
self.apply_btn.clicked.connect(self._button_pushed_callback)
|
||||
|
||||
@property
|
||||
def x(self):
|
||||
@@ -66,9 +66,9 @@ class NewModelDialog(QDialog):
|
||||
self.to_input = QLineEdit()
|
||||
self.step_input = QLineEdit()
|
||||
self.height_input = QLineEdit()
|
||||
self.ok_btn = QPushButton("Ok")
|
||||
self.apply_btn = QPushButton("Apply Changes")
|
||||
self.cancel_btn = QPushButton("Cancel")
|
||||
self.ok_btn.setDefault(True)
|
||||
self.apply_btn.setDefault(True)
|
||||
|
||||
bold_font = QFont()
|
||||
bold_font.setBold(True)
|
||||
@@ -94,7 +94,7 @@ class NewModelDialog(QDialog):
|
||||
hbox = QHBoxLayout()
|
||||
hbox.setAlignment(Qt.AlignRight)
|
||||
hbox.addWidget(self.cancel_btn)
|
||||
hbox.addWidget(self.ok_btn)
|
||||
hbox.addWidget(self.apply_btn)
|
||||
layout.addLayout(hbox)
|
||||
|
||||
self.setLayout(layout)
|
||||
@@ -103,7 +103,7 @@ class NewModelDialog(QDialog):
|
||||
sender_text = self.sender().text()
|
||||
if sender_text == "Cancel":
|
||||
self.close()
|
||||
elif sender_text == "Ok":
|
||||
elif sender_text == "Apply Changes":
|
||||
filled_entries = self._check_filled_entries()
|
||||
if filled_entries:
|
||||
self._completed = True
|
||||
@@ -39,13 +39,13 @@ class Moulder(FigureCanvasQTAgg):
|
||||
'n: New polygon', 'd: delete', 'click: select/move', 'a: add vertex',
|
||||
'r: reset view', 'esc: cancel'])
|
||||
|
||||
def __init__(self, parent, area, x, z, density_range=[-2000, 2000],
|
||||
width=5, height=4, dpi=100):
|
||||
def __init__(self, parent, x, z, min_depth, max_depth,
|
||||
density_range=[-2000, 2000], width=5, height=4, dpi=100):
|
||||
self.fig = Figure(figsize=(width, height), dpi=dpi)
|
||||
super().__init__(self.fig)
|
||||
self.setParent(parent)
|
||||
|
||||
self._area = area
|
||||
self.min_depth, self.max_depth = min_depth, max_depth
|
||||
self._x, self._z = x, z
|
||||
self.density_range = density_range
|
||||
self._predicted = numpy.zeros_like(x)
|
||||
@@ -86,14 +86,6 @@ class Moulder(FigureCanvasQTAgg):
|
||||
def z(self, new_value):
|
||||
self._z = numpy.asarray(new_value)
|
||||
|
||||
@property
|
||||
def area(self):
|
||||
return self._area
|
||||
|
||||
@area.setter
|
||||
def area(self, new_area):
|
||||
self._area = new_area
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data
|
||||
@@ -134,6 +126,15 @@ class Moulder(FigureCanvasQTAgg):
|
||||
for p, d in zip(self.polygons, self.densities)]
|
||||
return m
|
||||
|
||||
def set_meassurement_points(self, x, z):
|
||||
self.x = x
|
||||
self.z = z
|
||||
self.modelax.set_xlim(self.x.min(), self.x.max())
|
||||
self.modelax.set_ylim(self.min_depth, self.max_depth)
|
||||
self.predicted_line.remove()
|
||||
self.predicted_line, = self.dataax.plot(self.x, self.predicted, '-r')
|
||||
self._update_data_plot()
|
||||
|
||||
def _figure_setup(self):
|
||||
self.dataax, self.modelax = self.fig.subplots(2, 1, sharex=True)
|
||||
self.dataax.set_ylabel("Gravity Anomaly [mGal]")
|
||||
@@ -141,8 +142,8 @@ class Moulder(FigureCanvasQTAgg):
|
||||
self.dataax.grid(True)
|
||||
self.modelax.set_xlabel("x [m]")
|
||||
self.modelax.set_ylabel("z [m]")
|
||||
self.modelax.set_xlim(self.area[:2])
|
||||
self.modelax.set_ylim(self.area[2:])
|
||||
self.modelax.set_xlim(self.x.min(), self.x.max())
|
||||
self.modelax.set_ylim(self.min_depth, self.max_depth)
|
||||
self.modelax.grid(True)
|
||||
self.modelax.invert_yaxis()
|
||||
self.predicted_line, = self.dataax.plot(self.x, self.predicted, '-r')
|
||||
@@ -477,8 +478,8 @@ class Moulder(FigureCanvasQTAgg):
|
||||
line.set_color([0, 0, 0, 0])
|
||||
self.canvas.draw()
|
||||
elif event_key == 'r':
|
||||
self.modelax.set_xlim(self.area[:2])
|
||||
self.modelax.set_ylim(self.area[2:])
|
||||
self.modelax.set_xlim(self.x.min(), self.x.max())
|
||||
self.modelax.set_ylim(self.min_depth, self.max_depth)
|
||||
self._update_data_plot()
|
||||
elif event_key == 'a':
|
||||
self._add_vertex = not self._add_vertex
|
||||
|
||||
45
moulder.py
45
moulder.py
@@ -16,7 +16,7 @@ from PyQt5.QtWidgets import QDialogButtonBox
|
||||
|
||||
from figure_canvas import GravityModelCanvas
|
||||
from interactive import Moulder
|
||||
from new_dialog import NewModelDialog
|
||||
from configure_dialog import ConfigureMeassurementDialog
|
||||
|
||||
|
||||
class MoulderApp(QMainWindow):
|
||||
@@ -29,21 +29,20 @@ class MoulderApp(QMainWindow):
|
||||
self.init_ui()
|
||||
self.set_callbacks()
|
||||
|
||||
self.canvas = Moulder(self, [0, 100, 0, 1000],
|
||||
numpy.linspace(0, 100, 11),
|
||||
numpy.zeros(11),
|
||||
width=5, height=4, dpi=100)
|
||||
#self.canvas = GravityModelCanvas(self,
|
||||
self.moulder = Moulder(self, numpy.linspace(0, 100, 11),
|
||||
numpy.zeros(11), 0, 1000,
|
||||
width=5, height=4, dpi=100)
|
||||
#self.moulder = GravityModelCanvas(self,
|
||||
# width=5, height=4, dpi=100)
|
||||
# self.canvas.setFocus()
|
||||
self.setCentralWidget(self.canvas)
|
||||
# self.moulder.setFocus()
|
||||
self.setCentralWidget(self.moulder)
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
keys_dict = {Qt.Key_N: "n", Qt.Key_R: "r",
|
||||
Qt.Key_A: "a", Qt.Key_D: "d",
|
||||
Qt.Key_Escape: "escape"}
|
||||
if event.key() in keys_dict.keys():
|
||||
self.canvas._key_press_callback(keys_dict[event.key()])
|
||||
self.moulder._key_press_callback(keys_dict[event.key()])
|
||||
|
||||
def closeEvent(self, event):
|
||||
event.ignore()
|
||||
@@ -55,15 +54,15 @@ class MoulderApp(QMainWindow):
|
||||
self._configure_toolbar()
|
||||
|
||||
def set_callbacks(self):
|
||||
self.new_action.triggered.connect(self._new_model_callback)
|
||||
self.configure_action.triggered.connect(
|
||||
self._configure_meassurement_callback)
|
||||
self.about_action.triggered.connect(self._about_callback)
|
||||
# self.file_menu.triggered.connect(self._file_menu_callback)
|
||||
self.quit_action.triggered.connect(self._quit_callback)
|
||||
|
||||
def _define_actions(self):
|
||||
self.new_action = QAction(QIcon.fromTheme('document-new'),
|
||||
'&New model', self)
|
||||
self.new_action.setShortcut('Ctrl+N')
|
||||
self.configure_action = QAction(QIcon.fromTheme('preferences-system'),
|
||||
'&Configure Meassurement Points', self)
|
||||
self.open_action = QAction(QIcon.fromTheme('document-open'),
|
||||
'&Open model', self)
|
||||
self.open_action.setShortcut('Ctrl+O')
|
||||
@@ -89,7 +88,7 @@ class MoulderApp(QMainWindow):
|
||||
|
||||
def _configure_toolbar(self):
|
||||
self.toolbar = self.addToolBar("adasd")
|
||||
self.toolbar.addAction(self.new_action)
|
||||
self.toolbar.addAction(self.configure_action)
|
||||
self.toolbar.addAction(self.open_action)
|
||||
self.toolbar.addAction(self.save_action)
|
||||
self.toolbar.addAction(self.save_as_action)
|
||||
@@ -98,14 +97,12 @@ class MoulderApp(QMainWindow):
|
||||
QMessageBox.about(self, "About Moulder",
|
||||
"About Moulder\nVersion 0.1")
|
||||
|
||||
def _new_model_callback(self):
|
||||
new_model_dialog = NewModelDialog(parent=self)
|
||||
new_model_dialog.exec_()
|
||||
if new_model_dialog.is_completed():
|
||||
self.canvas.x = new_model_dialog.x
|
||||
self.canvas.z = new_model_dialog.z
|
||||
self.canvas.run()
|
||||
self.setCentralWidget(self.canvas)
|
||||
def _configure_meassurement_callback(self):
|
||||
configure_dialog = ConfigureMeassurementDialog(self)
|
||||
configure_dialog.exec_()
|
||||
if configure_dialog.is_completed():
|
||||
self.moulder.set_meassurement_points(configure_dialog.x,
|
||||
configure_dialog.z)
|
||||
|
||||
def _quit_callback(self):
|
||||
answer = QMessageBox.question(self, "Quit",
|
||||
@@ -118,6 +115,6 @@ class MoulderApp(QMainWindow):
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
app.setApplicationName("Moulder")
|
||||
moulder = MoulderApp()
|
||||
moulder.show()
|
||||
moulder_app = MoulderApp()
|
||||
moulder_app.show()
|
||||
sys.exit(app.exec_())
|
||||
|
||||
Reference in New Issue
Block a user