openstudiocoalition / OpenStudioApplication

The OpenStudio Application is a fully featured graphical interface to OpenStudio models including envelope, loads, schedules, and HVAC.
https://openstudiocoalition.org
Other
136 stars 25 forks source link

Fix #262 #263 - Handle Path Arguments (QFileDialog) #761

Closed jmarrec closed 2 weeks ago

jmarrec commented 1 month ago

The OS SDK / BCL-gem implementation of the path arguments is incomplete and confusing, and they don't handle the makePathArgument arguments:

path_arguments

jmarrec commented 1 month ago

here is my test measure

example_path_argument.zip

  # define the arguments that the user will input
  def arguments(model)
    args = OpenStudio::Measure::OSArgumentVector.new

    isRead = false
    extension = "CSV (*.csv);;Excel (*.xls *.xlsx);;All Files (*)"
    required = true
    modelDependent = false
    output_path = OpenStudio::Measure::OSArgument.makePathArgument('output_path', isRead, extension, required, modelDependent)
    output_path.setDisplayName('Output Path on Disk')
    args << output_path

    return args
  end

  # define what happens when the measure is run
  def run(model, runner, user_arguments)
    super(model, runner, user_arguments)  # Do **NOT** remove this line

    # use the built-in error checking
    if !runner.validateUserArguments(arguments(model), user_arguments)
      return false
    end

    # assign the user inputs to variables
    output_path = runner.getPathArgumentValue('output_path', user_arguments)

    puts "output_path=#{output_path}"

    File.write(output_path.to_s, "hello")

    # report final condition of model
    runner.registerFinalCondition("The output path is #{output_path}")

    return true
  end
jmarrec commented 3 weeks ago

@macumber ping

macumber commented 3 weeks ago

This is cool @jmarrec, I added some comments, maybe it is worth adding some new attributes if you are already updating the SDK?

jmarrec commented 2 weeks ago

@macumber until #5273 is addressed, I'd say we just merge this. Does that work for you?

macumber commented 2 weeks ago

This looks good to me @jmarrec, I'm fine if you want to merge this now before https://github.com/NREL/OpenStudio/issues/5273 is complete