VAPoR  0.1
eventrouter.h
Go to the documentation of this file.
1 //************************************************************************
2 // *
3 // Copyright (C) 2006 *
4 // University Corporation for Atmospheric Research *
5 // All Rights Reserved *
6 // *
7 //************************************************************************/
8 //
9 // File: eventrouter.h
10 //
11 // Author: Alan Norton
12 // National Center for Atmospheric Research
13 // PO 3000, Boulder, Colorado
14 //
15 // Date: May 2006
16 //
17 // Description: Definition of EventRouter class
18 // This (pure virtual) class manages communication between
19 // gui elements, visualizers, and params.
20 
21 #ifndef EVENTROUTER_H
22 #define EVENTROUTER_H
23 #include "assert.h"
24 #include "params.h"
25 #include "vizwinmgr.h"
26 #include "vizwin.h"
27 #include "histo.h"
28 #include "mapperfunction.h"
29 #include "panelcommand.h"
30 #include <qobject.h>
31 
32 class QWidget;
33 class QComboBox;
34 class QButtonGroup;
35 class QGroupBox;
36 class QHBoxLayout;
37 #ifdef WIN32
38 //Annoying unreferenced formal parameter warning
39 #pragma warning( disable : 4100)
40 #endif
41 
42 namespace VAPoR{
43  class PanelCommand;
44  class Histo;
45 
54 //
56 {
57 
58 public:
59 
62  virtual void hookUpTab() = 0;
63 
66  virtual void updateTab() = 0;
67 
74  virtual void updateUrgentTabState() {return;}
75 
83  virtual void makeCurrent(Params* prevParams, Params* newParams, bool newWin, int instance = -1, bool reEnable = false) = 0;
84 
89  virtual void performGuiChangeInstance(int newCurrent, bool undoredo=true);
90 
93  virtual void performGuiNewInstance();
94 
97  virtual void performGuiDeleteInstance();
98 
101  virtual void performGuiCopyInstance();
102 
106  virtual void performGuiCopyInstanceToViz(int vizwin);
107 
112  void guiSetTextChanged(bool on) {textChangedFlag = on;}
113 
118  virtual void confirmText(bool /*render*/) = 0;
119 
125  virtual void reinitTab(bool doOverride) = 0;
126 
131  virtual void guiSetEnabled(bool On, int instance, bool undoredo=false ) {assert(0);}
132 
135  virtual void captureMouseUp() {assert(0);}
136 
139  virtual void captureMouseDown(int mouseNum) {assert(0);}
140 
141 #ifndef DOXYGEN_SKIP_THIS
142  EventRouter() {
143  textChangedFlag = 0; savedCommand = 0;
144  fidelityDefaultChanged = true;
145  histogramList = 0;
146  numHistograms = 0;
147  isoShown = colorMapShown = opacityMapShown = texShown = false;
148  }
149  virtual ~EventRouter() {
150  for (int i = 0; i<numHistograms; i++)
151  if (histogramList[i]) delete histogramList[i];
152  if (histogramList) delete [] histogramList;
153  }
154  //Methods to change instances (for undo/redo).
155  //Only used by renderer params
156  //Insert an instance (where there was none).
157  //if instPosition is at end, appends to current instances
158  //void insertCurrentInstance(Params* newParams, int instPosition);
159  //Remove specified instance, disable it if necessary.
160  void removeRendererInstance(int winnum, int instance);
161  void newRendererInstance(int winnum);
162  void copyRendererInstance(int toWinnum, RenderParams* rParams);
163  void changeRendererInstance(int winnum, int newInstance);
164 
165  Params::ParamsBaseType getParamsBaseType() {return myParamsBaseType;}
166 
167  //Make the tab refresh after a scrolling operation.
168  //Helpful on windows only, and only some tabs
169  virtual void refreshTab() {}
170 
171  //UpdateRenderer ignores renderParams argument and uses the
172  //params associated with the instance if it is nonnegative
173  virtual void updateRenderer(RenderParams* , bool /*wasEnabled*/, bool /*newWindow*/){assert(0);}
174 
175  //make sure the params cleanly detaches from gui, to
176  //handle possible connections from editors, frames, etc.
177  virtual void cleanParams(Params*) {}
178 
179  virtual void sessionLoadTF(QString* ) {assert(0);}
180  //Clone the params and any other related classes.
181  //Default just clones the params:
182  virtual Params* deepCopy(Params* p) {return (p->deepCopy());}
183 
184  virtual void guiSetLocal(Params* p, bool lg){
185  if (textChangedFlag) confirmText(false);
186 
187  PanelCommand* cmd;
188  Params* localParams = VizWinMgr::getInstance()->getCorrespondingLocalParams(p);
189  if (lg){
190  cmd = PanelCommand::captureStart(localParams, "set Global to Local");
191  }
192  else cmd = PanelCommand::captureStart(localParams, "set Local to Global");
193  localParams->setLocal(lg);
194  int winnum = localParams->getVizNum();
195  GLWindow* glwin = VizWinMgr::getInstance()->getVizWin(winnum)->getGLWindow();
196  glwin->setActiveParams(Params::GetCurrentParamsInstance(localParams->GetParamsBaseTypeId(),winnum),localParams->GetParamsBaseTypeId());
197  PanelCommand::captureEnd(cmd, localParams);
198  updateTab();
199  }
200 
201  virtual void setFidelityDefaultChangedFlag(bool val){fidelityDefaultChanged = val;}
202  //Methods to support maintaining a list of histograms
203  //in each router (at least those with a TFE)
204 
205  virtual Histo* getHistogram(RenderParams*, bool mustGet, bool isIsoWin = false);
206  virtual void refreshHistogram(RenderParams* , int sesVarNum, const float drange[2]);
207  virtual void refresh2DHistogram(RenderParams* , int sesVarNum, const float drange[2]);
208 
209  //For render params, setEditorDirty uses the current instance if Params
210  //arg is null
211  virtual void setEditorDirty(RenderParams*){}
212  virtual void updateMapBounds(RenderParams*) {assert (0);}
213  virtual void updateClut(RenderParams*){assert(0);}
214 
215 //Methods for loading/saving transfer functions:
216 void saveTF(RenderParams* rParams);
217 void fileSaveTF(RenderParams* rParams);
218 void loadInstalledTF(RenderParams* rParams, int varnum);
219 void loadTF(RenderParams* rParams, int varnum);
220 
221 void fileLoadTF(RenderParams* rParams, int varnum, const char* startPath, bool savePath);
222  //Workaround Darwin/Qt bug. Note these are public:
223  bool isoShown, colorMapShown, opacityMapShown, texShown;
224 
225 public slots:
226 
227  virtual void guiStartChangeMapFcn(QString) { assert(0); }
228  virtual void guiEndChangeMapFcn() { assert(0); }
229 
230 
231 protected:
232  bool textChangedFlag;
233  QButtonGroup* fidelityButtons;
234  //for subclasses with a box:
235  void setIgnoreBoxSliderEvents(bool val) {ignoreBoxSliderEvents = val;}
236  //Use fidelity setting and preferences to calculate LOD and Refinement
237  //To support Fidelity, each eventRouter class must perform the following:
238  //Implement fidelityBox and fidelityLayout as in dvr.ui
239  // set fidelityButtons = 0 in constructor
240  // implement slots guiSetFidelity(int) and guiSetFidelityDefault()
241  // connect fidelityDefaultButton clicked() to guiSetFidelityDefault
242  // in updateTab, check for fidelityUpdateChanged, if so, call setupFidelity
243  // then connect fidelityButtons to guiSetFidelity, then call updateFidelity()
244  // in reinitTab, call SetFidelityLevel, then connect fidelityButtons to guiSetFidelity
245  // in guiSetCompRatios, call SetIgnoreFidelity(true)
246  // in guiSetRefinement, call SetIgnoreFidelity(true)
247  // in guiSetFidelityDefault, call setFidelityDefault
248 
249  //Build the vectors of reflevels and lods
250  virtual int orderLODRefs(int dim);
251  //Determine the default lod and ref level for a specified region size
252  virtual void calcLODRefDefault(int dim, float regMBs, int* lod, int* reflevel);
253  virtual void updateFidelity(QGroupBox*, RenderParams* rp, QComboBox* lodCombo, QComboBox* refinementCombo);
254 
255  void setupFidelity(int dim, QHBoxLayout* fidelityLayout,
256  QGroupBox* fidelityBox, RenderParams* dParams, bool useDefault=false);
257  void setFidelityDefault(int dim, RenderParams* dParams);
258  bool ignoreBoxSliderEvents;
259  //for subclasses with a datarange:
260  virtual void setDatarangeDirty(RenderParams* ) {assert(0);}
261  //Routers with histograms keep an array, one for each variable,
262  // or variable combination
263  Histo** histogramList;
264  int numHistograms; //how large is histo array..
265  //There is one tabbed panel for each class of Params
266 
267  Params::ParamsBaseType myParamsBaseType;
268 
269  PanelCommand* savedCommand;
270 
271  vector<QAction*>* makeWebHelpActions(const char* text[], const char* urls[]);
272  virtual QAction* getWebHelpAction(int n) {return (*myWebHelpActions)[n];}
273  vector<QAction*>* myWebHelpActions;
274 
275  vector<int> fidelityRefinements;
276  vector<int> fidelityLODs;
277  bool fidelityDefaultChanged;
278 
279 #endif //DOXYGEN_SKIP_THIS
280 };
281 };
282 #endif // EVENTROUTER_H
283 
A pure virtual class for managing parameters used in visualization.
Definition: params.h:75
static Params * GetCurrentParamsInstance(int pType, int winnum)
Definition: params.h:157
virtual void hookUpTab()=0
virtual void performGuiNewInstance()
ParamsBaseType GetParamsBaseTypeId()
Definition: ParamsBase.h:164
virtual void confirmText(bool)=0
A pure virtual class specifying the common properties of all the parameter tabs in the VAPOR GUI...
Definition: eventrouter.h:55
void guiSetTextChanged(bool on)
Definition: eventrouter.h:112
virtual void makeCurrent(Params *prevParams, Params *newParams, bool newWin, int instance=-1, bool reEnable=false)=0
virtual void guiSetEnabled(bool On, int instance, bool undoredo=false)
Definition: eventrouter.h:131
virtual void updateUrgentTabState()
Definition: eventrouter.h:74
virtual void captureMouseUp()
Definition: eventrouter.h:135
virtual void performGuiCopyInstanceToViz(int vizwin)
virtual void performGuiCopyInstance()
virtual void reinitTab(bool doOverride)=0
virtual void performGuiDeleteInstance()
virtual void performGuiChangeInstance(int newCurrent, bool undoredo=true)
virtual void updateTab()=0
virtual void captureMouseDown(int mouseNum)
Definition: eventrouter.h:139