1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File: VISU_ScalarBarCtrl.cxx
24 // Author: Peter KURNEV
27 #include "VISU_ScalarBarCtrl.hxx"
28 #include "VISU_LookupTable.hxx"
29 #include "VISU_ScalarBarActor.hxx"
31 #include <vtkObjectFactory.h>
32 #include <vtkActor2D.h>
33 #include <vtkCoordinate.h>
34 #include <vtkRenderer.h>
35 #include <vtkScalarsToColors.h>
36 #include <vtkTextProperty.h>
42 //----------------------------------------------------------------------------
43 vtkStandardNewMacro(VISU_ScalarBarCtrl);
45 //----------------------------------------------------------------------------
47 ::VISU_ScalarBarCtrl():
48 myGlobalRangeIsDefined(false)
59 // Initilize global scalar bar
60 myGlobalLookupTable = VISU_LookupTable::New();
61 myGlobalLookupTable->SetHueRange(0.667,0.0);
63 myGlobalScalarBar = VISU_ScalarBarActor::New();
64 myGlobalScalarBar->SetLookupTable(myGlobalLookupTable);
65 myGlobalLookupTable->Delete();
67 // Initilize local scalar bar
68 myLocalLookupTable = VISU_LookupTable::New();
69 myLocalLookupTable->SetHueRange(0.667,0.0);
71 myLocalScalarBar = VISU_ScalarBarActor::New();
72 myLocalScalarBar->SetLookupTable(myLocalLookupTable);
73 myLocalLookupTable->Delete();
75 myBlack[0] = myBlack[1] = myBlack[2] = 0;
76 myGrey[0] = myGrey[1] = myGrey[2] = 192;
83 //----------------------------------------------------------------------------
85 ::~VISU_ScalarBarCtrl()
87 myGlobalScalarBar->Delete();
91 //----------------------------------------------------------------------------
94 ::SetMode(VISU_ScalarBarCtrl::EMode theMode)
99 VISU_ScalarBarCtrl::EMode
107 //----------------------------------------------------------------------------
110 ::SetVisibility(int theVisibility)
112 myGlobalScalarBar->SetVisibility(false);
113 myLocalScalarBar->SetVisibility(false);
114 int aVisibility = (myCtrlVisibility && theVisibility);
116 if(myMode != eSimple)
117 myGlobalScalarBar->SetVisibility(aVisibility);
118 myLocalScalarBar->SetVisibility(aVisibility);
124 ::GetVisibility() const
126 return myGlobalScalarBar->GetVisibility() || myLocalScalarBar->GetVisibility();
131 ::SetCtrlVisibility(int theVisibility)
133 myCtrlVisibility = theVisibility;
138 ::GetCtrlVisibility() const
140 return myCtrlVisibility;
144 //----------------------------------------------------------------------------
147 ::SetRangeLocal(vtkFloatingPointType *theRange)
149 myLocalLookupTable->SetTableRange(theRange);
154 ::SetRangeLocal(vtkFloatingPointType theMin,
155 vtkFloatingPointType theMax)
157 myLocalLookupTable->SetTableRange(theMin,theMax);
161 //----------------------------------------------------------------------------
164 ::SetRangeGlobal(vtkFloatingPointType *theRange)
166 myGlobalLookupTable->SetTableRange(theRange);
171 ::SetRangeGlobal(vtkFloatingPointType theMin,
172 vtkFloatingPointType theMax)
174 myGlobalLookupTable->SetTableRange(theMin,theMax);
179 ::SetGlobalRangeIsDefined(bool theIsDefined)
181 myGlobalRangeIsDefined = theIsDefined;
185 //----------------------------------------------------------------------------
190 return myLocalScalarBar;
197 return myGlobalScalarBar;
201 //----------------------------------------------------------------------------
206 return myLocalLookupTable;
213 return myGlobalLookupTable;
217 //----------------------------------------------------------------------------
220 ::AddToRender(vtkRenderer* theRenderer)
222 theRenderer->AddActor2D(myGlobalScalarBar);
223 theRenderer->AddActor2D(myLocalScalarBar);
229 ::RemoveFromRender(vtkRenderer* theRenderer)
231 theRenderer->RemoveActor2D(myGlobalScalarBar);
232 theRenderer->RemoveActor2D(myLocalScalarBar);
236 //----------------------------------------------------------------------------
239 ::SetWidth(vtkFloatingPointType theWidth)
241 myGlobalScalarBar->SetWidth(theWidth);
242 myLocalScalarBar->SetWidth(theWidth);
249 return myGlobalScalarBar->GetWidth();
253 //----------------------------------------------------------------------------
256 ::SetHeight(vtkFloatingPointType theHeight)
258 myGlobalScalarBar->SetHeight(theHeight);
259 myLocalScalarBar->SetHeight(theHeight);
267 return myGlobalScalarBar->GetHeight();
271 //----------------------------------------------------------------------------
274 ::SetPosition(const vtkFloatingPointType* thePosition)
276 myPosition[0] = thePosition[0];
277 myPosition[1] = thePosition[1];
280 const vtkFloatingPointType*
281 VISU_ScalarBarCtrl::GetPosition() const
287 //----------------------------------------------------------------------------
290 ::SetSpacing(const vtkFloatingPointType theSpacing)
292 myDistance = theSpacing;
303 //----------------------------------------------------------------------------
306 ::SetBicolor(const bool theBicolor)
308 myBicolor = theBicolor;
319 //----------------------------------------------------------------------------
322 ::SetMarkValue(const vtkFloatingPointType theValue)
324 myMarkedValue = theValue;
329 ::GetMarkValue() const
331 return myMarkedValue;
335 //----------------------------------------------------------------------------
338 ::SetIsMarked(const bool theFlag)
345 ::GetIsMarked() const
351 //----------------------------------------------------------------------------
356 SetVisibility(GetVisibility());
369 //----------------------------------------------------------------------------
375 if(myMode == eGlobal){
376 myGlobalLookupTable->MarkValueByColor( myMarkedValue, myBlack );
378 myLocalLookupTable->MarkValueByColor( myMarkedValue, myBlack );
381 if(myGlobalRangeIsDefined){
382 vtkFloatingPointType aLocalRange[2];
383 myLocalLookupTable->GetTableRange(aLocalRange);
384 myGlobalLookupTable->MarkValueByColor( aLocalRange[0], myBlack );
385 myGlobalLookupTable->MarkValueByColor( aLocalRange[1], myBlack );
390 //----------------------------------------------------------------------------
393 ::PrepareTables(VISU_ScalarBarActor* theScalarBarActor,
394 VISU_LookupTable *theLookupTable,
397 vtkCoordinate * aCoordinate = theScalarBarActor->GetPositionCoordinate();
398 aCoordinate->SetCoordinateSystemToNormalizedViewport();
399 if(theScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL){
400 vtkFloatingPointType aWidth = theScalarBarActor->GetWidth();
401 aCoordinate->SetValue(myPosition[0]+theId*(aWidth+myDistance), myPosition[1]);
403 vtkFloatingPointType aHeight = theScalarBarActor->GetHeight();
404 aCoordinate->SetValue(myPosition[0], myPosition[1]+theId*(aHeight+myDistance));
406 // Initialize Lookup Tables and Scalar Bars
407 theLookupTable->Modified();
408 theLookupTable->Build();
416 if(myMode != eSimple){
417 PrepareTables(myGlobalScalarBar,myGlobalLookupTable,0);
418 PrepareTables(myLocalScalarBar,myLocalLookupTable,1);
420 PrepareTables(myLocalScalarBar,myLocalLookupTable,0);
425 //----------------------------------------------------------------------------
430 if(myMode == eGlobal){
431 myLocalLookupTable->FillByColor( myGrey );
432 }else if(myMode == eLocal){
433 myGlobalLookupTable->FillByColor( myGrey );
438 //----------------------------------------------------------------------------
443 myLocalLookupTable->Modified();
444 myLocalLookupTable->Build();
446 if(myMode == eSimple){
447 myLocalLookupTable->MakeBiColor();
451 if(myMode == eGlobal){
452 myGlobalLookupTable->MakeBiColor();
453 myLocalLookupTable->FillByColor( myGrey );
454 }else if(myMode == eLocal){
455 myLocalLookupTable->MakeBiColor();
456 myGlobalLookupTable->FillByColor( myGrey );