Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Oct 14, 2024

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
Copy link
Collaborator Author

jmarrec commented Oct 14, 2024

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 jmarrec changed the title Fix #262 #263 - Handle Path Arguments Fix #262 #263 - Handle Path Arguments (QFileDialog) Oct 14, 2024
Comment on lines +610 to +613
// TODO: aside from the fact that these arguments are weird / incorrectly named, neither the BCL-gem schema nor OS SDK actually handle them so
// they are not even inside the measure.xml
bool isRead = argument.get("is_read", Json::Value(false)).asBool();
std::string extension = argument.get("extension", Json::Value("*")).asString();
std::string extension = argument.get("extension", Json::Value("All files (*)")).asString();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default to something sensible for now

filed at NREL/OpenStudio#5273

Comment on lines +504 to +505
} else if (argument.type() == measure::OSArgumentType::Path) {
m_step.setArgument(argument.name(), openstudio::toString(argument.valueAsPath()));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this you, you get valueAsString, and it gets quoted in the workflowJSON as

    "my_path_argument": "\"/the/path/\""

and when you run, Ruby for eg can't understand it.

Comment on lines +429 to +430
// TODO: sanitize the input?
m_extension = toQString(extension);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO here. Basically I think OS SDK should store it as a readable format, and we can reconstruct a proper Qt files Filter from it.

Comment on lines +201 to +227
class PathInputView : public InputView
{
Q_OBJECT

public:
PathInputView(const std::string& extension, bool isRead);
virtual ~PathInputView() = default;

QLineEdit* lineEdit;
QPushButton* selectPathButton;

void setName(const std::string& name, const boost::optional<std::string>& units, const boost::optional<std::string>& description);

void setIncomplete(bool incomplete) override;

void setDisplayValue(const QVariant& value) override;

signals:
void selectedPathChanged(const openstudio::path& p);

private slots:
void onSelectPathButtonClicked();

private:
QLabel* nameLabel;
QString m_extension;
bool m_isRead;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New PathInputView class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot enter path arguments in apply measure now Add file system browse control for measure path arguments
1 participant