]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_ScalarBarActor.hxx
Salome HOME
Issue 0019818: EDF 703 SMESH VISU : Display Mesh Groups names in viewer (as a caption)
[modules/visu.git] / src / PIPELINE / VISU_ScalarBarActor.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
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 GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU OBJECT : interactive object for VISU entities implementation
23 // File:    VISU_PipeLine.hxx
24 // Author:  Alexey PETROV
25 // Module : VISU
26 //
27 #ifndef VISU_ScalarBarActor_HeaderFile
28 #define VISU_ScalarBarActor_HeaderFile
29
30 #include "VISUPipeline.hxx"
31 #include "VISU_LookupTable.hxx"
32 #include "VISU_XYPlotActor.hxx"
33
34 #include <vtkActor2D.h>
35 #include <vtkDoubleArray.h> // RKV
36
37 class vtkPolyData;
38 class vtkPolyDataMapper2D;
39 class vtkScalarsToColors;
40 class vtkTextMapper;
41 class vtkTextProperty;
42
43 #ifndef VTK_ORIENT_HORIZONTAL
44 #define VTK_ORIENT_HORIZONTAL 0
45 #endif
46
47 #ifndef VTK_ORIENT_VERTICAL
48 #define VTK_ORIENT_VERTICAL 1
49 #endif
50
51 class VISU_PIPELINE_EXPORT VISU_ScalarBarActor : public vtkActor2D
52 {
53 public:
54   vtkTypeRevisionMacro(VISU_ScalarBarActor,vtkActor2D);
55   void PrintSelf(ostream& os, vtkIndent indent);
56
57   // Description:
58   // Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label
59   // format, no title, and vertical orientation. The initial scalar bar
60   // size is (0.05 x 0.8) of the viewport size.
61   static VISU_ScalarBarActor *New();
62
63   // Description:
64   // Draw the scalar bar and annotation text to the screen.
65   int RenderOpaqueGeometry(vtkViewport* viewport);
66   int RenderTranslucentGeometry(vtkViewport*) { return 0; };
67   int RenderOverlay(vtkViewport* viewport);
68
69   // Description:
70   // Release any graphics resources that are being consumed by this actor.
71   // The parameter window could be used to determine which graphic
72   // resources to release.
73   virtual void ReleaseGraphicsResources(vtkWindow *);
74
75   // Description:
76   // Set/Get the vtkLookupTable to use. The lookup table specifies the number
77   // of colors to use in the table (if not overridden), as well as the scalar
78   // range.
79   virtual void SetLookupTable(VISU_LookupTable*);
80   vtkGetObjectMacro(LookupTable,VISU_LookupTable);
81
82   // Description:
83   // Set/Get the maximum number of scalar bar segments to show. This may
84   // differ from the number of colors in the lookup table, in which case
85   // the colors are samples from the lookup table.
86   vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_LARGE_INTEGER);
87   vtkGetMacro(MaximumNumberOfColors, int);
88   
89   // Description:
90   // Set/Get the number of annotation labels to show.
91   vtkSetClampMacro(NumberOfLabels, int, 0, 64);
92   vtkGetMacro(NumberOfLabels, int);
93   
94   // Description:
95   // Control the orientation of the scalar bar.
96   vtkSetClampMacro(Orientation,int,VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
97   vtkGetMacro(Orientation, int);
98   void SetOrientationToHorizontal()
99        {this->SetOrientation(VTK_ORIENT_HORIZONTAL);};
100   void SetOrientationToVertical() {this->SetOrientation(VTK_ORIENT_VERTICAL);};
101
102   // Description:
103   // Set/Get the title text property.
104   virtual void SetTitleTextProperty(vtkTextProperty *p);
105   vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
106   
107   // Description:
108   // Set/Get the labels text property.
109   virtual void SetLabelTextProperty(vtkTextProperty *p);
110   vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
111
112 // RKV : Begin
113   // Description:
114   // Set/Get the values distribution array
115   virtual void SetDistribution(vtkDoubleArray *d);
116   vtkGetObjectMacro(Distribution,vtkDoubleArray);
117   
118   // Description:
119   // Set/Get the flag of distribution plot visibility
120   void SetDistributionVisibility(int v);
121   vtkGetMacro(DistributionVisibility, int);
122   void DistributionVisibilityOn()
123        {this->SetDistributionVisibility(1);};
124   void DistributionVisibilityOff() {this->SetDistributionVisibility(0);};
125
126   void DebugOn();
127   void DebugOff();
128 // RKV : End
129     
130   // Description:
131   // Set/Get the scalar bar dimention properties in persents.
132   // 0 <= ration <= 100
133   void SetRatios(int titleRatioSize,int labelRatioWidth,
134                  int barRatioWidth, int barRatioHeight);
135   void GetRatios(int& titleRatioSize, int& labelRatioWidth,
136                  int& barRatioWidth, int& barRatioHeight);
137
138   // Description:
139   // Set/Get the format with which to print the labels on the scalar
140   // bar.
141   vtkSetStringMacro(LabelFormat);
142   vtkGetStringMacro(LabelFormat);
143
144   // Description:
145   // Set/Get the title of the scalar bar actor,
146   vtkSetStringMacro(Title);
147   vtkGetStringMacro(Title);
148
149   // Description:
150   // Shallow copy of a scalar bar actor. Overloads the virtual vtkProp method.
151   void ShallowCopy(vtkProp *prop);
152
153 protected:
154   VISU_ScalarBarActor();
155   ~VISU_ScalarBarActor();
156
157   VISU_LookupTable *LookupTable;
158   vtkTextProperty *TitleTextProperty;
159   vtkTextProperty *LabelTextProperty;
160   
161   /** Array for keeping the distribution of colors within cells.
162    * For each color index the appropriate element of the array contains 
163    * a number of cells for this color.*/ 
164   vtkDoubleArray     *Distribution; // RKV
165   /** Visibility flag for the distribution plot */
166   int             DistributionVisibility; // RKV
167
168   int   MaximumNumberOfColors;
169   int   NumberOfLabels;
170   int   NumberOfLabelsBuilt;
171   int   Orientation;
172   char  *Title;
173   char  *LabelFormat;
174   int   TitleRatioSize;
175   int   LabelRatioWidth;
176   int   BarRatioWidth;
177   int   BarRatioHeight;
178
179   vtkTextMapper **TextMappers;
180   virtual void AllocateAndSizeLabels(int *labelSize, int *size,
181                                      vtkViewport *viewport, vtkFloatingPointType *range);
182
183 private:
184   vtkTextMapper *TitleMapper;
185   vtkActor2D    *TitleActor;
186
187   vtkActor2D    **TextActors;
188
189   vtkPolyData         *ScalarBar;
190   vtkPolyDataMapper2D *ScalarBarMapper;
191   vtkActor2D          *ScalarBarActor;
192
193   vtkDataObject       *DistributionObj; // RKV
194   VISU_XYPlotActor    *DistributionActor; // RKV
195
196   vtkTimeStamp  BuildTime;
197   int LastSize[2];
198   int LastOrigin[2];
199
200   void SizeTitle(int *titleSize, int *size, vtkViewport *viewport);
201
202   void SizeBar(int& barSizeWidth, int& barSizeHeight, int *size,
203                vtkViewport *viewport, vtkFloatingPointType *range);
204                
205   /** Place the distribution plot actor in the viewport according to the 
206    * scalar bar location and orientation */
207   void PlaceDistribution(vtkViewport *viewport, const int barWidth, const int barHeight);
208
209 private:
210   VISU_ScalarBarActor(const VISU_ScalarBarActor&);  // Not implemented.
211   void operator=(const VISU_ScalarBarActor&);  // Not implemented.
212 };
213
214 #endif