52 UserInterface::UserInterface(
const QString &xmlfile,
int &argc,
65 FileName setup =
"$HOME/.Isis/history";
68 setup.
dir().mkpath(
".");
81 p_gui = Gui::Create(*
this, argc, argv);
135 for (
unsigned int currArgument = 1; currArgument <
p_cmdline.size(); currArgument ++) {
137 vector<QString> paramValue;
143 if (paramName[0] ==
'-')
146 for (
unsigned int value = 0; value < paramValue.size(); value++) {
147 IString thisValue = paramValue[value];
148 QString token = thisValue.
Token(
"$").
ToQt();
152 while (thisValue !=
"") {
155 int j =
toInt( thisValue.substr(0, 1).c_str() ) - 1;
157 thisValue.replace(0, 1,
"");
170 paramValue[value] = newValue;
182 if(paramValue.size() == 1) {
183 cout <<
"=" << paramValue[0] <<
" ";
185 else if (paramValue.size() > 1) {
188 for (
unsigned int value = 0; value < paramValue.size(); value++) {
192 cout << paramValue[value] << endl;
219 os.open(fileName.toLatin1().data(), std::ios::app);
223 QString msg =
"Unable to create error list [" +
p_errList 224 +
"] Disk may be full or directory permissions not writeable";
228 for (
int j = 0; j < (int)
p_batchList[i].size(); j++) {
247 if (grp[
"HistoryRecording"][0] ==
"Off")
278 while( hist.
groups() >
toInt(grp[
"HistoryLength"][0]) ) {
311 QString msg =
"The batchlist file [" + file +
"] could not be opened";
317 for (
int i = 0; i < temp.
LineCount(); i++) {
334 foreach (QString token, tokens) {
336 token = token.remove( QRegExp(
"[\"']") );
346 QString msg =
"The number of columns must be constant in batchlist";
352 QString msg =
"The list file [" + file +
"] does not contain any data";
379 if ( (argc == 1) && (file.
name() !=
"unitTest") ) {
384 for (
int i = 0; i < argc; i++) {
389 vector<QString> options;
390 options.push_back(
"-GUI");
391 options.push_back(
"-NOGUI");
392 options.push_back(
"-BATCHLIST");
393 options.push_back(
"-LAST");
394 options.push_back(
"-RESTORE");
395 options.push_back(
"-WEBHELP");
396 options.push_back(
"-HELP");
397 options.push_back(
"-ERRLIST");
398 options.push_back(
"-ONERROR");
399 options.push_back(
"-SAVE");
400 options.push_back(
"-INFO");
401 options.push_back(
"-PREFERENCE");
402 options.push_back(
"-LOG");
403 options.push_back(
"-VERBOSE");
404 options.push_back(
"-PID");
406 bool usedDashLast =
false;
407 bool usedDashRestore =
false;
416 for (
unsigned int currArgument = 1; currArgument < (unsigned)argc; currArgument++) {
418 vector<QString> paramValue;
423 if (paramName[0] ==
'-') {
424 paramName = paramName.toUpper();
428 if (paramValue.size() > 1) {
429 QString msg =
"Invalid value for reserve parameter [" 439 if (paramName ==
"-LAST") {
446 if (paramName ==
"-RESTORE") {
447 usedDashRestore =
true;
451 QString realValue =
"";
453 if ( paramValue.size() ) {
454 realValue = paramValue[0];
472 || usedDashRestore) ) {
473 QString msg =
"-BATCHLIST cannot be used with -GUI, -SAVE, -RESTORE, ";
480 QString msg =
"-ERRLIST and -ONERROR=continue cannot be used without ";
481 msg +=
" the -BATCHLIST option";
505 if (g >= 0 && lab.group(g).isNamed(
"UserParameters") ) {
508 for (
int k = 0; k < up.
keywords(); k++) {
509 QString keyword = up[k].
name();
511 vector<QString> values;
513 for (
int i = 0; i < up[k].size(); i++) {
514 values.push_back(up[k][i]);
519 bool matchesDefault =
false;
520 if (values.size() == 1 && paramData->internalDefault == values[0])
521 matchesDefault =
true;
523 if (!matchesDefault) {
525 (values.size() == paramData->defaultValues.size());
527 for (
int i = 0; matchesDefault && i < (int)values.size(); i++) {
528 matchesDefault = matchesDefault &&
529 values[i] == paramData->defaultValues[i];
533 if (!matchesDefault) {
535 commandline += keyword +
"=";
536 foreach(QString val, values) {
537 commandline += val +
" ";
541 std::cout << commandline << std::endl;
545 for (
int o = lab.objects() - 1; o >= 0; o--) {
548 for (
int g = obj.
groups() - 1; g >= 0; g--) {
550 if ( up.
isNamed(
"UserParameters") ) {
551 for (
int k = 0; k < up.
keywords(); k++) {
552 QString keyword = up[k].
name();
553 QString value = up[k][0];
567 QString msg =
"The history file [" + file +
"] is for a different application or corrupt, "\
568 "please fix or delete this file";
573 QString msg =
"The history file [" + file +
"] does not exist";
594 const QString value) {
596 bool unitTest =
false;
602 if (name ==
"-GUI") {
605 else if (name ==
"-NOGUI") {
608 else if (name ==
"-BATCHLIST") {
611 else if (name ==
"-LAST") {
624 else if(name ==
"-RESTORE") {
627 else if(name ==
"-WEBHELP") {
629 QString command = pref[
"GuiHelpBrowser"];
630 command +=
" $ISISROOT/doc/Application/presentation/Tabbed/";
635 "Evaluating -WEBHELP should only throw this exception during a unitTest",
644 else if (name ==
"-INFO") {
648 if (value.size() != 0) {
652 else if (name ==
"-HELP") {
653 if (value.size() == 0) {
796 "Evaluating -HELP should only throw this exception during a unitTest",
804 else if (name ==
"-PID") {
807 else if (name ==
"-ERRLIST") {
811 QString msg =
"-ERRLIST expects a file name";
819 else if (name ==
"-ONERROR") {
820 if (value.toUpper() ==
"CONTINUE") {
824 else if (value.toUpper() ==
"ABORT") {
829 QString msg =
"[" + value
830 +
"] is an invalid value for -ONERROR, options are ABORT or CONTINUE";
834 else if (name ==
"-SAVE") {
835 if (value.size() == 0) {
842 else if (name ==
"-PREFERENCE") {
845 else if (name ==
"-LOG") {
846 if( value.isEmpty() ) {
847 p.
findGroup(
"SessionLog")[
"FileOutput"].setValue(
"On");
850 p.
findGroup(
"SessionLog")[
"FileOutput"].setValue(
"On");
851 p.
findGroup(
"SessionLog")[
"FileName"].setValue(value);
855 else if (name ==
"-VERBOSE") {
856 p.
findGroup(
"SessionLog")[
"TerminalOutput"].setValue(
"On");
861 QString msg =
"-GUI and -PID are incompatible arguments";
880 std::vector<QString> &value) {
882 QString paramValue =
"";
887 if ( !paramName.contains(
"=") ) {
892 if (QString(
p_cmdline[curPos + 1]).compare(
"=") == 0) {
901 else if ( paramName.endsWith(
"=") ) {
902 paramName = paramName.mid(0, paramName.size() - 1);
912 else if (paramName.indexOf(
"=") > 0) {
913 QString parameterLiteral =
p_cmdline[curPos];
914 paramName = parameterLiteral.mid( 0, parameterLiteral.indexOf(
"=") );
915 paramValue = parameterLiteral.mid(parameterLiteral.indexOf(
"=") + 1);
920 QString msg =
"Unknown parameter [" + QString(
p_cmdline[curPos])
929 paramValue = paramValue.trimmed();
931 if (paramValue.length() > 0 && paramValue[0] !=
'(') {
936 if (paramValue.length() > 1 && paramValue.mid(0, 2) ==
"\\(") {
937 paramValue = paramValue.mid(1);
940 else if (paramValue.length() > 2 && paramValue.mid(0, 3) ==
"\\\\(") {
941 paramValue = paramValue.mid(1);
944 value.push_back(paramValue);
946 else if ( paramValue.length() ) {
966 std::vector<QString> &reservedParams) {
967 for (
unsigned int currArgument = 1; currArgument < (unsigned)
p_cmdline.size();
970 QString paramName =
p_cmdline[currArgument];
971 QString trueParamValue =
"";
972 vector<QString> paramValue;
975 if (paramName[0] ==
'-') {
979 paramName = paramName.toUpper();
982 if ( paramValue.size() ) {
983 trueParamValue = paramValue[0].toUpper();
990 if (fullReservedName == paramName) {
1012 std::vector<QString> values;
1014 bool inDoubleQuotes =
false;
1015 bool inSingleQuotes =
false;
1016 bool arrayClosed =
false;
1017 bool nextElementStarted =
false;
1018 QString currElement =
"";
1020 for (
int strPos = 0; strPos < arrayString.size(); strPos++) {
1022 if (arrayString[strPos] !=
'(') {
1023 QString msg =
"Invalid array format [" + arrayString +
"]";
1031 if ( arrayString[strPos] ==
'\\' && strPos + 1 < (
int)arrayString.size() ) {
1032 currElement += arrayString[strPos+1];
1037 else if (arrayString[strPos] ==
'\\') {
1038 QString msg =
"Invalid array format [" + arrayString +
"]";
1043 if (!inDoubleQuotes && !inSingleQuotes) {
1045 QString msg =
"Invalid array format [" + arrayString +
"]";
1049 nextElementStarted = (nextElementStarted || arrayString[strPos] !=
' ');
1051 if (!nextElementStarted) {
1055 if (arrayString[strPos] ==
'"') {
1056 inDoubleQuotes =
true;
1058 else if (arrayString[strPos] ==
'\'') {
1059 inSingleQuotes =
true;
1061 else if (arrayString[strPos] ==
',') {
1062 values.push_back(currElement);
1064 nextElementStarted =
false;
1066 else if (arrayString[strPos] ==
')') {
1067 values.push_back(currElement);
1070 nextElementStarted =
false;
1072 else if (nextElementStarted && arrayString[strPos] ==
' ') {
1074 bool onlyWhite =
true;
1075 int closingPos = strPos + 1;
1077 for(
int pos = strPos;
1078 onlyWhite && arrayString[pos] !=
',' && arrayString[pos] !=
')' &&
1079 pos < arrayString.size(); pos++) {
1081 onlyWhite &= (arrayString[pos] ==
' ');
1085 currElement += arrayString[strPos];
1088 else if (nextElementStarted) {
1089 currElement += arrayString[strPos];
1092 else if (inSingleQuotes) {
1093 if(arrayString[strPos] ==
'\'') {
1094 inSingleQuotes =
false;
1097 currElement += arrayString[strPos];
1102 if (arrayString[strPos] ==
'"') {
1103 inDoubleQuotes =
false;
1106 currElement += arrayString[strPos];
1111 if (!arrayClosed || currElement !=
"") {
1112 QString msg =
"Invalid array format [" + arrayString +
"]";
1139 std::vector<QString> &reservedParams,
1140 bool handleNoMatches) {
1142 int matchOption = -1;
1144 for (
int option = 0; option < (int)reservedParams.size(); option++) {
1147 if ( reservedParams[option].startsWith(unresolvedParam) ) {
1148 if (matchOption >= 0) {
1149 QString msg =
"Ambiguous Reserve Parameter [" 1150 + unresolvedParam +
"]. Please clarify.";
1154 matchOption = option;
1158 if (handleNoMatches) {
1160 if (matchOption < 0) {
1161 QString msg =
"Invalid Reserve Parameter Option [" 1162 + unresolvedParam +
"]. Choices are ";
1165 for (
int option = 0; option < (int)reservedParams.size(); option++) {
1167 if (reservedParams[option].compare(
"-PID") == 0) {
1171 msgOptions += reservedParams[option];
1184 msg +=
" [" + msgOptions +
"]";
1189 if (matchOption < 0) {
1193 return reservedParams[matchOption];
PvlObject & object(const int index)
Return the object at the specified index.
int NumParams(const int &) const
Returns the number of parameters in a group.
QString ParamListBrief(const int &group, const int ¶m, const int &option) const
Returns the brief description for a specific option to a parameter.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
int ParamLessThanOrEqualSize(const int &group, const int ¶m) const
Returns the number of values in the parameters less than or equal list.
QString ProgramName() const
Returns the Program name.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
File name manipulation and expansion.
int NumGroups() const
Returns the number of groups found in the XML.
QString resolveParameter(QString &name, std::vector< QString > &reservedParams, bool handleNoMatches=true)
This resolves a reserved parameter token on the command line to its fullname.
int ParamListSize(const int &group, const int ¶m) const
Returns the number of options in the specified parameter's list.
static void checkX11()
check to see if X is available
void Open(const QString &filename, const char *openmode="input", const char *extension="")
Opens a text file.
void loadHistory(const QString file)
Loads the previous history for the program.
int ParamGreaterThanSize(const int &group, const int ¶m) const
Returns the number of values in the parameters greater than list.
int ParamListExcludeSize(const int &group, const int ¶m, const int &option) const
Returns the number of items in a parameters list exclude section.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
int toInt(const QString &string)
Global function to convert from a string to an integer.
Namespace for the standard library.
QString ParamMaximum(const int &group, const int ¶m) const
Returns the maximum value of a parameter in a specified group.
void PutAsString(const QString ¶mName, const QString &value)
Allows the insertion of a value for any parameter.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
int BatchListSize()
Returns the size of the batchlist.
int p_parentId
This is a status to indicate if the GUI is running or not.
Gui * p_gui
Pointer to the gui object.
QString GetInfoFileName()
This method returns the filename where the debugging info is stored when the "-info" tag is used...
This error is for when a programmer made an API call that was illegal.
QString p_saveFile
FileName to save last history to.
int ParamIncludeSize(const int &group, const int ¶m) const
Returns the number of parameters included in this parameter's inclusions.
std::vector< char * > p_cmdline
This variable will contain argv.
void deleteGroup(const QString &name)
Remove a group from the current PvlObject.
const IsisParameterData * ReturnParam(const QString ¶mName) const
Returns a pointer to a parameter whose name starts with paramName.
QString ParamType(const int &group, const int ¶m) const
Returns the parameter type of a parameter in a specified group.
int ParamListIncludeSize(const int &group, const int ¶m, const int &option) const
Returns the number of items in a parameters list include section.
void SaveHistory()
Saves the user parameter information in the history of the program for later use. ...
QString ParamInternalDefault(const int &group, const int ¶m) const
Returns the internal default for a parameter in a specified group.
QString name() const
Returns the container name.
QString PixelType(const int &group, const int ¶m) const
Returns the default pixel type from the XML.
void setTerminator(const QString &term)
Sets the terminator used to signify the end of the PVL informationDefaults to "END".
static void RunSystemCommand(QString commandLine)
This runs arbitrary system commands.
QString ParamListExclude(const int &group, const int ¶m, const int &option, const int &exclude) const
Returns the parameter name to be excluded if this option is selected.
QString ParamGreaterThanOrEqual(const int &group, const int ¶m, const int &great) const
Returns the name of the specified greaterThanOrEqual parameter.
QString ParamNotEqual(const int &group, const int ¶m, const int ¬Eq) const
Returns the name of the specified notEqual parameter.
QString ParamOdd(const int &group, const int ¶m) const
Returns whether the selected parameter has a restriction on odd values or not.
IString Compress(bool force=false)
Collapses multiple spaces into single spaces.
IString Token(const IString &separator)
Returns the first token in the IString.
QString ParamListInclude(const int &group, const int ¶m, const int &option, const int &include) const
Returns the parameter name to be included if this option is selected.
Contains multiple PvlContainers.
void evaluateOption(const QString name, const QString value)
This interprets the "-" options for reserved parameters.
#define _FILEINFO_
Macro for the filename and line number.
A type of error that could only have occurred due to a mistake on the user's part (e...
A single keyword-value pair.
QString p_infoFileName
FileName to save debugging info.
void loadBatchList(const QString file)
Loads the user entered batchlist file into a private variable for later use.
A type of error that cannot be classified as any of the other error types.
QString ToQt() const
Retuns the object string as a QString.
int LineCount(const int &maxLinesToRead=0)
Counts number of lines in file.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
bool GetLine(QString &line, const bool skipComments=true)
Gets next line from file.
int ParamLessThanSize(const int &group, const int ¶m) const
Returns the number of values in the parameters less than list.
bool GetInfoFlag()
This method returns the flag state of info.
void Clear(const QString ¶mName)
Clears the value(s) in the named parameter.
QDir dir() const
Returns the path of the file's parent directory as a QDir object.
std::vector< std::vector< QString > > p_batchList
Vector of batchlist data.
void CommandLine(Isis::Pvl &lab) const
Creates a QString which could be used as a command line.
Container for cube-like labels.
~UserInterface()
Destroys the UserInterface object.
bool p_interactive
Boolean value representing whether the program is interactive or not.
QString ParamMaximumInclusive(const int &group, const int ¶m) const
Returns whether the maximum value is inclusive or not.
QString ParamMinimum(const int &group, const int ¶m) const
Returns the minimum value of a parameter in a specified group.
void loadCommandLine(int argc, char *argv[])
This is used to load the command line into p_cmdline and the Aml object using information contained i...
QString p_progName
Name of program to run.
Application program XML file parameter manager.
bool isNamed(const QString &match) const
Returns whether the given string is equal to the container name or not.
QString p_errList
FileName to write batchlist line that caused error on.
Provides access to sequential ASCII stream I/O.
int ParamExcludeSize(const int &group, const int ¶m) const
Returns the number of parameters excluded in this parameter's exclusions.
PvlGroup & group(const int index)
Return the group at the specified index.
int ParamGreaterThanOrEqualSize(const int &group, const int ¶m) const
Returns the number of values in the parameters greater than or equal list.
IString Replace(const std::string &from, const std::string &to, int maxReplaceCount=20)
Replaces all instances of the first input string with the second input string.
Adds specific functionality to C++ strings.
Namespace for ISIS/Bullet specific routines.
void VerifyAll()
Verify all parameters.
bool p_info
Boolean value representing if it's in debug mode.
QString ParamDefault(const int &group, const int ¶m) const
Returns the default for a parameter in a specified group.
int groups() const
Returns the number of groups contained.
std::vector< QString > readArray(QString arrayString)
This interprets an array value from the command line.
QString ParamLessThanOrEqual(const int &group, const int ¶m, const int &les) const
Returns the name of the specified lessThanOrEqual parameter.
void SetBatchList(int i)
Clears the gui parameters and sets the batch list information at line i as the new parameters...
void write(const QString &file)
Opens and writes PVL information to a file and handles the end of line sequence.
QString ParamMinimumInclusive(const int &group, const int ¶m) const
Returns whether the minimum value is inclusive or not.
QString ParamBrief(const int &group, const int ¶m) const
Returns the brief description of a parameter in a specified group.
void SetErrorList(int i)
This method adds the line specified in the BatchList that the error occured on.
QString ParamGreaterThan(const int &group, const int ¶m, const int &great) const
Returns the name of the specified greaterThan parameter.
Contains Pvl Groups and Pvl Objects.
QString ParamName(const int &group, const int ¶m) const
Returns the parameter name.
void read(const QString &file)
Loads PVL information from a stream.
void getNextParameter(unsigned int &curPos, QString &unresolvedParam, std::vector< QString > &value)
This gets the next parameter in the list of arguments.
QString ParamLessThan(const int &group, const int ¶m, const int &great) const
Returns the name of the specified lessThan parameter.
QString ParamListValue(const int &group, const int ¶m, const int &option) const
Returns the option value for a specific option to a parameter.
QString ParamExclude(const int &group, const int ¶m, const int &exclude) const
Returns the name of the specified excluded parameter.
bool fileExists() const
Returns true if the file exists; false otherwise.
void preProcess(QString fullReservedName, std::vector< QString > &reservedParams)
This parses the command line and looks for the specified reserved parameter name passed.
bool p_abortOnError
Boolean value representing whether to abort or continue on error.
int ParamNotEqualSize(const int &group, const int ¶m) const
Returns the number of values in the not equal list.
Reads user preferences from a data file.
QString ParamInclude(const int &group, const int ¶m, const int &include) const
Returns the name of the specified included parameter.
void addValue(QString value, QString unit="")
Adds a value with units.