Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_I / VISU_IsoSurfaces_i.cc
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_PrsObject_i.cxx
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #include "VISU_IsoSurfaces_i.hh"
29 #include "VISU_Prs3dUtils.hh"
30
31 #include "VISU_IsoSurfacesPL.hxx"
32 #include "VISU_Result_i.hh"
33 #include "VISU_Actor.h"
34 #include "VISU_ScalarMapAct.h"
35 #include "VISU_IsoSurfActor.h"
36
37 #include "SUIT_ResourceMgr.h"
38 #include "SALOME_Event.h"
39 #include <vtkMapper.h>
40
41 #ifdef _DEBUG_
42 static int MYDEBUG = 0;
43 #else
44 static int MYDEBUG = 0;
45 #endif
46
47 using namespace std;
48
49 //---------------------------------------------------------------
50 size_t
51 VISU::IsoSurfaces_i
52 ::IsPossible(Result_i* theResult, 
53              const std::string& theMeshName, 
54              VISU::Entity theEntity,
55              const std::string& theFieldName, 
56              CORBA::Long theTimeStampNumber,
57              bool theIsMemoryCheck)
58 {
59   return TSuperClass::IsPossible(theResult,
60                                  theMeshName,
61                                  theEntity,
62                                  theFieldName,
63                                  theTimeStampNumber,
64                                  theIsMemoryCheck);
65 }
66
67 //---------------------------------------------------------------
68 int VISU::IsoSurfaces_i::myNbPresent = 0;
69
70 //---------------------------------------------------------------
71 QString VISU::IsoSurfaces_i::GenerateName()
72
73   return VISU::GenerateName("IsoSurfaces",myNbPresent++);
74 }
75
76 //---------------------------------------------------------------
77 const string VISU::IsoSurfaces_i::myComment = "ISOSURFACES";
78
79 //---------------------------------------------------------------
80 const char* 
81 VISU::IsoSurfaces_i
82 ::GetComment() const
83
84   return myComment.c_str();
85 }
86
87 //---------------------------------------------------------------
88 const char*
89 VISU::IsoSurfaces_i
90 ::GetIconName()
91 {
92   if (!IsGroupsUsed())
93     return "ICON_TREE_ISO_SURFACES";
94   else
95     return "ICON_TREE_ISO_SURFACES_GROUPS";
96 }
97
98 //---------------------------------------------------------------
99 VISU::IsoSurfaces_i
100 ::IsoSurfaces_i(EPublishInStudyMode thePublishInStudyMode) :
101   ColoredPrs3d_i(thePublishInStudyMode),
102   ScalarMap_i(thePublishInStudyMode),
103   MonoColorPrs_i(thePublishInStudyMode),
104   myIsoSurfacesPL(NULL),
105   myIsLabeled(false),
106   myNbLabels(3)
107 {}
108
109
110 //---------------------------------------------------------------
111 VISU::Storable* 
112 VISU::IsoSurfaces_i
113 ::Create(const std::string& theMeshName, 
114          VISU::Entity theEntity,
115          const std::string& theFieldName, 
116          CORBA::Long theTimeStampNumber)
117 {
118   VISU::Storable* aRes = TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
119   myIsColored = true;
120   myColor.R = myColor.G = myColor.B = 0.;
121   //myIsLabeled = false;
122   //myNbLabels = 3;
123   return aRes;
124 }
125
126
127 //---------------------------------------------------------------
128 VISU::Storable* 
129 VISU::IsoSurfaces_i
130 ::Restore(SALOMEDS::SObject_ptr theSObject,
131           const Storable::TRestoringMap& theMap)
132 {
133   if(!TSuperClass::Restore(theSObject, theMap))
134     return NULL;
135
136   SetNbSurfaces(VISU::Storable::FindValue(theMap,"myNbSurface").toInt());
137   float aMin = VISU::Storable::FindValue(theMap,"myRange[0]").toDouble();
138   float aMax = VISU::Storable::FindValue(theMap,"myRange[1]").toDouble();
139   myNbLabels = VISU::Storable::FindValue(theMap,"myNbLabels").toInt();
140   myIsLabeled = VISU::Storable::FindValue(theMap,"myIsLabeled").toInt();
141   SetSubRange(aMin,aMax);
142
143   SetSubRangeFixed(VISU::Storable::FindValue(theMap,"myIsRangeFixed").toInt());
144     
145   return this;
146 }
147
148
149 //---------------------------------------------------------------
150 void
151 VISU::IsoSurfaces_i
152 ::ToStream(std::ostringstream& theStr)
153 {
154   TSuperClass::ToStream(theStr);
155
156   Storable::DataToStream( theStr, "myNbSurface", int(GetNbSurfaces()) );
157   Storable::DataToStream( theStr, "myRange[0]", GetSubMin() );
158   Storable::DataToStream( theStr, "myRange[1]", GetSubMax() );
159   Storable::DataToStream( theStr, "myNbLabels", myNbLabels );
160   Storable::DataToStream( theStr, "myIsLabeled", myIsLabeled );
161   Storable::DataToStream( theStr, "myIsRangeFixed", IsSubRangeFixed() );
162 }
163
164 //---------------------------------------------------------------
165 void VISU::IsoSurfaces_i::SameAs(const Prs3d_i* theOrigin)
166 {
167   TSuperClass::SameAs(theOrigin);
168
169   if(const IsoSurfaces_i* aPrs3d = dynamic_cast<const IsoSurfaces_i*>(theOrigin)){
170     IsoSurfaces_i* anOrigin = const_cast<IsoSurfaces_i*>(aPrs3d);
171     ShowLabels(anOrigin->IsLabeled(), anOrigin->GetNbLabels());
172   }
173 }
174
175
176
177 //---------------------------------------------------------------
178 VISU::IsoSurfaces_i
179 ::~IsoSurfaces_i()
180 {
181   if(MYDEBUG) MESSAGE("IsoSurfaces_i::~IsoSurfaces_i()");
182 }
183
184
185 //---------------------------------------------------------------
186 void 
187 VISU::IsoSurfaces_i
188 ::SetNbSurfaces(CORBA::Long theNb)
189 {
190   VISU::TSetModified aModified(this);
191   
192   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_IsoSurfacesPL, int>
193                    (GetSpecificPL(), &VISU_IsoSurfacesPL::SetNbParts, theNb));
194 }
195
196 //---------------------------------------------------------------
197 CORBA::Long 
198 VISU::IsoSurfaces_i
199 ::GetNbSurfaces()
200 {
201   return myIsoSurfacesPL->GetNbParts();
202 }
203
204
205 //---------------------------------------------------------------
206 void
207 VISU::IsoSurfaces_i
208 ::SetSubRange(CORBA::Double theMin, CORBA::Double theMax)
209
210   VISU::TSetModified aModified(this);
211
212   bool isForced = false;
213   vtkFloatingPointType aRange[2] = {theMin, theMax};
214   ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_IsoSurfacesPL, vtkFloatingPointType*, bool>
215                    (GetSpecificPL(), &VISU_IsoSurfacesPL::SetRange, aRange, isForced));
216 }
217
218 //---------------------------------------------------------------
219 CORBA::Double 
220 VISU::IsoSurfaces_i
221 ::GetSubMin()
222 {
223   return myIsoSurfacesPL->GetMin();
224 }
225
226 //---------------------------------------------------------------
227 CORBA::Double 
228 VISU::IsoSurfaces_i
229 ::GetSubMax()
230 {
231   return myIsoSurfacesPL->GetMax();
232 }
233
234 //---------------------------------------------------------------
235 void
236 VISU::IsoSurfaces_i
237 ::SetSubRangeFixed(CORBA::Boolean theIsFixed)
238 {
239   VISU::TSetModified aModified(this);
240   
241   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_IsoSurfacesPL, bool>
242                    (GetSpecificPL(), &VISU_IsoSurfacesPL::SetRangeFixed, theIsFixed));
243 }
244
245 //---------------------------------------------------------------
246 CORBA::Boolean
247 VISU::IsoSurfaces_i
248 ::IsSubRangeFixed()
249 {
250   return myIsoSurfacesPL->IsRangeFixed();
251 }
252
253
254 //---------------------------------------------------------------
255 void 
256 VISU::IsoSurfaces_i
257 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
258 {
259   if(!thePipeLine){
260     myIsoSurfacesPL = VISU_IsoSurfacesPL::New();
261   }else
262     myIsoSurfacesPL = dynamic_cast<VISU_IsoSurfacesPL*>(thePipeLine);
263
264   TSuperClass::CreatePipeLine(myIsoSurfacesPL);
265 }
266
267
268 //----------------------------------------------------------------------------
269 void 
270 VISU::IsoSurfaces_i
271 ::DoSetInput(bool theIsInitilizePipe, bool theReInit)
272 {
273   TSuperClass::DoSetInput(theIsInitilizePipe, theReInit);
274   if(theIsInitilizePipe || (!IsTimeStampFixed() && !IsRangeFixed()) || theReInit)
275     SetSubRange(GetSourceMin(), GetSourceMax());
276 }
277
278 //---------------------------------------------------------------
279 bool
280 VISU::IsoSurfaces_i
281 ::CheckIsPossible() 
282 {
283   return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
284 }
285
286 //---------------------------------------------------------------
287 VISU_Actor* VISU::IsoSurfaces_i::CreateActor()
288 {
289   VISU_IsoSurfActor* anActor = VISU_IsoSurfActor::New();
290   try{
291     VISU::Prs3d_i::CreateActor(anActor);
292     anActor->SetBarVisibility(true);
293     anActor->SetVTKMapping(true);
294     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
295     int  aDispMode = aResourceMgr->integerValue("VISU" , "iso_surfaces_represent", 2);
296     anActor->SetRepresentation(aDispMode);
297     UpdateActor(anActor);
298   }catch(...){
299     anActor->Delete();
300     throw ;
301   }
302
303  return anActor;
304 }
305
306 //---------------------------------------------------------------
307 void VISU::IsoSurfaces_i::UpdateActor(VISU_ActorBase* theActor) 
308 {
309   if(VISU_IsoSurfActor* anActor = dynamic_cast<VISU_IsoSurfActor*>(theActor)){
310     anActor->SetLinesLabeled(myIsLabeled, myNbLabels);
311   }
312   TSuperClass::UpdateActor(theActor);
313 }
314
315 //---------------------------------------------------------------
316 void
317 VISU::IsoSurfaces_i
318 ::SetMapScale(double theMapScale)
319 {
320   myIsoSurfacesPL->SetMapScale(theMapScale);
321 }
322
323 //---------------------------------------------------------------
324 CORBA::Boolean VISU::IsoSurfaces_i::IsLabeled()
325 {
326   return myIsLabeled;
327 }
328
329 //---------------------------------------------------------------
330 void VISU::IsoSurfaces_i::ShowLabels(CORBA::Boolean theShow, CORBA::Long theNb)
331 {
332   if ((myIsLabeled == theShow) && (myNbLabels == theNb)) return;
333   VISU::TSetModified aModified(this);
334   myIsLabeled = theShow;
335   myNbLabels = theNb;
336   myParamsTime.Modified();
337 }
338
339 //---------------------------------------------------------------
340 CORBA::Long VISU::IsoSurfaces_i::GetNbLabels()
341 {
342   return myNbLabels;
343 }
344