Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeGraphic.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDSImpl_AttributeGraphic.cxx
21 //  Author : Sergey LITONIN
22 //  Module : SALOME
23
24 #include "SALOMEDSImpl_AttributeGraphic.hxx"
25 #include <TDF_Attribute.hxx>
26 #include <Standard_GUID.hxx>
27 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
28
29 /*
30   Class       : SALOMEDSImpl_AttributeGraphic
31   Description : This class is intended for storing information about
32                 graphic representation of objects in dirrent views
33 */
34
35 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeGraphic, SALOMEDSImpl_GenericAttribute )
36 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeGraphic, SALOMEDSImpl_GenericAttribute )
37
38 //=======================================================================
39 //function : GetID
40 //purpose  : Get GUID of this attribute
41 //=======================================================================
42 const Standard_GUID& SALOMEDSImpl_AttributeGraphic::GetID()
43 {
44   static Standard_GUID SALOMEDSImpl_AttributeGraphicID( "F17AE8F0-E354-4d6f-8E42-38385C36E67E" );
45   return SALOMEDSImpl_AttributeGraphicID;
46 }
47
48 //=======================================================================
49 //function : SALOMEDSImpl_AttributeGraphic
50 //purpose  : Empty Constructor
51 //=======================================================================
52 SALOMEDSImpl_AttributeGraphic::SALOMEDSImpl_AttributeGraphic()
53 :SALOMEDSImpl_GenericAttribute("AttributeGraphic")
54 {
55 }
56
57 //=======================================================================
58 //function : ~SALOMEDSImpl_AttributeGraphic
59 //purpose  : Destructor
60 //=======================================================================
61 SALOMEDSImpl_AttributeGraphic::~SALOMEDSImpl_AttributeGraphic()
62 {
63 }
64
65 //=======================================================================
66 //function : SetVisibility
67 //purpose  : Set visibility of object in given view
68 //=======================================================================
69 void SALOMEDSImpl_AttributeGraphic::SetVisibility(const Standard_Integer theViewId,
70                                                   const Standard_Boolean theValue )
71 {
72   if ( myVisibility.IsBound( theViewId ) && myVisibility( theViewId ) == theValue )
73     return;
74
75   Backup();
76   if ( myVisibility.IsBound( theViewId ) )
77     myVisibility.ChangeFind( theViewId ) = theValue ? 1 : 0;
78   else
79     myVisibility.Bind( theViewId, theValue ? 1 : 0 );
80 }
81
82
83 //=======================================================================
84 //function : Get
85 //purpose  : Get visibility of object in given view
86 //=======================================================================
87 Standard_Boolean SALOMEDSImpl_AttributeGraphic::GetVisibility(const Standard_Integer theViewId ) const
88 {
89   return myVisibility.IsBound( theViewId ) ? myVisibility( theViewId ) : false;
90 }
91
92
93 //=======================================================================
94 //function : ID
95 //purpose  : Get GUID of this attribute
96 //=======================================================================
97 const Standard_GUID& SALOMEDSImpl_AttributeGraphic::ID () const
98 {
99   return GetID();
100 }
101
102
103 //=======================================================================
104 //function : NewEmpty
105 //purpose  : Create new empty attribute
106 //=======================================================================
107 Handle(TDF_Attribute) SALOMEDSImpl_AttributeGraphic::NewEmpty () const
108 {
109   return new SALOMEDSImpl_AttributeGraphic ();
110 }
111
112 //=======================================================================
113 //function : SetVisibility
114 //purpose  : Set visibility of object in all views
115 //=======================================================================
116 void SALOMEDSImpl_AttributeGraphic::SetVisibility( const TColStd_DataMapOfIntegerInteger& theMap )
117 {
118   myVisibility = theMap;
119 }
120
121 //=======================================================================
122 //function : SetVisibility
123 //purpose  : Get visibility of object in all views
124 //=======================================================================
125 const TColStd_DataMapOfIntegerInteger& SALOMEDSImpl_AttributeGraphic::GetVisibility()
126 {
127   return myVisibility;
128 }
129
130 //=======================================================================
131 //function : Restore
132 //purpose  : Restore value of attribute with value of theWith one
133 //=======================================================================
134 void SALOMEDSImpl_AttributeGraphic::Restore( const Handle(TDF_Attribute)& theWith )
135 {
136   Handle(SALOMEDSImpl_AttributeGraphic) anAttr =
137     Handle(SALOMEDSImpl_AttributeGraphic)::DownCast( theWith );
138
139   if ( !anAttr.IsNull() )
140     SetVisibility( anAttr->GetVisibility() );
141 }
142
143 //=======================================================================
144 //function : Paste
145 //purpose  : Paste value of current attribute to the value of entry one
146 //=======================================================================
147 void SALOMEDSImpl_AttributeGraphic::Paste( const Handle(TDF_Attribute)& theInto,
148                                        const Handle(TDF_RelocationTable)& ) const
149 {
150   Handle(SALOMEDSImpl_AttributeGraphic) anAttr =
151     Handle(SALOMEDSImpl_AttributeGraphic)::DownCast( theInto );
152
153   if ( !anAttr.IsNull() )
154     anAttr->SetVisibility( myVisibility );
155 }
156
157 //=======================================================================
158 //function : Dump
159 //purpose  : Dump
160 //=======================================================================
161 Standard_OStream& SALOMEDSImpl_AttributeGraphic::Dump( Standard_OStream& anOS ) const
162 {
163   anOS << "Visibility of object:" << endl;
164   TColStd_DataMapIteratorOfDataMapOfIntegerInteger anIter( myVisibility );
165   for ( ; anIter.More(); anIter.Next() )
166   {
167     char str[ 100 ];
168     
169     if ( GetVisibility( anIter.Key() ) )
170       sprintf( str, "Viewer ID = 0x%X State = VISIBLE\n", anIter.Key() );
171     else
172       sprintf( str, "Viewer ID = 0x%X State = INVISIBLE\n", anIter.Key() );
173       
174     anOS << str;
175   }
176   
177   anOS << "Integer";
178   return anOS;
179 }
180