USGS

Isis 3.0 Object Programmers' Reference

Home

IsisAml.cpp
Go to the documentation of this file.
1 
24 #include <sstream>
25 #include <xercesc/util/PlatformUtils.hpp>
26 #include <xercesc/util/TransService.hpp>
27 #include <xercesc/sax2/XMLReaderFactory.hpp>
28 
29 #include "FileName.h"
30 #include "IException.h"
31 #include "IsisAml.h"
32 #include "IsisXMLChTrans.h"
33 #include "IString.h"
34 #include "Preference.h"
35 #include "Pvl.h"
36 #include "PvlGroup.h"
37 #include "PvlKeyword.h"
38 #include "PvlObject.h"
39 
40 using namespace std;
41 
46 namespace XERCES = XERCES_CPP_NAMESPACE;
47 
54 IsisAml::IsisAml(const QString &xmlfile) {
55  StartParser(xmlfile.toAscii().data());
56 }
57 
62 }
63 
81 void IsisAml::PutAsString(const QString &paramName,
82  const QString &value) {
83 
84  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
85 
86  if(param->values.size() > 0) {
87  QString message = "A value for this parameter [" + paramName + "] has "
88  "already been entered.";
90  }
91 
92  param->values.clear();
93  param->values.push_back(value);
94 
95 }
96 
109 void IsisAml::PutAsString(const QString &paramName,
110  const vector<QString> &value) {
111 
112  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
113 
114  if(param->values.size() > 0) {
115  QString message = "A value for this parameter [" + paramName + "] has "
116  "already been entered.";
118  }
119 
120  param->values.resize(value.size());
121  param->values = value;
122 
123 }
124 
125 
126 // Public: Sets the value member of a parameter of type QString whose name
127 // starts with paramName
128 
144 void IsisAml::PutString(const QString &paramName, const QString &value) {
145 
146  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
147 
148  if(param->type != "string" && param->type != "combo") {
149  QString message = "Parameter [" + paramName + "] is not a string.";
151  }
152 
153  if(param->values.size() > 0) {
154  QString message = "A value for this parameter [" + paramName + "] has "
155  "already been saved (possibly by IsisGui). If you need to "
156  "change the value use \"Clear\" before the Put.";
158  }
159 
160  param->values.clear();
161  param->values.push_back(value);
162 
163  Verify(param);
164 }
165 
166 
167 // Public: Sets the value member of a parameter of type QString whose name
168 // starts with paramName
176 void IsisAml::PutString(const QString &paramName,
177  const vector<QString> &value) {
178 
179  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
180 
181  if(param->type != "string" && param->type != "combo") {
182  QString message = "Parameter [" + paramName + "] is not a string.";
184  }
185 
186  if(param->values.size() > 0) {
187  QString message = "A value for this parameter [" + paramName + "] has "
188  "already been saved (possibly by IsisGui). If you need to "
189  "change the value use \"Clear\" before the Put.";
191  }
192 
193  param->values.resize(value.size());
194  param->values = value;
195 
196  Verify(param);
197 }
198 
199 
200 // Public: Sets the value member of a parameter of type filename whose name
201 // starts with paramName
202 
211 void IsisAml::PutFileName(const QString &paramName,
212  const QString &value) {
213 
214  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
215 
216  if((param->type != "filename") && (param->type != "cube")) {
217  QString message = "Parameter [" + paramName + "] is not a filename.";
219  }
220 
221  if(param->values.size() > 0) {
222  QString message = "A value for this parameter [" + paramName + "] has "
223  "already been saved (possibly by IsisGui). If you need to "
224  "change the value use \"Clear\" before the Put.";
226  }
227 
228  param->values.clear();
229  param->values.push_back(value);
230 
231  Verify(param);
232 }
233 
234 
235 // Public: Sets the value member of a parameter of type filename whose name
236 // starts with paramName
237 
253 void IsisAml::PutFileName(const QString &paramName,
254  const vector<QString> &value) {
255 
256  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
257 
258  if((param->type != "filename") && (param->type != "cube")) {
259  QString message = "Parameter [" + paramName + "] is not a filename.";
261  }
262 
263  if(param->values.size() > 0) {
264  QString message = "A value for this parameter [" + paramName + "] has "
265  "already been saved (possibly by IsisGui). If you need to "
266  "change the value use \"Clear\" before the Put.";
268  }
269 
270  param->values.resize(value.size());
271  param->values = value;
272 
273  Verify(param);
274 }
275 
276 
277 // Public: Sets the value member of a parameter of type integer whose name
278 // starts with paramName
279 
291 void IsisAml::PutInteger(const QString &paramName,
292  const int &value) {
293 
294  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
295 
296  if(param->type != "integer") {
297  QString message = "Parameter [" + paramName + "] is not an integer.";
299  }
300 
301  if(param->values.size() > 0) {
302  QString message = "A value for this parameter [" + paramName + "] has "
303  "already been saved (possibly by IsisGui). If you need to "
304  "change the value use \"Clear\" before the Put.";
306  }
307 
308  param->values.clear();
309  param->values.push_back(Isis::toString(value));
310 
311  Verify(param);
312 }
313 
314 
315 // Public: Sets the value member of a parameter of type integer whose name
316 // starts with paramName
317 
332 void IsisAml::PutInteger(const QString &paramName,
333  const vector<int> &value) {
334 
335  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
336 
337  if(param->type != "integer") {
338  QString message = "Parameter [" + paramName + "] is not an integer.";
340  }
341 
342  if(param->values.size() > 0) {
343  QString message = "A value for this parameter [" + paramName + "] has "
344  "already been saved (possibly by IsisGui). If you need to "
345  "change the value use \"Clear\" before the Put.";
347  }
348 
349  param->values.resize(value.size());
350  for(unsigned int i = 0; i < value.size(); i++) {
351  param->values[i] = Isis::toString(value[i]);
352  }
353 
354  Verify(param);
355 }
356 
357 
358 
359 
360 // Public: Sets the value member of a parameter of type double whose name
361 // starts with paramName
377 void IsisAml::PutDouble(const QString &paramName,
378  const double &value) {
379 
380  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
381 
382  if(param->type != "double") {
383  QString message = "Parameter [" + paramName + "] is not a double.";
385  }
386 
387  if(param->values.size() > 0) {
388  QString message = "A value for this parameter [" + paramName + "] has "
389  "already been saved (possibly by IsisGui). If you need to "
390  "change the value use \"Clear\" before the Put.";
392  }
393 
394  param->values.clear();
395  param->values.push_back(Isis::toString(value));
396 
397  Verify(param);
398 }
399 
400 
401 // Public: Sets the value member of a parameter of type double whose name
402 // starts with paramName
418 void IsisAml::PutDouble(const QString &paramName,
419  const vector<double> &value) {
420 
421  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
422 
423  if(param->type != "double") {
424  QString message = "Parameter [" + paramName + "] is not a double.";
426  }
427 
428  if(param->values.size() > 0) {
429  QString message = "A value for this parameter [" + paramName + "] has "
430  "already been saved (possibly by IsisGui). If you need to "
431  "change the value use \"Clear\" before the Put.";
433  }
434 
435  param->values.resize(value.size());
436  for(unsigned int i = 0; i < value.size(); i++) {
437  param->values[i] = Isis::toString(value[i]);
438  }
439 
440  Verify(param);
441 }
442 
443 
444 
445 // Public: Sets the value member of a parameter of type boolean whose name
446 // starts with paramName
462 void IsisAml::PutBoolean(const QString &paramName,
463  const bool &value) {
464 
465  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
466 
467  if(param->type != "boolean") {
468  QString message = "Parameter [" + paramName + "] is not a boolean.";
470  }
471 
472  if(param->values.size() > 0) {
473  QString message = "A value for this parameter [" + paramName + "] has "
474  "already been saved (possibly by IsisGui). If you need to "
475  "change the value use \"Clear\" before the Put.";
477  }
478 
479  param->values.clear();
480  if(value) {
481  param->values.push_back("YES");
482  }
483  else {
484  param->values.push_back("NO");
485  }
486 
487  Verify(param);
488 }
489 
490 
491 // Public: Sets the value member of a parameter of type boolean whose name
492 // starts with paramName
508 void IsisAml::PutBoolean(const QString &paramName,
509  const vector<bool> &value) {
510 
511  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
512 
513  if(param->type != "boolean") {
514  QString message = "Parameter [" + paramName + "] is not a boolean.";
516  }
517 
518  if(param->values.size() > 0) {
519  QString message = "A value for this parameter [" + paramName + "] has "
520  "already been saved (possibly by IsisGui). If you need to "
521  "change the value use \"Clear\" before the Put.";
523  }
524 
525  param->values.resize(value.size());
526  for(unsigned int i = 0; i < value.size(); i++) {
527  if(value[i]) {
528  param->values.push_back("YES");
529  }
530  else {
531  param->values.push_back("NO");
532  }
533  }
534 
535  Verify(param);
536 }
537 
538 
539 // Accessor methods for getting the value(s) of a parameter
540 
541 // Public: Returns the first element of the value member of a parameter whos
542 // name starts with paramName as a QString. Any type can be retrieve with this member.
553 QString IsisAml::GetAsString(const QString &paramName) const {
554 
555  const IsisParameterData *param = ReturnParam(paramName);
556  QString value;
557  if(param->values.size() == 0) {
558  if(param->defaultValues.size() == 0) {
559  QString message = "Parameter [" + paramName + "] has no value.";
561  }
562  else {
563  value = param->defaultValues[0];
564  }
565  }
566  else {
567  value = param->values[0];
568  }
569 
570  return value;
571 }
572 
573 // Public: Returns the value member of a parameter whose name starts with paramName
574 // as a vector<QString>
585 void IsisAml::GetAsString(const QString &paramName,
586  vector<QString> &values) const {
587 
588  const IsisParameterData *param = ReturnParam(paramName);
589 
590  values.clear();
591  QString value;
592  if(param->values.size() == 0) {
593  if(param->defaultValues.size() == 0) {
594  QString message = "Parameter [" + paramName + "] has no value.";
596  }
597  else {
598  for(unsigned int i = 0; i < param->defaultValues.size(); i++)
599  values.push_back(param->defaultValues[i]);
600  }
601  }
602  else {
603  for(unsigned int i = 0; i < param->values.size(); i++)
604  values.push_back(param->values[i]);
605  }
606 
607  return;
608 }
609 
610 
611 // Public: Returns the first element of the value member of a parameter whose
612 // name starts with paramName as a QString/filename
623 QString IsisAml::GetFileName(const QString &paramName, QString extension) const {
624 
625  const IsisParameterData *param = ReturnParam(paramName);
626 
627  if((param->type != "filename") && (param->type != "cube")) {
628  QString message = "Parameter [" + paramName + "] is not a filename.";
630  }
631 
632  QString value;
633  if(param->values.size() == 0) {
634  if(param->defaultValues.size() == 0) {
635  QString message = "Parameter [" + paramName + "] has no value.";
637  }
638  else {
639  value = param->defaultValues[0];
640  }
641  }
642  else {
643  value = param->values[0];
644  }
645 
646  Isis::FileName name(value);
647  if(extension != "") name = name.addExtension(extension);
648  value = name.expanded();
649 
650  return value;
651 }
652 
653 
654 // Public: Returns the value member of a parameter whose name starts with paramName
655 // as a vector<QString/filename>
663 void IsisAml::GetFileName(const QString &paramName,
664  vector<QString> &values) const {
665 
666  const IsisParameterData *param = ReturnParam(paramName);
667 
668  if((param->type != "filename") && (param->type != "cube")) {
669  QString message = "Parameter [" + paramName + "] is not a filename.";
671  }
672 
673  values.clear();
674  if(param->values.size() == 0) {
675  if(param->defaultValues.size() == 0) {
676  QString message = "Parameter [" + paramName + "] has no value.";
678  }
679  else {
680  for(unsigned int i = 0; i < param->defaultValues.size(); i++) {
681  Isis::FileName name(param->defaultValues[i]);
682  values.push_back(name.expanded());
683  }
684  }
685  }
686  else {
687  for(unsigned int i = 0; i < param->values.size(); i++) {
688  Isis::FileName name(param->values[i]);
689  values.push_back(name.expanded());
690  }
691  }
692 
693  return;
694 }
695 
696 
697 // Public: Returns the first element of the value member of a parameter whos
698 // name starts with paramName as a QString
708 QString IsisAml::GetString(const QString &paramName) const {
709 
710  const IsisParameterData *param = ReturnParam(paramName);
711  QString value;
712 
713  if(param->type != "string" && param->type != "combo") {
714  QString message = "Parameter [" + paramName + "] is not a string.";
716  }
717 
718  if(param->values.size() == 0) {
719  if(param->defaultValues.size() == 0) {
720  QString message = "Parameter [" + paramName + "] has no value.";
722  }
723  else {
724  value = param->defaultValues[0];
725  }
726  }
727  else {
728  value = param->values[0];
729  // If there is a list of legal values return the list option that matches
730  // or begins with what was entered rather than exactly what was entered
731  if(param->listOptions.size() > 0) {
732  value = value.toUpper();
733  int found = -1;
734  int foundcount = 0;
735  for(unsigned int p = 0; p < param->listOptions.size(); p++) {
736  QString option = param->listOptions[p].value;
737  option = option.toUpper();
738  if(value == option) {
739  return value;
740  }
741  else if(value.startsWith(option) || option.startsWith(value)) {
742  found = p;
743  foundcount = foundcount + 1;
744  }
745  }
746  if(foundcount == 0) {
747  QString message = "Value [" + value + "] for parameter [" +
748  paramName + "] is not a valid value.";
750  }
751  if(foundcount > 1) {
752  QString message = "Value [" + value + "] for parameter [" +
753  paramName + "] is not unique.";
755  }
756  return param->listOptions[found].value;
757  }
758 
759  // Just return what is in the value
760  else {
761  value = param->values[0];
762  }
763  }
764  return value;
765 }
766 
767 
768 // Public: Returns the value member of a parameter whose name starts with paramName
769 // as a vector<QString>
780 void IsisAml::GetString(const QString &paramName,
781  vector<QString> &values) const {
782 
783  const IsisParameterData *param = ReturnParam(paramName);
784 
785  if(param->type != "string" && param->type != "combo") {
786  QString message = "Parameter [" + paramName + "] is not a string.";
788  }
789 
790  values.clear();
791  QString value;
792  if(param->values.size() == 0) {
793  if(param->defaultValues.size() == 0) {
794  QString message = "Parameter [" + paramName + "] has no value.";
796  }
797  else {
798  for(unsigned int i = 0; i < param->defaultValues.size(); i++)
799  values.push_back(param->defaultValues[i]);
800  }
801  }
802  else {
803  for(unsigned int i = 0; i < param->values.size(); i++)
804  values.push_back(param->values[i]);
805  }
806 
807  return;
808 }
809 
810 
811 
812 // Public: Returns the first element of the value member of a parameter whos
813 // name starts with paramName as an integer
823 int IsisAml::GetInteger(const QString &paramName) const {
824 
825  const IsisParameterData *param = ReturnParam(paramName);
826 
827  if(param->type != "integer") {
828  QString message = "Parameter [" + paramName + "] is not an integer.";
830  }
831 
832  Isis::IString value;
833  if(param->values.size() == 0) {
834  if(param->defaultValues.size() == 0) {
835  QString message = "Parameter [" + paramName + "] has no value.";
837  }
838  else {
839  value = param->defaultValues[0];
840  }
841  }
842  else {
843  value = param->values[0];
844  }
845 
846  return value.ToInteger();
847 }
848 
849 
850 // Public: Returns the value member of a parameter whose name starts with paramName
851 // as a vector<int>
862 void IsisAml::GetInteger(const QString &paramName,
863  vector<int> &values) const {
864 
865  const IsisParameterData *param = ReturnParam(paramName);
866 
867  if(param->type != "integer") {
868  QString message = "Parameter [" + paramName + "] is not an integer.";
870  }
871 
872  values.clear();
873  Isis::IString value;
874  if(param->values.size() == 0) {
875  if(param->defaultValues.size() == 0) {
876  QString message = "Parameter [" + paramName + "] has no value.";
878  }
879  else {
880  for(unsigned int i = 0; i < param->defaultValues.size(); i++)
881  value = param->defaultValues[i];
882  values.push_back(value.ToInteger());
883  }
884  }
885  else {
886  for(unsigned int i = 0; i < param->values.size(); i++)
887  value = param->values[i];
888  values.push_back(value.ToInteger());
889  }
890 
891  return;
892 }
893 
894 
895 
896 // Public: Returns the first element of the value member of a parameter whos
897 // name starts with paramName as a doubble
907 double IsisAml::GetDouble(const QString &paramName) const {
908 
909  const IsisParameterData *param = ReturnParam(paramName);
910 
911  if(param->type != "double") {
912  QString message = "Parameter [" + paramName + "] is not a double.";
914  }
915 
916  Isis::IString value;
917  if(param->values.size() == 0) {
918  if(param->defaultValues.size() == 0) {
919  QString message = "Parameter [" + paramName + "] has no value.";
921  }
922  else {
923  value = param->defaultValues[0];
924  }
925  }
926  else {
927  value = param->values[0];
928  }
929 
930  return value.ToDouble();
931 }
932 
933 // Public: Returns the value member of a parameter whose name starts with paramName
934 // as a vector<doubble>
945 void IsisAml::GetDouble(const QString &paramName,
946  vector<double> &values) const {
947 
948  const IsisParameterData *param = ReturnParam(paramName);
949 
950  if(param->type != "double") {
951  QString message = "Parameter [" + paramName + "] is not a double.";
953  }
954 
955  values.clear();
956  Isis::IString value;
957  if(param->values.size() == 0) {
958  if(param->defaultValues.size() == 0) {
959  QString message = "Parameter [" + paramName + "] has no value.";
961  }
962  else {
963  for(unsigned int i = 0; i < param->defaultValues.size(); i++)
964  value = param->defaultValues[i];
965  values.push_back(value.ToDouble());
966  }
967  }
968  else {
969  for(unsigned int i = 0; i < param->values.size(); i++)
970  value = param->values[i];
971  values.push_back(value.ToDouble());
972  }
973 
974  return;
975 }
976 
977 
978 // Public: Returns the first element of the value member of a parameter whos
979 // name starts with paramName as a bool
989 bool IsisAml::GetBoolean(const QString &paramName) const {
990 
991  const IsisParameterData *param = ReturnParam(paramName);
992 
993  if(param->type != "boolean") {
994  QString message = "Parameter [" + paramName + "] is not a boolean.";
996  }
997 
998  QString value;
999  if(param->values.size() == 0) {
1000  if(param->defaultValues.size() == 0) {
1001  QString message = "Parameter [" + paramName + "] has no value.";
1003  }
1004  else {
1005  value = param->defaultValues[0];
1006  }
1007  }
1008  else {
1009  value = param->values[0];
1010  }
1011 
1012  return Isis::toBool(value);
1013 
1014 }
1015 
1016 
1017 // Public: Returns the value member of a parameter whose name starts with paramName
1018 // as a vector<bool>
1029 void IsisAml::GetBoolean(const QString &paramName,
1030  vector<bool> &values) const {
1031 
1032  const IsisParameterData *param = ReturnParam(paramName);
1033 
1034  if(param->type != "boolean") {
1035  QString message = "Parameter [" + paramName + "] is not a boolean.";
1037  }
1038 
1039  values.clear();
1040  vector <QString> value;
1041  QString tmp;
1042  if(param->values.size() == 0) {
1043  if(param->defaultValues.size() == 0) {
1044  QString message = "Parameter [" + paramName + "] has no value.";
1046  }
1047  else {
1048  for(unsigned int i = 0; i < param->defaultValues.size(); i++) {
1049  tmp = param->defaultValues[i].toUpper();
1050  value.push_back(tmp);
1051  }
1052  }
1053  }
1054  else {
1055  for(unsigned int i = 0; i < param->values.size(); i++) {
1056  tmp = param->values[i].toUpper();
1057  value.push_back(tmp);
1058  }
1059  }
1060 
1061  for(unsigned int i = 0; i < value.size(); i++) {
1062  values.push_back(StringToBool(value[i]));
1063 
1064  }
1065 
1066  return;
1067 }
1073 QString IsisAml::ProgramName() const {
1074  QString tmp = name;
1075  return tmp;
1076 }
1077 
1078 
1084 QString IsisAml::Brief() const {
1085  return brief;
1086 }
1087 
1088 
1094 QString IsisAml::Description() const {
1095  return description;
1096 }
1097 
1103 int IsisAml::NumGroups() const {
1104  return groups.size();
1105 }
1106 
1114 QString IsisAml::GroupName(const int &index) const {
1115  QString s = groups[index].name;
1116  return s;
1117 }
1118 
1128 int IsisAml::GroupIndex(const QString & grpName) const {
1129  for(int i=0; i<(int)groups.size(); i++) {
1130  if(Isis::IString(grpName).DownCase() == Isis::IString(groups[i].name).DownCase()) {
1131  return i;
1132  }
1133  }
1134  return -1;
1135 }
1136 
1150 void IsisAml::CreatePVL(Isis::Pvl &pvlDef , QString guiGrpName, QString pvlObjName, QString pvlGrpName, vector<QString> & include) {
1151 
1152  Isis::PvlObject *pvlObj = NULL;
1153  if (pvlObjName != "") {
1154  pvlObj = new Isis::PvlObject(pvlObjName);
1155  }
1156 
1157  // Get Gui Group index
1158  int grpIndex= GroupIndex(guiGrpName);
1159 
1160  if (pvlGrpName == "" || grpIndex == -1 ) {
1161  QString errMsg = "Must provide Group Name\n";
1163  }
1164 
1165  Isis::PvlGroup grp(pvlGrpName);
1166  for(int i=0; i<NumParams(grpIndex); i++) {
1167  QString paramName = ParamName(grpIndex, i);
1168 
1169  if(IsParamInPvlInclude(paramName,include)) {
1170  Isis::IString paramType = Isis::IString(ParamType(grpIndex, i)).DownCase();
1171  if(paramType == "double") {
1172  grp += Isis::PvlKeyword(paramName, Isis::toString(GetDouble(paramName)));
1173  }
1174  if(paramType == "integer") {
1175  grp += Isis::PvlKeyword(paramName, Isis::toString(GetInteger(paramName)));
1176  }
1177  if(paramType == "boolean") {
1178  grp += Isis::PvlKeyword(paramName, Isis::toString(GetBoolean(paramName)));
1179  }
1180  if(paramType == "string" || paramType == "filename" || paramType == "combo") {
1181  grp += Isis::PvlKeyword(paramName, GetAsString(paramName));
1182  }
1183  }
1184  }
1185 
1186  if(pvlObj != NULL) {
1187  *pvlObj += grp;
1188  pvlDef += *pvlObj;
1189  delete (pvlObj);
1190  pvlObj = NULL;
1191  }
1192  else {
1193  pvlDef += grp;
1194  }
1195 }
1196 
1207 bool IsisAml::IsParamInPvlInclude(QString & paramName, vector<QString> & include) {
1208 
1209  for(int i=0; i<(int)include.size(); i++) {
1210  if(Isis::IString(paramName).DownCase() == Isis::IString(include[i]).DownCase()) {
1211  return true;
1212  }
1213  }
1214  return false;
1215 }
1223 int IsisAml::NumParams(const int &group) const {
1224  return groups[group].parameters.size();
1225 }
1226 
1235 QString IsisAml::ParamName(const int &group, const int &param) const {
1236  QString s = groups[group].parameters[param].name;
1237  return s;
1238 }
1239 
1248 QString IsisAml::ParamBrief(const int &group, const int &param) const {
1249  QString s = groups[group].parameters[param].brief;
1250  return s;
1251 }
1252 
1261 QString IsisAml::ParamDescription(const int &group, const int &param) const {
1262  QString s = groups[group].parameters[param].description;
1263  return s;
1264 }
1265 
1274 QString IsisAml::ParamMinimum(const int &group, const int &param) const {
1275  QString s = groups[group].parameters[param].minimum;
1276  return s;
1277 }
1278 
1287 QString IsisAml::ParamMaximum(const int &group, const int &param) const {
1288  QString s = groups[group].parameters[param].maximum;
1289  return s;
1290 }
1291 
1300 QString IsisAml::ParamMinimumInclusive(const int &group, const int &param) const {
1301  QString s = groups[group].parameters[param].minimum_inclusive;
1302  return s;
1303 }
1304 
1313 QString IsisAml::ParamMaximumInclusive(const int &group, const int &param) const {
1314  QString s = groups[group].parameters[param].maximum_inclusive;
1315  return s;
1316 }
1317 
1327 QString IsisAml::ParamOdd(const int &group, const int &param) const {
1328  QString s = groups[group].parameters[param].odd;
1329  return s;
1330 }
1331 
1340 int IsisAml::ParamGreaterThanSize(const int &group, const int &param) const {
1341  return groups[group].parameters[param].greaterThan.size();
1342 }
1343 
1353  const int &param) const {
1354  return groups[group].parameters[param].greaterThanOrEqual.size();
1355 }
1356 
1365 int IsisAml::ParamLessThanSize(const int &group, const int &param) const {
1366  return groups[group].parameters[param].lessThan.size();
1367 }
1368 
1378  const int &param) const {
1379  return groups[group].parameters[param].lessThanOrEqual.size();
1380 }
1381 
1390 int IsisAml::ParamNotEqualSize(const int &group, const int &param) const {
1391  return groups[group].parameters[param].notEqual.size();
1392 }
1393 
1403 QString IsisAml::ParamGreaterThan(const int &group, const int &param,
1404  const int &great) const {
1405  QString s = groups[group].parameters[param].greaterThan[great];
1406  return s;
1407 }
1408 
1418 QString IsisAml::ParamGreaterThanOrEqual(const int &group, const int &param,
1419  const int &great) const {
1420  QString s = groups[group].parameters[param].greaterThanOrEqual[great];
1421  return s;
1422 }
1423 
1433 QString IsisAml::ParamLessThan(const int &group, const int &param,
1434  const int &les) const {
1435  QString s = groups[group].parameters[param].lessThan[les];
1436  return s;
1437 }
1438 
1448 QString IsisAml::ParamLessThanOrEqual(const int &group, const int &param,
1449  const int &les) const {
1450  QString s = groups[group].parameters[param].lessThanOrEqual[les];
1451  return s;
1452 }
1453 
1463 QString IsisAml::ParamNotEqual(const int &group, const int &param,
1464  const int &notEq) const {
1465  QString s = groups[group].parameters[param].notEqual[notEq];
1466  return s;
1467 }
1468 
1478 QString IsisAml::ParamExclude(const int &group, const int &param,
1479  const int &exclude) const {
1480  QString s = groups[group].parameters[param].exclude[exclude];
1481  return s;
1482 }
1483 
1493 QString IsisAml::ParamInclude(const int &group, const int &param,
1494  const int &include) const {
1495  QString s = groups[group].parameters[param].include[include];
1496  return s;
1497 }
1498 
1499 
1508 QString IsisAml::ParamType(const int &group, const int &param) const {
1509  QString s = groups[group].parameters[param].type;
1510  return s;
1511 }
1512 
1521 QString IsisAml::ParamDefault(const int &group, const int &param) const {
1522  QString s;
1523  if(groups[group].parameters[param].defaultValues.size() == 0) {
1524  s = "";
1525  }
1526  else {
1527  s = groups[group].parameters[param].defaultValues[0];
1528  }
1529  return s;
1530 }
1531 
1540 QString IsisAml::ParamInternalDefault(const int &group, const int &param) const {
1541  QString s;
1542  if(groups[group].parameters[param].internalDefault.size() == 0) {
1543  s = "";
1544  }
1545  else {
1546  s = groups[group].parameters[param].internalDefault;
1547  }
1548  return s;
1549 }
1550 
1559 QString IsisAml::ParamFilter(const int &group, const int &param) const {
1560  QString s;
1561  if(groups[group].parameters[param].filter.size() == 0) {
1562  s = "";
1563  }
1564  else {
1565  s = groups[group].parameters[param].filter;
1566  }
1567  return s;
1568 }
1569 
1578 QString IsisAml::ParamPath(const int &group, const int &param) const {
1579  QString s;
1580  if(groups[group].parameters[param].path.size() == 0) {
1581  s = "";
1582  }
1583  else {
1584  s = groups[group].parameters[param].path;
1585  }
1586  return s;
1587 }
1588 
1597 QString IsisAml::ParamFileMode(const int &group, const int &param) const {
1598  QString s;
1599  if(groups[group].parameters[param].fileMode.size() == 0) {
1600  s = "";
1601  }
1602  else {
1603  s = groups[group].parameters[param].fileMode;
1604  }
1605  return s;
1606 }
1607 
1617 int IsisAml::ParamListSize(const int &group, const int &param) const {
1618  return groups[group].parameters[param].listOptions.size();
1619 }
1620 
1621 
1631 QString IsisAml::ParamListValue(const int &group, const int &param,
1632  const int &option) const {
1633  QString s = groups[group].parameters[param].listOptions[option].value;
1634  return s;
1635 }
1636 
1646 QString IsisAml::ParamListBrief(const int &group, const int &param,
1647  const int &option) const {
1648  QString s = groups[group].parameters[param].listOptions[option].brief;
1649  return s;
1650 }
1651 
1661 QString IsisAml::ParamListDescription(const int &group, const int &param,
1662  const int &option) const {
1663  QString s = groups[group].parameters[param].listOptions[option].description;
1664  return s;
1665 }
1666 
1676 int IsisAml::ParamListExcludeSize(const int &group, const int &param,
1677  const int &option) const {
1678  return groups[group].parameters[param].listOptions[option].exclude.size();
1679 }
1680 
1691 QString IsisAml::ParamListExclude(const int &group, const int &param,
1692  const int &option, const int &exclude) const {
1693  QString s = groups[group].parameters[param].listOptions[option].exclude[exclude];
1694  return s;
1695 }
1696 
1706 int IsisAml::ParamListIncludeSize(const int &group, const int &param,
1707  const int &option) const {
1708  return groups[group].parameters[param].listOptions[option].include.size();
1709 }
1710 
1721 QString IsisAml::ParamListInclude(const int &group, const int &param,
1722  const int &option, const int &include) const {
1723  QString s = groups[group].parameters[param].listOptions[option].include[include];
1724  return s;
1725 }
1726 
1735 int IsisAml::ParamExcludeSize(const int &group, const int &param) const {
1736  return groups[group].parameters[param].exclude.size();
1737 }
1738 
1747 int IsisAml::ParamIncludeSize(const int &group, const int &param) const {
1748  return groups[group].parameters[param].include.size();
1749 }
1750 
1759 QString IsisAml::PixelType(const int &group, const int &param) const {
1760  return groups[group].parameters[param].pixelType;
1761 }
1762 
1771 int IsisAml::HelpersSize(const int &group, const int &param) const {
1772  return groups[group].parameters[param].helpers.size();
1773 }
1774 
1784 QString IsisAml::HelperButtonName(const int &group, const int &param,
1785  const int &helper) const {
1786  return groups[group].parameters[param].helpers[helper].name;
1787 }
1788 
1798 QString IsisAml::HelperFunction(const int &group, const int &param,
1799  const int &helper) const {
1800  return groups[group].parameters[param].helpers[helper].function;
1801 }
1802 
1812 QString IsisAml::HelperBrief(const int &group, const int &param,
1813  const int &helper) const {
1814  return groups[group].parameters[param].helpers[helper].brief;
1815 }
1816 
1826 QString IsisAml::HelperDescription(const int &group, const int &param,
1827  const int &helper) const {
1828  return groups[group].parameters[param].helpers[helper].description;
1829 }
1830 
1840 QString IsisAml::HelperIcon(const int &group, const int &param,
1841  const int &helper) const {
1842  return groups[group].parameters[param].helpers[helper].icon;
1843 }
1844 
1852 bool IsisAml::WasEntered(const QString &paramName) const {
1853 
1854  const IsisParameterData *param = ReturnParam(paramName);
1855 
1856  if(param->values.size() == 0) {
1857  return false;
1858  }
1859 
1860  return true;
1861 }
1862 
1868 void IsisAml::Clear(const QString &paramName) {
1869 
1870  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
1871  param->values.clear();
1872 
1873  param->outCubeAtt.setAttributes("+" + param->pixelType);
1874  param->inCubeAtt.setAttributes("");
1875 
1876  return;
1877 }
1878 
1879 
1891 
1892  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
1893 
1894  if(param->type != "cube") {
1895  QString message = "Unable to get input cube attributes. Parameter ["
1896  + paramName + "] is not a cube. Parameter type = [" + param->type + "].";
1898  }
1899 
1900  QString value;
1901  if(param->values.size() == 0) {
1902  if(param->defaultValues.size() == 0) {
1903  value.clear();
1904 // QString message = "Parameter [" + paramName + "] has no value.";
1905 // throw Isis::IException(Isis::IException::User,message, _FILEINFO_);
1906  }
1907  else {
1908  value = param->defaultValues[0];
1909  }
1910  }
1911  else {
1912  value = param->values[0];
1913  }
1914  if(param->fileMode == "input") {
1915  param->inCubeAtt.setAttributes(value);
1916  }
1917  else {
1918  QString message = "Unable to get input cube attributes. Parameter ["
1919  + paramName + "] is not an input. Parameter fileMode = [" + param->fileMode + "].";
1921  }
1922  return param->inCubeAtt;
1923 }
1924 
1936 
1937  IsisParameterData *param = const_cast <IsisParameterData *>(ReturnParam(paramName));
1938 
1939  if(param->type != "cube") {
1940  QString message = "Unable to get output cube attributes. Parameter ["
1941  + paramName + "] is not a cube. Parameter type = [" + param->type + "].";
1943  }
1944 
1945  QString value;
1946  if(param->values.size() == 0) {
1947  if(param->defaultValues.size() == 0) {
1948  value.clear();
1949 // QString message = "Parameter [" + paramName + "] has no value.";
1950 // throw Isis::IException(Isis::IException::User,message, _FILEINFO_);
1951  }
1952  else {
1953  value = param->defaultValues[0];
1954  }
1955  }
1956  else {
1957  value = param->values[0];
1958  }
1959  if(param->fileMode == "output") {
1960  param->outCubeAtt.setAttributes("+" + param->pixelType);
1961  param->outCubeAtt.addAttributes(Isis::FileName(value));
1962  }
1963  else {
1964  QString message = "Unable to get output cube attributes. Parameter ["
1965  + paramName + "] is not an output. Parameter fileMode = [" + param->fileMode + "].";
1967  }
1968  return param->outCubeAtt;
1969 }
1970 
1981 const IsisParameterData *IsisAml::ReturnParam(const QString &paramName) const {
1982  Isis::IString pn = paramName;
1983  pn.UpCase();
1984  int found = 0;
1985  bool exact = false;
1986  const IsisParameterData *param = NULL;
1987  Isis::IString cur_pn;
1988 
1989  for(unsigned int g = 0; g < groups.size(); g++) {
1990  for(unsigned int p = 0; p < groups[g].parameters.size(); p++) {
1991  cur_pn = groups[g].parameters[p].name;
1992  cur_pn.UpCase();
1993  if(cur_pn.find(pn) == 0) {
1994  if(cur_pn == pn) {
1995  if(exact) {
1996  QString message = "Parameter [" + paramName + "] is not unique.";
1998  }
1999  else {
2000  exact = true;
2001  found = 0;
2002  param = &(groups[g].parameters[p]);
2003  }
2004  }
2005  else if(!exact) {
2006  found++;
2007  param = &(groups[g].parameters[p]);
2008  }
2009  }
2010  }
2011  }
2012  if(param == NULL) {
2013  QString message = "Unknown parameter [" + paramName + "].";
2015  }
2016  else if((found > 1) && (!exact)) {
2017  QString message = "Parameter [" + paramName + "] is not unique.";
2019  }
2020  return param;
2021 }
2022 
2034 
2035  // Check to make sure the value QString can be converted to the correct type
2036  for(unsigned int i = 0; i < param->values.size(); i++) {
2037  if(param->type == "integer") {
2038  try {
2039  Isis::IString value(param->values[i]);
2040  value.ToInteger();
2041  }
2042  catch(Isis::IException &e) {
2043  QString message = "Unable to convert [" + param->values[i] + "] to an integer,"
2044  " parameter [" + param->name + "].";
2046  }
2047  }
2048  else if(param->type == "double") {
2049  try {
2050  Isis::IString value(param->values[i]);
2051  value.ToDouble();
2052  }
2053  catch(Isis::IException &e) {
2054  QString message = "Unable to convert [" + param->values[i] + "] to a double,"
2055  " parameter [" + param->name + "].";
2057  }
2058  }
2059  else if(param->type == "boolean") {
2060  QString v = param->values[i].toUpper();
2061 
2062  try {
2063  StringToBool(v);
2064  }
2065  catch(Isis::IException &e) {
2066  QString message = "Illegal value for [" + param->name + "], [" + param->values[i] + "].";
2068  }
2069  }
2070  else if(param->type == "filename") {
2071  // If this is an output file and a file with this name already exists,
2072  // check user filename customization preferences.
2073  QString value(param->values[i]);
2074  Isis::FileName name(value);
2075  value = name.expanded();
2076  if(name.fileExists() && param->fileMode == "output") {
2077  CheckFileNamePreference(value, param->name);
2078  }
2079  }
2080  // THIS IS CURRENTLY HANDLED IN THE CUBE CLASS, see CubeIoHandler.cpp
2081  // 2010-07-15 Jeannie Walldren
2082  //
2083  // else if(param->type == "cube") {
2084  // Isis::IString value(param->values[i]);
2085  // Isis::FileName name(value);
2086  // value = name.expanded();
2087  // if (name.Exists() && param->fileMode == "output"
2088  // && Isis::Preference::Preferences().findGroup("CubeCustomization").findKeyword("Overwrite")[0] == "Error") {
2089  // QString message = "Invalid output cube for [" + param->name + "]. The cube file [" + value + "] already exists. " +
2090  // "The user preference cube customization group is set to disallow cube overwrites.";
2091  // throw Isis::IException(Isis::IException::User, message, _FILEINFO_);
2092  // }
2093  // }
2094  }
2095 
2096  // Check the default values if there were no values
2097  if(param->values.size() == 0) {
2098  for(unsigned int i = 0; i < param->defaultValues.size(); i++) {
2099  // Check to make sure the DefaultValue QString can be converted to the
2100  // correct type
2101  if(param->type == "integer") {
2102  try {
2103  Isis::IString value(param->defaultValues[i]);
2104  value.ToInteger();
2105  }
2106  catch(Isis::IException &e) {
2107  QString message = "Unable to convert default [" + param->defaultValues[i] +
2108  "] to an integer, parameter [" + param->name + "].";
2110  }
2111  }
2112  else if(param->type == "double") {
2113  try {
2114  Isis::IString value(param->defaultValues[i]);
2115  value.ToDouble();
2116  }
2117  catch(Isis::IException &e) {
2118  QString message = "Unable to convert default [" + param->defaultValues[i] +
2119  "] to a double, parameter [" + param->name + "].";
2121  }
2122  }
2123  else if(param->type == "boolean") {
2124  QString v = param->defaultValues[i].toUpper();
2125 
2126  try {
2127  StringToBool(v);
2128  }
2129  catch(Isis::IException &e) {
2130  QString message = "Illegal default value for [" + param->name + "], ["
2131  + param->defaultValues[i] + "].";
2133  }
2134  }
2135  else if(param->type == "filename") {
2136  // Put something here once we figure out what to do with filenames
2137  QString value(param->defaultValues[i]);
2138  Isis::FileName name(value);
2139  value = name.expanded();
2140  if(name.fileExists() && param->fileMode == "output") {
2141  CheckFileNamePreference(value, param->name);
2142  }
2143  }
2144  }
2145  }
2146 
2147  // Check the values against the values list if there is one
2148  if(param->listOptions.size() > 0) {
2149  for(unsigned int i = 0; i < param->values.size(); i++) {
2150  Isis::IString value = param->values[i];
2151  value = value.UpCase();
2152  int partial = 0;
2153  bool exact = false;
2154  for(unsigned int p = 0; p < param->listOptions.size(); p++) {
2155  Isis::IString option = param->listOptions[p].value;
2156  option = option.UpCase();
2157  // Check to see if the value matches the list option exactly
2158  if(value == option) {
2159  // If we already have one exact match then there is an error
2160  if(exact) {
2161  QString message = "Duplicate list options [" +
2162  param->listOptions[p].value +
2163  "] in parameter [" + param->name + "].";
2165  }
2166  exact = true;
2167  }
2168  // Check for a partial match
2169  // Compare the shorter of the two (values[i]) to a subQString of the
2170  // longer QString (listOptions[p].value)
2171  else if(option.compare(0, min(value.size(), option.size()),
2172  value, 0, min(value.size(), option.size())) == 0) {
2173  partial++;
2174  }
2175  }
2176  if(!exact && partial == 0) {
2177  QString message = "Value of [" + param->name + "] must be one of [" +
2178  param->listOptions[0].value;
2179  for(unsigned int p = 1; p < param->listOptions.size(); p++) {
2180  message += ", " + param->listOptions[p].value;
2181  }
2182  message += "].";
2184  }
2185  else if(!exact && partial > 1) {
2186  QString msg = "Value of [" + param->name +
2187  "] does not match a list option uniquely.";
2189  }
2190  }
2191  }
2192 
2193  // Check the values against the minimum
2194  if(param->minimum.length() > 0) {
2195  QString incl = param->minimum_inclusive;
2196  for(unsigned int i = 0; i < param->values.size(); i++) {
2197  if(param->type == "integer") {
2198  QString value(param->values[i]);
2199  int temp = Isis::toInt(value);
2200  value = param->minimum;
2201  int min = Isis::toInt(value);
2202  if(StringToBool(incl) && (temp < min)) {
2203  QString message = "Parameter [" + param->name +
2204  "] must be greater than or equal to [" + param->minimum + "].";
2206  }
2207  else if(!StringToBool(incl) && (temp <= min)) {
2208  QString message = "Parameter [" + param->name +
2209  "] must be greater than [" + param->minimum + "].";
2211  }
2212  }
2213  else if(param->type == "double") {
2214  Isis::IString value(param->values[i]);
2215  double temp = value.ToDouble();
2216  value = param->minimum;
2217  double min = value.ToDouble();
2218  if(StringToBool(incl) && (temp < min)) {
2219  QString message = "Parameter [" + param->name +
2220  "] must be greater than or equal to [" + param->minimum + "].";
2222  }
2223  else if(!StringToBool(incl) && (temp <= min)) {
2224  QString message = "Parameter [" + param->name +
2225  "] must be greater than [" + param->minimum + "].";
2227  }
2228  }
2229  }
2230  if(param->values.size() == 0) {
2231  for(unsigned int i = 0; i < param->defaultValues.size(); i++) {
2232  if(param->type == "integer") {
2233  Isis::IString value(param->defaultValues[i]);
2234  int temp = value.ToInteger();
2235  value = param->minimum;
2236  int min = value.ToInteger();
2237  if(StringToBool(incl) && (temp < min)) {
2238  QString message = "Parameter [" + param->name +
2239  "] must be greater than or equal to [" + param->minimum + "].";
2241  }
2242  else if(!StringToBool(incl) && (temp <= min)) {
2243  QString message = "Parameter [" + param->name +
2244  "] must be greater than [" + param->minimum + "].";
2246  }
2247  }
2248  else if(param->type == "double") {
2249  Isis::IString value(param->defaultValues[i]);
2250  double temp = value.ToDouble();
2251  value = param->minimum;
2252  double min = value.ToDouble();
2253  if(StringToBool(incl) && (temp < min)) {
2254  QString message = "Parameter [" + param->name +
2255  "] must be greater than or equal to [" + param->minimum + "].";
2257  }
2258  else if(!StringToBool(incl) && (temp <= min)) {
2259  QString message = "Parameter [" + param->name +
2260  "] must be greater than [" + param->minimum + "].";
2262  }
2263  }
2264  }
2265  }
2266  }
2267 
2268  // Check the values against the maximum
2269  if(param->maximum.length() > 0) {
2270  QString incl = param->maximum_inclusive.toLower();
2271  for(unsigned int i = 0; i < param->values.size(); i++) {
2272  if(param->type == "integer") {
2273  QString value(param->values[i]);
2274  int temp = Isis::toInt(value);
2275  value = param->maximum;
2276  int max = Isis::toInt(value);
2277  if(StringToBool(incl) && (temp > max)) {
2278  QString message = "Parameter [" + param->name +
2279  "] must be less than or equal to [" + param->maximum + "].";
2281  }
2282  else if(!StringToBool(incl) && (temp >= max)) {
2283  QString message = "Parameter [" + param->name +
2284  "] must be less than [" + param->maximum + "].";
2286  }
2287  }
2288  else if(param->type == "double") {
2289  Isis::IString value(param->values[i]);
2290  double temp = value.ToDouble();
2291  value = param->maximum;
2292  double max = value.ToDouble();
2293  if(StringToBool(incl) && (temp > max)) {
2294  QString message = "Parameter [" + param->name +
2295  "] must be less than or equal to [" + param->maximum + "].";
2297  }
2298  else if(!StringToBool(incl) && (temp >= max)) {
2299  QString message = "Parameter [" + param->name +
2300  "] must be less than [" + param->maximum + "].";
2302  }
2303  }
2304  }
2305  if(param->values.size() == 0) {
2306  for(unsigned int i = 0; i < param->defaultValues.size(); i++) {
2307  if(param->type == "integer") {
2308  Isis::IString value(param->defaultValues[i]);
2309  int temp = value.ToInteger();
2310  value = param->maximum;
2311  int max = value.ToInteger();
2312  if(StringToBool(incl) && (temp > max)) {
2313  QString message = "Parameter [" + param->name +
2314  "] must be less than or equal to [" + param->maximum + "].";
2316  }
2317  else if(!StringToBool(incl) && (temp >= max)) {
2318  QString message = "Parameter [" + param->name +
2319  "] must be less than [" + param->maximum + "].";
2321  }
2322  }
2323  else if(param->type == "double") {
2324  Isis::IString value(param->defaultValues[i]);
2325  double temp = value.ToDouble();
2326  value = param->maximum;
2327  double max = value.ToDouble();
2328  if(StringToBool(incl) && (temp > max)) {
2329  QString message = "Parameter [" + param->name +
2330  "] must be less than or equal to [" + param->maximum + "].";
2332  }
2333  else if(!StringToBool(incl) && (temp >= max)) {
2334  QString message = "Parameter [" + param->name +
2335  "] must be less than [" + param->maximum + "].";
2337  }
2338  }
2339  }
2340  }
2341  }
2342 
2343  // Check the value for an odd test
2344  QString odd = param->odd.toLower();
2345 
2346  if((odd != "") || StringToBool(odd)) {
2347  if(param->type != "integer") {
2348  QString message = "Parameter [" + param->name +
2349  "] must be of type integer to have an [odd] test.";
2351  }
2352  else {
2353  for(unsigned int i = 0; i < param->values.size(); i++) {
2354  Isis::IString value(param->values[i]);
2355  if((value.ToInteger() % 2) != 1) {
2356  QString message = "Value for [" + param->name + "] must be odd.";
2358  }
2359  }
2360  }
2361  }
2362  return;
2363 }
2364 
2365 
2383 void IsisAml::CheckFileNamePreference(QString filename, QString paramname) {
2384  Isis::PvlGroup fileCustomization = Isis::Preference::Preferences().findGroup("FileCustomization");
2385  QString overwritePreference = fileCustomization.findKeyword("Overwrite")[0].simplified().trimmed();
2386  QString temp = overwritePreference;
2387  if(overwritePreference.toUpper() == "ERROR") {
2388  QString message = "Invalid output filename for [" + paramname + "]. The file [" + filename + "] already exists. " +
2389  "The user preference file customization group is set to disallow file overwrites.";
2391  }
2392  else if(overwritePreference.toUpper() != "ALLOW") { // not set to ERROR or ALLOW
2393  QString message = "Invalid entry in user preference file FileCustomization group.";
2394  message += " Overwrite = [" + temp + "]. Valid values: [Allow] or [Error].";
2396  }
2397 }
2398 
2399 
2404  for(unsigned int g = 0; g < groups.size(); g++) {
2405  for(unsigned int p = 0; p < groups[g].parameters.size(); p++) {
2406  IsisParameterData *param = &(this->groups[g].parameters[p]);
2407 
2408  Verify(param);
2409 
2410  // Check the values for inclusive clauses
2411  for(unsigned int item = 0; item < param->include.size(); item++) {
2412  // If this parameter is a boolean and it is true/yes
2413  // all included parameters must have some type of value
2414  if(param->type == "boolean") {
2415  if(((param->values.size() > 0) && StringToBool(param->values[0])) ||
2416  ((param->values.size() == 0) && (param->defaultValues.size() > 0)
2417  && StringToBool(param->defaultValues[0]))) {
2418 
2419  const IsisParameterData *param2 = ReturnParam(param->include[item]);
2420  if((param2->values.size()) == 0 &&
2421  (param2->defaultValues.size() == 0) &&
2422  (param2->internalDefault.size() == 0)) {
2423  QString message = "Parameter [" + param2->name +
2424  "] must be used if parameter [" +
2425  param->name + "] equates to true.";
2427  }
2428  }
2429  }
2430  // This parameter is NOT a boolean but the other one might be
2431  else {
2432  // If the other parameter is a boolean and it is true/yes
2433  // then this parameter must have some type of value
2434  const IsisParameterData *param2 = ReturnParam(param->include[item]);
2435  if(param2->type == "boolean") {
2436  if(((param2->values.size() > 0) && StringToBool(param2->values[0])) ||
2437  ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
2438  StringToBool(param2->defaultValues[0]))) {
2439  if((param->values.size()) == 0 &&
2440  (param->defaultValues.size() == 0) &&
2441  (param->internalDefault.size() == 0)) {
2442  QString message = "Parameter [" + param2->name +
2443  "] must be used if parameter [" +
2444  param->name + "] is used.";
2446  }
2447  }
2448  }
2449  // Neithter parameter is a boolean so
2450  // If this one has a value the other parameter must have some type of value
2451  else {
2452  if(param->values.size() > 0 &&
2453  param2->values.size() == 0 &&
2454  param2->defaultValues.size() == 0 &&
2455  param2->internalDefault.size() == 0) {
2456  QString message = "Parameter [" + param2->name +
2457  "] must be used if parameter [" +
2458  param->name + "] is used.";
2460  }
2461  }
2462  }
2463  }
2464  // Check the values for exclusive clauses
2465  for(unsigned int item = 0; item < param->exclude.size(); item++) {
2466  // If this parameter is a boolean that is true/yes
2467  // the other parameter should not have a value
2468  if(param->type == "boolean") {
2469  if(((param->values.size() > 0) && StringToBool(param->values[0])) ||
2470  ((param->values.size() == 0) && (param->defaultValues.size() > 0) &&
2471  StringToBool(param->defaultValues[0]))) {
2472 
2473  const IsisParameterData *param2 = ReturnParam(param->exclude[item]);
2474  if(param2->values.size() > 0) {
2475  QString message = "Parameter [" + param2->name +
2476  "] must NOT be used if parameter [" +
2477  param->name + "] equates to true.";
2479  }
2480  }
2481  }
2482  // This parameter is NOT a boolean but the other one might be
2483  else {
2484  const IsisParameterData *param2 = ReturnParam(param->exclude[item]);
2485  if(param2->type == "boolean") {
2486  if(((param2->values.size() > 0) && StringToBool(param2->values[0])) ||
2487  ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
2488  StringToBool(param2->defaultValues[0]))) {
2489  if(param->values.size() > 0) {
2490  QString message = "Parameter [" + param2->name +
2491  "] must be used if parameter [" +
2492  param->name + "] is used.";
2494  }
2495  }
2496  }
2497  // Neither parameter is a boolean
2498  else {
2499  if(param->values.size() > 0 && param2->values.size() > 0) {
2500  QString message = "Parameter [" + param2->name +
2501  "] must NOT be used if parameter [" +
2502  param->name + "] is used.";
2504  }
2505  }
2506  }
2507  }
2508 
2509  // Check the values for greaterThan clauses
2510  if(param->values.size() > 0) {
2511  for(unsigned int item = 0; item < param->greaterThan.size(); item++) {
2512  const IsisParameterData *param2 = ReturnParam(param->greaterThan[item]);
2513  if(param2->values.size() != 0) {
2514  double double1, double2;
2515  if(param->type == "integer") {
2516  double1 = (double) GetInteger(param->name);
2517  }
2518  else if(param->type == "double") {
2519  double1 = GetDouble(param->name);
2520  }
2521  else {
2522  QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2523  param->name + "]";
2525  }
2526 
2527  if(param2->type == "integer") {
2528  double2 = GetInteger(param2->name);
2529  }
2530  else if(param2->type == "double") {
2531  double2 = GetDouble(param2->name);
2532  }
2533  else {
2534  QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2535  param->name + "]";
2537  }
2538 
2539  if(double2 >= double1) {
2540  QString message = "Parameter [" + param->name +
2541  "] must be greater than parameter [" +
2542  param2->name + "].";
2544  }
2545  }
2546  }
2547  }
2548 
2549  // Check the values for greaterThanOrEqual clauses
2550  if(param->values.size() > 0) {
2551  for(unsigned int item = 0; item < param->greaterThanOrEqual.size(); item++) {
2552  const IsisParameterData *param2 =
2553  ReturnParam(param->greaterThanOrEqual[item]);
2554  if(param2->values.size() != 0) {
2555  double double1, double2;
2556  if(param->type == "integer") {
2557  double1 = (double) GetInteger(param->name);
2558  }
2559  else if(param->type == "double") {
2560  double1 = GetDouble(param->name);
2561  }
2562  else {
2563  QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2564  param->name + "]";
2566  }
2567 
2568  if(param2->type == "integer") {
2569  double2 = GetInteger(param2->name);
2570  }
2571  else if(param2->type == "double") {
2572  double2 = GetDouble(param2->name);
2573  }
2574  else {
2575  QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2576  param->name + "]";
2578  }
2579 
2580  if(double2 > double1) {
2581  QString message = "Parameter [" + param->name +
2582  "] must be greater than or equal to parameter [" +
2583  param2->name + "].";
2585  }
2586  }
2587  }
2588  }
2589  // Check the values for lessThan clauses
2590  if(param->values.size() > 0) {
2591  for(unsigned int item = 0; item < param->lessThan.size(); item++) {
2592  const IsisParameterData *param2 = ReturnParam(param->lessThan[item]);
2593  if(param2->values.size() != 0) {
2594  double double1, double2;
2595  if(param->type == "integer") {
2596  double1 = (double) GetInteger(param->name);
2597  }
2598  else if(param->type == "double") {
2599  double1 = GetDouble(param->name);
2600  }
2601  else {
2602  QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2603  param->name + "]";
2605  }
2606 
2607  if(param2->type == "integer") {
2608  double2 = GetInteger(param2->name);
2609  }
2610  else if(param2->type == "double") {
2611  double2 = GetDouble(param2->name);
2612  }
2613  else {
2614  QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2615  param->name + "]";
2617  }
2618 
2619  if(double2 <= double1) {
2620  QString message = "Parameter [" + param->name +
2621  "] must be less than parameter [" +
2622  param2->name + "].";
2624  }
2625  }
2626  }
2627  }
2628 
2629  // Check the values for lessThanOrEqual clauses
2630  if(param->values.size() > 0) {
2631  for(unsigned int item = 0; item < param->lessThanOrEqual.size(); item++) {
2632  const IsisParameterData *param2 =
2633  ReturnParam(param->lessThanOrEqual[item]);
2634  if(param2->values.size() != 0) {
2635  double double1, double2;
2636  if(param->type == "integer") {
2637  double1 = (double) GetInteger(param->name);
2638  }
2639  else if(param->type == "double") {
2640  double1 = GetDouble(param->name);
2641  }
2642  else {
2643  QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2644  param->name + "]";
2646  }
2647 
2648  if(param2->type == "integer") {
2649  double2 = GetInteger(param2->name);
2650  }
2651  else if(param2->type == "double") {
2652  double2 = GetDouble(param2->name);
2653  }
2654  else {
2655  QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2656  param->name + "]";
2658  }
2659 
2660  if(double2 < double1) {
2661  QString message = "Parameter [" + param->name +
2662  "] must be less than or equal to parameter [" +
2663  param2->name + "].";
2665  }
2666  }
2667  }
2668  }
2669 
2670  // Check the values for notEqual clauses
2671  if(param->values.size() > 0) {
2672  for(unsigned int item = 0; item < param->notEqual.size(); item++) {
2673  const IsisParameterData *param2 = ReturnParam(param->notEqual[item]);
2674  if(param2->values.size() != 0) {
2675  double double1, double2;
2676  if(param->type == "integer") {
2677  double1 = (double) GetInteger(param->name);
2678  }
2679  else if(param->type == "double") {
2680  double1 = GetDouble(param->name);
2681  }
2682  else {
2683  QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2684  param->name + "]";
2686  }
2687 
2688  if(param2->type == "integer") {
2689  double2 = GetInteger(param2->name);
2690  }
2691  else if(param2->type == "double") {
2692  double2 = GetDouble(param2->name);
2693  }
2694  else {
2695  QString msg = "Parameter is not INTEGER or DOUBLE type [" +
2696  param->name + "]";
2698  }
2699 
2700  if(double2 == double1) {
2701  QString message = "Parameter [" + param->name +
2702  "] must NOT be equal to parameter [" +
2703  param2->name + "].";
2705  }
2706  }
2707  }
2708  }
2709 
2710  // If this parameter has a value, and a list/option/exclude, make sure
2711  // the excluded parameter has NO value
2712  if(((param->values.size() > 0) || (param->defaultValues.size())) > 0) {
2713  for(unsigned int o2 = 0; o2 < param->listOptions.size(); o2++) {
2714  QString value, option;
2715  if(param->type == "string" || param->type == "combo") {
2716  value = GetString(param->name);
2717  value = value.toUpper();
2718  option = param->listOptions[o2].value;
2719  option = option.toUpper();
2720  }
2721  else if(param->type == "integer") {
2722  value = GetAsString(param->name);
2723  value = value.trimmed();
2724  option = param->listOptions[o2].value;
2725  option = option.trimmed();
2726  }
2727  if(value == option) {
2728  for(unsigned int e2 = 0; e2 < param->listOptions[o2].exclude.size(); e2++) {
2729  const IsisParameterData *param2 =
2730  ReturnParam(param->listOptions[o2].exclude[e2]);
2731  if(param2->values.size() > 0) {
2732  QString message = "Parameter [" + param2->name +
2733  "] can not be entered if parameter [" +
2734  param->name + "] is equal to [" +
2735  value + "]";
2737  }
2738  }
2739  }
2740  }
2741  }
2742 
2743  // If this parameter has a value, and a list/option/include, make sure
2744  // the included parameter has a value
2745  if(((param->values.size() > 0) || (param->defaultValues.size())) > 0) {
2746  for(unsigned int o2 = 0; o2 < param->listOptions.size(); o2++) {
2747  QString value, option;
2748  if(param->type == "string" || param->type == "combo") {
2749  value = GetString(param->name);
2750  value = value.toUpper();
2751  option = param->listOptions[o2].value;
2752  option = option.toUpper();
2753  }
2754  else if(param->type == "integer") {
2755  value = GetAsString(param->name);
2756  value = value.trimmed();
2757  option = param->listOptions[o2].value;
2758  option = option.trimmed();
2759  }
2760  if(value == option) {
2761  for(unsigned int e2 = 0; e2 < param->listOptions[o2].include.size(); e2++) {
2762  const IsisParameterData *param2 =
2763  ReturnParam(param->listOptions[o2].include[e2]);
2764  if((param2->values.size() == 0) &&
2765  (param2->defaultValues.size() == 0)) {
2766  QString message = "Parameter [" + param2->name +
2767  "] must be entered if parameter [" +
2768  param->name + "] is equal to [" +
2769  value + "]";
2771  }
2772  }
2773  }
2774  }
2775  }
2776 
2777  // If this parameter has no value, default value or internal default
2778  // value then it must be excluded by some other parameter with an
2779  // exclude or list/option/exclude
2780  // OR
2781  // it must include a boolean which is false
2782  if((param->values.size() == 0) && (param->defaultValues.size() == 0) &&
2783  (param->internalDefault.size() == 0)) {
2784  bool excluded = false;
2785  // See if another parameter has a list option excluding this parameter
2786  for(unsigned int g2 = 0; g2 < groups.size(); g2++) {
2787  for(unsigned int p2 = 0; p2 < groups[g2].parameters.size(); p2++) {
2788  for(unsigned int o2 = 0;
2789  o2 < groups[g2].parameters[p2].listOptions.size(); o2++) {
2790  for(unsigned int e2 = 0;
2791  e2 < groups[g2].parameters[p2].listOptions[o2].exclude.size();
2792  e2++) {
2793  QString excl =
2794  this->groups[g2].parameters[p2].listOptions[o2].exclude[e2];
2795  if(excl == param->name) {
2796  excluded = true;
2797  break;
2798  }
2799  }
2800  }
2801 
2802  if(groups[g2].parameters[p2].type == "boolean") {
2803  const IsisParameterData *param2 = &groups[g2].parameters[p2];
2804  if(((param2->values.size() > 0) && !StringToBool(param2->values[0])) ||
2805  ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
2806  !StringToBool(param2->defaultValues[0]))) {
2807  for(unsigned int e2 = 0; e2 < groups[g2].parameters[p2].include.size();
2808  e2++) {
2809  QString incl =
2810  this->groups[g2].parameters[p2].include[e2];
2811  if(incl == param->name) {
2812  excluded = true;
2813  }
2814  }
2815  }
2816  else if(((param2->values.size() > 0) && StringToBool(param2->values[0])) ||
2817  ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
2818  StringToBool(param2->defaultValues[0]))) {
2819  for(unsigned int e2 = 0; e2 < groups[g2].parameters[p2].exclude.size();
2820  e2++) {
2821  QString excl =
2822  this->groups[g2].parameters[p2].exclude[e2];
2823  if(excl == param->name) {
2824  excluded = true;
2825  }
2826  }
2827  }
2828  }
2829  }
2830  }
2831 
2832  // See if this parameter excludes any other (this implies the other
2833  // one also excludes this one too
2834  for(unsigned int item = 0; item < param->exclude.size(); item++) {
2835  const IsisParameterData *param2 = ReturnParam(param->exclude[item]);
2836  if((param2->values.size() != 0) ||
2837  (param2->defaultValues.size() != 0) ||
2838  (param2->internalDefault.size() != 0)) {
2839  if(param2->type != "boolean") {
2840  excluded = true;
2841  }
2842  else {
2843  if(((param2->values.size() > 0) && !StringToBool(param2->values[0])) ||
2844  ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
2845  !StringToBool(param2->defaultValues[0]))) {
2846  excluded = true;
2847  }
2848  }
2849  }
2850  }
2851 
2852  // See if this parameter includes a boolean that is false
2853  // then it doesn't need a value
2854  for(unsigned int item = 0; item < param->include.size(); item++) {
2855  const IsisParameterData *param2 = ReturnParam(param->include[item]);
2856  if(param2->type == "boolean") {
2857  if(((param2->values.size() > 0) && !StringToBool(param2->values[0])) ||
2858  ((param2->values.size() == 0) && (param2->defaultValues.size() > 0) &&
2859  !StringToBool(param2->defaultValues[0]))) {
2860  excluded = true;
2861  }
2862  }
2863  }
2864 
2865  if(!excluded) {
2866  QString message = "Parameter [" + param->name + "] must be entered.";
2868  }
2869  }
2870  }
2871  }
2872 }
2873 
2883 bool IsisAml::StringToBool(QString value) const {
2884 
2885  value = value.toUpper();
2886  if(value == "") {
2887  return false;
2888  }
2889  else if(!value.compare("NO")) {
2890  return false;
2891  }
2892  else if(!value.compare("FALSE")) {
2893  return false;
2894  }
2895  else if(!value.compare("F")) {
2896  return false;
2897  }
2898  else if(!value.compare("N")) {
2899  return false;
2900  }
2901  else if(!value.compare("YES")) {
2902  return true;
2903  }
2904  else if(!value.compare("TRUE")) {
2905  return true;
2906  }
2907  else if(!value.compare("Y")) {
2908  return true;
2909  }
2910  else if(!value.compare("T")) {
2911  return true;
2912  }
2913  else {
2914  QString message = "Invalid boolean value [" + value + "].";
2916  }
2917  return false;
2918 }
2919 
2920 
2926 void IsisAml::CommandLine(Isis::Pvl &cont) const {
2927  Isis::PvlGroup group("UserParameters");
2928 
2929  // Add appropriate keywords
2930  for(unsigned int g = 0; g < groups.size(); g++) {
2931  for(unsigned int p = 0; p < groups[g].parameters.size(); p++) {
2932  const IsisParameterData *param = ReturnParam(ParamName(g, p));
2933  // If this param has a value add it to the command line
2934  if(param->values.size() > 0) {
2935  Isis::PvlKeyword paramKeyword(param->name);
2936 
2937  for(unsigned int value = 0; value < param->values.size(); value++) {
2938  paramKeyword.addValue(param->values[value]);
2939  }
2940 
2941  group += paramKeyword;
2942  }
2943 
2944  // Or if it has a default value add it to the command line
2945  else if(param->defaultValues.size() > 0) {
2946  Isis::PvlKeyword paramKeyword(param->name);
2947 
2948  for(unsigned int value = 0;
2949  value < param->defaultValues.size();
2950  value++) {
2951  paramKeyword.addValue(param->defaultValues[value]);
2952  }
2953 
2954  group += paramKeyword;
2955  }
2956  }
2957  }
2958  // Remove excluded keywords
2959  for(unsigned int g = 0; g < groups.size(); g++) {
2960  for(unsigned int p = 0; p < groups[g].parameters.size(); p++) {
2961  const IsisParameterData *param = ReturnParam(ParamName(g, p));
2962 
2963  if(((param->values.size() > 0) || (param->defaultValues.size())) > 0) {
2964  for(unsigned int o2 = 0; o2 < param->listOptions.size(); o2++) {
2965  Isis::IString value, option;
2966  if(param->type == "string" || param->type == "combo") {
2967  value = GetAsString(param->name);
2968  value = value.UpCase();
2969  option = param->listOptions[o2].value;
2970  option = option.UpCase();
2971  }
2972  else if(param->type == "integer") {
2973  value = GetAsString(param->name);
2974  value = value.Trim("\n\r\t\f\v\b");
2975  option = param->listOptions[o2].value;
2976  option = option.Trim("\n\r\t\f\v\b");
2977  }
2978  if(value == option) {
2979  for(unsigned int e2 = 0; e2 < param->listOptions[o2].exclude.size(); e2++) {
2980  const IsisParameterData *param2 =
2981  ReturnParam(param->listOptions[o2].exclude[e2]);
2982  if(group.hasKeyword(param2->name)) {
2983  group.deleteKeyword(param2->name);
2984  }
2985  }
2986  }
2987  }
2988  }
2989  }
2990  }
2991 
2992  cont.clear();
2993  cont.addGroup(group);
2994  return;
2995 }
2996 
2997 
3003 QString IsisAml::Version() const {
3004  QString st = "000-00-00";
3005  for(unsigned int i = 0; i < changes.size(); i++) {
3006  if(changes[i].date > st) st = changes[i].date;
3007  }
3008  return st;
3009 }
3010 
3011 
3019 void IsisAml::StartParser(const char *xmlfile) {
3020 
3021  // Initialize the XML system
3022  try {
3023  XERCES::XMLPlatformUtils::Initialize();
3024  }
3025 
3026  catch(const XERCES::XMLException &toCatch) {
3027  QString message = "Error during XML parser initialization" +
3028  (QString)XERCES::XMLString::transcode(toCatch.getMessage());
3030  return;
3031  }
3032 
3033  //
3034  // Create a SAX parser object. Then, set it to validate for an IsisAml file
3035  //
3036  parser = XERCES::XMLReaderFactory::createXMLReader();
3037 
3038 // SAX2XMLReader::ValSchemes valScheme = SAX2XMLReader::Val_Auto;
3039  XERCES::SAX2XMLReader::ValSchemes valScheme = XERCES::SAX2XMLReader::Val_Never;
3040  if(valScheme == XERCES::SAX2XMLReader::Val_Auto) {
3041  parser->setFeature(XERCES::XMLString::transcode("http://xml.org/sax/features/validation"), true);
3042  parser->setFeature(XERCES::XMLString::transcode("http://apache.org/xml/features/validation/dynamic"), true);
3043  }
3044  else if(valScheme == XERCES::SAX2XMLReader::Val_Never) {
3045  parser->setFeature(XERCES::XMLString::transcode("http://xml.org/sax/features/validation"), false);
3046  }
3047 
3048  else if(valScheme == XERCES::SAX2XMLReader::Val_Always) {
3049  parser->setFeature(XERCES::XMLString::transcode("http://xml.org/sax/features/validation"), true);
3050  parser->setFeature(XERCES::XMLString::transcode("http://apache.org/xml/features/validation/dynamic"), false);
3051  }
3052 
3053 // bool doSchema = true;
3054  bool doSchema = false;
3055  parser->setFeature(XERCES::XMLString::transcode("http://apache.org/xml/features/validation/schema"), doSchema);
3056 
3057  bool schemaFullChecking = false;
3058  parser->setFeature(XERCES::XMLString::transcode("http://apache.org/xml/features/validation/schema-full-checking"), schemaFullChecking);
3059 
3060  // Create the handler object for an application
3061  // Then parse the file
3062  char *encodingName = const_cast<char *>("LATIN1");
3063  bool expandNamespaces = false ;
3064 
3065  try {
3066  IsisAmlData *mydata = this;
3067  appHandler = new IsisXMLApplication(encodingName, expandNamespaces, parser, mydata);
3068  parser->parse(xmlfile);
3069  }
3070  catch(const XERCES::XMLException &toCatch) {
3071  QString message = "Error in application XML file: " +
3072  (QString)XERCES::XMLString::transcode(toCatch.getMessage());
3074  XERCES::XMLPlatformUtils::Terminate();
3075  return;
3076  }
3077 
3078  // Delete the parser
3079  delete parser;
3080  XERCES::XMLPlatformUtils::Terminate();
3081  delete appHandler;
3082  return;
3083 }
3084