Salome HOME
Remove unused variables
[modules/visu.git] / src / VISU_I / VISU_Vectors_i.cc
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //  File   : VISU_Vectors_i.cc
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_VectorsPL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_Vectors_i.hh"
30 #include "VISU_VectorsAct.h"
31
32 using namespace VISU;
33 using namespace std;
34
35 #ifdef _DEBUG_
36 static int MYDEBUG = 0;
37 #else
38 static int MYDEBUG = 0;
39 #endif
40
41 static int INCMEMORY = 4+12;
42
43 int VISU::Vectors_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
44                                 const char* theFieldName, int theIteration, int isMemoryCheck)
45 {
46   bool aResult = false;
47   try{
48     aResult = DeformedShape_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,false);
49     if(isMemoryCheck && aResult){
50       float aSize = INCMEMORY*
51         theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration);
52       aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
53       MESSAGE("Vectors_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
54     }
55   }catch(std::exception& exc){
56     INFOS("Follow exception was occured :\n"<<exc.what());
57   }catch(...){
58     INFOS("Unknown exception was occured!");
59   }
60   return aResult;
61 }
62
63
64 int VISU::Vectors_i::myNbPresent = 0;
65 QString VISU::Vectors_i::GenerateName() { return VISU::GenerateName("Vectors",myNbPresent++);}
66
67
68 const string VISU::Vectors_i::myComment = "VECTORS";
69 const char* VISU::Vectors_i::GetComment() const { return myComment.c_str();}
70
71
72 VISU::Vectors_i::Vectors_i(Result_i* theResult, bool theAddToStudy, SALOMEDS::SObject_ptr theSObject) :
73        PrsObject_i(theResult->GetStudyDocument()), 
74        Prs3d_i(theResult,theSObject),
75        ScalarMap_i(theResult,theAddToStudy,theSObject),
76        DeformedShape_i(theResult,theAddToStudy,theSObject)
77 {
78   myVectorsPL = NULL;
79 }
80
81
82 void VISU::Vectors_i::SameAs(const VISU::Vectors_i* theOrigin) {
83   Vectors_i* aVectors = const_cast<Vectors_i*>(theOrigin);
84   VISU::DeformedShape_i::SameAs(theOrigin);
85
86   SetLineWidth(aVectors->GetLineWidth());
87 }
88
89
90 VISU::Storable* VISU::Vectors_i::Create(const char* theMeshName, VISU::Entity theEntity, 
91                                         const char* theFieldName, int theIteration)
92 {
93   myLineWidth = 1.0;
94   return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
95 }
96
97
98 VISU::Storable* VISU::Vectors_i::Restore(const Storable::TRestoringMap& theMap)
99 {
100   DoHook();
101   SetGlyphType(VISU::Vectors::GlyphType(VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt()));
102   SetGlyphPos(VISU::Vectors::GlyphPos(VISU::Storable::FindValue(theMap,"myPosGlyph").toInt()));
103   SetLineWidth(VISU::Storable::FindValue(theMap,"myLineWidth").toDouble());
104
105   return DeformedShape_i::Restore(theMap);
106 }
107
108
109 void VISU::Vectors_i::ToStream(std::ostringstream& theStr){
110   DeformedShape_i::ToStream(theStr);
111
112   Storable::DataToStream( theStr, "myTypeGlyph", int(GetGlyphType()));
113   Storable::DataToStream( theStr, "myPosGlyph",  int(GetGlyphPos()));
114   Storable::DataToStream( theStr, "myLineWidth", GetLineWidth());
115 }
116
117
118 VISU::Vectors_i::~Vectors_i(){
119   if(MYDEBUG) MESSAGE("Vectors_i::~Vectors_i()");
120 }
121
122
123 void VISU::Vectors_i::SetLineWidth(CORBA::Double theWidth) { 
124   myLineWidth = theWidth;
125 }
126 CORBA::Double VISU::Vectors_i::GetLineWidth() { 
127   return myLineWidth;
128 }
129
130
131 void VISU::Vectors_i::SetGlyphType(VISU::Vectors::GlyphType theType) { 
132   myVectorsPL->SetGlyphType(VISU_VectorsPL::GlyphType(theType));
133 }
134 VISU::Vectors::GlyphType VISU::Vectors_i::GetGlyphType() { 
135   return VISU::Vectors::GlyphType(myVectorsPL->GetGlyphType());
136 }
137
138
139 void VISU::Vectors_i::SetGlyphPos(VISU::Vectors::GlyphPos thePos) { 
140   myVectorsPL->SetGlyphPos(VISU_VectorsPL::GlyphPos(thePos));
141 }
142 VISU::Vectors::GlyphPos VISU::Vectors_i::GetGlyphPos() { 
143   return VISU::Vectors::GlyphPos(myVectorsPL->GetGlyphPos());
144 }
145
146
147 void VISU::Vectors_i::DoHook(){
148   if(!myPipeLine) myPipeLine = VISU_VectorsPL::New();
149   myVectorsPL = dynamic_cast<VISU_VectorsPL*>(myPipeLine);
150
151   DeformedShape_i::DoHook();
152 }
153
154
155 VISU_PipeLine* VISU::Vectors_i::GetPipeLine(){
156   VISU_PipeLine* aPipeLine = VISU_VectorsPL::New();
157   aPipeLine->ShallowCopy(myPipeLine);
158   aPipeLine->Update();
159   return aPipeLine;
160 }
161
162
163 VISU_Actor* VISU::Vectors_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) 
164 {
165   VISU_VectorsAct* anActor = VISU_VectorsAct::New();
166   try{
167     VISU::Prs3d_i::CreateActor(anActor,theIO);
168     anActor->SetBarVisibility(true);
169     anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
170     anActor->GetProperty()->SetLineWidth(GetLineWidth());
171     UpdateActor(anActor);
172   }catch(...){
173     anActor->Delete();
174     throw ;
175   }
176   return anActor;
177 }
178
179
180 void VISU::Vectors_i::UpdateActor(VISU_Actor* theActor) {
181   if(VISU_VectorsAct* anActor = dynamic_cast<VISU_VectorsAct*>(theActor)){
182     VISU::DeformedShape_i::UpdateActor(anActor);
183     anActor->GetProperty()->SetLineWidth(GetLineWidth());
184     if(VISU_VectorsPL* aVectorsPL = dynamic_cast<VISU_VectorsPL*>(anActor->GetPipeLine())){
185       aVectorsPL->ShallowCopy(myPipeLine);
186       aVectorsPL->Update();
187       aVectorsPL->SetMapScale(myVectorsPL->GetMapScale());
188     }
189   }
190 }