Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
fix #266 handles arbitrary number of curve points
Browse files Browse the repository at this point in the history
  • Loading branch information
TongZhai committed Aug 7, 2019
1 parent 43d2a35 commit c309b19
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/ui/EPANET/frmCurveEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, main_form, edit_these, new_item):
self.HEADCURVE = 1
self.EFFCURVE = 2
self.HLOSSCURVE = 3
self.MAXPOINTS = 51
self.MAXPOINTS = self.tblMult.rowCount() + 1
self.TINY = 1.e-6
self.Xlabels = {CurveType.VOLUME : " Height",
CurveType.PUMP : " Flow",
Expand Down Expand Up @@ -100,6 +100,12 @@ def __init__(self, main_form, edit_these, new_item):

self.loaded = True

def update_row_count(self, row_count):
self.tblMult.setRowCount(row_count)
self.MAXPOINTS = self.tblMult.rowCount() + 1
self.X = np.arange(self.MAXPOINTS, dtype=float) * float('NaN')
self.Y = np.arange(self.MAXPOINTS, dtype=float) * float('NaN')

def set_from(self, curve):
if not isinstance(curve, Curve):
curve = self.section.value[curve]
Expand All @@ -124,6 +130,9 @@ def set_from(self, curve):
self.Yunits[CurveType.HEADLOSS] = ' (' + LengthUnits + ')'
self.Yunits[CurveType.UNSET] = ""
ui.convenience.set_combo(self.cboCurveType, curve.curve_type)
self.tblMult.cellChanged.disconnect(self.tblMult_cellChanged)
if len(curve.curve_xy) > self.tblMult.rowCount():
self.update_row_count(len(curve.curve_xy))
point_count = -1
for point in curve.curve_xy:
point_count += 1
Expand All @@ -134,6 +143,8 @@ def set_from(self, curve):
#CurveGrid.RowCount= MAXPOINTS + 1
#CurveID.MaxLength= MAXID; // Max.chars. in a ID
#ActiveControl= CurveID
self.tblMult.cellChanged.connect(self.tblMult_cellChanged)
self.tblMult_cellChanged(point_count - 1, 1)

def GetData(self):
n = 0
Expand Down Expand Up @@ -176,6 +187,11 @@ def load_curve_data(self):
a = lines[2].split()
self.txtCurveName.setText(a[len(a) - 1])
if len(lines) > 3:
self.tblMult.cellChanged.disconnect(self.tblMult_cellChanged)
if len(lines) - 3 > self.tblMult.rowCount():
self.update_row_count(len(lines) - 3)

point_count = -1
curve_xy = []
for i in range(3, len(lines)):
try:
Expand All @@ -196,6 +212,8 @@ def load_curve_data(self):
pass
except Exception as ex:
pass
self.tblMult.cellChanged.connect(self.tblMult_cellChanged)
self.tblMult_cellChanged(point_count - 1, 1)

def save_curve_data(self):
directory = self._main_form.program_settings.value("DataDir", "")
Expand Down

0 comments on commit c309b19

Please sign in to comment.