Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_I / VISU_CutLines_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_CutLines_i.hh"
29 #include "VISU_Prs3dUtils.hh"
30 #include "VISU_Result_i.hh"
31
32 #include "VISU_Actor.h"
33 #include "VISU_CutLinesPL.hxx"
34 #include "VISU_Convertor.hxx"
35 #include "VISU_PipeLineUtils.hxx"
36
37 #include "SUIT_ResourceMgr.h"
38 #include "SALOME_Event.h"
39
40 #include <vtkAppendPolyData.h>
41
42 #ifdef _DEBUG_
43 static int MYDEBUG = 0;
44 #else
45 static int MYDEBUG = 0;
46 #endif
47
48 using namespace std;
49
50 //---------------------------------------------------------------
51 size_t
52 VISU::CutLines_i
53 ::IsPossible(Result_i* theResult, 
54              const std::string& theMeshName, 
55              VISU::Entity theEntity, 
56              const std::string& theFieldName, 
57              CORBA::Long theTimeStampNumber, 
58              bool theIsMemoryCheck)
59 {
60   return TSuperClass::IsPossible(theResult,
61                                  theMeshName,
62                                  theEntity,
63                                  theFieldName,
64                                  theTimeStampNumber,
65                                  theIsMemoryCheck);
66 }
67
68 //---------------------------------------------------------------
69 int VISU::CutLines_i::myNbPresent = 0;
70
71 //---------------------------------------------------------------
72 QString 
73 VISU::CutLines_i::GenerateName() 
74
75   return VISU::GenerateName("CutLines",myNbPresent++);
76 }
77
78 //---------------------------------------------------------------
79 const string VISU::CutLines_i::myComment = "CUTLINES";
80
81 //---------------------------------------------------------------
82 const char* 
83 VISU::CutLines_i
84 ::GetComment() const 
85
86   return myComment.c_str();
87 }
88
89 //----------------------------------------------------------------------------
90 const char*
91 VISU::CutLines_i
92 ::GetIconName()
93 {
94   if (!IsGroupsUsed())
95     return "ICON_TREE_CUT_LINES";
96   else
97     return "ICON_TREE_CUT_LINES_GROUPS";
98 }
99
100 //---------------------------------------------------------------
101 VISU::CutLines_i::
102 CutLines_i(EPublishInStudyMode thePublishInStudyMode) :
103   ColoredPrs3d_i(thePublishInStudyMode),
104   ScalarMap_i(thePublishInStudyMode),
105   CutLinesBase_i(thePublishInStudyMode),
106   myCutLinesPL(NULL)
107 {}
108
109
110 //---------------------------------------------------------------
111 void
112 VISU::CutLines_i
113 ::SameAs(const Prs3d_i* theOrigin)
114 {
115   TSuperClass::SameAs(theOrigin);
116 }
117
118
119 //---------------------------------------------------------------
120 VISU::Storable* 
121 VISU::CutLines_i
122 ::Create(const std::string& theMeshName, 
123          VISU::Entity theEntity,
124          const std::string& theFieldName, 
125          CORBA::Long theTimeStampNumber)
126 {
127   return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
128 }
129
130
131 //---------------------------------------------------------------
132 VISU::Storable* 
133 VISU::CutLines_i
134 ::Restore(SALOMEDS::SObject_ptr theSObject,
135           const Storable::TRestoringMap& theMap)
136 {
137   if(!TSuperClass::Restore(theSObject, theMap))
138     return NULL;
139
140   SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement[0]").toDouble());
141   SetDisplacement2(VISU::Storable::FindValue(theMap,"myDisplacement[1]").toDouble());
142   SetOrientation(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[0]").toInt()),
143                  Storable::FindValue(theMap,"aRot[0][0]").toDouble(),
144                  Storable::FindValue(theMap,"aRot[0][1]").toDouble());
145   SetOrientation2(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[1]").toInt()),
146                   Storable::FindValue(theMap,"aRot[1][0]").toDouble(),
147                   Storable::FindValue(theMap,"aRot[1][1]").toDouble());
148
149   if (VISU::Storable::FindValue(theMap,"myBasePlaneCondition").toInt())
150     SetDefault();
151   else
152     SetBasePlanePosition(VISU::Storable::FindValue(theMap,"myBasePlanePosition").toDouble());
153   
154   QStringList aPosList = VISU::Storable::FindValue(theMap,"myLinePosition").split("|", QString::SkipEmptyParts );
155   QStringList aCondList = VISU::Storable::FindValue(theMap,"myLineCondition").split("|",QString::SkipEmptyParts );
156   for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++)
157     if(aCondList[i].toInt() == 0)
158       SetLinePosition(i,aPosList[i].toDouble());
159
160   return this;
161 }
162
163
164 //---------------------------------------------------------------
165 void
166 VISU::CutLines_i
167 ::ToStream(std::ostringstream& theStr)
168 {
169   TSuperClass::ToStream(theStr);
170
171   Storable::DataToStream( theStr, "myDisplacement[0]", GetDisplacement() );
172   Storable::DataToStream( theStr, "myDisplacement[1]", GetDisplacement2() );
173   Storable::DataToStream( theStr, "myBasePlane[0]",    int(GetOrientationType()) );
174   Storable::DataToStream( theStr, "myBasePlane[1]",    int(GetOrientationType2()) );
175   Storable::DataToStream( theStr, "aRot[0][0]",        GetRotateX() );
176   Storable::DataToStream( theStr, "aRot[0][1]",        GetRotateY() );
177   Storable::DataToStream( theStr, "aRot[1][0]",        GetRotateX2() );
178   Storable::DataToStream( theStr, "aRot[1][1]",        GetRotateY2() );
179   Storable::DataToStream( theStr, "myBasePlanePosition", GetBasePlanePosition() );
180   Storable::DataToStream( theStr, "myBasePlaneCondition", IsDefault() );
181
182   QString aStrPos, aStrCon;
183   for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++){
184     aStrPos.append(QString::number(GetLinePosition(i)) + "|");
185     aStrCon.append(QString::number(IsDefaultPosition(i)) + "|");
186   }
187
188   Storable::DataToStream( theStr, "myLinePosition",  (const char*)aStrPos.toLatin1());
189   Storable::DataToStream( theStr, "myLineCondition", (const char*)aStrCon.toLatin1());
190 }
191
192
193 //---------------------------------------------------------------
194 VISU::CutLines_i
195 ::~CutLines_i()
196 {
197   if(MYDEBUG) MESSAGE("CutLines_i::~CutLines_i()");
198 }
199
200
201 //---------------------------------------------------------------
202 void
203 VISU::CutLines_i
204 ::SetOrientation(VISU::CutPlanes::Orientation theOrient,
205                  CORBA::Double theXAngle, 
206                  CORBA::Double theYAngle)
207 {
208   struct TEvent: public SALOME_Event 
209   {
210     VISU_CutLinesPL* myCutLinesPL;
211     CORBA::Double myXAngle, myYAngle;
212     VISU::CutPlanes::Orientation myOrient;
213     TEvent(VISU_CutLinesPL* theCutLines, 
214            VISU::CutPlanes::Orientation theOrient,
215            CORBA::Double theXAngle, 
216            CORBA::Double theYAngle):
217       myCutLinesPL(theCutLines), 
218       myOrient(theOrient), 
219       myXAngle(theXAngle), 
220       myYAngle(theYAngle)
221     {}
222
223     virtual
224     void
225     Execute()
226     {
227       myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(myOrient),
228                                    myXAngle, 
229                                    myYAngle);
230     }
231   };
232
233   VISU::TSetModified aModified(this);
234
235   ProcessVoidEvent(new TEvent(myCutLinesPL, theOrient, theXAngle, theYAngle));
236 }
237
238 //---------------------------------------------------------------
239 void 
240 VISU::CutLines_i
241 ::SetOrientation2(VISU::CutPlanes::Orientation theOrient,
242                   CORBA::Double theXAngle, 
243                   CORBA::Double theYAngle)
244 {
245   struct TEvent: public SALOME_Event 
246   {
247     VISU_CutLinesPL* myCutLinesPL;
248     CORBA::Double myXAngle, myYAngle;
249     VISU::CutPlanes::Orientation myOrient;
250     TEvent(VISU_CutLinesPL* theCutLines, 
251            VISU::CutPlanes::Orientation theOrient,
252            CORBA::Double theXAngle, 
253            CORBA::Double theYAngle):
254       myCutLinesPL(theCutLines), 
255       myOrient(theOrient), 
256       myXAngle(theXAngle), 
257       myYAngle(theYAngle)
258     {}
259
260     virtual
261     void
262     Execute()
263     {
264       myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(myOrient),
265                                    myXAngle, 
266                                    myYAngle,
267                                    1);
268     }
269   };
270
271   VISU::TSetModified aModified(this);
272
273   ProcessVoidEvent(new TEvent(myCutLinesPL, theOrient, theXAngle, theYAngle));
274 }
275
276 //---------------------------------------------------------------
277 VISU::CutPlanes::Orientation 
278 VISU::CutLines_i
279 ::GetOrientationType() 
280
281   return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation());
282 }
283
284 //---------------------------------------------------------------
285 VISU::CutPlanes::Orientation 
286 VISU::CutLines_i
287 ::GetOrientationType2() 
288
289   return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation(1));
290 }
291
292 //---------------------------------------------------------------
293 CORBA::Double
294 VISU::CutLines_i
295 ::GetRotateX()
296 {
297   return myCutLinesPL->GetRotateX();
298 }
299
300 //---------------------------------------------------------------
301 CORBA::Double 
302 VISU::CutLines_i
303 ::GetRotateY()
304 {
305   return myCutLinesPL->GetRotateY();
306 }
307
308
309 //---------------------------------------------------------------
310 CORBA::Double 
311 VISU::CutLines_i
312 ::GetRotateX2()
313 {
314   return myCutLinesPL->GetRotateX(1);
315 }
316
317 //---------------------------------------------------------------
318 CORBA::Double 
319 VISU::CutLines_i
320 ::GetRotateY2()
321 {
322   return myCutLinesPL->GetRotateY(1);
323 }
324
325
326 //---------------------------------------------------------------
327 void
328 VISU::CutLines_i
329 ::SetDisplacement(CORBA::Double theDisp) 
330
331   VISU::TSetModified aModified(this);
332
333   ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, vtkFloatingPointType, int>
334                    (GetSpecificPL(), &VISU_CutLinesPL::SetDisplacement, theDisp, 0));
335 }
336
337 //---------------------------------------------------------------
338 void
339 VISU::CutLines_i
340 ::SetDisplacement2(CORBA::Double theDisp) 
341
342   VISU::TSetModified aModified(this);
343
344   ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, vtkFloatingPointType, int>
345                    (GetSpecificPL(), &VISU_CutLinesPL::SetDisplacement, theDisp, 1));
346 }
347
348
349 //---------------------------------------------------------------
350 CORBA::Double 
351 VISU::CutLines_i
352 ::GetDisplacement() 
353
354   return myCutLinesPL->GetDisplacement();
355 }
356
357 //---------------------------------------------------------------
358 CORBA::Double 
359 VISU::CutLines_i
360 ::GetDisplacement2() 
361
362   return myCutLinesPL->GetDisplacement(1);
363 }
364
365
366 //---------------------------------------------------------------
367 void 
368 VISU::CutLines_i
369 ::SetBasePlanePosition(CORBA::Double thePlanePosition)
370 {
371   VISU::TSetModified aModified(this);
372
373   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_CutLinesPL, vtkFloatingPointType>
374                    (GetSpecificPL(), &VISU_CutLinesPL::SetPosition, thePlanePosition));
375 }
376
377 //---------------------------------------------------------------
378 CORBA::Double 
379 VISU::CutLines_i
380 ::GetBasePlanePosition()
381
382   return myCutLinesPL->GetPosition();
383 }
384
385 //---------------------------------------------------------------
386 void 
387 VISU::CutLines_i
388 ::SetLinePosition(CORBA::Long thePlaneNumber, 
389                   CORBA::Double thePlanePosition)
390 {
391   VISU::TSetModified aModified(this);
392
393   ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, int, vtkFloatingPointType>
394                    (GetSpecificPL(), &VISU_CutLinesPL::SetPartPosition, thePlaneNumber, thePlanePosition));
395 }
396
397 //---------------------------------------------------------------
398 CORBA::Double 
399 VISU::CutLines_i
400 ::GetLinePosition(CORBA::Long thePlaneNumber)
401
402   return myCutLinesPL->GetPartPosition(thePlaneNumber,1);
403 }
404
405
406 //---------------------------------------------------------------
407 void
408 VISU::CutLines_i
409 ::SetDefault()
410 {
411   VISU::TSetModified aModified(this);
412
413   ProcessVoidEvent(new TVoidMemFunEvent<VISU_CutLinesPL>
414                    (GetSpecificPL(), &VISU_CutLinesPL::SetDefault));
415 }
416
417 //---------------------------------------------------------------
418 CORBA::Boolean
419 VISU::CutLines_i
420 ::IsDefault()
421
422   return myCutLinesPL->IsDefault();
423 }
424
425 //---------------------------------------------------------------
426 void
427 VISU::CutLines_i
428 ::SetDefaultPosition(CORBA::Long thePlaneNumber)
429 {
430   VISU::TSetModified aModified(this);
431
432   ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_CutLinesPL, int>
433                    (GetSpecificPL(), &VISU_CutLinesPL::SetPartDefault, thePlaneNumber));
434 }
435
436 //---------------------------------------------------------------
437 CORBA::Boolean
438 VISU::CutLines_i
439 ::IsDefaultPosition(CORBA::Long thePlaneNumber)
440
441   return myCutLinesPL->IsPartDefault(thePlaneNumber);
442 }
443
444 //---------------------------------------------------------------
445 void
446 VISU::CutLines_i
447 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
448 {
449   if(!thePipeLine){
450     myCutLinesPL = VISU_CutLinesPL::New();
451   }else
452     myCutLinesPL = dynamic_cast<VISU_CutLinesPL*>(thePipeLine);
453
454   TSuperClass::CreatePipeLine(myCutLinesPL);
455 }
456
457
458 //----------------------------------------------------------------------------
459 bool
460 VISU::CutLines_i
461 ::CheckIsPossible() 
462 {
463   return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
464 }
465
466
467 //---------------------------------------------------------------
468 VISU_Actor* 
469 VISU::CutLines_i
470 ::CreateActor()
471 {
472   if(VISU_Actor* anActor = TSuperClass::CreateActor()){
473     anActor->SetVTKMapping(true);
474     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
475     int aDispMode = aResourceMgr->integerValue("VISU" , "cut_lines_represent", 2);
476     anActor->SetRepresentation(aDispMode);
477     return anActor;
478   }
479   return NULL;
480 }