VAPoR  3.0.0
params.h
Go to the documentation of this file.
1 //************************************************************************
2 // *
3 // Copyright (C) 2004 *
4 // University Corporation for Atmospheric Research *
5 // All Rights Reserved *
6 // *
7 //************************************************************************/
8 //
9 // File: params.h
10 //
11 // Author: Alan Norton
12 // National Center for Atmospheric Research
13 // PO 3000, Boulder, Colorado
14 //
15 // Date: October 2004
16 //
17 // Description: Defines the Params classes.
18 // This is an abstract class for all the tabbed panel params classes.
19 // Supports functionality common to all the tabbed panel params.
20 
21 //
22 #ifndef PARAMS_H
23 #define PARAMS_H
24 
25 #include <vapor/XmlNode.h>
26 #include <vapor/ExpatParseMgr.h>
27 #include <vapor/ParamNode.h>
28 #include <map>
29 
30 #include "assert.h"
31 #include <vapor/common.h>
32 #include <vapor/ParamsBase.h>
33 #include <vapor/RegularGrid.h>
34 #include "Box.h"
35 
36 using namespace VetsUtil;
37 
38 namespace VAPoR{
39 
40 class XmlNode;
41 class ParamNode;
42 class DummyParams;
43 class RenderParams;
44 class ViewpointParams;
45 class RegionParams;
46 class DataMgrV3_0;
47 class Command;
48 
51 
129 class PARAMS_API Params : public MyBase, public ParamsBase {
130 
131 public:
135 
140 Params(
141  XmlNode *parent, const string &name, int winNum
142  );
144 Params(int winNum, const string& name) : ParamsBase(name) {
145  SetVizNum(winNum);
146  if(winNum < 0) SetLocal(false); else SetLocal( true);
147 
148  previousClass = 0;
149 }
150 
158  virtual int GetInstanceIndex();
159 
165  static int GetCurrentParamsInstanceIndex(int pType, int winnum){
166  return _currentParamsInstance[make_pair(pType,winnum)];
167  }
174  static int GetCurrentParamsInstanceIndex(const std::string tag, int winnum){
175  return GetCurrentParamsInstanceIndex(GetTypeFromTag(tag),winnum);
176  }
177 
183  static void SetCurrentParamsInstanceIndex(int pType, int winnum, int instance){
184  _currentParamsInstance[make_pair(pType,winnum)] = instance;
185  }
186 
194  static Params* GetParamsInstance(int pType, int winnum = -1, int instance = -1);
195 
203  static Params* GetParamsInstance(const std::string tag, int winnum = -1, int instance = -1){
204  return GetParamsInstance(GetTypeFromTag(tag), winnum, instance);
205  }
206 
212  static Params* GetCurrentParamsInstance(int pType, int winnum){
213  Params* p = GetParamsInstance(pType, winnum, -1);
214  if (!p) return p;
215  if (p->IsLocal()) return p;
216  return GetDefaultParams(pType);
217  }
218 
225  return _defaultParamsInstance[pType];
226  }
227 
234  static Params* GetDefaultParams(const string& tag){
235  return _defaultParamsInstance[GetTypeFromTag(tag)];
236  }
237 
243  static void SetDefaultParams(int pType, Params* p) {
244  _defaultParamsInstance[pType] = p;
245  }
246 
253  static void SetDefaultParams(const string& tag, Params* p) {
254  _defaultParamsInstance[GetTypeFromTag(tag)] = p;
255  }
260  static Params* CreateDefaultParams(int pType);
261 
262 
269  static int GetNumParamsInstances(int pType, int winnum);
270 
278  static int GetNumParamsInstances(const std::string tag, int winnum){
279  return GetNumParamsInstances(GetTypeFromTag(tag), winnum);
280  }
281 
288  static void AppendParamsInstance(int pType, int winnum, Params* p){
289  _paramsInstances[make_pair(pType,winnum)].push_back(p);
290  if (pType == 3) assert (_paramsInstances[make_pair(pType,winnum)].size() <= 1);
291  }
292 
300  static void AppendParamsInstance(const std::string tag, int winnum, Params* p){
301  AppendParamsInstance(GetTypeFromTag(tag),winnum, p);
302  }
303 
310  static void RemoveParamsInstance(int pType, int winnum, int instance);
311 
318  static vector<Params*>& GetAllParamsInstances(int pType, int winnum){
319  map< pair<int,int>, vector<Params*> >::const_iterator it = _paramsInstances.find(make_pair(pType,winnum));
320  if (it == _paramsInstances.end()) return (*new vector<Params*>);
321  return _paramsInstances[make_pair(pType,winnum)];
322  }
329  static int GetAllParamsInstances(string tag, vector<Params*>&);
330 
335  static int DeleteVisualizer(int viznum);
336 
344  static vector<Params*>& GetAllParamsInstances(const std::string tag, int winnum){
345  return GetAllParamsInstances(GetTypeFromTag(tag),winnum);
346  }
347 
353  static map <int, vector<Params*> >* cloneAllParamsInstances(int winnum);
354 
360  static vector <Params*>* cloneAllDefaultParams();
361 
366  virtual void SetVizNum(int vnum){
367  GetRootNode()->SetElementLong(_VisualizerNumTag,(long)vnum);
368  }
370 
371 
373  Params(const Params& p);
379  virtual ~Params();
380 
385  virtual const std::string getShortName()=0;
386 
387 
388 
405  virtual void Validate(int type)=0;
406 
411  static bool IsRenderingEnabled(int winnum);
412 
417  bool isRenderParams() const;
418 
425  bool isBasicParams() const;
426 
429  virtual void restart() = 0;
430 
433  virtual int GetVizNum() {return (int)(GetValueLong(_VisualizerNumTag));}
434 
441 
449  virtual int SetLocal(bool lg){
450  return SetValueLong(_LocalTag,"set local or global",(long)lg);
451  }
452 
455  virtual bool IsLocal() {
456  return (GetValueLong(_LocalTag) != 0);
457  }
458 
464  virtual Box* GetBox() {return 0;}
465 
466  //Following methods, while public, are not part of extensibility API
467 
468 #ifndef DOXYGEN_SKIP_THIS
469 
470  static Params* CreateDummyParams(std::string tag);
471  static void BailOut (const char *errstr, const char *fname, int lineno);
472 
473  static int getNumDummyClasses(){return _dummyParamsInstances.size();}
474  static Params* getDummyParamsInstance(int i) {return _dummyParamsInstances[i];}
475  static void addDummyParamsInstance(Params*const & p ) {_dummyParamsInstances.push_back(p);}
476 
477  static void clearDummyParamsInstances();
478  static const std::string paramName(ParamsBaseType t);
479 
480  static const string _regionParamsTag;
481  static const string _viewpointParamsTag;
482  static const string _animationParamsTag;
483  static const string _visualizerFeaturesParamsTag;
484  static const string _arrowParamsTag;
485  static const string _isolineParamsTag;
486  static const string _RefinementLevelTag;
487  static const string _CompressionLevelTag;
488  static const string _VisualizerNumTag;
489  static const string _LocalTag;
490  static const string _IsoControlTag;
491  static const string _IsoValueTag;
492  static const string _Variables3DTag;
493  static const string _Variables2DTag;
494 
495 #endif
496 protected:
497 
508  virtual int SetValueLong(string tag, const char* description, long value)
509  {return ParamsBase::SetValueLong(tag,description,value, this);}
510 
521  virtual int SetValueLong(string tag, const char* description, const vector<long>& value)
522  {return ParamsBase::SetValueLong(tag, description, value, this);}
523 
534  virtual int SetValueDouble(string tag, const char* description, double value)
535  {return ParamsBase::SetValueDouble(tag,description,value,this);}
536 
547  virtual int SetValueDouble(string tag, const char* description, const vector<double>& value)
548  {return ParamsBase::SetValueDouble(tag,description,value,this);}
549 
550 
561  virtual int SetValueString(string tag, const char* description, const string& value)
562  {return ParamsBase::SetValueString(tag,description,value,this);}
563 
575  virtual int SetValueStringVec(string tag, const char* description, const vector<string>& value)
576  {return ParamsBase::SetValueStringVec(tag, description, value, this);}
577 
578 #ifndef DOXYGEN_SKIP_THIS
579 
580  //Params instances are vectors of Params*, one per instance, indexed by paramsBaseType, winNum
581  static map<pair<int,int>,vector<Params*> > _paramsInstances;
582  //CurrentRenderParams indexed by paramsBaseType, winNum
583  static map<pair<int,int>, int> _currentParamsInstance;
584  //Dummy params are those that are found in a session file but not
585  //available in the current code.
586  //default params instances indexed by paramsBaseType
587  static map<int, Params*> _defaultParamsInstance;
588  static vector<Params*> _dummyParamsInstances;
589 #endif //DOXYGEN_SKIP_THIS
590 };
598 class PARAMS_API BasicParams : public Params {
599 public:
603  BasicParams(XmlNode *parent, const string &name) : Params(parent, name, -1) {}
604 };
606 
607 
608 #ifndef DOXYGEN_SKIP_THIS
609 //Note that DummyParams are not part of the Public API
610 //These provide a repository for Params state for Params classes that are not
611 //Available at run time.
612 class DummyParams : public Params {
613  public:
614  DummyParams(XmlNode *parent, const std::string tag, int winnum);
615  virtual ~DummyParams(){}
616  virtual void restart(){}
617 
618  virtual void Validate(int) {return;}
619 
620  virtual bool usingVariable(const std::string& ){
621  return false;
622  }
623  const std::string getShortName(){return _tag;}
624 
625  std::string _tag;
626 
627 };
628 
629 
630 #endif //DOXYGEN_SKIP_THIS
631 }; //End namespace VAPoR
632 #endif //PARAMS_H
static void AppendParamsInstance(const std::string tag, int winnum, Params *p)
Definition: params.h:300
virtual void SetVizNum(int vnum)
Definition: params.h:366
3D or 2D box with options for orientation angles and extents changing in time. Intended to be used in...
Definition: Box.h:43
A pure virtual class for managing parameters used in visualization.
Definition: params.h:129
virtual int SetValueDouble(string tag, const char *description, const vector< double > &value)
Definition: params.h:547
virtual int SetValueStringVec(string tag, const char *description, const vector< string > &value)
Definition: params.h:575
static int GetCurrentParamsInstanceIndex(const std::string tag, int winnum)
Definition: params.h:174
static Params * GetParamsInstance(const std::string tag, int winnum=-1, int instance=-1)
Definition: params.h:203
static Params * GetCurrentParamsInstance(int pType, int winnum)
Definition: params.h:212
virtual int SetLocal(bool lg)
Definition: params.h:449
virtual int SetValueString(string tag, const char *description, const string &value)
Definition: params.h:561
virtual bool IsLocal()
Definition: params.h:455
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:90
virtual int SetValueLong(string tag, const char *description, const vector< long > &value)
Definition: params.h:521
static void SetCurrentParamsInstanceIndex(int pType, int winnum, int instance)
Definition: params.h:183
static Params * GetDefaultParams(ParamsBase::ParamsBaseType pType)
Definition: params.h:224
static void SetDefaultParams(const string &tag, Params *p)
Definition: params.h:253
virtual int SetValueDouble(string tag, const char *description, double value)
Definition: params.h:534
virtual int SetValueLong(string tag, const char *description, long value)
Definition: params.h:508
Params(int winNum, const string &name)
Deprecated constructor, needed for built-in classes that do not have associated XML node: ...
Definition: params.h:144
BasicParams(XmlNode *parent, const string &name)
Definition: params.h:603
static vector< Params * > & GetAllParamsInstances(const std::string tag, int winnum)
Definition: params.h:344
virtual Box * GetBox()
Definition: params.h:464
VetsUtil base class.
Definition: MyBase.h:68
static Params * GetDefaultParams(const string &tag)
Definition: params.h:234
#define PARAMS_API
static int GetNumParamsInstances(const std::string tag, int winnum)
Definition: params.h:278
static void SetDefaultParams(int pType, Params *p)
Definition: params.h:243
A Params subclass for Params classes with one unique instance.
Definition: params.h:598
Definition: DC.h:10
static int GetCurrentParamsInstanceIndex(int pType, int winnum)
Definition: params.h:165
static vector< Params * > & GetAllParamsInstances(int pType, int winnum)
Definition: params.h:318
static void AppendParamsInstance(int pType, int winnum, Params *p)
Definition: params.h:288
virtual int GetVizNum()
Definition: params.h:433