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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_ScalarMap_i.hh"
28 #include "VISU_Prs3dUtils.hh"
30 #include "VISU_Result_i.hh"
32 #include "VISU_ScalarMapAct.h"
33 #include "VISU_ScalarMapPL.hxx"
34 #include "VISU_LookupTable.hxx"
35 #include "VISU_ScalarBarActor.hxx"
36 #include "VISU_Convertor.hxx"
38 #include "SUIT_ResourceMgr.h"
40 #include "SUIT_Session.h"
41 #include "SALOME_Event.hxx"
42 #include "SalomeApp_Study.h"
43 #include "SalomeApp_Application.h"
45 #include <vtkDataSetMapper.h>
46 #include <vtkTextProperty.h>
49 static int MYDEBUG = 0;
51 static int MYDEBUG = 0;
54 static int INCMEMORY = 4;
57 //----------------------------------------------------------------------------
60 ::IsPossible(Result_i* theResult,
61 const std::string& theMeshName,
62 VISU::Entity theEntity,
63 const std::string& theFieldName,
64 CORBA::Long theTimeStampNumber,
65 bool theIsMemoryCheck)
70 bool anIsEstimated = true;
71 VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
75 size_t aSize = anInput->GetTimeStampOnMeshSize(theMeshName,
76 (VISU::TEntity)theEntity,
84 aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
86 MESSAGE("ScalarMap_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
89 }catch(std::exception& exc){
90 INFOS("Follow exception was occured :\n"<<exc.what());
92 INFOS("Unknown exception was occured!");
97 //----------------------------------------------------------------------------
98 int VISU::ScalarMap_i::myNbPresent = 0;
100 //----------------------------------------------------------------------------
105 return VISU::GenerateName("ScalarMap",myNbPresent++);
108 //----------------------------------------------------------------------------
109 const string VISU::ScalarMap_i::myComment = "SCALARMAP";
111 //----------------------------------------------------------------------------
116 return myComment.c_str();
119 //----------------------------------------------------------------------------
125 return "ICON_TREE_SCALAR_MAP";
127 return "ICON_TREE_SCALAR_MAP_GROUPS";
130 //----------------------------------------------------------------------------
135 SALOMEDS::SObject_var aSObject = GetSObject();
136 if(CORBA::is_nil(aSObject))
139 SALOMEDS::Study_var aStudyDocument = GetStudyDocument();
140 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
142 // Check if the icon needs to be updated, update if necessary
143 SALOMEDS::GenericAttribute_var anAttr =
144 aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributePixMap");
145 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
147 CORBA::String_var aPixMapName = aPixmap->GetPixMap();
148 if(strcmp(GetIconName(), aPixMapName.in()) != 0)
149 aPixmap->SetPixMap(GetIconName());
151 // Update Object Browser
152 SUIT_Session* aSession = SUIT_Session::session();
153 QPtrList<SUIT_Application> anApplications = aSession->applications();
154 QPtrListIterator<SUIT_Application> anIter(anApplications);
155 while(SUIT_Application* aSApp = anIter.current()){
156 if(SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSApp)){
157 if(SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy())){
158 if(_PTR(Study) aCStudy = aStudy->studyDS()){
159 if(aStudyDocument->StudyId() == aCStudy->StudyId()){
160 anApp->updateObjectBrowser();
170 //----------------------------------------------------------------------------
172 ScalarMap_i(EPublishInStudyMode thePublishInStudyMode) :
173 ColoredPrs3d_i(thePublishInStudyMode)
176 //----------------------------------------------------------------------------
182 //----------------------------------------------------------------------------
185 ::SameAs(const Prs3d_i* theOrigin)
187 TSuperClass::SameAs(theOrigin);
189 if(const ScalarMap_i* aPrs3d = dynamic_cast<const ScalarMap_i*>(theOrigin)){
190 ScalarMap_i* anOrigin = const_cast<ScalarMap_i*>(aPrs3d);
192 SetScaling(anOrigin->GetScaling());
199 //----------------------------------------------------------------------------
201 * Creates Scalar Map and initialises it from resources
205 ::Create(const std::string& theMeshName,
206 VISU::Entity theEntity,
207 const std::string& theFieldName,
208 CORBA::Long theTimeStampNumber)
210 TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
212 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
214 if( aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false) )
215 SetScaling(VISU::LOGARITHMIC);
217 SetScaling(VISU::LINEAR);
222 //----------------------------------------------------------------------------
227 return TSuperClass::GetMemorySize();
230 //----------------------------------------------------------------------------
233 ::Restore(SALOMEDS::SObject_ptr theSObject,
234 const Storable::TRestoringMap& theMap)
236 if(!TSuperClass::Restore(theSObject, theMap))
239 SetScaling(VISU::Scaling(VISU::Storable::FindValue(theMap,"myScaling").toInt()));
241 // Check if the icon needs to be updated, update if necessary
242 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
243 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
244 SALOMEDS::GenericAttribute_var anAttr =
245 aStudyBuilder->FindOrCreateAttribute(theSObject, "AttributePixMap");
246 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
248 CORBA::String_var aPixMapName = aPixmap->GetPixMap();
249 if(strcmp(GetIconName(), aPixMapName.in()) != 0)
250 aPixmap->SetPixMap(GetIconName());
255 //----------------------------------------------------------------------------
258 ::ToStream(std::ostringstream& theStr)
260 TSuperClass::ToStream(theStr);
262 Storable::DataToStream( theStr, "myScaling", GetScaling() );
266 //----------------------------------------------------------------------------
271 return VISU::Scaling(GetSpecificPL()->GetScaling());
274 //----------------------------------------------------------------------------
277 ::SetScaling(VISU::Scaling theScaling)
279 VISU::TSetModified aModified(this);
281 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_ScalarMapPL, int>
282 (GetSpecificPL(), &VISU_ColoredPL::SetScaling, theScaling));
285 //----------------------------------------------------------------------------
288 ::SetSourceGeometry()
290 int aNbGroups = myGroupNames.size();
292 GetSpecificPL()->SetSourceGeometry();
293 myGroupNames.clear();
298 //----------------------------------------------------------------------------
301 ::AddMeshOnGroup(const char* theGroupName)
303 VISU::Result_i::PInput anInput = GetCResult()->GetInput();
304 VISU::PUnstructuredGridIDMapper anIDMapper = anInput->GetMeshOnGroup(GetCMeshName(), theGroupName);
306 int aNbGroups = myGroupNames.size();
307 if(myGroupNames.find(theGroupName) == myGroupNames.end()){
308 GetSpecificPL()->AddGeometry(anIDMapper->GetOutput());
309 myGroupNames.insert(theGroupName);
317 //----------------------------------------------------------------------------
322 int aNbGroups = myGroupNames.size();
323 GetSpecificPL()->ClearGeometry();
324 myGroupNames.clear();
330 //----------------------------------------------------------------------------
333 ::DoSetInput(bool theIsInitilizePipe, bool theReInit)
335 VISU::Result_i::PInput anInput = GetCResult()->GetInput(GetCMeshName(),
338 GetTimeStampNumber());
340 throw std::runtime_error("Mesh_i::Build - GetCResult()->GetInput() == NULL !!!");
342 SetField(anInput->GetField(GetCMeshName(),GetTEntity(),GetCFieldName()));
344 throw std::runtime_error("There is no Field with the parameters !!!");
346 VISU::PUnstructuredGridIDMapper anIDMapper =
347 anInput->GetTimeStampOnMesh(GetCMeshName(),GetTEntity(),GetCFieldName(),GetTimeStampNumber());
350 throw std::runtime_error("There is no TimeStamp with the parameters !!!");
352 GetSpecificPL()->SetUnstructuredGridIDMapper(anIDMapper);
356 //----------------------------------------------------------------------------
361 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
365 //----------------------------------------------------------------------------
368 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
370 if(MYDEBUG) MESSAGE("ScalarMap_i::CreatePipeLine() - "<<thePipeLine);
372 myScalarMapPL = VISU_ScalarMapPL::New();
373 myScalarMapPL->GetMapper()->SetScalarVisibility(1);
375 myScalarMapPL = dynamic_cast<VISU_ScalarMapPL*>(thePipeLine);
377 TSuperClass::CreatePipeLine(myScalarMapPL);
380 //----------------------------------------------------------------------------
383 ::SetMapScale(double theMapScale)
385 GetSpecificPL()->SetMapScale(theMapScale);
388 //----------------------------------------------------------------------------
391 ::CreateActor(bool toSupressShrinking)
393 VISU_ScalarMapAct* anActor = VISU_ScalarMapAct::New();
395 TSuperClass::CreateActor(anActor);
396 anActor->SetBarVisibility(true);
397 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
398 int aDispMode = aResourceMgr->integerValue("VISU", "scalar_map_represent", 2);
399 bool toShrink = aResourceMgr->booleanValue("VISU", "scalar_map_shrink", false);
400 bool toUseShading = aResourceMgr->booleanValue("VISU", "represent_shading", false);
401 anActor->SetRepresentation(aDispMode);
402 if (toShrink && !toSupressShrinking) anActor->SetShrink();
403 anActor->SetShading(toUseShading);
404 UpdateActor(anActor);
412 //----------------------------------------------------------------------------
417 return CreateActor(false);
420 //----------------------------------------------------------------------------
423 ::UpdateActor(VISU_Actor* theActor)
425 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
426 VISU_ScalarBarActor *aScalarBar = anActor->GetScalarBar();
427 aScalarBar->SetLookupTable(GetSpecificPL()->GetBarTable());
428 aScalarBar->SetTitle(GetScalarBarTitle().c_str());
429 aScalarBar->SetOrientation(GetBarOrientation());
430 aScalarBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
431 aScalarBar->GetPositionCoordinate()->SetValue(GetPosX(),GetPosY());
432 aScalarBar->SetWidth(GetWidth());
433 aScalarBar->SetHeight(GetHeight());
434 aScalarBar->SetRatios(GetTitleWidth(), GetTitleHeight(),
435 GetLabelWidth(), GetLabelHeight(),
436 GetBarWidth(), GetBarHeight());
437 aScalarBar->SetNumberOfLabels(GetLabels());
438 aScalarBar->SetLabelFormat(GetLabelsFormat());
440 vtkFloatingPointType anRGB[3];
442 vtkTextProperty* aTitleProp = aScalarBar->GetTitleTextProperty();
443 aTitleProp->SetFontFamily(GetTitFontType());
445 GetTitleColor(&anRGB[0],&anRGB[1],&anRGB[2]);
446 aTitleProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
448 IsBoldTitle()? aTitleProp->BoldOn() : aTitleProp->BoldOff();
449 IsItalicTitle()? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
450 IsShadowTitle()? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
452 vtkTextProperty* aLabelProp = aScalarBar->GetLabelTextProperty();
453 aLabelProp->SetFontFamily(GetLblFontType());
455 GetLabelColor(&anRGB[0],&anRGB[1],&anRGB[2]);
456 aLabelProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
458 IsBoldLabel()? aLabelProp->BoldOn() : aLabelProp->BoldOff();
459 IsItalicLabel()? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
460 IsShadowLabel()? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
462 aScalarBar->Modified();
464 TSuperClass::UpdateActor(theActor);