|
Isis 3 Programmer Reference
|
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";
50 setup.
dir().mkpath(
".");
84 FileName setup =
"$HOME/.Isis/history";
87 setup.
dir().mkpath(
".");
100 p_gui = Gui::Create(*
this, argc, argv);
154 for (
unsigned int currArgument = 1; currArgument <
p_cmdline.size(); currArgument ++) {
156 vector<QString> paramValue;
162 if (paramName[0] ==
'-')
165 for (
unsigned int value = 0; value < paramValue.size(); value++) {
166 IString thisValue = paramValue[value];
167 QString token = thisValue.
Token(
"$").
ToQt();
171 while (thisValue !=
"") {
174 int j =
toInt( thisValue.substr(0, 1).c_str() ) - 1;
176 thisValue.replace(0, 1,
"");
189 paramValue[value] = newValue;
201 if(paramValue.size() == 1) {
202 cout <<
"=" << paramValue[0] <<
" ";
204 else if (paramValue.size() > 1) {
207 for (
unsigned int value = 0; value < paramValue.size(); value++) {
211 cout << paramValue[value] << endl;
238 os.open(fileName.toLatin1().data(), std::ios::app);
242 QString msg =
"Unable to create error list [" +
p_errList
243 +
"] Disk may be full or directory permissions not writeable";
247 for (
int j = 0; j < (int)
p_batchList[i].size(); j++) {
266 if (grp[
"HistoryRecording"][0] ==
"Off")
297 while( hist.
groups() >
toInt(grp[
"HistoryLength"][0]) ) {
329 QString msg =
"The batchlist file [" + file +
"] could not be opened";
335 for (
int i = 0; i < temp.
LineCount(); i++) {
352 foreach (QString token, tokens) {
354 token = token.remove( QRegExp(
"[\"']") );
364 QString msg =
"The number of columns must be constant in batchlist";
370 QString msg =
"The list file [" + file +
"] does not contain any data";
394 args.prepend(
"someapp");
397 c_args = (
char**)malloc(
sizeof(
char*)*args.size());
399 for (
int i = 0; i < args.size(); i++) {
400 c_args[i] = (
char*)malloc(
sizeof(
char)*args[i].size()+1);
401 strcpy(c_args[i], args[i].toLatin1().data());
429 if ( (argc == 1) && (file.
name() !=
"unitTest") ) {
434 for (
int i = 0; i < argc; i++) {
439 vector<QString> options;
440 options.push_back(
"-GUI");
441 options.push_back(
"-NOGUI");
442 options.push_back(
"-BATCHLIST");
443 options.push_back(
"-LAST");
444 options.push_back(
"-RESTORE");
445 options.push_back(
"-WEBHELP");
446 options.push_back(
"-HELP");
447 options.push_back(
"-ERRLIST");
448 options.push_back(
"-ONERROR");
449 options.push_back(
"-SAVE");
450 options.push_back(
"-INFO");
451 options.push_back(
"-PREFERENCE");
452 options.push_back(
"-LOG");
453 options.push_back(
"-VERBOSE");
454 options.push_back(
"-PID");
456 bool usedDashLast =
false;
457 bool usedDashRestore =
false;
466 for (
unsigned int currArgument = 1; currArgument < (unsigned)argc; currArgument++) {
468 vector<QString> paramValue;
473 if (paramName[0] ==
'-') {
474 paramName = paramName.toUpper();
478 if (paramValue.size() > 1) {
479 QString msg =
"Invalid value for reserve parameter ["
489 if (paramName ==
"-LAST") {
496 if (paramName ==
"-RESTORE") {
497 usedDashRestore =
true;
501 QString realValue =
"";
503 if ( paramValue.size() ) {
504 realValue = paramValue[0];
524 || usedDashRestore) ) {
525 QString msg =
"-BATCHLIST cannot be used with -GUI, -SAVE, -RESTORE, ";
532 QString msg =
"-ERRLIST and -ONERROR=continue cannot be used without ";
533 msg +=
" the -BATCHLIST option";
557 if (g >= 0 && lab.
group(g).
isNamed(
"UserParameters") ) {
560 for (
int k = 0; k < up.
keywords(); k++) {
561 QString keyword = up[k].
name();
563 vector<QString> values;
565 for (
int i = 0; i < up[k].size(); i++) {
566 values.push_back(up[k][i]);
571 bool matchesDefault =
false;
572 if (values.size() == 1 && paramData->internalDefault == values[0])
573 matchesDefault =
true;
575 if (!matchesDefault) {
577 (values.size() == paramData->defaultValues.size());
579 for (
int i = 0; matchesDefault && i < (int)values.size(); i++) {
580 matchesDefault = matchesDefault &&
581 values[i] == paramData->defaultValues[i];
585 if (!matchesDefault) {
587 commandline += keyword +
"=";
588 foreach(QString val, values) {
589 commandline += val +
" ";
594 cout << commandline << endl;
598 for (
int o = lab.
objects() - 1; o >= 0; o--) {
601 for (
int g = obj.
groups() - 1; g >= 0; g--) {
603 if ( up.
isNamed(
"UserParameters") ) {
604 for (
int k = 0; k < up.
keywords(); k++) {
605 QString keyword = up[k].
name();
606 QString value = up[k][0];
620 QString msg =
"The history file [" + file +
"] is for a different application or corrupt, "\
621 "please fix or delete this file";
626 QString msg =
"The history file [" + file +
"] does not exist";
650 const QString value) {
652 bool unitTest =
false;
658 if (name ==
"-GUI") {
661 else if (name ==
"-NOGUI") {
664 else if (name ==
"-BATCHLIST") {
667 else if (name ==
"-LAST") {
680 else if(name ==
"-RESTORE") {
683 else if(name ==
"-WEBHELP") {
685 QString command = pref[
"GuiHelpBrowser"];
686 command +=
" $ISISROOT/docs/Application/presentation/Tabbed/";
691 "Evaluating -WEBHELP should only throw this exception during a unitTest",
700 else if (name ==
"-INFO") {
704 if (value.size() != 0) {
708 else if (name ==
"-HELP") {
709 if (value.size() == 0) {
852 "Evaluating -HELP should only throw this exception during a unitTest",
860 else if (name ==
"-PID") {
863 else if (name ==
"-ERRLIST") {
867 QString msg =
"-ERRLIST expects a file name";
875 else if (name ==
"-ONERROR") {
876 if (value.toUpper() ==
"CONTINUE") {
880 else if (value.toUpper() ==
"ABORT") {
885 QString msg =
"[" + value
886 +
"] is an invalid value for -ONERROR, options are ABORT or CONTINUE";
890 else if (name ==
"-SAVE") {
891 if (value.size() == 0) {
898 else if (name ==
"-PREFERENCE") {
901 else if (name ==
"-LOG") {
902 if( value.isEmpty() ) {
903 p.
findGroup(
"SessionLog")[
"FileOutput"].setValue(
"On");
906 p.
findGroup(
"SessionLog")[
"FileOutput"].setValue(
"On");
907 p.
findGroup(
"SessionLog")[
"FileName"].setValue(value);
911 else if (name ==
"-VERBOSE") {
912 p.
findGroup(
"SessionLog")[
"TerminalOutput"].setValue(
"On");
917 QString msg =
"-GUI and -PID are incompatible arguments";
936 std::vector<QString> &value) {
938 QString paramValue =
"";
943 if ( !paramName.contains(
"=") ) {
948 if (QString(
p_cmdline[curPos + 1]).compare(
"=") == 0) {
957 else if ( paramName.endsWith(
"=") ) {
958 paramName = paramName.mid(0, paramName.size() - 1);
968 else if (paramName.indexOf(
"=") > 0) {
969 QString parameterLiteral =
p_cmdline[curPos];
970 paramName = parameterLiteral.mid( 0, parameterLiteral.indexOf(
"=") );
971 paramValue = parameterLiteral.mid(parameterLiteral.indexOf(
"=") + 1);
976 QString msg =
"Unknown parameter [" + QString(
p_cmdline[curPos])
985 paramValue = paramValue.trimmed();
987 if (paramValue.length() > 0 && paramValue[0] !=
'(') {
992 if (paramValue.length() > 1 && paramValue.mid(0, 2) ==
"\\(") {
993 paramValue = paramValue.mid(1);
996 else if (paramValue.length() > 2 && paramValue.mid(0, 3) ==
"\\\\(") {
997 paramValue = paramValue.mid(1);
1000 value.push_back(paramValue);
1002 else if ( paramValue.length() ) {
1022 std::vector<QString> &reservedParams) {
1023 for (
unsigned int currArgument = 1; currArgument < (unsigned)
p_cmdline.size();
1026 QString paramName =
p_cmdline[currArgument];
1027 QString trueParamValue =
"";
1028 vector<QString> paramValue;
1031 if (paramName[0] ==
'-') {
1035 paramName = paramName.toUpper();
1038 if ( paramValue.size() ) {
1039 trueParamValue = paramValue[0].toUpper();
1046 if (fullReservedName == paramName) {
1068 std::vector<QString> values;
1070 bool inDoubleQuotes =
false;
1071 bool inSingleQuotes =
false;
1072 bool arrayClosed =
false;
1073 bool nextElementStarted =
false;
1074 QString currElement =
"";
1076 for (
int strPos = 0; strPos < arrayString.size(); strPos++) {
1078 if (arrayString[strPos] !=
'(') {
1079 QString msg =
"Invalid array format [" + arrayString +
"]";
1087 if ( arrayString[strPos] ==
'\\' && strPos + 1 < (
int)arrayString.size() ) {
1088 currElement += arrayString[strPos+1];
1093 else if (arrayString[strPos] ==
'\\') {
1094 QString msg =
"Invalid array format [" + arrayString +
"]";
1099 if (!inDoubleQuotes && !inSingleQuotes) {
1101 QString msg =
"Invalid array format [" + arrayString +
"]";
1105 nextElementStarted = (nextElementStarted || arrayString[strPos] !=
' ');
1107 if (!nextElementStarted) {
1111 if (arrayString[strPos] ==
'"') {
1112 inDoubleQuotes =
true;
1114 else if (arrayString[strPos] ==
'\'') {
1115 inSingleQuotes =
true;
1117 else if (arrayString[strPos] ==
',') {
1118 values.push_back(currElement);
1120 nextElementStarted =
false;
1122 else if (arrayString[strPos] ==
')') {
1123 values.push_back(currElement);
1126 nextElementStarted =
false;
1128 else if (nextElementStarted && arrayString[strPos] ==
' ') {
1130 bool onlyWhite =
true;
1131 int closingPos = strPos + 1;
1133 for(
int pos = strPos;
1134 onlyWhite && arrayString[pos] !=
',' && arrayString[pos] !=
')' &&
1135 pos < arrayString.size(); pos++) {
1137 onlyWhite &= (arrayString[pos] ==
' ');
1141 currElement += arrayString[strPos];
1144 else if (nextElementStarted) {
1145 currElement += arrayString[strPos];
1148 else if (inSingleQuotes) {
1149 if(arrayString[strPos] ==
'\'') {
1150 inSingleQuotes =
false;
1153 currElement += arrayString[strPos];
1158 if (arrayString[strPos] ==
'"') {
1159 inDoubleQuotes =
false;
1162 currElement += arrayString[strPos];
1167 if (!arrayClosed || currElement !=
"") {
1168 QString msg =
"Invalid array format [" + arrayString +
"]";
1195 std::vector<QString> &reservedParams,
1196 bool handleNoMatches) {
1198 int matchOption = -1;
1200 for (
int option = 0; option < (int)reservedParams.size(); option++) {
1202 if ( reservedParams[option].startsWith(unresolvedParam) ) {
1203 if (matchOption >= 0) {
1204 QString msg =
"Ambiguous Reserve Parameter ["
1205 + unresolvedParam +
"]. Please clarify.";
1209 matchOption = option;
1213 if (handleNoMatches) {
1215 if (matchOption < 0) {
1216 QString msg =
"Invalid Reserve Parameter Option ["
1217 + unresolvedParam +
"]. Choices are ";
1220 for (
int option = 0; option < (int)reservedParams.size(); option++) {
1222 if (reservedParams[option].compare(
"-PID") == 0) {
1226 msgOptions += reservedParams[option];
1239 msg +=
" [" + msgOptions +
"]";
1244 if (matchOption < 0) {
1248 return reservedParams[matchOption];
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.
QString GetInfoFileName()
This method returns the filename where the debugging info is stored when the "-info" tag is used.
void PutAsString(const QString ¶mName, const QString &value)
Allows the insertion of a value for any parameter.
int ParamListSize(const int &group, const int ¶m) const
Returns the number of options in the specified parameter's list.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
PvlGroup & group(const int index)
Return the group at the specified index.
void evaluateOption(const QString name, const QString value)
This interprets the "-" options for reserved parameters.
Contains Pvl Groups and Pvl Objects.
A single keyword-value pair.
QString p_errList
FileName to write batchlist line that caused error on.
static void RunSystemCommand(QString commandLine)
This runs arbitrary system commands.
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.
QString ParamMinimumInclusive(const int &group, const int ¶m) const
Returns whether the minimum value is inclusive or not.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
File name manipulation and expansion.
bool p_info
Boolean value representing if it's in debug mode.
@ Unknown
A type of error that cannot be classified as any of the other error types.
void addValue(QString value, QString unit="")
Adds a value with units.
void SetErrorList(int i)
This method adds the line specified in the BatchList that the error occured on.
int groups() const
Returns the number of groups contained.
bool fileExists() const
Returns true if the file exists; false otherwise.
std::vector< std::vector< QString > > p_batchList
Vector of batchlist data.
QString ParamBrief(const int &group, const int ¶m) const
Returns the brief description of a parameter in a specified group.
QString ParamGreaterThanOrEqual(const int &group, const int ¶m, const int &great) const
Returns the name of the specified greaterThanOrEqual parameter.
bool p_interactive
Boolean value representing whether the program is interactive or not.
Provides access to sequential ASCII stream I/O.
QString ParamMaximum(const int &group, const int ¶m) const
Returns the maximum value of a parameter in a specified group.
Container for cube-like labels.
bool GetLine(QString &line, const bool skipComments=true)
Gets next line from file.
int objects() const
Returns the number of objects.
void write(const QString &file)
Opens and writes PVL information to a file and handles the end of line sequence.
bool GetInfoFlag()
This method returns the flag state of info.
QString ParamGreaterThan(const int &group, const int ¶m, const int &great) const
Returns the name of the specified greaterThan parameter.
PvlObject & object(const int index)
Return the object at the specified index.
QString ParamDefault(const int &group, const int ¶m) const
Returns the default for a parameter in a specified 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 ParamIncludeSize(const int &group, const int ¶m) const
Returns the number of parameters included in this parameter's inclusions.
QString p_infoFileName
FileName to save debugging info.
std::vector< QString > readArray(QString arrayString)
This interprets an array value from the command line.
void loadBatchList(const QString file)
Loads the user entered batchlist file into a private variable for later use.
QString ParamType(const int &group, const int ¶m) const
Returns the parameter type of a parameter in a specified group.
int BatchListSize()
Returns the size of the batchlist.
int p_parentId
This is a status to indicate if the GUI is running or not.
QString ParamInternalDefault(const int &group, const int ¶m) const
Returns the internal default for a parameter in a specified group.
int ParamListExcludeSize(const int &group, const int ¶m, const int &option) const
Returns the number of items in a parameters list exclude section.
~UserInterface()
Destroys the UserInterface object.
IString Compress(bool force=false)
Collapses multiple spaces into single spaces.
@ Traverse
Search child objects.
void Open(const QString &filename, const char *openmode="input", const char *extension="")
Opens a text file.
void VerifyAll()
Verify all parameters.
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.
int ParamNotEqualSize(const int &group, const int ¶m) const
Returns the number of values in the not equal list.
Gui * p_gui
Pointer to the gui object.
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...
Contains multiple PvlContainers.
QDir dir() const
Returns the path of the file's parent directory as a QDir object.
QString p_progName
Name of program to run.
void read(const QString &file)
Loads PVL information from a stream.
bool isNamed(const QString &match) const
Returns whether the given string is equal to the container name or not.
int toInt(const QString &string)
Global function to convert from a string to an integer.
Application program XML file parameter manager.
void SetBatchList(int i)
Clears the gui parameters and sets the batch list information at line i as the new parameters.
std::vector< char * > p_cmdline
This variable will contain argv.
QString ParamExclude(const int &group, const int ¶m, const int &exclude) const
Returns the name of the specified excluded parameter.
QString ParamNotEqual(const int &group, const int ¶m, const int ¬Eq) const
Returns the name of the specified notEqual parameter.
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.
QString ParamMinimum(const int &group, const int ¶m) const
Returns the minimum value of a parameter in a specified group.
int ParamExcludeSize(const int &group, const int ¶m) const
Returns the number of parameters excluded in this parameter's exclusions.
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.
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.
const IsisParameterData * ReturnParam(const QString ¶mName) const
Returns a pointer to a parameter whose name starts with paramName.
void getNextParameter(unsigned int &curPos, QString &unresolvedParam, std::vector< QString > &value)
This gets the next parameter in the list of arguments.
QString name() const
Returns the container name.
QString PixelType(const int &group, const int ¶m) const
Returns the default pixel type from the XML.
int ParamGreaterThanOrEqualSize(const int &group, const int ¶m) const
Returns the number of values in the parameters greater than or equal list.
void preProcess(QString fullReservedName, std::vector< QString > &reservedParams)
This parses the command line and looks for the specified reserved parameter name passed.
int ParamGreaterThanSize(const int &group, const int ¶m) const
Returns the number of values in the parameters greater than list.
QString p_saveFile
FileName to save last history to.
QString ParamLessThan(const int &group, const int ¶m, const int &great) const
Returns the name of the specified lessThan parameter.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
int ParamListIncludeSize(const int &group, const int ¶m, const int &option) const
Returns the number of items in a parameters list include section.
void Clear(const QString ¶mName)
Clears the value(s) in the named parameter.
int ParamLessThanSize(const int &group, const int ¶m) const
Returns the number of values in the parameters less than list.
@ Programmer
This error is for when a programmer made an API call that was illegal.
Namespace for the standard library.
void SaveHistory()
Saves the user parameter information in the history of the program for later use.
int ParamLessThanOrEqualSize(const int &group, const int ¶m) const
Returns the number of values in the parameters less than or equal list.
QString resolveParameter(QString &name, std::vector< QString > &reservedParams, bool handleNoMatches=true)
This resolves a reserved parameter token on the command line to its fullname.
void CommandLine(Isis::Pvl &lab) const
Creates a QString which could be used as a command line.
IString Token(const IString &separator)
Returns the first token in the IString.
QString ParamLessThanOrEqual(const int &group, const int ¶m, const int &les) const
Returns the name of the specified lessThanOrEqual parameter.
static void checkX11()
check to see if X is available
bool p_abortOnError
Boolean value representing whether to abort or continue on error.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
UserInterface(const QString &xmlfile, int &argc, char *argv[])
Constructs an UserInterface object.
Adds specific functionality to C++ strings.
QString ParamMaximumInclusive(const int &group, const int ¶m) const
Returns whether the maximum value is inclusive or not.
void deleteGroup(const QString &name)
Remove a group from the current PvlObject.
QString ProgramName() const
Returns the Program name.
QString ParamOdd(const int &group, const int ¶m) const
Returns whether the selected parameter has a restriction on odd values or not.
QString ParamName(const int &group, const int ¶m) const
Returns the parameter name.
This is free and unencumbered software released into the public domain.
void setTerminator(const QString &term)
Sets the terminator used to signify the end of the PVL informationDefaults to "END".
QString ToQt() const
Retuns the object string as a QString.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
void loadHistory(const QString file)
Loads the previous history for the program.
int NumParams(const int &) const
Returns the number of parameters in a group.