Optika GUI Toolik  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test/gui/dependencyandexec/main.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Optika: A Tool For Developing Parameter Obtaining GUIs
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the
8 // U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com)
38 //
39 // ***********************************************************************
40 // @HEADER
43 #include "Teuchos_FancyOStream.hpp"
44 #include "Optika_GUI.hpp"
45 
47 
49  Teuchos::VerboseObjectBase::getDefaultOStream();
50  writeParameterListToXmlOStream(*theList, *out);
51 }
52 
53 namespace Optika{
54 
55 
69  using Teuchos::tuple;
70  using Teuchos::rcp;
71 
72 
73  RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream();
74  RCP<ParameterList> My_deplist = rcp(new ParameterList);
75  RCP<DependencySheet> depSheet1 = rcp(new DependencySheet);
76 
78  stringFoodTypeValidator = rcp(
79  new StringToIntegralParameterEntryValidator<int>(
80  tuple<std::string>( "Cheese", "Soda", "Chips" )
81  ,"Food Type"
82  )
83  );
84 
86  cheeseValidator = rcp(
87  new StringToIntegralParameterEntryValidator<int>(
88  tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" )
89  ,"Food Selector"
90  )
91  );
93  sodaValidator = rcp(
94  new StringToIntegralParameterEntryValidator<int>(
95  tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" )
96  ,"Food Selector"
97  )
98  );
100  chipsValidator = rcp(
101  new StringToIntegralParameterEntryValidator<int>(
102  tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" )
103  ,"Food Selector"
104  )
105  );
106 
107  StringValidatorDependency::ValueToValidatorMap testValidatorMap1;
108  testValidatorMap1["Cheese"] = cheeseValidator;
109  testValidatorMap1["Soda"] = sodaValidator;
110  testValidatorMap1["Chips"] = chipsValidator;
111 
112 
114  stringValiDepList = My_deplist->sublist("String Validator Dependency", false, "String Validator Dependency testing list.\nWorking June 27th 2009");
115  stringValiDepList.set("Food Selector", "Swiss", "select the food you want", cheeseValidator);
116  stringValiDepList.set("Food Type", "Cheese", "String Validator Dependency Tester", stringFoodTypeValidator);
118  new StringValidatorDependency(
119  My_deplist->getEntryRCP("Food Type"),
120  My_deplist->getEntryRCP("Food Selector"),
121  testValidatorMap1 )));
122 
123 
125  stringRangeValidator = rcp(
126  new StringToIntegralParameterEntryValidator<int>(
127  tuple<std::string>( "1-10", "10-33", "50-60" )
128  ,"Range selector"
129  )
130  );
132  stringValiDepList2 = My_deplist->sublist("String Validator Dependency (other validators)", false, "String Validator Dependency testing list for EnhancedNumber Validators.");
133  stringValiDepList2.set("Range selector", "1-10", "selects the range to validate", stringRangeValidator);
134  RCP<EnhancedNumberValidator<int> > range110Vali =
136  RCP<EnhancedNumberValidator<int> > range1033Vali =
137  rcp(new EnhancedNumberValidator<int>(10,33));
138  RCP<EnhancedNumberValidator<int> > range5060Vali =
139  rcp(new EnhancedNumberValidator<int>(50,60));
140  StringValidatorDependency::ValueToValidatorMap rangeValidatorMap1;
141  rangeValidatorMap1["1-10"] = range110Vali;
142  rangeValidatorMap1["10-33"] = range1033Vali;
143  rangeValidatorMap1["50-60"] = range5060Vali;
144  stringValiDepList2.set("RangeValue", 3, "the value of the range", range110Vali);
146  new StringValidatorDependency(
147  My_deplist->getEntryRCP("Range selector"),
148  My_deplist->getEntryRCP("RangeValue"),
149  rangeValidatorMap1)));
150 
151 
153  boolValidatorDepList = My_deplist->sublist("Bool Validator Dependency List", false, "Bool Validator Dependency testing list.\nWorking June 27th 2009");
154  boolValidatorDepList.set("Use Validator?", true, "truns the validator on and off");
155  RCP<EnhancedNumberValidator<int> > basicVali =
157  boolValidatorDepList.set("do I have a validator?", 4, "does it have a validator?", basicVali);
159  new BoolValidatorDependency(
160  My_deplist->getEntryRCP("Use Validator?"),
161  My_deplist->getEntryRCP("do I have a validator?"),
162  basicVali,
164 
165 
167  lowTempCheeseValidator = rcp(
168  new StringToIntegralParameterEntryValidator<int>(
169  tuple<std::string>( "PepperJack", "Swiss", "American" )
170  ,"Cheese to Fondue"
171  )
172  );
173 
175  highTempCheeseValidator = rcp(
176  new StringToIntegralParameterEntryValidator<int>(
177  tuple<std::string>( "Munster", "Provalone", "Kurtis Super Awesome Cheese")
178  ,"Cheese to Fondue"
179  )
180  );
182  rangeValidatorDepList = My_deplist->sublist("Range Validator and NumberVisual Dependency List", false, "Range Validator and Number Visual Dependency testing list.");
183  rangeValidatorDepList.set("Temperature",101.0, "The temperature of the fondue");
184  rangeValidatorDepList.set("Cheese to Fondue", "Swiss", "The cheese we'll be using in our fondue pot.", lowTempCheeseValidator);
185  RangeValidatorDependency<double>::RangeToValidatorMap tempranges;
186  tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator;
187  tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator;
188  RCP<RangeValidatorDependency<double> > cheeseTempDep = rcp(
189  new RangeValidatorDependency<double>(
190  My_deplist->getEntryRCP("Temperature"),
191  My_deplist->getEntryRCP("Cheese to Fondue"),
192  tempranges));
193 
194  depSheet1->addDependency(cheeseTempDep);
195 
196  RCP<SubtractionFunction<double> > fondueFunc = rcp(
197  new SubtractionFunction<double>(100));
199  RCP<NumberVisualDependency<double> >(new NumberVisualDependency<double>(
200  My_deplist->getEntryRCP("Temperature"),
201  My_deplist->getEntryRCP("Cheese to Fondue"),
202  true,
203  fondueFunc));
204  depSheet1->addDependency(fondueDep);
205 
207  numberArrayLengthDepList = My_deplist->sublist("Number Array Length Dependency List", false, "Number Array Length ependecy testing list.");
208  numberArrayLengthDepList.set("Array Length", 8, "array length setter");
209  Array<double> variableLengthArray(10,23.0);
211  new EnhancedNumberValidator<double>(10,50,4) );
212  numberArrayLengthDepList.set("Variable Length Array", variableLengthArray, "variable length array",
213  RCP<ArrayNumberValidator<double> >(new ArrayNumberValidator<double>(varLengthArrayVali)));
214 
216  new NumberArrayLengthDependency<int, double>(My_deplist->getEntryRCP("Array Length"),
217  My_deplist->getEntryRCP("Variable Length Array")));
218  depSheet1->addDependency(arrayLengthDep);
219 
220 
221 
223  numberValiAspDepList = My_deplist->sublist("Number Validator Aspect Dependency List", false, "Number Validator Aspect Dependency testing list.");
226  numberValiAspDepList.set("Int", 8, "Int tester", intVali2);
227  numberValiAspDepList.set("Int2", 8, "int2 tester", intVali2);
228  numberValiAspDepList.set("Int dependee", 1, "Int dependee");
229 
231  boolVisDepList = My_deplist->sublist("Bool Visual Dependency List", false, "Bool Visual Dependency testing list.");
232  boolVisDepList.set("ShowPrecs", true, "Whether or not to should the Preciondtioner list");
234  Prec_List0 = boolVisDepList.sublist("Preconditioner",false,"Sublist that defines the preconditioner.");
235  Prec_List0.set("Type", "ILU", "The tpye of preconditioner to use");
236  RCP<EnhancedNumberValidator<double> > droptolValidator = rcp(new EnhancedNumberValidator<double>(0,10,1e-3));
237  Prec_List0.set("Drop Tolerance", 1e-3
238  ,"The tolerance below which entries from the\n""factorization are left out of the factors.", droptolValidator);
239  RCP<BoolVisualDependency> precDep1 = rcp(new BoolVisualDependency(
240  My_deplist->getEntryRCP("ShowPrecs"),
241  My_deplist->getEntryRCP("Preconditioner"),
242  true));
243  depSheet1->addDependency(precDep1);
244 
245 
246 
247 
249  stringVisDepList = My_deplist->sublist("String Visual Dependency List", false, "String Visual Dependency testing list.\nWorking June 29 2009");
251  favCheeseValidator = rcp(
252  new StringToIntegralParameterEntryValidator<int>(
253  tuple<std::string>( "Swiss", "American", "Cheder" )
254  ,"Favorite Cheese"
255  )
256  );
257 
258  stringVisDepList.set(
259  "Favorite Cheese", "American", "Your favorite type of cheese", favCheeseValidator);
261  stringVisDepList.set("Swiss rating", 0, "How you rate swiss on a scale of 1 to 10", swissValidator);
262  RCP<StringVisualDependency> swissDep1 =
263  RCP<StringVisualDependency>(new StringVisualDependency(
264  My_deplist->getEntryRCP("Favorite Cheese"),
265  My_deplist->getEntryRCP("Swiss rating"),
266  "Swiss",
267  true));
268  depSheet1->addDependency(swissDep1);
269 
270 
271 
272 
273 
274  RCP<SubtractionFunction<int> > intVisTester =
275  rcp(new SubtractionFunction<int>(32));
277  numberVisDepList = My_deplist->sublist(
278  "Number Visual Dependency List", false,
279  "Number Visual Dependency testing list.");
280  numberVisDepList.set("Ice", 50, "Ice stuff");
281  numberVisDepList.set("Room Temp", 10, "Room temperature");
284  new NumberVisualDependency<int>(
285  My_deplist->getEntryRCP("Room Temp"),
286  My_deplist->getEntryRCP("Ice"),
287  true,
288  intVisTester));
289  depSheet1->addDependency(iceDep);
290 
291 
292 
293 
294  void (*myFunc)(RCP<const ParameterList>);
295  myFunc = print;
296  getInput(My_deplist, depSheet1, myFunc);
297 
298  std::cout << "Dep List: \n";
299  writeParameterListToXmlOStream(*My_deplist, *out);
300 
301  std::cout << "Deps: \n";
302  depSheet1->printDeps(std::cout);
303 
304 
305 }
306 
307 
308 }
309 
310 
311 int main(){
313  return 0;
314 }
315 
316 
RCP< ParameterEntry > getEntryRCP(const std::string &name)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
A collection of functions and an Object that serve as the primary interface to the Optika package all...
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void printDeps(std::ostream &out) const
void addDependency(RCP< Dependency > dependency)
void getInput(RCP< ParameterList > validParameters, RCP< DependencySheet > dependencySheet, void(*customFunc)(RCP< const ParameterList >))
Retreives the input for a Teuchos Parameter List using a GUI. Note the Parameter List will be edited...
Definition: Optika_GUI.cpp:47
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void RUN_OPTIKA_DEPENDENCY_AND_EXEC_TEST()
basic_FancyOStream< char > FancyOStream
void print(Teuchos::RCP< const Teuchos::ParameterList > theList)