1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_ScalarMap_i.hh"
29 #include "VISU_Result_i.hh"
30 #include "VISU_ViewManager_i.hh"
32 #include "VISU_ScalarMapAct.h"
33 #include "VISU_ScalarMapPL.hxx"
34 #include "VISU_Convertor.hxx"
36 #include "SUIT_ResourceMgr.h"
38 #include <vtkDataSetMapper.h>
39 #include <vtkTextProperty.h>
45 static int MYDEBUG = 0;
47 static int MYDEBUG = 0;
50 static int INCMEMORY = 4;
53 //============================================================================
56 ::IsPossible(Result_i* theResult,
57 const char* theMeshName,
58 VISU::Entity theEntity,
59 const char* theFieldName, int theIteration, int isMemoryCheck)
62 float aSize = INCMEMORY*
63 theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration);
66 aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
67 MESSAGE("ScalarMap_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
70 }catch(std::exception& exc){
71 INFOS("Follow exception was occured :\n"<<exc.what());
73 INFOS("Unknown exception was occured!");
78 //----------------------------------------------------------------------------
87 return VISU::GenerateName("ScalarMap",myNbPresent++);
92 ::myComment = "SCALARMAP";
96 ::GetComment() const {
97 return myComment.c_str();
101 //----------------------------------------------------------------------------
103 ScalarMap_i(Result_i* theResult,
104 bool theAddToStudy) :
105 PrsObject_i(theResult->GetStudyDocument()),
106 Prs3d_i(theResult,theAddToStudy),
107 ColoredPrs3d_i(theResult,theAddToStudy)
111 ScalarMap_i(Result_i* theResult,
112 SALOMEDS::SObject_ptr theSObject) :
113 PrsObject_i(theResult->GetStudyDocument()),
114 Prs3d_i(theResult,theSObject),
115 ColoredPrs3d_i(theResult,theSObject)
123 //----------------------------------------------------------------------------
126 ::SameAs(const Prs3d_i* theOrigin)
128 TSuperClass::SameAs(theOrigin);
130 if(const ScalarMap_i* aPrs3d = dynamic_cast<const ScalarMap_i*>(theOrigin)){
131 ScalarMap_i* anOrigin = const_cast<ScalarMap_i*>(aPrs3d);
133 SetRange(anOrigin->GetMin(), anOrigin->GetMax());
134 myIsFixedRange = anOrigin->IsRangeFixed();
136 SetScaling(anOrigin->GetScaling());
143 //----------------------------------------------------------------------------
145 * Creates Scalar Map and initialises it from resources
149 ::Create(const char* theMeshName,
150 VISU::Entity theEntity,
151 const char* theFieldName,
154 TSuperClass::Create(theMeshName,theEntity,theFieldName,theIteration);
156 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
159 int aRangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0);
160 myIsFixedRange = (aRangeType == 1) ? true : false;
163 float aMin = aResourceMgr->doubleValue("VISU", "scalar_range_min", 0);
164 float aMax = aResourceMgr->doubleValue("VISU", "scalar_range_max", 0);
168 bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false);
171 SetScaling(VISU::LOGARITHMIC);
173 SetScaling(VISU::LINEAR);
180 ::Restore(const Storable::TRestoringMap& theMap)
182 TSuperClass::Restore(theMap);
184 SetScaling(VISU::Scaling(VISU::Storable::FindValue(theMap,"myScaling").toInt()));
186 float aMin = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble();
187 float aMax = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble();
190 myIsFixedRange = VISU::Storable::FindValue(theMap,"myIsFixedRange").toInt();
197 ::ToStream(std::ostringstream& theStr)
199 TSuperClass::ToStream(theStr);
201 Storable::DataToStream( theStr, "myScalarRange[0]", GetMin() );
202 Storable::DataToStream( theStr, "myScalarRange[1]", GetMax() );
203 Storable::DataToStream( theStr, "myIsFixedRange", myIsFixedRange );
204 Storable::DataToStream( theStr, "myScaling", GetScaling() );
208 //----------------------------------------------------------------------------
211 ::SetBarOrientation(VISU::ScalarMap::Orientation theOrientation)
213 TSuperClass::SetBarOrientation(theOrientation);
216 VISU::ScalarMap::Orientation
218 ::GetBarOrientation()
220 return TSuperClass::GetBarOrientation();
227 return VISU::Scaling(myScalarMapPL->GetScaling());
232 ::SetScaling(VISU::Scaling theScaling)
234 myScalarMapPL->SetScaling(theScaling);
239 ::SetRange(CORBA::Double theMin, CORBA::Double theMax)
243 float aScalarRange[2] = {theMin, theMax};
244 myScalarMapPL->SetScalarRange(aScalarRange);
245 myIsFixedRange = true;
249 //----------------------------------------------------------------------------
252 ::DoSetInput(Result_i* theResult)
254 VISU::Result_i::TInput* anInput = theResult->GetInput();
256 throw std::runtime_error("Mesh_i::Build - theResult->GetInput() == NULL !!!");
258 myField = anInput->GetField(myMeshName,myEntity,myFieldName);
260 throw std::runtime_error("There is no Field with the parameters !!!");
262 VISU::PIDMapper anIDMapper =
263 anInput->GetTimeStampOnMesh(myMeshName,myEntity,myFieldName,myIteration);
266 throw std::runtime_error("There is no TimeStamp with the parameters !!!");
268 myScalarMapPL->SetIDMapper(anIDMapper);
269 myScalarMapPL->Init();
270 myScalarMapPL->Build();
277 TSuperClass::Update();
281 //----------------------------------------------------------------------------
284 ::SetMapScale(double theMapScale)
286 myScalarMapPL->SetMapScale(theMapScale);
293 return myIsFixedRange;
300 myScalarMapPL->SetSourceRange();
301 myIsFixedRange = false;
304 //----------------------------------------------------------------------------
307 ::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
309 VISU_ScalarMapAct* anActor = VISU_ScalarMapAct::New();
311 TSuperClass::CreateActor(anActor,theIO);
312 anActor->SetBarVisibility(true);
313 anActor->SetRepresentation(2);
314 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
315 bool toUseShading = aResourceMgr->booleanValue("VISU", "represent_shading", false);
316 anActor->SetShading(toUseShading);
317 UpdateActor(anActor);
327 ::UpdateActor(VISU_Actor* theActor)
329 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
330 VISU_ScalarBarActor *aScalarBar = anActor->GetScalarBar();
331 aScalarBar->SetLookupTable(myScalarMapPL->GetBarTable());
332 aScalarBar->SetTitle(myTitle.c_str());
333 aScalarBar->SetOrientation(myOrientation);
334 aScalarBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
335 aScalarBar->GetPositionCoordinate()->SetValue(myPosition[0],myPosition[1]);
336 aScalarBar->SetWidth(myWidth);
337 aScalarBar->SetHeight(myHeight);
338 aScalarBar->SetNumberOfLabels(myNumberOfLabels);
340 vtkTextProperty* aTitleProp = aScalarBar->GetTitleTextProperty();
341 aTitleProp->SetFontFamily(myTitFontType);
342 aTitleProp->SetColor(myTitleColor);
343 (myIsBoldTitle)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
344 (myIsItalicTitle)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
345 (myIsShadowTitle)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
347 vtkTextProperty* aLabelProp = aScalarBar->GetLabelTextProperty();
348 aLabelProp->SetFontFamily(myLblFontType);
349 aLabelProp->SetColor(myLabelColor);
350 (myIsBoldLabel)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
351 (myIsItalicLabel)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
352 (myIsShadowLabel)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
354 aScalarBar->Modified();
356 TSuperClass::UpdateActor(theActor);