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_ScalarMapPL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_ScalarMap_i.hh"
30 #include "VISU_ScalarMapAct.h"
31 #include "QAD_Config.h"
37 static int MYDEBUG = 0;
38 static int MYDEBUGWITHFILES = 0;
40 static int MYDEBUG = 0;
41 static int MYDEBUGWITHFILES = 0;
44 static int INCMEMORY = 4;
46 int VISU::ScalarMap_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
47 const char* theFieldName, int theIteration)
50 vtkIdType aSize = INCMEMORY*
51 theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration);
52 if(MYDEBUG) MESSAGE("ScalarMap_i::IsPossible - CheckAvailableMemory = "<<aSize);
53 if(VISU_PipeLine::CheckAvailableMemory(aSize)) return true;
55 }catch(std::runtime_error& exc){
56 INFOS("Follow exception was accured :\n"<<exc.what());
58 INFOS("Unknown exception was accured!");
63 int VISU::ScalarMap_i::myNbPresent = 0;
64 QString VISU::ScalarMap_i::GenerateName() { return VISU::GenerateName("ScalarMap",myNbPresent++);}
66 const string VISU::ScalarMap_i::myComment = "SCALARMAP";
67 const char* VISU::ScalarMap_i::GetComment() const { return myComment.c_str();}
69 VISU::ScalarMap_i::ScalarMap_i(Result_i* theResult, bool theAddToStudy) :
70 PrsObject_i(theResult->GetStudyDocument()),
73 myAddToStudy = theAddToStudy;
77 void VISU::ScalarMap_i::Destroy(){
79 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(GetEntry());
80 if(!aSObj->_is_nil()){
81 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
82 aStudyBuilder->RemoveObject(aSObj);
89 void VISU::ScalarMap_i::SameAs(const ScalarMap_i* theOrigin)
91 ScalarMap_i* aScalarMap = const_cast<ScalarMap_i*>(theOrigin);
93 VISU::Prs3d_i::SameAs(aScalarMap);
94 myField = aScalarMap->GetField();
95 myMeshName = myField->myMeshName;
96 myEntity = myField->myEntity;
97 myIteration = aScalarMap->GetIteration();
98 myFieldName = aScalarMap->GetFieldName();
100 SetScalarMode(aScalarMap->GetScalarMode());
102 SetRange(aScalarMap->GetMin(), aScalarMap->GetMax());
103 myIsFixedRange = aScalarMap->IsRangeFixed();
105 SetScaling(aScalarMap->GetScaling());
107 SetOrientation(aScalarMap->GetOrientation());
108 SetPosition(aScalarMap->GetPosX(), aScalarMap->GetPosY());
109 SetSize(aScalarMap->GetWidth(), aScalarMap->GetHeight());
110 SetNbColors(aScalarMap->GetNbColors());
111 SetLabels(aScalarMap->GetLabels());
112 SetTitle(aScalarMap->GetTitle());
120 * Creates Scalar Map and initialises it from resources
122 VISU::Storable* VISU::ScalarMap_i::Create(const char* theMeshName, VISU::Entity theEntity,
123 const char* theFieldName, int theIteration)
128 QString aOrient = QAD_CONFIG->getSetting("Visu:SBOrientation");
129 if ( !aOrient.isEmpty() )
130 myOrientation = (VISU::ScalarMap::Orientation) aOrient.toInt();
132 myOrientation = VISU::ScalarMap::VERTICAL;
135 QString aXorigin = QAD_CONFIG->getSetting("Visu:SBXorigin");
136 if ( !aXorigin.isEmpty() )
137 myPosition[0] = aXorigin.toFloat();
139 if(myOrientation == VISU::ScalarMap::VERTICAL) {
140 myPosition[0] = 0.03;
146 QString aYorigin = QAD_CONFIG->getSetting("Visu:SBYorigin");
147 if ( !aYorigin.isEmpty() )
148 myPosition[1] = aYorigin.toFloat();
150 if(myOrientation == VISU::ScalarMap::VERTICAL) {
153 myPosition[1] = 0.012;
158 QString aWidth = QAD_CONFIG->getSetting("Visu:SBWidth");
159 if ( !aWidth.isEmpty() )
160 myWidth = aWidth.toFloat();
162 myWidth =(myOrientation == VISU::ScalarMap::VERTICAL)? 0.17:0.6;
164 QString aHeight = QAD_CONFIG->getSetting("Visu:SBHeight");
165 if ( !aHeight.isEmpty() )
166 myHeight = aHeight.toFloat();
168 myHeight =(myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12;
172 QString aColors = QAD_CONFIG->getSetting("Visu:SBNumberOfColors");
173 int aNumberOfColors = (aColors.isEmpty())? 64 : aColors.toInt();
174 if (aNumberOfColors > 64)
175 aNumberOfColors = 64;
176 SetNbColors(aNumberOfColors);
179 QString aLabels = QAD_CONFIG->getSetting("Visu:SBNumberOfLabels");
180 myNumberOfLabels = (aLabels.isEmpty())? 5 : aLabels.toInt();
181 if (myNumberOfLabels > 65)
182 myNumberOfLabels = 65;
185 QString aFixRange = QAD_CONFIG->getSetting("Visu:SBImposeRange");
186 myIsFixedRange = (aFixRange.compare("true") == 0);
189 float aScalarRange[2];
190 QString aRangeMin = QAD_CONFIG->getSetting("Visu:SBMinimumValue");
191 float aMin = (aRangeMin.isEmpty())? 0 : aRangeMin.toFloat();
192 QString aRangeMax = QAD_CONFIG->getSetting("Visu:SBMaximumValue");
193 float aMax = (aRangeMax.isEmpty())? 0 : aRangeMax.toFloat();
197 QString aScaling = QAD_CONFIG->getSetting("Visu:SBScaling");
198 if(aScaling.compare("LOGARITHMIC") == 0)
199 SetScaling(VISU::LOGARITHMIC);
201 SetScaling(VISU::LINEAR);
203 myMeshName = theMeshName;
204 myEntity = (VISU::TEntity)theEntity;
205 myFieldName =theFieldName;
206 myIteration = theIteration;
212 VISU::Storable* VISU::ScalarMap_i::Restore(const Storable::TRestoringMap& theMap)
213 throw(std::logic_error&)
217 Prs3d_i::Restore(theMap);
219 myAddToStudy = false; //SRN Added 21/06/2003 SAL2983: to avoid addition of the new ScalarMap to study.
221 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
222 myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt();
223 myFieldName = VISU::Storable::FindValue(theMap,"myFieldName").latin1();
224 myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt();
226 SetScalarMode(VISU::Storable::FindValue(theMap,"myScalarMode").toInt());
227 SetScaling(VISU::Scaling(VISU::Storable::FindValue(theMap,"myScaling").toInt()));
228 float aMin = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble();
229 float aMax = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble();
231 myIsFixedRange = VISU::Storable::FindValue(theMap,"myIsFixedRange").toInt();
233 myTitle = VISU::Storable::FindValue(theMap,"myTitle").latin1();
234 myOrientation = (VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt();
235 SetNbColors(VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt());
236 myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt();
237 myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
238 myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
239 myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble();
240 myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble();
246 void VISU::ScalarMap_i::ToStream(std::ostringstream& theStr){
247 Prs3d_i::ToStream(theStr);
249 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
250 Storable::DataToStream( theStr, "myEntity", myEntity );
251 Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() );
252 Storable::DataToStream( theStr, "myIteration", myIteration );
254 Storable::DataToStream( theStr, "myScalarMode", int(GetScalarMode()) );
255 Storable::DataToStream( theStr, "myScalarRange[0]", GetMin() );
256 Storable::DataToStream( theStr, "myScalarRange[1]", GetMax() );
257 Storable::DataToStream( theStr, "myIsFixedRange", myIsFixedRange );
258 Storable::DataToStream( theStr, "myScaling", GetScaling() );
260 Storable::DataToStream( theStr, "myTitle", myTitle.c_str() );
261 Storable::DataToStream( theStr, "myOrientation", myOrientation );
262 Storable::DataToStream( theStr, "myNumberOfColors", int(GetNbColors()) );
263 Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels );
264 Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] );
265 Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] );
266 Storable::DataToStream( theStr, "myWidth", myWidth );
267 Storable::DataToStream( theStr, "myHeight", myHeight );
271 CORBA::Long VISU::ScalarMap_i::GetScalarMode(){
272 return myScalarMapPL->GetScalarMode();
274 void VISU::ScalarMap_i::SetScalarMode(CORBA::Long theScalarMode) {
275 myScalarMapPL->SetScalarMode(theScalarMode);
279 VISU::Scaling VISU::ScalarMap_i::GetScaling(){
280 return VISU::Scaling(myScalarMapPL->GetScaling());
282 void VISU::ScalarMap_i::SetScaling(VISU::Scaling theScaling){
283 myScalarMapPL->SetScaling(theScaling);
287 void VISU::ScalarMap_i::SetRange(CORBA::Double theMin, CORBA::Double theMax){
288 if(theMin > theMax) return;
289 float aScalarRange[2] = {theMin, theMax};
290 myScalarMapPL->SetScalarRange(aScalarRange);
291 myIsFixedRange = true;
294 CORBA::Double VISU::ScalarMap_i::GetMin(){
295 return myScalarMapPL->GetScalarRange()[0];
298 CORBA::Double VISU::ScalarMap_i::GetMax(){
299 return myScalarMapPL->GetScalarRange()[1];
303 void VISU::ScalarMap_i::SetNbColors(CORBA::Long theNbColors){
304 myScalarMapPL->SetNbColors(theNbColors);
307 CORBA::Long VISU::ScalarMap_i::GetNbColors(){
308 return myScalarMapPL->GetNbColors();
312 VISU::Storable* VISU::ScalarMap_i::Restore(SALOMEDS::SObject_ptr theSObject,
313 const string& thePrefix, const Storable::TRestoringMap& theMap)
314 throw(std::logic_error&)
316 if(VISU::Result_i* pResult = GetResult(theSObject)){
317 VISU::ScalarMap_i* pResent = new VISU::ScalarMap_i(pResult);
318 return pResent->Restore(theMap);
324 VISU::ScalarMap_i::~ScalarMap_i(){
325 if(MYDEBUG) MESSAGE("ScalarMap_i::~ScalarMap_i()");
329 VISU::Storable* VISU::ScalarMap_i::Build(int theRestoring){
331 MESSAGE("ScalarMap_i::Build - "<<myFieldName<<"; theRestoring = "<<theRestoring);
333 if(myResult->GetInput() == NULL)
334 throw std::runtime_error("Mesh_i::Build - myResult->GetInput() == NULL !!!");
335 myField = &(myResult->GetInput()->GetField(myMeshName,myEntity,myFieldName));
336 if(myField == NULL) throw std::runtime_error("There is no Field with the parameters !!!");
337 VISU_Convertor::TOutput *anOutput =
338 myResult->GetInput()->GetTimeStampOnMesh(myMeshName,myEntity,myFieldName,myIteration);
339 if(anOutput == NULL) throw std::runtime_error("There is no TimeStamp with the parameters !!!");
340 myScalarMapPL->SetInput(anOutput);
341 myScalarMapPL->Build();
344 if(theRestoring <= 0){
345 if(theRestoring == 0) myScalarMapPL->Init();
346 if(!myIsFixedRange) myScalarMapPL->SetSourceRange();
347 const VISU::TField::TValField& aValField = myField->myValField;
348 const VISU::TField::TValForTime& aValForTime = aValField.find(myIteration)->second;
349 aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime.myTime).c_str());
350 myTitle = aComment.simplifyWhiteSpace().latin1();
353 myName = GenerateName().latin1();
354 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
355 VISU::TTIMESTAMP,myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp);
356 string aResultEntry = myResult->GetEntry();
357 string aRefFatherEntry = myResult->GetRefFatherEntry();
358 string anEntry = FindEntryWithComment(myStudy,aResultEntry.c_str(),aComment.latin1());
359 if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!");
360 aComment.sprintf("myComment=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
361 GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp);
362 CORBA::String_var anIOR = GetID();
363 CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),anIOR,myName.c_str(),"",aComment.latin1(),true);
366 }catch(std::runtime_error& exc){
367 INFOS("Follow exception was accured :\n"<<exc.what());
369 INFOS("Unknown exception was accured!");
375 void VISU::ScalarMap_i::DoHook(){
376 if(MYDEBUG) MESSAGE("ScalarMap_i::DoHook() - "<<myPipeLine);
378 myPipeLine = VISU_ScalarMapPL::New();
379 myPipeLine->GetMapper()->SetScalarVisibility(1);
381 myScalarMapPL = dynamic_cast<VISU_ScalarMapPL*>(myPipeLine);
384 void VISU::ScalarMap_i::Update(){
385 VISU::Prs3d_i::Update();
388 void VISU::ScalarMap_i::SetMapScale(double theMapScale){
389 myScalarMapPL->SetMapScale(theMapScale);
392 VISU_Actor* VISU::ScalarMap_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
393 throw (std::runtime_error&)
395 VISU_ScalarMapAct* anActor = VISU_ScalarMapAct::New();
397 VISU::Prs3d_i::CreateActor(anActor,theIO);
398 anActor->SetBarVisibility(true);
399 anActor->SetRepresentation(2);
400 anActor->myFieldName = myFieldName;
401 UpdateActor(anActor);
402 }catch(std::runtime_error& exc){
409 void VISU::ScalarMap_i::UpdateActor(VISU_Actor* theActor){
410 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
411 VISU::Prs3d_i::UpdateActor(theActor);
412 VISU_ScalarBarActor *aScalarBar = anActor->GetScalarBar();
413 aScalarBar->SetLookupTable(myScalarMapPL->GetBarTable());
414 aScalarBar->SetTitle(myTitle.c_str());
415 aScalarBar->SetOrientation(myOrientation);
416 aScalarBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
417 aScalarBar->GetPositionCoordinate()->SetValue(myPosition[0],myPosition[1]);
418 aScalarBar->SetWidth(myWidth);
419 aScalarBar->SetHeight(myHeight);
420 aScalarBar->SetNumberOfLabels(myNumberOfLabels);
421 aScalarBar->Modified();
426 void VISU::ScalarMap_i::SetSourceRange(){
427 myScalarMapPL->SetSourceRange();
428 myIsFixedRange = false;