1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // VISU OBJECT : interactive object for VISU entities implementation
21 // File : VISU_MonoColorPrs_i.cxx
22 // Author : Vitaly Smetannikov
25 #include "VISU_MonoColorPrs_i.hh"
26 #include "VISU_Prs3dUtils.hh"
27 #include "VISU_PipeLineUtils.hxx"
28 #include "VISU_ScalarMapAct.h"
30 #include "VISU_PipeLine.hxx"
32 #include <vtkDataSetMapper.h>
33 #include <vtkProperty.h>
36 static int MYDEBUG = 0;
38 static int MYDEBUG = 0;
41 //---------------------------------------------------------------
43 ::MonoColorPrs_i(EPublishInStudyMode thePublishInStudyMode):
44 ColoredPrs3d_i(thePublishInStudyMode),
45 ScalarMap_i(thePublishInStudyMode)
47 if(MYDEBUG) MESSAGE("MonoColorPrs_i::MonoColorPrs_i");
50 //---------------------------------------------------------------
53 ::SameAs(const Prs3d_i* theOrigin)
55 TSuperClass::SameAs(theOrigin);
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());
65 //---------------------------------------------------------------
68 ::Create(const std::string& theMeshName,
69 VISU::Entity theEntity,
70 const std::string& theFieldName,
71 CORBA::Long theTimeStampNumber)
74 myColor.R = myColor.G = myColor.B = 0.5;
75 return TSuperClass::Create(theMeshName,theEntity,theFieldName,theTimeStampNumber);
78 //---------------------------------------------------------------
81 ::Restore(SALOMEDS::SObject_ptr theSObject,
82 const Storable::TRestoringMap& theMap)
84 if(!TSuperClass::Restore(theSObject, theMap))
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();
95 //---------------------------------------------------------------
98 ::ToStream(std::ostringstream& theStr)
100 TSuperClass::ToStream(theStr);
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 );
109 //---------------------------------------------------------------
110 VISU::MonoColorPrs_i::~MonoColorPrs_i()
112 if(MYDEBUG) MESSAGE("MonoColorPrs_i::~MonoColorPrs_i()");
115 //---------------------------------------------------------------
116 CORBA::Boolean VISU::MonoColorPrs_i::IsColored()
123 //---------------------------------------------------------------
125 VISU::MonoColorPrs_i::ShowColored(CORBA::Boolean theColored)
127 if(myIsColored == theColored)
129 myIsColored = theColored;
130 myParamsTime.Modified();
133 //---------------------------------------------------------------
134 SALOMEDS::Color VISU::MonoColorPrs_i::GetColor()
139 //---------------------------------------------------------------
140 void VISU::MonoColorPrs_i::SetColor(const SALOMEDS::Color& theColor)
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);
148 VISU::TSetModified aModified(this);
151 myParamsTime.Modified();
154 //---------------------------------------------------------------
155 VISU_Actor* VISU::MonoColorPrs_i::CreateActor(bool toSupressShrinking)
157 VISU_Actor* anActor = TSuperClass::CreateActor(toSupressShrinking);
158 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
162 //---------------------------------------------------------------
163 VISU_Actor* VISU::MonoColorPrs_i::CreateActor()
165 return CreateActor(false);
168 //---------------------------------------------------------------
169 void VISU::MonoColorPrs_i::UpdateActor(VISU_ActorBase* theActor)
171 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
173 GetPipeLine()->GetMapper()->SetScalarVisibility(1);
175 GetPipeLine()->GetMapper()->SetScalarVisibility(0);
176 anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B);
178 TSuperClass::UpdateActor(theActor);
180 // this method should be called after TSuperClass::UpdateActor()
181 anActor->SetBarVisibility( IsBarVisible() && IsColored() );