mirror of https://gitlab.com/pamhyr/pamhyr2
SedimentLayer: Add d50, sigma and critical_constraint data.
parent
d636f5b637
commit
17d4b15761
|
|
@ -11,7 +11,9 @@ class Layer(SQLSubModel):
|
|||
|
||||
def __init__(self,
|
||||
id:int = -1, name:str = "",
|
||||
type = "", height = 0,
|
||||
type = "",
|
||||
height = 0.0, d50 = 0.0, sigma = 0.0,
|
||||
critical_constraint = 0.0,
|
||||
sl = None, status = None):
|
||||
super(Layer, self).__init__()
|
||||
|
||||
|
|
@ -19,7 +21,11 @@ class Layer(SQLSubModel):
|
|||
|
||||
self._name = name
|
||||
self._type = type
|
||||
|
||||
self._height = height
|
||||
self._d50 = d50
|
||||
self._sigma = sigma
|
||||
self._critical_constraint = critical_constraint
|
||||
|
||||
if id == -1:
|
||||
self.id = Layer._id_cnt
|
||||
|
|
@ -52,6 +58,30 @@ class Layer(SQLSubModel):
|
|||
def height(self, height):
|
||||
self._height = float(height)
|
||||
|
||||
@property
|
||||
def d50(self):
|
||||
return self._d50
|
||||
|
||||
@d50.setter
|
||||
def d50(self, d50):
|
||||
self._d50 = float(d50)
|
||||
|
||||
@property
|
||||
def sigma(self):
|
||||
return self._sigma
|
||||
|
||||
@sigma.setter
|
||||
def sigma(self, sigma):
|
||||
self._sigma = float(sigma)
|
||||
|
||||
@property
|
||||
def critical_constraint(self):
|
||||
return self._critical_constraint
|
||||
|
||||
@critical_constraint.setter
|
||||
def critical_constraint(self, critical_constraint):
|
||||
self._critical_constraint = float(critical_constraint)
|
||||
|
||||
@classmethod
|
||||
def _sql_create(cls, execute):
|
||||
execute("""
|
||||
|
|
@ -61,6 +91,9 @@ class Layer(SQLSubModel):
|
|||
name TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
height REAL NOT NULL,
|
||||
d50 REAL NOT NULL,
|
||||
sigma REAL NOT NULL,
|
||||
critical_constraint REAL NOT NULL,
|
||||
sl INTEGER,
|
||||
FOREIGN KEY(sl) REFERENCES sedimentary_layer(id)
|
||||
)
|
||||
|
|
@ -83,7 +116,7 @@ class Layer(SQLSubModel):
|
|||
sl = data["sl"]
|
||||
|
||||
table = execute(
|
||||
"SELECT id, ind, name, type, height " +
|
||||
"SELECT id, ind, name, type, height, d50, sigma, critical_constraint " +
|
||||
"FROM sedimentary_layer_layer " +
|
||||
f"WHERE sl = {sl}"
|
||||
)
|
||||
|
|
@ -97,6 +130,8 @@ class Layer(SQLSubModel):
|
|||
layer = cls(
|
||||
id = row[0], name = row[2],
|
||||
type = row[3], height = row[4],
|
||||
d50 = row[5], sigma = row[6],
|
||||
critical_constraint = row[7],
|
||||
sl = sl, status = data['status']
|
||||
)
|
||||
|
||||
|
|
@ -110,10 +145,12 @@ class Layer(SQLSubModel):
|
|||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"sedimentary_layer_layer(id, ind, name, type, height, sl) "+
|
||||
"sedimentary_layer_layer(id, ind, name, type, height, d50, sigma, critical_constraint, sl) "+
|
||||
"VALUES (" +
|
||||
f"{self.id}, {ind}, '{self._sql_format(self._name)}', " +
|
||||
f"'{self._sql_format(self._type)}', '{self._height}', {sl.id}" +
|
||||
f"'{self._sql_format(self._type)}', {self._height}, " +
|
||||
f"{self._d50}, {self._sigma}, {self._critical_constraint}, " +
|
||||
f"{sl.id}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
|
|
|
|||
|
|
@ -54,6 +54,12 @@ class TableModel(QAbstractTableModel):
|
|||
return self._sl.get(row).type
|
||||
elif self._headers[column] == "height":
|
||||
return self._sl.get(row).height
|
||||
elif self._headers[column] == "d50":
|
||||
return self._sl.get(row).d50
|
||||
elif self._headers[column] == "sigma":
|
||||
return self._sl.get(row).sigma
|
||||
elif self._headers[column] == "critical_constraint":
|
||||
return self._sl.get(row).critical_constraint
|
||||
|
||||
return QVariant()
|
||||
|
||||
|
|
@ -88,6 +94,24 @@ class TableModel(QAbstractTableModel):
|
|||
self._sl, row, value
|
||||
)
|
||||
)
|
||||
if self._headers[column] == "d50":
|
||||
self._undo.push(
|
||||
SetD50Command(
|
||||
self._sl, row, value
|
||||
)
|
||||
)
|
||||
if self._headers[column] == "sigma":
|
||||
self._undo.push(
|
||||
SetSigmaCommand(
|
||||
self._sl, row, value
|
||||
)
|
||||
)
|
||||
if self._headers[column] == "critical_constraint":
|
||||
self._undo.push(
|
||||
SetCriticalConstraintCommand(
|
||||
self._sl, row, value
|
||||
)
|
||||
)
|
||||
|
||||
self.dataChanged.emit(index, index)
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -55,6 +55,51 @@ class SetHeightCommand(QUndoCommand):
|
|||
def redo(self):
|
||||
self._sediment_layers.get(self._index).height = self._new
|
||||
|
||||
class SetD50Command(QUndoCommand):
|
||||
def __init__(self, sediment_layers, index, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._sediment_layers = sediment_layers
|
||||
self._index = index
|
||||
self._old = self._sediment_layers.get(self._index).d50
|
||||
self._new = new_value
|
||||
|
||||
def undo(self):
|
||||
self._sediment_layers.get(self._index).d50 = self._old
|
||||
|
||||
def redo(self):
|
||||
self._sediment_layers.get(self._index).d50 = self._new
|
||||
|
||||
class SetSigmaCommand(QUndoCommand):
|
||||
def __init__(self, sediment_layers, index, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._sediment_layers = sediment_layers
|
||||
self._index = index
|
||||
self._old = self._sediment_layers.get(self._index).sigma
|
||||
self._new = new_value
|
||||
|
||||
def undo(self):
|
||||
self._sediment_layers.get(self._index).sigma = self._old
|
||||
|
||||
def redo(self):
|
||||
self._sediment_layers.get(self._index).sigma = self._new
|
||||
|
||||
class SetCriticalConstraintCommand(QUndoCommand):
|
||||
def __init__(self, sediment_layers, index, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._sediment_layers = sediment_layers
|
||||
self._index = index
|
||||
self._old = self._sediment_layers.get(self._index).critical_constraint
|
||||
self._new = new_value
|
||||
|
||||
def undo(self):
|
||||
self._sediment_layers.get(self._index).critical_constraint = self._old
|
||||
|
||||
def redo(self):
|
||||
self._sediment_layers.get(self._index).critical_constraint = self._new
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, sediment_layers, index):
|
||||
QUndoCommand.__init__(self)
|
||||
|
|
|
|||
|
|
@ -8,4 +8,7 @@ table_headers = {
|
|||
"name": _translate("SedimentLayers", "Name"),
|
||||
"type": _translate("SedimentLayers", "Type"),
|
||||
"height": _translate("Sedimentlayers", "Height"),
|
||||
"d50": _translate("Sedimentlayers", "D50"),
|
||||
"sigma": _translate("Sedimentlayers", "Sigma"),
|
||||
"critical_constraint": _translate("Sedimentlayers", "Critical constraint"),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue