6#include
"UserInterface.h"
13#include "Application.h"
16#include "IException.h"
19#include "Preference.h"
20#include "ProgramLauncher.h"
47 FileName setup =
"$HOME/.Isis/history";
49 if ( !setup.fileExists() ) {
50 setup.
dir().mkpath(
".");
84 FileName setup =
"$HOME/.Isis/history";
86 if ( !setup.fileExists() ) {
87 setup.
dir().mkpath(
".");
100 p_gui = Gui::Create(*
this, argc, argv);
155 for (
unsigned int currArgument = 1; currArgument <
p_cmdline.size(); currArgument ++) {
157 vector<QString> paramValue;
163 if (paramName[0] ==
'-')
166 for (
unsigned int value = 0; value < paramValue.size(); value++) {
167 IString thisValue = paramValue[value];
168 QString token = thisValue.
Token(
"$").
ToQt();
172 while (thisValue !=
"") {
175 int j =
toInt( thisValue.substr(0, 1).c_str() ) - 1;
177 thisValue.replace(0, 1,
"");
178 token = thisValue.Token(
"$").ToQt();
183 token = thisValue.Token(
"$").ToQt();
190 paramValue[value] = newValue;
202 if(paramValue.size() == 1) {
203 cout <<
"=" << paramValue[0] <<
" ";
205 else if (paramValue.size() > 1) {
208 for (
unsigned int value = 0; value < paramValue.size(); value++) {
212 cout << paramValue[value] << endl;
239 os.open(fileName.toLatin1().data(), std::ios::app);
243 QString msg =
"Unable to create error list [" +
p_errList
244 +
"] Disk may be full or directory permissions not writeable";
248 for (
int j = 0; j < (int)
p_batchList[i].size(); j++) {
267 if (grp[
"HistoryRecording"][0] ==
"Off")
287 if ( histFile.fileExists() ) {
288 hist.
read( histFile.expanded() );
295 hist.addGroup( cmdLine.findGroup(
"UserParameters") );
298 while( hist.groups() >
toInt(grp[
"HistoryLength"][0]) ) {
299 hist.deleteGroup(
"UserParameters");
304 hist.write( histFile.expanded() );
330 QString msg =
"The batchlist file [" + file +
"] could not be opened";
336 for (
int i = 0; i < temp.LineCount(); i++) {
353 foreach (QString token, tokens) {
355 token = token.remove( QRegExp(
"[\"']") );
365 QString msg =
"The number of columns must be constant in batchlist";
371 QString msg =
"The list file [" + file +
"] does not contain any data";
395 args.prepend(
"someapp");
398 c_args = (
char**)malloc(
sizeof(
char*)*args.size());
400 for (
int i = 0; i < args.size(); i++) {
401 c_args[i] = (
char*)malloc(
sizeof(
char)*args[i].size()+1);
402 strcpy(c_args[i], args[i].toLatin1().data());
430 if ( (argc == 1) && (file.name() !=
"unitTest") ) {
435 for (
int i = 0; i < argc; i++) {
440 vector<QString> options;
441 options.push_back(
"-GUI");
442 options.push_back(
"-NOGUI");
443 options.push_back(
"-BATCHLIST");
444 options.push_back(
"-LAST");
445 options.push_back(
"-RESTORE");
446 options.push_back(
"-WEBHELP");
447 options.push_back(
"-HELP");
448 options.push_back(
"-ERRLIST");
449 options.push_back(
"-ONERROR");
450 options.push_back(
"-SAVE");
451 options.push_back(
"-INFO");
452 options.push_back(
"-PREFERENCE");
453 options.push_back(
"-LOG");
454 options.push_back(
"-VERBOSE");
455 options.push_back(
"-PID");
457 bool usedDashLast =
false;
458 bool usedDashRestore =
false;
467 for (
unsigned int currArgument = 1; currArgument < (unsigned)argc; currArgument++) {
469 vector<QString> paramValue;
474 if (paramName[0] ==
'-') {
475 paramName = paramName.toUpper();
479 if (paramValue.size() > 1) {
480 QString msg =
"Invalid value for reserve parameter ["
492 if (paramName ==
"-LAST") {
499 if (paramName ==
"-RESTORE") {
500 usedDashRestore =
true;
504 QString realValue =
"";
506 if ( paramValue.size() ) {
507 realValue = paramValue[0];
527 cout << BuildNewCommandLineFromPvl(temp) << endl;
532 || usedDashRestore) ) {
533 QString msg =
"-BATCHLIST cannot be used with -GUI, -SAVE, -RESTORE, ";
540 QString msg =
"-ERRLIST and -ONERROR=continue cannot be used without ";
541 msg +=
" the -BATCHLIST option";
546 QString UserInterface::BuildNewCommandLineFromPvl(
Pvl temp){
551 for(
int i = 0; i < numKeywords; i++){
553 returnVal += key.
name();
555 returnVal += QString(key);
573 if ( hist.fileExists() ) {
577 int g = lab.groups() - 1;
578 if (g >= 0 && lab.group(g).isNamed(
"UserParameters") ) {
581 for (
int k = 0; k < up.keywords(); k++) {
582 QString keyword = up[k].name();
584 vector<QString> values;
586 for (
int i = 0; i < up[k].size(); i++) {
587 values.push_back(up[k][i]);
592 bool matchesDefault =
false;
593 if (values.size() == 1 && paramData->internalDefault == values[0])
594 matchesDefault =
true;
596 if (!matchesDefault) {
598 (values.size() == paramData->defaultValues.size());
600 for (
int i = 0; matchesDefault && i < (int)values.size(); i++) {
601 matchesDefault = matchesDefault &&
602 values[i] == paramData->defaultValues[i];
606 if (!matchesDefault) {
608 commandline += keyword +
"=";
609 foreach(QString val, values) {
610 commandline += val +
" ";
618 for (
int o = lab.objects() - 1; o >= 0; o--) {
621 for (
int g = obj.groups() - 1; g >= 0; g--) {
623 if ( up.isNamed(
"UserParameters") ) {
624 for (
int k = 0; k < up.keywords(); k++) {
625 QString keyword = up[k].
name();
626 QString value = up[k][0];
640 QString msg =
"The history file [" + file +
"] is for a different application or corrupt, "\
641 "please fix or delete this file";
646 QString msg =
"The history file [" + file +
"] does not exist";
670 const QString value) {
672 bool unitTest =
false;
678 if (name ==
"-GUI") {
681 else if (name ==
"-NOGUI") {
684 else if (name ==
"-BATCHLIST") {
687 else if (name ==
"-LAST") {
700 else if(name ==
"-RESTORE") {
703 else if(name ==
"-WEBHELP") {
704 Isis::PvlGroup &pref = Isis::Preference::Preferences().findGroup(
"UserInterface");
705 QString command = pref[
"GuiHelpBrowser"];
706 command +=
" $ISISROOT/docs/Application/presentation/Tabbed/";
711 "Evaluating -WEBHELP should only throw this exception during a unitTest",
720 else if (name ==
"-INFO") {
724 if (value.size() != 0) {
728 else if (name ==
"-HELP") {
729 if (value.size() == 0) {
872 "Evaluating -HELP should only throw this exception during a unitTest",
880 else if (name ==
"-PID") {
883 else if (name ==
"-ERRLIST") {
887 QString msg =
"-ERRLIST expects a file name";
895 else if (name ==
"-ONERROR") {
896 if (value.toUpper() ==
"CONTINUE") {
900 else if (value.toUpper() ==
"ABORT") {
905 QString msg =
"[" + value
906 +
"] is an invalid value for -ONERROR, options are ABORT or CONTINUE";
910 else if (name ==
"-SAVE") {
911 if (value.size() == 0) {
918 else if (name ==
"-PREFERENCE") {
920 p_preference = value;
922 else if (name ==
"-LOG") {
923 if( value.isEmpty() ) {
924 p.findGroup(
"SessionLog")[
"FileOutput"].setValue(
"On");
927 p.findGroup(
"SessionLog")[
"FileOutput"].setValue(
"On");
928 p.findGroup(
"SessionLog")[
"FileName"].setValue(value);
932 else if (name ==
"-VERBOSE") {
933 p.findGroup(
"SessionLog")[
"TerminalOutput"].setValue(
"On");
938 QString msg =
"-GUI and -PID are incompatible arguments";
958 std::vector<QString> &value) {
960 QString paramValue =
"";
965 if ( !paramName.contains(
"=") ) {
970 if (QString(
p_cmdline[curPos + 1]).compare(
"=") == 0) {
979 else if ( paramName.endsWith(
"=") ) {
980 paramName = paramName.mid(0, paramName.size() - 1);
990 else if (paramName.indexOf(
"=") > 0) {
991 QString parameterLiteral =
p_cmdline[curPos];
992 paramName = parameterLiteral.mid( 0, parameterLiteral.indexOf(
"=") );
993 paramValue = parameterLiteral.mid(parameterLiteral.indexOf(
"=") + 1);
998 QString msg =
"Unknown parameter [" + QString(
p_cmdline[curPos])
1007 paramValue = paramValue.trimmed();
1009 if (paramValue.length() > 0 && paramValue[0] !=
'(') {
1014 if (paramValue.length() > 1 && paramValue.mid(0, 2) ==
"\\(") {
1015 paramValue = paramValue.mid(1);
1018 else if (paramValue.length() > 2 && paramValue.mid(0, 3) ==
"\\\\(") {
1019 paramValue = paramValue.mid(1);
1022 value.push_back(paramValue);
1024 else if ( paramValue.length() ) {
1044 std::vector<QString> &reservedParams) {
1045 for (
unsigned int currArgument = 1; currArgument < (unsigned)
p_cmdline.size();
1048 QString paramName =
p_cmdline[currArgument];
1049 QString trueParamValue =
"";
1050 vector<QString> paramValue;
1053 if (paramName[0] ==
'-') {
1057 paramName = paramName.toUpper();
1060 if ( paramValue.size() ) {
1061 trueParamValue = paramValue[0].toUpper();
1068 if (fullReservedName == paramName) {
1090 std::vector<QString> values;
1092 bool inDoubleQuotes =
false;
1093 bool inSingleQuotes =
false;
1094 bool arrayClosed =
false;
1095 bool nextElementStarted =
false;
1096 QString currElement =
"";
1098 for (
int strPos = 0; strPos < arrayString.size(); strPos++) {
1100 if (arrayString[strPos] !=
'(') {
1101 QString msg =
"Invalid array format [" + arrayString +
"]";
1109 if ( arrayString[strPos] ==
'\\' && strPos + 1 < (
int)arrayString.size() ) {
1110 currElement += arrayString[strPos+1];
1115 else if (arrayString[strPos] ==
'\\') {
1116 QString msg =
"Invalid array format [" + arrayString +
"]";
1121 if (!inDoubleQuotes && !inSingleQuotes) {
1123 QString msg =
"Invalid array format [" + arrayString +
"]";
1127 nextElementStarted = (nextElementStarted || arrayString[strPos] !=
' ');
1129 if (!nextElementStarted) {
1133 if (arrayString[strPos] ==
'"') {
1134 inDoubleQuotes =
true;
1136 else if (arrayString[strPos] ==
'\'') {
1137 inSingleQuotes =
true;
1139 else if (arrayString[strPos] ==
',') {
1140 values.push_back(currElement);
1142 nextElementStarted =
false;
1144 else if (arrayString[strPos] ==
')') {
1145 values.push_back(currElement);
1148 nextElementStarted =
false;
1150 else if (nextElementStarted && arrayString[strPos] ==
' ') {
1152 bool onlyWhite =
true;
1153 int closingPos = strPos + 1;
1155 for(
int pos = strPos;
1156 onlyWhite && arrayString[pos] !=
',' && arrayString[pos] !=
')' &&
1157 pos < arrayString.size(); pos++) {
1159 onlyWhite &= (arrayString[pos] ==
' ');
1163 currElement += arrayString[strPos];
1166 else if (nextElementStarted) {
1167 currElement += arrayString[strPos];
1170 else if (inSingleQuotes) {
1171 if(arrayString[strPos] ==
'\'') {
1172 inSingleQuotes =
false;
1175 currElement += arrayString[strPos];
1180 if (arrayString[strPos] ==
'"') {
1181 inDoubleQuotes =
false;
1184 currElement += arrayString[strPos];
1189 if (!arrayClosed || currElement !=
"") {
1190 QString msg =
"Invalid array format [" + arrayString +
"]";
1217 std::vector<QString> &reservedParams,
1218 bool handleNoMatches) {
1220 int matchOption = -1;
1222 for (
int option = 0; option < (int)reservedParams.size(); option++) {
1224 if ( reservedParams[option].startsWith(unresolvedParam) ) {
1225 if (matchOption >= 0) {
1226 QString msg =
"Ambiguous Reserve Parameter ["
1227 + unresolvedParam +
"]. Please clarify.";
1231 matchOption = option;
1235 if (handleNoMatches) {
1237 if (matchOption < 0) {
1238 QString msg =
"Invalid Reserve Parameter Option ["
1239 + unresolvedParam +
"]. Choices are ";
1242 for (
int option = 0; option < (int)reservedParams.size(); option++) {
1244 if (reservedParams[option].compare(
"-PID") == 0) {
1248 msgOptions += reservedParams[option];
1261 msg +=
" [" + msgOptions +
"]";
1266 if (matchOption < 0) {
1270 return reservedParams[matchOption];
File name manipulation and expansion.
QDir dir() const
Returns the path of the file's parent directory as a QDir object.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
static void checkX11()
check to see if X is available
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
@ Programmer
This error is for when a programmer made an API call that was illegal.
Adds specific functionality to C++ strings.
IString Compress(bool force=false)
Collapses multiple spaces into single spaces.
IString Token(const IString &separator)
Returns the first token in the IString.
QString ToQt() const
Retuns the object string as a QString.
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.
Reads user preferences from a data file.
static void RunSystemCommand(QString commandLine)
This runs arbitrary system commands.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
QString name() const
Returns the container name.
Contains multiple PvlContainers.
Container for cube-like labels.
void setTerminator(const QString &term)
Sets the terminator used to signify the end of the PVL informationDefaults to "END".
void read(const QString &file)
Loads PVL information from a stream.
A single keyword-value pair.
QString name() const
Returns the keyword name.
void addValue(QString value, QString unit="")
Adds a value with units.
Contains Pvl Groups and Pvl Objects.
PvlObject & object(const int index)
Return the object at the specified index.
@ Traverse
Search child objects.
Provides access to sequential ASCII stream I/O.
void Open(const QString &filename, const char *openmode="input", const char *extension="")
Opens a text file.
QString p_saveFile
FileName to save last history to.
int p_parentId
This is a status to indicate if the GUI is running or not.
void preProcess(QString fullReservedName, std::vector< QString > &reservedParams)
This parses the command line and looks for the specified reserved parameter name passed.
std::vector< std::vector< QString > > p_batchList
Vector of batchlist data.
QString resolveParameter(QString &name, std::vector< QString > &reservedParams, bool handleNoMatches=true)
This resolves a reserved parameter token on the command line to its fullname.
QString p_progName
Name of program to run.
QString p_infoFileName
FileName to save debugging info.
QString GetInfoFileName()
This method returns the filename where the debugging info is stored when the "-info" tag is used.
std::vector< char * > p_cmdline
This variable will contain argv.
bool p_interactive
Boolean value representing whether the program is interactive or not.
bool p_info
Boolean value representing if it's in debug mode.
UserInterface(const QString &xmlfile, int &argc, char *argv[])
Constructs an UserInterface object.
void loadBatchList(const QString file)
Loads the user entered batchlist file into a private variable for later use.
void loadCommandLine(QVector< QString > &args, bool ignoreAppName=true)
This is used to load the command line into p_cmdline and the Aml object using information contained i...
bool GetInfoFlag()
This method returns the flag state of info.
std::vector< QString > readArray(QString arrayString)
This interprets an array value from the command line.
void evaluateOption(const QString name, const QString value)
This interprets the "-" options for reserved parameters.
void loadHistory(const QString file)
Loads the previous history for the program.
bool p_abortOnError
Boolean value representing whether to abort or continue on error.
Gui * p_gui
Pointer to the gui object.
QString p_errList
FileName to write batchlist line that caused error on.
int BatchListSize()
Returns the size of the batchlist.
void SetErrorList(int i)
This method adds the line specified in the BatchList that the error occured on.
void SaveHistory()
Saves the user parameter information in the history of the program for later use.
void SetBatchList(int i)
Clears the gui parameters and sets the batch list information at line i as the new parameters.
~UserInterface()
Destroys the UserInterface object.
void getNextParameter(unsigned int &curPos, QString &unresolvedParam, std::vector< QString > &value)
This gets the next parameter in the list of arguments.
Application program XML file parameter manager.
void CommandLine(Isis::Pvl &lab) const
Creates a QString which could be used as a command line.
QString ParamOdd(const int &group, const int ¶m) const
Returns whether the selected parameter has a restriction on odd values or not.
int ParamExcludeSize(const int &group, const int ¶m) const
Returns the number of parameters excluded in this parameter's exclusions.
QString ParamLessThan(const int &group, const int ¶m, const int &great) const
Returns the name of the specified lessThan parameter.
QString ParamLessThanOrEqual(const int &group, const int ¶m, const int &les) const
Returns the name of the specified lessThanOrEqual parameter.
QString ParamBrief(const int &group, const int ¶m) const
Returns the brief description of a parameter in a specified group.
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.
int ParamListIncludeSize(const int &group, const int ¶m, const int &option) const
Returns the number of items in a parameters list include section.
QString ParamListValue(const int &group, const int ¶m, const int &option) const
Returns the option value for a specific option to a parameter.
int NumGroups() const
Returns the number of groups found in the XML.
int ParamListExcludeSize(const int &group, const int ¶m, const int &option) const
Returns the number of items in a parameters list exclude section.
int ParamGreaterThanSize(const int &group, const int ¶m) const
Returns the number of values in the parameters greater than list.
QString ParamNotEqual(const int &group, const int ¶m, const int ¬Eq) const
Returns the name of the specified notEqual parameter.
QString ParamGreaterThanOrEqual(const int &group, const int ¶m, const int &great) const
Returns the name of the specified greaterThanOrEqual parameter.
QString ParamMaximumInclusive(const int &group, const int ¶m) const
Returns whether the maximum value is inclusive or not.
QString ParamType(const int &group, const int ¶m) const
Returns the parameter type of a parameter in a specified group.
int ParamListSize(const int &group, const int ¶m) const
Returns the number of options in the specified parameter's list.
int NumParams(const int &) const
Returns the number of parameters in a group.
QString ParamExclude(const int &group, const int ¶m, const int &exclude) const
Returns the name of the specified excluded parameter.
const IsisParameterData * ReturnParam(const QString ¶mName) const
Returns a pointer to a parameter whose name starts with paramName.
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.
int ParamLessThanOrEqualSize(const int &group, const int ¶m) const
Returns the number of values in the parameters less than or equal list.
QString ParamListBrief(const int &group, const int ¶m, const int &option) const
Returns the brief description for a specific option to a parameter.
QString ParamDefault(const int &group, const int ¶m) const
Returns the default for a parameter in a specified group.
int ParamLessThanSize(const int &group, const int ¶m) const
Returns the number of values in the parameters less than list.
QString ParamInclude(const int &group, const int ¶m, const int &include) const
Returns the name of the specified included parameter.
int ParamGreaterThanOrEqualSize(const int &group, const int ¶m) const
Returns the number of values in the parameters greater than or equal list.
QString ParamInternalDefault(const int &group, const int ¶m) const
Returns the internal default for a parameter in a specified group.
int ParamNotEqualSize(const int &group, const int ¶m) const
Returns the number of values in the not equal list.
QString ProgramName() const
Returns the Program name.
int ParamIncludeSize(const int &group, const int ¶m) const
Returns the number of parameters included in this parameter's inclusions.
QString ParamMinimumInclusive(const int &group, const int ¶m) const
Returns whether the minimum value is inclusive or not.
QString ParamGreaterThan(const int &group, const int ¶m, const int &great) const
Returns the name of the specified greaterThan parameter.
QString ParamMinimum(const int &group, const int ¶m) const
Returns the minimum value of a parameter in a specified group.
void Clear(const QString ¶mName)
Clears the value(s) in the named parameter.
void VerifyAll()
Verify all parameters.
QString ParamName(const int &group, const int ¶m) const
Returns the parameter name.
void PutAsString(const QString ¶mName, const QString &value)
Allows the insertion of a value for any parameter.
QString ParamMaximum(const int &group, const int ¶m) const
Returns the maximum value of a parameter in a specified group.
This is free and unencumbered software released into the public domain.
int toInt(const QString &string)
Global function to convert from a string to an integer.
PixelType
Enumerations for Isis Pixel Types.
Namespace for the standard library.