Salome HOME
4e01b20bbe909c375cf635c681f9222a3a23a94f
[modules/visu.git] / src / VISU_I / VISU_CutSegment_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 //  File   : VISU_CutSegment_i.cc
23 //  Author : Oleg UVAROV
24 //  Module : VISU
25 //
26 #include "VISU_CutSegment_i.hh"
27 #include "VISU_Prs3dUtils.hh"
28 #include "VISU_Result_i.hh"
29
30 #include "VISU_Actor.h"
31 #include "VISU_CutSegmentPL.hxx"
32 #include "VISU_Convertor.hxx"
33 #include "VISU_PipeLineUtils.hxx"
34
35 #include "SUIT_ResourceMgr.h"
36 #include "SALOME_Event.h"
37
38 #include <vtkAppendPolyData.h>
39
40 #ifdef _DEBUG_
41 static int MYDEBUG = 0;
42 #else
43 static int MYDEBUG = 0;
44 #endif
45
46 using namespace std;
47
48 //---------------------------------------------------------------
49 size_t
50 VISU::CutSegment_i
51 ::IsPossible(Result_i* theResult, 
52              const std::string& theMeshName, 
53              VISU::Entity theEntity, 
54              const std::string& theFieldName, 
55              CORBA::Long theTimeStampNumber, 
56              bool theIsMemoryCheck)
57 {
58   return TSuperClass::IsPossible(theResult,
59                                  theMeshName,
60                                  theEntity,
61                                  theFieldName,
62                                  theTimeStampNumber,
63                                  theIsMemoryCheck);
64 }
65
66 //---------------------------------------------------------------
67 int VISU::CutSegment_i::myNbPresent = 0;
68
69 //---------------------------------------------------------------
70 QString 
71 VISU::CutSegment_i::GenerateName() 
72
73   return VISU::GenerateName("CutSegment",myNbPresent++);
74 }
75
76 //---------------------------------------------------------------
77 const string VISU::CutSegment_i::myComment = "CUTSEGMENT";
78
79 //---------------------------------------------------------------
80 const char* 
81 VISU::CutSegment_i
82 ::GetComment() const 
83
84   return myComment.c_str();
85 }
86
87 //----------------------------------------------------------------------------
88 const char*
89 VISU::CutSegment_i
90 ::GetIconName()
91 {
92   if (!IsGroupsUsed())
93     return "ICON_TREE_CUT_SEGMENT";
94   else
95     return "ICON_TREE_CUT_SEGMENT_GROUPS";
96 }
97
98 //---------------------------------------------------------------
99 VISU::CutSegment_i::
100 CutSegment_i(EPublishInStudyMode thePublishInStudyMode) :
101   ColoredPrs3d_i(thePublishInStudyMode),
102   ScalarMap_i(thePublishInStudyMode),
103   CutLinesBase_i(thePublishInStudyMode),
104   myCutSegmentPL(NULL)
105 {}
106
107
108 //---------------------------------------------------------------
109 void
110 VISU::CutSegment_i
111 ::SameAs(const Prs3d_i* theOrigin)
112 {
113   TSuperClass::SameAs(theOrigin);
114 }
115
116
117 //---------------------------------------------------------------
118 VISU::Storable* 
119 VISU::CutSegment_i
120 ::Create(const std::string& theMeshName, 
121          VISU::Entity theEntity,
122          const std::string& theFieldName, 
123          CORBA::Long theTimeStampNumber)
124 {
125   return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
126 }
127
128
129 //---------------------------------------------------------------
130 VISU::Storable* 
131 VISU::CutSegment_i
132 ::Restore(SALOMEDS::SObject_ptr theSObject,
133           const Storable::TRestoringMap& theMap)
134 {
135   if(!TSuperClass::Restore(theSObject, theMap))
136     return NULL;
137
138   SetPoint1(VISU::Storable::FindValue(theMap,"myPoint1[0]").toDouble(),
139             VISU::Storable::FindValue(theMap,"myPoint1[1]").toDouble(),
140             VISU::Storable::FindValue(theMap,"myPoint1[2]").toDouble());
141   SetPoint2(VISU::Storable::FindValue(theMap,"myPoint2[0]").toDouble(),
142             VISU::Storable::FindValue(theMap,"myPoint2[1]").toDouble(),
143             VISU::Storable::FindValue(theMap,"myPoint2[2]").toDouble());
144
145   return this;
146 }
147
148
149 //---------------------------------------------------------------
150 void
151 VISU::CutSegment_i
152 ::ToStream(std::ostringstream& theStr)
153 {
154   TSuperClass::ToStream(theStr);
155
156   double aCoord[3];
157   GetPoint1( aCoord[0], aCoord[1], aCoord[2] );
158   Storable::DataToStream( theStr, "myPoint1[0]",       aCoord[0] );
159   Storable::DataToStream( theStr, "myPoint1[1]",       aCoord[1] );
160   Storable::DataToStream( theStr, "myPoint1[2]",       aCoord[2] );
161
162   GetPoint2( aCoord[0], aCoord[1], aCoord[2] );
163   Storable::DataToStream( theStr, "myPoint2[0]",       aCoord[0] );
164   Storable::DataToStream( theStr, "myPoint2[1]",       aCoord[1] );
165   Storable::DataToStream( theStr, "myPoint2[2]",       aCoord[2] );
166 }
167
168
169 //---------------------------------------------------------------
170 VISU::CutSegment_i
171 ::~CutSegment_i()
172 {
173   if(MYDEBUG) MESSAGE("CutSegment_i::~CutSegment_i()");
174 }
175
176
177 //---------------------------------------------------------------
178 struct TSetPoint1Event: public SALOME_Event 
179 {
180   VISU_CutSegmentPL* myCutSegmentPL;
181   CORBA::Double myX, myY, myZ;
182   TSetPoint1Event(VISU_CutSegmentPL* theCutSegment, 
183          CORBA::Double theX, 
184          CORBA::Double theY,
185          CORBA::Double theZ):
186     myCutSegmentPL(theCutSegment), 
187     myX(theX), 
188     myY(theY),
189     myZ(theZ)
190   {}
191
192   virtual
193   void
194   Execute()
195   {
196     myCutSegmentPL->SetPoint1(myX, myY, myZ);
197   }
198 };
199
200 void
201 VISU::CutSegment_i
202 ::SetPoint1(CORBA::Double theX,
203             CORBA::Double theY,
204             CORBA::Double theZ)
205 {
206   VISU::TSetModified aModified(this);
207
208   ProcessVoidEvent(new TSetPoint1Event(myCutSegmentPL, theX, theY, theZ));
209 }
210
211
212 //---------------------------------------------------------------
213 void
214 VISU::CutSegment_i
215 ::GetPoint1(CORBA::Double& theX,
216             CORBA::Double& theY,
217             CORBA::Double& theZ)
218 {
219   myCutSegmentPL->GetPoint1(theX, theY, theZ);
220 }
221
222
223 //---------------------------------------------------------------
224 struct TSetPoint2Event: public SALOME_Event 
225 {
226   VISU_CutSegmentPL* myCutSegmentPL;
227   CORBA::Double myX, myY, myZ;
228   TSetPoint2Event(VISU_CutSegmentPL* theCutSegment, 
229          CORBA::Double theX, 
230          CORBA::Double theY,
231          CORBA::Double theZ):
232     myCutSegmentPL(theCutSegment), 
233     myX(theX), 
234     myY(theY),
235     myZ(theZ)
236   {}
237
238   virtual
239   void
240   Execute()
241   {
242     myCutSegmentPL->SetPoint2(myX, myY, myZ);
243   }
244 };
245
246 void
247 VISU::CutSegment_i
248 ::SetPoint2(CORBA::Double theX,
249             CORBA::Double theY,
250             CORBA::Double theZ)
251 {
252   VISU::TSetModified aModified(this);
253
254   ProcessVoidEvent(new TSetPoint2Event(myCutSegmentPL, theX, theY, theZ));
255 }
256
257
258 //---------------------------------------------------------------
259 void
260 VISU::CutSegment_i
261 ::GetPoint2(CORBA::Double& theX,
262             CORBA::Double& theY,
263             CORBA::Double& theZ)
264 {
265   myCutSegmentPL->GetPoint2(theX, theY, theZ);
266 }
267
268
269 //---------------------------------------------------------------
270 void
271 VISU::CutSegment_i
272 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
273 {
274   if(!thePipeLine){
275     myCutSegmentPL = VISU_CutSegmentPL::New();
276   }else
277     myCutSegmentPL = dynamic_cast<VISU_CutSegmentPL*>(thePipeLine);
278
279   TSuperClass::CreatePipeLine(myCutSegmentPL);
280 }
281
282
283 //----------------------------------------------------------------------------
284 bool
285 VISU::CutSegment_i
286 ::CheckIsPossible() 
287 {
288   return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
289 }
290
291
292 //---------------------------------------------------------------
293 VISU_Actor* 
294 VISU::CutSegment_i
295 ::CreateActor()
296 {
297   if(VISU_Actor* anActor = TSuperClass::CreateActor()){
298     anActor->SetVTKMapping(true);
299     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
300     int aDispMode = aResourceMgr->integerValue("VISU", "cut_segment_represent", 2);
301     anActor->SetRepresentation(aDispMode);
302     return anActor;
303   }
304   return NULL;
305 }