~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Gui/SoFCColorBar.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2005 Werner Mayer <werner.wm.mayer@gmx.de>              *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  is distributed in the hope that it will be useful,      *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#ifndef GUI_SOFCCOLORBAR_H
 
25
#define GUI_SOFCCOLORBAR_H
 
26
 
 
27
#ifndef __Qt4All__
 
28
# include "Qt4All.h"
 
29
#endif
 
30
 
 
31
#ifndef __InventorAll__
 
32
# include "InventorAll.h"
 
33
#endif
 
34
 
 
35
#include <Base/Observer.h>
 
36
#include <App/ColorModel.h>
 
37
#include <vector>
 
38
 
 
39
class SoSwitch;
 
40
class SoEventCallback;
 
41
class SbVec2s;
 
42
class SoHandleEventAction;
 
43
class SoGLRenderAction;
 
44
 
 
45
namespace Gui {
 
46
class SoFCColorGradient;
 
47
 
 
48
/**
 
49
 * The abstract color bar base class to get most important information on how to convert a scalar to an RGB color. 
 
50
 * @author Werner Mayer
 
51
 */
 
52
class GuiExport SoFCColorBarBase : public SoSeparator, public App::ValueFloatToRGB {
 
53
  typedef SoSeparator inherited;
 
54
 
 
55
  SO_NODE_ABSTRACT_HEADER(Gui::SoFCColorBarBase);
 
56
 
 
57
public:
 
58
  static void initClass(void);
 
59
  static void finish(void);
 
60
 
 
61
  virtual void GLRenderBelowPath ( SoGLRenderAction *action );
 
62
 
 
63
  /**
 
64
   * Sets the range of the colorbar from the maximum \a fMax to the minimum \a fMin.
 
65
   * \a prec indicates the post decimal positions, \a prec should be in between 0 and 6.
 
66
   *
 
67
   * This method must be implemented in subclasses.
 
68
   */
 
69
  virtual void setRange( float fMin, float fMax, int prec=3 ) = 0;
 
70
  /**
 
71
   * Returns the associated color to the value \a fVal.
 
72
   *
 
73
   * This method must be implemented in subclasses.
 
74
   */
 
75
  virtual App::Color getColor(float fVal) const = 0;
 
76
  /**
 
77
   * Returns always true if the color bar is in mode to show colors to arbitrary values of \a fVal,
 
78
   * otherwise true is returned if \a fVal is within the specified parameter range, if not false is
 
79
   * returned.
 
80
   *
 
81
   * This method must be implemented in subclasses.
 
82
   */
 
83
  virtual bool isVisible (float fVal) const = 0;
 
84
  /** Returns the current minimum of the parameter range. 
 
85
   *
 
86
   * This method must be implemented in subclasses.
 
87
   */
 
88
  virtual float getMinValue (void) const = 0;
 
89
  /** Returns the current maximum of the parameter range. 
 
90
   *
 
91
   * This method must be implemented in subclasses.
 
92
   */
 
93
  virtual float getMaxValue (void) const = 0;
 
94
  /**
 
95
   * Opems a dialog to customie the current settings of the color bar.
 
96
   * Returns true if the settings have been changed, false otherwise.
 
97
   *
 
98
   * This method must be implemented in subclasses.
 
99
   */
 
100
  virtual bool customize() = 0;
 
101
  /** Returns the name of the color bar. 
 
102
   *
 
103
   * This method must be implemented in subclasses.
 
104
   */
 
105
  virtual const char* getColorBarName() const = 0;
 
106
 
 
107
protected:
 
108
  /**
 
109
   * Sets the current viewer size to recalculate the new position.
 
110
   *
 
111
   * This method must be implemented in subclasses.
 
112
   */
 
113
  virtual void setViewportSize( const SbVec2s& size ) = 0;
 
114
 
 
115
  SoFCColorBarBase (void);
 
116
  virtual ~SoFCColorBarBase ();
 
117
 
 
118
private:
 
119
  SbVec2s _windowSize;
 
120
};
 
121
 
 
122
// --------------------------------------------------------------------------
 
123
 
 
124
/**
 
125
 * The color bar class that redirects all calls to its handled color bars. 
 
126
 * @author Werner Mayer
 
127
 */
 
128
class GuiExport SoFCColorBar : public SoFCColorBarBase, public Base::Subject<int> {
 
129
  typedef SoFCColorBarBase inherited;
 
130
 
 
131
  SO_NODE_HEADER(Gui::SoFCColorBar);
 
132
 
 
133
public:
 
134
  static void initClass(void);
 
135
  static void finish(void);
 
136
  SoFCColorBar(void);
 
137
 
 
138
  /**
 
139
   * Returns the currently active color bar object.
 
140
   */
 
141
  SoFCColorBarBase* getActiveBar() const;
 
142
  /**
 
143
   * Handles the mouse button events and checks if the user has clicked on the area of the currently active color bar.
 
144
   */
 
145
  void handleEvent (SoHandleEventAction *action);
 
146
  /**
 
147
   * Sets the range of all color bars from the maximum \a fMax to the minimum \a fMin.
 
148
   * \a prec indicates the post decimal positions, \a prec should be in between 0 and 6.
 
149
   */
 
150
  void setRange( float fMin, float fMax, int prec=3 );
 
151
  /**
 
152
   * Returns the associated color to the value \a fVal of the currently active color bar.
 
153
   */
 
154
  App::Color getColor(float fVal) const;
 
155
  /**
 
156
   * Returns the return value of the currently active color bar.
 
157
   */
 
158
  bool isVisible (float fVal) const;
 
159
  /** 
 
160
   * Returns the current minimum of the parameter range of the currently active color bar. 
 
161
   */
 
162
  float getMinValue (void) const;
 
163
  /** 
 
164
   * Returns the current maximum of the parameter range of the currently active color bar. 
 
165
   */
 
166
  float getMaxValue (void) const;
 
167
  /**
 
168
   * Customizes the currently active color bar.
 
169
   */
 
170
  bool customize();
 
171
  /** Returns the name of the color bar. 
 
172
   */
 
173
  const char* getColorBarName() const { return "Color Bar"; }
 
174
 
 
175
protected:
 
176
  /**
 
177
   * Sets the current viewer size to all color bars to recalculate their new position.
 
178
   */
 
179
  void setViewportSize( const SbVec2s& size );
 
180
 
 
181
  virtual ~SoFCColorBar();
 
182
 
 
183
private:
 
184
  static void eventCallback(void * userdata, SoEventCallback * node);
 
185
 
 
186
private:
 
187
  float _fMaxX, _fMinX, _fMaxY, _fMinY;
 
188
  QTime _timer;
 
189
 
 
190
  SoSwitch* pColorMode; 
 
191
  std::vector<SoFCColorBarBase*> _colorBars;
 
192
};
 
193
 
 
194
} // namespace Gui
 
195
 
 
196
 
 
197
#endif // GUI_SOFCCOLORBAR_H
 
198