Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_I / VISU_CutSegment_i.cc
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  File   : VISU_CutSegment_i.cc
21 //  Author : Oleg UVAROV
22 //  Module : VISU
23 //
24 #include "VISU_CutSegment_i.hh"
25 #include "VISU_Prs3dUtils.hh"
26 #include "VISU_Result_i.hh"
27
28 #include "VISU_Actor.h"
29 #include "VISU_CutSegmentPL.hxx"
30 #include "VISU_Convertor.hxx"
31 #include "VISU_PipeLineUtils.hxx"
32
33 #include "SUIT_ResourceMgr.h"
34 #include "SALOME_Event.h"
35
36 #include <vtkAppendPolyData.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::CutSegment_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,
57                                  theMeshName,
58                                  theEntity,
59                                  theFieldName,
60                                  theTimeStampNumber,
61                                  theIsMemoryCheck);
62 }
63
64 //---------------------------------------------------------------
65 int VISU::CutSegment_i::myNbPresent = 0;
66
67 //---------------------------------------------------------------
68 QString 
69 VISU::CutSegment_i::GenerateName() 
70
71   return VISU::GenerateName("CutSegment",myNbPresent++);
72 }
73
74 //---------------------------------------------------------------
75 const string VISU::CutSegment_i::myComment = "CUTSEGMENT";
76
77 //---------------------------------------------------------------
78 const char* 
79 VISU::CutSegment_i
80 ::GetComment() const 
81
82   return myComment.c_str();
83 }
84
85 //----------------------------------------------------------------------------
86 const char*
87 VISU::CutSegment_i
88 ::GetIconName()
89 {
90   if (!IsGroupsUsed())
91     return "ICON_TREE_CUT_SEGMENT";
92   else
93     return "ICON_TREE_CUT_SEGMENT_GROUPS";
94 }
95
96 //---------------------------------------------------------------
97 VISU::CutSegment_i::
98 CutSegment_i(EPublishInStudyMode thePublishInStudyMode) :
99   ColoredPrs3d_i(thePublishInStudyMode),
100   ScalarMap_i(thePublishInStudyMode),
101   CutLinesBase_i(thePublishInStudyMode),
102   myCutSegmentPL(NULL)
103 {}
104
105
106 //---------------------------------------------------------------
107 void
108 VISU::CutSegment_i
109 ::SameAs(const Prs3d_i* theOrigin)
110 {
111   TSuperClass::SameAs(theOrigin);
112 }
113
114
115 //---------------------------------------------------------------
116 VISU::Storable* 
117 VISU::CutSegment_i
118 ::Create(const std::string& theMeshName, 
119          VISU::Entity theEntity,
120          const std::string& theFieldName, 
121          CORBA::Long theTimeStampNumber)
122 {
123   return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
124 }
125
126
127 //---------------------------------------------------------------
128 VISU::Storable* 
129 VISU::CutSegment_i
130 ::Restore(SALOMEDS::SObject_ptr theSObject,
131           const Storable::TRestoringMap& theMap)
132 {
133   if(!TSuperClass::Restore(theSObject, theMap))
134     return NULL;
135
136   SetPoint1(VISU::Storable::FindValue(theMap,"myPoint1[0]").toDouble(),
137             VISU::Storable::FindValue(theMap,"myPoint1[1]").toDouble(),
138             VISU::Storable::FindValue(theMap,"myPoint1[2]").toDouble());
139   SetPoint2(VISU::Storable::FindValue(theMap,"myPoint2[0]").toDouble(),
140             VISU::Storable::FindValue(theMap,"myPoint2[1]").toDouble(),
141             VISU::Storable::FindValue(theMap,"myPoint2[2]").toDouble());
142
143   return this;
144 }
145
146
147 //---------------------------------------------------------------
148 void
149 VISU::CutSegment_i
150 ::ToStream(std::ostringstream& theStr)
151 {
152   TSuperClass::ToStream(theStr);
153
154   double aCoord[3];
155   GetPoint1( aCoord[0], aCoord[1], aCoord[2] );
156   Storable::DataToStream( theStr, "myPoint1[0]",       aCoord[0] );
157   Storable::DataToStream( theStr, "myPoint1[1]",       aCoord[1] );
158   Storable::DataToStream( theStr, "myPoint1[2]",       aCoord[2] );
159
160   GetPoint2( aCoord[0], aCoord[1], aCoord[2] );
161   Storable::DataToStream( theStr, "myPoint2[0]",       aCoord[0] );
162   Storable::DataToStream( theStr, "myPoint2[1]",       aCoord[1] );
163   Storable::DataToStream( theStr, "myPoint2[2]",       aCoord[2] );
164 }
165
166
167 //---------------------------------------------------------------
168 VISU::CutSegment_i
169 ::~CutSegment_i()
170 {
171   if(MYDEBUG) MESSAGE("CutSegment_i::~CutSegment_i()");
172 }
173
174
175 //---------------------------------------------------------------
176 struct TSetPoint1Event: public SALOME_Event 
177 {
178   VISU_CutSegmentPL* myCutSegmentPL;
179   CORBA::Double myX, myY, myZ;
180   TSetPoint1Event(VISU_CutSegmentPL* theCutSegment, 
181          CORBA::Double theX, 
182          CORBA::Double theY,
183          CORBA::Double theZ):
184     myCutSegmentPL(theCutSegment), 
185     myX(theX), 
186     myY(theY),
187     myZ(theZ)
188   {}
189
190   virtual
191   void
192   Execute()
193   {
194     myCutSegmentPL->SetPoint1(myX, myY, myZ);
195   }
196 };
197
198 void
199 VISU::CutSegment_i
200 ::SetPoint1(CORBA::Double theX,
201             CORBA::Double theY,
202             CORBA::Double theZ)
203 {
204   VISU::TSetModified aModified(this);
205
206   ProcessVoidEvent(new TSetPoint1Event(myCutSegmentPL, theX, theY, theZ));
207 }
208
209
210 //---------------------------------------------------------------
211 void
212 VISU::CutSegment_i
213 ::GetPoint1(CORBA::Double& theX,
214             CORBA::Double& theY,
215             CORBA::Double& theZ)
216 {
217   myCutSegmentPL->GetPoint1(theX, theY, theZ);
218 }
219
220
221 //---------------------------------------------------------------
222 struct TSetPoint2Event: public SALOME_Event 
223 {
224   VISU_CutSegmentPL* myCutSegmentPL;
225   CORBA::Double myX, myY, myZ;
226   TSetPoint2Event(VISU_CutSegmentPL* theCutSegment, 
227          CORBA::Double theX, 
228          CORBA::Double theY,
229          CORBA::Double theZ):
230     myCutSegmentPL(theCutSegment), 
231     myX(theX), 
232     myY(theY),
233     myZ(theZ)
234   {}
235
236   virtual
237   void
238   Execute()
239   {
240     myCutSegmentPL->SetPoint2(myX, myY, myZ);
241   }
242 };
243
244 void
245 VISU::CutSegment_i
246 ::SetPoint2(CORBA::Double theX,
247             CORBA::Double theY,
248             CORBA::Double theZ)
249 {
250   VISU::TSetModified aModified(this);
251
252   ProcessVoidEvent(new TSetPoint2Event(myCutSegmentPL, theX, theY, theZ));
253 }
254
255
256 //---------------------------------------------------------------
257 void
258 VISU::CutSegment_i
259 ::GetPoint2(CORBA::Double& theX,
260             CORBA::Double& theY,
261             CORBA::Double& theZ)
262 {
263   myCutSegmentPL->GetPoint2(theX, theY, theZ);
264 }
265
266
267 //---------------------------------------------------------------
268 void
269 VISU::CutSegment_i
270 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
271 {
272   if(!thePipeLine){
273     myCutSegmentPL = VISU_CutSegmentPL::New();
274   }else
275     myCutSegmentPL = dynamic_cast<VISU_CutSegmentPL*>(thePipeLine);
276
277   TSuperClass::CreatePipeLine(myCutSegmentPL);
278 }
279
280
281 //----------------------------------------------------------------------------
282 bool
283 VISU::CutSegment_i
284 ::CheckIsPossible() 
285 {
286   return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
287 }
288
289
290 //---------------------------------------------------------------
291 VISU_Actor* 
292 VISU::CutSegment_i
293 ::CreateActor()
294 {
295   if(VISU_Actor* anActor = TSuperClass::CreateActor()){
296     anActor->SetVTKMapping(true);
297     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
298     int aDispMode = aResourceMgr->integerValue("VISU", "cut_segment_represent", 2);
299     anActor->SetRepresentation(aDispMode);
300     return anActor;
301   }
302   return NULL;
303 }