1 // Copyright (C) 2007-2012 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_IsoSurfaces_i.hh"
29 #include "VISU_Prs3dUtils.hh"
31 #include "VISU_IsoSurfacesPL.hxx"
32 #include "VISU_Result_i.hh"
33 #include "VISU_Actor.h"
34 #include "VISU_ScalarMapAct.h"
35 #include "VISU_IsoSurfActor.h"
37 #include "SUIT_ResourceMgr.h"
38 #include "SALOME_Event.h"
39 #include <vtkMapper.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::IsoSurfaces_i::myNbPresent = 0;
70 //---------------------------------------------------------------
71 QString VISU::IsoSurfaces_i::GenerateName()
73 return VISU::GenerateName("IsoSurfaces",myNbPresent++);
76 //---------------------------------------------------------------
77 const string VISU::IsoSurfaces_i::myComment = "ISOSURFACES";
79 //---------------------------------------------------------------
84 return myComment.c_str();
87 //---------------------------------------------------------------
93 return "ICON_TREE_ISO_SURFACES";
95 return "ICON_TREE_ISO_SURFACES_GROUPS";
98 //---------------------------------------------------------------
100 ::IsoSurfaces_i(EPublishInStudyMode thePublishInStudyMode) :
101 ColoredPrs3d_i(thePublishInStudyMode),
102 ScalarMap_i(thePublishInStudyMode),
103 MonoColorPrs_i(thePublishInStudyMode),
104 myIsoSurfacesPL(NULL),
110 //---------------------------------------------------------------
113 ::Create(const std::string& theMeshName,
114 VISU::Entity theEntity,
115 const std::string& theFieldName,
116 CORBA::Long theTimeStampNumber)
118 VISU::Storable* aRes = TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
120 myColor.R = myColor.G = myColor.B = 0.;
121 //myIsLabeled = false;
127 //---------------------------------------------------------------
130 ::Restore(SALOMEDS::SObject_ptr theSObject,
131 const Storable::TRestoringMap& theMap)
133 if(!TSuperClass::Restore(theSObject, theMap))
136 SetNbSurfaces(VISU::Storable::FindValue(theMap,"myNbSurface").toInt());
137 float aMin = VISU::Storable::FindValue(theMap,"myRange[0]").toDouble();
138 float aMax = VISU::Storable::FindValue(theMap,"myRange[1]").toDouble();
139 myNbLabels = VISU::Storable::FindValue(theMap,"myNbLabels").toInt();
140 myIsLabeled = VISU::Storable::FindValue(theMap,"myIsLabeled").toInt();
141 SetSubRange(aMin,aMax);
143 SetSubRangeFixed(VISU::Storable::FindValue(theMap,"myIsRangeFixed").toInt());
149 //---------------------------------------------------------------
152 ::ToStream(std::ostringstream& theStr)
154 TSuperClass::ToStream(theStr);
156 Storable::DataToStream( theStr, "myNbSurface", int(GetNbSurfaces()) );
157 Storable::DataToStream( theStr, "myRange[0]", GetSubMin() );
158 Storable::DataToStream( theStr, "myRange[1]", GetSubMax() );
159 Storable::DataToStream( theStr, "myNbLabels", myNbLabels );
160 Storable::DataToStream( theStr, "myIsLabeled", myIsLabeled );
161 Storable::DataToStream( theStr, "myIsRangeFixed", IsSubRangeFixed() );
164 //---------------------------------------------------------------
165 void VISU::IsoSurfaces_i::SameAs(const Prs3d_i* theOrigin)
167 TSuperClass::SameAs(theOrigin);
169 if(const IsoSurfaces_i* aPrs3d = dynamic_cast<const IsoSurfaces_i*>(theOrigin)){
170 IsoSurfaces_i* anOrigin = const_cast<IsoSurfaces_i*>(aPrs3d);
171 ShowLabels(anOrigin->IsLabeled(), anOrigin->GetNbLabels());
177 //---------------------------------------------------------------
181 if(MYDEBUG) MESSAGE("IsoSurfaces_i::~IsoSurfaces_i()");
185 //---------------------------------------------------------------
188 ::SetNbSurfaces(CORBA::Long theNb)
190 VISU::TSetModified aModified(this);
192 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_IsoSurfacesPL, int>
193 (GetSpecificPL(), &VISU_IsoSurfacesPL::SetNbParts, theNb));
196 //---------------------------------------------------------------
201 return myIsoSurfacesPL->GetNbParts();
205 //---------------------------------------------------------------
208 ::SetSubRange(CORBA::Double theMin, CORBA::Double theMax)
210 VISU::TSetModified aModified(this);
212 bool isForced = false;
213 vtkFloatingPointType aRange[2] = {theMin, theMax};
214 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_IsoSurfacesPL, vtkFloatingPointType*, bool>
215 (GetSpecificPL(), &VISU_IsoSurfacesPL::SetRange, aRange, isForced));
218 //---------------------------------------------------------------
223 return myIsoSurfacesPL->GetMin();
226 //---------------------------------------------------------------
231 return myIsoSurfacesPL->GetMax();
234 //---------------------------------------------------------------
237 ::SetSubRangeFixed(CORBA::Boolean theIsFixed)
239 VISU::TSetModified aModified(this);
241 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_IsoSurfacesPL, bool>
242 (GetSpecificPL(), &VISU_IsoSurfacesPL::SetRangeFixed, theIsFixed));
245 //---------------------------------------------------------------
250 return myIsoSurfacesPL->IsRangeFixed();
254 //---------------------------------------------------------------
257 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
260 myIsoSurfacesPL = VISU_IsoSurfacesPL::New();
262 myIsoSurfacesPL = dynamic_cast<VISU_IsoSurfacesPL*>(thePipeLine);
264 TSuperClass::CreatePipeLine(myIsoSurfacesPL);
268 //----------------------------------------------------------------------------
271 ::DoSetInput(bool theIsInitilizePipe, bool theReInit)
273 TSuperClass::DoSetInput(theIsInitilizePipe, theReInit);
274 if(theIsInitilizePipe || (!IsTimeStampFixed() && !IsRangeFixed()) || theReInit)
275 SetSubRange(GetSourceMin(), GetSourceMax());
278 //---------------------------------------------------------------
283 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
286 //---------------------------------------------------------------
287 VISU_Actor* VISU::IsoSurfaces_i::CreateActor()
289 VISU_IsoSurfActor* anActor = VISU_IsoSurfActor::New();
291 VISU::Prs3d_i::CreateActor(anActor);
292 anActor->SetBarVisibility(true);
293 anActor->SetVTKMapping(true);
294 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
295 int aDispMode = aResourceMgr->integerValue("VISU" , "iso_surfaces_represent", 2);
296 bool toUseShading = aResourceMgr->booleanValue("VISU", "represent_shading", false);
297 anActor->SetRepresentation(aDispMode);
298 anActor->SetShading(toUseShading);
299 UpdateActor(anActor);
308 //---------------------------------------------------------------
309 void VISU::IsoSurfaces_i::UpdateActor(VISU_ActorBase* theActor)
311 if(VISU_IsoSurfActor* anActor = dynamic_cast<VISU_IsoSurfActor*>(theActor)){
312 anActor->SetLinesLabeled(myIsLabeled, myNbLabels);
314 TSuperClass::UpdateActor(theActor);
317 //---------------------------------------------------------------
320 ::SetMapScale(double theMapScale)
322 myIsoSurfacesPL->SetMapScale(theMapScale);
325 //---------------------------------------------------------------
326 CORBA::Boolean VISU::IsoSurfaces_i::IsLabeled()
331 //---------------------------------------------------------------
332 void VISU::IsoSurfaces_i::ShowLabels(CORBA::Boolean theShow, CORBA::Long theNb)
334 if ((myIsLabeled == theShow) && (myNbLabels == theNb)) return;
335 VISU::TSetModified aModified(this);
336 myIsLabeled = theShow;
338 myParamsTime.Modified();
341 //---------------------------------------------------------------
342 CORBA::Long VISU::IsoSurfaces_i::GetNbLabels()