From 423415c03dbab0bbe3b3f605a3255042baa10bb7 Mon Sep 17 00:00:00 2001 From: johodges Date: Wed, 9 Aug 2023 15:02:15 -0400 Subject: [PATCH] re-add wind filepath as parameter --- qgis2fds_export_algo.py | 6 +++++- qgis2fds_params.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/qgis2fds_export_algo.py b/qgis2fds_export_algo.py index 78ea4ec..7b890de 100644 --- a/qgis2fds_export_algo.py +++ b/qgis2fds_export_algo.py @@ -64,6 +64,7 @@ def initAlgorithm(self, config=None): ExportOBSTParam.set(**kwargs) StartTimeParam.set(**kwargs) EndTimeParam.set(**kwargs) + wind_filepath = WindFilepathParam.set(**kwargs) # Define destination layers @@ -136,6 +137,9 @@ def processAlgorithm(self, parameters, context, model_feedback): export_obst = ExportOBSTParam.get(**kwargs) t_begin = StartTimeParam.get(**kwargs) t_end = EndTimeParam.get(**kwargs) + wind_filepath = WindFilepathParam.get(**kwargs) + + # Check parameter values @@ -428,7 +432,7 @@ def processAlgorithm(self, parameters, context, model_feedback): ) # Add empty wind - wind = Wind(feedback=feedback, project_path=fds_path, filepath="") + wind = Wind(feedback=feedback, project_path=fds_path, filepath=wind_filepath) # Prepare terrain, domain, fds_case diff --git a/qgis2fds_params.py b/qgis2fds_params.py index 3c5a3f0..9fd36be 100644 --- a/qgis2fds_params.py +++ b/qgis2fds_params.py @@ -524,3 +524,40 @@ def get(cls, algo, parameters, context, feedback, project): project.writeEntry("qgis2fds", cls.label, value) feedback.setProgressText(f"{cls.desc}: <{value}>") return value + +class WindFilepathParam: + label = "wind_filepath" + desc = "Wind text file" + default = "" + optional = True + + @classmethod + def set(cls, algo, config, project): + defaultValue, _ = project.readEntry("qgis2fds", cls.label, cls.default) + param = QgsProcessingParameterFile( + cls.label, + cls.desc, + defaultValue=defaultValue, + optional=cls.optional, + behavior=QgsProcessingParameterFile.File, + # fileFilter="TXT files (*.txt)", + ) + param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) + algo.addParameter(param) + + @classmethod + def get(cls, algo, parameters, context, feedback, project): + value = None + if parameters.get(cls.label): + value = algo.parameterAsFile(parameters, cls.label, context) + project.writeEntry("qgis2fds", cls.label, value or "") # protect + if value: + # Make and check absolute path + project_path = project.absolutePath() + if not project_path: + raise QgsProcessingException( + "Save QGIS project to disk, cannot proceed." + ) + value = os.path.join(project_path, value) + feedback.setProgressText(f"{cls.desc}: <{value}>") + return value