mirror of https://gitlab.com/pamhyr/pamhyr2
BC: Edit: Add plot (not finish).
parent
d49091a469
commit
2f0b5b2e31
|
|
@ -27,10 +27,12 @@ from View.BoundaryCondition.BCUndoCommand import (
|
|||
AddCommand, DelCommand, SortCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand,
|
||||
)
|
||||
|
||||
from Model.BoundaryCondition.BoundaryConditionTypes import (
|
||||
NotDefined, PonctualContribution,
|
||||
TimeOverZ, TimeOverDebit, ZOverDebit
|
||||
)
|
||||
|
||||
from View.BoundaryCondition.translate import long_types
|
||||
from View.BoundaryCondition.Edit.Window import EditBoundaryConditionWindow
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from tools import timer, trace
|
||||
from View.Plot.APlot import APlot
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication
|
||||
)
|
||||
|
||||
from View.BoundaryCondition.Edit.translate import *
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
class Plot(APlot):
|
||||
def __init__(self, canvas=None, data=None, toolbar=None):
|
||||
super(Plot, self).__init__(
|
||||
canvas=canvas,
|
||||
data=data,
|
||||
toolbar=toolbar
|
||||
)
|
||||
|
||||
@timer
|
||||
def draw(self):
|
||||
self.canvas.axes.cla()
|
||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||
|
||||
if len(self.data) == 0:
|
||||
self._init = False
|
||||
return
|
||||
|
||||
# Plot data
|
||||
x = list(map(lambda v: v[0], self.data.data))
|
||||
y = list(map(lambda v: v[1], self.data.data))
|
||||
self._line, = self.canvas.axes.plot(
|
||||
x, y,
|
||||
color='r', lw=1.,
|
||||
markersize=5, marker='+',
|
||||
picker=30
|
||||
)
|
||||
|
||||
# Plot label
|
||||
header = self.data.header
|
||||
self.canvas.axes.set_xlabel(
|
||||
table_headers[header[0]], color='black', fontsize=10
|
||||
)
|
||||
self.canvas.axes.set_ylabel(
|
||||
table_headers[header[1]], color='black', fontsize=10
|
||||
)
|
||||
|
||||
self.canvas.figure.tight_layout()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
self.toolbar.update()
|
||||
|
||||
self._init = True
|
||||
|
||||
@timer
|
||||
def update(self, ind=None):
|
||||
if self._init == False:
|
||||
self.draw()
|
||||
return
|
||||
|
||||
# if ind is not None:
|
||||
|
||||
# else:
|
||||
|
||||
self.canvas.figure.tight_layout()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
|
|
@ -15,24 +15,19 @@ from PyQt5.QtWidgets import (
|
|||
QTableView, QAbstractItemView,
|
||||
)
|
||||
|
||||
from View.BoundaryCondition.Edit.UndoCommand import (
|
||||
SetDataCommand, AddCommand, DelCommand,
|
||||
SortCommand, MoveCommand, PasteCommand,
|
||||
DuplicateCommand,
|
||||
)
|
||||
|
||||
from Model.BoundaryCondition.BoundaryConditionTypes import (
|
||||
NotDefined, PonctualContribution,
|
||||
TimeOverZ, TimeOverDebit, ZOverDebit
|
||||
)
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
from View.BoundaryCondition.Edit.UndoCommand import (
|
||||
SetDataCommand, AddCommand, DelCommand,
|
||||
SortCommand, MoveCommand, PasteCommand,
|
||||
DuplicateCommand,
|
||||
)
|
||||
from View.BoundaryCondition.Edit.translate import *
|
||||
|
||||
table_headers = {
|
||||
"time": _translate("BoundaryCondition", "Time"),
|
||||
"debit": _translate("BoundaryCondition", "Debit"),
|
||||
"z": _translate("BoundaryCondition", "Z (m)")
|
||||
}
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class TableModel(QAbstractTableModel):
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class SortCommand(QUndoCommand):
|
|||
|
||||
def redo(self):
|
||||
self._data.sort(
|
||||
reverse=self._reverse,
|
||||
_reverse=self._reverse,
|
||||
key=lambda x: x.name
|
||||
)
|
||||
if self._indexes is None:
|
||||
|
|
|
|||
|
|
@ -17,8 +17,11 @@ from PyQt5.QtWidgets import (
|
|||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
)
|
||||
|
||||
from View.Plot.MplCanvas import MplCanvas
|
||||
|
||||
from View.BoundaryCondition.translate import long_types
|
||||
from View.BoundaryCondition.Edit.Table import TableModel
|
||||
from View.BoundaryCondition.Edit.Plot import Plot
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
|
@ -34,6 +37,7 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
|
|||
self.setup_window()
|
||||
self.setup_sc()
|
||||
self.setup_table()
|
||||
self.setup_plot()
|
||||
self.setup_connections()
|
||||
|
||||
def setup_window(self):
|
||||
|
|
@ -67,6 +71,18 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
|
|||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
table.setAlternatingRowColors(True)
|
||||
|
||||
def setup_plot(self):
|
||||
self.canvas = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas.setObjectName("canvas")
|
||||
self.verticalLayout.addWidget(self.canvas)
|
||||
|
||||
self.plot = Plot(
|
||||
canvas = self.canvas,
|
||||
data = self._data,
|
||||
)
|
||||
self.plot.draw()
|
||||
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt5.QtCore import QCoreApplication
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
table_headers = {
|
||||
"time": _translate("BoundaryCondition", "Time"),
|
||||
"debit": _translate("BoundaryCondition", "Debit"),
|
||||
"z": _translate("BoundaryCondition", "Z (m)")
|
||||
}
|
||||
|
|
@ -25,19 +25,43 @@
|
|||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QTableView" name="tableView"/>
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout"/>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Liquid</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QTableView" name="tableView"/>
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Solid</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>Suspension</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
Loading…
Reference in New Issue