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