1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_CutLines_i.hh"
28 #include "VISU_Prs3dUtils.hh"
29 #include "VISU_Result_i.hh"
31 #include "VISU_Actor.h"
32 #include "VISU_CutLinesPL.hxx"
33 #include "VISU_Convertor.hxx"
34 #include "VISU_PipeLineUtils.hxx"
36 #include "SUIT_ResourceMgr.h"
37 #include "SALOME_Event.h"
39 #include <vtkAppendPolyData.h>
42 static int MYDEBUG = 0;
44 static int MYDEBUG = 0;
49 //---------------------------------------------------------------
52 ::IsPossible(Result_i* theResult,
53 const std::string& theMeshName,
54 VISU::Entity theEntity,
55 const std::string& theFieldName,
56 CORBA::Long theTimeStampNumber,
57 bool theIsMemoryCheck)
59 return TSuperClass::IsPossible(theResult,
67 //---------------------------------------------------------------
68 int VISU::CutLines_i::myNbPresent = 0;
70 //---------------------------------------------------------------
72 VISU::CutLines_i::GenerateName()
74 return VISU::GenerateName("CutLines",myNbPresent++);
77 //---------------------------------------------------------------
78 const string VISU::CutLines_i::myComment = "CUTLINES";
80 //---------------------------------------------------------------
85 return myComment.c_str();
88 //----------------------------------------------------------------------------
94 return "ICON_TREE_CUT_LINES";
96 return "ICON_TREE_CUT_LINES_GROUPS";
99 //---------------------------------------------------------------
101 CutLines_i(EPublishInStudyMode thePublishInStudyMode) :
102 ColoredPrs3d_i(thePublishInStudyMode),
103 ScalarMap_i(thePublishInStudyMode),
104 CutLinesBase_i(thePublishInStudyMode),
109 //---------------------------------------------------------------
112 ::SameAs(const Prs3d_i* theOrigin)
114 TSuperClass::SameAs(theOrigin);
118 //---------------------------------------------------------------
121 ::Create(const std::string& theMeshName,
122 VISU::Entity theEntity,
123 const std::string& theFieldName,
124 CORBA::Long theTimeStampNumber)
126 return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
130 //---------------------------------------------------------------
133 ::Restore(SALOMEDS::SObject_ptr theSObject,
134 const Storable::TRestoringMap& theMap)
136 if(!TSuperClass::Restore(theSObject, theMap))
139 SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement[0]").toDouble());
140 SetDisplacement2(VISU::Storable::FindValue(theMap,"myDisplacement[1]").toDouble());
141 SetOrientation(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[0]").toInt()),
142 Storable::FindValue(theMap,"aRot[0][0]").toDouble(),
143 Storable::FindValue(theMap,"aRot[0][1]").toDouble());
144 SetOrientation2(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[1]").toInt()),
145 Storable::FindValue(theMap,"aRot[1][0]").toDouble(),
146 Storable::FindValue(theMap,"aRot[1][1]").toDouble());
148 if (VISU::Storable::FindValue(theMap,"myBasePlaneCondition").toInt())
151 SetBasePlanePosition(VISU::Storable::FindValue(theMap,"myBasePlanePosition").toDouble());
153 QStringList aPosList = VISU::Storable::FindValue(theMap,"myLinePosition").split("|", QString::SkipEmptyParts );
154 QStringList aCondList = VISU::Storable::FindValue(theMap,"myLineCondition").split("|",QString::SkipEmptyParts );
155 for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++)
156 if(aCondList[i].toInt() == 0)
157 SetLinePosition(i,aPosList[i].toDouble());
163 //---------------------------------------------------------------
166 ::ToStream(std::ostringstream& theStr)
168 TSuperClass::ToStream(theStr);
170 Storable::DataToStream( theStr, "myDisplacement[0]", GetDisplacement() );
171 Storable::DataToStream( theStr, "myDisplacement[1]", GetDisplacement2() );
172 Storable::DataToStream( theStr, "myBasePlane[0]", int(GetOrientationType()) );
173 Storable::DataToStream( theStr, "myBasePlane[1]", int(GetOrientationType2()) );
174 Storable::DataToStream( theStr, "aRot[0][0]", GetRotateX() );
175 Storable::DataToStream( theStr, "aRot[0][1]", GetRotateY() );
176 Storable::DataToStream( theStr, "aRot[1][0]", GetRotateX2() );
177 Storable::DataToStream( theStr, "aRot[1][1]", GetRotateY2() );
178 Storable::DataToStream( theStr, "myBasePlanePosition", GetBasePlanePosition() );
179 Storable::DataToStream( theStr, "myBasePlaneCondition", IsDefault() );
181 QString aStrPos, aStrCon;
182 for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++){
183 aStrPos.append(QString::number(GetLinePosition(i)) + "|");
184 aStrCon.append(QString::number(IsDefaultPosition(i)) + "|");
187 Storable::DataToStream( theStr, "myLinePosition", (const char*)aStrPos.toLatin1());
188 Storable::DataToStream( theStr, "myLineCondition", (const char*)aStrCon.toLatin1());
192 //---------------------------------------------------------------
196 if(MYDEBUG) MESSAGE("CutLines_i::~CutLines_i()");
200 //---------------------------------------------------------------
203 ::SetOrientation(VISU::CutPlanes::Orientation theOrient,
204 CORBA::Double theXAngle,
205 CORBA::Double theYAngle)
207 struct TEvent: public SALOME_Event
209 VISU_CutLinesPL* myCutLinesPL;
210 CORBA::Double myXAngle, myYAngle;
211 VISU::CutPlanes::Orientation myOrient;
212 TEvent(VISU_CutLinesPL* theCutLines,
213 VISU::CutPlanes::Orientation theOrient,
214 CORBA::Double theXAngle,
215 CORBA::Double theYAngle):
216 myCutLinesPL(theCutLines),
226 myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(myOrient),
232 VISU::TSetModified aModified(this);
234 ProcessVoidEvent(new TEvent(myCutLinesPL, theOrient, theXAngle, theYAngle));
237 //---------------------------------------------------------------
240 ::SetOrientation2(VISU::CutPlanes::Orientation theOrient,
241 CORBA::Double theXAngle,
242 CORBA::Double theYAngle)
244 struct TEvent: public SALOME_Event
246 VISU_CutLinesPL* myCutLinesPL;
247 CORBA::Double myXAngle, myYAngle;
248 VISU::CutPlanes::Orientation myOrient;
249 TEvent(VISU_CutLinesPL* theCutLines,
250 VISU::CutPlanes::Orientation theOrient,
251 CORBA::Double theXAngle,
252 CORBA::Double theYAngle):
253 myCutLinesPL(theCutLines),
263 myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(myOrient),
270 VISU::TSetModified aModified(this);
272 ProcessVoidEvent(new TEvent(myCutLinesPL, theOrient, theXAngle, theYAngle));
275 //---------------------------------------------------------------
276 VISU::CutPlanes::Orientation
278 ::GetOrientationType()
280 return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation());
283 //---------------------------------------------------------------
284 VISU::CutPlanes::Orientation
286 ::GetOrientationType2()
288 return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation(1));
291 //---------------------------------------------------------------
296 return myCutLinesPL->GetRotateX();
299 //---------------------------------------------------------------
304 return myCutLinesPL->GetRotateY();
308 //---------------------------------------------------------------
313 return myCutLinesPL->GetRotateX(1);
316 //---------------------------------------------------------------
321 return myCutLinesPL->GetRotateY(1);
325 //---------------------------------------------------------------
328 ::SetDisplacement(CORBA::Double theDisp)
330 VISU::TSetModified aModified(this);
332 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, vtkFloatingPointType, int>
333 (GetSpecificPL(), &VISU_CutLinesPL::SetDisplacement, theDisp, 0));
336 //---------------------------------------------------------------
339 ::SetDisplacement2(CORBA::Double theDisp)
341 VISU::TSetModified aModified(this);
343 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, vtkFloatingPointType, int>
344 (GetSpecificPL(), &VISU_CutLinesPL::SetDisplacement, theDisp, 1));
348 //---------------------------------------------------------------
353 return myCutLinesPL->GetDisplacement();
356 //---------------------------------------------------------------
361 return myCutLinesPL->GetDisplacement(1);
365 //---------------------------------------------------------------
368 ::SetBasePlanePosition(CORBA::Double thePlanePosition)
370 VISU::TSetModified aModified(this);
372 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_CutLinesPL, vtkFloatingPointType>
373 (GetSpecificPL(), &VISU_CutLinesPL::SetPosition, thePlanePosition));
376 //---------------------------------------------------------------
379 ::GetBasePlanePosition()
381 return myCutLinesPL->GetPosition();
384 //---------------------------------------------------------------
387 ::SetLinePosition(CORBA::Long thePlaneNumber,
388 CORBA::Double thePlanePosition)
390 VISU::TSetModified aModified(this);
392 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_CutLinesPL, int, vtkFloatingPointType>
393 (GetSpecificPL(), &VISU_CutLinesPL::SetPartPosition, thePlaneNumber, thePlanePosition));
396 //---------------------------------------------------------------
399 ::GetLinePosition(CORBA::Long thePlaneNumber)
401 return myCutLinesPL->GetPartPosition(thePlaneNumber,1);
405 //---------------------------------------------------------------
410 VISU::TSetModified aModified(this);
412 ProcessVoidEvent(new TVoidMemFunEvent<VISU_CutLinesPL>
413 (GetSpecificPL(), &VISU_CutLinesPL::SetDefault));
416 //---------------------------------------------------------------
421 return myCutLinesPL->IsDefault();
424 //---------------------------------------------------------------
427 ::SetDefaultPosition(CORBA::Long thePlaneNumber)
429 VISU::TSetModified aModified(this);
431 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_CutLinesPL, int>
432 (GetSpecificPL(), &VISU_CutLinesPL::SetPartDefault, thePlaneNumber));
435 //---------------------------------------------------------------
438 ::IsDefaultPosition(CORBA::Long thePlaneNumber)
440 return myCutLinesPL->IsPartDefault(thePlaneNumber);
443 //---------------------------------------------------------------
446 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
449 myCutLinesPL = VISU_CutLinesPL::New();
451 myCutLinesPL = dynamic_cast<VISU_CutLinesPL*>(thePipeLine);
453 TSuperClass::CreatePipeLine(myCutLinesPL);
457 //----------------------------------------------------------------------------
462 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
466 //---------------------------------------------------------------
471 if(VISU_Actor* anActor = TSuperClass::CreateActor()){
472 anActor->SetVTKMapping(true);
473 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
474 int aDispMode = aResourceMgr->integerValue("VISU" , "cut_lines_represent", 2);
475 anActor->SetRepresentation(aDispMode);