Salome HOME
cea07c35fbd21cd97246f2b97f24952e1f19b2e3
[modules/visu.git] / src / VISU_I / VISU_Plot3D_i.cc
1 //  Copyright (C) 2007-2008  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 #include "VISU_Plot3D_i.hh"
23 #include "VISU_Prs3dUtils.hh"
24
25 #include "VISU_Result_i.hh"
26 #include "VISU_Plot3DPL.hxx"
27 #include "VISU_Actor.h"
28
29 #include "SUIT_ResourceMgr.h"
30 #include "SALOME_Event.h"
31
32 #ifdef _DEBUG_
33 static int MYDEBUG = 0;
34 #else
35 static int MYDEBUG = 0;
36 #endif
37
38 using namespace std;
39
40 //---------------------------------------------------------------
41 size_t 
42 VISU::Plot3D_i
43 ::IsPossible(Result_i* theResult, 
44              const std::string& theMeshName, 
45              VISU::Entity theEntity,
46              const std::string& theFieldName, 
47              CORBA::Long theTimeStampNumber,
48              bool theIsMemoryCheck)
49 {
50   return TSuperClass::IsPossible(theResult,
51                                  theMeshName,
52                                  theEntity,
53                                  theFieldName,
54                                  theTimeStampNumber,
55                                  theIsMemoryCheck);
56 }
57
58 //---------------------------------------------------------------
59 int VISU::Plot3D_i::myNbPresent = 0;
60
61 //---------------------------------------------------------------
62 QString 
63 VISU::Plot3D_i
64 ::GenerateName() 
65
66   return VISU::GenerateName("Plot3D",myNbPresent++); 
67 }
68
69 //---------------------------------------------------------------
70 const string VISU::Plot3D_i::myComment = "PLOT3D";
71
72 //---------------------------------------------------------------
73 const char* 
74 VISU::Plot3D_i
75 ::GetComment() const 
76
77   return myComment.c_str(); 
78 }
79
80 //---------------------------------------------------------------
81 const char*
82 VISU::Plot3D_i
83 ::GetIconName()
84 {
85   if (!IsGroupsUsed())
86     return "ICON_TREE_PLOT_3D";
87   else
88     return "ICON_TREE_PLOT_3D_GROUPS";
89 }
90
91 //---------------------------------------------------------------
92 VISU::Plot3D_i
93 ::Plot3D_i(EPublishInStudyMode thePublishInStudyMode) :
94   ColoredPrs3d_i(thePublishInStudyMode),
95   ScalarMap_i(thePublishInStudyMode),
96   myPlot3DPL(NULL)
97 {}
98
99
100 //---------------------------------------------------------------
101 VISU::Storable* 
102 VISU::Plot3D_i
103 ::Create(const std::string& theMeshName, 
104          VISU::Entity theEntity,
105          const std::string& theFieldName, 
106          CORBA::Long theTimeStampNumber)
107 {
108   return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
109 }
110
111
112 //---------------------------------------------------------------
113 VISU::Storable* 
114 VISU::Plot3D_i
115 ::Restore(SALOMEDS::SObject_ptr theSObject,
116           const Storable::TRestoringMap& theMap)
117 {
118   if(!TSuperClass::Restore(theSObject, theMap))
119     return NULL;
120
121   SetOrientation(VISU::Plot3D::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane").toInt()),
122                  Storable::FindValue(theMap,"aRot[0]").toDouble(),
123                  Storable::FindValue(theMap,"aRot[1]").toDouble());
124   SetPlanePosition(VISU::Storable::FindValue(theMap,"myPlanePosition").toDouble(),
125                    VISU::Storable::FindValue(theMap,"myPlaneCondition").toInt());
126   SetScaleFactor(VISU::Storable::FindValue(theMap,"myScaleFactor").toDouble());
127   SetContourPrs(VISU::Storable::FindValue(theMap,"myContourPrs").toInt());
128   SetNbOfContours(VISU::Storable::FindValue(theMap,"myNbOfContours").toInt());
129
130   return this;
131 }
132
133
134 //---------------------------------------------------------------
135 void
136 VISU::Plot3D_i
137 ::ToStream(std::ostringstream& theStr)
138 {
139   TSuperClass::ToStream(theStr);
140
141   Storable::DataToStream(theStr, "myBasePlane", int(GetOrientationType()));
142   Storable::DataToStream(theStr, "aRot[0]", GetRotateX());
143   Storable::DataToStream(theStr, "aRot[1]", GetRotateY());
144   Storable::DataToStream(theStr, "myPlanePosition", GetPlanePosition());
145   Storable::DataToStream(theStr, "myPlaneCondition", int(IsPositionRelative()));
146   Storable::DataToStream(theStr, "myScaleFactor", GetScaleFactor());
147   Storable::DataToStream(theStr, "myContourPrs", int(GetIsContourPrs()));
148   Storable::DataToStream(theStr, "myNbOfContours", int(GetNbOfContours()));
149 }
150
151
152 //---------------------------------------------------------------
153 VISU::Plot3D_i
154 ::~Plot3D_i()
155 {
156   if(MYDEBUG) MESSAGE("Plot3D_i::~Plot3D_i()");
157 }
158
159
160 //---------------------------------------------------------------
161 void
162 VISU::Plot3D_i
163 ::SetOrientation(VISU::Plot3D::Orientation theOrient,
164                  CORBA::Double theXAngle, 
165                  CORBA::Double theYAngle)
166 {
167   struct TEvent: public SALOME_Event 
168   {
169     VISU_Plot3DPL* myPipeLine;
170     VISU_CutPlanesPL::PlaneOrientation myOrient;
171     CORBA::Double myXAngle;
172     CORBA::Double myYAngle;
173
174     TEvent(VISU_Plot3DPL* thePipeLine,
175            VISU_CutPlanesPL::PlaneOrientation theOrient,
176            CORBA::Double theXAngle, 
177            CORBA::Double theYAngle):
178       myPipeLine(thePipeLine),
179       myOrient(theOrient),
180       myXAngle(theXAngle),
181       myYAngle(theYAngle)
182     {}
183
184     virtual
185     void
186     Execute()
187     {
188       myPipeLine->SetOrientation(myOrient,
189                                  myXAngle,
190                                  myYAngle);
191     }
192   };
193
194   VISU::TSetModified aModified(this);
195   
196   ProcessVoidEvent(new TEvent(GetSpecificPL(),
197                               VISU_CutPlanesPL::PlaneOrientation(theOrient),
198                               theXAngle,
199                               theYAngle));
200 }
201
202
203 //---------------------------------------------------------------
204 VISU::Plot3D::Orientation
205 VISU::Plot3D_i
206 ::GetOrientationType()
207 {
208   return VISU::Plot3D::Orientation(myPlot3DPL->GetPlaneOrientation());
209 }
210
211
212 //---------------------------------------------------------------
213 CORBA::Double
214 VISU::Plot3D_i
215 ::GetRotateX()
216 {
217   return myPlot3DPL->GetRotateX();
218 }
219
220
221 //---------------------------------------------------------------
222 CORBA::Double 
223 VISU::Plot3D_i
224 ::GetRotateY()
225 {
226   return myPlot3DPL->GetRotateY();
227 }
228
229
230 //---------------------------------------------------------------
231 void
232 VISU::Plot3D_i
233 ::SetPlanePosition(CORBA::Double  thePlanePosition,
234                    CORBA::Boolean theIsRelative)
235 {
236   VISU::TSetModified aModified(this);
237   
238   ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_Plot3DPL, vtkFloatingPointType, bool>
239                    (GetSpecificPL(), &VISU_Plot3DPL::SetPlanePosition, thePlanePosition, theIsRelative));
240 }
241
242
243 //---------------------------------------------------------------
244 CORBA::Double
245 VISU::Plot3D_i
246 ::GetPlanePosition()
247 {
248   return myPlot3DPL->GetPlanePosition();
249 }
250
251
252 //---------------------------------------------------------------
253 CORBA::Boolean
254 VISU::Plot3D_i
255 ::IsPositionRelative()
256 {
257   return myPlot3DPL->IsPositionRelative();
258 }
259
260
261 //---------------------------------------------------------------
262 void
263 VISU::Plot3D_i
264 ::SetScaleFactor(CORBA::Double theScaleFactor)
265 {
266   VISU::TSetModified aModified(this);
267   
268   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_Plot3DPL, vtkFloatingPointType>
269                    (GetSpecificPL(), &VISU_Plot3DPL::SetScaleFactor, theScaleFactor));
270 }
271
272
273 //---------------------------------------------------------------
274 CORBA::Double
275 VISU::Plot3D_i
276 ::GetScaleFactor()
277 {
278   return myPlot3DPL->GetScaleFactor();
279 }
280
281
282 //---------------------------------------------------------------
283 void
284 VISU::Plot3D_i
285 ::SetNbOfContours(CORBA::Long theNb)
286 {
287   VISU::TSetModified aModified(this);
288   
289   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_Plot3DPL, int>
290                    (GetSpecificPL(), &VISU_Plot3DPL::SetNumberOfContours, theNb));
291 }
292
293
294 //---------------------------------------------------------------
295 CORBA::Long
296 VISU::Plot3D_i
297 ::GetNbOfContours()
298 {
299   return myPlot3DPL->GetNumberOfContours();
300 }
301
302
303 //---------------------------------------------------------------
304 void
305 VISU::Plot3D_i
306 ::SetContourPrs(CORBA::Boolean theIsContourPrs)
307 {
308   VISU::TSetModified aModified(this);
309   
310   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_Plot3DPL, bool>
311                    (GetSpecificPL(), &VISU_Plot3DPL::SetContourPrs, theIsContourPrs));
312 }
313
314
315 //---------------------------------------------------------------
316 CORBA::Boolean
317 VISU::Plot3D_i
318 ::GetIsContourPrs()
319 {
320   return myPlot3DPL->GetIsContourPrs();
321 }
322
323
324 //---------------------------------------------------------------
325 void
326 VISU::Plot3D_i
327 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
328 {
329   if(!thePipeLine){
330     myPlot3DPL = VISU_Plot3DPL::New();
331   }else
332     myPlot3DPL = dynamic_cast<VISU_Plot3DPL*>(thePipeLine);
333
334   TSuperClass::CreatePipeLine(myPlot3DPL);
335 }
336
337
338 //---------------------------------------------------------------
339 bool
340 VISU::Plot3D_i
341 ::CheckIsPossible() 
342 {
343   return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
344 }
345
346 //---------------------------------------------------------------
347 VISU_Actor* 
348 VISU::Plot3D_i
349 ::CreateActor()
350 {
351   if(VISU_Actor* anActor = TSuperClass::CreateActor()){
352     anActor->SetVTKMapping(true);
353     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
354     int aDispMode = aResourceMgr->integerValue("VISU", "plot3d_represent", 2);
355     anActor->SetRepresentation(aDispMode);
356     return anActor;
357   }
358   return NULL;
359 }
360
361
362 //---------------------------------------------------------------
363 void
364 VISU::Plot3D_i
365 ::SetMapScale(double theMapScale)
366 {
367   myPlot3DPL->SetMapScale(theMapScale);
368 }