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