VAPOR3 3.9.4
ParamsMgr.h
Go to the documentation of this file.
1//************************************************************************
2// *
3// Copyright (C) 2016 *
4// University Corporation for Atmospheric Research *
5// All Rights Reserved *
6// *
7//************************************************************************/
8//
9// File: ParamsMgr.h
10//
11// Author: Alan Norton
12// National Center for Atmospheric Research
13// PO 3000, Boulder, Colorado
14//
15// Date: February 2016
16//
17// Description: Defines the ParamsMgr class.
18// This provides an API for manipulating the Params Objects that are used in VAPOR applications
19//
20#ifndef PARAMSMGR_H
21#define PARAMSMGR_H
22
23#include "vapor/VAssert.h"
24#include <map>
25#include <deque>
26#include <stack>
27#include <utility>
28#include <functional>
29
30#include <vapor/DataMgr.h>
31#include <vapor/ParamsBase.h>
32#include <vapor/RenderParams.h>
34#include <vapor/regionparams.h>
37
38namespace VAPoR {
39
42
51
53class PARAMS_API ParamsMgr : public MyBase {
54public:
72 //
73 ParamsMgr(std::vector<string> appParamNames = std::vector<string>(), std::vector<string> appRenderParamNames = std::vector<string>());
74
77 virtual ~ParamsMgr();
78
82 //
83 virtual void LoadState();
84
90 //
91 virtual void LoadState(const XmlNode *node);
92
98 //
99 virtual int LoadState(string stateFile);
100
108 void AddDataMgr(string dataSetName, DataMgr *dataMgr);
109
113 //
114 void RemoveVisualizer(string winName);
115
121 void RemoveDataMgr(string dataSetName);
122
126 //
127 vector<string> GetDataMgrNames() const;
128
141 //
143
147 //
148 void RemoveVisualizerParamsInstance(string winName);
149
173 //
174 RenderParams *CreateRenderParamsInstance(string winName, string dataSetName, string classType, string instName);
175
190 //
191 RenderParams *CreateRenderParamsInstance(string winName, string dataSetName, string instName, const RenderParams *rp);
192
208 //
209 void RemoveRenderParamsInstance(string winName, string dataSetName, string classType, string instName);
210
230 //
231 RenderParams *GetRenderParams(string winName, string dataSetName, string classType, string instName) const;
232
233 void GetRenderParams(string winName, string dataSetName, vector<RenderParams *> &rParams) const;
234
235 void GetRenderParams(string winName, vector<RenderParams *> &rParams) const;
236
237 void GetRenderParams(vector<RenderParams *> &rParams) const;
238
247 void GetRenderParamNames(string winName, string dataSetName, string classType, vector<string> &instNames) const;
248
249 void GetRenderParamNames(string winName, string dataSetName, vector<string> &instNames) const;
250
251 void GetRenderParamNames(string winName, vector<string> &instNames) const;
252
253 void GetRenderParamNames(vector<string> &instNames) const;
254
265 //
266 bool RenderParamsLookup(string instName, string &winName, string &dataSetName, string &className) const;
267
276 //
277 vector<string> GetVisualizerNames() const;
278
286 //
287 vector<string> GetRenderParamsClassNames(string winName) const;
288
296 //
297 vector<string> GetRenderParamsClassNames(string winName, string dataSetName) const;
298
306 //
307 static vector<string> GetRenderParamsClassNamesAvail() { return (RenParamsFactory::Instance()->GetFactoryNames()); }
308
318 //
319 vector<string> GetRenderParamInstances(string winName, string dataSetName, string classType) const;
320
321 vector<string> GetRenderParamInstances(string winName, string classType) const;
322
330 //
331 ViewpointParams *GetViewpointParams(string winName) const;
332
340 //
341 RegionParams *GetRegionParams(string winName) const { return ((RegionParams *)_otherParams->GetParams(RegionParams::GetClassType())); };
342
350 //
351 AnnotationParams *GetAnnotationParams(string winName) const { return ((AnnotationParams *)_otherParams->GetParams(AnnotationParams::GetClassType())); };
352
357 //
358 DatasetsParams *GetDatasetsParams() const { return ((DatasetsParams *)_otherParams->GetParams(DatasetsParams::GetClassType())); };
359
370 //
371 ParamsBase *GetParams(string classType) { return (_otherParams->GetParams(classType)); }
372
388 //
389 RenderParams *GetAppRenderParams(string dataSetName, string classType)
390 {
391 std::map<string, RenParamsContainer *>::const_iterator itr;
392 itr = _otherRenParams.find(dataSetName);
393 return (itr != _otherRenParams.cend() ? itr->second->GetParams(classType) : NULL);
394 }
395
406 //
407 void GetAppRenderParams(string dataSetName, vector<RenderParams *> &appRenderParams) const;
408
414 //
415 int SaveToFile(string path) const;
416
417 // const DataMgr *GetDataMgr() const {return (_dataMgr);}
418
434 void BeginSaveStateGroup(string description) { _ssave.BeginGroup(description); }
435
438 //
439 void EndSaveStateGroup() { _ssave.EndGroup(); };
440
443 void IntermediateChange() { _ssave.IntermediateChange(); }
444
445 void SetSaveStateEnabled(bool enabled) { _ssave.SetEnabled(enabled); }
446
447 bool GetSaveStateEnabled() const { return (_ssave.GetEnabled()); }
448
453 void SetSaveStateUndoEnabled(bool enabled) { _ssave.SetUndoEnabled(enabled); }
454
456 bool GetSaveStateUndoEnabled() const { return (_ssave.GetUndoEnabled()); }
457
462 //
463 bool Undo();
464
469 //
470 bool Redo();
471
473
475 //
476 string GetTopUndoDesc() const;
477
479 //
480 string GetTopRedoDesc() const;
481
484 size_t UndoSize() const { return (_ssave.UndoSize()); }
485
486 size_t RedoSize() const { return (_ssave.RedoSize()); }
487
496 //
497 void RegisterStateChangeFlag(bool *flag) { _ssave.RegisterStateChangeFlag(flag); }
498
504 //
505 void RegisterStateChangeCB(std::function<void()> callback) { _ssave.RegisterStateChangeCB(callback); }
506
509 void RegisterIntermediateStateChangeCB(std::function<void()> callback) { _ssave.RegisterIntermediateStateChangeCB(callback); }
510
514 void RebaseStateSave() { _ssave.Rebase(); }
515
516 const XmlNode *GetXMLRoot() const { return (_rootSeparator->GetNode()); }
517
524 //
526 {
527 if (*(_rootSeparator->GetNode()) == _prevState) return (false);
528
529 _prevState = *(_rootSeparator->GetNode());
530 return (true);
531 }
532
533private:
534 class PMgrStateSave : public ParamsBase::StateSave {
535 public:
536 PMgrStateSave(int stackSize = 100);
537 ~PMgrStateSave();
538
539 void Reinit(const XmlNode *rootNode)
540 {
541 _rootNode = rootNode;
542 emitStateChange();
543 }
544
545 void Rebase()
546 {
547 if (_state0) delete _state0;
548 _state0 = _rootNode ? new XmlNode(*_rootNode) : NULL;
549 }
550 void Save(const XmlNode *node, string description);
551 void BeginGroup(string descripion);
552 void EndGroup();
553 void IntermediateChange();
554
555 void SetEnabled(bool onOff)
556 {
557 if (!_groups.empty()) return; // Can't change inside group
558 _enabled = onOff;
559 }
560
561 bool GetEnabled() const { return (_enabled); }
562
563 void SetUndoEnabled(bool b)
564 {
565 if (!_groups.empty()) return; // Can't change inside group
566 _addToUndoEnabled = b;
567 }
568 bool GetUndoEnabled() const { return _addToUndoEnabled; }
569
570 const XmlNode *GetTopUndo(string &description) const;
571 const XmlNode *GetTopRedo(string &description) const;
572 const XmlNode *GetBase() const { return (_state0); }
573
574 bool Undo();
575 bool Redo();
576 void Clear();
577
578 size_t UndoSize() const { return (_undoStack.size()); }
579
580 size_t RedoSize() const { return (_redoStack.size()); }
581
582 void RegisterStateChangeFlag(bool *flag) { _stateChangeFlags.push_back(flag); }
583 void RegisterStateChangeCB(std::function<void()> callback) { _stateChangeCBs.push_back(callback); }
584 void RegisterIntermediateStateChangeCB(std::function<void()> callback) { _intermediateStateChangeCBs.push_back(callback); }
585
586 private:
587 bool _enabled;
588 bool _addToUndoEnabled = true;
589 int _stackSize;
590 const XmlNode *_rootNode;
591 const XmlNode *_state0;
592
593 std::stack<string> _groups;
594 std::deque<std::pair<string, XmlNode *>> _undoStack;
595 std::deque<std::pair<string, XmlNode *>> _redoStack;
596
597 std::vector<bool *> _stateChangeFlags;
598 std::vector<std::function<void()>> _stateChangeCBs;
599 std::vector<std::function<void()>> _intermediateStateChangeCBs;
600
601 void cleanStack(int maxN, std::deque<std::pair<string, XmlNode *>> &s);
602 void emitStateChange();
603 void emitIntermediateStateChange();
604 };
605
606 map<string, DataMgr *> _dataMgrMap;
607 ParamsSeparator * _rootSeparator;
608 XmlNode _prevState;
609 std::vector<string> _appParamNames;
610 std::vector<string> _appRenderParamNames;
611
612 // Map of RenParamsContainers referenced by Window Name, then by
613 // data set name, and finally Renderer Name.
614 //
615 map<string, map<string, map<string, RenParamsContainer *>>> _renderParamsMap;
616
617 // Map of ViewpointParams referenced by Window Name
618 //
619 map<string, ViewpointParams *> _viewpointParamsMap;
620
621 ParamsContainer * _otherParams;
622 std::map<string, RenParamsContainer *> _otherRenParams;
623
624 PMgrStateSave _ssave;
625
626 static const string _rootTag;
627 static const string _globalTag;
628 static const string _renderersTag;
629 static const string _appRenderersTag;
630 static const string _windowsTag;
631
632 void _init(std::vector<string> appParamNames, XmlNode *node);
633 void _createAppRenParams(string dataSetName);
634 void _destroy();
635
636 const map<string, map<string, RenParamsContainer *>> *getWinMap3(const map<string, map<string, map<string, RenParamsContainer *>>> &m3, string key) const;
637
638 const map<string, RenParamsContainer *> *getWinMap3(const map<string, map<string, map<string, RenParamsContainer *>>> &m3, string key1, string key2) const;
639
640 const map<string, RenParamsContainer *> *getWinMap2(const map<string, map<string, RenParamsContainer *>> &m2, string key) const;
641
642 RenParamsContainer *get_ren_container(string winName, string dataSetName, string renderName) const;
643
644 map<string, map<string, RenParamsContainer *>> *getWinMap3(map<string, map<string, map<string, RenParamsContainer *>>> &m3, string key) const;
645
646 map<string, RenParamsContainer *> *getWinMap3(map<string, map<string, map<string, RenParamsContainer *>>> &m3, string key1, string key2) const;
647
648 map<string, RenParamsContainer *> *getWinMap2(map<string, map<string, RenParamsContainer *>> &m2, string key) const;
649
650 void delete_ren_container(string winName, string dataSetName, string renderName);
651
652 void delete_ren_containers(string winName, string dataSetName);
653 void delete_ren_containers(string winName);
654 void delete_ren_containers();
655 void delete_datasets(string dataSetName);
656
657 RenParamsContainer *make_ren_container(string winName, string dataSetName, string renderName);
658
659 ViewpointParams *get_vp_params(string winName) const;
660
661 void delete_vp_params(string winName);
662
663 ViewpointParams *make_vp_params(string winName);
664
665 void addDataMgrNew();
666 void addDataMgrMerge(string dataSetName);
667
668 bool undoRedoHelper();
669
670 RenParamsContainer *createRenderParamsHelper(string winName, string dataSetName, string className, string instName);
671};
672
673}; // End namespace VAPoR
674#endif // PARAMSMGR_H
A class for describing visual features displayed in the visualizer.
A cache based data reader.
Definition: DataMgr.h:110
State capture class.
Definition: ParamsBase.h:62
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:50
A singleton class for managing Params instances.
Definition: ParamsMgr.h:53
void RemoveVisualizerParamsInstance(string winName)
void GetRenderParamNames(string winName, string dataSetName, vector< string > &instNames) const
virtual int LoadState(string stateFile)
void RemoveDataMgr(string dataSetName)
void SetSaveStateUndoEnabled(bool enabled)
Definition: ParamsMgr.h:453
DatasetsParams * GetDatasetsParams() const
Definition: ParamsMgr.h:358
void GetRenderParams(string winName, string dataSetName, vector< RenderParams * > &rParams) const
RegionParams * GetRegionParams(string winName) const
Definition: ParamsMgr.h:341
const XmlNode * GetXMLRoot() const
Definition: ParamsMgr.h:516
vector< string > GetVisualizerNames() const
void RebaseStateSave()
Definition: ParamsMgr.h:514
size_t RedoSize() const
Definition: ParamsMgr.h:486
void EndSaveStateGroup()
Definition: ParamsMgr.h:439
bool RenderParamsLookup(string instName, string &winName, string &dataSetName, string &className) const
void RegisterStateChangeFlag(bool *flag)
Definition: ParamsMgr.h:497
bool GetSaveStateUndoEnabled() const
Get whether updating the undo list is enabled.
Definition: ParamsMgr.h:456
void BeginSaveStateGroup(string description)
Definition: ParamsMgr.h:434
void AddDataMgr(string dataSetName, DataMgr *dataMgr)
void GetRenderParamNames(vector< string > &instNames) const
void GetRenderParamNames(string winName, string dataSetName, string classType, vector< string > &instNames) const
void GetRenderParams(string winName, vector< RenderParams * > &rParams) const
size_t UndoSize() const
Definition: ParamsMgr.h:484
ViewpointParams * GetViewpointParams(string winName) const
RenderParams * GetAppRenderParams(string dataSetName, string classType)
Definition: ParamsMgr.h:389
string GetTopUndoDesc() const
Return description string for event at top of undo stack.
bool GetSaveStateEnabled() const
Definition: ParamsMgr.h:447
static vector< string > GetRenderParamsClassNamesAvail()
Definition: ParamsMgr.h:307
void SetSaveStateEnabled(bool enabled)
Definition: ParamsMgr.h:445
virtual ~ParamsMgr()
vector< string > GetRenderParamsClassNames(string winName) const
vector< string > GetDataMgrNames() const
void IntermediateChange()
Definition: ParamsMgr.h:443
RenderParams * GetRenderParams(string winName, string dataSetName, string classType, string instName) const
AnnotationParams * GetAnnotationParams(string winName) const
Definition: ParamsMgr.h:351
void RegisterIntermediateStateChangeCB(std::function< void()> callback)
Definition: ParamsMgr.h:509
void GetRenderParamNames(string winName, vector< string > &instNames) const
void RemoveRenderParamsInstance(string winName, string dataSetName, string classType, string instName)
void GetAppRenderParams(string dataSetName, vector< RenderParams * > &appRenderParams) const
void GetRenderParams(vector< RenderParams * > &rParams) const
string GetTopRedoDesc() const
Return description string for event at top of redo stack.
ViewpointParams * CreateVisualizerParamsInstance(string winName)
ParamsMgr(std::vector< string > appParamNames=std::vector< string >(), std::vector< string > appRenderParamNames=std::vector< string >())
vector< string > GetRenderParamInstances(string winName, string dataSetName, string classType) const
RenderParams * CreateRenderParamsInstance(string winName, string dataSetName, string instName, const RenderParams *rp)
virtual void LoadState(const XmlNode *node)
void RemoveVisualizer(string winName)
void RegisterStateChangeCB(std::function< void()> callback)
Definition: ParamsMgr.h:505
bool StateChanged()
Definition: ParamsMgr.h:525
vector< string > GetRenderParamInstances(string winName, string classType) const
RenderParams * CreateRenderParamsInstance(string winName, string dataSetName, string classType, string instName)
ParamsBase * GetParams(string classType)
Definition: ParamsMgr.h:371
int SaveToFile(string path) const
virtual void LoadState()
vector< string > GetRenderParamsClassNames(string winName, string dataSetName) const
A class for describing a 3D axis-aligned region in user space.
Definition: regionparams.h:44
A Params subclass for managing parameters used by Renderers.
Definition: RenderParams.h:43
A class for describing the viewpoint and lights in a 3D VAPOR scene.
An Xml tree.
Definition: XmlNode.h:49
Wasp base class.
Definition: MyBase.h:67
#define PARAMS_API
Definition: common.h:77