Salome HOME
Merge from V6_main 01/04/2013
[modules/visu.git] / src / VISU_I / VISU_MonoColorPrs_i.cc
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  VISU OBJECT : interactive object for VISU entities implementation
21 //  File   : VISU_MonoColorPrs_i.cxx
22 //  Author : Vitaly Smetannikov
23 //  Module : VISU
24 //
25 #include "VISU_MonoColorPrs_i.hh"
26 #include "VISU_Prs3dUtils.hh"
27 #include "VISU_PipeLineUtils.hxx"
28 #include "VISU_ScalarMapAct.h"
29
30 #include "VISU_PipeLine.hxx"
31
32 #include <vtkDataSetMapper.h>
33 #include <vtkProperty.h>
34
35 #ifdef _DEBUG_
36 static int MYDEBUG = 0;
37 #else
38 static int MYDEBUG = 0;
39 #endif
40
41 //---------------------------------------------------------------
42 VISU::MonoColorPrs_i
43 ::MonoColorPrs_i(EPublishInStudyMode thePublishInStudyMode):
44   ColoredPrs3d_i(thePublishInStudyMode),
45   ScalarMap_i(thePublishInStudyMode)
46 {
47   if(MYDEBUG) MESSAGE("MonoColorPrs_i::MonoColorPrs_i");
48 }
49
50 //---------------------------------------------------------------
51 void 
52 VISU::MonoColorPrs_i
53 ::SameAs(const Prs3d_i* theOrigin)
54 {
55   TSuperClass::SameAs(theOrigin);
56
57   if(const MonoColorPrs_i* aPrs3d = dynamic_cast<const MonoColorPrs_i*>(theOrigin)){
58     MonoColorPrs_i* anOrigin = const_cast<MonoColorPrs_i*>(aPrs3d);
59     SetColor(anOrigin->GetColor());
60     ShowColored(anOrigin->IsColored());
61   }
62 }
63
64
65 //---------------------------------------------------------------
66 VISU::Storable* 
67 VISU::MonoColorPrs_i
68 ::Create(const std::string& theMeshName, 
69          VISU::Entity theEntity,
70          const std::string& theFieldName, 
71          CORBA::Long theTimeStampNumber)
72 {
73   myIsColored = false;
74   myColor.R = myColor.G = myColor.B = 0.5;
75   return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
76 }
77
78 //---------------------------------------------------------------
79 VISU::Storable* 
80 VISU::MonoColorPrs_i
81 ::Restore(SALOMEDS::SObject_ptr theSObject,
82           const Storable::TRestoringMap& theMap)
83 {
84   if(!TSuperClass::Restore(theSObject, theMap))
85     return NULL;
86
87   myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
88   myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
89   myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
90   myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
91
92   return this;
93 }
94
95 //---------------------------------------------------------------
96 void
97 VISU::MonoColorPrs_i
98 ::ToStream(std::ostringstream& theStr)
99 {
100   TSuperClass::ToStream(theStr);
101
102   Storable::DataToStream( theStr, "myIsColored", myIsColored );
103   Storable::DataToStream( theStr, "myColor.R", myColor.R );
104   Storable::DataToStream( theStr, "myColor.G", myColor.G );
105   Storable::DataToStream( theStr, "myColor.B", myColor.B );
106 }
107
108
109 //---------------------------------------------------------------
110 VISU::MonoColorPrs_i::~MonoColorPrs_i()
111 {
112   if(MYDEBUG) MESSAGE("MonoColorPrs_i::~MonoColorPrs_i()");
113 }
114
115 //---------------------------------------------------------------
116 CORBA::Boolean VISU::MonoColorPrs_i::IsColored()
117 {
118   return myIsColored;
119 }
120
121
122
123 //---------------------------------------------------------------
124 void
125 VISU::MonoColorPrs_i::ShowColored(CORBA::Boolean theColored)
126 {
127   if(myIsColored == theColored)
128     return;
129   myIsColored = theColored; 
130   myParamsTime.Modified();
131 }
132
133 //---------------------------------------------------------------
134 SALOMEDS::Color VISU::MonoColorPrs_i::GetColor()
135 {
136   return myColor;
137 }
138
139 //---------------------------------------------------------------
140 void VISU::MonoColorPrs_i::SetColor(const SALOMEDS::Color& theColor)
141 {
142   bool anIsSameValue = VISU::CheckIsSameValue(myColor.R, theColor.R);
143   anIsSameValue &= VISU::CheckIsSameValue(myColor.G, theColor.G);
144   anIsSameValue &= VISU::CheckIsSameValue(myColor.B, theColor.B);
145   if(anIsSameValue)
146     return;
147
148   VISU::TSetModified aModified(this);
149   
150   myColor = theColor;
151   myParamsTime.Modified();
152 }
153
154 //---------------------------------------------------------------
155 VISU_Actor* VISU::MonoColorPrs_i::CreateActor(bool toSupressShrinking) 
156 {
157   VISU_Actor* anActor = TSuperClass::CreateActor(toSupressShrinking);
158   anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
159   return anActor;
160 }
161
162 //---------------------------------------------------------------
163 VISU_Actor* VISU::MonoColorPrs_i::CreateActor()
164 {
165   return CreateActor(false);
166 }
167
168 //---------------------------------------------------------------
169 void VISU::MonoColorPrs_i::UpdateActor(VISU_ActorBase* theActor) 
170 {
171   if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
172     if(IsColored()){
173       GetPipeLine()->GetMapper()->SetScalarVisibility(1);
174     }else{
175       GetPipeLine()->GetMapper()->SetScalarVisibility(0);
176       anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
177     }
178     TSuperClass::UpdateActor(theActor);
179
180     // this method should be called after TSuperClass::UpdateActor()
181     anActor->SetBarVisibility( IsBarVisible() && IsColored() );
182   }
183 }
184