Salome HOME
b7ddf5765c9cf4a7ab0af3b1f2bf94a6d3d394a6
[modules/visu.git] / src / VISU_I / VISU_MonoColorPrs_i.cc
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : VISU_MonoColorPrs_i.cxx
24 //  Author : Vitaly Smetannikov
25 //  Module : VISU
26 //
27 #include "VISU_MonoColorPrs_i.hh"
28 #include "VISU_Prs3dUtils.hh"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "VISU_ScalarMapAct.h"
31
32 #include "VISU_PipeLine.hxx"
33
34 #include <vtkDataSetMapper.h>
35 #include <vtkProperty.h>
36
37 #ifdef _DEBUG_
38 static int MYDEBUG = 0;
39 #else
40 static int MYDEBUG = 0;
41 #endif
42
43 //---------------------------------------------------------------
44 VISU::MonoColorPrs_i
45 ::MonoColorPrs_i(EPublishInStudyMode thePublishInStudyMode):
46   ColoredPrs3d_i(thePublishInStudyMode),
47   ScalarMap_i(thePublishInStudyMode)
48 {
49   if(MYDEBUG) MESSAGE("MonoColorPrs_i::MonoColorPrs_i");
50 }
51
52 //---------------------------------------------------------------
53 void 
54 VISU::MonoColorPrs_i
55 ::SameAs(const Prs3d_i* theOrigin)
56 {
57   TSuperClass::SameAs(theOrigin);
58
59   if(const MonoColorPrs_i* aPrs3d = dynamic_cast<const MonoColorPrs_i*>(theOrigin)){
60     MonoColorPrs_i* anOrigin = const_cast<MonoColorPrs_i*>(aPrs3d);
61     SetColor(anOrigin->GetColor());
62     ShowColored(anOrigin->IsColored());
63   }
64 }
65
66
67 //---------------------------------------------------------------
68 VISU::Storable* 
69 VISU::MonoColorPrs_i
70 ::Create(const std::string& theMeshName, 
71          VISU::Entity theEntity,
72          const std::string& theFieldName, 
73          CORBA::Long theTimeStampNumber)
74 {
75   myIsColored = false;
76   myColor.R = myColor.G = myColor.B = 0.5;
77   return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
78 }
79
80 //---------------------------------------------------------------
81 VISU::Storable* 
82 VISU::MonoColorPrs_i
83 ::Restore(SALOMEDS::SObject_ptr theSObject,
84           const Storable::TRestoringMap& theMap)
85 {
86   if(!TSuperClass::Restore(theSObject, theMap))
87     return NULL;
88
89   myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
90   myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
91   myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
92   myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
93
94   return this;
95 }
96
97 //---------------------------------------------------------------
98 void
99 VISU::MonoColorPrs_i
100 ::ToStream(std::ostringstream& theStr)
101 {
102   TSuperClass::ToStream(theStr);
103
104   Storable::DataToStream( theStr, "myIsColored", myIsColored );
105   Storable::DataToStream( theStr, "myColor.R", myColor.R );
106   Storable::DataToStream( theStr, "myColor.G", myColor.G );
107   Storable::DataToStream( theStr, "myColor.B", myColor.B );
108 }
109
110
111 //---------------------------------------------------------------
112 VISU::MonoColorPrs_i::~MonoColorPrs_i()
113 {
114   if(MYDEBUG) MESSAGE("MonoColorPrs_i::~MonoColorPrs_i()");
115 }
116
117 //---------------------------------------------------------------
118 CORBA::Boolean VISU::MonoColorPrs_i::IsColored()
119 {
120   return myIsColored;
121 }
122
123
124
125 //---------------------------------------------------------------
126 void
127 VISU::MonoColorPrs_i::ShowColored(CORBA::Boolean theColored)
128 {
129   if(myIsColored == theColored)
130     return;
131   myIsColored = theColored; 
132   myParamsTime.Modified();
133 }
134
135 //---------------------------------------------------------------
136 SALOMEDS::Color VISU::MonoColorPrs_i::GetColor()
137 {
138   return myColor;
139 }
140
141 //---------------------------------------------------------------
142 void VISU::MonoColorPrs_i::SetColor(const SALOMEDS::Color& theColor)
143 {
144   bool anIsSameValue = VISU::CheckIsSameValue(myColor.R, theColor.R);
145   anIsSameValue &= VISU::CheckIsSameValue(myColor.G, theColor.G);
146   anIsSameValue &= VISU::CheckIsSameValue(myColor.B, theColor.B);
147   if(anIsSameValue)
148     return;
149
150   VISU::TSetModified aModified(this);
151   
152   myColor = theColor;
153   myParamsTime.Modified();
154 }
155
156 //---------------------------------------------------------------
157 VISU_Actor* VISU::MonoColorPrs_i::CreateActor(bool toSupressShrinking) 
158 {
159   VISU_Actor* anActor = TSuperClass::CreateActor(toSupressShrinking);
160   anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
161   return anActor;
162 }
163
164 //---------------------------------------------------------------
165 VISU_Actor* VISU::MonoColorPrs_i::CreateActor()
166 {
167   return CreateActor(false);
168 }
169
170 //---------------------------------------------------------------
171 void VISU::MonoColorPrs_i::UpdateActor(VISU_ActorBase* theActor) 
172 {
173   if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
174     if(IsColored()){
175       anActor->SetBarVisibility(true);
176       GetPipeLine()->GetMapper()->SetScalarVisibility(1);
177     }else{
178       anActor->SetBarVisibility(false);
179       GetPipeLine()->GetMapper()->SetScalarVisibility(0);
180       anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
181     }
182     TSuperClass::UpdateActor(theActor);
183   }
184 }
185