-
Notifications
You must be signed in to change notification settings - Fork 169
/
UserInterface.cpp
1248 lines (1093 loc) · 40.3 KB
/
UserInterface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** This is free and unencumbered software released into the public domain.
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/
/* SPDX-License-Identifier: CC0-1.0 */#include "UserInterface.h"
#include <sstream>
#include <vector>
#include <QDir>
#include "Application.h"
#include "FileName.h"
#include "Gui.h"
#include "IException.h"
#include "IString.h"
#include "Message.h"
#include "Preference.h"
#include "ProgramLauncher.h"
#include "TextFile.h"
using namespace std;
namespace Isis {
/**
* Constructs an UserInterface object.
*
* @param xmlfile Name of the Isis application xml file to open.
*
* @param argc Number of arguments on the command line. Must be pass by
* reference!!
*
* @param argv[] Array of arguments
*/
UserInterface::UserInterface(const QString &xmlfile, QVector<QString> &args) : IsisAml::IsisAml(xmlfile) {
p_interactive = false;
p_info = false;
p_infoFileName = "";
p_gui = NULL;
p_errList = "";
p_saveFile = "";
p_abortOnError = true;
p_parentId = 0;
// Make sure the user has a .Isis and .Isis/history directory
try {
FileName setup = "$HOME/.Isis/history";
// cannot completely test this if in unit test
if ( !setup.fileExists() ) {
setup.dir().mkpath(".");
}
}
catch (IException &) {
}
// Parse the user input
loadCommandLine(args);
}
/**
* Constructs an UserInterface object.
*
* @param xmlfile Name of the Isis application xml file to open.
*
* @param argc Number of arguments on the command line. Must be pass by
* reference!!
*
* @param argv[] Array of arguments
*/
UserInterface::UserInterface(const QString &xmlfile, int &argc,
char *argv[]) : IsisAml::IsisAml(xmlfile) {
p_interactive = false;
p_info = false;
p_infoFileName = "";
p_gui = NULL;
p_errList = "";
p_saveFile = "";
p_abortOnError = true;
p_parentId = 0;
// Make sure the user has a .Isis and .Isis/history directory
try {
FileName setup = "$HOME/.Isis/history";
// cannot completely test this if in unit test
if ( !setup.fileExists() ) {
setup.dir().mkpath(".");
}
}
catch (IException &) {
}
// Parse the user input
loadCommandLine(argc, argv);
// See if we need to create the gui
// can't unit test - don't want to create a Gui object while unit testing
if (p_interactive) {
Gui::checkX11();
p_gui = Gui::Create(*this, argc, argv);
}
}
//! Destroys the UserInterface object
UserInterface::~UserInterface() {
// can't unit test - p_gui will be NULL in unit test
if (p_gui) {
delete p_gui;
p_gui = NULL;
}
}
/**
* This method returns the filename where the debugging info is
* stored when the "-info" tag is used.
*
* @return @b QString Name of file containing debugging ingo.
*/
QString UserInterface::GetInfoFileName() {
return p_infoFileName;
}
/**
* This method returns the flag state of info. This returns if
* its in debugging mode(the -info tag was specified).
*
* @return @b bool Flag state on info.
*/
bool UserInterface::GetInfoFlag() {
return p_info;
}
/**
* Clears the gui parameters and sets the batch list information at line i as
* the new parameters
*
* @param i The line number to retrieve parameter information from
*
* @throws Isis::IException::User - Invalid command line
*/
void UserInterface::SetBatchList(int i) {
//Clear all parameters currently in the gui
for (int k = 0; k < NumGroups(); k++) {
for (int j = 0; j < NumParams(k); j++) {
Clear( ParamName(k, j) );
}
}
//Load the new parameters into the gui
cout << p_progName << " ";
for (unsigned int currArgument = 1; currArgument < p_cmdline.size(); currArgument ++) {
QString paramName;
vector<QString> paramValue;
try {
getNextParameter(currArgument, paramName, paramValue);
if (paramName[0] == '-')
continue;
for (unsigned int value = 0; value < paramValue.size(); value++) {
IString thisValue = paramValue[value];
QString token = thisValue.Token("$").ToQt();
QString newValue;
while (thisValue != "") {
newValue += token;
try {
int j = toInt( thisValue.substr(0, 1).c_str() ) - 1;
newValue += p_batchList[i][j];
thisValue.replace(0, 1, "");
token = thisValue.Token("$").ToQt();
}
catch (IException &e) {
// Let the variable be parsed by the application
newValue += "$";
token = thisValue.Token("$").ToQt();
}
}
if (token != "")
newValue += token;
paramValue[value] = newValue;
}
}
// can't test with unit test - command line is already parsed before SetBatchList() is called
catch (IException &e) {
throw IException(IException::User, "Invalid command line", _FILEINFO_);
}
PutAsString(paramName, paramValue);
cout << paramName;
if(paramValue.size() == 1) {
cout << "=" << paramValue[0] << " ";
}
else if (paramValue.size() > 1) {
cout << "=(";
for (unsigned int value = 0; value < paramValue.size(); value++) {
if(value != 0)
cout << ",";
cout << paramValue[value] << endl;
}
cout << ") ";
}
}
cout << endl;
// Verify the command line
VerifyAll();
}
/**
* This method adds the line specified in the BatchList that the error occured
* on. The BatchList line is added exactly as it is seen, so the BatchList
* command can be run on the errorlist file created.
*
* @param i The line of the batchlist to write to the error file
*
* @throws Isis::IException::User - Unable to create error list - Disk may be full or
* directory permissions not writeable
*/
void UserInterface::SetErrorList(int i) {
if (p_errList != "") {
std::ofstream os;
QString fileName( FileName(p_errList).expanded() );
os.open(fileName.toLatin1().data(), std::ios::app);
// did not unit test since it is assumed ofstream will be instantiated correctly
if ( !os.good() ) {
QString msg = "Unable to create error list [" + p_errList
+ "] Disk may be full or directory permissions not writeable";
throw IException(IException::User, msg, _FILEINFO_);
}
for (int j = 0; j < (int) p_batchList[i].size(); j++) {
os << p_batchList[i][j] << " ";
}
os << endl;
os.close();
}
}
/**
* Saves the user parameter information in the history of the program for later
* use
*/
void UserInterface::SaveHistory() {
// If history recording is off, return
Preference &p = Preference::Preferences();
PvlGroup &grp = p.findGroup("UserInterface", Isis::Pvl::Traverse);
if (grp["HistoryRecording"][0] == "Off")
return;
// Get the current history file
Isis::FileName histFile(grp["HistoryPath"][0] + "/" + ProgramName() + ".par");
// If a save file is specified, override the default file path
if (p_saveFile != "")
histFile = p_saveFile;
// Get the current command line
Isis::Pvl cmdLine;
CommandLine(cmdLine);
Isis::Pvl hist;
// If the history file's Pvl is corrupted, then
// leave hist empty such that the history gets
// overwriten with the new entry.
try {
if ( histFile.fileExists() ) {
hist.read( histFile.expanded() );
}
}
catch (IException &) {
}
// Add it
hist.addGroup( cmdLine.findGroup("UserParameters") );
// See if we have exceeded history length
while( hist.groups() > toInt(grp["HistoryLength"][0]) ) {
hist.deleteGroup("UserParameters");
}
// Write it
try {
hist.write( histFile.expanded() );
}
catch (IException &) {
}
}
/**
* Loads the user entered batchlist file into a private variable for later use
*
* @param file The batchlist file to load
*
* @history 2010-03-26 Sharmila Prasad - Remove the restriction of the number of
* columns in the batchlist file to 10.
* @throws Isis::IException::User - The batchlist file could not be opened
* @throws Isis::IException::User - The number of columns in the batchlist file must be
* consistent
* @throws Isis::IException::User - The batchlist does not contain any data
*/
void UserInterface::loadBatchList(const QString file) {
// Read in the batch list
TextFile temp;
try {
temp.Open(file);
}
catch (IException &e) {
QString msg = "The batchlist file [" + file + "] could not be opened";
throw IException(IException::User, msg, _FILEINFO_);
}
p_batchList.resize( temp.LineCount() );
for (int i = 0; i < temp.LineCount(); i++) {
QString t;
temp.GetLine(t);
// Convert tabs to spaces but leave tabs inside quotes alone
t = IString(t).Replace("\t", " ", true).ToQt();
t = IString(t).Compress().ToQt().trimmed();
// Allow " ," " , " or ", " as a valid single seperator
t = IString(t).Replace(" ,", ",", true).ToQt();
t = IString(t).Replace(", ", ",", true).ToQt();
// Convert all spaces to "," the use "," as delimiter
t = IString(t).Replace(" ", ",", true).ToQt();
int j = 0;
QStringList tokens = t.split(",");
foreach (QString token, tokens) {
// removes quotes from tokens. NOTE: also removes escaped quotes.
token = token.remove( QRegExp("[\"']") );
p_batchList[i].push_back(token);
j++ ;
}
p_batchList[i].resize(j);
// Every row in the batchlist must have the same number of columns
if (i == 0)
continue;
if ( p_batchList[i - 1].size() != p_batchList[i].size() ) {
QString msg = "The number of columns must be constant in batchlist";
throw IException(IException::User, msg, _FILEINFO_);
}
}
// The batchlist cannot be empty
if (p_batchList.size() < 1) {
QString msg = "The list file [" + file + "] does not contain any data";
throw IException(IException::User, msg, _FILEINFO_);
}
}
/**
* This is used to load the command line into p_cmdline and the Aml object
* using information contained in argc and argv.
*
* @param args QVector of arguments
*
* @throws Isis::IException::User - Invalid value for reserve parameter
* @throws Isis::IException::User - Invalid command line
* @throws Isis::IException::User - -BATCHLIST cannot be used with -GUI, -SAVE,
* -RESTORE, or -LAST
* @throws Isis::IException::User - -ERRLIST and -ONERROR=continue cannot be used without
* -BATCHLIST
*/
void UserInterface::loadCommandLine(QVector<QString> &args, bool ignoreAppName) {
char **c_args;
if (ignoreAppName) {
args.prepend("someapp");
}
c_args = (char**)malloc(sizeof(char*)*args.size());
for (int i = 0; i < args.size(); i++) {
c_args[i] = (char*)malloc(sizeof(char)*args[i].size()+1);
strcpy(c_args[i], args[i].toLatin1().data());
}
loadCommandLine(args.size(), c_args);
}
/**
* This is used to load the command line into p_cmdline and the Aml object
* using information contained in argc and argv.
*
* @param argc Number of arguments on the command line
*
* @param argv[] Array of arguments
*
* @throws Isis::IException::User - Invalid value for reserve parameter
* @throws Isis::IException::User - Invalid command line
* @throws Isis::IException::User - -BATCHLIST cannot be used with -GUI, -SAVE,
* -RESTORE, or -LAST
* @throws Isis::IException::User - -ERRLIST and -ONERROR=continue cannot be used without
* -BATCHLIST
*/
void UserInterface::loadCommandLine(int argc, char *argv[]) {
// The program will be interactive if it has no arguments or
// if it has the name unitTest
p_progName = argv[0];
Isis::FileName file(p_progName);
// cannot completely test in a unit test since unitTest will always evaluate to true
if ( (argc == 1) && (file.name() != "unitTest") ) {
p_interactive = true;
}
p_cmdline.clear();
for (int i = 0; i < argc; i++) {
p_cmdline.push_back(argv[i]);
}
// Check for special tokens (reserved parameters) (those beginning with a dash)
vector<QString> options;
options.push_back("-GUI");
options.push_back("-NOGUI");
options.push_back("-BATCHLIST");
options.push_back("-LAST");
options.push_back("-RESTORE");
options.push_back("-WEBHELP");
options.push_back("-HELP");
options.push_back("-ERRLIST");
options.push_back("-ONERROR");
options.push_back("-SAVE");
options.push_back("-INFO");
options.push_back("-PREFERENCE");
options.push_back("-LOG");
options.push_back("-VERBOSE");
options.push_back("-PID");
bool usedDashLast = false;
bool usedDashRestore = false; //< for throwing -batchlist exceptions at end of function
// pre-process command line for -HELP first
preProcess("-HELP", options);
// pre-process command line for -WEBHELP
preProcess("-WEBHELP", options);
// now, parse command line to evaluate -LAST
preProcess("-LAST", options);
for (unsigned int currArgument = 1; currArgument < (unsigned)argc; currArgument++) {
QString paramName;
vector<QString> paramValue;
getNextParameter(currArgument, paramName, paramValue);
// we now have a name,value pair
if (paramName[0] == '-') {
paramName = paramName.toUpper();
// where if(paramname == -last ) to continue } was originally
if (paramValue.size() > 1) {
QString msg = "Invalid value for reserve parameter ["
+ paramName + "]";
throw IException(IException::User, msg, _FILEINFO_);
}
// resolve the reserved parameter (e.g. set -h to -HELP)
paramName = resolveParameter(paramName, options);
// Prevent double handling of -LAST to prevent conflicts
// Keep track of using -LAST to prevent conflicts with -BATCHLIST
if (paramName == "-LAST") {
usedDashLast = true;
continue;
}
// Keep track of using -RESTORE to prevent conflicts with -BATCHLIST
if (paramName == "-RESTORE") {
usedDashRestore = true;
}
QString realValue = "";
if ( paramValue.size() ) {
realValue = paramValue[0];
}
evaluateOption(paramName, realValue);
continue;
}
try {
Clear(paramName);
PutAsString(paramName, paramValue);
}
catch (IException &e) {
throw IException(e, IException::User, "Invalid command line", _FILEINFO_);
}
}
// Can't use the batchlist with the gui, save, last or restore option
if ( BatchListSize() != 0 && (p_interactive || usedDashLast || p_saveFile != ""
|| usedDashRestore) ) {
QString msg = "-BATCHLIST cannot be used with -GUI, -SAVE, -RESTORE, ";
msg += "or -LAST";
throw IException(IException::User, msg, _FILEINFO_);
}
// Must use batchlist if using errorlist or onerror=continue
if ( (BatchListSize() == 0) && (!p_abortOnError || p_errList != "") ) {
QString msg = "-ERRLIST and -ONERROR=continue cannot be used without ";
msg += " the -BATCHLIST option";
throw IException(IException::User, msg, _FILEINFO_);
}
}
/**
* Loads the previous history for the program
*
* @param file FileName to get the history entry from
*
* @throws Isis::IException::User - The file does not contain any parameters
* to restore
* @throws Isis::IException::User - The file does not contain a valid parameter
* history file
* @throws Isis::IException::User - Parameter history file does not exist
*/
void UserInterface::loadHistory(const QString file) {
Isis::FileName hist(file);
if ( hist.fileExists() ) {
try {
Isis::Pvl lab( hist.expanded() );
int g = lab.groups() - 1;
if (g >= 0 && lab.group(g).isNamed("UserParameters") ) {
Isis::PvlGroup &up = lab.group(g);
QString commandline(p_progName + " ");
for (int k = 0; k < up.keywords(); k++) {
QString keyword = up[k].name();
vector<QString> values;
for (int i = 0; i < up[k].size(); i++) {
values.push_back(up[k][i]);
}
const IsisParameterData *paramData = ReturnParam(keyword);
bool matchesDefault = false;
if (values.size() == 1 && paramData->internalDefault == values[0])
matchesDefault = true;
if (!matchesDefault) {
matchesDefault =
(values.size() == paramData->defaultValues.size());
for (int i = 0; matchesDefault && i < (int)values.size(); i++) {
matchesDefault = matchesDefault &&
values[i] == paramData->defaultValues[i];
}
}
if (!matchesDefault) {
PutAsString(keyword, values);
commandline += keyword + "=";
foreach(QString val, values) {
commandline += val + " ";
}
}
}
cout << commandline << endl;
return;
}
for (int o = lab.objects() - 1; o >= 0; o--) {
if ( lab.object(o).isNamed( ProgramName() ) ) {
Isis::PvlObject &obj = lab.object(o);
for (int g = obj.groups() - 1; g >= 0; g--) {
Isis::PvlGroup &up = obj.group(g);
if ( up.isNamed("UserParameters") ) {
for (int k = 0; k < up.keywords(); k++) {
QString keyword = up[k].name();
QString value = up[k][0];
PutAsString(keyword, value);
}
}
return;
}
}
}
/*QString msg = "[" + hist.expanded() +
"] does not contain any parameters to restore";
throw Isis::iException::Message( Isis::iException::User, msg, _FILEINFO_ );*/
}
catch (...) {
QString msg = "The history file [" + file + "] is for a different application or corrupt, "\
"please fix or delete this file";
throw IException(IException::User, msg, _FILEINFO_);
}
}
else {
QString msg = "The history file [" + file + "] does not exist";
throw IException(IException::User, msg, _FILEINFO_);
}
}
/**
* This interprets the "-" options for reserved parameters
*
* @param name "-OPTIONNAME" (name of the reserved parameter)
* @param value Value of the option, if supplied (-name=value)
*
* @throws Isis::IException::Programmer - evaluating -WEBHELP throws an exception when
* unit testing to avoid exiting from the unit test
* @throws Isis::IException::Programmer - evaluating -HELP throws an exception when
* unit testing to avoid exiting from the unit test
* @throws Isis::IException::User - -ERRLIST expects a file name
* @throws Isis::IException::User - -ONERROR only accpets CONTINUE and ABORT as valid values
* @throws Isis::IException::Unknown - -GUI and -PID are incompatible arguments
*/
void UserInterface::evaluateOption(const QString name,
const QString value) {
// check to see if the program is a unitTest
bool unitTest = false;
if (FileName(p_progName).name() == "unitTest") {
unitTest = true;
}
Preference &p = Preference::Preferences();
if (name == "-GUI") {
p_interactive = true;
}
else if (name == "-NOGUI") {
p_interactive = false;
}
else if (name == "-BATCHLIST") {
loadBatchList(value);
}
else if (name == "-LAST") {
QString histFile;
// need to handle for unit test since -LAST is preprocessed
if (unitTest) {
histFile = "./" + FileName(p_progName).name() + ".par";
}
else {
PvlGroup &grp = p.findGroup("UserInterface", Isis::Pvl::Traverse);
histFile = grp["HistoryPath"][0] + "/" + FileName(p_progName).name() + ".par";
}
loadHistory(histFile);
}
else if(name == "-RESTORE") {
loadHistory(value);
}
else if(name == "-WEBHELP") {
Isis::PvlGroup &pref = Isis::Preference::Preferences().findGroup("UserInterface");
QString command = pref["GuiHelpBrowser"];
command += " $ISISROOT/doc/Application/presentation/Tabbed/";
command += FileName(p_progName).name() + "/" + FileName(p_progName).name() + ".html";
// cannot test else in unit test - don't want to open webhelp
if (unitTest) {
throw IException(IException::Programmer,
"Evaluating -WEBHELP should only throw this exception during a unitTest",
_FILEINFO_);
}
else {
ProgramLauncher::RunSystemCommand(command);
exit(0);
}
}
else if (name == "-INFO") {
p_info = true;
// check for filename and set value
if (value.size() != 0) {
p_infoFileName = value;
}
}
else if (name == "-HELP") {
if (value.size() == 0) {
Pvl params;
params.setTerminator("");
for (int k = 0; k < NumGroups(); k++) {
for (int j = 0; j < NumParams(k); j++) {
if (ParamListSize(k, j) == 0) {
params += PvlKeyword( ParamName(k, j), ParamDefault(k, j) );
}
else {
PvlKeyword key( ParamName(k, j) );
QString def = ParamDefault(k, j);
for (int l = 0; l < ParamListSize(k, j); l++) {
if (ParamListValue(k, j, l) == def)
key.addValue("*" + def);
else
key.addValue( ParamListValue(k, j, l) );
}
params += key;
}
}
}
cout << params;
}
else {
Pvl param;
param.setTerminator("");
QString key = value;
for (int k = 0; k < NumGroups(); k++) {
for (int j = 0; j < NumParams(k); j++) {
if (ParamName(k, j) == key) {
param += PvlKeyword("ParameterName", key);
param += PvlKeyword( "Brief", ParamBrief(k, j) );
param += PvlKeyword( "Type", ParamType(k, j) );
if (PixelType(k, j) != "") {
param += PvlKeyword( "PixelType", PixelType(k, j) );
}
if (ParamInternalDefault(k, j) != "") {
param += PvlKeyword( "InternalDefault", ParamInternalDefault(k, j) );
}
else {
param += PvlKeyword( "Default", ParamDefault(k, j) );
}
if (ParamMinimum(k, j) != "") {
if (ParamMinimumInclusive(k, j).toUpper() == "YES") {
param += PvlKeyword( "GreaterThanOrEqual",
ParamMinimum(k, j) );
}
else {
param += PvlKeyword( "GreaterThan",
ParamMinimum(k, j) );
}
}
if (ParamMaximum(k, j) != "") {
if (ParamMaximumInclusive(k, j).toUpper() == "YES") {
param += PvlKeyword( "LessThanOrEqual",
ParamMaximum(k, j) );
}
else {
param += PvlKeyword( "LessThan",
ParamMaximum(k, j) );
}
}
if (ParamLessThanSize(k, j) > 0) {
PvlKeyword key("LessThan");
for(int l = 0; l < ParamLessThanSize(k, j); l++) {
key.addValue( ParamLessThan(k, j, l) );
}
param += key;
}
if (ParamLessThanOrEqualSize(k, j) > 0) {
PvlKeyword key("LessThanOrEqual");
for (int l = 0; l < ParamLessThanOrEqualSize(k, j); l++) {
key.addValue( ParamLessThanOrEqual(k, j, l) );
}
param += key;
}
if (ParamNotEqualSize(k, j) > 0) {
PvlKeyword key("NotEqual");
for (int l = 0; l < ParamNotEqualSize(k, j); l++) {
key.addValue( ParamNotEqual(k, j, l) );
}
param += key;
}
if (ParamGreaterThanSize(k, j) > 0) {
PvlKeyword key("GreaterThan");
for (int l = 0; l < ParamGreaterThanSize(k, j); l++) {
key.addValue( ParamGreaterThan(k, j, l) );
}
param += key;
}
if (ParamGreaterThanOrEqualSize(k, j) > 0) {
PvlKeyword key("GreaterThanOrEqual");
for(int l = 0; l < ParamGreaterThanOrEqualSize(k, j); l++) {
key.addValue( ParamGreaterThanOrEqual(k, j, l) );
}
param += key;
}
if (ParamIncludeSize(k, j) > 0) {
PvlKeyword key("Inclusions");
for (int l = 0; l < ParamIncludeSize(k, j); l++) {
key.addValue( ParamInclude(k, j, l) );
}
param += key;
}
if (ParamExcludeSize(k, j) > 0) {
PvlKeyword key("Exclusions");
for (int l = 0; l < ParamExcludeSize(k, j); l++) {
key.addValue( ParamExclude(k, j, l) );
}
param += key;
}
if (ParamOdd(k, j) != "") {
param += PvlKeyword( "Odd", ParamOdd(k, j) );
}
if (ParamListSize(k, j) != 0) {
for (int l = 0; l < ParamListSize(k, j); l++) {
PvlGroup grp( ParamListValue(k, j, l) );
grp += PvlKeyword( "Brief", ParamListBrief(k, j, l) );
if (ParamListIncludeSize(k, j, l) != 0) {
PvlKeyword include("Inclusions");
for (int m = 0; m < ParamListIncludeSize(k, j, l); m++) {
include.addValue( ParamListInclude(k, j, l, m) );
}
grp += include;
}
if (ParamListExcludeSize(k, j, l) != 0) {
PvlKeyword exclude("Exclusions");
for (int m = 0; m < ParamListExcludeSize(k, j, l); m++) {
exclude.addValue( ParamListExclude(k, j, l, m) );
}
grp += exclude;
}
param.addGroup(grp);
}
}
cout << param;
}
}
}
}
// we must throw an exception for unitTest to handle to continue testing
if (unitTest) {
throw IException(IException::Programmer,
"Evaluating -HELP should only throw this exception during a unitTest",
_FILEINFO_);
}
// all other apps shall exit when -HELP is present
else {
exit(0);
}
}
else if (name == "-PID") {
p_parentId = toInt(value);
}
else if (name == "-ERRLIST") {
p_errList = value;
if (value == "") {
QString msg = "-ERRLIST expects a file name";
throw IException(IException::User, msg, _FILEINFO_);
}
if ( FileName(p_errList).fileExists() ) {
QFile::remove(p_errList);
}
}
else if (name == "-ONERROR") {
if (value.toUpper() == "CONTINUE") {
p_abortOnError = false;
}
else if (value.toUpper() == "ABORT") {
p_abortOnError = true;
}
else {
QString msg = "[" + value
+ "] is an invalid value for -ONERROR, options are ABORT or CONTINUE";
throw IException(IException::User, msg, _FILEINFO_);
}
}
else if (name == "-SAVE") {
if (value.size() == 0) {
p_saveFile = ProgramName() + ".par";
}
else {
p_saveFile = value;
}
}
else if (name == "-PREFERENCE") {
p.Load(value);
}
else if (name == "-LOG") {
if( value.isEmpty() ) {
p.findGroup("SessionLog")["FileOutput"].setValue("On");
}
else {
p.findGroup("SessionLog")["FileOutput"].setValue("On");
p.findGroup("SessionLog")["FileName"].setValue(value);
}
}
// this only evaluates to true in unit test since this is last else if
else if (name == "-VERBOSE") {
p.findGroup("SessionLog")["TerminalOutput"].setValue("On");
}
// Can't have a parent id and the gui
if (p_parentId > 0 && p_interactive) {
QString msg = "-GUI and -PID are incompatible arguments";
throw IException(IException::Unknown, msg, _FILEINFO_);
}
}
/**
* This gets the next parameter in the list of arguments. curPos will be changed
* to be the end of the current argument (still needs incremented to get the
* next argument).
*
* @param curPos End of previous argument
* @param name Resulting parameter name
* @param value Resulting array of parameter values (usually just 1 element)
*
* @throws Isis::IException::User - parameters cannot start with "="
*/
void UserInterface::getNextParameter(unsigned int &curPos,
QString &name,
std::vector<QString> &value) {
QString paramName = p_cmdline[curPos];
QString paramValue = "";
// we need to split name and value, they can either be in 1, 2 or 3 arguments,
// try to see if "=" is end of argument to distinguish. Some options have no
// "=" and they are value-less (-gui for example).
if ( !paramName.contains("=") ) {
// This looks value-less, but lets make sure
// the next argument is not an equals sign by
// itself
if (curPos < p_cmdline.size() - 2) {
if (QString(p_cmdline[curPos + 1]).compare("=") == 0) {
paramValue = p_cmdline[curPos + 2];
// increment extra to skip 2 elements next time around
curPos += 2;
}
}
}
// = is end of parameter, next item must be value
else if ( paramName.endsWith("=") ) {
paramName = paramName.mid(0, paramName.size() - 1);
if (curPos + 1 < p_cmdline.size() ) {
paramValue = p_cmdline[curPos + 1];
}
// increment extra to skip next element next time around
curPos++ ;
}
// we found "=" in the middle
else if (paramName.indexOf("=") > 0) {
QString parameterLiteral = p_cmdline[curPos];
paramName = parameterLiteral.mid( 0, parameterLiteral.indexOf("=") );
paramValue = parameterLiteral.mid(parameterLiteral.indexOf("=") + 1);
}
// We found "=" at the beginning - did we find "appname param =value" ?
else {
// parameters can not start with "="
QString msg = "Unknown parameter [" + QString(p_cmdline[curPos])
+ "]";
throw IException(IException::User, msg, _FILEINFO_);
}
name = paramName;
value.clear();
// read arrays out of paramValue
paramValue = paramValue.trimmed();
if (paramValue.length() > 0 && paramValue[0] != '(') {
// We dont have an array... if they escaped
// an open paren, undo their escape
// escape: \( result: (
if (paramValue.length() > 1 && paramValue.mid(0, 2) =="\\(") {
paramValue = paramValue.mid(1);
}
// escape: \\( result: \(
else if (paramValue.length() > 2 && paramValue.mid(0, 3) == "\\\\(") {
paramValue = paramValue.mid(1);
}
value.push_back(paramValue);
}
else if ( paramValue.length() ) {
// We have an array...