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