1 // Copyright (C) 2007-2012 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
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File: VISU_ScalarBarCtrl.cxx
25 // Author: Peter KURNEV
28 #include "VISU_ScalarBarCtrl.hxx"
29 #include "VISU_LookupTable.hxx"
30 #include "VISU_ScalarBarActor.hxx"
32 #include <vtkObjectFactory.h>
33 #include <vtkActor2D.h>
34 #include <vtkCoordinate.h>
35 #include <vtkRenderer.h>
36 #include <vtkScalarsToColors.h>
37 #include <vtkTextProperty.h>
43 //----------------------------------------------------------------------------
44 vtkStandardNewMacro(VISU_ScalarBarCtrl);
46 //----------------------------------------------------------------------------
48 ::VISU_ScalarBarCtrl():
49 myGlobalRangeIsDefined(false)
60 // Initilize global scalar bar
61 myGlobalLookupTable = VISU_LookupTable::New();
62 myGlobalLookupTable->SetHueRange(0.667,0.0);
64 myGlobalScalarBar = VISU_ScalarBarActor::New();
65 myGlobalScalarBar->SetLookupTable(myGlobalLookupTable);
66 myGlobalLookupTable->Delete();
68 // Initilize local scalar bar
69 myLocalLookupTable = VISU_LookupTable::New();
70 myLocalLookupTable->SetHueRange(0.667,0.0);
72 myLocalScalarBar = VISU_ScalarBarActor::New();
73 myLocalScalarBar->SetLookupTable(myLocalLookupTable);
74 myLocalLookupTable->Delete();
76 myBlack[0] = myBlack[1] = myBlack[2] = 0;
77 myGrey[0] = myGrey[1] = myGrey[2] = 192;
84 //----------------------------------------------------------------------------
86 ::~VISU_ScalarBarCtrl()
88 myGlobalScalarBar->Delete();
92 //----------------------------------------------------------------------------
95 ::SetMode(VISU_ScalarBarCtrl::EMode theMode)
100 VISU_ScalarBarCtrl::EMode
108 //----------------------------------------------------------------------------
111 ::SetVisibility(int theVisibility)
113 myGlobalScalarBar->SetVisibility(false);
114 myLocalScalarBar->SetVisibility(false);
115 int aVisibility = (myCtrlVisibility && theVisibility);
117 if(myMode != eSimple)
118 myGlobalScalarBar->SetVisibility(aVisibility);
119 myLocalScalarBar->SetVisibility(aVisibility);
125 ::GetVisibility() const
127 return myGlobalScalarBar->GetVisibility() || myLocalScalarBar->GetVisibility();
132 ::SetCtrlVisibility(int theVisibility)
134 myCtrlVisibility = theVisibility;
139 ::GetCtrlVisibility() const
141 return myCtrlVisibility;
145 //----------------------------------------------------------------------------
148 ::SetRangeLocal(vtkFloatingPointType *theRange)
150 myLocalLookupTable->SetTableRange(theRange);
155 ::SetRangeLocal(vtkFloatingPointType theMin,
156 vtkFloatingPointType theMax)
158 myLocalLookupTable->SetTableRange(theMin,theMax);
162 //----------------------------------------------------------------------------
165 ::SetRangeGlobal(vtkFloatingPointType *theRange)
167 myGlobalLookupTable->SetTableRange(theRange);
172 ::SetRangeGlobal(vtkFloatingPointType theMin,
173 vtkFloatingPointType theMax)
175 myGlobalLookupTable->SetTableRange(theMin,theMax);
180 ::SetGlobalRangeIsDefined(bool theIsDefined)
182 myGlobalRangeIsDefined = theIsDefined;
186 //----------------------------------------------------------------------------
191 return myLocalScalarBar;
198 return myGlobalScalarBar;
202 //----------------------------------------------------------------------------
207 return myLocalLookupTable;
214 return myGlobalLookupTable;
218 //----------------------------------------------------------------------------
221 ::AddToRender(vtkRenderer* theRenderer)
223 theRenderer->AddActor2D(myGlobalScalarBar);
224 theRenderer->AddActor2D(myLocalScalarBar);
230 ::RemoveFromRender(vtkRenderer* theRenderer)
232 theRenderer->RemoveActor2D(myGlobalScalarBar);
233 theRenderer->RemoveActor2D(myLocalScalarBar);
237 //----------------------------------------------------------------------------
240 ::SetWidth(vtkFloatingPointType theWidth)
242 myGlobalScalarBar->SetWidth(theWidth);
243 myLocalScalarBar->SetWidth(theWidth);
250 return myGlobalScalarBar->GetWidth();
254 //----------------------------------------------------------------------------
257 ::SetHeight(vtkFloatingPointType theHeight)
259 myGlobalScalarBar->SetHeight(theHeight);
260 myLocalScalarBar->SetHeight(theHeight);
268 return myGlobalScalarBar->GetHeight();
272 //----------------------------------------------------------------------------
275 ::SetPosition(const vtkFloatingPointType* thePosition)
277 myPosition[0] = thePosition[0];
278 myPosition[1] = thePosition[1];
281 const vtkFloatingPointType*
282 VISU_ScalarBarCtrl::GetPosition() const
288 //----------------------------------------------------------------------------
291 ::SetSpacing(const vtkFloatingPointType theSpacing)
293 myDistance = theSpacing;
304 //----------------------------------------------------------------------------
307 ::SetBicolor(const bool theBicolor)
309 myBicolor = theBicolor;
320 //----------------------------------------------------------------------------
323 ::SetMarkValue(const vtkFloatingPointType theValue)
325 myMarkedValue = theValue;
330 ::GetMarkValue() const
332 return myMarkedValue;
336 //----------------------------------------------------------------------------
339 ::SetIsMarked(const bool theFlag)
346 ::GetIsMarked() const
352 //----------------------------------------------------------------------------
357 SetVisibility(GetVisibility());
370 //----------------------------------------------------------------------------
376 if(myMode == eGlobal){
377 myGlobalLookupTable->MarkValueByColor( myMarkedValue, myBlack );
379 myLocalLookupTable->MarkValueByColor( myMarkedValue, myBlack );
382 if(myGlobalRangeIsDefined){
383 vtkFloatingPointType aLocalRange[2];
384 myLocalLookupTable->GetTableRange(aLocalRange);
385 myGlobalLookupTable->MarkValueByColor( aLocalRange[0], myBlack );
386 myGlobalLookupTable->MarkValueByColor( aLocalRange[1], myBlack );
391 //----------------------------------------------------------------------------
394 ::PrepareTables(VISU_ScalarBarActor* theScalarBarActor,
395 VISU_LookupTable *theLookupTable,
398 vtkCoordinate * aCoordinate = theScalarBarActor->GetPositionCoordinate();
399 aCoordinate->SetCoordinateSystemToNormalizedViewport();
400 if(theScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL){
401 vtkFloatingPointType aWidth = theScalarBarActor->GetWidth();
402 aCoordinate->SetValue(myPosition[0]+theId*(aWidth+myDistance), myPosition[1]);
404 vtkFloatingPointType aHeight = theScalarBarActor->GetHeight();
405 aCoordinate->SetValue(myPosition[0], myPosition[1]+theId*(aHeight+myDistance));
407 // Initialize Lookup Tables and Scalar Bars
408 theLookupTable->Modified();
409 theLookupTable->Build();
417 if(myMode != eSimple){
418 PrepareTables(myGlobalScalarBar,myGlobalLookupTable,0);
419 PrepareTables(myLocalScalarBar,myLocalLookupTable,1);
421 PrepareTables(myLocalScalarBar,myLocalLookupTable,0);
426 //----------------------------------------------------------------------------
431 if(myMode == eGlobal){
432 myLocalLookupTable->FillByColor( myGrey );
433 }else if(myMode == eLocal){
434 myGlobalLookupTable->FillByColor( myGrey );
439 //----------------------------------------------------------------------------
444 myLocalLookupTable->Modified();
445 myLocalLookupTable->Build();
447 if(myMode == eSimple){
448 myLocalLookupTable->MakeBiColor();
452 if(myMode == eGlobal){
453 myGlobalLookupTable->MakeBiColor();
454 myLocalLookupTable->FillByColor( myGrey );
455 }else if(myMode == eLocal){
456 myLocalLookupTable->MakeBiColor();
457 myGlobalLookupTable->FillByColor( myGrey );