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_Vectors_i.cc
25 // Author : Alexey PETROV
28 #include "VISU_Vectors_i.hh"
29 #include "VISU_Prs3dUtils.hh"
30 #include "VISU_Result_i.hh"
32 #include "VISU_VectorsAct.h"
33 #include "VISU_VectorsPL.hxx"
34 #include "VISU_PipeLineUtils.hxx"
35 #include "VISU_Convertor.hxx"
37 #include "SUIT_ResourceMgr.h"
38 #include "SALOME_Event.h"
40 #include <vtkProperty.h>
43 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
48 static int INCMEMORY = 4+12;
52 //---------------------------------------------------------------
55 ::IsPossible(Result_i* theResult,
56 const std::string& theMeshName,
57 VISU::Entity theEntity,
58 const std::string& theFieldName,
59 CORBA::Long theTimeStampNumber,
60 bool theIsMemoryCheck)
63 size_t aResult = TSuperClass::IsPossible(theResult,
69 if(theIsMemoryCheck && aResult){
70 bool anIsEstimated = true;
71 VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
75 size_t aSize = anInput->GetTimeStampOnMeshSize(theMeshName,
76 (VISU::TEntity)theEntity,
82 aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
84 MESSAGE("Vectors_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
87 }catch(std::exception& exc){
88 INFOS("Follow exception was occured :\n"<<exc.what());
90 INFOS("Unknown exception was occured!");
95 //---------------------------------------------------------------
96 int VISU::Vectors_i::myNbPresent = 0;
98 //---------------------------------------------------------------
103 return VISU::GenerateName("Vectors",myNbPresent++);
106 //---------------------------------------------------------------
107 const string VISU::Vectors_i::myComment = "VECTORS";
109 //---------------------------------------------------------------
114 return myComment.c_str();
118 //---------------------------------------------------------------
124 return "ICON_TREE_VECTORS";
126 return "ICON_TREE_VECTORS_GROUPS";
129 //---------------------------------------------------------------
131 ::Vectors_i(EPublishInStudyMode thePublishInStudyMode) :
132 ColoredPrs3d_i(thePublishInStudyMode),
133 ScalarMap_i(thePublishInStudyMode),
134 MonoColorPrs_i(thePublishInStudyMode),
135 DeformedShape_i(thePublishInStudyMode),
141 //---------------------------------------------------------------
144 ::SameAs(const VISU::Prs3d_i* theOrigin)
146 TSuperClass::SameAs(theOrigin);
148 if(const Vectors_i* aPrs3d = dynamic_cast<const Vectors_i*>(theOrigin)){
149 Vectors_i* anOrigin = const_cast<Vectors_i*>(aPrs3d);
150 SetLineWidth(anOrigin->GetLineWidth());
155 //---------------------------------------------------------------
158 ::Create(const std::string& theMeshName,
159 VISU::Entity theEntity,
160 const std::string& theFieldName,
161 CORBA::Long theTimeStampNumber)
163 return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
167 //---------------------------------------------------------------
170 ::Restore(SALOMEDS::SObject_ptr theSObject,
171 const Storable::TRestoringMap& theMap)
173 if(!TSuperClass::Restore(theSObject, theMap))
176 SetGlyphType(VISU::Vectors::GlyphType(VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt()));
177 SetGlyphPos(VISU::Vectors::GlyphPos(VISU::Storable::FindValue(theMap,"myPosGlyph").toInt()));
178 SetLineWidth(VISU::Storable::FindValue(theMap,"myLineWidth").toDouble());
184 //---------------------------------------------------------------
187 ::ToStream(std::ostringstream& theStr)
189 TSuperClass::ToStream(theStr);
191 Storable::DataToStream( theStr, "myTypeGlyph", int(GetGlyphType()));
192 Storable::DataToStream( theStr, "myPosGlyph", int(GetGlyphPos()));
193 Storable::DataToStream( theStr, "myLineWidth", GetLineWidth());
197 //---------------------------------------------------------------
201 if(MYDEBUG) MESSAGE("Vectors_i::~Vectors_i()");
205 //---------------------------------------------------------------
208 ::SetLineWidth(CORBA::Double theWidth)
210 if(VISU::CheckIsSameValue(myLineWidth, theWidth))
213 VISU::TSetModified aModified(this);
215 myLineWidth = theWidth;
216 myParamsTime.Modified();
219 //---------------------------------------------------------------
228 //---------------------------------------------------------------
231 ::SetGlyphType(VISU::Vectors::GlyphType theType)
233 VISU::TSetModified aModified(this);
235 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_VectorsPL, VISU_VectorsPL::GlyphType>
236 (GetSpecificPL(), &VISU_VectorsPL::SetGlyphType, VISU_VectorsPL::GlyphType(theType)));
239 //---------------------------------------------------------------
240 VISU::Vectors::GlyphType
244 return VISU::Vectors::GlyphType(myVectorsPL->GetGlyphType());
248 //---------------------------------------------------------------
251 ::SetGlyphPos(VISU::Vectors::GlyphPos thePos)
253 VISU::TSetModified aModified(this);
255 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_VectorsPL, VISU_VectorsPL::GlyphPos>
256 (GetSpecificPL(), &VISU_VectorsPL::SetGlyphPos, VISU_VectorsPL::GlyphPos(thePos)));
259 //---------------------------------------------------------------
260 VISU::Vectors::GlyphPos
261 VISU::Vectors_i::GetGlyphPos()
263 return VISU::Vectors::GlyphPos(myVectorsPL->GetGlyphPos());
267 //---------------------------------------------------------------
270 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
273 myVectorsPL = VISU_VectorsPL::New();
275 myVectorsPL = dynamic_cast<VISU_VectorsPL*>(thePipeLine);
277 TSuperClass::CreatePipeLine(myVectorsPL);
281 //---------------------------------------------------------------
286 VISU_PipeLine* aPipeLine = VISU_VectorsPL::New();
287 aPipeLine->ShallowCopy(GetPipeLine(), true);
292 //---------------------------------------------------------------
297 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
300 //---------------------------------------------------------------
305 VISU_VectorsAct* anActor = VISU_VectorsAct::New();
307 VISU::Prs3d_i::CreateActor(anActor);
308 anActor->SetVTKMapping(true);
309 anActor->SetBarVisibility(true);
310 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
311 anActor->GetProperty()->SetLineWidth(GetLineWidth());
312 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
313 int aDispMode = aResourceMgr->integerValue("VISU", "vectors_represent", 1);
314 bool toUseShading = aResourceMgr->booleanValue("VISU", "represent_shading", false);
315 anActor->SetRepresentation(aDispMode);
316 anActor->SetShading(toUseShading);
317 UpdateActor(anActor);
326 //---------------------------------------------------------------
329 ::UpdateActor(VISU_ActorBase* theActor)
331 if(VISU_VectorsAct* anActor = dynamic_cast<VISU_VectorsAct*>(theActor)){
332 TSuperClass::UpdateActor(anActor);
333 anActor->GetProperty()->SetLineWidth(GetLineWidth());
334 if(VISU_VectorsPL* aVectorsPL = dynamic_cast<VISU_VectorsPL*>(anActor->GetPipeLine())){
335 aVectorsPL->ShallowCopy(GetPipeLine(), true);
336 aVectorsPL->Update();
337 aVectorsPL->SetMapScale(myVectorsPL->GetMapScale());