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);
147 void VISU::ScalarMap_i::SameAsParams (const ScalarMap_i* theOrigin)
149 int time = GetIteration();
160 * Creates Scalar Map and initialises it from resources
162 VISU::Storable* VISU::ScalarMap_i::Create(const char* theMeshName, VISU::Entity theEntity,
163 const char* theFieldName, int theIteration)
167 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
169 int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
170 SetScalarMode(aScalarMode);
173 int orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", 0);
175 myOrientation = VISU::ScalarMap::HORIZONTAL;
177 myOrientation = VISU::ScalarMap::VERTICAL;
180 QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
182 float aXorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.01 : 0.2;
183 aXorigin = aResourceMgr->doubleValue("VISU", propertyName + "x", aXorigin);
184 myPosition[0] = aXorigin;
186 float aYorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.1 : 0.012;
187 aYorigin = aResourceMgr->doubleValue("VISU", propertyName + "y", aYorigin);
188 myPosition[1] = aYorigin;
191 myWidth = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.1 : 0.6;
192 myWidth = aResourceMgr->doubleValue("VISU", propertyName + "width", myWidth);
194 myHeight = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12;
195 myHeight = aResourceMgr->doubleValue("VISU", propertyName + "height", myHeight);
198 int aNumberOfColors = aResourceMgr->integerValue( "VISU", "scalar_bar_num_colors", 64 );
199 SetNbColors(aNumberOfColors);
202 myNumberOfLabels = aResourceMgr->integerValue( "VISU", "scalar_bar_num_labels", 5 );
205 int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0);
206 myIsFixedRange = (rangeType == 1) ? true : false;
210 float aMin = aResourceMgr->doubleValue("VISU", "scalar_range_min", 0);
211 float aMax = aResourceMgr->doubleValue("VISU", "scalar_range_max", 0);
215 bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false);
218 SetScaling(VISU::LOGARITHMIC);
220 SetScaling(VISU::LINEAR);
222 // Fonts properties definition
223 myIsBoldTitle = myIsItalicTitle = myIsShadowTitle = true;
224 myTitFontType = VTK_ARIAL;
226 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) )
228 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" );
230 if ( f.family() == "Arial" )
231 myTitFontType = VTK_ARIAL;
232 else if ( f.family() == "Courier" )
233 myTitFontType = VTK_COURIER;
234 else if ( f.family() == "Times" )
235 myTitFontType = VTK_TIMES;
237 myIsBoldTitle = f.bold();
238 myIsItalicTitle = f.italic();
239 myIsShadowTitle = f.underline();
242 QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
244 myTitleColor[0] = aTextColor.red() / 255;
245 myTitleColor[1] = aTextColor.green() / 255;
246 myTitleColor[2] = aTextColor.blue() / 255;
250 myIsBoldLabel = myIsItalicLabel = myIsShadowLabel = true;
251 myLblFontType = VTK_ARIAL;
253 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) )
255 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" );
257 if ( f.family() == "Arial" )
258 myLblFontType = VTK_ARIAL;
259 else if ( f.family() == "Courier" )
260 myLblFontType = VTK_COURIER;
261 else if ( f.family() == "Times" )
262 myLblFontType = VTK_TIMES;
264 myIsBoldLabel = f.bold();
265 myIsItalicLabel = f.italic();
266 myIsShadowLabel = f.underline();
269 QColor aLabelColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
271 myLabelColor[0] = aLabelColor.red() / 255;
272 myLabelColor[1] = aLabelColor.green() / 255;
273 myLabelColor[2] = aLabelColor.blue() / 255;
276 myMeshName = theMeshName;
277 myEntity = (VISU::TEntity)theEntity;
278 myFieldName =theFieldName;
279 myIteration = theIteration;
285 VISU::Storable* VISU::ScalarMap_i::Restore(const Storable::TRestoringMap& theMap)
288 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
289 myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
290 myFieldName = VISU::Storable::FindValue(theMap,"myFieldName").latin1();
291 myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt();
293 SetScalarMode(VISU::Storable::FindValue(theMap,"myScalarMode").toInt());
294 SetScaling(VISU::Scaling(VISU::Storable::FindValue(theMap,"myScaling").toInt()));
295 float aMin = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble();
296 float aMax = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble();
298 myIsFixedRange = VISU::Storable::FindValue(theMap,"myIsFixedRange").toInt();
300 myTitle = VISU::Storable::FindValue(theMap,"myTitle").latin1();
301 myOrientation = (VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt();
302 SetNbColors(VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt());
303 myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt();
304 myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
305 myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
306 myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble();
307 myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble();
309 myTitFontType = VISU::Storable::FindValue(theMap,"myTitFontType").toInt();
310 myIsBoldTitle = VISU::Storable::FindValue(theMap,"myIsBoldTitle").toInt();
311 myIsItalicTitle = VISU::Storable::FindValue(theMap,"myIsItalicTitle").toInt();
312 myIsShadowTitle = VISU::Storable::FindValue(theMap,"myIsShadowTitle").toInt();
313 myTitleColor[0] = VISU::Storable::FindValue(theMap,"myTitleColor[0]").toFloat();
314 myTitleColor[1] = VISU::Storable::FindValue(theMap,"myTitleColor[1]").toFloat();
315 myTitleColor[2] = VISU::Storable::FindValue(theMap,"myTitleColor[2]").toFloat();
317 myLblFontType = VISU::Storable::FindValue(theMap,"myLblFontType").toInt();
318 myIsBoldLabel = VISU::Storable::FindValue(theMap,"myIsBoldLabel").toInt();
319 myIsItalicLabel = VISU::Storable::FindValue(theMap,"myIsItalicLabel").toInt();
320 myIsShadowLabel = VISU::Storable::FindValue(theMap,"myIsShadowLabel").toInt();
321 myLabelColor[0] = VISU::Storable::FindValue(theMap,"myLabelColor[0]").toFloat();
322 myLabelColor[1] = VISU::Storable::FindValue(theMap,"myLabelColor[1]").toFloat();
323 myLabelColor[2] = VISU::Storable::FindValue(theMap,"myLabelColor[2]").toFloat();
325 Prs3d_i::Restore(theMap);
326 myAddToStudy = false; //SRN Added 21/06/2003 SAL2983: to avoid addition of the new ScalarMap to study.
331 void VISU::ScalarMap_i::ToStream(std::ostringstream& theStr){
332 Prs3d_i::ToStream(theStr);
334 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
335 Storable::DataToStream( theStr, "myEntity", myEntity );
336 Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() );
337 Storable::DataToStream( theStr, "myIteration", myIteration );
339 Storable::DataToStream( theStr, "myScalarMode", int(GetScalarMode()) );
340 Storable::DataToStream( theStr, "myScalarRange[0]", GetMin() );
341 Storable::DataToStream( theStr, "myScalarRange[1]", GetMax() );
342 Storable::DataToStream( theStr, "myIsFixedRange", myIsFixedRange );
343 Storable::DataToStream( theStr, "myScaling", GetScaling() );
345 Storable::DataToStream( theStr, "myTitle", myTitle.c_str() );
346 Storable::DataToStream( theStr, "myOrientation", myOrientation );
347 Storable::DataToStream( theStr, "myNumberOfColors", int(GetNbColors()) );
348 Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels );
349 Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] );
350 Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] );
351 Storable::DataToStream( theStr, "myWidth", myWidth );
352 Storable::DataToStream( theStr, "myHeight", myHeight );
354 Storable::DataToStream( theStr, "myTitFontType", myTitFontType );
355 Storable::DataToStream( theStr, "myIsBoldTitle", myIsBoldTitle );
356 Storable::DataToStream( theStr, "myIsItalicTitle", myIsItalicTitle );
357 Storable::DataToStream( theStr, "myIsShadowTitle", myIsShadowTitle );
358 Storable::DataToStream( theStr, "myTitleColor[0]", myTitleColor[0] );
359 Storable::DataToStream( theStr, "myTitleColor[1]", myTitleColor[1] );
360 Storable::DataToStream( theStr, "myTitleColor[2]", myTitleColor[2] );
362 Storable::DataToStream( theStr, "myLblFontType", myLblFontType );
363 Storable::DataToStream( theStr, "myIsBoldLabel", myIsBoldLabel );
364 Storable::DataToStream( theStr, "myIsItalicLabel", myIsItalicLabel );
365 Storable::DataToStream( theStr, "myIsShadowLabel", myIsShadowLabel );
366 Storable::DataToStream( theStr, "myLabelColor[0]", myLabelColor[0] );
367 Storable::DataToStream( theStr, "myLabelColor[1]", myLabelColor[1] );
368 Storable::DataToStream( theStr, "myLabelColor[2]", myLabelColor[2] );
372 CORBA::Long VISU::ScalarMap_i::GetScalarMode(){
373 return myScalarMapPL->GetScalarMode();
375 void VISU::ScalarMap_i::SetScalarMode(CORBA::Long theScalarMode) {
376 myScalarMapPL->SetScalarMode(theScalarMode);
380 VISU::Scaling VISU::ScalarMap_i::GetScaling(){
381 return VISU::Scaling(myScalarMapPL->GetScaling());
383 void VISU::ScalarMap_i::SetScaling(VISU::Scaling theScaling){
384 myScalarMapPL->SetScaling(theScaling);
388 void VISU::ScalarMap_i::SetRange(CORBA::Double theMin, CORBA::Double theMax){
389 if(theMin > theMax) return;
390 float aScalarRange[2] = {theMin, theMax};
391 myScalarMapPL->SetScalarRange(aScalarRange);
392 myIsFixedRange = true;
395 CORBA::Double VISU::ScalarMap_i::GetMin(){
396 return myScalarMapPL->GetScalarRange()[0];
399 CORBA::Double VISU::ScalarMap_i::GetMax(){
400 return myScalarMapPL->GetScalarRange()[1];
404 void VISU::ScalarMap_i::SetNbColors(CORBA::Long theNbColors){
405 myScalarMapPL->SetNbColors(theNbColors);
408 CORBA::Long VISU::ScalarMap_i::GetNbColors(){
409 return myScalarMapPL->GetNbColors();
413 VISU::ScalarMap_i::~ScalarMap_i(){}
416 VISU::Storable* VISU::ScalarMap_i::Build(int theRestoring){
418 MESSAGE("ScalarMap_i::Build - "<<myFieldName<<"; theRestoring = "<<theRestoring);
419 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
420 if(myAddToStudy) aStudyBuilder->NewCommand(); // There is a transaction
422 if(myResult->GetInput() == NULL)
423 throw std::runtime_error("Mesh_i::Build - myResult->GetInput() == NULL !!!");
424 myField = myResult->GetInput()->GetField(myMeshName,myEntity,myFieldName);
425 if(myField == NULL) throw std::runtime_error("There is no Field with the parameters !!!");
426 VISU_Convertor::TOutput *anOutput =
427 myResult->GetInput()->GetTimeStampOnMesh(myMeshName,myEntity,myFieldName,myIteration);
428 if(anOutput == NULL) throw std::runtime_error("There is no TimeStamp with the parameters !!!");
429 myScalarMapPL->SetInput(anOutput);
430 myScalarMapPL->Build();
433 if(theRestoring <= 0){
434 if(theRestoring == 0) myScalarMapPL->Init();
435 if(!myIsFixedRange) myScalarMapPL->SetSourceRange();
436 const VISU::TValField& aValField = myField->myValField;
437 const VISU::PValForTime aValForTime = aValField.find(myIteration)->second;
438 aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime->myTime).c_str());
439 if (theRestoring == 0) myTitle = aComment.simplifyWhiteSpace().latin1();
442 myName = GenerateName().latin1();
443 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
444 VISU::TTIMESTAMP,myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp);
445 string aResultEntry = myResult->GetEntry();
446 string aRefFatherEntry = myResult->GetRefFatherEntry();
447 string anEntry = myResult->GetEntry(aComment.latin1());
448 if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!");
449 aComment.sprintf("myComment=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
450 GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp);
451 CORBA::String_var anIOR = GetID();
452 CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),anIOR,myName.c_str(),"",aComment.latin1(),true);
453 mySObject = myStudy->FindObjectIOR(anIOR);
455 }catch(std::exception& exc){
456 INFOS("Follow exception was occured :\n"<<exc.what());
459 INFOS("Unknown exception was occured!");
462 if(myAddToStudy) aStudyBuilder->CommitCommand();
467 void VISU::ScalarMap_i::DoHook(){
468 if(MYDEBUG) MESSAGE("ScalarMap_i::DoHook() - "<<myPipeLine);
470 myPipeLine = VISU_ScalarMapPL::New();
471 myPipeLine->GetMapper()->SetScalarVisibility(1);
473 myScalarMapPL = dynamic_cast<VISU_ScalarMapPL*>(myPipeLine);
476 void VISU::ScalarMap_i::Update() {
477 VISU::Prs3d_i::Update();
480 void VISU::ScalarMap_i::SetMapScale(double theMapScale){
481 myScalarMapPL->SetMapScale(theMapScale);
484 VISU_Actor* VISU::ScalarMap_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
486 VISU_ScalarMapAct* anActor = VISU_ScalarMapAct::New();
488 VISU::Prs3d_i::CreateActor(anActor,theIO);
489 anActor->SetBarVisibility(true);
490 anActor->SetRepresentation(2);
491 UpdateActor(anActor);
499 void VISU::ScalarMap_i::UpdateActor(VISU_Actor* theActor) {
500 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
501 VISU::Prs3d_i::UpdateActor(theActor);
502 VISU_ScalarBarActor *aScalarBar = anActor->GetScalarBar();
503 aScalarBar->SetLookupTable(myScalarMapPL->GetBarTable());
504 aScalarBar->SetTitle(myTitle.c_str());
505 aScalarBar->SetOrientation(myOrientation);
506 aScalarBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
507 aScalarBar->GetPositionCoordinate()->SetValue(myPosition[0],myPosition[1]);
508 aScalarBar->SetWidth(myWidth);
509 aScalarBar->SetHeight(myHeight);
510 aScalarBar->SetNumberOfLabels(myNumberOfLabels);
512 vtkTextProperty* aTitleProp = aScalarBar->GetTitleTextProperty();
513 aTitleProp->SetFontFamily(myTitFontType);
514 aTitleProp->SetColor(myTitleColor);
515 (myIsBoldTitle)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
516 (myIsItalicTitle)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
517 (myIsShadowTitle)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
519 vtkTextProperty* aLabelProp = aScalarBar->GetLabelTextProperty();
520 aLabelProp->SetFontFamily(myLblFontType);
521 aLabelProp->SetColor(myLabelColor);
522 (myIsBoldLabel)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
523 (myIsItalicLabel)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
524 (myIsShadowLabel)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
526 aScalarBar->Modified();
531 void VISU::ScalarMap_i::SetSourceRange(){
532 myScalarMapPL->SetSourceRange();
533 myIsFixedRange = false;