30
30
from .gis_file_create import GwGisFileCreate
31
31
from ..threads .task import GwTask
32
32
from ..ui .ui_manager import GwAdminUi , GwAdminDbProjectUi , GwAdminRenameProjUi , GwAdminProjectInfoUi , \
33
- GwAdminGisProjectUi , GwAdminImportUi , GwAdminFieldsUi , GwCredentialsUi , GwReplaceInFileUi
33
+ GwAdminGisProjectUi , GwAdminFieldsUi , GwCredentialsUi , GwReplaceInFileUi
34
34
from ..utils import tools_gw
35
35
from ... import global_vars
36
36
from .i18n_generator import GwI18NGenerator
@@ -133,8 +133,6 @@ def create_project_data_schema(self, project_name_schema=None, project_descript=
133
133
# Save in settings
134
134
tools_gw .set_config_parser ('btn_admin' , 'project_name_schema' , f'{ project_name_schema } ' , prefix = False )
135
135
tools_gw .set_config_parser ('btn_admin' , 'project_descript' , f'{ project_descript } ' , prefix = False )
136
- inp_file_path = tools_qt .get_text (self .dlg_readsql_create_project , 'data_file' , False , False )
137
- tools_gw .set_config_parser ('btn_admin' , 'inp_file_path' , f'{ inp_file_path } ' , prefix = False )
138
136
locale = tools_qt .get_combo_value (self .dlg_readsql_create_project , self .cmb_locale , 0 )
139
137
tools_gw .set_config_parser ('btn_admin' , 'project_locale' , f'{ locale } ' , prefix = False )
140
138
@@ -156,28 +154,7 @@ def create_project_data_schema(self, project_name_schema=None, project_descript=
156
154
157
155
tools_log .log_info (f"Create schema of type '{ project_type } ': '{ project_name_schema } '" )
158
156
159
- if self .rdb_inp .isChecked ():
160
- self .file_inp = tools_qt .get_text (self .dlg_readsql_create_project , 'data_file' )
161
- if self .file_inp == 'null' :
162
- msg = "The 'Path' field is required for Import INP data."
163
- tools_qt .show_info_box (msg , "Info" )
164
- return
165
- # Check that the INP file works with the selected project_type
166
- with open (self .file_inp , 'rb' , 0 ) as file , \
167
- mmap .mmap (file .fileno (), 0 , access = mmap .ACCESS_READ ) as s :
168
- msg = ""
169
- # If we're creating a 'ud' project but the INP file is from epanet
170
- if project_type == 'ud' and s .find (b'[PIPES]' ) != - 1 :
171
- msg = "The selected INP file does not match with a 'UD' project.\n " \
172
- "Please check it before continuing..."
173
- # If we're creating a 'ws' project but the INP file is from swmm
174
- if project_type == 'ws' and s .find (b'[CONDUITS]' ) != - 1 :
175
- msg = "The selected INP file does not match with a 'WS' project.\n " \
176
- "Please check it before continuing..."
177
- if msg :
178
- tools_qt .show_info_box (msg , "Warning" )
179
- return
180
- elif self .rdb_sample_full .isChecked () or self .rdb_sample_inv .isChecked ():
157
+ if self .rdb_sample_full .isChecked () or self .rdb_sample_inv .isChecked ():
181
158
if self .locale != 'en_US' or str (self .project_epsg ) != '25831' :
182
159
msg = ("This functionality is only allowed with the locality 'en_US' and SRID 25831."
183
160
"\n Do you want change it and continue?" )
@@ -275,43 +252,6 @@ def execute_last_process(self, new_project=False, schema_name=None, schema_type=
275
252
return result
276
253
277
254
278
- def execute_import_inp_data (self , project_name , project_type ):
279
- """ Executed when option 'Import INP data' has been selected """
280
-
281
- # Create dialog
282
- self .dlg_import_inp = GwAdminImportUi (self )
283
- tools_gw .load_settings (self .dlg_import_inp )
284
-
285
- # Hide widgets
286
- self .dlg_import_inp .progressBar .setVisible (False )
287
-
288
- if project_type .lower () == 'ws' :
289
- extras = '"functionId":2522'
290
- elif project_type .lower () == 'ud' :
291
- extras = '"functionId":2524'
292
- else :
293
- self .error_count = self .error_count + 1
294
- return
295
-
296
- schema_name = tools_qt .get_text (self .dlg_readsql_create_project , 'project_name' )
297
-
298
- body = tools_gw .create_body (extras = extras )
299
- complet_result = tools_gw .execute_procedure ('gw_fct_getprocess' , body , schema_name , commit = False )
300
- if not complet_result or complet_result ['status' ] == 'Failed' :
301
- return False
302
- self ._populate_functions_dlg (self .dlg_import_inp , complet_result ['body' ]['data' ])
303
-
304
- # Disable tab log
305
- tools_gw .disable_tab_log (self .dlg_import_inp )
306
-
307
- # Set listeners
308
- self .dlg_import_inp .btn_run .clicked .connect (partial (self ._execute_import_inp , True , project_name , project_type ))
309
- self .dlg_import_inp .btn_close .clicked .connect (partial (self ._execute_import_inp , False , project_name , project_type ))
310
-
311
- # Open dialog
312
- tools_gw .open_dialog (self .dlg_import_inp , dlg_name = 'admin_importinp' )
313
-
314
-
315
255
def cancel_task (self ):
316
256
if hasattr (self , 'task_create_schema' ) and not isdeleted (self .task_create_schema ):
317
257
self .task_create_schema .cancel ()
@@ -401,8 +341,6 @@ def init_dialog_create_project(self, project_type=None):
401
341
self .rdb_sample_inv = self .dlg_readsql_create_project .findChild (QRadioButton , 'rdb_sample_inv' )
402
342
self .rdb_sample_full = self .dlg_readsql_create_project .findChild (QRadioButton , 'rdb_sample_full' )
403
343
self .rdb_empty = self .dlg_readsql_create_project .findChild (QRadioButton , 'rdb_empty' )
404
- self .rdb_inp = self .dlg_readsql_create_project .findChild (QRadioButton , 'rdb_inp' )
405
- self .data_file = self .dlg_readsql_create_project .findChild (QLineEdit , 'data_file' )
406
344
407
345
# Load user values
408
346
self .project_name .setText (tools_gw .get_config_parser ('btn_admin' , 'project_name_schema' , "user" , "session" ,
@@ -417,12 +355,9 @@ def init_dialog_create_project(self, project_type=None):
417
355
chk_widget .setChecked (True )
418
356
except :
419
357
pass
420
- inp_file_path = tools_gw .get_config_parser ('btn_admin' , 'inp_file_path' , "user" , "session" , False , force_reload = True )
421
- if inp_file_path not in ('null' , None ):
422
- self .data_file .setText (inp_file_path )
358
+
423
359
424
360
# TODO: do and call listener for buton + table -> temp_csv
425
- self .btn_push_file = self .dlg_readsql_create_project .findChild (QPushButton , 'btn_push_file' )
426
361
427
362
# Manage SRID
428
363
self ._manage_srid ()
@@ -436,9 +371,6 @@ def init_dialog_create_project(self, project_type=None):
436
371
tools_qt .set_widget_text (self .dlg_readsql_create_project , self .cmb_create_project_type , project_type )
437
372
self ._change_project_type (self .cmb_create_project_type )
438
373
439
- # Enable_disable data file widgets
440
- self ._enable_datafile ()
441
-
442
374
# Get combo locale
443
375
self .cmb_locale = self .dlg_readsql_create_project .findChild (QComboBox , 'cmb_locale' )
444
376
@@ -1480,17 +1412,6 @@ def _update_locale(self):
1480
1412
self .folder_locale = os .path .join (self .sql_dir , 'i18n' , cmb_locale )
1481
1413
1482
1414
1483
- def _enable_datafile (self ):
1484
- """"""
1485
-
1486
- if self .rdb_inp .isChecked () is True :
1487
- self .data_file .setEnabled (True )
1488
- self .btn_push_file .setEnabled (True )
1489
- else :
1490
- self .data_file .setEnabled (False )
1491
- self .btn_push_file .setEnabled (False )
1492
-
1493
-
1494
1415
def _populate_data_schema_name (self , widget ):
1495
1416
""""""
1496
1417
@@ -1576,12 +1497,14 @@ def _set_info_project(self):
1576
1497
1577
1498
self .postgresql_version = tools_db .get_pg_version ()
1578
1499
self .postgis_version = tools_db .get_postgis_version ()
1500
+ self .pgrouting_version = tools_db .get_pgrouting_version ()
1579
1501
1580
1502
if schema_name == 'null' :
1581
1503
tools_qt .enable_tab_by_tab_name (self .dlg_readsql .tab_main , "others" , False )
1582
1504
1583
- msg = (f'Database version: { self .postgresql_version } \n '
1584
- f'PostGis version: { self .postgis_version } \n \n ' )
1505
+ msg = (f'PostgreSQL version: { self .postgresql_version } \n '
1506
+ f'PostGis version: { self .postgis_version } \n '
1507
+ f'pgRouting version: { self .pgrouting_version } \n \n ' )
1585
1508
self .software_version_info .setText (msg )
1586
1509
1587
1510
else :
@@ -1596,8 +1519,9 @@ def _set_info_project(self):
1596
1519
project_date_update = last_dict_info ['project_date' ].strftime ('%d-%m-%Y %H:%M:%S' )
1597
1520
if project_date_create == project_date_update :
1598
1521
project_date_update = ''
1599
- msg = (f'Database version: { self .postgresql_version } \n '
1600
- f'PostGis version: { self .postgis_version } \n \n '
1522
+ msg = (f'PostgreSQL version: { self .postgresql_version } \n '
1523
+ f'PostGis version: { self .postgis_version } \n '
1524
+ f'PgRouting version: { self .pgrouting_version } \n \n '
1601
1525
f'Schema name: { schema_name } \n '
1602
1526
f'Version: { self .project_version } \n '
1603
1527
f'EPSG: { self .project_epsg } \n '
@@ -1696,11 +1620,9 @@ def _set_signals_create_project(self):
1696
1620
self .dlg_readsql_create_project .btn_accept .clicked .connect (partial (self .create_project_data_schema ))
1697
1621
self .dlg_readsql_create_project .btn_close .clicked .connect (
1698
1622
partial (self ._close_dialog_admin , self .dlg_readsql_create_project ))
1699
- self .dlg_readsql_create_project .btn_push_file .clicked .connect (partial (self ._select_file_inp ))
1700
1623
self .cmb_create_project_type .currentIndexChanged .connect (
1701
1624
partial (self ._change_project_type , self .cmb_create_project_type ))
1702
1625
self .cmb_locale .currentIndexChanged .connect (partial (self ._update_locale ))
1703
- self .rdb_inp .toggled .connect (partial (self ._enable_datafile ))
1704
1626
self .filter_srid .textChanged .connect (partial (self ._filter_srid_changed ))
1705
1627
1706
1628
@@ -1965,96 +1887,6 @@ def _delete_schema(self):
1965
1887
self ._set_info_project ()
1966
1888
1967
1889
1968
- def _execute_import_inp (self , accepted , project_name , project_type ):
1969
- """"""
1970
-
1971
- if accepted :
1972
-
1973
- self .dlg_import_inp .btn_run .setVisible (False )
1974
-
1975
- # Set wait cursor
1976
- self .task1 = GwTask ('Manage schema' )
1977
- QgsApplication .taskManager ().addTask (self .task1 )
1978
- self .task1 .setProgress (0 )
1979
-
1980
- # Insert inp values into database
1981
- self ._insert_inp_into_db (self .file_inp )
1982
-
1983
- # Get the debugMode. If it's None it will be False
1984
- debug_mode = tools_gw .get_config_parser ('system' , 'import_inp_debug_mode' , "user" , "init" , force_reload = True ) or False
1985
-
1986
- # Execute import data
1987
- if project_type .lower () == 'ws' :
1988
- function_name = 'gw_fct_import_epanet_inp'
1989
- extras = '"parameters":{"debugMode":"' + debug_mode + '"}'
1990
- elif project_type .lower () == 'ud' :
1991
- function_name = 'gw_fct_import_swmm_inp'
1992
- createSubcGeom = self .dlg_import_inp .findChild (QWidget , 'createSubcGeom' )
1993
- extras = '"parameters":{"createSubcGeom":"' + str (createSubcGeom .isChecked ()) + '", "debugMode":"' + debug_mode + '"}'
1994
- else :
1995
- self .error_count = self .error_count + 1
1996
- return
1997
-
1998
- # Set progressBar ON
1999
- self .dlg_import_inp .progressBar .setMaximum (0 )
2000
- self .dlg_import_inp .progressBar .setMinimum (0 )
2001
- self .dlg_import_inp .progressBar .setVisible (True )
2002
- self .dlg_import_inp .progressBar .setFormat ("Running function: " + str (function_name ))
2003
- self .dlg_import_inp .progressBar .setAlignment (Qt .AlignCenter )
2004
- self .dlg_import_inp .progressBar .setFormat ("" )
2005
-
2006
- body = tools_gw .create_body (extras = extras )
2007
- complet_result = tools_gw .execute_procedure (f"{ function_name } " , body , self .schema , commit = False )
2008
-
2009
- self .task1 = GwTask ('Manage schema' )
2010
- QgsApplication .taskManager ().addTask (self .task1 )
2011
- self .task1 .setProgress (50 )
2012
-
2013
- if complet_result :
2014
-
2015
- if complet_result ['status' ] == 'Failed' :
2016
- msg = f'The importation process has failed!'
2017
- replace = complet_result ['body' ]['data' ].get ('replace' )
2018
- if replace is not None :
2019
- msg += f'<br>This can be fixed in the next dialog.'
2020
- msg += f'<br>See Info log for more details.'
2021
- self ._set_log_text (self .dlg_import_inp , complet_result ['body' ]['data' ])
2022
- tools_qt .show_info_box (msg , "Info" )
2023
- if replace is not None :
2024
- retry = self ._build_replace_dlg (replace )
2025
- if retry :
2026
- sql = "DELETE FROM temp_csv WHERE fid = 239;"
2027
- tools_db .execute_sql (sql , commit = False )
2028
- self .dlg_import_inp .mainTab .setTabEnabled (0 , True )
2029
- self .dlg_import_inp .mainTab .setCurrentIndex (0 ) # TODO: this doesnt work for some reason...
2030
- return self ._execute_import_inp (accepted , project_name , project_type )
2031
- tools_db .dao .rollback ()
2032
- self .error_count = 0
2033
-
2034
- # Close dialog
2035
- tools_gw .close_dialog (self .dlg_import_inp )
2036
- tools_gw .close_dialog (self .dlg_readsql_create_project , False )
2037
- return
2038
- self ._set_log_text (self .dlg_import_inp , complet_result ['body' ]['data' ])
2039
- else :
2040
- self .error_count = self .error_count + 1
2041
-
2042
- self .task1 .setProgress (100 )
2043
- # Manage process result
2044
- self .manage_process_result (project_name , project_type , dlg = self .dlg_import_inp )
2045
- else :
2046
- msg = "A rollback on schema will be done."
2047
- tools_qt .show_info_box (msg , "Info" )
2048
- tools_db .dao .rollback ()
2049
- self .error_count = 0
2050
- tools_gw .close_dialog (self .dlg_import_inp )
2051
- return
2052
-
2053
-
2054
- # Hide button execute
2055
- self .dlg_import_inp .btn_run .setVisible (False )
2056
-
2057
-
2058
1890
def _build_replace_dlg (self , replace_json ):
2059
1891
2060
1892
# Build the dialog
@@ -2791,24 +2623,6 @@ def _insert_inp_into_db(self, folder_path=None):
2791
2623
del _file
2792
2624
2793
2625
2794
- def _select_file_inp (self ):
2795
- """ Select INP file """
2796
-
2797
- file_inp = tools_qt .get_text (self .dlg_readsql_create_project , 'data_file' )
2798
- # Set default value if necessary
2799
- if file_inp is None or file_inp == '' :
2800
- file_inp = self .plugin_dir
2801
-
2802
- # Get directory of that file
2803
- folder_path = os .path .dirname (file_inp )
2804
- if not os .path .exists (folder_path ):
2805
- folder_path = os .path .dirname (__file__ )
2806
- os .chdir (folder_path )
2807
- message = tools_qt .tr ("Select INP file" )
2808
- file_inp , filter_ = QFileDialog .getOpenFileName (None , message , "" , '*.inp' )
2809
- self .dlg_readsql_create_project .data_file .setText (file_inp )
2810
-
2811
-
2812
2626
def _populate_functions_dlg (self , dialog , result ):
2813
2627
""""""
2814
2628
0 commit comments