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