Skip to content

Commit

Permalink
Merge pull request #75 from johodges/dev
Browse files Browse the repository at this point in the history
re-add wind filepath as parameter
  • Loading branch information
johodges committed Aug 9, 2023
2 parents b4b7f3f + 423415c commit 6e72eb4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion qgis2fds_export_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
37 changes: 37 additions & 0 deletions qgis2fds_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6e72eb4

Please sign in to comment.