1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISU_PrsObject_i.cxx
25 // Author : Alexey PETROV
28 #include "VISU_CutLines_i.hh"
29 #include "VISU_Prs3dUtils.hh"
30 #include "VISU_Result_i.hh"
32 #include "VISU_Actor.h"
33 #include "VISU_CutLinesPL.hxx"
34 #include "VISU_Convertor.hxx"
35 #include "VISU_PipeLineUtils.hxx"
37 #include "SUIT_ResourceMgr.h"
38 #include "SALOME_Event.h"
40 #include <vtkAppendPolyData.h>
43 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
50 //---------------------------------------------------------------
53 ::IsPossible(Result_i* theResult,
54 const std::string& theMeshName,
55 VISU::Entity theEntity,
56 const std::string& theFieldName,
57 CORBA::Long theTimeStampNumber,
58 bool theIsMemoryCheck)
60 return TSuperClass::IsPossible(theResult,
68 //---------------------------------------------------------------
69 int VISU::CutLines_i::myNbPresent = 0;
71 //---------------------------------------------------------------
73 VISU::CutLines_i::GenerateName()
75 return VISU::GenerateName("CutLines",myNbPresent++);
78 //---------------------------------------------------------------
79 const string VISU::CutLines_i::myComment = "CUTLINES";
81 //---------------------------------------------------------------
86 return myComment.c_str();
89 //----------------------------------------------------------------------------
95 return "ICON_TREE_CUT_LINES";
97 return "ICON_TREE_CUT_LINES_GROUPS";
100 //---------------------------------------------------------------
102 CutLines_i(EPublishInStudyMode thePublishInStudyMode) :
103 ColoredPrs3d_i(thePublishInStudyMode),
104 ScalarMap_i(thePublishInStudyMode),
105 CutLinesBase_i(thePublishInStudyMode),
110 //---------------------------------------------------------------
113 ::SameAs(const Prs3d_i* theOrigin)
115 TSuperClass::SameAs(theOrigin);
119 //---------------------------------------------------------------
122 ::Create(const std::string& theMeshName,
123 VISU::Entity theEntity,
124 const std::string& theFieldName,
125 CORBA::Long theTimeStampNumber)
127 return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
131 //---------------------------------------------------------------
134 ::Restore(SALOMEDS::SObject_ptr theSObject,
135 const Storable::TRestoringMap& theMap)
137 if(!TSuperClass::Restore(theSObject, theMap))
140 SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement[0]").toDouble());
141 SetDisplacement2(VISU::Storable::FindValue(theMap,"myDisplacement[1]").toDouble());
142 SetOrientation(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[0]").toInt()),
143 Storable::FindValue(theMap,"aRot[0][0]").toDouble(),
144 Storable::FindValue(theMap,"aRot[0][1]").toDouble());
145 SetOrientation2(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[1]").toInt()),
146 Storable::FindValue(theMap,"aRot[1][0]").toDouble(),
147 Storable::FindValue(theMap,"aRot[1][1]").toDouble());
149 if (VISU::Storable::FindValue(theMap,"myBasePlaneCondition").toInt())
152 SetBasePlanePosition(VISU::Storable::FindValue(theMap,"myBasePlanePosition").toDouble());
154 QStringList aPosList = VISU::Storable::FindValue(theMap,"myLinePosition").split("|", QString::SkipEmptyParts );
155 QStringList aCondList = VISU::Storable::FindValue(theMap,"myLineCondition").split("|",QString::SkipEmptyParts );
156 for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++)
157 if(aCondList[i].toInt() == 0)
158 SetLinePosition(i,aPosList[i].toDouble());
164 //---------------------------------------------------------------
167 ::ToStream(std::ostringstream& theStr)
169 TSuperClass::ToStream(theStr);
171 Storable::DataToStream( theStr, "myDisplacement[0]", GetDisplacement() );
172 Storable::DataToStream( theStr, "myDisplacement[1]", GetDisplacement2() );
173 Storable::DataToStream( theStr, "myBasePlane[0]", int(GetOrientationType()) );
174 Storable::DataToStream( theStr, "myBasePlane[1]", int(GetOrientationType2()) );
175 Storable::DataToStream( theStr, "aRot[0][0]", GetRotateX() );
176 Storable::DataToStream( theStr, "aRot[0][1]", GetRotateY() );
177 Storable::DataToStream( theStr, "aRot[1][0]", GetRotateX2() );
178 Storable::DataToStream( theStr, "aRot[1][1]", GetRotateY2() );
179 Storable::DataToStream( theStr, "myBasePlanePosition", GetBasePlanePosition() );
180 Storable::DataToStream( theStr, "myBasePlaneCondition", IsDefault() );
182 QString aStrPos, aStrCon;
183 for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++){
184 aStrPos.append(QString::number(GetLinePosition(i)) + "|");
185 aStrCon.append(QString::number(IsDefaultPosition(i)) + "|");
188 Storable::DataToStream( theStr, "myLinePosition", (const char*)aStrPos.toLatin1());
189 Storable::DataToStream( theStr, "myLineCondition", (const char*)aStrCon.toLatin1());
193 //---------------------------------------------------------------
197 if(MYDEBUG) MESSAGE("CutLines_i::~CutLines_i()");
201 //---------------------------------------------------------------
204 ::SetOrientation(VISU::CutPlanes::Orientation theOrient,
205 CORBA::Double theXAngle,
206 CORBA::Double theYAngle)
208 struct TEvent: public SALOME_Event
210 VISU_CutLinesPL* myCutLinesPL;
211 CORBA::Double myXAngle, myYAngle;
212 VISU::CutPlanes::Orientation myOrient;
213 TEvent(VISU_CutLinesPL* theCutLines,
214 VISU::CutPlanes::Orientation theOrient,
215 CORBA::Double theXAngle,
216 CORBA::Double theYAngle):
217 myCutLinesPL(theCutLines),
227 myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(myOrient),
233 VISU::TSetModified aModified(this);
235 ProcessVoidEvent(new TEvent(myCutLinesPL, theOrient, theXAngle, theYAngle));
238 //---------------------------------------------------------------
241 ::SetOrientation2(VISU::CutPlanes::Orientation theOrient,
242 CORBA::Double theXAngle,
243 CORBA::Double theYAngle)
245 struct TEvent: public SALOME_Event
247 VISU_CutLinesPL* myCutLinesPL;
248 CORBA::Double myXAngle, myYAngle;
249 VISU::CutPlanes::Orientation myOrient;
250 TEvent(VISU_CutLinesPL* theCutLines,
251 VISU::CutPlanes::Orientation theOrient,
252 CORBA::Double theXAngle,
253 CORBA::Double theYAngle):
254 myCutLinesPL(theCutLines),
264 myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(myOrient),
271 VISU::TSetModified aModified(this);
273 ProcessVoidEvent(new TEvent(myCutLinesPL, theOrient, theXAngle, theYAngle));
276 //---------------------------------------------------------------
277 VISU::CutPlanes::Orientation
279 ::GetOrientationType()
281 return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation());
284 //---------------------------------------------------------------
285 VISU::CutPlanes::Orientation
287 ::GetOrientationType2()
289 return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation(1));
292 //---------------------------------------------------------------
297 return myCutLinesPL->GetRotateX();
300 //---------------------------------------------------------------
305 return myCutLinesPL->GetRotateY();
309 //---------------------------------------------------------------
314 return myCutLinesPL->GetRotateX(1);
317 //---------------------------------------------------------------
322 return myCutLinesPL->GetRotateY(1);
326 //---------------------------------------------------------------
329 ::SetDisplacement(CORBA::Double theDisp)
331 VISU::TSetModified aModified(this);
333 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, vtkFloatingPointType, int>
334 (GetSpecificPL(), &VISU_CutLinesPL::SetDisplacement, theDisp, 0));
337 //---------------------------------------------------------------
340 ::SetDisplacement2(CORBA::Double theDisp)
342 VISU::TSetModified aModified(this);
344 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, vtkFloatingPointType, int>
345 (GetSpecificPL(), &VISU_CutLinesPL::SetDisplacement, theDisp, 1));
349 //---------------------------------------------------------------
354 return myCutLinesPL->GetDisplacement();
357 //---------------------------------------------------------------
362 return myCutLinesPL->GetDisplacement(1);
366 //---------------------------------------------------------------
369 ::SetBasePlanePosition(CORBA::Double thePlanePosition)
371 VISU::TSetModified aModified(this);
373 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_CutLinesPL, vtkFloatingPointType>
374 (GetSpecificPL(), &VISU_CutLinesPL::SetPosition, thePlanePosition));
377 //---------------------------------------------------------------
380 ::GetBasePlanePosition()
382 return myCutLinesPL->GetPosition();
385 //---------------------------------------------------------------
388 ::SetLinePosition(CORBA::Long thePlaneNumber,
389 CORBA::Double thePlanePosition)
391 VISU::TSetModified aModified(this);
393 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, int, vtkFloatingPointType>
394 (GetSpecificPL(), &VISU_CutLinesPL::SetPartPosition, thePlaneNumber, thePlanePosition));
397 //---------------------------------------------------------------
400 ::GetLinePosition(CORBA::Long thePlaneNumber)
402 return myCutLinesPL->GetPartPosition(thePlaneNumber,1);
406 //---------------------------------------------------------------
411 VISU::TSetModified aModified(this);
413 ProcessVoidEvent(new TVoidMemFunEvent<VISU_CutLinesPL>
414 (GetSpecificPL(), &VISU_CutLinesPL::SetDefault));
417 //---------------------------------------------------------------
422 return myCutLinesPL->IsDefault();
425 //---------------------------------------------------------------
428 ::SetDefaultPosition(CORBA::Long thePlaneNumber)
430 VISU::TSetModified aModified(this);
432 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_CutLinesPL, int>
433 (GetSpecificPL(), &VISU_CutLinesPL::SetPartDefault, thePlaneNumber));
436 //---------------------------------------------------------------
439 ::IsDefaultPosition(CORBA::Long thePlaneNumber)
441 return myCutLinesPL->IsPartDefault(thePlaneNumber);
444 //---------------------------------------------------------------
447 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
450 myCutLinesPL = VISU_CutLinesPL::New();
452 myCutLinesPL = dynamic_cast<VISU_CutLinesPL*>(thePipeLine);
454 TSuperClass::CreatePipeLine(myCutLinesPL);
458 //----------------------------------------------------------------------------
463 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
467 //---------------------------------------------------------------
472 if(VISU_Actor* anActor = TSuperClass::CreateActor()){
473 anActor->SetVTKMapping(true);
474 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
475 int aDispMode = aResourceMgr->integerValue("VISU" , "cut_lines_represent", 2);
476 anActor->SetRepresentation(aDispMode);