]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_ScalarMap_i.cc
Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISU_I / VISU_ScalarMap_i.cc
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //  File   : VISU_PrsObject_i.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_ScalarMap_i.hh"
28
29 #include "VISU_Result_i.hh"
30 #include "VISU_ViewManager_i.hh"
31
32 #include "VISU_ScalarMapAct.h"
33 #include "VISU_ScalarMapPL.hxx"
34 #include "VISU_Convertor.hxx"
35
36 #include "SUIT_ResourceMgr.h"
37
38 #include <vtkDataSetMapper.h>
39 #include <vtkTextProperty.h>
40
41 using namespace VISU;
42 using namespace std;
43
44 #ifdef _DEBUG_
45 static int MYDEBUG = 0;
46 #else
47 static int MYDEBUG = 0;
48 #endif
49
50 static int INCMEMORY = 4;
51
52
53 //============================================================================
54 int
55 VISU::ScalarMap_i
56 ::IsPossible(Result_i* theResult, 
57              const char* theMeshName, 
58              VISU::Entity theEntity,
59              const char* theFieldName, int theIteration, int isMemoryCheck)
60 {
61   try{
62     float aSize = INCMEMORY*
63       theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration);
64     bool aResult = true;
65     if(isMemoryCheck){
66       aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
67       MESSAGE("ScalarMap_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
68     }
69     return aResult;
70   }catch(std::exception& exc){
71     INFOS("Follow exception was occured :\n"<<exc.what());
72   }catch(...){
73     INFOS("Unknown exception was occured!");
74   }
75   return 0;
76 }
77
78 //----------------------------------------------------------------------------
79 int
80 VISU::ScalarMap_i
81 ::myNbPresent = 0;
82
83 QString
84 VISU::ScalarMap_i
85 ::GenerateName() 
86
87   return VISU::GenerateName("ScalarMap",myNbPresent++);
88 }
89
90 const string
91 VISU::ScalarMap_i
92 ::myComment = "SCALARMAP";
93
94 const char* 
95 VISU::ScalarMap_i
96 ::GetComment() const { 
97   return myComment.c_str();
98 }
99
100
101 //----------------------------------------------------------------------------
102 VISU::ScalarMap_i::
103 ScalarMap_i(Result_i* theResult,
104             bool theAddToStudy) :
105   PrsObject_i(theResult->GetStudyDocument()),
106   Prs3d_i(theResult,theAddToStudy),
107   ColoredPrs3d_i(theResult,theAddToStudy)
108 {}
109
110 VISU::ScalarMap_i::
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)
116 {}
117
118 VISU::ScalarMap_i
119 ::~ScalarMap_i()
120 {}
121
122
123 //----------------------------------------------------------------------------
124 void
125 VISU::ScalarMap_i
126 ::SameAs(const Prs3d_i* theOrigin)
127 {
128   TSuperClass::SameAs(theOrigin);
129
130   if(const ScalarMap_i* aPrs3d = dynamic_cast<const ScalarMap_i*>(theOrigin)){
131     ScalarMap_i* anOrigin = const_cast<ScalarMap_i*>(aPrs3d);
132  
133     SetRange(anOrigin->GetMin(), anOrigin->GetMax());
134     myIsFixedRange = anOrigin->IsRangeFixed();
135
136     SetScaling(anOrigin->GetScaling());
137     
138     Update();
139   }
140 }
141
142
143 //----------------------------------------------------------------------------
144 /**
145  * Creates Scalar Map and initialises it from resources
146  */
147 VISU::Storable* 
148 VISU::ScalarMap_i
149 ::Create(const char* theMeshName, 
150          VISU::Entity theEntity,
151          const char* theFieldName, 
152          int theIteration)
153 {
154   TSuperClass::Create(theMeshName,theEntity,theFieldName,theIteration);
155
156   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
157
158   // Scalar Range
159   int aRangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0);
160   myIsFixedRange = (aRangeType == 1) ? true : false;
161
162   if(myIsFixedRange){
163     float aMin = aResourceMgr->doubleValue("VISU", "scalar_range_min", 0);
164     float aMax = aResourceMgr->doubleValue("VISU", "scalar_range_max", 0);
165     SetRange(aMin,aMax);
166   }
167
168   bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false);
169
170   if( isLog )
171     SetScaling(VISU::LOGARITHMIC);
172   else
173     SetScaling(VISU::LINEAR);
174
175   return this;
176 }
177
178 VISU::Storable* 
179 VISU::ScalarMap_i
180 ::Restore(const Storable::TRestoringMap& theMap)
181 {
182   TSuperClass::Restore(theMap);
183
184   SetScaling(VISU::Scaling(VISU::Storable::FindValue(theMap,"myScaling").toInt()));
185
186   float aMin = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble();
187   float aMax = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble();
188   SetRange(aMin,aMax);
189
190   myIsFixedRange = VISU::Storable::FindValue(theMap,"myIsFixedRange").toInt();
191
192   return this;
193 }
194
195 void 
196 VISU::ScalarMap_i
197 ::ToStream(std::ostringstream& theStr)
198 {
199   TSuperClass::ToStream(theStr);
200
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() );
205 }
206
207
208 //----------------------------------------------------------------------------
209 void
210 VISU::ScalarMap_i
211 ::SetBarOrientation(VISU::ScalarMap::Orientation theOrientation)
212 {
213   TSuperClass::SetBarOrientation(theOrientation);
214 }
215
216 VISU::ScalarMap::Orientation 
217 VISU::ScalarMap_i
218 ::GetBarOrientation() 
219 {
220   return TSuperClass::GetBarOrientation();
221 }
222
223 VISU::Scaling 
224 VISU::ScalarMap_i
225 ::GetScaling()
226 {
227   return VISU::Scaling(myScalarMapPL->GetScaling());
228 }
229
230 void
231 VISU::ScalarMap_i
232 ::SetScaling(VISU::Scaling theScaling)
233 {
234   myScalarMapPL->SetScaling(theScaling);
235 }
236
237 void
238 VISU::ScalarMap_i
239 ::SetRange(CORBA::Double theMin, CORBA::Double theMax)
240 {
241   if(theMin > theMax) 
242     return;
243   float aScalarRange[2] = {theMin, theMax};
244   myScalarMapPL->SetScalarRange(aScalarRange);
245   myIsFixedRange = true;
246 }
247
248
249 //----------------------------------------------------------------------------
250 void 
251 VISU::ScalarMap_i
252 ::DoSetInput(Result_i* theResult)
253 {
254   VISU::Result_i::TInput* anInput = theResult->GetInput();
255   if(!anInput)
256     throw std::runtime_error("Mesh_i::Build - theResult->GetInput() == NULL !!!");
257
258   myField = anInput->GetField(myMeshName,myEntity,myFieldName);
259   if(!myField) 
260     throw std::runtime_error("There is no Field with the parameters !!!");
261
262   VISU::PIDMapper anIDMapper =
263     anInput->GetTimeStampOnMesh(myMeshName,myEntity,myFieldName,myIteration);
264
265   if(!anIDMapper) 
266     throw std::runtime_error("There is no TimeStamp with the parameters !!!");
267
268   myScalarMapPL->SetIDMapper(anIDMapper);
269   myScalarMapPL->Init();
270   myScalarMapPL->Build();
271 }
272
273 void
274 VISU::ScalarMap_i
275 ::Update() 
276 {
277   TSuperClass::Update();
278 }
279
280
281 //----------------------------------------------------------------------------
282 void
283 VISU::ScalarMap_i
284 ::SetMapScale(double theMapScale)
285 {
286   myScalarMapPL->SetMapScale(theMapScale);
287 }
288
289 bool
290 VISU::ScalarMap_i
291 ::IsRangeFixed() 
292
293   return myIsFixedRange; 
294 }
295
296 void
297 VISU::ScalarMap_i
298 ::SetSourceRange()
299 {
300   myScalarMapPL->SetSourceRange();
301   myIsFixedRange = false;
302 }
303
304 //----------------------------------------------------------------------------
305 VISU_Actor* 
306 VISU::ScalarMap_i
307 ::CreateActor(const Handle(SALOME_InteractiveObject)& theIO)
308 {
309   VISU_ScalarMapAct* anActor = VISU_ScalarMapAct::New();
310   try{
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);
318   }catch(...){
319     anActor->Delete();
320     throw;
321   }
322   return anActor;
323 }
324
325 void
326 VISU::ScalarMap_i
327 ::UpdateActor(VISU_Actor* theActor) 
328 {
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);
339
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();
346
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();
353
354     aScalarBar->Modified();
355   }
356   TSuperClass::UpdateActor(theActor);
357 }