33 #include <tclap/CmdLine.h>
34 #include <tclap/SwitchArg.h>
35 #include <tclap/ValueArg.h>
36 #include <tclap/ValuesConstraint.h>
37 #include <QApplication>
50 using namespace TCLAP;
56 int simPTCLIMode::operator()(
int argc,
char** argv)
58 int exit_status = EXIT_SUCCESS;
62 QCoreApplication app(argc, argv,
false);
63 qRegisterMetaType<std::string>(
"std::string");
66 CmdLine cmd(
"simPT_sim",
' ',
"1.0");
67 SwitchArg rev_Arg(
"r",
"revision",
"Revision identification", cmd,
false);
68 SwitchArg quiet_Arg(
"q",
"quiet",
"Quit mode (no output)", cmd,
false);
69 ValueArg<unsigned int> num_steps_Arg(
"s",
"stepcount",
"number of steps",
false, 0,
"NUMBER OF STEPS", cmd);
70 ValueArg<string> file_Arg(
"f",
"file",
"Tissue file in project",
false,
"",
"TISSUE FILE", cmd);
71 ValueArg<string> project_Arg(
"p",
"project",
"Name of project",
false,
"unnamed",
"PROJECT NAME", cmd);
72 ValueArg<string> workspace_Arg(
"w",
"workspace",
"Path to workspace",
false,
"simPT_Default_workspace",
"WORKSPACE PATH", cmd);
74 vector<string> convert_output_formats;
75 for (
auto f : FileConverterFormats::GetFormats()) {
76 if (!f->IsPostProcessFormat())
77 convert_output_formats.push_back(f->GetName());
80 vector<string> postprocess_output_formats;
81 for (
auto f : FileConverterFormats::GetFormats()) {
82 if (f->IsPostProcessFormat())
83 postprocess_output_formats.push_back(f->GetName());
86 ValueArg<string> timestep_filter_Arg(
"t",
"timestep-filter",
87 "Filter timesteps to convert, (list of) ranges are accepted, e.g. \"200-300,600\".",
false, {},
"", cmd);
89 ValuesConstraint<string> allowedConvertFormats(convert_output_formats);
90 ValueArg<string> convert_Arg(
"c",
"convert",
91 "Convert mode (no simulation): Convert existing files in workspace.",
92 false,
"xml", &allowedConvertFormats, cmd);
94 ValuesConstraint<string> allowedPostprocessFormats(postprocess_output_formats);
95 ValueArg<string> postprocess_Arg(
"o",
"postprocess",
96 "Postprocess mode (no simulation): Postprocess existing files in workspace.",
97 false,
"png", &allowedPostprocessFormats, cmd);
99 ValuesConstraint<string> allowedInputFormats(convert_output_formats);
100 ValueArg<string> input_format_Arg(
"z",
"input-format-filter",
101 "Only use a specific input format",
false,
"", &allowedInputFormats, cmd);
103 cmd.parse(argc, argv);
105 if (rev_Arg.isSet()) {
106 cout << RevisionInfo::CompoundId() << endl;
109 if (workspace_Arg.isSet()) {
112 cout <<
"Executing: " << argv[0]<< endl;
113 cout <<
"Revision: " << RevisionInfo::CompoundId() << endl;
116 const bool quiet = quiet_Arg.getValue();
117 const string workspace_path = workspace_Arg.getValue();
118 const string project_name = project_Arg.getValue();
123 if (convert_Arg.isSet() || postprocess_Arg.isSet()) {
124 const string timestep_filter = timestep_filter_Arg.getValue();
125 const string output_format_str = convert_Arg.isSet() ? convert_Arg.getValue() : postprocess_Arg.getValue();
126 const string input_format_filter = input_format_Arg.isSet() ? input_format_Arg.getValue() :
"";
129 for (
auto f : FileConverterFormats::GetFormats()) {
130 if (output_format_str == f->GetName()) {
134 if (output_format ==
nullptr) {
135 throw Exception(
"Convert mode selected but no output format given!");
139 CliConverterTask task(project_name, timestep_filter, output_format, input_format_filter);
140 exit_status = c->Execute(task);
142 const unsigned int num_steps = num_steps_Arg.getValue();
143 const bool num_steps_set = num_steps_Arg.isSet();
144 const string file = file_Arg.getValue();
145 const bool file_set = file_Arg.isSet();
149 exit_status = c->Execute(task);
151 if (exit_status == EXIT_SUCCESS) {
152 cout << endl << c->GetTimings() << endl << endl;
161 catch (exception& e) {
162 exit_status = EXIT_FAILURE;
163 cerr << e.what() << endl;
166 exit_status = EXIT_FAILURE;
167 cerr <<
"Unknown exception." << endl;
Interface for CliController.
Interface for ClockTraits.
A CliConverterTask represents an invocation of the converter from the command line.
Info on git revision and commit date.
Namespace for miscellaneous utilities.
Interface/Implementation for CliTask.
Interface for CumulativeRecords.
Namespace for SimPT shell package.
Namespace for startup modes for simPT tools.
static std::shared_ptr< CliController > Create(const std::string &workspace, bool quiet)
Create controller.
Extremely simple Exception root class.
Interface for IConverterFormat.
Interface for file convenvereter formats.
Interface of file converter formats.
Namespace for SimPT specific session classes.
Provides wall-clock time stamp using the time call.
Interface/Implementation for CliConverterTask.
Header file for Exception class.
std::string ToString() const
Returns string with the time stamp after eliminating newline.
A CliTask represents an invocation of the program from the command line.
Namespace for clock and timekeeping related classes.
Interface/Implementation for the exec modes.