VAPoR  0.1
vizwinmgr.h
Go to the documentation of this file.
1 //************************************************************************
2 // *tab
3 // Copyright (C) 2004 *
4 // University Corporation for Atmospheric Research *
5 // All Rights Reserved *
6 // *
7 //************************************************************************/
8 //
9 // File: vizwinmgr.h
10 //
11 // Author: Alan Norton
12 // National Center for Atmospheric Research
13 // PO 3000, Boulder, Colorado
14 //
15 // Date: Sept 2004
16 //
17 
18 
19 #ifndef VIZWINMGR_H
20 #define VIZWINMGR_H
21 
22 class QMdiArea;
23 class QMdiSubWindow;
24 class QWidget;
25 class QDesktopWidget;
26 class QMainWidget;
27 class QTimer;
28 
29 #include <qobject.h>
30 #include "twoDdataparams.h"
31 #include "twoDimageparams.h"
32 #include "viewpointparams.h"
33 #include "regionparams.h"
34 #include "probeparams.h"
35 #include "flowparams.h"
36 #include "isolineparams.h"
37 
38 #include "dvrparams.h"
39 #include "animationparams.h"
40 #include <vapor/common.h>
41 #include "params.h"
42 #include "command.h"
43 
44 
45 namespace VAPoR{
46 class AnimationController;
47 class AnimationParams;
48 
49 class EventRouter;
50 class TabManager;
51 class MainForm;
52 class ViewpointParams;
53 class RegionParams;
54 class DvrParams;
55 class ProbeParams;
56 class TwoDDataParams;
57 class TwoDImageParams;
58 class Trackball;
59 class VizWin;
60 class AnimationEventRouter;
61 class RegionEventRouter;
62 class DvrEventRouter;
63 class ProbeEventRouter;
64 class TwoDDataEventRouter;
65 class TwoDImageEventRouter;
66 class ViewpointEventRouter;
67 class FlowEventRouter;
68 class IsoEventRouter;
69 
71 
80 //
81 class VizWinMgr : public QObject, public ParsedXml
82 {
83  Q_OBJECT
84 
85  enum
86  {
87  PREAMBLE,
88  RENDER,
89  TEMPORAL,
90  TFEDIT,
91  DONE
92  };
93 
94 public:
95 
100  static Params* getActiveParams(const std::string& tag){
101  return (Params::GetParamsInstance(tag, getInstance()->activeViz));
102  }
103 
108  void forceRender(RenderParams* rp, bool always=false);
109 
111  bool reloadShaders();
117 
122  static void InstallTab(const std::string tag, EventRouterCreateFcn fcn);
123 
127  static EventRouter* getEventRouter(const std::string& tag){
129  }
130 
137 
145  void setParams(int winNum, Params* p, ParamsBase::ParamsBaseType typeId, int instance = -1);
146 
152  Params* getParams(int winNum, Params::ParamsBaseType pType, int instance = -1);
153 
158  static int getNumInstances(int winnum, Params::ParamsBaseType pType);
159 
164  static int getCurrentInstanceIndex(int winnum, Params::ParamsBaseType t);
165 
173  static int findInstanceIndex(int winnum, Params* params, Params::ParamsBaseType t);
174 
179  return getCurrentInstanceIndex(activeViz,t);
180  }
181 
186 
190  Params* getApplicableParams(const std::string& tag){
192  }
193 
203  void setVizDirty(Params* p, DirtyBitType bittype, bool bit = true, bool refresh = true);
204 
210  static int RegisterMouseMode(const std::string paramsTag, int manipType, const char* name, const char* const xpmIcon[]=0);
211 
212 #ifndef DOXYGEN_SKIP_THIS
213  //Following methods are not usually needed for extensibility:
214  ~VizWinMgr();
215  static VizWinMgr* getInstance() {
216  if (!theVizWinMgr)
217  theVizWinMgr = new VizWinMgr();
218  return theVizWinMgr;
219  }
220  static DvrParams* getActiveDvrParams(){
221  return((DvrParams*)Params::GetParamsInstance(Params::_dvrParamsTag,getInstance()->activeViz,-1));
222  }
223  static IsolineParams* getActiveIsolineParams(){
224  return ((IsolineParams*)Params::GetParamsInstance(IsolineParams::_isolineParamsTag,getInstance()->activeViz,-1));}
225  static ProbeParams* getActiveProbeParams(){
226  return ((ProbeParams*)Params::GetParamsInstance(Params::_probeParamsTag,getInstance()->activeViz,-1));}
227  static TwoDDataParams* getActiveTwoDDataParams(){
228  return ((TwoDDataParams*)Params::GetParamsInstance(Params::_twoDDataParamsTag,getInstance()->activeViz,-1));}
229  static TwoDImageParams* getActiveTwoDImageParams(){
230  return ((TwoDImageParams*)Params::GetParamsInstance(Params::_twoDImageParamsTag,getInstance()->activeViz,-1));}
231  static RegionParams* getActiveRegionParams(){
232  return (getInstance()->getRegionParams(getInstance()->activeViz));
233  }
234  static FlowParams* getActiveFlowParams(){
235  return ((FlowParams*)Params::GetParamsInstance(Params::_flowParamsTag,getInstance()->activeViz,-1));}
236  static ViewpointParams* getActiveVPParams(){
237  return (getInstance()->getViewpointParams(getInstance()->activeViz));
238  }
239  static AnimationParams* getActiveAnimationParams(){
240  return (getInstance()->getAnimationParams(getInstance()->activeViz));
241  }
242  void forceFidelityUpdate();
243  void createAllDefaultParams();
244  void RegisterMouseModes();
245 
246  //Respond to end:
247  void closeEvent();
248  void vizAboutToDisappear(int i);
249 
250  //Public Inlines:
251  //Respond to user events,
252  //Make sure this state tracks actual window state.
253  void minimize(int i) {
254  isMin[i] = true;
255  isMax[i] = false;
256  }
257  void maximize(int i) {
258  isMin[i] = false;
259  isMax[i] = true;
260 
261  }
262  void normalize(int i) {
263  isMin[i] = false;
264  isMax[i] = false;
265  }
266  //method to launch a viz window, returns vizNum
267  //Default values create a new vis use whatever available number.
268  //If usenum is >= 0 it relaunches a previously used visualizer.
269  //If usenum is < 0 and newNum is >=0, it creates a new visualizer
270  //at position "newNum"
271  int launchVisualizer(int usenum = -1, const char* name = "", int newNum = -1);
272 
273  void nameChanged(QString& name, int num);
274 
275  int getNumVisualizers();
276  TabManager* getTabManager() { return tabManager;}
277 
278  //activeViz is -1 if none is active, otherwise is no. of active viz win.
279  int getActiveViz() {return activeViz;}
280  VizWin* getActiveVisualizer() {
281  if(activeViz>=0)return vizWin[activeViz];
282  else return 0;
283  }
284  //Method that is called when a window is made active:
285  void setActiveViz(int vizNum);
286  //Obtain the parameters that currently apply in specified window:
287  ViewpointParams* getViewpointParams(int winNum);
288  RegionParams* getRegionParams(int winNum);
289  //For a renderer, there will only exist a local version.
290  // If instance is negative, return the current instance.
291 
292  Params* getIsoParams(int winnum, int instance = -1){
293  return Params::GetParamsInstance(Params::GetTypeFromTag(Params::_isoParamsTag),winnum, instance);
294  }
295  Params* getDvrParams(int winnum, int instance = -1){
296  return Params::GetParamsInstance(Params::GetTypeFromTag(Params::_dvrParamsTag),winnum, instance);
297  }
298  ProbeParams* getProbeParams(int winNum, int instance = -1);
299  IsolineParams* getIsolineParams(int winNum, int instance = -1);
300  TwoDDataParams* getTwoDDataParams(int winNum, int instance = -1);
301  TwoDImageParams* getTwoDImageParams(int winNum, int instance = -1);
302 
303  int getNumFlowInstances(int winnum){return Params::GetNumParamsInstances(Params::_flowParamsTag,winnum);}
304  int getNumProbeInstances(int winnum){return Params::GetNumParamsInstances(Params::_probeParamsTag,winnum);}
305  int getNumTwoDDataInstances(int winnum){return Params::GetNumParamsInstances(Params::_twoDDataParamsTag,winnum);}
306  int getNumTwoDImageInstances(int winnum){return Params::GetNumParamsInstances(Params::_twoDImageParamsTag,winnum);}
307  int getNumDvrInstances(int winnum){
308  return Params::GetNumParamsInstances(Params::_dvrParamsTag, winnum);
309  }
310  int getNumIsoInstances(int winnum){
311  return Params::GetNumParamsInstances(Params::_isoParamsTag, winnum);
312  }
313 
314  void setCurrentInstanceIndex(int winnum, int inst, Params::ParamsBaseType t);
315 
316  void appendInstance(int winnum, Params* p);
317 
318  void insertInstance(int winnum, int posn, Params* p);
319 
320 
321  void removeInstance(int winnum, int instance, Params::ParamsBaseType t);
322  FlowParams* getFlowParams(int winNum, int instance = -1);
323  AnimationParams* getAnimationParams(int winNum);
324 
325  RegionEventRouter* getRegionRouter();
326  AnimationEventRouter* getAnimationRouter();
327  ProbeEventRouter* getProbeRouter();
328  TwoDDataEventRouter* getTwoDDataRouter();
329  TwoDImageEventRouter* getTwoDImageRouter();
330  ViewpointEventRouter* getViewpointRouter();
331  FlowEventRouter* getFlowRouter();
332 
333 
334  //Make all the params for the current window update their tabs:
335  void updateActiveParams();
336 
337  //set/get Data describing window states
338  VizWin* getVizWin(int i) {return vizWin[i];}
339 
340 
341  void setVizWinName(int winNum, QString& qs);
342  QString& getVizWinName(int winNum) {return vizName[winNum];}
343  bool isMinimized(int winNum) {return isMin[winNum];}
344  bool isMaximized(int winNum) {return isMax[winNum];}
345 
346 
347  void setViewpointParams(int winNum, ViewpointParams* p){setParams(winNum, (Params*)p, Params::GetTypeFromTag(Params::_viewpointParamsTag));}
348  void setRegionParams(int winNum, RegionParams* p){setParams(winNum, (Params*)p, Params::GetTypeFromTag(Params::_regionParamsTag));}
349  void setAnimationParams(int winNum, AnimationParams* p){setParams(winNum, (Params*)p, Params::GetTypeFromTag(Params::_animationParamsTag));}
350  void replaceGlobalParams(Params* p, ParamsBase::ParamsBaseType t);
351  void createDefaultParams(int winnum);
352  Params* getCorrespondingLocalParams(Params* p) {
353  return getLocalParams(p->GetParamsBaseTypeId());
354  }
355 
356  void setSelectionMode( int mode);
357  //Direct access to actual params object:
358  ViewpointParams* getRealVPParams(int win) {
359  if (!vizWin[win]) return 0;
360  Params* p = Params::GetParamsInstance(Params::_viewpointParamsTag,win,-1);
361  if (p->isLocal()) return (ViewpointParams*)p;
362  return (ViewpointParams*)Params::GetDefaultParams(Params::_viewpointParamsTag);
363  }
364  Trackball* getGlobalTrackball() {return globalTrackball;}
365 
366  //Force all renderers to re-obtain render data
367  void refreshRenderData();
368  //
369  //Disable all renderers that use specified variables
370  void disableRenderers(const vector<string>& vars2D, const vector<string>& vars3D);
371  //Disable all renderers
372  void disableAllRenderers();
373  //Following methods notify all params that are associated with a
374  //specific window.
375  //Set the dirty bits in all the visualizers that use a
376  //region parameter setting
377  //
378 
379  void setRegionDirty(RegionParams* p){setVizDirty(p, RegionBit, true);}
380 
381  //AnimationParams, force a render. Probe & Volume renderer need to rebuild
382  //
383  void setAnimationDirty(AnimationParams* ap){setVizDirty(ap, AnimationBit, true);}
384  //Force rerender of window using a flowParams, or region params..
385  //
386  void refreshFlow(FlowParams*);
387  void refreshViewpoint(ViewpointParams* vParams);
388  void refreshRegion(RegionParams* rParams);
389  void refreshProbe(ProbeParams* pParams);
390  void refreshIsoline(IsolineParams* pParams);
391  void refreshTwoDData(TwoDDataParams* pParams);
392  void refreshTwoDImage(TwoDImageParams* pParams);
393 
394  //Force dvr renderer to get latest CLUT
395  //
396  void setClutDirty(RenderParams* p);
397 
398  //Force all text-renderers to refresh, e.g. if background color changes
399  void refreshText();
400 
401 
402  //Force dvr renderers to get latest DataRange
403  //
404  void setDatarangeDirty(RenderParams* p);
405  void setFlowGraphicsDirty(FlowParams* p);
406  void setFlowDataDirty(FlowParams* p, bool doInterrupt = true);
407  void setFlowDisplayListDirty(FlowParams* p);
408  bool flowDataIsDirty(FlowParams* p);
409 
410  //Force reconstructing of all elevation grids
411  void setAllTwoDElevDirty();
412  //Tell the animationController that the frame counter has changed
413  //for all the associated windows.
414  //
415  void animationParamsChanged(AnimationParams* );
416  //Reset the near/far distances for all the windows that
417  //share a viewpoint, based on region in specified regionparams
418  //
419  void resetViews(ViewpointParams* vp);
420  //Set the viewer coords changed flag in all the visualizers
421  //that use these vp params:
422  void setViewerCoordsChanged(ViewpointParams* vp);
423  //Change to play state for the specified renderers:
424  //
425  void startPlay(AnimationParams* aParams);
426  //Tell all parameter panels to reinitialize (based on change of
427  //Metadata). If the parameter is true, we can override the panels'
428  //previous state
429  //
430  void reinitializeParams(bool doOverride);
431  //Reinitialize params and tabs for
432  //change in active variables
433  //
434  void reinitializeVariables();
435  //reset to starting state
436  //
437  void restartParams();
438 
439  //Make each window use its viewpoint params
440  void initViews();
441 
442  //Methods to handle save/restore of session state
443  ParamNode* buildNode();
444  bool elementStartHandler(ExpatParseMgr*, int /* depth*/ , std::string& /*tag*/, const char ** /*attribs*/);
445  bool elementEndHandler(ExpatParseMgr*, int /*depth*/ , std::string& /*tag*/);
446  //this tag needs to be visible in session class
447  static const string _visualizersTag;
448 
449 
450 
451  void setInteractiveNavigating(int level);
452  bool findCoincident2DSurface(int vizwin, float coordinate, TwoDParams *tParams);
453  void stopFlowIntegration();
454 
455 
456 
457 
458 public slots:
459  //arrange the viz windows:
460  void cascade();
461  void coverRight();
462  void fitSpace();
463  //Slots to handle home viewpoint (dispatch to proper panel)
464  void home();
465  void sethome();
466  //Slot that responds when user requests to activate a window:
467  void winActivated(int);
468  void killViz(int viznum);
469  //Slots that set viewpoint:
470  void viewAll();
471  void viewRegion();
472  void alignView(int axis);
473  //The vizWinMgr has to dispatch signals from gui's to the appropriate parameter panels
474 
475  void setVpLocalGlobal(int val);
476  void setRgLocalGlobal(int val);
477  void setAnimationLocalGlobal(int val);
478 
479 signals:
480  //Turn on/off multiple viz options:
481 
482  void enableMultiViz(bool onOff);
483  //Respond to user setting the vizselectorcombo:
484  void newViz(QString&, int);
485  void removeViz(int);
486  void activateViz(int);
487  void changeName(QString&, int);
488 
489 
490 protected:
491  static const string _vizUseLatLonAttr;
492  static const string _vizTimeAnnotColorAttr;
493  static const string _vizTimeAnnotTextSizeAttr;
494  static const string _vizTimeAnnotTypeAttr;
495  static const string _vizTimeAnnotCoordsAttr;
496  static const string _vizElevGridEnabledAttr;
497  static const string _vizElevGridColorAttr;
498  static const string _vizElevGridRefinementAttr;
499  static const string _vizWinTag;
500  static const string _vizWinNameAttr;
501  static const string _vizBgColorAttr;
502  static const string _vizRegionColorAttr;
503  static const string _vizSubregionColorAttr;
504  static const string _vizColorbarBackgroundColorAttr;
505  static const string _vizAxisPositionAttr;
506  static const string _vizAxisOriginAttr;
507  static const string _vizAxisAnnotationEnabledAttr;
508  static const string _vizMinTicAttr;
509  static const string _vizMaxTicAttr;
510  static const string _vizTicLengthAttr;
511  static const string _vizTicDirAttr;
512  static const string _vizNumTicsAttr;
513  static const string _vizAxisColorAttr;
514  static const string _vizTicWidthAttr;
515  static const string _vizLabelHeightAttr;
516  static const string _vizLabelDigitsAttr;
517  static const string _vizColorbarDigitsAttr;
518  static const string _vizColorbarFontsizeAttr;
519  static const string _vizColorbarLLPositionAttr;//obsolete with 2.4
520  static const string _vizColorbarURPositionAttr;//obsolete with 2.4
521  static const string _vizColorbarSizeAttr; //new with 2.4
522  static const string _vizColorbarLLXTag;//new with 2.4
523  static const string _vizColorbarLLYTag;//new with 2.4
524  static const string _vizColorbarTitlesTag; //new with 2.4
525  static const string _vizColorbarNumTicsAttr;
526  static const string _vizAxisArrowsEnabledAttr;
527  static const string _vizColorbarEnabledAttr; //obsolete with 2.4
528  static const string _vizColorbarEnabledTag; //new with 2.4
529  static const string _vizColorbarParamsNameAttr; //obsolete with 2.4
530  static const string _vizRegionFrameEnabledAttr;
531  static const string _vizSubregionFrameEnabledAttr;
532  static const string _visualizerNumAttr;
533  static const string _vizElevGridDisplacementAttr;
534  static const string _vizElevGridInvertedAttr;
535  static const string _vizElevGridRotationAttr;
536  static const string _vizElevGridTexturedAttr;
537  static const string _vizElevGridTextureNameAttr;
538 
539 
540  RegionParams* getRealRegionParams(int win) {
541  if (!vizWin[win]) return 0;
542  Params* p = Params::GetParamsInstance(Params::_regionParamsTag,win,-1);
543  if (p->isLocal()) return (RegionParams*)p;
544  return (RegionParams*)Params::GetDefaultParams(Params::_regionParamsTag);
545  }
546  AnimationParams* getRealAnimationParams(int win) {
547  if (!vizWin[win]) return 0;
548  Params* p = Params::GetParamsInstance(Params::_animationParamsTag,win,-1);
549  if (p->isLocal()) return (AnimationParams*)p;
550  return (AnimationParams*)Params::GetDefaultParams(Params::_animationParamsTag);
551  }
552  ViewpointParams* getGlobalVPParams(){return (ViewpointParams*)(Params::GetDefaultParams(Params::_viewpointParamsTag));}
553  RegionParams* getGlobalRegionParams(){
554  return (RegionParams*)(Params::GetDefaultParams(Params::_regionParamsTag));
555  }
556  AnimationParams* getGlobalAnimationParams(){return (AnimationParams*)(Params::GetDefaultParams(Params::_animationParamsTag));}
557 
558  static Params::ParamsBaseType RegisterEventRouter(const std::string tag, EventRouter* router);
559  static std::map<ParamsBase::ParamsBaseType, EventRouter*> eventRouterMap;
560 
561  // Method that returns the current params instance that applies in the current
562  // active visualizer if it is local.
563  Params* getLocalParams(Params::ParamsBaseType t);
564 
565  static void setGlobalParams(Params* p, ParamsBase::ParamsBaseType t);
566 
567  static VizWinMgr* theVizWinMgr;
568  VizWinMgr ();
569 
570  VizWin* vizWin[MAXVIZWINS];
571  QMdiSubWindow* vizMdiWin[MAXVIZWINS];
572 
573  QString vizName[MAXVIZWINS];
574  bool isMax[MAXVIZWINS];
575  bool isMin[MAXVIZWINS];
576 
577  //Remember the activation order:
578  int activationOrder[MAXVIZWINS];
579  int activationCount;
580  int getLastActive(){
581  int mx = -1; int mj = -1;
582  for (int j = 0; j< MAXVIZWINS; j++){
583  if (vizWin[j] && activationOrder[j]>mx){
584  mx = activationOrder[j];
585  mj = j;
586  }
587  }
588  return mj;
589  }
590  Trackball* globalTrackball;
591 
592 
593 
594  MainForm* myMainWindow;
595  static TabManager* tabManager;
596 
597  int activeViz;
598  vector<int> parsingInstance;
599  int parsingVizNum, parsingDvrInstance, parsingIsoInstance,parsingFlowInstance, parsingProbeInstance,parsingTwoDDataInstance,parsingTwoDImageInstance;
600 
601  QMdiArea* myMDIArea;
602  FlowTab* myFlowTab;
603 
604  int benchmark;
605  QTimer *benchmarkTimer;
606  bool spinAnimate;
607 
608 #endif //DOXYGEN_SKIP_THIS
609 
610 
611 
612 };
613 };
614 #endif // VIZWINMGR_H
615 
A pure virtual class for managing parameters used in visualization.
Definition: params.h:75
void forceRender(RenderParams *rp, bool always=false)
A Params subclass for managing parameters used by Renderers.
Definition: params.h:564
static Params * getActiveParams(const std::string &tag)
Definition: vizwinmgr.h:100
Region bit indicates the region bounds have changed.
Definition: params.h:48
static int getCurrentInstanceIndex(int winnum, Params::ParamsBaseType t)
static Params * getGlobalParams(Params::ParamsBaseType ptype)
int getActiveInstanceIndex(Params::ParamsBaseType t)
Definition: vizwinmgr.h:178
bool reloadShaders()
Method that forces all glWindows to reload their shaders.
static int GetNumParamsInstances(int pType, int winnum)
Definition: params.h:205
A pure virtual class specifying the common properties of all the parameter tabs in the VAPOR GUI...
Definition: eventrouter.h:55
Params * getApplicableParams(const std::string &tag)
Definition: vizwinmgr.h:190
virtual bool elementStartHandler(ExpatParseMgr *, int, std::string &, const char **)=0
static int findInstanceIndex(int winnum, Params *params, Params::ParamsBaseType t)
static Params * GetParamsInstance(int pType, int winnum=-1, int instance=-1)
static void InstallTab(const std::string tag, EventRouterCreateFcn fcn)
static Params * GetDefaultParams(ParamsBase::ParamsBaseType pType)
Definition: params.h:162
Params * getApplicableParams(Params::ParamsBaseType t)
DirtyBitType
Definition: params.h:46
A class for managing all visualizers.
Definition: vizwinmgr.h:81
#define MAXVIZWINS
Definition: params.h:39
void setVizDirty(Params *p, DirtyBitType bittype, bool bit=true, bool refresh=true)
static EventRouter * getEventRouter(const std::string &tag)
Definition: vizwinmgr.h:127
static int RegisterMouseMode(const std::string paramsTag, int manipType, const char *name, const char *const xpmIcon[]=0)
static ParamsBaseType GetTypeFromTag(const string &tag)
static EventRouter * getEventRouter(Params::ParamsBaseType typeId)
EventRouter *( EventRouterCreateFcn)()
Definition: vizwinmgr.h:70
void setParams(int winNum, Params *p, ParamsBase::ParamsBaseType typeId, int instance=-1)
static int getNumInstances(int winnum, Params::ParamsBaseType pType)
virtual bool elementEndHandler(ExpatParseMgr *, int, std::string &)=0
Params * getParams(int winNum, Params::ParamsBaseType pType, int instance=-1)
AnimationBit indicates a change in current frame.
Definition: params.h:58