Continue writting

This commit is contained in:
Santiago Soler
2018-02-01 14:44:20 -03:00
parent 902eb6b670
commit e0471351d4
3 changed files with 45 additions and 47 deletions

View File

@@ -15,19 +15,19 @@ from PyQt5.QtWidgets import QSlider, QHBoxLayout, QLabel, QDialog, QPushButton
from PyQt5.QtWidgets import QDialogButtonBox, QGridLayout, QRadioButton, QLineEdit 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) super().__init__(parent)
self.setModal(False) self.setModal(False)
self.setWindowTitle("Create New Model") self.setWindowTitle("Configure Meassurement Points")
self._completed = False self._completed = False
self._init_ui() self._init_ui()
self.regular_grid_btn.toggled.connect(self._radio_button_callback) self.regular_grid_btn.toggled.connect(self._radio_button_callback)
self.custom_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.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 @property
def x(self): def x(self):
@@ -66,9 +66,9 @@ class NewModelDialog(QDialog):
self.to_input = QLineEdit() self.to_input = QLineEdit()
self.step_input = QLineEdit() self.step_input = QLineEdit()
self.height_input = QLineEdit() self.height_input = QLineEdit()
self.ok_btn = QPushButton("Ok") self.apply_btn = QPushButton("Apply Changes")
self.cancel_btn = QPushButton("Cancel") self.cancel_btn = QPushButton("Cancel")
self.ok_btn.setDefault(True) self.apply_btn.setDefault(True)
bold_font = QFont() bold_font = QFont()
bold_font.setBold(True) bold_font.setBold(True)
@@ -94,7 +94,7 @@ class NewModelDialog(QDialog):
hbox = QHBoxLayout() hbox = QHBoxLayout()
hbox.setAlignment(Qt.AlignRight) hbox.setAlignment(Qt.AlignRight)
hbox.addWidget(self.cancel_btn) hbox.addWidget(self.cancel_btn)
hbox.addWidget(self.ok_btn) hbox.addWidget(self.apply_btn)
layout.addLayout(hbox) layout.addLayout(hbox)
self.setLayout(layout) self.setLayout(layout)
@@ -103,7 +103,7 @@ class NewModelDialog(QDialog):
sender_text = self.sender().text() sender_text = self.sender().text()
if sender_text == "Cancel": if sender_text == "Cancel":
self.close() self.close()
elif sender_text == "Ok": elif sender_text == "Apply Changes":
filled_entries = self._check_filled_entries() filled_entries = self._check_filled_entries()
if filled_entries: if filled_entries:
self._completed = True self._completed = True

View File

@@ -39,13 +39,13 @@ class Moulder(FigureCanvasQTAgg):
'n: New polygon', 'd: delete', 'click: select/move', 'a: add vertex', 'n: New polygon', 'd: delete', 'click: select/move', 'a: add vertex',
'r: reset view', 'esc: cancel']) 'r: reset view', 'esc: cancel'])
def __init__(self, parent, area, x, z, density_range=[-2000, 2000], def __init__(self, parent, x, z, min_depth, max_depth,
width=5, height=4, dpi=100): density_range=[-2000, 2000], width=5, height=4, dpi=100):
self.fig = Figure(figsize=(width, height), dpi=dpi) self.fig = Figure(figsize=(width, height), dpi=dpi)
super().__init__(self.fig) super().__init__(self.fig)
self.setParent(parent) self.setParent(parent)
self._area = area self.min_depth, self.max_depth = min_depth, max_depth
self._x, self._z = x, z self._x, self._z = x, z
self.density_range = density_range self.density_range = density_range
self._predicted = numpy.zeros_like(x) self._predicted = numpy.zeros_like(x)
@@ -86,14 +86,6 @@ class Moulder(FigureCanvasQTAgg):
def z(self, new_value): def z(self, new_value):
self._z = numpy.asarray(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 @property
def data(self): def data(self):
return self._data return self._data
@@ -134,6 +126,15 @@ class Moulder(FigureCanvasQTAgg):
for p, d in zip(self.polygons, self.densities)] for p, d in zip(self.polygons, self.densities)]
return m 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): def _figure_setup(self):
self.dataax, self.modelax = self.fig.subplots(2, 1, sharex=True) self.dataax, self.modelax = self.fig.subplots(2, 1, sharex=True)
self.dataax.set_ylabel("Gravity Anomaly [mGal]") self.dataax.set_ylabel("Gravity Anomaly [mGal]")
@@ -141,8 +142,8 @@ class Moulder(FigureCanvasQTAgg):
self.dataax.grid(True) self.dataax.grid(True)
self.modelax.set_xlabel("x [m]") self.modelax.set_xlabel("x [m]")
self.modelax.set_ylabel("z [m]") self.modelax.set_ylabel("z [m]")
self.modelax.set_xlim(self.area[:2]) self.modelax.set_xlim(self.x.min(), self.x.max())
self.modelax.set_ylim(self.area[2:]) self.modelax.set_ylim(self.min_depth, self.max_depth)
self.modelax.grid(True) self.modelax.grid(True)
self.modelax.invert_yaxis() self.modelax.invert_yaxis()
self.predicted_line, = self.dataax.plot(self.x, self.predicted, '-r') 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]) line.set_color([0, 0, 0, 0])
self.canvas.draw() self.canvas.draw()
elif event_key == 'r': elif event_key == 'r':
self.modelax.set_xlim(self.area[:2]) self.modelax.set_xlim(self.x.min(), self.x.max())
self.modelax.set_ylim(self.area[2:]) self.modelax.set_ylim(self.min_depth, self.max_depth)
self._update_data_plot() self._update_data_plot()
elif event_key == 'a': elif event_key == 'a':
self._add_vertex = not self._add_vertex self._add_vertex = not self._add_vertex

View File

@@ -16,7 +16,7 @@ from PyQt5.QtWidgets import QDialogButtonBox
from figure_canvas import GravityModelCanvas from figure_canvas import GravityModelCanvas
from interactive import Moulder from interactive import Moulder
from new_dialog import NewModelDialog from configure_dialog import ConfigureMeassurementDialog
class MoulderApp(QMainWindow): class MoulderApp(QMainWindow):
@@ -29,21 +29,20 @@ class MoulderApp(QMainWindow):
self.init_ui() self.init_ui()
self.set_callbacks() self.set_callbacks()
self.canvas = Moulder(self, [0, 100, 0, 1000], self.moulder = Moulder(self, numpy.linspace(0, 100, 11),
numpy.linspace(0, 100, 11), numpy.zeros(11), 0, 1000,
numpy.zeros(11),
width=5, height=4, dpi=100) width=5, height=4, dpi=100)
#self.canvas = GravityModelCanvas(self, #self.moulder = GravityModelCanvas(self,
# width=5, height=4, dpi=100) # width=5, height=4, dpi=100)
# self.canvas.setFocus() # self.moulder.setFocus()
self.setCentralWidget(self.canvas) self.setCentralWidget(self.moulder)
def keyPressEvent(self, event): def keyPressEvent(self, event):
keys_dict = {Qt.Key_N: "n", Qt.Key_R: "r", keys_dict = {Qt.Key_N: "n", Qt.Key_R: "r",
Qt.Key_A: "a", Qt.Key_D: "d", Qt.Key_A: "a", Qt.Key_D: "d",
Qt.Key_Escape: "escape"} Qt.Key_Escape: "escape"}
if event.key() in keys_dict.keys(): 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): def closeEvent(self, event):
event.ignore() event.ignore()
@@ -55,15 +54,15 @@ class MoulderApp(QMainWindow):
self._configure_toolbar() self._configure_toolbar()
def set_callbacks(self): 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.about_action.triggered.connect(self._about_callback)
# self.file_menu.triggered.connect(self._file_menu_callback) # self.file_menu.triggered.connect(self._file_menu_callback)
self.quit_action.triggered.connect(self._quit_callback) self.quit_action.triggered.connect(self._quit_callback)
def _define_actions(self): def _define_actions(self):
self.new_action = QAction(QIcon.fromTheme('document-new'), self.configure_action = QAction(QIcon.fromTheme('preferences-system'),
'&New model', self) '&Configure Meassurement Points', self)
self.new_action.setShortcut('Ctrl+N')
self.open_action = QAction(QIcon.fromTheme('document-open'), self.open_action = QAction(QIcon.fromTheme('document-open'),
'&Open model', self) '&Open model', self)
self.open_action.setShortcut('Ctrl+O') self.open_action.setShortcut('Ctrl+O')
@@ -89,7 +88,7 @@ class MoulderApp(QMainWindow):
def _configure_toolbar(self): def _configure_toolbar(self):
self.toolbar = self.addToolBar("adasd") 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.open_action)
self.toolbar.addAction(self.save_action) self.toolbar.addAction(self.save_action)
self.toolbar.addAction(self.save_as_action) self.toolbar.addAction(self.save_as_action)
@@ -98,14 +97,12 @@ class MoulderApp(QMainWindow):
QMessageBox.about(self, "About Moulder", QMessageBox.about(self, "About Moulder",
"About Moulder\nVersion 0.1") "About Moulder\nVersion 0.1")
def _new_model_callback(self): def _configure_meassurement_callback(self):
new_model_dialog = NewModelDialog(parent=self) configure_dialog = ConfigureMeassurementDialog(self)
new_model_dialog.exec_() configure_dialog.exec_()
if new_model_dialog.is_completed(): if configure_dialog.is_completed():
self.canvas.x = new_model_dialog.x self.moulder.set_meassurement_points(configure_dialog.x,
self.canvas.z = new_model_dialog.z configure_dialog.z)
self.canvas.run()
self.setCentralWidget(self.canvas)
def _quit_callback(self): def _quit_callback(self):
answer = QMessageBox.question(self, "Quit", answer = QMessageBox.question(self, "Quit",
@@ -118,6 +115,6 @@ class MoulderApp(QMainWindow):
if __name__ == "__main__": if __name__ == "__main__":
app = QApplication(sys.argv) app = QApplication(sys.argv)
app.setApplicationName("Moulder") app.setApplicationName("Moulder")
moulder = MoulderApp() moulder_app = MoulderApp()
moulder.show() moulder_app.show()
sys.exit(app.exec_()) sys.exit(app.exec_())