Loading [MathJax]/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
IsisAml.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#include <sstream>
9#include <xercesc/util/PlatformUtils.hpp>
10#include <xercesc/util/TransService.hpp>
11#include <xercesc/sax2/XMLReaderFactory.hpp>
12
13#include <nlohmann/json.hpp>
14using json = nlohmann::json;
15
16#include "FileName.h"
17#include "IException.h"
18#include "IsisAml.h"
19#include "IsisXMLChTrans.h"
20#include "IString.h"
21#include "Preference.h"
22#include "Pvl.h"
23#include "PvlGroup.h"
24#include "PvlKeyword.h"
25#include "PvlObject.h"
26
27using namespace std;
28
33namespace XERCES = XERCES_CPP_NAMESPACE;
34
41IsisAml::IsisAml(const QString &xmlfile) {
42 StartParser(xmlfile.toLatin1().data());
43}
44
50
68void IsisAml::PutAsString(const QString &paramName,
69 const QString &value) {
70
71 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
72
73 if(param->values.size() > 0) {
74 QString message = "A value for this parameter [" + paramName + "] has "
75 "already been entered.";
76 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
77 }
78
79 param->values.clear();
80 param->values.push_back(value);
81
82}
83
96void IsisAml::PutAsString(const QString &paramName,
97 const vector<QString> &value) {
98
99 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
100
101 if(param->values.size() > 0) {
102 QString message = "A value for this parameter [" + paramName + "] has "
103 "already been entered.";
104 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
105 }
106
107 param->values.resize(value.size());
108 param->values = value;
109
110}
111
112
113// Public: Sets the value member of a parameter of type QString whose name
114// starts with paramName
115
131void IsisAml::PutString(const QString &paramName, const QString &value) {
132
133 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
134
135 if(param->type != "string" && param->type != "combo") {
136 QString message = "Parameter [" + paramName + "] is not a string.";
137 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
138 }
139
140 if(param->values.size() > 0) {
141 QString message = "A value for this parameter [" + paramName + "] has "
142 "already been saved (possibly by IsisGui). If you need to "
143 "change the value use \"Clear\" before the Put.";
144 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
145 }
146
147 param->values.clear();
148 param->values.push_back(value);
149
150 Verify(param);
151}
152
153
154// Public: Sets the value member of a parameter of type QString whose name
155// starts with paramName
163void IsisAml::PutString(const QString &paramName,
164 const vector<QString> &value) {
165
166 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
167
168 if(param->type != "string" && param->type != "combo") {
169 QString message = "Parameter [" + paramName + "] is not a string.";
170 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
171 }
172
173 if(param->values.size() > 0) {
174 QString message = "A value for this parameter [" + paramName + "] has "
175 "already been saved (possibly by IsisGui). If you need to "
176 "change the value use \"Clear\" before the Put.";
177 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
178 }
179
180 param->values.resize(value.size());
181 param->values = value;
182
183 Verify(param);
184}
185
186
187// Public: Sets the value member of a parameter of type filename whose name
188// starts with paramName
189
198void IsisAml::PutFileName(const QString &paramName,
199 const QString &value) {
200
201 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
202
203 if((param->type != "filename") && (param->type != "cube")) {
204 QString message = "Parameter [" + paramName + "] is not a filename.";
205 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
206 }
207
208 if(param->values.size() > 0) {
209 QString message = "A value for this parameter [" + paramName + "] has "
210 "already been saved (possibly by IsisGui). If you need to "
211 "change the value use \"Clear\" before the Put.";
212 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
213 }
214
215 param->values.clear();
216 param->values.push_back(value);
217
218 Verify(param);
219}
220
221
222// Public: Sets the value member of a parameter of type filename whose name
223// starts with paramName
224
240void IsisAml::PutFileName(const QString &paramName,
241 const vector<QString> &value) {
242
243 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
244
245 if((param->type != "filename") && (param->type != "cube")) {
246 QString message = "Parameter [" + paramName + "] is not a filename.";
247 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
248 }
249
250 if(param->values.size() > 0) {
251 QString message = "A value for this parameter [" + paramName + "] has "
252 "already been saved (possibly by IsisGui). If you need to "
253 "change the value use \"Clear\" before the Put.";
254 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
255 }
256
257 param->values.resize(value.size());
258 param->values = value;
259
260 Verify(param);
261}
262
263
273void IsisAml::PutCubeName(const QString &paramName,
274 const QString &value) {
275
276 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
277
278 if(param->type != "cube") {
279 QString message = "Parameter [" + paramName + "] is not a cubename.";
280 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
281 }
282
283 if(param->values.size() > 0) {
284 QString message = "A value for this parameter [" + paramName + "] has "
285 "already been saved (possibly by IsisGui). If you need to "
286 "change the value use \"Clear\" before the Put.";
287 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
288 }
289
290 param->values.clear();
291 param->values.push_back(value);
292
293 Verify(param);
294}
295
296
297// Public: Sets the value member of a parameter of type integer whose name
298// starts with paramName
299
311void IsisAml::PutInteger(const QString &paramName,
312 const int &value) {
313
314 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
315
316 if(param->type != "integer") {
317 QString message = "Parameter [" + paramName + "] is not an integer.";
318 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
319 }
320
321 if(param->values.size() > 0) {
322 QString message = "A value for this parameter [" + paramName + "] has "
323 "already been saved (possibly by IsisGui). If you need to "
324 "change the value use \"Clear\" before the Put.";
325 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
326 }
327
328 param->values.clear();
329 param->values.push_back(Isis::toString(value));
330
331 Verify(param);
332}
333
334
335// Public: Sets the value member of a parameter of type integer whose name
336// starts with paramName
337
352void IsisAml::PutInteger(const QString &paramName,
353 const vector<int> &value) {
354
355 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
356
357 if(param->type != "integer") {
358 QString message = "Parameter [" + paramName + "] is not an integer.";
359 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
360 }
361
362 if(param->values.size() > 0) {
363 QString message = "A value for this parameter [" + paramName + "] has "
364 "already been saved (possibly by IsisGui). If you need to "
365 "change the value use \"Clear\" before the Put.";
366 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
367 }
368
369 param->values.resize(value.size());
370 for(unsigned int i = 0; i < value.size(); i++) {
371 param->values[i] = Isis::toString(value[i]);
372 }
373
374 Verify(param);
375}
376
377
378// Public: Sets the value member of a parameter of type double whose name
379// starts with paramName
395void IsisAml::PutDouble(const QString &paramName,
396 const double &value) {
397
398 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
399
400 if(param->type != "double") {
401 QString message = "Parameter [" + paramName + "] is not a double.";
402 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
403 }
404
405 if(param->values.size() > 0) {
406 QString message = "A value for this parameter [" + paramName + "] has "
407 "already been saved (possibly by IsisGui). If you need to "
408 "change the value use \"Clear\" before the Put.";
409 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
410 }
411
412 param->values.clear();
413 param->values.push_back(Isis::toString(value));
414
415 Verify(param);
416}
417
418
419// Public: Sets the value member of a parameter of type double whose name
420// starts with paramName
436void IsisAml::PutDouble(const QString &paramName,
437 const vector<double> &value) {
438
439 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
440
441 if(param->type != "double") {
442 QString message = "Parameter [" + paramName + "] is not a double.";
443 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
444 }
445
446 if(param->values.size() > 0) {
447 QString message = "A value for this parameter [" + paramName + "] has "
448 "already been saved (possibly by IsisGui). If you need to "
449 "change the value use \"Clear\" before the Put.";
450 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
451 }
452
453 param->values.resize(value.size());
454 for(unsigned int i = 0; i < value.size(); i++) {
455 param->values[i] = Isis::toString(value[i]);
456 }
457
458 Verify(param);
459}
460
461
462// Public: Sets the value member of a parameter of type boolean whose name
463// starts with paramName
479void IsisAml::PutBoolean(const QString &paramName,
480 const bool &value) {
481
482 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
483
484 if(param->type != "boolean") {
485 QString message = "Parameter [" + paramName + "] is not a boolean.";
486 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
487 }
488
489 if(param->values.size() > 0) {
490 QString message = "A value for this parameter [" + paramName + "] has "
491 "already been saved (possibly by IsisGui). If you need to "
492 "change the value use \"Clear\" before the Put.";
493 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
494 }
495
496 param->values.clear();
497 if(value) {
498 param->values.push_back("YES");
499 }
500 else {
501 param->values.push_back("NO");
502 }
503
504 Verify(param);
505}
506
507
508// Public: Sets the value member of a parameter of type boolean whose name
509// starts with paramName
525void IsisAml::PutBoolean(const QString &paramName,
526 const vector<bool> &value) {
527
528 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
529
530 if(param->type != "boolean") {
531 QString message = "Parameter [" + paramName + "] is not a boolean.";
532 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
533 }
534
535 if(param->values.size() > 0) {
536 QString message = "A value for this parameter [" + paramName + "] has "
537 "already been saved (possibly by IsisGui). If you need to "
538 "change the value use \"Clear\" before the Put.";
539 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
540 }
541
542 param->values.resize(value.size());
543 for(unsigned int i = 0; i < value.size(); i++) {
544 if(value[i]) {
545 param->values.push_back("YES");
546 }
547 else {
548 param->values.push_back("NO");
549 }
550 }
551
552 Verify(param);
553}
554
555
556// Accessor methods for getting the value(s) of a parameter
557
558// Public: Returns the first element of the value member of a parameter whos
559// name starts with paramName as a QString. Any type can be retrieve with this member.
570QString IsisAml::GetAsString(const QString &paramName) const {
571
572 const IsisParameterData *param = ReturnParam(paramName);
573 QString value;
574 if(param->values.size() == 0) {
575 if(param->defaultValues.size() == 0) {
576 QString message = "Parameter [" + paramName + "] has no value.";
577 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
578 }
579 else {
580 value = param->defaultValues[0];
581 }
582 }
583 else {
584 value = param->values[0];
585 }
586
587 return value;
588}
589
590
591// Public: Returns the value member of a parameter whose name starts with paramName
592// as a vector<QString>
603void IsisAml::GetAsString(const QString &paramName,
604 vector<QString> &values) const {
605
606 const IsisParameterData *param = ReturnParam(paramName);
607
608 values.clear();
609 QString value;
610 if(param->values.size() == 0) {
611 if(param->defaultValues.size() == 0) {
612 QString message = "Parameter [" + paramName + "] has no value.";
613 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
614 }
615 else {
616 for(unsigned int i = 0; i < param->defaultValues.size(); i++)
617 values.push_back(param->defaultValues[i]);
618 }
619 }
620 else {
621 for(unsigned int i = 0; i < param->values.size(); i++)
622 values.push_back(param->values[i]);
623 }
624
625 return;
626}
627
628
629// Public: Returns the first element of the value member of a parameter whose
630// name starts with paramName as a QString/filename
641QString IsisAml::GetFileName(const QString &paramName, QString extension) const {
642
643 const IsisParameterData *param = ReturnParam(paramName);
644 if(param->type != "filename") {
645 QString message = "Parameter [" + paramName + "] is not a filename.";
646 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
647 }
648
649 QString value;
650 if(param->values.size() == 0) {
651 if(param->defaultValues.size() == 0) {
652 QString message = "Parameter [" + paramName + "] has no value.";
653 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
654 }
655 else {
656 value = param->defaultValues[0];
657 }
658 }
659 else {
660 value = param->values[0];
661 }
662
663 Isis::FileName name(value);
664 if(extension != "") name = name.addExtension(extension);
665 value = name.expanded();
666
667 return value;
668}
669
670
671// Public: Returns the value member of a parameter whose name starts with paramName
672// as a vector<QString/filename>
680void IsisAml::GetFileName(const QString &paramName,
681 vector<QString> &values) const {
682
683 const IsisParameterData *param = ReturnParam(paramName);
684
685 if(param->type != "filename") {
686 QString message = "Parameter [" + paramName + "] is not a filename.";
687 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
688 }
689
690 values.clear();
691 if(param->values.size() == 0) {
692 if(param->defaultValues.size() == 0) {
693 QString message = "Parameter [" + paramName + "] has no value.";
694 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
695 }
696 else {
697 for(unsigned int i = 0; i < param->defaultValues.size(); i++) {
698 Isis::FileName name(param->defaultValues[i]);
699 values.push_back(name.expanded());
700 }
701 }
702 }
703 else {
704 for(unsigned int i = 0; i < param->values.size(); i++) {
705 Isis::FileName name(param->values[i]);
706 values.push_back(name.expanded());
707 }
708 }
709
710 return;
711}
712
713
724QString IsisAml::GetCubeName(const QString &paramName, QString extension) const {
725
726 const IsisParameterData *param = ReturnParam(paramName);
727
728 if (param->type != "cube") {
729 QString message = "Parameter [" + paramName + "] is not a cubename.";
730 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
731 }
732
733 QString value;
734 if (param->values.size() == 0) {
735 if (param->defaultValues.size() == 0) {
736 QString message = "Parameter [" + paramName + "] has no value.";
737 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
738 }
739 else {
740 value = param->defaultValues[0];
741 }
742 }
743 else {
744 value = param->values[0];
745 }
746
747 Isis::FileName name(value);
748 if (extension != "") name = name.addExtension(extension);
749 value = name.expanded();
750 if (name.attributes().length() > 0) {
751 value += "+" + name.attributes();
752 }
753
754 return value;
755}
756
757
758// Public: Returns the first element of the value member of a parameter whos
759// name starts with paramName as a QString
769QString IsisAml::GetString(const QString &paramName) const {
770
771 const IsisParameterData *param = ReturnParam(paramName);
772 QString value;
773
774 if(param->type != "string" && param->type != "combo") {
775 QString message = "Parameter [" + paramName + "] is not a string.";
776 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
777 }
778
779 if(param->values.size() == 0) {
780 if(param->defaultValues.size() == 0) {
781 QString message = "Parameter [" + paramName + "] has no value.";
782 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
783 }
784 else {
785 value = param->defaultValues[0];
786 }
787 }
788 else {
789 value = param->values[0];
790 // If there is a list of legal values return the list option that matches
791 // or begins with what was entered rather than exactly what was entered
792 if(param->listOptions.size() > 0) {
793 value = value.toUpper();
794 int found = -1;
795 int foundcount = 0;
796 for(unsigned int p = 0; p < param->listOptions.size(); p++) {
797 QString option = param->listOptions[p].value;
798 option = option.toUpper();
799 if(value == option) {
800 return value;
801 }
802 else if(value.startsWith(option) || option.startsWith(value)) {
803 found = p;
804 foundcount = foundcount + 1;
805 }
806 }
807 if(foundcount == 0) {
808 QString message = "Value [" + value + "] for parameter [" +
809 paramName + "] is not a valid value.";
810 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
811 }
812 if(foundcount > 1) {
813 QString message = "Value [" + value + "] for parameter [" +
814 paramName + "] is not unique.";
815 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
816 }
817 return param->listOptions[found].value;
818 }
819
820 // Just return what is in the value
821 else {
822 value = param->values[0];
823 }
824 }
825 return value;
826}
827
828
829// Public: Returns the value member of a parameter whose name starts with paramName
830// as a vector<QString>
841void IsisAml::GetString(const QString &paramName,
842 vector<QString> &values) const {
843
844 const IsisParameterData *param = ReturnParam(paramName);
845
846 if(param->type != "string" && param->type != "combo") {
847 QString message = "Parameter [" + paramName + "] is not a string.";
848 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
849 }
850
851 values.clear();
852 QString value;
853 if(param->values.size() == 0) {
854 if(param->defaultValues.size() == 0) {
855 QString message = "Parameter [" + paramName + "] has no value.";
856 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
857 }
858 else {
859 for(unsigned int i = 0; i < param->defaultValues.size(); i++)
860 values.push_back(param->defaultValues[i]);
861 }
862 }
863 else {
864 for(unsigned int i = 0; i < param->values.size(); i++)
865 values.push_back(param->values[i]);
866 }
867
868 return;
869}
870
871
872// Public: Returns the first element of the value member of a parameter whos
873// name starts with paramName as an integer
883int IsisAml::GetInteger(const QString &paramName) const {
884
885 const IsisParameterData *param = ReturnParam(paramName);
886
887 if(param->type != "integer") {
888 QString message = "Parameter [" + paramName + "] is not an integer.";
889 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
890 }
891
892 Isis::IString value;
893 if(param->values.size() == 0) {
894 if(param->defaultValues.size() == 0) {
895 QString message = "Parameter [" + paramName + "] has no value.";
896 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
897 }
898 else {
899 value = param->defaultValues[0];
900 }
901 }
902 else {
903 value = param->values[0];
904 }
905
906 return value.ToInteger();
907}
908
909
910// Public: Returns the value member of a parameter whose name starts with paramName
911// as a vector<int>
922void IsisAml::GetInteger(const QString &paramName,
923 vector<int> &values) const {
924
925 const IsisParameterData *param = ReturnParam(paramName);
926
927 if(param->type != "integer") {
928 QString message = "Parameter [" + paramName + "] is not an integer.";
929 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
930 }
931
932 values.clear();
933 Isis::IString value;
934 if(param->values.size() == 0) {
935 if(param->defaultValues.size() == 0) {
936 QString message = "Parameter [" + paramName + "] has no value.";
937 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
938 }
939 else {
940 for(unsigned int i = 0; i < param->defaultValues.size(); i++)
941 value = param->defaultValues[i];
942 values.push_back(value.ToInteger());
943 }
944 }
945 else {
946 for(unsigned int i = 0; i < param->values.size(); i++)
947 value = param->values[i];
948 values.push_back(value.ToInteger());
949 }
950
951 return;
952}
953
954
955// Public: Returns the first element of the value member of a parameter whos
956// name starts with paramName as a doubble
966double IsisAml::GetDouble(const QString &paramName) const {
967
968 const IsisParameterData *param = ReturnParam(paramName);
969
970 if(param->type != "double") {
971 QString message = "Parameter [" + paramName + "] is not a double.";
972 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
973 }
974
975 Isis::IString value;
976 if(param->values.size() == 0) {
977 if(param->defaultValues.size() == 0) {
978 QString message = "Parameter [" + paramName + "] has no value.";
979 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
980 }
981 else {
982 value = param->defaultValues[0];
983 }
984 }
985 else {
986 value = param->values[0];
987 }
988
989 return value.ToDouble();
990}
991
992
993// Public: Returns the value member of a parameter whose name starts with paramName
994// as a vector<doubble>
1005void IsisAml::GetDouble(const QString &paramName,
1006 vector<double> &values) const {
1007
1008 const IsisParameterData *param = ReturnParam(paramName);
1009
1010 if(param->type != "double") {
1011 QString message = "Parameter [" + paramName + "] is not a double.";
1012 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
1013 }
1014
1015 values.clear();
1016 Isis::IString value;
1017 if(param->values.size() == 0) {
1018 if(param->defaultValues.size() == 0) {
1019 QString message = "Parameter [" + paramName + "] has no value.";
1020 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
1021 }
1022 else {
1023 for(unsigned int i = 0; i < param->defaultValues.size(); i++)
1024 value = param->defaultValues[i];
1025 values.push_back(value.ToDouble());
1026 }
1027 }
1028 else {
1029 for(unsigned int i = 0; i < param->values.size(); i++)
1030 value = param->values[i];
1031 values.push_back(value.ToDouble());
1032 }
1033
1034 return;
1035}
1036
1037
1038// Public: Returns the first element of the value member of a parameter whos
1039// name starts with paramName as a bool
1049bool IsisAml::GetBoolean(const QString &paramName) const {
1050
1051 const IsisParameterData *param = ReturnParam(paramName);
1052
1053 if(param->type != "boolean") {
1054 QString message = "Parameter [" + paramName + "] is not a boolean.";
1055 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
1056 }
1057
1058 QString value;
1059 if(param->values.size() == 0) {
1060 if(param->defaultValues.size() == 0) {
1061 QString message = "Parameter [" + paramName + "] has no value.";
1062 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
1063 }
1064 else {
1065 value = param->defaultValues[0];
1066 }
1067 }
1068 else {
1069 value = param->values[0];
1070 }
1071
1072 return Isis::toBool(value);
1073
1074}
1075
1076
1077// Public: Returns the value member of a parameter whose name starts with paramName
1078// as a vector<bool>
1089void IsisAml::GetBoolean(const QString &paramName,
1090 vector<bool> &values) const {
1091
1092 const IsisParameterData *param = ReturnParam(paramName);
1093
1094 if(param->type != "boolean") {
1095 QString message = "Parameter [" + paramName + "] is not a boolean.";
1096 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
1097 }
1098
1099 values.clear();
1100 vector <QString> value;
1101 QString tmp;
1102 if(param->values.size() == 0) {
1103 if(param->defaultValues.size() == 0) {
1104 QString message = "Parameter [" + paramName + "] has no value.";
1105 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
1106 }
1107 else {
1108 for(unsigned int i = 0; i < param->defaultValues.size(); i++) {
1109 tmp = param->defaultValues[i].toUpper();
1110 value.push_back(tmp);
1111 }
1112 }
1113 }
1114 else {
1115 for(unsigned int i = 0; i < param->values.size(); i++) {
1116 tmp = param->values[i].toUpper();
1117 value.push_back(tmp);
1118 }
1119 }
1120
1121 for(unsigned int i = 0; i < value.size(); i++) {
1122 values.push_back(StringToBool(value[i]));
1123
1124 }
1125
1126 return;
1127}
1133QString IsisAml::ProgramName() const {
1134 QString tmp = name;
1135 return tmp;
1136}
1137
1138
1144QString IsisAml::Brief() const {
1145 return brief;
1146}
1147
1148
1154QString IsisAml::Description() const {
1155 return description;
1156}
1157
1158
1165 return groups.size();
1166}
1167
1168
1176QString IsisAml::GroupName(const int &index) const {
1177 QString s = groups[index].name;
1178 return s;
1179}
1180
1181
1191int IsisAml::GroupIndex(const QString & grpName) const {
1192 for(int i=0; i<(int)groups.size(); i++) {
1193 if(Isis::IString(grpName).DownCase() == Isis::IString(groups[i].name).DownCase()) {
1194 return i;
1195 }
1196 }
1197 return -1;
1198}
1199
1200
1206 json ret = {};
1207 Isis::PvlGroup group("UserParameters");
1208
1209 // Add appropriate keywords
1210 for(unsigned int g = 0; g < groups.size(); g++) {
1211 for(unsigned int p = 0; p < groups[g].parameters.size(); p++) {
1212 const IsisParameterData *param = ReturnParam(ParamName(g, p));
1213 // If this param has a value add it to the command line
1214 if(param->values.size() > 0) {
1215 std::vector<std::string> values(param->values.size());
1216
1217 for(unsigned int value = 0; value < param->values.size(); value++) {
1218 values[value] = param->values[value].toStdString();
1219 }
1220
1221 if (values.size() == 0) {
1222 ret[param->name.toStdString()] = "NULL";
1223 }
1224 if (values.size() > 1) {
1225 ret[param->name.toStdString()] = values;
1226 }
1227 else {
1228 ret[param->name.toStdString()] = values.at(0);
1229 }
1230
1231 }
1232
1233 // Or if it has a default value add it to the command line
1234 else if(param->defaultValues.size() > 0) {
1235 std::vector<std::string> values(param->defaultValues.size());
1236
1237 for(unsigned int value = 0;
1238 value < param->defaultValues.size();
1239 value++) {
1240 values[value] = param->defaultValues[value].toStdString();
1241 }
1242
1243 if (values.size() == 0) {
1244 ret[param->name.toStdString()] = "NULL";
1245 }
1246 else if (values.size() > 1) {
1247 ret[param->name.toStdString()] = values;
1248 }
1249 else {
1250 ret[param->name.toStdString()] = values.at(0);
1251 }
1252 }
1253 }
1254 }
1255
1256 return ret;
1257}
1258
1259
1273void IsisAml::CreatePVL(Isis::Pvl &pvlDef , QString guiGrpName, QString pvlObjName, QString pvlGrpName, vector<QString> & include) {
1274
1275 Isis::PvlObject *pvlObj = NULL;
1276 if (pvlObjName != "") {
1277 pvlObj = new Isis::PvlObject(pvlObjName);
1278 }
1279
1280 // Get Gui Group index
1281 int grpIndex= GroupIndex(guiGrpName);
1282
1283 if (pvlGrpName == "" || grpIndex == -1 ) {
1284 QString errMsg = "Must provide Group Name\n";
1285 throw Isis::IException(Isis::IException::User, errMsg, _FILEINFO_);
1286 }
1287
1288 Isis::PvlGroup grp(pvlGrpName);
1289 for(int i=0; i<NumParams(grpIndex); i++) {
1290 QString paramName = ParamName(grpIndex, i);
1291
1292 if(IsParamInPvlInclude(paramName,include)) {
1293 Isis::IString paramType = Isis::IString(ParamType(grpIndex, i)).DownCase();
1294 if(paramType == "double") {
1295 grp += Isis::PvlKeyword(paramName, Isis::toString(GetDouble(paramName)));
1296 }
1297 if(paramType == "integer") {
1298 grp += Isis::PvlKeyword(paramName, Isis::toString(GetInteger(paramName)));
1299 }
1300 if(paramType == "boolean") {
1301 grp += Isis::PvlKeyword(paramName, Isis::toString(GetBoolean(paramName)));
1302 }
1303 if(paramType == "string" || paramType == "filename" || paramType == "combo") {
1304 grp += Isis::PvlKeyword(paramName, GetAsString(paramName));
1305 }
1306 }
1307 }
1308
1309 if(pvlObj != NULL) {
1310 *pvlObj += grp;
1311 pvlDef += *pvlObj;
1312 delete (pvlObj);
1313 pvlObj = NULL;
1314 }
1315 else {
1316 pvlDef += grp;
1317 }
1318}
1319
1320
1331bool IsisAml::IsParamInPvlInclude(QString & paramName, vector<QString> & include) {
1332
1333 for(int i=0; i<(int)include.size(); i++) {
1334 if(Isis::IString(paramName).DownCase() == Isis::IString(include[i]).DownCase()) {
1335 return true;
1336 }
1337 }
1338 return false;
1339}
1340
1341
1349int IsisAml::NumParams(const int &group) const {
1350 return groups[group].parameters.size();
1351}
1352
1353
1362QString IsisAml::ParamName(const int &group, const int &param) const {
1363 QString s = groups[group].parameters[param].name;
1364 return s;
1365}
1366
1367
1376QString IsisAml::ParamBrief(const int &group, const int &param) const {
1377 QString s = groups[group].parameters[param].brief;
1378 return s;
1379}
1380
1381
1390QString IsisAml::ParamDescription(const int &group, const int &param) const {
1391 QString s = groups[group].parameters[param].description;
1392 return s;
1393}
1394
1395
1404QString IsisAml::ParamMinimum(const int &group, const int &param) const {
1405 QString s = groups[group].parameters[param].minimum;
1406 return s;
1407}
1408
1409
1418QString IsisAml::ParamMaximum(const int &group, const int &param) const {
1419 QString s = groups[group].parameters[param].maximum;
1420 return s;
1421}
1422
1423
1432QString IsisAml::ParamMinimumInclusive(const int &group, const int &param) const {
1433 QString s = groups[group].parameters[param].minimum_inclusive;
1434 return s;
1435}
1436
1437
1446QString IsisAml::ParamMaximumInclusive(const int &group, const int &param) const {
1447 QString s = groups[group].parameters[param].maximum_inclusive;
1448 return s;
1449}
1450
1451
1461QString IsisAml::ParamOdd(const int &group, const int &param) const {
1462 QString s = groups[group].parameters[param].odd;
1463 return s;
1464}
1465
1466
1475int IsisAml::ParamGreaterThanSize(const int &group, const int &param) const {
1476 return groups[group].parameters[param].greaterThan.size();
1477}
1478
1479
1489 const int &param) const {
1490 return groups[group].parameters[param].greaterThanOrEqual.size();
1491}
1492
1493
1502int IsisAml::ParamLessThanSize(const int &group, const int &param) const {
1503 return groups[group].parameters[param].lessThan.size();
1504}
1505
1506
1516 const int &param) const {
1517 return groups[group].parameters[param].lessThanOrEqual.size();
1518}
1519
1520
1529int IsisAml::ParamNotEqualSize(const int &group, const int &param) const {
1530 return groups[group].parameters[param].notEqual.size();
1531}
1532
1533
1543QString IsisAml::ParamGreaterThan(const int &group, const int &param,
1544 const int &great) const {
1545 QString s = groups[group].parameters[param].greaterThan[great];
1546 return s;
1547}
1548
1549
1559QString IsisAml::ParamGreaterThanOrEqual(const int &group, const int &param,
1560 const int &great) const {
1561 QString s = groups[group].parameters[param].greaterThanOrEqual[great];
1562 return s;
1563}
1564
1565
1575QString IsisAml::ParamLessThan(const int &group, const int &param,
1576 const int &les) const {
1577 QString s = groups[group].parameters[param].lessThan[les];
1578 return s;
1579}
1580
1581
1591QString IsisAml::ParamLessThanOrEqual(const int &group, const int &param,
1592 const int &les) const {
1593 QString s = groups[group].parameters[param].lessThanOrEqual[les];
1594 return s;
1595}
1596
1597
1607QString IsisAml::ParamNotEqual(const int &group, const int &param,
1608 const int &notEq) const {
1609 QString s = groups[group].parameters[param].notEqual[notEq];
1610 return s;
1611}
1612
1613
1623QString IsisAml::ParamExclude(const int &group, const int &param,
1624 const int &exclude) const {
1625 QString s = groups[group].parameters[param].exclude[exclude];
1626 return s;
1627}
1628
1629
1639QString IsisAml::ParamInclude(const int &group, const int &param,
1640 const int &include) const {
1641 QString s = groups[group].parameters[param].include[include];
1642 return s;
1643}
1644
1645
1654QString IsisAml::ParamType(const int &group, const int &param) const {
1655 QString s = groups[group].parameters[param].type;
1656 return s;
1657}
1658
1659
1668QString IsisAml::ParamDefault(const int &group, const int &param) const {
1669 QString s;
1670 if(groups[group].parameters[param].defaultValues.size() == 0) {
1671 s = "";
1672 }
1673 else {
1674 s = groups[group].parameters[param].defaultValues[0];
1675 }
1676 return s;
1677}
1678
1679
1688QString IsisAml::ParamInternalDefault(const int &group, const int &param) const {
1689 QString s;
1690 if(groups[group].parameters[param].internalDefault.size() == 0) {
1691 s = "";
1692 }
1693 else {
1694 s = groups[group].parameters[param].internalDefault;
1695 }
1696 return s;
1697}
1698
1699
1708QString IsisAml::ParamFilter(const int &group, const int &param) const {
1709 QString s;
1710 if(groups[group].parameters[param].filter.size() == 0) {
1711 s = "";
1712 }
1713 else {
1714 s = groups[group].parameters[param].filter;
1715 }
1716 return s;
1717}
1718
1719
1728QString IsisAml::ParamPath(const int &group, const int &param) const {
1729 QString s;
1730 if(groups[group].parameters[param].path.size() == 0) {
1731 s = "";
1732 }
1733 else {
1734 s = groups[group].parameters[param].path;
1735 }
1736 return s;
1737}
1738
1739
1748QString IsisAml::ParamFileMode(const int &group, const int &param) const {
1749 QString s;
1750 if(groups[group].parameters[param].fileMode.size() == 0) {
1751 s = "";
1752 }
1753 else {
1754 s = groups[group].parameters[param].fileMode;
1755 }
1756 return s;
1757}
1758
1759
1769int IsisAml::ParamListSize(const int &group, const int &param) const {
1770 return groups[group].parameters[param].listOptions.size();
1771}
1772
1773
1783QString IsisAml::ParamListValue(const int &group, const int &param,
1784 const int &option) const {
1785 QString s = groups[group].parameters[param].listOptions[option].value;
1786 return s;
1787}
1788
1789
1799QString IsisAml::ParamListBrief(const int &group, const int &param,
1800 const int &option) const {
1801 QString s = groups[group].parameters[param].listOptions[option].brief;
1802 return s;
1803}
1804
1805
1815QString IsisAml::ParamListDescription(const int &group, const int &param,
1816 const int &option) const {
1817 QString s = groups[group].parameters[param].listOptions[option].description;
1818 return s;
1819}
1820
1821
1831int IsisAml::ParamListExcludeSize(const int &group, const int &param,
1832 const int &option) const {
1833 return groups[group].parameters[param].listOptions[option].exclude.size();
1834}
1835
1836
1847QString IsisAml::ParamListExclude(const int &group, const int &param,
1848 const int &option, const int &exclude) const {
1849 QString s = groups[group].parameters[param].listOptions[option].exclude[exclude];
1850 return s;
1851}
1852
1853
1863int IsisAml::ParamListIncludeSize(const int &group, const int &param,
1864 const int &option) const {
1865 return groups[group].parameters[param].listOptions[option].include.size();
1866}
1867
1868
1879QString IsisAml::ParamListInclude(const int &group, const int &param,
1880 const int &option, const int &include) const {
1881 QString s = groups[group].parameters[param].listOptions[option].include[include];
1882 return s;
1883}
1884
1885
1894int IsisAml::ParamExcludeSize(const int &group, const int &param) const {
1895 return groups[group].parameters[param].exclude.size();
1896}
1897
1898
1907int IsisAml::ParamIncludeSize(const int &group, const int &param) const {
1908 return groups[group].parameters[param].include.size();
1909}
1910
1911
1920QString IsisAml::PixelType(const int &group, const int &param) const {
1921 return groups[group].parameters[param].pixelType;
1922}
1923
1924
1933int IsisAml::HelpersSize(const int &group, const int &param) const {
1934 return groups[group].parameters[param].helpers.size();
1935}
1936
1937
1947QString IsisAml::HelperButtonName(const int &group, const int &param,
1948 const int &helper) const {
1949 return groups[group].parameters[param].helpers[helper].name;
1950}
1951
1952
1962QString IsisAml::HelperFunction(const int &group, const int &param,
1963 const int &helper) const {
1964 return groups[group].parameters[param].helpers[helper].function;
1965}
1966
1967
1977QString IsisAml::HelperBrief(const int &group, const int &param,
1978 const int &helper) const {
1979 return groups[group].parameters[param].helpers[helper].brief;
1980}
1981
1982
1992QString IsisAml::HelperDescription(const int &group, const int &param,
1993 const int &helper) const {
1994 return groups[group].parameters[param].helpers[helper].description;
1995}
1996
1997
2007QString IsisAml::HelperIcon(const int &group, const int &param,
2008 const int &helper) const {
2009 return groups[group].parameters[param].helpers[helper].icon;
2010}
2011
2012
2020bool IsisAml::WasEntered(const QString &paramName) const {
2021
2022 const IsisParameterData *param = ReturnParam(paramName);
2023
2024 if(param->values.size() == 0) {
2025 return false;
2026 }
2027
2028 return true;
2029}
2030
2031
2037void IsisAml::Clear(const QString &paramName) {
2038
2039 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
2040 param->values.clear();
2041
2042 param->outCubeAtt.setAttributes("+" + param->pixelType);
2043 param->inCubeAtt.setAttributes("");
2044
2045 return;
2046}
2047
2048
2060
2061 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
2062
2063 if(param->type != "cube") {
2064 QString message = "Unable to get input cube attributes. Parameter ["
2065 + paramName + "] is not a cube. Parameter type = [" + param->type + "].";
2066 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
2067 }
2068
2069 QString value;
2070 if(param->values.size() == 0) {
2071 if(param->defaultValues.size() == 0) {
2072 value.clear();
2073// QString message = "Parameter [" + paramName + "] has no value.";
2074// throw Isis::IException(Isis::IException::User,message, _FILEINFO_);
2075 }
2076 else {
2077 value = param->defaultValues[0];
2078 }
2079 }
2080 else {
2081 value = param->values[0];
2082 }
2083 if(param->fileMode == "input") {
2084 param->inCubeAtt.setAttributes(value);
2085 }
2086 else {
2087 QString message = "Unable to get input cube attributes. Parameter ["
2088 + paramName + "] is not an input. Parameter fileMode = [" + param->fileMode + "].";
2089 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
2090 }
2091 return param->inCubeAtt;
2092}
2093
2094
2106
2107 IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
2108
2109 if(param->type != "cube") {
2110 QString message = "Unable to get output cube attributes. Parameter ["
2111 + paramName + "] is not a cube. Parameter type = [" + param->type + "].";
2112 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
2113 }
2114
2115 QString value;
2116 if(param->values.size() == 0) {
2117 if(param->defaultValues.size() == 0) {
2118 value.clear();
2119// QString message = "Parameter [" + paramName + "] has no value.";
2120// throw Isis::IException(Isis::IException::User,message, _FILEINFO_);
2121 }
2122 else {
2123 value = param->defaultValues[0];
2124 }
2125 }
2126 else {
2127 value = param->values[0];
2128 }
2129 if(param->fileMode == "output") {
2130 param->outCubeAtt.setAttributes("+" + param->pixelType);
2131 param->outCubeAtt.addAttributes(Isis::FileName(value));
2132 }
2133 else {
2134 QString message = "Unable to get output cube attributes. Parameter ["
2135 + paramName + "] is not an output. Parameter fileMode = [" + param->fileMode + "].";
2136 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
2137 }
2138 return param->outCubeAtt;
2139}
2140
2141
2152const IsisParameterData *IsisAml::ReturnParam(const QString &paramName) const {
2153 Isis::IString pn = paramName;
2154 pn.UpCase();
2155 int found = 0;
2156 bool exact = false;
2157 const IsisParameterData *param = NULL;
2158 Isis::IString cur_pn;
2159
2160 for(unsigned int g = 0; g < groups.size(); g++) {
2161 for(unsigned int p = 0; p < groups[g].parameters.size(); p++) {
2162 cur_pn = groups[g].parameters[p].name;
2163 cur_pn.UpCase();
2164 if(cur_pn.find(pn) == 0) {
2165 if(cur_pn == pn) {
2166 if(exact) {
2167 QString message = "Parameter [" + paramName + "] is not unique.";
2168 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2169 }
2170 else {
2171 exact = true;
2172 found = 0;
2173 param = &(groups[g].parameters[p]);
2174 }
2175 }
2176 else if(!exact) {
2177 found++;
2178 param = &(groups[g].parameters[p]);
2179 }
2180 }
2181 }
2182 }
2183 if(param == NULL) {
2184 QString message = "Unknown parameter [" + paramName + "].";
2185 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2186 }
2187 else if((found > 1) && (!exact)) {
2188 QString message = "Parameter [" + paramName + "] is not unique.";
2189 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2190 }
2191 return param;
2192}
2193
2194
2206
2207 // Check to make sure the value QString can be converted to the correct type
2208 for(unsigned int i = 0; i < param->values.size(); i++) {
2209 if(param->type == "integer") {
2210 try {
2211 Isis::IString value(param->values[i]);
2212 value.ToInteger();
2213 }
2214 catch(Isis::IException &e) {
2215 QString message = "Unable to convert [" + param->values[i] + "] to an integer,"
2216 " parameter [" + param->name + "].";
2217 throw Isis::IException(e, Isis::IException::User, message, _FILEINFO_);
2218 }
2219 }
2220 else if(param->type == "double") {
2221 try {
2222 Isis::IString value(param->values[i]);
2223 value.ToDouble();
2224 }
2225 catch(Isis::IException &e) {
2226 QString message = "Unable to convert [" + param->values[i] + "] to a double,"
2227 " parameter [" + param->name + "].";
2228 throw Isis::IException(e, Isis::IException::User, message, _FILEINFO_);
2229 }
2230 }
2231 else if(param->type == "boolean") {
2232 QString v = param->values[i].toUpper();
2233
2234 try {
2235 StringToBool(v);
2236 }
2237 catch(Isis::IException &e) {
2238 QString message = "Illegal value for [" + param->name + "], [" + param->values[i] + "].";
2239 throw Isis::IException(e, Isis::IException::User, message, _FILEINFO_);
2240 }
2241 }
2242 else if(param->type == "filename") {
2243 // If this is an output file and a file with this name already exists,
2244 // check user filename customization preferences.
2245 QString value(param->values[i]);
2246 Isis::FileName name(value);
2247 value = name.expanded();
2248 if(name.fileExists() && param->fileMode == "output") {
2249 CheckFileNamePreference(value, param->name);
2250 }
2251 }
2252 // THIS IS CURRENTLY HANDLED IN THE CUBE CLASS, see CubeIoHandler.cpp
2253 // 2010-07-15 Jeannie Walldren
2254 //
2255 // else if(param->type == "cube") {
2256 // Isis::IString value(param->values[i]);
2257 // Isis::FileName name(value);
2258 // value = name.expanded();
2259 // if (name.Exists() && param->fileMode == "output"
2260 // && Isis::Preference::Preferences().findGroup("CubeCustomization").findKeyword("Overwrite")[0] == "Error") {
2261 // QString message = "Invalid output cube for [" + param->name + "]. The cube file [" + value + "] already exists. " +
2262 // "The user preference cube customization group is set to disallow cube overwrites.";
2263 // throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2264 // }
2265 // }
2266 }
2267
2268 // Check the default values if there were no values
2269 if(param->values.size() == 0) {
2270 for(unsigned int i = 0; i < param->defaultValues.size(); i++) {
2271 // Check to make sure the DefaultValue QString can be converted to the
2272 // correct type
2273 if(param->type == "integer") {
2274 try {
2275 Isis::IString value(param->defaultValues[i]);
2276 value.ToInteger();
2277 }
2278 catch(Isis::IException &e) {
2279 QString message = "Unable to convert default [" + param->defaultValues[i] +
2280 "] to an integer, parameter [" + param->name + "].";
2281 throw Isis::IException(e, Isis::IException::Programmer, message, _FILEINFO_);
2282 }
2283 }
2284 else if(param->type == "double") {
2285 try {
2286 Isis::IString value(param->defaultValues[i]);
2287 value.ToDouble();
2288 }
2289 catch(Isis::IException &e) {
2290 QString message = "Unable to convert default [" + param->defaultValues[i] +
2291 "] to a double, parameter [" + param->name + "].";
2292 throw Isis::IException(e, Isis::IException::Programmer, message, _FILEINFO_);
2293 }
2294 }
2295 else if(param->type == "boolean") {
2296 QString v = param->defaultValues[i].toUpper();
2297
2298 try {
2299 StringToBool(v);
2300 }
2301 catch(Isis::IException &e) {
2302 QString message = "Illegal default value for [" + param->name + "], ["
2303 + param->defaultValues[i] + "].";
2304 throw Isis::IException(e, Isis::IException::User, message, _FILEINFO_);
2305 }
2306 }
2307 else if(param->type == "filename") {
2308 // Put something here once we figure out what to do with filenames
2309 QString value(param->defaultValues[i]);
2310 Isis::FileName name(value);
2311 value = name.expanded();
2312 if(name.fileExists() && param->fileMode == "output") {
2313 CheckFileNamePreference(value, param->name);
2314 }
2315 }
2316 }
2317 }
2318
2319 // Check the values against the values list if there is one
2320 if(param->listOptions.size() > 0) {
2321 for(unsigned int i = 0; i < param->values.size(); i++) {
2322 Isis::IString value = param->values[i];
2323 value = value.UpCase();
2324 int partial = 0;
2325 bool exact = false;
2326 for(unsigned int p = 0; p < param->listOptions.size(); p++) {
2327 Isis::IString option = param->listOptions[p].value;
2328 option = option.UpCase();
2329 // Check to see if the value matches the list option exactly
2330 if(value == option) {
2331 // If we already have one exact match then there is an error
2332 if(exact) {
2333 QString message = "Duplicate list options [" +
2334 param->listOptions[p].value +
2335 "] in parameter [" + param->name + "].";
2336 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
2337 }
2338 exact = true;
2339 }
2340 // Check for a partial match
2341 // Compare the shorter of the two (values[i]) to a subQString of the
2342 // longer QString (listOptions[p].value)
2343 else if(option.compare(0, min(value.size(), option.size()),
2344 value, 0, min(value.size(), option.size())) == 0) {
2345 partial++;
2346 }
2347 }
2348 if(!exact && partial == 0) {
2349 QString message = "Value of [" + param->name + "] must be one of [" +
2350 param->listOptions[0].value;
2351 for(unsigned int p = 1; p < param->listOptions.size(); p++) {
2352 message += ", " + param->listOptions[p].value;
2353 }
2354 message += "].";
2355 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2356 }
2357 else if(!exact && partial > 1) {
2358 QString msg = "Value of [" + param->name +
2359 "] does not match a list option uniquely.";
2360 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2361 }
2362 }
2363 }
2364
2365 // Check the values against the minimum
2366 if(param->minimum.length() > 0) {
2367 QString incl = param->minimum_inclusive;
2368 for(unsigned int i = 0; i < param->values.size(); i++) {
2369 if(param->type == "integer") {
2370 QString value(param->values[i]);
2371 int temp = Isis::toInt(value);
2372 value = param->minimum;
2373 int min = Isis::toInt(value);
2374 if(StringToBool(incl) && (temp < min)) {
2375 QString message = "Parameter [" + param->name +
2376 "] must be greater than or equal to [" + param->minimum + "].";
2377 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2378 }
2379 else if(!StringToBool(incl) && (temp <= min)) {
2380 QString message = "Parameter [" + param->name +
2381 "] must be greater than [" + param->minimum + "].";
2382 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2383 }
2384 }
2385 else if(param->type == "double") {
2386 Isis::IString value(param->values[i]);
2387 double temp = value.ToDouble();
2388 value = param->minimum;
2389 double min = value.ToDouble();
2390 if(StringToBool(incl) && (temp < min)) {
2391 QString message = "Parameter [" + param->name +
2392 "] must be greater than or equal to [" + param->minimum + "].";
2393 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2394 }
2395 else if(!StringToBool(incl) && (temp <= min)) {
2396 QString message = "Parameter [" + param->name +
2397 "] must be greater than [" + param->minimum + "].";
2398 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2399 }
2400 }
2401 }
2402 if(param->values.size() == 0) {
2403 for(unsigned int i = 0; i < param->defaultValues.size(); i++) {
2404 if(param->type == "integer") {
2405 Isis::IString value(param->defaultValues[i]);
2406 int temp = value.ToInteger();
2407 value = param->minimum;
2408 int min = value.ToInteger();
2409 if(StringToBool(incl) && (temp < min)) {
2410 QString message = "Parameter [" + param->name +
2411 "] must be greater than or equal to [" + param->minimum + "].";
2412 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2413 }
2414 else if(!StringToBool(incl) && (temp <= min)) {
2415 QString message = "Parameter [" + param->name +
2416 "] must be greater than [" + param->minimum + "].";
2417 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2418 }
2419 }
2420 else if(param->type == "double") {
2421 Isis::IString value(param->defaultValues[i]);
2422 double temp = value.ToDouble();
2423 value = param->minimum;
2424 double min = value.ToDouble();
2425 if(StringToBool(incl) && (temp < min)) {
2426 QString message = "Parameter [" + param->name +
2427 "] must be greater than or equal to [" + param->minimum + "].";
2428 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2429 }
2430 else if(!StringToBool(incl) && (temp <= min)) {
2431 QString message = "Parameter [" + param->name +
2432 "] must be greater than [" + param->minimum + "].";
2433 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2434 }
2435 }
2436 }
2437 }
2438 }
2439
2440 // Check the values against the maximum
2441 if(param->maximum.length() > 0) {
2442 QString incl = param->maximum_inclusive.toLower();
2443 for(unsigned int i = 0; i < param->values.size(); i++) {
2444 if(param->type == "integer") {
2445 QString value(param->values[i]);
2446 int temp = Isis::toInt(value);
2447 value = param->maximum;
2448 int max = Isis::toInt(value);
2449 if(StringToBool(incl) && (temp > max)) {
2450 QString message = "Parameter [" + param->name +
2451 "] must be less than or equal to [" + param->maximum + "].";
2452 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2453 }
2454 else if(!StringToBool(incl) && (temp >= max)) {
2455 QString message = "Parameter [" + param->name +
2456 "] must be less than [" + param->maximum + "].";
2457 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2458 }
2459 }
2460 else if(param->type == "double") {
2461 Isis::IString value(param->values[i]);
2462 double temp = value.ToDouble();
2463 value = param->maximum;
2464 double max = value.ToDouble();
2465 if(StringToBool(incl) && (temp > max)) {
2466 QString message = "Parameter [" + param->name +
2467 "] must be less than or equal to [" + param->maximum + "].";
2468 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2469 }
2470 else if(!StringToBool(incl) && (temp >= max)) {
2471 QString message = "Parameter [" + param->name +
2472 "] must be less than [" + param->maximum + "].";
2473 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2474 }
2475 }
2476 }
2477 if(param->values.size() == 0) {
2478 for(unsigned int i = 0; i < param->defaultValues.size(); i++) {
2479 if(param->type == "integer") {
2480 Isis::IString value(param->defaultValues[i]);
2481 int temp = value.ToInteger();
2482 value = param->maximum;
2483 int max = value.ToInteger();
2484 if(StringToBool(incl) && (temp > max)) {
2485 QString message = "Parameter [" + param->name +
2486 "] must be less than or equal to [" + param->maximum + "].";
2487 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2488 }
2489 else if(!StringToBool(incl) && (temp >= max)) {
2490 QString message = "Parameter [" + param->name +
2491 "] must be less than [" + param->maximum + "].";
2492 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2493 }
2494 }
2495 else if(param->type == "double") {
2496 Isis::IString value(param->defaultValues[i]);
2497 double temp = value.ToDouble();
2498 value = param->maximum;
2499 double max = value.ToDouble();
2500 if(StringToBool(incl) && (temp > max)) {
2501 QString message = "Parameter [" + param->name +
2502 "] must be less than or equal to [" + param->maximum + "].";
2503 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2504 }
2505 else if(!StringToBool(incl) && (temp >= max)) {
2506 QString message = "Parameter [" + param->name +
2507 "] must be less than [" + param->maximum + "].";
2508 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2509 }
2510 }
2511 }
2512 }
2513 }
2514
2515 // Check the value for an odd test
2516 QString odd = param->odd.toLower();
2517
2518 if((odd != "") || StringToBool(odd)) {
2519 if(param->type != "integer") {
2520 QString message = "Parameter [" + param->name +
2521 "] must be of type integer to have an [odd] test.";
2522 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
2523 }
2524 else {
2525 for(unsigned int i = 0; i < param->values.size(); i++) {
2526 Isis::IString value(param->values[i]);
2527 if((value.ToInteger() % 2) != 1) {
2528 QString message = "Value for [" + param->name + "] must be odd.";
2529 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2530 }
2531 }
2532 }
2533 }
2534 return;
2535}
2536
2537
2555void IsisAml::CheckFileNamePreference(QString filename, QString paramname) {
2556 Isis::PvlGroup fileCustomization = Isis::Preference::Preferences().findGroup("FileCustomization");
2557 QString overwritePreference = fileCustomization.findKeyword("Overwrite")[0].simplified().trimmed();
2558 QString temp = overwritePreference;
2559 if(overwritePreference.toUpper() == "ERROR") {
2560 QString message = "Invalid output filename for [" + paramname + "]. The file [" + filename + "] already exists. " +
2561 "The user preference file customization group is set to disallow file overwrites.";
2562 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2563 }
2564 else if(overwritePreference.toUpper() != "ALLOW") { // not set to ERROR or ALLOW
2565 QString message = "Invalid entry in user preference file FileCustomization group.";
2566 message += " Overwrite = [" + temp + "]. Valid values: [Allow] or [Error].";
2567 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2568 }
2569}
2570
2571
2576 for(unsigned int g = 0; g < groups.size(); g++) {
2577 for(unsigned int p = 0; p < groups[g].parameters.size(); p++) {
2578 IsisParameterData *param = &(this->groups[g].parameters[p]);
2579
2580 Verify(param);
2581
2582 // Check the values for inclusive clauses
2583 for(unsigned int item = 0; item < param->include.size(); item++) {
2584 // If this parameter is a boolean and it is true/yes
2585 // all included parameters must have some type of value
2586 if(param->type == "boolean") {
2587 if(((param->values.size() > 0) && StringToBool(param->values[0])) ||
2588 ((param->values.size() == 0) && (param->defaultValues.size() > 0)
2589 && StringToBool(param->defaultValues[0]))) {
2590
2591 const IsisParameterData *param2 = ReturnParam(param->include[item]);
2592 if((param2->values.size()) == 0 &&
2593 (param2->defaultValues.size() == 0) &&
2594 (param2->internalDefault.size() == 0)) {
2595 QString message = "Parameter [" + param2->name +
2596 "] must be used if parameter [" +
2597 param->name + "] equates to true.";
2598 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2599 }
2600 }
2601 }
2602 // This parameter is NOT a boolean but the other one might be
2603 else {
2604 // If the other parameter is a boolean and it is true/yes
2605 // then this parameter must have some type of value
2606 const IsisParameterData *param2 = ReturnParam(param->include[item]);
2607 if(param2->type == "boolean") {
2608 if(((param2->values.size() > 0) && StringToBool(param2->values[0])) ||
2609 ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
2610 StringToBool(param2->defaultValues[0]))) {
2611 if((param->values.size()) == 0 &&
2612 (param->defaultValues.size() == 0) &&
2613 (param->internalDefault.size() == 0)) {
2614 QString message = "Parameter [" + param2->name +
2615 "] must be used if parameter [" +
2616 param->name + "] is used.";
2617 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2618 }
2619 }
2620 }
2621 // Neithter parameter is a boolean so
2622 // If this one has a value the other parameter must have some type of value
2623 else {
2624 if(param->values.size() > 0 &&
2625 param2->values.size() == 0 &&
2626 param2->defaultValues.size() == 0 &&
2627 param2->internalDefault.size() == 0) {
2628 QString message = "Parameter [" + param2->name +
2629 "] must be used if parameter [" +
2630 param->name + "] is used.";
2631 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2632 }
2633 }
2634 }
2635 }
2636 // Check the values for exclusive clauses
2637 for(unsigned int item = 0; item < param->exclude.size(); item++) {
2638 // If this parameter is a boolean that is true/yes
2639 // the other parameter should not have a value
2640 if(param->type == "boolean") {
2641 if(((param->values.size() > 0) && StringToBool(param->values[0])) ||
2642 ((param->values.size() == 0) && (param->defaultValues.size() > 0) &&
2643 StringToBool(param->defaultValues[0]))) {
2644
2645 const IsisParameterData *param2 = ReturnParam(param->exclude[item]);
2646 if(param2->values.size() > 0) {
2647 QString message = "Parameter [" + param2->name +
2648 "] must NOT be used if parameter [" +
2649 param->name + "] equates to true.";
2650 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2651 }
2652 }
2653 }
2654 // This parameter is NOT a boolean but the other one might be
2655 else {
2656 const IsisParameterData *param2 = ReturnParam(param->exclude[item]);
2657 if(param2->type == "boolean") {
2658 if(((param2->values.size() > 0) && StringToBool(param2->values[0])) ||
2659 ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
2660 StringToBool(param2->defaultValues[0]))) {
2661 if(param->values.size() > 0) {
2662 QString message = "Parameter [" + param2->name +
2663 "] must be used if parameter [" +
2664 param->name + "] is used.";
2665 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2666 }
2667 }
2668 }
2669 // Neither parameter is a boolean
2670 else {
2671 if(param->values.size() > 0 && param2->values.size() > 0) {
2672 QString message = "Parameter [" + param2->name +
2673 "] must NOT be used if parameter [" +
2674 param->name + "] is used.";
2675 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2676 }
2677 }
2678 }
2679 }
2680
2681 // Check the values for greaterThan clauses
2682 if(param->values.size() > 0) {
2683 for(unsigned int item = 0; item < param->greaterThan.size(); item++) {
2684 const IsisParameterData *param2 = ReturnParam(param->greaterThan[item]);
2685 if(param2->values.size() != 0) {
2686 double double1, double2;
2687 if(param->type == "integer") {
2688 double1 = (double) GetInteger(param->name);
2689 }
2690 else if(param->type == "double") {
2691 double1 = GetDouble(param->name);
2692 }
2693 else {
2694 QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2695 param->name + "]";
2696 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2697 }
2698
2699 if(param2->type == "integer") {
2700 double2 = GetInteger(param2->name);
2701 }
2702 else if(param2->type == "double") {
2703 double2 = GetDouble(param2->name);
2704 }
2705 else {
2706 QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2707 param->name + "]";
2708 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2709 }
2710
2711 if(double2 >= double1) {
2712 QString message = "Parameter [" + param->name +
2713 "] must be greater than parameter [" +
2714 param2->name + "].";
2715 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2716 }
2717 }
2718 }
2719 }
2720
2721 // Check the values for greaterThanOrEqual clauses
2722 if(param->values.size() > 0) {
2723 for(unsigned int item = 0; item < param->greaterThanOrEqual.size(); item++) {
2724 const IsisParameterData *param2 =
2725 ReturnParam(param->greaterThanOrEqual[item]);
2726 if(param2->values.size() != 0) {
2727 double double1, double2;
2728 if(param->type == "integer") {
2729 double1 = (double) GetInteger(param->name);
2730 }
2731 else if(param->type == "double") {
2732 double1 = GetDouble(param->name);
2733 }
2734 else {
2735 QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2736 param->name + "]";
2737 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2738 }
2739
2740 if(param2->type == "integer") {
2741 double2 = GetInteger(param2->name);
2742 }
2743 else if(param2->type == "double") {
2744 double2 = GetDouble(param2->name);
2745 }
2746 else {
2747 QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2748 param->name + "]";
2749 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2750 }
2751
2752 if(double2 > double1) {
2753 QString message = "Parameter [" + param->name +
2754 "] must be greater than or equal to parameter [" +
2755 param2->name + "].";
2756 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2757 }
2758 }
2759 }
2760 }
2761 // Check the values for lessThan clauses
2762 if(param->values.size() > 0) {
2763 for(unsigned int item = 0; item < param->lessThan.size(); item++) {
2764 const IsisParameterData *param2 = ReturnParam(param->lessThan[item]);
2765 if(param2->values.size() != 0) {
2766 double double1, double2;
2767 if(param->type == "integer") {
2768 double1 = (double) GetInteger(param->name);
2769 }
2770 else if(param->type == "double") {
2771 double1 = GetDouble(param->name);
2772 }
2773 else {
2774 QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2775 param->name + "]";
2776 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2777 }
2778
2779 if(param2->type == "integer") {
2780 double2 = GetInteger(param2->name);
2781 }
2782 else if(param2->type == "double") {
2783 double2 = GetDouble(param2->name);
2784 }
2785 else {
2786 QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2787 param->name + "]";
2788 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2789 }
2790
2791 if(double2 <= double1) {
2792 QString message = "Parameter [" + param->name +
2793 "] must be less than parameter [" +
2794 param2->name + "].";
2795 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2796 }
2797 }
2798 }
2799 }
2800
2801 // Check the values for lessThanOrEqual clauses
2802 if(param->values.size() > 0) {
2803 for(unsigned int item = 0; item < param->lessThanOrEqual.size(); item++) {
2804 const IsisParameterData *param2 =
2805 ReturnParam(param->lessThanOrEqual[item]);
2806 if(param2->values.size() != 0) {
2807 double double1, double2;
2808 if(param->type == "integer") {
2809 double1 = (double) GetInteger(param->name);
2810 }
2811 else if(param->type == "double") {
2812 double1 = GetDouble(param->name);
2813 }
2814 else {
2815 QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2816 param->name + "]";
2817 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2818 }
2819
2820 if(param2->type == "integer") {
2821 double2 = GetInteger(param2->name);
2822 }
2823 else if(param2->type == "double") {
2824 double2 = GetDouble(param2->name);
2825 }
2826 else {
2827 QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2828 param->name + "]";
2829 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2830 }
2831
2832 if(double2 < double1) {
2833 QString message = "Parameter [" + param->name +
2834 "] must be less than or equal to parameter [" +
2835 param2->name + "].";
2836 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2837 }
2838 }
2839 }
2840 }
2841
2842 // Check the values for notEqual clauses
2843 if(param->values.size() > 0) {
2844 for(unsigned int item = 0; item < param->notEqual.size(); item++) {
2845 const IsisParameterData *param2 = ReturnParam(param->notEqual[item]);
2846 if(param2->values.size() != 0) {
2847 double double1, double2;
2848 if(param->type == "integer") {
2849 double1 = (double) GetInteger(param->name);
2850 }
2851 else if(param->type == "double") {
2852 double1 = GetDouble(param->name);
2853 }
2854 else {
2855 QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2856 param->name + "]";
2857 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2858 }
2859
2860 if(param2->type == "integer") {
2861 double2 = GetInteger(param2->name);
2862 }
2863 else if(param2->type == "double") {
2864 double2 = GetDouble(param2->name);
2865 }
2866 else {
2867 QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2868 param->name + "]";
2869 throw Isis::IException(Isis::IException::Programmer, msg, _FILEINFO_);
2870 }
2871
2872 if(double2 == double1) {
2873 QString message = "Parameter [" + param->name +
2874 "] must NOT be equal to parameter [" +
2875 param2->name + "].";
2876 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2877 }
2878 }
2879 }
2880 }
2881
2882 // If this parameter has a value, and a list/option/exclude, make sure
2883 // the excluded parameter has NO value
2884 if(((param->values.size() > 0) || (param->defaultValues.size())) > 0) {
2885 for(unsigned int o2 = 0; o2 < param->listOptions.size(); o2++) {
2886 QString value, option;
2887 if(param->type == "string" || param->type == "combo") {
2888 value = GetString(param->name);
2889 value = value.toUpper();
2890 option = param->listOptions[o2].value;
2891 option = option.toUpper();
2892 }
2893 else if(param->type == "integer") {
2894 value = GetAsString(param->name);
2895 value = value.trimmed();
2896 option = param->listOptions[o2].value;
2897 option = option.trimmed();
2898 }
2899 if(value == option) {
2900 for(unsigned int e2 = 0; e2 < param->listOptions[o2].exclude.size(); e2++) {
2901 const IsisParameterData *param2 =
2902 ReturnParam(param->listOptions[o2].exclude[e2]);
2903 if(param2->values.size() > 0) {
2904 QString message = "Parameter [" + param2->name +
2905 "] can not be entered if parameter [" +
2906 param->name + "] is equal to [" +
2907 value + "]";
2908 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2909 }
2910 }
2911 }
2912 }
2913 }
2914
2915 // If this parameter has a value, and a list/option/include, make sure
2916 // the included parameter has a value
2917 if(((param->values.size() > 0) || (param->defaultValues.size())) > 0) {
2918 for(unsigned int o2 = 0; o2 < param->listOptions.size(); o2++) {
2919 QString value, option;
2920 if(param->type == "string" || param->type == "combo") {
2921 value = GetString(param->name);
2922 value = value.toUpper();
2923 option = param->listOptions[o2].value;
2924 option = option.toUpper();
2925 }
2926 else if(param->type == "integer") {
2927 value = GetAsString(param->name);
2928 value = value.trimmed();
2929 option = param->listOptions[o2].value;
2930 option = option.trimmed();
2931 }
2932 if(value == option) {
2933 for(unsigned int e2 = 0; e2 < param->listOptions[o2].include.size(); e2++) {
2934 const IsisParameterData *param2 =
2935 ReturnParam(param->listOptions[o2].include[e2]);
2936 if((param2->values.size() == 0) &&
2937 (param2->defaultValues.size() == 0)) {
2938 QString message = "Parameter [" + param2->name +
2939 "] must be entered if parameter [" +
2940 param->name + "] is equal to [" +
2941 value + "]";
2942 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2943 }
2944 }
2945 }
2946 }
2947 }
2948
2949 // If this parameter has no value, default value or internal default
2950 // value then it must be excluded by some other parameter with an
2951 // exclude or list/option/exclude
2952 // OR
2953 // it must include a boolean which is false
2954 if((param->values.size() == 0) && (param->defaultValues.size() == 0) &&
2955 (param->internalDefault.size() == 0)) {
2956 bool excluded = false;
2957 // See if another parameter has a list option excluding this parameter
2958 for(unsigned int g2 = 0; g2 < groups.size(); g2++) {
2959 for(unsigned int p2 = 0; p2 < groups[g2].parameters.size(); p2++) {
2960 for(unsigned int o2 = 0;
2961 o2 < groups[g2].parameters[p2].listOptions.size(); o2++) {
2962 for(unsigned int e2 = 0;
2963 e2 < groups[g2].parameters[p2].listOptions[o2].exclude.size();
2964 e2++) {
2965 QString excl =
2966 this->groups[g2].parameters[p2].listOptions[o2].exclude[e2];
2967 if(excl == param->name) {
2968 excluded = true;
2969 break;
2970 }
2971 }
2972 }
2973
2974 if(groups[g2].parameters[p2].type == "boolean") {
2975 const IsisParameterData *param2 = &groups[g2].parameters[p2];
2976 if(((param2->values.size() > 0) && !StringToBool(param2->values[0])) ||
2977 ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
2978 !StringToBool(param2->defaultValues[0]))) {
2979 for(unsigned int e2 = 0; e2 < groups[g2].parameters[p2].include.size();
2980 e2++) {
2981 QString incl =
2982 this->groups[g2].parameters[p2].include[e2];
2983 if(incl == param->name) {
2984 excluded = true;
2985 }
2986 }
2987 }
2988 else if(((param2->values.size() > 0) && StringToBool(param2->values[0])) ||
2989 ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
2990 StringToBool(param2->defaultValues[0]))) {
2991 for(unsigned int e2 = 0; e2 < groups[g2].parameters[p2].exclude.size();
2992 e2++) {
2993 QString excl =
2994 this->groups[g2].parameters[p2].exclude[e2];
2995 if(excl == param->name) {
2996 excluded = true;
2997 }
2998 }
2999 }
3000 }
3001 }
3002 }
3003
3004 // See if this parameter excludes any other (this implies the other
3005 // one also excludes this one too
3006 for(unsigned int item = 0; item < param->exclude.size(); item++) {
3007 const IsisParameterData *param2 = ReturnParam(param->exclude[item]);
3008 if((param2->values.size() != 0) ||
3009 (param2->defaultValues.size() != 0) ||
3010 (param2->internalDefault.size() != 0)) {
3011 if(param2->type != "boolean") {
3012 excluded = true;
3013 }
3014 else {
3015 if(((param2->values.size() > 0) && !StringToBool(param2->values[0])) ||
3016 ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
3017 !StringToBool(param2->defaultValues[0]))) {
3018 excluded = true;
3019 }
3020 }
3021 }
3022 }
3023
3024 // See if this parameter includes a boolean that is false
3025 // then it doesn't need a value
3026 for(unsigned int item = 0; item < param->include.size(); item++) {
3027 const IsisParameterData *param2 = ReturnParam(param->include[item]);
3028 if(param2->type == "boolean") {
3029 if(((param2->values.size() > 0) && !StringToBool(param2->values[0])) ||
3030 ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
3031 !StringToBool(param2->defaultValues[0]))) {
3032 excluded = true;
3033 }
3034 }
3035 }
3036
3037 if(!excluded) {
3038 QString message = "Parameter [" + param->name + "] must be entered.";
3039 throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
3040 }
3041 }
3042 }
3043 }
3044}
3045
3046
3056bool IsisAml::StringToBool(QString value) const {
3057
3058 value = value.toUpper();
3059 if(value == "") {
3060 return false;
3061 }
3062 else if(!value.compare("NO")) {
3063 return false;
3064 }
3065 else if(!value.compare("FALSE")) {
3066 return false;
3067 }
3068 else if(!value.compare("F")) {
3069 return false;
3070 }
3071 else if(!value.compare("N")) {
3072 return false;
3073 }
3074 else if(!value.compare("YES")) {
3075 return true;
3076 }
3077 else if(!value.compare("TRUE")) {
3078 return true;
3079 }
3080 else if(!value.compare("Y")) {
3081 return true;
3082 }
3083 else if(!value.compare("T")) {
3084 return true;
3085 }
3086 else {
3087 QString message = "Invalid boolean value [" + value + "].";
3088 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
3089 }
3090 return false;
3091}
3092
3093
3100 Isis::PvlGroup group("UserParameters");
3101
3102 // Add appropriate keywords
3103 for(unsigned int g = 0; g < groups.size(); g++) {
3104 for(unsigned int p = 0; p < groups[g].parameters.size(); p++) {
3105 const IsisParameterData *param = ReturnParam(ParamName(g, p));
3106 // If this param has a value add it to the command line
3107 if(param->values.size() > 0) {
3108 Isis::PvlKeyword paramKeyword(param->name);
3109
3110 for(unsigned int value = 0; value < param->values.size(); value++) {
3111 paramKeyword.addValue(param->values[value]);
3112 }
3113
3114 group += paramKeyword;
3115 }
3116
3117 // Or if it has a default value add it to the command line
3118 else if(param->defaultValues.size() > 0) {
3119 Isis::PvlKeyword paramKeyword(param->name);
3120
3121 for(unsigned int value = 0;
3122 value < param->defaultValues.size();
3123 value++) {
3124 paramKeyword.addValue(param->defaultValues[value]);
3125 }
3126
3127 group += paramKeyword;
3128 }
3129 }
3130 }
3131 // Remove excluded keywords
3132 for(unsigned int g = 0; g < groups.size(); g++) {
3133 for(unsigned int p = 0; p < groups[g].parameters.size(); p++) {
3134 const IsisParameterData *param = ReturnParam(ParamName(g, p));
3135
3136 if(((param->values.size() > 0) || (param->defaultValues.size())) > 0) {
3137 for(unsigned int o2 = 0; o2 < param->listOptions.size(); o2++) {
3138 Isis::IString value, option;
3139 if(param->type == "string" || param->type == "combo") {
3140 value = GetAsString(param->name);
3141 value = value.UpCase();
3142 option = param->listOptions[o2].value;
3143 option = option.UpCase();
3144 }
3145 else if(param->type == "integer") {
3146 value = GetAsString(param->name);
3147 value = value.Trim("\n\r\t\f\v\b");
3148 option = param->listOptions[o2].value;
3149 option = option.Trim("\n\r\t\f\v\b");
3150 }
3151 if(value == option) {
3152 for(unsigned int e2 = 0; e2 < param->listOptions[o2].exclude.size(); e2++) {
3153 const IsisParameterData *param2 =
3154 ReturnParam(param->listOptions[o2].exclude[e2]);
3155 if(group.hasKeyword(param2->name)) {
3156 group.deleteKeyword(param2->name);
3157 }
3158 }
3159 }
3160 }
3161 }
3162 }
3163 }
3164
3165 cont.clear();
3166 cont.addGroup(group);
3167 return;
3168}
3169
3170
3176QString IsisAml::Version() const {
3177 QString st = "000-00-00";
3178 for(unsigned int i = 0; i < changes.size(); i++) {
3179 if(changes[i].date > st) st = changes[i].date;
3180 }
3181 return st;
3182}
3183
3184
3192void IsisAml::StartParser(const char *xmlfile) {
3193
3194 // Initialize the XML system
3195 try {
3196 XERCES::XMLPlatformUtils::Initialize();
3197 }
3198
3199 catch(const XERCES::XMLException &toCatch) {
3200
3201 QString message = "Error during XML parser initialization" +
3202 (QString)XERCES::XMLString::transcode(toCatch.getMessage());
3203 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
3204 return;
3205 }
3206
3207 //
3208 // Create a SAX parser object. Then, set it to validate for an IsisAml file
3209 //
3210 parser = XERCES::XMLReaderFactory::createXMLReader();
3211
3212// SAX2XMLReader::ValSchemes valScheme = SAX2XMLReader::Val_Auto;
3213 XERCES::SAX2XMLReader::ValSchemes valScheme = XERCES::SAX2XMLReader::Val_Never;
3214 if(valScheme == XERCES::SAX2XMLReader::Val_Auto) {
3215 parser->setFeature(XERCES::XMLString::transcode("http://xml.org/sax/features/validation"), true);
3216 parser->setFeature(XERCES::XMLString::transcode("http://apache.org/xml/features/validation/dynamic"), true);
3217 }
3218 else if(valScheme == XERCES::SAX2XMLReader::Val_Never) {
3219 parser->setFeature(XERCES::XMLString::transcode("http://xml.org/sax/features/validation"), false);
3220 }
3221
3222 else if(valScheme == XERCES::SAX2XMLReader::Val_Always) {
3223 parser->setFeature(XERCES::XMLString::transcode("http://xml.org/sax/features/validation"), true);
3224 parser->setFeature(XERCES::XMLString::transcode("http://apache.org/xml/features/validation/dynamic"), false);
3225 }
3226
3227// bool doSchema = true;
3228 bool doSchema = false;
3229 parser->setFeature(XERCES::XMLString::transcode("http://apache.org/xml/features/validation/schema"), doSchema);
3230
3231 bool schemaFullChecking = false;
3232 parser->setFeature(XERCES::XMLString::transcode("http://apache.org/xml/features/validation/schema-full-checking"), schemaFullChecking);
3233
3234 // Create the handler object for an application
3235 // Then parse the file
3236 char *encodingName = const_cast<char *>("LATIN1");
3237 bool expandNamespaces = false ;
3238
3239 try {
3240 IsisAmlData *mydata = this;
3241 appHandler = new IsisXMLApplication(encodingName, expandNamespaces, parser, mydata);
3242 parser->parse(xmlfile);
3243 }
3244 catch (const XERCES::XMLException &toCatch) {
3245 QString message = "Error in application XML file: " +
3246 (QString)XERCES::XMLString::transcode(toCatch.getMessage());
3247 throw Isis::IException(Isis::IException::Programmer, message, _FILEINFO_);
3248 XERCES::XMLPlatformUtils::Terminate();
3249 return;
3250 }
3251 // This Exception is thrown whenever an error is encountered while parsing an XML file.
3252 // Stacked error messages are generated containing the file path and additional data about where the error occurred.
3253 catch (Isis::IException &e) {
3254 QString filePath = (QString) xmlfile;
3255 QString previousErrorMessage = (QString) e.toString();
3256 QString additionalErrorMessage = "Error while parsing application XML file [" + filePath + "]";
3257
3258 throw Isis::IException(Isis::IException::Programmer, additionalErrorMessage + "\n" + previousErrorMessage, _FILEINFO_);
3259 XERCES::XMLPlatformUtils::Terminate();
3260 return;
3261 }
3262
3263 // Delete the parser
3264 delete parser;
3265 XERCES::XMLPlatformUtils::Terminate();
3266 delete appHandler;
3267 return;
3268}
void addAttributes(const FileName &fileNameWithAtts)
Append the attributes found in the filename to these cube attributes.
void setAttributes(const FileName &fileName)
Replaces the current attributes with the attributes in the given file name.
Manipulate and parse attributes of input cube filenames.
Manipulate and parse attributes of output cube filenames.
File name manipulation and expansion.
Definition FileName.h:100
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
QString toString() const
Returns a string representation of this exception.
Adds specific functionality to C++ strings.
Definition IString.h:165
int ToInteger() const
Returns the object string as an integer.
Definition IString.cpp:718
IString Trim(const std::string &chars)
Removes characters from the beginning and end of the IString.
Definition IString.cpp:525
IString UpCase()
Converst any lower case characters in the object IString with uppercase characters.
Definition IString.cpp:617
IString DownCase()
Converts all upper case letters in the object IString into lower case characters.
Definition IString.cpp:644
double ToDouble() const
Returns the floating point value the IString represents.
Definition IString.cpp:799
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
void deleteKeyword(const QString &name)
Remove a specified keyword.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
void addValue(QString value, QString unit="")
Adds a value with units.
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
void clear()
Remove everything from the current PvlObject.
Definition PvlObject.h:341
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition PvlObject.h:186
double GetDouble(const QString &paramName) const
Allows the retrieval of a value for a parameter of type "double".
Definition IsisAml.cpp:966
IsisXMLApplication * appHandler
The application handler.
Definition IsisAml.h:350
void CommandLine(Isis::Pvl &lab) const
Creates a QString which could be used as a command line.
Definition IsisAml.cpp:3099
QString ParamOdd(const int &group, const int &param) const
Returns whether the selected parameter has a restriction on odd values or not.
Definition IsisAml.cpp:1461
int ParamExcludeSize(const int &group, const int &param) const
Returns the number of parameters excluded in this parameter's exclusions.
Definition IsisAml.cpp:1894
Isis::CubeAttributeInput & GetInputAttribute(const QString &paramName)
Gets the attributes for an input cube.
Definition IsisAml.cpp:2059
int GetInteger(const QString &paramName) const
Allows the retrieval of a value for a parameter of type "integer".
Definition IsisAml.cpp:883
QString ParamLessThan(const int &group, const int &param, const int &great) const
Returns the name of the specified lessThan parameter.
Definition IsisAml.cpp:1575
QString ParamLessThanOrEqual(const int &group, const int &param, const int &les) const
Returns the name of the specified lessThanOrEqual parameter.
Definition IsisAml.cpp:1591
QString ParamBrief(const int &group, const int &param) const
Returns the brief description of a parameter in a specified group.
Definition IsisAml.cpp:1376
QString ParamListInclude(const int &group, const int &param, const int &option, const int &include) const
Returns the parameter name to be included if this option is selected.
Definition IsisAml.cpp:1879
QString ParamDescription(const int &group, const int &param) const
Returns the long description of a parameter in a specified group.
Definition IsisAml.cpp:1390
bool StringToBool(QString value) const
Returns a boolean value based on the QString contents.
Definition IsisAml.cpp:3056
void PutCubeName(const QString &paramName, const QString &value)
Allows the insertion of a value for a parameter of type "cubename".
Definition IsisAml.cpp:273
int ParamListIncludeSize(const int &group, const int &param, const int &option) const
Returns the number of items in a parameters list include section.
Definition IsisAml.cpp:1863
void PutBoolean(const QString &paramName, const bool &value)
Allows the insertion of a value for a parameter of type "boolean".
Definition IsisAml.cpp:479
QString GetFileName(const QString &paramName, QString extension="") const
Allows the retrieval of a value for a parameter of type "filename".
Definition IsisAml.cpp:641
bool WasEntered(const QString &paramName) const
Returns a true if the parameter has a value, and false if it does not.
Definition IsisAml.cpp:2020
QString ParamListValue(const int &group, const int &param, const int &option) const
Returns the option value for a specific option to a parameter.
Definition IsisAml.cpp:1783
int NumGroups() const
Returns the number of groups found in the XML.
Definition IsisAml.cpp:1164
int ParamListExcludeSize(const int &group, const int &param, const int &option) const
Returns the number of items in a parameters list exclude section.
Definition IsisAml.cpp:1831
QString PixelType(const int &group, const int &param) const
Returns the default pixel type from the XML.
Definition IsisAml.cpp:1920
QString GetString(const QString &paramName) const
Allows the retrieval of a value for a parameter of type "string".
Definition IsisAml.cpp:769
bool GetBoolean(const QString &paramName) const
Allows the retrieval of a value for a parameter of type "boolean".
Definition IsisAml.cpp:1049
nlohmann::json GetParams()
Creates a json object which could be used as a command line.
Definition IsisAml.cpp:1205
int ParamGreaterThanSize(const int &group, const int &param) const
Returns the number of values in the parameters greater than list.
Definition IsisAml.cpp:1475
QString ParamNotEqual(const int &group, const int &param, const int &notEq) const
Returns the name of the specified notEqual parameter.
Definition IsisAml.cpp:1607
void PutInteger(const QString &paramName, const int &value)
Allows the insertion of a value for a parameter of type "integer".
Definition IsisAml.cpp:311
int HelpersSize(const int &group, const int &param) const
Returns the number of helpers the parameter has.
Definition IsisAml.cpp:1933
QString ParamGreaterThanOrEqual(const int &group, const int &param, const int &great) const
Returns the name of the specified greaterThanOrEqual parameter.
Definition IsisAml.cpp:1559
void CreatePVL(Isis::Pvl &pvlDef, QString guiGrpName, QString pvlObjName, QString pvlGrpName, std::vector< QString > &exclude)
Create Pvl with the parameters in a user defined group given the Pvl object and group name.
Definition IsisAml.cpp:1273
QString GetCubeName(const QString &paramName, QString extension="") const
Retrieves of a value for a parameter of type "cubename".
Definition IsisAml.cpp:724
QString ParamMaximumInclusive(const int &group, const int &param) const
Returns whether the maximum value is inclusive or not.
Definition IsisAml.cpp:1446
QString Description() const
Returns the full description of the program.
Definition IsisAml.cpp:1154
QString ParamType(const int &group, const int &param) const
Returns the parameter type of a parameter in a specified group.
Definition IsisAml.cpp:1654
int ParamListSize(const int &group, const int &param) const
Returns the number of options in the specified parameter's list.
Definition IsisAml.cpp:1769
int NumParams(const int &) const
Returns the number of parameters in a group.
Definition IsisAml.cpp:1349
QString Version() const
Returns the application version date.
Definition IsisAml.cpp:3176
QString GroupName(const int &group) const
Returns the group name of group[index].
Definition IsisAml.cpp:1176
QString ParamExclude(const int &group, const int &param, const int &exclude) const
Returns the name of the specified excluded parameter.
Definition IsisAml.cpp:1623
QString HelperFunction(const int &group, const int &param, const int &helper) const
Returns the name of the helper function.
Definition IsisAml.cpp:1962
QString HelperButtonName(const int &group, const int &param, const int &helper) const
Returns the name of the helper button.
Definition IsisAml.cpp:1947
QString Brief() const
Returns the brief description of the program.
Definition IsisAml.cpp:1144
const IsisParameterData * ReturnParam(const QString &paramName) const
Returns a pointer to a parameter whose name starts with paramName.
Definition IsisAml.cpp:2152
IsisAml(const QString &xmlfile)
Constructs an IsisAml object and internalizes the XML data in the given file name.
Definition IsisAml.cpp:41
QString ParamFilter(const int &group, const int &param) const
Returns the parameter filter for a parameter in a specified group.
Definition IsisAml.cpp:1708
QString ParamListExclude(const int &group, const int &param, const int &option, const int &exclude) const
Returns the parameter name to be excluded if this option is selected.
Definition IsisAml.cpp:1847
int ParamLessThanOrEqualSize(const int &group, const int &param) const
Returns the number of values in the parameters less than or equal list.
Definition IsisAml.cpp:1515
QString ParamListBrief(const int &group, const int &param, const int &option) const
Returns the brief description for a specific option to a parameter.
Definition IsisAml.cpp:1799
QString ParamListDescription(const int &group, const int &param, const int &option) const
Returns the full description for a specific option to a parameter.
Definition IsisAml.cpp:1815
QString ParamDefault(const int &group, const int &param) const
Returns the default for a parameter in a specified group.
Definition IsisAml.cpp:1668
int ParamLessThanSize(const int &group, const int &param) const
Returns the number of values in the parameters less than list.
Definition IsisAml.cpp:1502
QString HelperBrief(const int &group, const int &param, const int &helper) const
Returns the brief description of the helper button.
Definition IsisAml.cpp:1977
QString ParamInclude(const int &group, const int &param, const int &include) const
Returns the name of the specified included parameter.
Definition IsisAml.cpp:1639
QString GetAsString(const QString &paramName) const
Allows the retrieval of a value for a parameter of any type.
Definition IsisAml.cpp:570
int GroupIndex(const QString &grpName) const
Given the group name get its index in group array.
Definition IsisAml.cpp:1191
void PutDouble(const QString &paramName, const double &value)
Allows the insertion of a value for a parameter of type "double".
Definition IsisAml.cpp:395
int ParamGreaterThanOrEqualSize(const int &group, const int &param) const
Returns the number of values in the parameters greater than or equal list.
Definition IsisAml.cpp:1488
QString ParamInternalDefault(const int &group, const int &param) const
Returns the internal default for a parameter in a specified group.
Definition IsisAml.cpp:1688
int ParamNotEqualSize(const int &group, const int &param) const
Returns the number of values in the not equal list.
Definition IsisAml.cpp:1529
QString ProgramName() const
Returns the Program name.
Definition IsisAml.cpp:1133
int ParamIncludeSize(const int &group, const int &param) const
Returns the number of parameters included in this parameter's inclusions.
Definition IsisAml.cpp:1907
QString ParamMinimumInclusive(const int &group, const int &param) const
Returns whether the minimum value is inclusive or not.
Definition IsisAml.cpp:1432
void PutString(const QString &paramName, const QString &value)
Allows the insertion of a value for any parameter.
Definition IsisAml.cpp:131
QString ParamGreaterThan(const int &group, const int &param, const int &great) const
Returns the name of the specified greaterThan parameter.
Definition IsisAml.cpp:1543
QString ParamMinimum(const int &group, const int &param) const
Returns the minimum value of a parameter in a specified group.
Definition IsisAml.cpp:1404
QString ParamFileMode(const int &group, const int &param) const
Returns the file mode for a parameter in a specified group.
Definition IsisAml.cpp:1748
XERCES::SAX2XMLReader * parser
The XML file parser.
Definition IsisAml.h:348
Isis::CubeAttributeOutput & GetOutputAttribute(const QString &paramName)
Gets the attributes for an output cube.
Definition IsisAml.cpp:2105
void CheckFileNamePreference(QString filename, QString paramname)
This method checks whether the user preferences are set to allow overwrites of existing files.
Definition IsisAml.cpp:2555
void Clear(const QString &paramName)
Clears the value(s) in the named parameter.
Definition IsisAml.cpp:2037
void Verify(const IsisParameterData *param)
Throws an Isis::iExceptionXxxxxxxx if the parameter value(s) is invalid.
Definition IsisAml.cpp:2205
QString ParamPath(const int &group, const int &param) const
Returns the default path for a filename/cube parameter.
Definition IsisAml.cpp:1728
QString HelperDescription(const int &group, const int &param, const int &helper) const
Returns the long description of the helper button.
Definition IsisAml.cpp:1992
void StartParser(const char *xmlfile)
Starts parsing an application xml file.
Definition IsisAml.cpp:3192
void VerifyAll()
Verify all parameters.
Definition IsisAml.cpp:2575
QString ParamName(const int &group, const int &param) const
Returns the parameter name.
Definition IsisAml.cpp:1362
QString HelperIcon(const int &group, const int &param, const int &helper) const
Returns the name of the icon for the helper button.
Definition IsisAml.cpp:2007
bool IsParamInPvlInclude(QString &paramName, std::vector< QString > &exclude)
Verify whether Parameter name is in the Include list Used in creation of DefFile.
Definition IsisAml.cpp:1331
void PutAsString(const QString &paramName, const QString &value)
Allows the insertion of a value for any parameter.
Definition IsisAml.cpp:68
~IsisAml()
Destructs an IsisAml object.
Definition IsisAml.cpp:48
void PutFileName(const QString &paramName, const QString &value)
Allows the insertion of a value for a parameter of type "filename".
Definition IsisAml.cpp:198
QString ParamMaximum(const int &group, const int &param) const
Returns the maximum value of a parameter in a specified group.
Definition IsisAml.cpp:1418
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition IString.cpp:93
bool toBool(const QString &string)
Global function to convert from a string to a boolean.
Definition IString.cpp:38
Namespace for the standard library.