Salome HOME
DCQ : Merge with Ecole Ete a6.
[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 static int MYDEBUGWITHFILES = 0;
38 #else
39 static int MYDEBUG = 0;
40 static int MYDEBUGWITHFILES = 0;
41 #endif
42
43 static int INCMEMORY = 4+12;
44
45 int VISU::Vectors_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, 
46                                 const char* theFieldName, int theIteration, int isMemoryCheck)
47 {
48   bool aResult = false;
49   try{
50     aResult = DeformedShape_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,false);
51     if(isMemoryCheck && aResult){
52       float aSize = INCMEMORY*
53         theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration);
54       aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
55       MESSAGE("Vectors_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<aResult);
56     }
57   }catch(std::runtime_error& exc){
58     INFOS("Follow exception was accured :\n"<<exc.what());
59   }catch(...){
60     INFOS("Unknown exception was accured!");
61   }
62   return aResult;
63 }
64
65
66 int VISU::Vectors_i::myNbPresent = 0;
67 QString VISU::Vectors_i::GenerateName() { return VISU::GenerateName("Vectors",myNbPresent++);}
68
69
70 const string VISU::Vectors_i::myComment = "VECTORS";
71 const char* VISU::Vectors_i::GetComment() const { return myComment.c_str();}
72
73
74 VISU::Vectors_i::Vectors_i(Result_i* theResult, bool theAddToStudy, SALOMEDS::SObject_ptr theSObject) :
75        PrsObject_i(theResult->GetStudyDocument()), 
76        Prs3d_i(theResult,theSObject),
77        ScalarMap_i(theResult,theAddToStudy,theSObject),
78        DeformedShape_i(theResult,theAddToStudy,theSObject)
79 {
80   myVectorsPL = NULL;
81 }
82
83
84 void VISU::Vectors_i::SameAs(const VISU::Vectors_i* theOrigin) {
85   Vectors_i* aVectors = const_cast<Vectors_i*>(theOrigin);
86   VISU::DeformedShape_i::SameAs(theOrigin);
87
88   SetLineWidth(aVectors->GetLineWidth());
89 }
90
91
92 VISU::Storable* VISU::Vectors_i::Create(const char* theMeshName, VISU::Entity theEntity, 
93                                         const char* theFieldName, int theIteration)
94 {
95   myLineWidth = 1.0;
96   return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
97 }
98
99
100 VISU::Storable* VISU::Vectors_i::Restore(const Storable::TRestoringMap& theMap)
101 {
102   DoHook();
103   SetGlyphType(VISU::Vectors::GlyphType(VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt()));
104   SetGlyphPos(VISU::Vectors::GlyphPos(VISU::Storable::FindValue(theMap,"myPosGlyph").toInt()));
105   SetLineWidth(VISU::Storable::FindValue(theMap,"myLineWidth").toDouble());
106
107   return DeformedShape_i::Restore(theMap);
108 }
109
110
111 void VISU::Vectors_i::ToStream(std::ostringstream& theStr){
112   DeformedShape_i::ToStream(theStr);
113
114   Storable::DataToStream( theStr, "myTypeGlyph", int(GetGlyphType()));
115   Storable::DataToStream( theStr, "myPosGlyph",  int(GetGlyphPos()));
116   Storable::DataToStream( theStr, "myLineWidth", GetLineWidth());
117 }
118
119
120 VISU::Vectors_i::~Vectors_i(){
121   if(MYDEBUG) MESSAGE("Vectors_i::~Vectors_i()");
122 }
123
124
125 void VISU::Vectors_i::SetLineWidth(CORBA::Double theWidth) { 
126   myLineWidth = theWidth;
127 }
128 CORBA::Double VISU::Vectors_i::GetLineWidth() { 
129   return myLineWidth;
130 }
131
132
133 void VISU::Vectors_i::SetGlyphType(VISU::Vectors::GlyphType theType) { 
134   myVectorsPL->SetGlyphType(VISU_VectorsPL::GlyphType(theType));
135 }
136 VISU::Vectors::GlyphType VISU::Vectors_i::GetGlyphType() { 
137   return VISU::Vectors::GlyphType(myVectorsPL->GetGlyphType());
138 }
139
140
141 void VISU::Vectors_i::SetGlyphPos(VISU::Vectors::GlyphPos thePos) { 
142   myVectorsPL->SetGlyphPos(VISU_VectorsPL::GlyphPos(thePos));
143 }
144 VISU::Vectors::GlyphPos VISU::Vectors_i::GetGlyphPos() { 
145   return VISU::Vectors::GlyphPos(myVectorsPL->GetGlyphPos());
146 }
147
148
149 void VISU::Vectors_i::DoHook(){
150   if(!myPipeLine) myPipeLine = VISU_VectorsPL::New();
151   myVectorsPL = dynamic_cast<VISU_VectorsPL*>(myPipeLine);
152
153   DeformedShape_i::DoHook();
154 }
155
156
157 VISU_PipeLine* VISU::Vectors_i::GetPipeLine(){
158   VISU_PipeLine* aPipeLine = VISU_VectorsPL::New();
159   aPipeLine->ShallowCopy(myPipeLine);
160   aPipeLine->Update();
161   return aPipeLine;
162 }
163
164
165 VISU_Actor* VISU::Vectors_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) 
166 {
167   VISU_VectorsAct* anActor = VISU_VectorsAct::New();
168   try{
169     VISU::Prs3d_i::CreateActor(anActor,theIO);
170     anActor->SetBarVisibility(true);
171     anActor->myFieldName = myFieldName;
172     anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
173     anActor->GetProperty()->SetLineWidth(GetLineWidth());
174     UpdateActor(anActor);
175   }catch(...){
176     anActor->Delete();
177     throw ;
178   }
179   return anActor;
180 }
181
182
183 void VISU::Vectors_i::UpdateActor(VISU_Actor* theActor) {
184   if(VISU_VectorsAct* anActor = dynamic_cast<VISU_VectorsAct*>(theActor)){
185     VISU::DeformedShape_i::UpdateActor(anActor);
186     anActor->GetProperty()->SetLineWidth(GetLineWidth());
187     if(VISU_VectorsPL* aVectorsPL = dynamic_cast<VISU_VectorsPL*>(anActor->GetPipeLine())){
188       aVectorsPL->ShallowCopy(myPipeLine);
189       aVectorsPL->Update();
190       aVectorsPL->SetMapScale(myVectorsPL->GetMapScale());
191     }
192   }
193 }