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_Vectors_i.cc
24 // Author : Alexey PETROV
27 #include "VISU_Vectors_i.hh"
28 #include "VISU_Prs3dUtils.hh"
29 #include "VISU_Result_i.hh"
31 #include "VISU_VectorsAct.h"
32 #include "VISU_VectorsPL.hxx"
33 #include "VISU_PipeLineUtils.hxx"
34 #include "VISU_Convertor.hxx"
36 #include "SUIT_ResourceMgr.h"
37 #include "SALOME_Event.h"
39 #include <vtkProperty.h>
42 static int MYDEBUG = 0;
44 static int MYDEBUG = 0;
47 static int INCMEMORY = 4+12;
51 //---------------------------------------------------------------
54 ::IsPossible(Result_i* theResult,
55 const std::string& theMeshName,
56 VISU::Entity theEntity,
57 const std::string& theFieldName,
58 CORBA::Long theTimeStampNumber,
59 bool theIsMemoryCheck)
62 size_t aResult = TSuperClass::IsPossible(theResult,
68 if(theIsMemoryCheck && aResult){
69 bool anIsEstimated = true;
70 VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
74 size_t aSize = anInput->GetTimeStampOnMeshSize(theMeshName,
75 (VISU::TEntity)theEntity,
81 aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
83 MESSAGE("Vectors_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
86 }catch(std::exception& exc){
87 INFOS("Follow exception was occured :\n"<<exc.what());
89 INFOS("Unknown exception was occured!");
94 //---------------------------------------------------------------
95 int VISU::Vectors_i::myNbPresent = 0;
97 //---------------------------------------------------------------
102 return VISU::GenerateName("Vectors",myNbPresent++);
105 //---------------------------------------------------------------
106 const string VISU::Vectors_i::myComment = "VECTORS";
108 //---------------------------------------------------------------
113 return myComment.c_str();
117 //---------------------------------------------------------------
123 return "ICON_TREE_VECTORS";
125 return "ICON_TREE_VECTORS_GROUPS";
128 //---------------------------------------------------------------
130 ::Vectors_i(EPublishInStudyMode thePublishInStudyMode) :
131 ColoredPrs3d_i(thePublishInStudyMode),
132 ScalarMap_i(thePublishInStudyMode),
133 MonoColorPrs_i(thePublishInStudyMode),
134 DeformedShape_i(thePublishInStudyMode),
140 //---------------------------------------------------------------
143 ::SameAs(const VISU::Prs3d_i* theOrigin)
145 TSuperClass::SameAs(theOrigin);
147 if(const Vectors_i* aPrs3d = dynamic_cast<const Vectors_i*>(theOrigin)){
148 Vectors_i* anOrigin = const_cast<Vectors_i*>(aPrs3d);
149 SetLineWidth(anOrigin->GetLineWidth());
154 //---------------------------------------------------------------
157 ::Create(const std::string& theMeshName,
158 VISU::Entity theEntity,
159 const std::string& theFieldName,
160 CORBA::Long theTimeStampNumber)
162 return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
166 //---------------------------------------------------------------
169 ::Restore(SALOMEDS::SObject_ptr theSObject,
170 const Storable::TRestoringMap& theMap)
172 if(!TSuperClass::Restore(theSObject, theMap))
175 SetGlyphType(VISU::Vectors::GlyphType(VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt()));
176 SetGlyphPos(VISU::Vectors::GlyphPos(VISU::Storable::FindValue(theMap,"myPosGlyph").toInt()));
177 SetLineWidth(VISU::Storable::FindValue(theMap,"myLineWidth").toDouble());
183 //---------------------------------------------------------------
186 ::ToStream(std::ostringstream& theStr)
188 TSuperClass::ToStream(theStr);
190 Storable::DataToStream( theStr, "myTypeGlyph", int(GetGlyphType()));
191 Storable::DataToStream( theStr, "myPosGlyph", int(GetGlyphPos()));
192 Storable::DataToStream( theStr, "myLineWidth", GetLineWidth());
196 //---------------------------------------------------------------
200 if(MYDEBUG) MESSAGE("Vectors_i::~Vectors_i()");
204 //---------------------------------------------------------------
207 ::SetLineWidth(CORBA::Double theWidth)
209 if(VISU::CheckIsSameValue(myLineWidth, theWidth))
212 VISU::TSetModified aModified(this);
214 myLineWidth = theWidth;
215 myParamsTime.Modified();
218 //---------------------------------------------------------------
227 //---------------------------------------------------------------
230 ::SetGlyphType(VISU::Vectors::GlyphType theType)
232 VISU::TSetModified aModified(this);
234 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_VectorsPL, VISU_VectorsPL::GlyphType>
235 (GetSpecificPL(), &VISU_VectorsPL::SetGlyphType, VISU_VectorsPL::GlyphType(theType)));
238 //---------------------------------------------------------------
239 VISU::Vectors::GlyphType
243 return VISU::Vectors::GlyphType(myVectorsPL->GetGlyphType());
247 //---------------------------------------------------------------
250 ::SetGlyphPos(VISU::Vectors::GlyphPos thePos)
252 VISU::TSetModified aModified(this);
254 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_VectorsPL, VISU_VectorsPL::GlyphPos>
255 (GetSpecificPL(), &VISU_VectorsPL::SetGlyphPos, VISU_VectorsPL::GlyphPos(thePos)));
258 //---------------------------------------------------------------
259 VISU::Vectors::GlyphPos
260 VISU::Vectors_i::GetGlyphPos()
262 return VISU::Vectors::GlyphPos(myVectorsPL->GetGlyphPos());
266 //---------------------------------------------------------------
269 ::CreatePipeLine(VISU_PipeLine* thePipeLine)
272 myVectorsPL = VISU_VectorsPL::New();
274 myVectorsPL = dynamic_cast<VISU_VectorsPL*>(thePipeLine);
276 TSuperClass::CreatePipeLine(myVectorsPL);
280 //---------------------------------------------------------------
285 VISU_PipeLine* aPipeLine = VISU_VectorsPL::New();
286 aPipeLine->ShallowCopy(GetPipeLine(), true);
291 //---------------------------------------------------------------
296 return IsPossible(GetCResult(),GetCMeshName(),GetEntity(),GetCFieldName(),GetTimeStampNumber(),true);
299 //---------------------------------------------------------------
304 VISU_VectorsAct* anActor = VISU_VectorsAct::New();
306 VISU::Prs3d_i::CreateActor(anActor);
307 anActor->SetVTKMapping(true);
308 anActor->SetBarVisibility(true);
309 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
310 anActor->GetProperty()->SetLineWidth(GetLineWidth());
311 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
312 int aDispMode = aResourceMgr->integerValue("VISU", "vectors_represent", 1);
313 bool toUseShading = aResourceMgr->booleanValue("VISU", "represent_shading", false);
314 anActor->SetRepresentation(aDispMode);
315 anActor->SetShading(toUseShading);
316 UpdateActor(anActor);
325 //---------------------------------------------------------------
328 ::UpdateActor(VISU_ActorBase* theActor)
330 if(VISU_VectorsAct* anActor = dynamic_cast<VISU_VectorsAct*>(theActor)){
331 TSuperClass::UpdateActor(anActor);
332 anActor->GetProperty()->SetLineWidth(GetLineWidth());
333 if(VISU_VectorsPL* aVectorsPL = dynamic_cast<VISU_VectorsPL*>(anActor->GetPipeLine())){
334 aVectorsPL->ShallowCopy(GetPipeLine(), true);
335 aVectorsPL->Update();
336 aVectorsPL->SetMapScale(myVectorsPL->GetMapScale());