Skip to content

Commit

Permalink
Merge pull request #884 from Giswater/dev-3.5
Browse files Browse the repository at this point in the history
Dev 3.5
  • Loading branch information
edgarfuste authored Mar 8, 2023
2 parents 961a4a5 + 715191a commit 0f6814a
Show file tree
Hide file tree
Showing 29 changed files with 223,157 additions and 189,706 deletions.
12 changes: 12 additions & 0 deletions config/user_params.config
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,18 @@ _gw_fct_graphanalytics_minsector_updatefeature = None
_gw_fct_graphanalytics_minsector_geomparamupdate = None
_gw_fct_graphanalytics_minsector_updatemapzone = None
_gw_fct_graphanalytics_mapzones_advanced_commitchanges = None
_gw_fct_waterbalance_method = None
_gw_fct_capture_address_cmb_feature_type = None
_gw_fct_capture_address_cmb_layers = None
_gw_fct_capture_address_rbt_previous = None
_gw_fct_capture_address_catfeature = None
_gw_fct_setclosestaddress_cmb_feature_type = None
_gw_fct_setclosestaddress_cmb_layers = None
_gw_fct_setclosestaddress_rbt_previous = None
_gw_fct_setclosestaddress_catfeature = None
_gw_fct_setclosestaddress_fieldtoupdate = None
_gw_fct_setclosestaddress_searchbuffer = None
_gw_fct_setclosestaddress_updatevalues = None

[session.docker]
_position = None
Expand Down
15 changes: 15 additions & 0 deletions core/admin/admin_btn.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,18 @@ def execute_last_process(self, new_project=False, schema_name=None, schema_type=
return result


def execute_reset_sequences(self, schema_name=None):
""" Execute last process function """

self.schema_name = schema_name

result = tools_gw.execute_procedure('gw_fct_admin_reset_sequences', schema_name=self.schema_name, commit=False)
if result is None or ('status' in result and result['status'] == 'Failed'):
self.error_count = self.error_count + 1

return result


def execute_import_inp_data(self, project_name, project_type):
""" Executed when option 'Import INP data' has been selected """

Expand Down Expand Up @@ -372,6 +384,9 @@ def load_updates(self, project_type=None, update_changelog=False, schema_name=No
self.task1.setProgress(60)
if status:
status = self.execute_last_process(schema_name=schema_name, locale=True)
if status:
self.execute_reset_sequences(schema_name=schema_name)

self.task1.setProgress(100)

if update_changelog is False:
Expand Down
1 change: 1 addition & 0 deletions core/admin/i18n_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def _create_py_files(self):
line = '\t</context>\n\n'
line += '\t<!-- PYTHON MESSAGES -->\n'
line += '\t<context>\n'
line += f'\t\t<name>{self.scode}</name>\n'
ts_file.write(line)

# Create children for message
Expand Down
4 changes: 4 additions & 0 deletions core/shared/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self):
self.canvas = global_vars.canvas
self.snapper_manager = GwSnapManager(self.iface)
self.vertex_marker = self.snapper_manager.vertex_marker
self.dlg_add_element = None


def get_element(self, new_element_id=True, feature=None, feature_type=None, selected_object_id=None, list_tabs=None):
Expand Down Expand Up @@ -250,6 +251,9 @@ def get_element(self, new_element_id=True, feature=None, feature_type=None, sele
return self.dlg_add_element


def get_element_dialog(self):
return self.dlg_add_element

def _update_location_cmb(self):

element_type = tools_qt.get_text(self.dlg_add_element, self.dlg_add_element.element_type)
Expand Down
15 changes: 12 additions & 3 deletions core/shared/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ def open_form(self, point=None, table_name=None, feature_id=None, feature_cat=No
dlg_add_visit = manage_visit.get_visit_dialog()
dlg_add_visit.rejected.connect(lambda: tools_gw.reset_rubberband(self.rubber_band))

elif template == 'element':
element_id = self.complet_result['body']['feature']['id']
manage_element = GwElement()
manage_element.get_element(new_element_id=False, selected_object_id=element_id)
dlg_add_element = manage_element.get_element_dialog()
dlg_add_element.rejected.connect(lambda: tools_gw.reset_rubberband(self.rubber_band))

else:
tools_log.log_warning(f"template not managed: {template}")
return False, None
Expand Down Expand Up @@ -2894,7 +2901,8 @@ def _manage_element(self, dialog, element_id=None, feature=None):
""" Execute action of button 33 """

elem = GwElement()
elem.get_element(False, feature, self.feature_type)
new_element = element_id is None
elem.get_element(new_element, feature, self.feature_type)
elem.dlg_add_element.accepted.connect(partial(self._manage_element_new, dialog, elem))
elem.dlg_add_element.rejected.connect(partial(self._manage_element_new, dialog, elem))

Expand Down Expand Up @@ -4331,8 +4339,9 @@ def _get_id(self, dialog, action, option, emit_point, child_type, point, event):
widget = dialog.findChild(QWidget, f"{options[option][1]}")
widget.setFocus()
tools_qt.set_widget_text(dialog, widget, str(feat_id))
# Insert result into self.my_json regardless of widget editing
self.my_json[f"{option}_id"] = f"{feat_id}"
if action == self.action_get_arc_id:
# Insert result into self.my_json regardless of widget editing
self.my_json[f"{option}_id"] = f"{feat_id}"
elif option == 'set_to_arc':
# functions called in -> getattr(self, options[option][0])(feat_id, child_type)
# def _set_to_arc(self, feat_id, child_type)
Expand Down
27 changes: 22 additions & 5 deletions core/shared/nonvisual.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def get_curves(self, curve_id=None, duplicate=False):

# Connect dialog signals
cmb_curve_type.currentIndexChanged.connect(partial(self._manage_curve_type, self.dialog, curve_type_headers, tbl_curve_value))
cmb_curve_type.currentIndexChanged.connect(partial(self._manage_curve_plot, self.dialog, tbl_curve_value, plot_widget))
tbl_curve_value.cellChanged.connect(partial(self._onCellChanged, tbl_curve_value))
tbl_curve_value.cellChanged.connect(partial(self._manage_curve_value, self.dialog, tbl_curve_value))
tbl_curve_value.cellChanged.connect(partial(self._manage_curve_plot, self.dialog, tbl_curve_value, plot_widget))
Expand All @@ -302,7 +303,7 @@ def get_curves(self, curve_id=None, duplicate=False):

# Set initial curve_value table headers
self._manage_curve_type(self.dialog, curve_type_headers, tbl_curve_value, 0)
self._manage_curve_plot(self.dialog, tbl_curve_value, plot_widget, None, None)
self._manage_curve_plot(self.dialog, tbl_curve_value, plot_widget)
# Set scale-to-fit
tools_qt.set_tableview_config(tbl_curve_value, sectionResizeMode=1, edit_triggers=QTableView.DoubleClicked)

Expand Down Expand Up @@ -473,12 +474,15 @@ def _manage_curve_value(self, dialog, table, row, column):
self.valid = (valid, "Invalid curve. Values must go in pairs.")


def _manage_curve_plot(self, dialog, table, plot_widget, row, column):
def _manage_curve_plot(self, dialog, table, plot_widget):
""" Note: row & column parameters are passed by the signal """

# Clear plot
plot_widget.axes.cla()

# Check combo type
curve_type = tools_qt.get_combo_value(dialog, dialog.cmb_curve_type)

# Read row values
values = self._read_tbl_values(table)
temp_list = [] # String list with all table values
Expand Down Expand Up @@ -514,7 +518,6 @@ def _manage_curve_plot(self, dialog, table, plot_widget, row, column):
y_list = [x[1] for x in float_list] # y_list = [y1, y2, y3]

# Create curve if only one value with curve_type 'PUMP'
curve_type = tools_qt.get_combo_value(dialog, dialog.cmb_curve_type)
if scipy_imported and len(x_list) == 1 and curve_type == 'PUMP':
# Draw curve with points (0, 1.33y), (x, y), (2x, 0)
x = x_list[0]
Expand All @@ -532,8 +535,22 @@ def _manage_curve_plot(self, dialog, table, plot_widget, row, column):
x_list = xnew
y_list = y_smooth

# Create and draw plot
plot_widget.axes.plot(x_list, y_list, color='indianred')
# Manage inverted plot and mirror plot for SHAPE type
if curve_type == 'SHAPE':

# Get inverted points from y_lits
y_list_inverted = [-y for y in y_list]

# Get figure
fig = plot_widget.figure
# Create inverted plot
plot_widget.axes.plot(y_list, x_list, color="blue")
# Create mirror plot
plot_widget.axes.plot(y_list_inverted, x_list, color="grey")
else:
plot_widget.axes.plot(x_list, y_list, color='indianred')

# Draw plot
plot_widget.draw()


Expand Down
72 changes: 39 additions & 33 deletions core/shared/psector.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ def get_psector(self, psector_id=None, list_coord=None):
self.dlg_plan_psector.tab_feature.currentChanged.connect(
partial(self._manage_tab_feature_buttons))
self.dlg_plan_psector.name.textChanged.connect(partial(self.enable_relation_tab, 'plan_psector'))
self.dlg_plan_psector.expl_id.currentIndexChanged.connect(partial(self.enable_relation_tab, 'plan_psector'))
viewname = 'v_edit_plan_psector_x_other'
self.dlg_plan_psector.txt_name.textChanged.connect(
partial(self.query_like_widget_text, self.dlg_plan_psector, self.dlg_plan_psector.txt_name,
Expand Down Expand Up @@ -859,7 +860,8 @@ def enable_buttons(self, enabled):
def enable_relation_tab(self, tablename):

psector_name = f"{tools_qt.get_text(self.dlg_plan_psector, self.dlg_plan_psector.name)}"
sql = f"SELECT name FROM {tablename} WHERE LOWER(name) = '{psector_name}'"
psector_expl = tools_qt.get_combo_value(self.dlg_plan_psector, "expl_id", 0)
sql = f"SELECT name FROM {tablename} WHERE LOWER(name) = '{psector_name}' AND expl_id = {psector_expl}"
rows = tools_db.get_rows(sql)
if not rows:
if self.dlg_plan_psector.name.text() != '':
Expand Down Expand Up @@ -1011,11 +1013,11 @@ def reset_model_psector(self, feature_type):
widget.setModel(None)


def check_name(self, psector_name):
def check_name(self, psector_name, expl_id):
""" Check if name of new psector exist or not """

sql = (f"SELECT name FROM plan_psector"
f" WHERE name = '{psector_name}'")
sql = (f"SELECT name, expl_id FROM plan_psector"
f" WHERE name = '{psector_name}' AND expl_id = '{expl_id}'")
row = tools_db.get_row(sql)
if row is None:
return False
Expand All @@ -1030,14 +1032,20 @@ def insert_or_update_new_psector(self, tablename, close_dlg=False):
tools_qgis.show_warning(message, parameter='Name', dialog=self.dlg_plan_psector)
return

expl_id = tools_qt.get_combo_value(self.dlg_plan_psector, "expl_id", 0)
if expl_id == -1:
message = "Mandatory field is missing. Please, set a value"
tools_qgis.show_warning(message, parameter='Exploitation', dialog=self.dlg_plan_psector)
return

rotation = tools_qt.get_text(self.dlg_plan_psector, "rotation", return_string_null=False)
if rotation == "":
tools_qt.set_widget_text(self.dlg_plan_psector, self.dlg_plan_psector.rotation, 0)

name_exist = self.check_name(psector_name)
name_exist = self.check_name(psector_name, expl_id)

if name_exist and not self.update:
message = "The name is current in use"
message = "The name is currently in use"
tools_qgis.show_warning(message, dialog=self.dlg_plan_psector)
return
else:
Expand Down Expand Up @@ -1602,7 +1610,7 @@ def set_toggle_active(self, dialog, qtbl_psm):
selected_list = qtbl_psm.selectionModel().selectedRows()
if len(selected_list) == 0:
message = "Any record selected"
tools_qgis.show_warning(message, dialog=self.dlg_psector_mng)
tools_qgis.show_warning(message, dialog=dialog)
return
for i in range(0, len(selected_list)):
row = selected_list[i].row()
Expand All @@ -1611,7 +1619,7 @@ def set_toggle_active(self, dialog, qtbl_psm):
active = qtbl_psm.model().record(row).value("active")
if psector_id == self.current_psector_id[0]:
message = f"The active state of the current psector cannot be changed. Current psector: {self.current_psector_id[1]}"
tools_qgis.show_warning(message, dialog=self.dlg_psector_mng)
tools_qgis.show_warning(message, dialog=dialog)
return
if active:
sql += f"UPDATE plan_psector SET active = False WHERE psector_id = {psector_id};"
Expand All @@ -1635,7 +1643,7 @@ def update_current_psector(self, dialog, qtbl_psm):
active = qtbl_psm.model().record(row).value("active")
if active is False:
message = f"Cannot set the current psector of an inactive psector. You must activate it before."
tools_qgis.show_warning(message, dialog=self.dlg_psector_mng)
tools_qgis.show_warning(message, dialog=dialog)
return
aux_widget = QLineEdit()
aux_widget.setText(str(psector_id))
Expand All @@ -1645,6 +1653,7 @@ def update_current_psector(self, dialog, qtbl_psm):
tools_qgis.show_info(message, dialog=dialog)

self.fill_table(dialog, qtbl_psm, "v_ui_plan_psector")
self._filter_table(self.dlg_psector_mng, self.qtbl_psm, self.dlg_psector_mng.txt_name,self.dlg_psector_mng.chk_active, 'v_ui_plan_psector')
tools_gw.set_tablemodel_config(dialog, qtbl_psm, "v_ui_plan_psector")
self.set_label_current_psector(dialog)
tools_gw.open_dialog(dialog)
Expand Down Expand Up @@ -1716,16 +1725,6 @@ def _filter_table(self, dialog, table, widget_txt, widget_chk, tablename):
else:
self.fill_table(dialog, table, tablename)

def filter_by_active(self, dialog, table):

chk_active_state = dialog.chk_active.isChecked()
expr = f" active is {chk_active_state}"

# Refresh model with selected filter
table.model().setFilter(expr)
table.model().select()



def charge_psector(self, qtbl_psm):

Expand Down Expand Up @@ -2099,8 +2098,9 @@ def _set_to_arc(self, idx):
# Set signals
tools_gw.connect_signal(self.canvas.xyCoordinates, self._mouse_move_arc, 'psector',
'set_to_arc_xyCoordinates_mouse_move_arc')
tools_gw.connect_signal(self.emit_point.canvasClicked, partial(self._set_arc_id, idx),
'psector', 'set_to_arc_ep_canvasClicked_set_arc_id')
# To activate action pan and not move the canvas accidentally we have to override the canvasReleaseEvent.
# The "e" is the QgsMapMouseEvent given by the function
self.emit_point.canvasReleaseEvent = lambda e: self._set_arc_id(idx, e.mapPoint(), 1)


def _set_arc_id(self, idx, point, event):
Expand Down Expand Up @@ -2178,30 +2178,36 @@ def _set_arc_id(self, idx, point, event):

the_geom = f"ST_GeomFromText('POINT({point.x()} {point.y()})', {global_vars.data_epsg})"

if tab_idx == 2:
self._update_tbl_relations(selected_rows, idx, the_geom, self.qtbl_connec, "id", self.tablename_psector_x_connec, self.arc_id, self.qtbl_connec)
elif tab_idx == 3:
self._update_tbl_relations(selected_rows, idx, the_geom, self.qtbl_gully, "id", self.tablename_psector_x_gully, self.arc_id, self.qtbl_gully)

# Force a map refresh
tools_qgis.force_refresh_map_canvas()

# Manage signals
tools_qgis.disconnect_snapping(True, self.emit_point, self.vertex_marker)
tools_gw.set_model_signals(self)


def _update_tbl_relations(self, selected_rows, idx, the_geom, table_name, id_column, tablename_psector_x_connec, arc_id, qtbl):
for row in selected_rows:
sql = ""
if idx == 1:
sql += (f"INSERT INTO temp_table (fid, geom_point) VALUES (485, {the_geom});\n")

row_id = self.qtbl_connec.model().record(row.row()).value("id")
row_id = qtbl.model().record(row.row()).value(id_column)

sql += (f"UPDATE {self.tablename_psector_x_connec} SET arc_id = "
f"'{self.arc_id}' WHERE id = '{row_id}'")
sql += (f"UPDATE {tablename_psector_x_connec} SET arc_id = "
f"'{arc_id}' WHERE id = '{row_id}'")

tools_db.execute_sql(sql)

filter_ = "psector_id = '" + str(self.psector_id.text()) + "'"
self.fill_table(self.dlg_plan_psector, self.qtbl_connec, self.tablename_psector_x_connec,
self.fill_table(self.dlg_plan_psector, table_name, tablename_psector_x_connec,
set_edit_triggers=QTableView.DoubleClicked, expr=filter_)

# Force a map refresh
tools_qgis.force_refresh_map_canvas()

# Manage signals
tools_qgis.disconnect_snapping(True, self.emit_point, self.vertex_marker)
tools_gw.set_model_signals(self)


def _replace_arc(self):

if hasattr(self, 'emit_point') and self.emit_point is not None:
Expand Down
6 changes: 3 additions & 3 deletions core/shared/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ def get_selector(self, dialog, selector_type, filter=False, widget=None, text_fi
selector_type = selector_type.strip('"')
# Built querytext
form = f'"currentTab":"{current_tab}"'
extras = f'"selectorType":"{selector_type}", "filterText":"{text_filter}",'
extras = f'"selectorType":"{selector_type}", "filterText":"{text_filter}" '
if aux_params:
tools_gw.set_config_parser("selector_mincut", f"aux_params", f"{aux_params}", "user", "session")
extras = f"{extras}, {aux_params}, "
extras += f'"addSchema":"{global_vars.project_vars["add_schema"]}"'
extras = f"{extras}, {aux_params} "
extras += f', "addSchema":"{global_vars.project_vars["add_schema"]}"'
body = tools_gw.create_body(form=form, extras=extras)
json_result = tools_gw.execute_procedure('gw_fct_getselectors', body)

Expand Down
7 changes: 6 additions & 1 deletion core/threads/project_schema_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .task import GwTask
from ..utils import tools_gw
from ...lib import tools_qt, tools_log, tools_db
from ...lib import tools_qt, tools_log, tools_db, tools_qgis


class GwUpdateSchemaTask(GwTask):
Expand Down Expand Up @@ -76,6 +76,11 @@ def finished(self, result):
tools_gw.fill_tab_log(self.admin.dlg_readsql_show_info, self.status['body']['data'], True, True, 1)
else:
tools_log.log_warning(f"Key not found: 'body'")
else:
tools_qgis.show_warning("Update project failed.", dialog=self.admin.dlg_readsql_show_info)
# Show message
status = (self.admin.error_count == 0)
self.admin._manage_result_message(status, parameter="Update project")

# Reset count error variable to 0
self.admin.error_count = 0
Expand Down
Loading

0 comments on commit 0f6814a

Please sign in to comment.