test/gui/dependencyandexec/main.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00005 //                Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00008 // U.S. Government retains certain rights in this software.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 #include "Teuchos_XMLParameterListHelpers.hpp"
00029 #include "Teuchos_VerboseObject.hpp"
00030 #include "Teuchos_FancyOStream.hpp"
00031 #include "Optika_GUI.hpp"
00032 #include "Optika_StandardDependencies.hpp"
00033 
00034 void print(Teuchos::RCP<const Teuchos::ParameterList> theList){
00035   Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
00036   Teuchos::writeParameterListToXmlOStream(*theList, *out);
00037 }
00038 
00039 int intFuncTester(int argument){
00040   return argument+10;
00041 }
00042 
00043 int intVisualTester(int argument){
00044   if(argument <= 32){
00045     return 1;
00046   }
00047   else{
00048     return 0;
00049   }
00050 }
00051 
00052 double fondueTempTester(double argument){
00053   return argument-100;
00054 }
00055 
00056 int main(){
00057  Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
00058  Teuchos::RCP<Teuchos::ParameterList> My_deplist = Teuchos::RCP<Teuchos::ParameterList>(new Teuchos::ParameterList);
00059  Teuchos::RCP<Optika::DependencySheet> depSheet1 = Teuchos::RCP<Optika::DependencySheet>(new Optika::DependencySheet(My_deplist));
00060 
00061   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00062     stringFoodTypeValidator = Teuchos::rcp(
00063       new Teuchos::StringToIntegralParameterEntryValidator<int>(
00064         Teuchos::tuple<std::string>( "Cheese", "Soda", "Chips" )
00065         ,"Food Type"
00066         )
00067       );
00068 
00069   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00070     cheeseValidator = Teuchos::rcp(
00071       new Teuchos::StringToIntegralParameterEntryValidator<int>(
00072         Teuchos::tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" )
00073         ,"Food Selector"
00074         )
00075       );
00076   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00077     sodaValidator = Teuchos::rcp(
00078       new Teuchos::StringToIntegralParameterEntryValidator<int>(
00079         Teuchos::tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" )
00080         ,"Food Selector"
00081         )
00082       );
00083   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00084     chipsValidator = Teuchos::rcp(
00085       new Teuchos::StringToIntegralParameterEntryValidator<int>(
00086         Teuchos::tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" )
00087         ,"Food Selector"
00088         )
00089       );
00090 
00091   Optika::StringValidatorDependency::ValueToValidatorMap testValidatorMap1;
00092   testValidatorMap1["Cheese"] = cheeseValidator;
00093   testValidatorMap1["Soda"] = sodaValidator;
00094   testValidatorMap1["Chips"] = chipsValidator;
00095 
00096 
00097   Teuchos::ParameterList&
00098     stringValiDepList = My_deplist->sublist("String Validator Dependency", false, "String Validator Dependency testing list.\nWorking June 27th 2009");
00099   stringValiDepList.set("Food Selector", "Swiss", "select the food you want", cheeseValidator);
00100   stringValiDepList.set("Food Type", "Cheese", "String Validator Dependency Tester", stringFoodTypeValidator);
00101   depSheet1->addDependency(Teuchos::RCP<Optika::StringValidatorDependency>(
00102     new Optika::StringValidatorDependency("Food Type", 
00103   Teuchos::sublist(My_deplist,"String Validator Dependency"),
00104   "Food Selector", 
00105   Teuchos::sublist(My_deplist,"String Validator Dependency"),
00106   testValidatorMap1, 
00107   cheeseValidator)));
00108  
00109 
00110   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00111     stringRangeValidator = Teuchos::rcp(
00112       new Teuchos::StringToIntegralParameterEntryValidator<int>(
00113         Teuchos::tuple<std::string>( "1-10", "10-33", "50-60" )
00114         ,"Range selector"
00115         )
00116       );
00117   Teuchos::ParameterList&
00118     stringValiDepList2 = My_deplist->sublist("String Validator Dependency (other validators)", false, "String Validator Dependency testing list for EnhancedNumber Validators.\nWorking June 27th 2009");
00119   stringValiDepList2.set("Range selector", "1-10", "selects the range to validate", stringRangeValidator);
00120   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > range110Vali = 
00121     Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(1,10));
00122   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > range1033Vali = 
00123     Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(10,33));
00124   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > range5060Vali = 
00125     Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(50,60));
00126   Optika::StringValidatorDependency::ValueToValidatorMap rangeValidatorMap1;
00127   rangeValidatorMap1["1-10"] = range110Vali;
00128   rangeValidatorMap1["10-33"] = range1033Vali;
00129   rangeValidatorMap1["50-60"] = range5060Vali;
00130   stringValiDepList2.set("RangeValue", 3, "the value of the range", range110Vali);
00131   depSheet1->addDependency(Teuchos::RCP<Optika::StringValidatorDependency>(
00132     new Optika::StringValidatorDependency(
00133   "Range selector", 
00134   Teuchos::sublist(My_deplist,"String Validator Dependency (other validators)"),
00135   "RangeValue", 
00136   Teuchos::sublist(My_deplist,"String Validator Dependency (other validators)"),
00137   rangeValidatorMap1, 
00138   range110Vali)));
00139 
00140 
00141   Teuchos::ParameterList&
00142     boolValidatorDepList = My_deplist->sublist("Bool Validator Dependency List", false, "Bool Validator Dependency testing list.\nWorking June 27th 2009");
00143   boolValidatorDepList.set("Use Validator?", true, "truns the validator on and off");
00144   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > basicVali = 
00145     Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(1,10));
00146   boolValidatorDepList.set("do I have a validator?", 4, "does it have a validator?", basicVali);
00147   depSheet1->addDependency(Teuchos::RCP<Optika::BoolValidatorDependency>(
00148     new Optika::BoolValidatorDependency(
00149   "Use Validator?", 
00150   Teuchos::sublist(My_deplist,"Bool Validator Dependency List"),
00151   "do I have a validator?", 
00152   Teuchos::sublist(My_deplist,"Bool Validator Dependency List"),
00153   basicVali, 
00154   Teuchos::RCP<Teuchos::ParameterEntryValidator>())));
00155   
00156 
00157 
00158 
00159 
00160 
00161 
00162   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00163     lowTempCheeseValidator = Teuchos::rcp(
00164       new Teuchos::StringToIntegralParameterEntryValidator<int>(
00165         Teuchos::tuple<std::string>( "PepperJack", "Swiss", "American" )
00166         ,"Cheese to Fondue"
00167         )
00168       );
00169 
00170   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00171     highTempCheeseValidator = Teuchos::rcp(
00172       new Teuchos::StringToIntegralParameterEntryValidator<int>(
00173         Teuchos::tuple<std::string>( "Munster", "Provalone", "Kurtis Super Awesome Cheese")
00174         ,"Cheese to Fondue"
00175         )
00176       );
00177   Teuchos::ParameterList&
00178     rangeValidatorDepList = My_deplist->sublist("Range Validator and NumberVisual Dependency List", false, "Range Validator and Number Visual Dependency testing list.\nWorking June 27th 2009");
00179   rangeValidatorDepList.set("Temperature",101.0, "The temperature of the fondue");
00180   rangeValidatorDepList.set("Cheese to Fondue", "Swiss", "The cheese we'll be using in our fondue pot.", lowTempCheeseValidator);
00181   Optika::RangeValidatorDependency<double>::RangeToValidatorMap tempranges;
00182   tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator;
00183   tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator;
00184   Teuchos::RCP<Optika::RangeValidatorDependency<double> > cheeseTempDep = Teuchos::RCP<Optika::RangeValidatorDependency<double> >(
00185     new Optika::RangeValidatorDependency<double>(
00186   "Temperature", 
00187   Teuchos::sublist(My_deplist,"Range Validator and NumberVisual Dependency List"),
00188   "Cheese to Fondue", 
00189   Teuchos::sublist(My_deplist,"Range Validator and NumberVisual Dependency List"),
00190   tempranges, 
00191   lowTempCheeseValidator) );
00192   depSheet1->addDependency(cheeseTempDep);
00193   
00194   double (*fondueFunc)(double);
00195   fondueFunc = fondueTempTester;
00196 
00197   Teuchos::RCP<Optika::NumberVisualDependency<double> > fondueDep = 
00198       Teuchos::RCP<Optika::NumberVisualDependency<double> >(new Optika::NumberVisualDependency<double>(
00199       "Temperature", 
00200       Teuchos::sublist(My_deplist,"Range Validator and NumberVisual Dependency List"),
00201       "Cheese to Fondue", 
00202       Teuchos::sublist(My_deplist,"Range Validator and NumberVisual Dependency List"),
00203       fondueFunc));
00204   depSheet1->addDependency(fondueDep);
00205 
00206 
00207 
00208 
00209   Teuchos::ParameterList&
00210     numberArrayLengthDepList = My_deplist->sublist("Number Array Length Dependency List", false, "Number Array Length ependecy testing list.\nWorking June 27th 2009");
00211   numberArrayLengthDepList.set("Array Length", 8, "array length setter");
00212   Teuchos::Array<double> variableLengthArray(10,23.0);
00213   Teuchos::RCP<Optika::EnhancedNumberValidator<double> > varLengthArrayVali = Teuchos::RCP<Optika::EnhancedNumberValidator<double> >(
00214     new Optika::EnhancedNumberValidator<double>(10,50,4) );
00215   numberArrayLengthDepList.set("Variable Length Array", variableLengthArray, "variable length array",
00216   Teuchos::RCP<Optika::ArrayNumberValidator<double> >(new Optika::ArrayNumberValidator<double>(varLengthArrayVali)));
00217 
00218   Teuchos::RCP<Optika::NumberArrayLengthDependency> arrayLengthDep = Teuchos::RCP<Optika::NumberArrayLengthDependency>(
00219     new Optika::NumberArrayLengthDependency(
00220   "Array Length", 
00221   Teuchos::sublist(My_deplist,"Number Array Length Dependency List"),
00222   "Variable Length Array", 
00223   Teuchos::sublist(My_deplist,"Number Array Length Dependency List")));
00224   depSheet1->addDependency(arrayLengthDep);
00225 
00226 
00227 
00228   Teuchos::ParameterList&
00229     numberValiAspDepList = My_deplist->sublist("Number Validator Aspect Dependency List", false, "Number Validator Aspect Dependency testing list.\nWorking June 27th 2009");
00230   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > intVali2 = 
00231     Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(0,20));
00232   numberValiAspDepList.set("Int", 8, "Int tester", intVali2);
00233   numberValiAspDepList.set("Int2", 8, "int2 tester", intVali2);
00234   numberValiAspDepList.set("Int dependee", 1, "Int dependee");
00235 
00236   int (*func)(int);
00237   func = intFuncTester;
00238 
00239   Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> > intDep1 =
00240      Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> >(
00241        new Optika::NumberValidatorAspectDependency<int>(
00242    "Int dependee",
00243   Teuchos::sublist(My_deplist,"Number Validator Aspect Dependency List"),
00244          "Int",
00245   Teuchos::sublist(My_deplist,"Number Validator Aspect Dependency List"),
00246    intVali2,
00247    Optika::NumberValidatorAspectDependency<int>::Max,
00248    func
00249    ));
00250   Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> > intDep2 =
00251      Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> >(
00252        new Optika::NumberValidatorAspectDependency<int>(
00253    "Int dependee",
00254   Teuchos::sublist(My_deplist,"Number Validator Aspect Dependency List"),
00255          "Int2",
00256   Teuchos::sublist(My_deplist,"Number Validator Aspect Dependency List"),
00257    intVali2,
00258    Optika::NumberValidatorAspectDependency<int>::Max,
00259    func
00260    ));
00261 
00262   depSheet1->addDependency(intDep1);
00263   depSheet1->addDependency(intDep2);
00264 
00265   
00266 
00267 
00268 
00269   Teuchos::ParameterList&
00270     boolVisDepList = My_deplist->sublist("Bool Visual Dependency List", false, "Bool Visual Dependency testing list.\nWorking June 29 2009");
00271   boolVisDepList.set("ShowPrecs", true, "Whether or not to should the Preciondtioner list");
00272   Teuchos::ParameterList&
00273     Prec_List0 = boolVisDepList.sublist("Preconditioner",false,"Sublist that defines the preconditioner.");
00274   Prec_List0.set("Type", "ILU", "The tpye of preconditioner to use");
00275   Teuchos::RCP<Optika::EnhancedNumberValidator<double> > droptolValidator = Teuchos::rcp(new Optika::EnhancedNumberValidator<double>(0,10,1e-3));
00276   Prec_List0.set("Drop Tolerance", 1e-3
00277                 ,"The tolerance below which entries from the\n""factorization are left out of the factors.", droptolValidator);
00278   Teuchos::RCP<Optika::BoolVisualDependency> precDep1 = Teuchos::RCP<Optika::BoolVisualDependency>(new Optika::BoolVisualDependency(
00279   "ShowPrecs", 
00280   Teuchos::sublist(My_deplist,"Bool Visual Dependency List"),
00281   "Preconditioner", 
00282   Teuchos::sublist(My_deplist,"Bool Visual Dependency List"),
00283   true));
00284   depSheet1->addDependency(precDep1);
00285 
00286 
00287 
00288 
00289 Teuchos::ParameterList&
00290     stringVisDepList = My_deplist->sublist("String Visual Dependency List", false, "String Visual Dependency testing list.\nWorking June 29 2009");
00291   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00292     favCheeseValidator = Teuchos::rcp(
00293       new Teuchos::StringToIntegralParameterEntryValidator<int>(
00294         Teuchos::tuple<std::string>( "Swiss", "American", "Cheder" )
00295         ,"Favorite Cheese"
00296         )
00297       );
00298    
00299    stringVisDepList.set(
00300     "Favorite Cheese", "American", "Your favorite type of cheese", favCheeseValidator);
00301    Teuchos::RCP<Optika::EnhancedNumberValidator<int> > swissValidator = Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(0,10));
00302    stringVisDepList.set("Swiss rating", 0, "How you rate swiss on a scale of 1 to 10", swissValidator);
00303    Teuchos::RCP<Optika::StringVisualDependency> swissDep1 = 
00304       Teuchos::RCP<Optika::StringVisualDependency>(new Optika::StringVisualDependency(
00305       "Favorite Cheese", 
00306   Teuchos::sublist(My_deplist,"String Visual Dependency List"),
00307       "Swiss rating", 
00308   Teuchos::sublist(My_deplist,"String Visual Dependency List"),
00309       "Swiss", 
00310       true));
00311    depSheet1->addDependency(swissDep1);
00312 
00313 
00314 
00315 
00316 
00317   int (*visfunc)(int);
00318   visfunc = intVisualTester;
00319 Teuchos::ParameterList&
00320     numberVisDepList = My_deplist->sublist("Number Visual Dependency List", false, "Number Visual Dependency testing list.\nWorking June 27th 2009");
00321   numberVisDepList.set("Ice", 50, "Ice stuff");
00322   numberVisDepList.set("Room Temp", 10, "Room temperature");
00323   Teuchos::RCP<Optika::NumberVisualDependency<int> > iceDep = 
00324       Teuchos::RCP<Optika::NumberVisualDependency<int> >(new Optika::NumberVisualDependency<int>(
00325       "Room Temp", 
00326   Teuchos::sublist(My_deplist,"Number Visual Dependency List"),
00327       "Ice", 
00328   Teuchos::sublist(My_deplist,"Number Visual Dependency List"),
00329       visfunc));
00330   depSheet1->addDependency(iceDep);
00331 
00332 
00333 
00334 
00335  void (*myFunc)(Teuchos::RCP<const Teuchos::ParameterList>);
00336   myFunc = print;
00337   Optika::getInput(My_deplist, depSheet1, myFunc);
00338 
00339   std::cout << "Dep List: \n";
00340   Teuchos::writeParameterListToXmlOStream(*My_deplist, *out);
00341 
00342   std::cout << "Deps: \n";
00343   depSheet1->printDeps();
00344 
00345 
00346   return 0;
00347 }
00348 
00349 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Generated on Wed Apr 13 10:05:58 2011 for Optika GUI Toolik by  doxygen 1.6.3