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_ScalarMapPL.hxx"
33 #include "VISU_ScalarMapAct.h"
35 #include "SUIT_ResourceMgr.h"
37 #include <vtkDataSetMapper.h>
38 #include <vtkTextProperty.h>
44 static int MYDEBUG = 0;
46 static int MYDEBUG = 0;
49 static int INCMEMORY = 4;
51 int VISU::ScalarMap_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
52 const char* theFieldName, int theIteration, int isMemoryCheck)
55 float aSize = INCMEMORY*
56 theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration);
59 aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
60 MESSAGE("ScalarMap_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
63 }catch(std::exception& exc){
64 INFOS("Follow exception was occured :\n"<<exc.what());
66 INFOS("Unknown exception was occured!");
71 int VISU::ScalarMap_i::myNbPresent = 0;
72 QString VISU::ScalarMap_i::GenerateName() { return VISU::GenerateName("ScalarMap",myNbPresent++);}
74 const string VISU::ScalarMap_i::myComment = "SCALARMAP";
75 const char* VISU::ScalarMap_i::GetComment() const { return myComment.c_str();}
77 ScalarMap_i(Result_i* theResult,
79 PrsObject_i(theResult->GetStudyDocument()),
80 Prs3d_i(theResult,theAddToStudy),
87 ScalarMap_i(Result_i* theResult,
88 SALOMEDS::SObject_ptr theSObject) :
89 PrsObject_i(theResult->GetStudyDocument()),
90 Prs3d_i(theResult,theSObject),
96 void VISU::ScalarMap_i::RemoveFromStudy()
98 VISU::DeleteActors(this);
99 VISU::RemoveFromStudy(mySObject,false);
103 void VISU::ScalarMap_i::SameAs(const ScalarMap_i* theOrigin)
105 ScalarMap_i* aScalarMap = const_cast<ScalarMap_i*>(theOrigin);
107 VISU::Prs3d_i::SameAs(aScalarMap);
108 myField = aScalarMap->GetField();
109 myMeshName = myField->myMeshName;
110 myEntity = myField->myEntity;
111 myIteration = aScalarMap->GetIteration();
112 myFieldName = aScalarMap->GetFieldName();
114 SetScalarMode(aScalarMap->GetScalarMode());
116 SetRange(aScalarMap->GetMin(), aScalarMap->GetMax());
117 myIsFixedRange = aScalarMap->IsRangeFixed();
119 SetScaling(aScalarMap->GetScaling());
121 SetBarOrientation(aScalarMap->GetBarOrientation());
122 SetPosition(aScalarMap->GetPosX(), aScalarMap->GetPosY());
123 SetSize(aScalarMap->GetWidth(), aScalarMap->GetHeight());
124 SetNbColors(aScalarMap->GetNbColors());
125 SetLabels(aScalarMap->GetLabels());
126 SetTitle(aScalarMap->GetTitle());
128 SetBoldTitle(aScalarMap->IsBoldTitle());
129 SetItalicTitle(aScalarMap->IsItalicTitle());
130 SetShadowTitle(aScalarMap->IsShadowTitle());
131 SetTitFontType(aScalarMap->GetTitFontType());
133 aScalarMap->GetTitleColor(&r,&g,&b);
134 SetTitleColor(r,g,b);
136 SetBoldLabel(aScalarMap->IsBoldLabel());
137 SetItalicLabel(aScalarMap->IsItalicLabel());
138 SetShadowLabel(aScalarMap->IsShadowLabel());
139 SetLblFontType(aScalarMap->GetLblFontType());
140 aScalarMap->GetLabelColor(&r,&g,&b);
141 SetLabelColor(r,g,b);
149 * Creates Scalar Map and initialises it from resources
151 VISU::Storable* VISU::ScalarMap_i::Create(const char* theMeshName, VISU::Entity theEntity,
152 const char* theFieldName, int theIteration)
156 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
158 int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
159 SetScalarMode(aScalarMode);
162 int orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", 0);
164 myOrientation = VISU::ScalarMap::HORIZONTAL;
166 myOrientation = VISU::ScalarMap::VERTICAL;
169 QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
171 float aXorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.01 : 0.2;
172 aXorigin = aResourceMgr->doubleValue("VISU", propertyName + "x", aXorigin);
173 myPosition[0] = aXorigin;
175 float aYorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.1 : 0.012;
176 aYorigin = aResourceMgr->doubleValue("VISU", propertyName + "y", aYorigin);
177 myPosition[1] = aYorigin;
180 myWidth = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.1 : 0.6;
181 myWidth = aResourceMgr->doubleValue("VISU", propertyName + "width", myWidth);
183 myHeight = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12;
184 myHeight = aResourceMgr->doubleValue("VISU", propertyName + "height", myHeight);
187 int aNumberOfColors = aResourceMgr->integerValue( "VISU", "scalar_bar_num_colors", 64 );
188 SetNbColors(aNumberOfColors);
191 myNumberOfLabels = aResourceMgr->integerValue( "VISU", "scalar_bar_num_labels", 5 );
194 int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0);
195 myIsFixedRange = (rangeType == 1) ? true : false;
199 float aMin = aResourceMgr->doubleValue("VISU", "scalar_range_min", 0);
200 float aMax = aResourceMgr->doubleValue("VISU", "scalar_range_max", 0);
204 bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false);
207 SetScaling(VISU::LOGARITHMIC);
209 SetScaling(VISU::LINEAR);
211 // Fonts properties definition
212 myIsBoldTitle = myIsItalicTitle = myIsShadowTitle = true;
213 myTitFontType = VTK_ARIAL;
215 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) )
217 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" );
219 if ( f.family() == "Arial" )
220 myTitFontType = VTK_ARIAL;
221 else if ( f.family() == "Courier" )
222 myTitFontType = VTK_COURIER;
223 else if ( f.family() == "Times" )
224 myTitFontType = VTK_TIMES;
226 myIsBoldTitle = f.bold();
227 myIsItalicTitle = f.italic();
228 myIsShadowTitle = f.underline();
231 QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
233 myTitleColor[0] = aTextColor.red() / 255;
234 myTitleColor[1] = aTextColor.green() / 255;
235 myTitleColor[2] = aTextColor.blue() / 255;
239 myIsBoldLabel = myIsItalicLabel = myIsShadowLabel = true;
240 myLblFontType = VTK_ARIAL;
242 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) )
244 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" );
246 if ( f.family() == "Arial" )
247 myLblFontType = VTK_ARIAL;
248 else if ( f.family() == "Courier" )
249 myLblFontType = VTK_COURIER;
250 else if ( f.family() == "Times" )
251 myLblFontType = VTK_TIMES;
253 myIsBoldLabel = f.bold();
254 myIsItalicLabel = f.italic();
255 myIsShadowLabel = f.underline();
258 QColor aLabelColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
260 myLabelColor[0] = aLabelColor.red() / 255;
261 myLabelColor[1] = aLabelColor.green() / 255;
262 myLabelColor[2] = aLabelColor.blue() / 255;
265 myMeshName = theMeshName;
266 myEntity = (VISU::TEntity)theEntity;
267 myFieldName =theFieldName;
268 myIteration = theIteration;
274 VISU::Storable* VISU::ScalarMap_i::Restore(const Storable::TRestoringMap& theMap)
277 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
278 myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
279 myFieldName = VISU::Storable::FindValue(theMap,"myFieldName").latin1();
280 myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt();
282 SetScalarMode(VISU::Storable::FindValue(theMap,"myScalarMode").toInt());
283 SetScaling(VISU::Scaling(VISU::Storable::FindValue(theMap,"myScaling").toInt()));
284 float aMin = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble();
285 float aMax = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble();
287 myIsFixedRange = VISU::Storable::FindValue(theMap,"myIsFixedRange").toInt();
289 myTitle = VISU::Storable::FindValue(theMap,"myTitle").latin1();
290 myOrientation = (VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt();
291 SetNbColors(VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt());
292 myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt();
293 myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
294 myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
295 myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble();
296 myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble();
298 myTitFontType = VISU::Storable::FindValue(theMap,"myTitFontType").toInt();
299 myIsBoldTitle = VISU::Storable::FindValue(theMap,"myIsBoldTitle").toInt();
300 myIsItalicTitle = VISU::Storable::FindValue(theMap,"myIsItalicTitle").toInt();
301 myIsShadowTitle = VISU::Storable::FindValue(theMap,"myIsShadowTitle").toInt();
302 myTitleColor[0] = VISU::Storable::FindValue(theMap,"myTitleColor[0]").toFloat();
303 myTitleColor[1] = VISU::Storable::FindValue(theMap,"myTitleColor[1]").toFloat();
304 myTitleColor[2] = VISU::Storable::FindValue(theMap,"myTitleColor[2]").toFloat();
306 myLblFontType = VISU::Storable::FindValue(theMap,"myLblFontType").toInt();
307 myIsBoldLabel = VISU::Storable::FindValue(theMap,"myIsBoldLabel").toInt();
308 myIsItalicLabel = VISU::Storable::FindValue(theMap,"myIsItalicLabel").toInt();
309 myIsShadowLabel = VISU::Storable::FindValue(theMap,"myIsShadowLabel").toInt();
310 myLabelColor[0] = VISU::Storable::FindValue(theMap,"myLabelColor[0]").toFloat();
311 myLabelColor[1] = VISU::Storable::FindValue(theMap,"myLabelColor[1]").toFloat();
312 myLabelColor[2] = VISU::Storable::FindValue(theMap,"myLabelColor[2]").toFloat();
314 Prs3d_i::Restore(theMap);
315 myAddToStudy = false; //SRN Added 21/06/2003 SAL2983: to avoid addition of the new ScalarMap to study.
320 void VISU::ScalarMap_i::ToStream(std::ostringstream& theStr){
321 Prs3d_i::ToStream(theStr);
323 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
324 Storable::DataToStream( theStr, "myEntity", myEntity );
325 Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() );
326 Storable::DataToStream( theStr, "myIteration", myIteration );
328 Storable::DataToStream( theStr, "myScalarMode", int(GetScalarMode()) );
329 Storable::DataToStream( theStr, "myScalarRange[0]", GetMin() );
330 Storable::DataToStream( theStr, "myScalarRange[1]", GetMax() );
331 Storable::DataToStream( theStr, "myIsFixedRange", myIsFixedRange );
332 Storable::DataToStream( theStr, "myScaling", GetScaling() );
334 Storable::DataToStream( theStr, "myTitle", myTitle.c_str() );
335 Storable::DataToStream( theStr, "myOrientation", myOrientation );
336 Storable::DataToStream( theStr, "myNumberOfColors", int(GetNbColors()) );
337 Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels );
338 Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] );
339 Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] );
340 Storable::DataToStream( theStr, "myWidth", myWidth );
341 Storable::DataToStream( theStr, "myHeight", myHeight );
343 Storable::DataToStream( theStr, "myTitFontType", myTitFontType );
344 Storable::DataToStream( theStr, "myIsBoldTitle", myIsBoldTitle );
345 Storable::DataToStream( theStr, "myIsItalicTitle", myIsItalicTitle );
346 Storable::DataToStream( theStr, "myIsShadowTitle", myIsShadowTitle );
347 Storable::DataToStream( theStr, "myTitleColor[0]", myTitleColor[0] );
348 Storable::DataToStream( theStr, "myTitleColor[1]", myTitleColor[1] );
349 Storable::DataToStream( theStr, "myTitleColor[2]", myTitleColor[2] );
351 Storable::DataToStream( theStr, "myLblFontType", myLblFontType );
352 Storable::DataToStream( theStr, "myIsBoldLabel", myIsBoldLabel );
353 Storable::DataToStream( theStr, "myIsItalicLabel", myIsItalicLabel );
354 Storable::DataToStream( theStr, "myIsShadowLabel", myIsShadowLabel );
355 Storable::DataToStream( theStr, "myLabelColor[0]", myLabelColor[0] );
356 Storable::DataToStream( theStr, "myLabelColor[1]", myLabelColor[1] );
357 Storable::DataToStream( theStr, "myLabelColor[2]", myLabelColor[2] );
361 CORBA::Long VISU::ScalarMap_i::GetScalarMode(){
362 return myScalarMapPL->GetScalarMode();
364 void VISU::ScalarMap_i::SetScalarMode(CORBA::Long theScalarMode) {
365 myScalarMapPL->SetScalarMode(theScalarMode);
369 VISU::Scaling VISU::ScalarMap_i::GetScaling(){
370 return VISU::Scaling(myScalarMapPL->GetScaling());
372 void VISU::ScalarMap_i::SetScaling(VISU::Scaling theScaling){
373 myScalarMapPL->SetScaling(theScaling);
377 void VISU::ScalarMap_i::SetRange(CORBA::Double theMin, CORBA::Double theMax){
378 if(theMin > theMax) return;
379 float aScalarRange[2] = {theMin, theMax};
380 myScalarMapPL->SetScalarRange(aScalarRange);
381 myIsFixedRange = true;
384 CORBA::Double VISU::ScalarMap_i::GetMin(){
385 return myScalarMapPL->GetScalarRange()[0];
388 CORBA::Double VISU::ScalarMap_i::GetMax(){
389 return myScalarMapPL->GetScalarRange()[1];
393 void VISU::ScalarMap_i::SetNbColors(CORBA::Long theNbColors){
394 myScalarMapPL->SetNbColors(theNbColors);
397 CORBA::Long VISU::ScalarMap_i::GetNbColors(){
398 return myScalarMapPL->GetNbColors();
402 VISU::ScalarMap_i::~ScalarMap_i(){}
405 VISU::Storable* VISU::ScalarMap_i::Build(int theRestoring){
407 MESSAGE("ScalarMap_i::Build - "<<myFieldName<<"; theRestoring = "<<theRestoring);
408 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
409 if(myAddToStudy) aStudyBuilder->NewCommand(); // There is a transaction
411 if(myResult->GetInput() == NULL)
412 throw std::runtime_error("Mesh_i::Build - myResult->GetInput() == NULL !!!");
413 myField = myResult->GetInput()->GetField(myMeshName,myEntity,myFieldName);
414 if(myField == NULL) throw std::runtime_error("There is no Field with the parameters !!!");
415 VISU_Convertor::TOutput *anOutput =
416 myResult->GetInput()->GetTimeStampOnMesh(myMeshName,myEntity,myFieldName,myIteration);
417 if(anOutput == NULL) throw std::runtime_error("There is no TimeStamp with the parameters !!!");
418 myScalarMapPL->SetInput(anOutput);
419 myScalarMapPL->Build();
422 if(theRestoring <= 0){
423 if(theRestoring == 0) myScalarMapPL->Init();
424 if(!myIsFixedRange) myScalarMapPL->SetSourceRange();
425 const VISU::TValField& aValField = myField->myValField;
426 const VISU::PValForTime aValForTime = aValField.find(myIteration)->second;
427 aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime->myTime).c_str());
428 if (theRestoring == 0) myTitle = aComment.simplifyWhiteSpace().latin1();
431 myName = GenerateName().latin1();
432 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
433 VISU::TTIMESTAMP,myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp);
434 string aResultEntry = myResult->GetEntry();
435 string aRefFatherEntry = myResult->GetRefFatherEntry();
436 string anEntry = myResult->GetEntry(aComment.latin1());
437 if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!");
438 aComment.sprintf("myComment=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
439 GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp);
440 CORBA::String_var anIOR = GetID();
441 CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),anIOR,myName.c_str(),"",aComment.latin1(),true);
442 mySObject = myStudy->FindObjectIOR(anIOR);
444 }catch(std::exception& exc){
445 INFOS("Follow exception was occured :\n"<<exc.what());
448 INFOS("Unknown exception was occured!");
451 if(myAddToStudy) aStudyBuilder->CommitCommand();
456 void VISU::ScalarMap_i::DoHook(){
457 if(MYDEBUG) MESSAGE("ScalarMap_i::DoHook() - "<<myPipeLine);
459 myPipeLine = VISU_ScalarMapPL::New();
460 myPipeLine->GetMapper()->SetScalarVisibility(1);
462 myScalarMapPL = dynamic_cast<VISU_ScalarMapPL*>(myPipeLine);
465 void VISU::ScalarMap_i::Update() {
466 VISU::Prs3d_i::Update();
469 void VISU::ScalarMap_i::SetMapScale(double theMapScale){
470 myScalarMapPL->SetMapScale(theMapScale);
473 VISU_Actor* VISU::ScalarMap_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
475 VISU_ScalarMapAct* anActor = VISU_ScalarMapAct::New();
477 VISU::Prs3d_i::CreateActor(anActor,theIO);
478 anActor->SetBarVisibility(true);
479 anActor->SetRepresentation(2);
480 UpdateActor(anActor);
483 throw std::runtime_error("CreateActor error");
488 void VISU::ScalarMap_i::UpdateActor(VISU_Actor* theActor) {
489 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
490 VISU::Prs3d_i::UpdateActor(theActor);
491 VISU_ScalarBarActor *aScalarBar = anActor->GetScalarBar();
492 aScalarBar->SetLookupTable(myScalarMapPL->GetBarTable());
493 aScalarBar->SetTitle(myTitle.c_str());
494 aScalarBar->SetOrientation(myOrientation);
495 aScalarBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
496 aScalarBar->GetPositionCoordinate()->SetValue(myPosition[0],myPosition[1]);
497 aScalarBar->SetWidth(myWidth);
498 aScalarBar->SetHeight(myHeight);
499 aScalarBar->SetNumberOfLabels(myNumberOfLabels);
501 vtkTextProperty* aTitleProp = aScalarBar->GetTitleTextProperty();
502 aTitleProp->SetFontFamily(myTitFontType);
503 aTitleProp->SetColor(myTitleColor);
504 (myIsBoldTitle)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
505 (myIsItalicTitle)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
506 (myIsShadowTitle)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
508 vtkTextProperty* aLabelProp = aScalarBar->GetLabelTextProperty();
509 aLabelProp->SetFontFamily(myLblFontType);
510 aLabelProp->SetColor(myLabelColor);
511 (myIsBoldLabel)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
512 (myIsItalicLabel)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
513 (myIsShadowLabel)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
515 aScalarBar->Modified();
520 void VISU::ScalarMap_i::SetSourceRange(){
521 myScalarMapPL->SetSourceRange();
522 myIsFixedRange = false;