Skip to content

Commit

Permalink
Merge pull request #896 from Giswater/dev-3.5
Browse files Browse the repository at this point in the history
Dev 3.5
  • Loading branch information
smaspons authored Aug 2, 2023
2 parents 7396dbd + 159939b commit 605f98d
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 137 deletions.
4 changes: 2 additions & 2 deletions config/user_params.config
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ _psector_replace_feature_keep_active = False
force_import_velocity_higher_50ms = False #If true, it will replace all '>50' velocities for '50'

[init.btn_go2epa_selector]
_load_result_layers = True #If true, it will automatically load the epa results layers
_load_compare_layers = True #If true, it will automatically load the epa compare layers
_load_result_layers = False #If true, it will automatically load the epa results layers
_load_compare_layers = False #If true, it will automatically load the epa compare layers

[session.btn_admin]
project_type = None
Expand Down
2 changes: 2 additions & 0 deletions core/admin/admin_btn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,8 @@ def _open_create_project(self):
self._change_project_type(self.cmb_create_project_type)
self.connection_name = str(tools_qt.get_text(self.dlg_readsql, self.cmb_connection))

self._update_time_elapsed("", self.dlg_readsql_create_project)

# Open dialog
self.dlg_readsql_create_project.setWindowTitle(f"Create Project - {self.connection_name}")
tools_gw.open_dialog(self.dlg_readsql_create_project, dlg_name='admin_dbproject')
Expand Down
4 changes: 2 additions & 2 deletions core/toolbars/epa/go2epa_selector_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _load_result_layers(self):
""" Adds any missing Compare layers to TOC """

# Manage user variable
if not tools_os.set_boolean(tools_gw.get_config_parser('btn_go2epa_selector', 'load_result_layers', "user", "init")):
if not tools_os.set_boolean(tools_gw.get_config_parser('btn_go2epa_selector', 'load_result_layers', "user", "init"), default=False):
return

filtre = "(id LIKE 'v_rpt_arc%' OR id LIKE 'v_rpt_node%')"
Expand All @@ -57,7 +57,7 @@ def _load_compare_layers(self):
""" Adds any missing Compare layers to TOC """

# Manage user variable
if not tools_os.set_boolean(tools_gw.get_config_parser('btn_go2epa_selector', 'load_compare_layers', "user", "init")):
if not tools_os.set_boolean(tools_gw.get_config_parser('btn_go2epa_selector', 'load_compare_layers', "user", "init"), default=False):
return

filtre = 'v_rpt_comp_%'
Expand Down
252 changes: 146 additions & 106 deletions core/utils/tools_gw.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbmodel
Submodule dbmodel updated 43 files
+0 −1 example/user/ws/ws_99_sample_other.sql
+4 −2 ud/fct/ud_gw_fct_rpt2pg_import_rpt.sql
+1 −1 ud/ftrg/ud_gw_trg_edit_arc.sql
+1 −1 ud/ftrg/ud_gw_trg_edit_connec.sql
+3 −3 ud/ftrg/ud_gw_trg_edit_dma.sql
+1 −1 ud/ftrg/ud_gw_trg_edit_gully.sql
+1 −1 ud/ftrg/ud_gw_trg_edit_node.sql
+6 −2 updates/35/35031/ud/dml.sql
+6 −2 updates/35/35031/ws/dml.sql
+26 −0 updates/35/35038/ud/dml.sql
+11 −0 updates/35/35038/ws/dml.sql
+4 −0 updates/35/35039/changelog.txt
+13 −0 updates/35/35039/ud/ddl.sql
+175 −0 updates/35/35039/ud/ddlview.sql
+4 −2 updates/35/35039/ud/dml.sql
+11 −0 updates/35/35039/ud/trg.sql
+27 −0 updates/35/35039/utils/ddl.sql
+57 −0 updates/35/35039/utils/dml.sql
+25 −0 updates/35/35039/ws/ddl.sql
+49 −0 updates/35/35039/ws/ddlview.sql
+15 −0 updates/35/35039/ws/dml.sql
+14 −0 updates/35/35039/ws/tablect.sql
+14 −0 updates/35/35039/ws/trg.sql
+2 −1 utils/fct/gw_fct_admin_role_permissions.sql
+1 −1 utils/fct/gw_fct_getaddlayervalues.sql
+22 −19 utils/fct/gw_fct_getfeatureupsert.sql
+29 −8 utils/fct/gw_fct_getformfields.sql
+934 −879 utils/fct/gw_fct_graphanalytics_mapzones.sql
+8 −3 utils/fct/gw_fct_linktonetwork.sql
+49 −38 utils/fct/gw_fct_psector_duplicate.sql
+6 −0 utils/fct/gw_fct_setarcdivide.sql
+8 −0 utils/fct/gw_fct_setcheckproject.sql
+1 −13 utils/fct/gw_fct_setselectors.sql
+303 −175 ws/fct/ws_gw_fct_graphanalytics_minsector.sql
+4 −0 ws/fct/ws_gw_fct_pg2epa_check_result.sql
+0 −9 ws/fct/ws_gw_fct_pg2epa_dscenario.sql
+4 −0 ws/fct/ws_gw_fct_rpt2pg_main.sql
+1 −1 ws/ftrg/ws_gw_trg_edit_arc.sql
+1 −1 ws/ftrg/ws_gw_trg_edit_connec.sql
+3 −3 ws/ftrg/ws_gw_trg_edit_dma.sql
+918 −917 ws/ftrg/ws_gw_trg_edit_node.sql
+1 −1 ws/ftrg/ws_gw_trg_node_rotation_update.sql
+60 −58 ws/ftrg/ws_gw_trg_topocontrol_node.sql
2 changes: 1 addition & 1 deletion lib/tools_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def manage_pg_service(section):
tools_log.log_warning(f"File defined in environment variable 'PGSERVICEFILE' not found: {service_file}")
return None

config_parser = configparser.ConfigParser(strict=False)
config_parser = configparser.ConfigParser(comment_prefixes=";", allow_no_value=True, strict=False)
credentials = {'host': None, 'port': None, 'dbname': None, 'user': None, 'password': None, 'sslmode': None}
try:
config_parser.read(service_file)
Expand Down
12 changes: 7 additions & 5 deletions lib/tools_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from qgis.core import QgsExpressionContextUtils, QgsProject, QgsPointLocator, \
QgsSnappingUtils, QgsTolerance, QgsPointXY, QgsFeatureRequest, QgsRectangle, QgsSymbol, \
QgsLineSymbol, QgsRendererCategory, QgsCategorizedSymbolRenderer, QgsGeometry, QgsCoordinateReferenceSystem, \
QgsCoordinateTransform
QgsCoordinateTransform, QgsFillSymbol
from qgis.core import QgsVectorLayer
from qgis.utils import iface

Expand Down Expand Up @@ -202,7 +202,7 @@ def get_plugin_metadata(parameter, default_value, plugin_dir=None):

value = None
try:
metadata = configparser.ConfigParser(strict=False)
metadata = configparser.ConfigParser(comment_prefixes=";", allow_no_value=True, strict=False)
metadata.read(metadata_file)
value = metadata.get('general', parameter)
except configparser.NoOptionError:
Expand All @@ -224,7 +224,7 @@ def get_plugin_version():
message = f"Metadata file not found: {metadata_file}"
return plugin_version, message

metadata = configparser.ConfigParser(strict=False)
metadata = configparser.ConfigParser(comment_prefixes=";", allow_no_value=True, strict=False)
metadata.read(metadata_file)
plugin_version = metadata.get('general', 'version')
if plugin_version is None:
Expand Down Expand Up @@ -676,7 +676,7 @@ def restore_user_layer(layer_name, user_current_layer=None):
iface.setActiveLayer(layer)


def set_layer_categoryze(layer, cat_field, size, color_values, unique_values=None):
def set_layer_categoryze(layer, cat_field, size, color_values, unique_values=None, opacity=255):
"""
:param layer: QgsVectorLayer to be categorized (QgsVectorLayer)
:param cat_field: Field to categorize (String)
Expand All @@ -695,6 +695,8 @@ def set_layer_categoryze(layer, cat_field, size, color_values, unique_values=Non
symbol = QgsSymbol.defaultSymbol(layer.geometryType())
if type(symbol) in (QgsLineSymbol, ):
symbol.setWidth(size)
elif type(symbol) in (QgsFillSymbol, ):
pass
else:
symbol.setSize(size)

Expand All @@ -703,7 +705,7 @@ def set_layer_categoryze(layer, cat_field, size, color_values, unique_values=Non
color = color_values.get(str(unique_value))
symbol.setColor(color)
except Exception:
color = QColor(randrange(0, 256), randrange(0, 256), randrange(0, 256))
color = QColor(randrange(0, 256), randrange(0, 256), randrange(0, 256), opacity)
symbol.setColor(color)

# create renderer object
Expand Down
13 changes: 7 additions & 6 deletions lib/tools_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,14 +948,15 @@ def reset_model(dialog, table_object, feature_type):

def get_feature_by_id(layer, id, field_id=None):

features = layer.getFeatures()
for feature in features:
if field_id is None:
if feature.id() == id:
return feature
else:
if field_id is not None:
expr = f"{field_id} = '{id}'"
features = layer.getFeatures(expr)
for feature in features:
if feature[field_id] == id:
return feature
else:
return layer.getFeature(id)

return False


Expand Down
23 changes: 14 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,21 @@ def _init_plugin(self):
self._manage_user_config_folder(f"{global_vars.user_folder_dir}{os.sep}core")

# Initialize parsers of configuration files: init, session, giswater, user_params
tools_gw.initialize_parsers()
success = tools_gw.initialize_parsers()

# Check if user has config files 'init' and 'session' and its parameters (only those without prefix)
try:
tools_gw.check_old_userconfig(global_vars.user_folder_dir)
except Exception as e:
# This may happen if the user doesn't have permission to move/delete files
msg = "Exception while moving/deleting old user config files"
tools_log.log_warning(msg, parameter=e)
tools_gw.user_params_to_userconfig()
if not success:
tools_gw.recreate_config_files()
msg = "The user config files have been recreated. A backup of the broken ones have been created at"
tools_qgis.show_message(msg, message_level=3, title="Parsing error fixed", parameter=f"{global_vars.user_folder_dir}{os.sep}core{os.sep}config{os.sep}")
else:
# Check if user has config files 'init' and 'session' and its parameters (only those without prefix)
try:
tools_gw.check_old_userconfig(global_vars.user_folder_dir)
except Exception as e:
# This may happen if the user doesn't have permission to move/delete files
msg = "Exception while moving/deleting old user config files"
tools_log.log_warning(msg, parameter=e)
tools_gw.user_params_to_userconfig()

# Set logger parameters min_log_level and log_limit_characters
min_log_level = tools_gw.get_config_parser('log', 'log_level', 'user', 'init', False)
Expand Down
9 changes: 5 additions & 4 deletions metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ qgisMinimumVersion=3.10
qgisMaximumVersion=3.99
description=Plugin to manage water networks (water supply, sewerage and urban drainage) using QGIS and PostGIS-PostgreSQL(from 9.5 to 14.x)
about=Disclaimer: This plugin is released using the open source GNU-GPL3 license. Although a reasonable effort has been made to assure that the results obtained are correct, some of the capabilities provided by Giswater are experimental, therefore the development team and the Giswater Association are not responsible and assume no liability whatsoever for any results or any use made of the results obtained from the program, nor for any damages or litigation that result from the use of these programs for any purpose.
version=3.5.038
version=3.5.039
author=David Erill, Luigi Pirelli, Natasa Cica, Nestor Ibañez, Adrian Valenciano, Barbara Rzepka, Sergi Muñoz, Josep Lluís Sala, Edgar Fusté, Albert Bofill, Sergi Maspons, Elies Bertran, Abel García Juanes, Xavier Torret

Changelog=Version 3.5.038
- Add user variables to auto load or not go2epa selector layers
Changelog=Version 3.5.039
- Massive performance improvement of get_feature_by_id. Now the tools that search for features should be faster
- Improve handling of config files.
- Don't load epa result/compare layers by default
- Various bug fixes


tags= giswater, water networks, sewerage, urban drainage, EPANET, SWMM
homepage=https://www.giswater.org
repository=https://github.com/giswater/giswater_qgis_plugin
Expand Down
2 changes: 1 addition & 1 deletion test/test_giswater.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_plugin_metadata(self, parameter, default_value):

value = None
try:
metadata = configparser.ConfigParser()
metadata = configparser.ConfigParser(comment_prefixes=";", allow_no_value=True, strict=False)
metadata.read(metadata_file)
value = metadata.get('general', parameter)
except configparser.NoOptionError:
Expand Down

0 comments on commit 605f98d

Please sign in to comment.