OpenStudioApplication icon indicating copy to clipboard operation
OpenStudioApplication copied to clipboard

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

Open jmarrec opened this issue 1 year ago • 1 comments

  • Fix #262
  • Fix #263

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

  • isRead. what does that even mean? Is this assuming that this is for reading meaning it must be 1) a file (not a directory) and 2) it must exist?)
  • extension

path_arguments

jmarrec avatar Oct 14 '24 11:10 jmarrec

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 avatar Oct 14 '24 11:10 jmarrec

@macumber ping

jmarrec avatar Oct 29 '24 21:10 jmarrec

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

macumber avatar Oct 30 '24 02:10 macumber

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

  • https://github.com/NREL/OpenStudio/issues/5273

jmarrec avatar Nov 07 '24 14:11 jmarrec

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

macumber avatar Nov 07 '24 15:11 macumber