Optika GUI Toolik Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 #include "Teuchos_XMLParameterListHelpers.hpp"
00042 #include "Teuchos_VerboseObject.hpp"
00043 #include "Teuchos_FancyOStream.hpp"
00044 #include "Optika_GUI.hpp"
00045 
00046 void print(Teuchos::RCP<const Teuchos::ParameterList> theList){
00047   
00048   Teuchos::RCP<Teuchos::FancyOStream> out = 
00049     Teuchos::VerboseObjectBase::getDefaultOStream();
00050   writeParameterListToXmlOStream(*theList, *out);
00051 }
00052 
00053 namespace Optika{
00054 
00055 
00056 void RUN_OPTIKA_DEPENDENCY_AND_EXEC_TEST(){
00057  using Teuchos::FancyOStream;
00058  using Teuchos::VerboseObjectBase;
00059  using Teuchos::StringToIntegralParameterEntryValidator;
00060  using Teuchos::StringValidatorDependency;
00061  using Teuchos::ArrayNumberValidator;
00062  using Teuchos::StringVisualDependency;
00063  using Teuchos::NumberVisualDependency;
00064  using Teuchos::NumberArrayLengthDependency;
00065  using Teuchos::BoolValidatorDependency;
00066  using Teuchos::BoolVisualDependency;
00067  using Teuchos::SubtractionFunction;
00068  using Teuchos::RangeValidatorDependency;
00069  using Teuchos::tuple;
00070  using Teuchos::rcp;
00071 
00072 
00073  RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream();
00074  RCP<ParameterList> My_deplist = rcp(new ParameterList);
00075  RCP<DependencySheet> depSheet1 = rcp(new DependencySheet);
00076 
00077   RCP<StringToIntegralParameterEntryValidator<int> >
00078     stringFoodTypeValidator = rcp(
00079       new StringToIntegralParameterEntryValidator<int>(
00080         tuple<std::string>( "Cheese", "Soda", "Chips" )
00081         ,"Food Type"
00082         )
00083       );
00084 
00085   RCP<StringToIntegralParameterEntryValidator<int> >
00086     cheeseValidator = rcp(
00087       new StringToIntegralParameterEntryValidator<int>(
00088         tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" )
00089         ,"Food Selector"
00090         )
00091       );
00092   RCP<StringToIntegralParameterEntryValidator<int> >
00093     sodaValidator = rcp(
00094       new StringToIntegralParameterEntryValidator<int>(
00095         tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" )
00096         ,"Food Selector"
00097         )
00098       );
00099   RCP<StringToIntegralParameterEntryValidator<int> >
00100     chipsValidator = rcp(
00101       new StringToIntegralParameterEntryValidator<int>(
00102         tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" )
00103         ,"Food Selector"
00104         )
00105       );
00106 
00107   StringValidatorDependency::ValueToValidatorMap testValidatorMap1;
00108   testValidatorMap1["Cheese"] = cheeseValidator;
00109   testValidatorMap1["Soda"] = sodaValidator;
00110   testValidatorMap1["Chips"] = chipsValidator;
00111 
00112 
00113   ParameterList&
00114     stringValiDepList = My_deplist->sublist("String Validator Dependency", false, "String Validator Dependency testing list.\nWorking June 27th 2009");
00115   stringValiDepList.set("Food Selector", "Swiss", "select the food you want", cheeseValidator);
00116   stringValiDepList.set("Food Type", "Cheese", "String Validator Dependency Tester", stringFoodTypeValidator);
00117   depSheet1->addDependency(RCP<StringValidatorDependency>(
00118     new StringValidatorDependency(
00119     My_deplist->getEntryRCP("Food Type"),
00120     My_deplist->getEntryRCP("Food Selector"),
00121     testValidatorMap1 )));
00122  
00123 
00124   RCP<StringToIntegralParameterEntryValidator<int> >
00125     stringRangeValidator = rcp(
00126       new StringToIntegralParameterEntryValidator<int>(
00127         tuple<std::string>( "1-10", "10-33", "50-60" )
00128         ,"Range selector"
00129         )
00130       );
00131   ParameterList&
00132     stringValiDepList2 = My_deplist->sublist("String Validator Dependency (other validators)", false, "String Validator Dependency testing list for EnhancedNumber Validators.");
00133   stringValiDepList2.set("Range selector", "1-10", "selects the range to validate", stringRangeValidator);
00134   RCP<EnhancedNumberValidator<int> > range110Vali = 
00135     rcp(new EnhancedNumberValidator<int>(1,10));
00136   RCP<EnhancedNumberValidator<int> > range1033Vali = 
00137     rcp(new EnhancedNumberValidator<int>(10,33));
00138   RCP<EnhancedNumberValidator<int> > range5060Vali = 
00139     rcp(new EnhancedNumberValidator<int>(50,60));
00140   StringValidatorDependency::ValueToValidatorMap rangeValidatorMap1;
00141   rangeValidatorMap1["1-10"] = range110Vali;
00142   rangeValidatorMap1["10-33"] = range1033Vali;
00143   rangeValidatorMap1["50-60"] = range5060Vali;
00144   stringValiDepList2.set("RangeValue", 3, "the value of the range", range110Vali);
00145   depSheet1->addDependency(RCP<StringValidatorDependency>(
00146     new StringValidatorDependency(
00147   My_deplist->getEntryRCP("Range selector"),
00148   My_deplist->getEntryRCP("RangeValue"),
00149   rangeValidatorMap1)));
00150 
00151 
00152   ParameterList&
00153     boolValidatorDepList = My_deplist->sublist("Bool Validator Dependency List", false, "Bool Validator Dependency testing list.\nWorking June 27th 2009");
00154   boolValidatorDepList.set("Use Validator?", true, "truns the validator on and off");
00155   RCP<EnhancedNumberValidator<int> > basicVali = 
00156     rcp(new EnhancedNumberValidator<int>(1,10));
00157   boolValidatorDepList.set("do I have a validator?", 4, "does it have a validator?", basicVali);
00158   depSheet1->addDependency(RCP<BoolValidatorDependency>(
00159     new BoolValidatorDependency(
00160       My_deplist->getEntryRCP("Use Validator?"),
00161       My_deplist->getEntryRCP("do I have a validator?"),
00162       basicVali, 
00163       RCP<ParameterEntryValidator>())));
00164 
00165 
00166   RCP<StringToIntegralParameterEntryValidator<int> >
00167     lowTempCheeseValidator = rcp(
00168       new StringToIntegralParameterEntryValidator<int>(
00169         tuple<std::string>( "PepperJack", "Swiss", "American" )
00170         ,"Cheese to Fondue"
00171         )
00172       );
00173 
00174   RCP<StringToIntegralParameterEntryValidator<int> >
00175     highTempCheeseValidator = rcp(
00176       new StringToIntegralParameterEntryValidator<int>(
00177         tuple<std::string>( "Munster", "Provalone", "Kurtis Super Awesome Cheese")
00178         ,"Cheese to Fondue"
00179         )
00180       );
00181   ParameterList&
00182     rangeValidatorDepList = My_deplist->sublist("Range Validator and NumberVisual Dependency List", false, "Range Validator and Number Visual Dependency testing list.");
00183   rangeValidatorDepList.set("Temperature",101.0, "The temperature of the fondue");
00184   rangeValidatorDepList.set("Cheese to Fondue", "Swiss", "The cheese we'll be using in our fondue pot.", lowTempCheeseValidator);
00185   RangeValidatorDependency<double>::RangeToValidatorMap tempranges;
00186   tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator;
00187   tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator;
00188   RCP<RangeValidatorDependency<double> > cheeseTempDep = rcp(
00189     new RangeValidatorDependency<double>(
00190       My_deplist->getEntryRCP("Temperature"),
00191       My_deplist->getEntryRCP("Cheese to Fondue"),
00192       tempranges));
00193  
00194   depSheet1->addDependency(cheeseTempDep);
00195   
00196   RCP<SubtractionFunction<double> > fondueFunc = rcp(
00197     new SubtractionFunction<double>(100));
00198   RCP<NumberVisualDependency<double> > fondueDep = 
00199       RCP<NumberVisualDependency<double> >(new NumberVisualDependency<double>(
00200       My_deplist->getEntryRCP("Temperature"),
00201       My_deplist->getEntryRCP("Cheese to Fondue"),
00202       true,
00203       fondueFunc));
00204   depSheet1->addDependency(fondueDep);
00205 
00206   ParameterList&
00207     numberArrayLengthDepList = My_deplist->sublist("Number Array Length Dependency List", false, "Number Array Length ependecy testing list.");
00208   numberArrayLengthDepList.set("Array Length", 8, "array length setter");
00209   Array<double> variableLengthArray(10,23.0);
00210   RCP<EnhancedNumberValidator<double> > varLengthArrayVali = RCP<EnhancedNumberValidator<double> >(
00211     new EnhancedNumberValidator<double>(10,50,4) );
00212   numberArrayLengthDepList.set("Variable Length Array", variableLengthArray, "variable length array",
00213   RCP<ArrayNumberValidator<double> >(new ArrayNumberValidator<double>(varLengthArrayVali)));
00214 
00215   RCP<NumberArrayLengthDependency<int, double> > arrayLengthDep(
00216     new NumberArrayLengthDependency<int, double>(My_deplist->getEntryRCP("Array Length"), 
00217     My_deplist->getEntryRCP("Variable Length Array")));
00218   depSheet1->addDependency(arrayLengthDep);
00219 
00220 
00221 
00222   ParameterList&
00223     numberValiAspDepList = My_deplist->sublist("Number Validator Aspect Dependency List", false, "Number Validator Aspect Dependency testing list.");
00224   RCP<EnhancedNumberValidator<int> > intVali2 = 
00225     rcp(new EnhancedNumberValidator<int>(0,20));
00226   numberValiAspDepList.set("Int", 8, "Int tester", intVali2);
00227   numberValiAspDepList.set("Int2", 8, "int2 tester", intVali2);
00228   numberValiAspDepList.set("Int dependee", 1, "Int dependee");
00229 
00230   ParameterList&
00231     boolVisDepList = My_deplist->sublist("Bool Visual Dependency List", false, "Bool Visual Dependency testing list.");
00232   boolVisDepList.set("ShowPrecs", true, "Whether or not to should the Preciondtioner list");
00233   ParameterList&
00234     Prec_List0 = boolVisDepList.sublist("Preconditioner",false,"Sublist that defines the preconditioner.");
00235   Prec_List0.set("Type", "ILU", "The tpye of preconditioner to use");
00236   RCP<EnhancedNumberValidator<double> > droptolValidator = rcp(new EnhancedNumberValidator<double>(0,10,1e-3));
00237   Prec_List0.set("Drop Tolerance", 1e-3
00238                 ,"The tolerance below which entries from the\n""factorization are left out of the factors.", droptolValidator);
00239   RCP<BoolVisualDependency> precDep1 = rcp(new BoolVisualDependency(
00240   My_deplist->getEntryRCP("ShowPrecs"),
00241   My_deplist->getEntryRCP("Preconditioner"),
00242   true));
00243   depSheet1->addDependency(precDep1);
00244 
00245 
00246 
00247 
00248 ParameterList&
00249     stringVisDepList = My_deplist->sublist("String Visual Dependency List", false, "String Visual Dependency testing list.\nWorking June 29 2009");
00250   RCP<StringToIntegralParameterEntryValidator<int> >
00251     favCheeseValidator = rcp(
00252       new StringToIntegralParameterEntryValidator<int>(
00253         tuple<std::string>( "Swiss", "American", "Cheder" )
00254         ,"Favorite Cheese"
00255         )
00256       );
00257    
00258    stringVisDepList.set(
00259     "Favorite Cheese", "American", "Your favorite type of cheese", favCheeseValidator);
00260    RCP<EnhancedNumberValidator<int> > swissValidator = rcp(new EnhancedNumberValidator<int>(0,10));
00261    stringVisDepList.set("Swiss rating", 0, "How you rate swiss on a scale of 1 to 10", swissValidator);
00262    RCP<StringVisualDependency> swissDep1 = 
00263       RCP<StringVisualDependency>(new StringVisualDependency(
00264       My_deplist->getEntryRCP("Favorite Cheese"),
00265       My_deplist->getEntryRCP("Swiss rating"),
00266       "Swiss", 
00267       true));
00268    depSheet1->addDependency(swissDep1);
00269 
00270 
00271 
00272 
00273 
00274   RCP<SubtractionFunction<int> > intVisTester =
00275     rcp(new SubtractionFunction<int>(32));
00276   ParameterList&
00277     numberVisDepList = My_deplist->sublist(
00278       "Number Visual Dependency List", false, 
00279       "Number Visual Dependency testing list.");
00280   numberVisDepList.set("Ice", 50, "Ice stuff");
00281   numberVisDepList.set("Room Temp", 10, "Room temperature");
00282   RCP<NumberVisualDependency<int> > iceDep = 
00283       RCP<NumberVisualDependency<int> >(
00284         new NumberVisualDependency<int>(
00285       My_deplist->getEntryRCP("Room Temp"),
00286       My_deplist->getEntryRCP("Ice"),
00287       true,
00288       intVisTester));
00289   depSheet1->addDependency(iceDep);
00290 
00291 
00292 
00293 
00294   void (*myFunc)(RCP<const ParameterList>);
00295   myFunc = print;
00296   getInput(My_deplist, depSheet1, myFunc);
00297 
00298   std::cout << "Dep List: \n";
00299   writeParameterListToXmlOStream(*My_deplist, *out);
00300 
00301   std::cout << "Deps: \n";
00302   depSheet1->printDeps(std::cout);
00303 
00304 
00305 }
00306 
00307 
00308 }
00309 
00310 
00311 int main(){
00312   Optika::RUN_OPTIKA_DEPENDENCY_AND_EXEC_TEST();
00313   return 0;
00314 }
00315 
00316 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines