mantaflow  0.10
A framework for fluid simulation
painter.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  *
4  * MantaFlow fluid solver framework
5  * Copyright 2011 Tobias Pfaff, Nils Thuerey
6  *
7  * This program is free software, distributed under the terms of the
8  * GNU General Public License (GPL)
9  * http://www.gnu.org/licenses
10  *
11  * Base class for objects painting into the GL widget
12  *
13  ******************************************************************************/
14 
15 #ifndef _PAINTER_H_
16 #define _PAINTER_H_
17 
18 #include <QWidget>
19 #include <QLabel>
20 #include <map>
21 #include "grid.h"
22 
23 namespace Manta {
24 
25 // forward decl.
26 class PbClass;
27 
29 
30 class Painter : public QObject {
31  Q_OBJECT
32 public:
33  enum PainterEvent {
34  EventNone = 0, UpdateRequest, UpdateFull, UpdateStep,
35  EventScaleVecUpSm, EventScaleVecDownSm, EventScaleVecUp, EventScaleVecDown,
36  EventNextRealDisplayMode, EventScaleRealUp, EventScaleRealDown, EventScaleRealUpSm, EventScaleRealDownSm, EventChangePlane,
37  EventSetPlane, EventSetDim, EventNextInt, EventNextReal, EventNextVec, EventNextVecDisplayMode,
38  EventNextMesh, EventMeshMode, EventToggleGridDisplay, EventScaleMeshUp, EventScaleMeshDown, EventMeshColorMode,
39  EventNextSystem, EventToggleParticles, EventNextParticleDisplayMode, EventToggleBackgroundMesh, EventSetMax,
40  EventScalePdataDown, EventScalePdataUp };
41 
43  enum RealDisplayModes { RealDispOff=0, RealDispStd, RealDispLevelset, RealDispShadeVol, RealDispShadeSurf, NumRealDispModes };
44  enum VecDisplayModes { VecDispOff=0, VecDispCentered, VecDispStaggered, VecDispUv, NumVecDispModes };
45 
46  Painter(QWidget* par = 0) : QObject(par) {}
47  virtual ~Painter() {}
48 
49  virtual std::string clickLine(const Vec3& p0, const Vec3& p1) { return ""; }
50  virtual void attachWidget(QLayout* layout) {}
51 signals:
52  void setViewport(const Vec3i& gridsize);
53 
54 public slots:
55  virtual void paint() = 0;
56  virtual void doEvent(int e, int param=0) = 0;
57 };
58 
60 
61 class LockedObjPainter : public Painter {
62  Q_OBJECT
63 public:
64  LockedObjPainter(QWidget* par = 0) : Painter(par), mRequestUpdate(false), mObject(NULL), mObjIndex(-1) {}
65 
66  void doEvent(int e, int param=0); // don't overload, use processKeyEvent and update instead
67 
68 protected:
69  void nextObject();
70  virtual std::string getID() = 0;
71  virtual void update() = 0;
72  virtual void processKeyEvent(PainterEvent e, int param) = 0;
73 
74  bool mRequestUpdate;
75  PbClass* mObject;
76  int mObjIndex;
77 };
78 
80 template<class T>
81 class GridPainter : public LockedObjPainter {
82 public:
83  GridPainter(FlagGrid** flags = NULL, QWidget* par = 0);
84  ~GridPainter();
85 
86  void paint();
87  void attachWidget(QLayout* layout);
88  Grid<T>** getGridPtr() { return &mLocalGrid; }
89  int getPlane() { return mPlane; }
90  int getDim() { return mDim; }
91  int getMax() { return mMax; }
92  virtual std::string clickLine(const Vec3& p0, const Vec3& p1);
93 
94 protected:
95  std::string getID();
96  Real getScale();
97  void setScale(Real v);
98  int getDispMode();
99  void setDispMode(int dm);
100  void update();
101  void updateText();
102  void processKeyEvent(PainterEvent e, int param);
103  void processSpecificKeyEvent(PainterEvent e, int param);
104  //void paintGridLines(bool lines, bool box);
105 
106  Real mMaxVal;
107  int mDim, mPlane, mMax;
108  Grid<T>* mLocalGrid;
110  QLabel* mInfo;
111  bool mHide;
112  bool mHideLocal;
113  std::map< void*, int > mDispMode;
114  std::map< std::pair<void*, int>, Real> mValScale;
115 };
116 
117 }
118 
119 #endif
120 
121 
bool mHide
info string
Definition: painter.h:111
Definition: commonkernels.h:22
FlagGrid ** mFlags
currently selected grid
Definition: painter.h:109
Definition: grid.h:267
Definition: fileio.h:25
Basic inlined vector class.
Definition: vectorbase.h:71
RealDisplayModes
display modes, note - 0=off,1=std are shared for real & vec grids! same semantics ...
Definition: painter.h:43
Base clas for all painters that require access to a locked PbClass.
Definition: painter.h:61
Painter object for int,Real,Vec3 grids.
Definition: painter.h:81
Base class for all painter.
Definition: painter.h:30
bool mHideLocal
hide all grids?
Definition: painter.h:112
int mDim
stats
Definition: painter.h:107
std::map< std::pair< void *, int >, Real > mValScale
display modes , for each object
Definition: painter.h:114
QLabel * mInfo
flag grid (can influence display of selected grid)
Definition: painter.h:110
std::map< void *, int > mDispMode
hide only this type?
Definition: painter.h:113