Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

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