Salome HOME
Merge with PAL/SALOME 2.1.0d
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_GraphicAttribute.cxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
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 //
24 //  File   : SALOMEDS_GraphicAttribute.cxx
25 //  Author : Sergey LITONIN
26 //  Module : SALOME
27
28 #include "SALOMEDS_GraphicAttribute.hxx"
29 #include <TDF_Attribute.hxx>
30 #include <Standard_GUID.hxx>
31 #include <TDF_Label.hxx>
32 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
33
34 /*
35   Class       : SALOMEDS_GraphicAttribute
36   Description : This class is intended for storing information about
37                 graphic representation of objects in dirrent views
38 */
39
40 IMPLEMENT_STANDARD_HANDLE( SALOMEDS_GraphicAttribute, TDF_Attribute )
41 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDS_GraphicAttribute, TDF_Attribute )
42
43 //=======================================================================
44 //function : GetID
45 //purpose  : Get GUID of this attribute
46 //=======================================================================
47 const Standard_GUID& SALOMEDS_GraphicAttribute::GetID()
48 {
49   static Standard_GUID SALOMEDS_GraphicAttributeID( "F17AE8F0-E354-4d6f-8E42-38385C36E67E" );
50   return SALOMEDS_GraphicAttributeID;
51 }
52
53 //=======================================================================
54 //function : SALOMEDS_GraphicAttribute
55 //purpose  : Empty Constructor
56 //=======================================================================
57 SALOMEDS_GraphicAttribute::SALOMEDS_GraphicAttribute()
58 {
59 }
60
61 //=======================================================================
62 //function : ~SALOMEDS_GraphicAttribute
63 //purpose  : Destructor
64 //=======================================================================
65 SALOMEDS_GraphicAttribute::~SALOMEDS_GraphicAttribute()
66 {
67 }
68
69 //=======================================================================
70 //function : SetVisibility
71 //purpose  : Set visibility of object in given view
72 //=======================================================================
73 void SALOMEDS_GraphicAttribute::SetVisibility( const Standard_Integer theViewId,
74                                                const Standard_Boolean theValue )
75 {
76   if ( myVisibility.IsBound( theViewId ) && myVisibility( theViewId ) == theValue )
77     return;
78
79   Backup();
80   if ( myVisibility.IsBound( theViewId ) )
81     myVisibility.ChangeFind( theViewId ) = theValue ? 1 : 0;
82   else
83     myVisibility.Bind( theViewId, theValue ? 1 : 0 );
84 }
85
86
87 //=======================================================================
88 //function : Get
89 //purpose  : Get visibility of object in given view
90 //=======================================================================
91 Standard_Boolean SALOMEDS_GraphicAttribute::GetVisibility(
92   const Standard_Integer theViewId ) const
93 {
94   return myVisibility.IsBound( theViewId ) ? myVisibility( theViewId ) : false;
95 }
96
97
98 //=======================================================================
99 //function : ID
100 //purpose  : Get GUID of this attribute
101 //=======================================================================
102 const Standard_GUID& SALOMEDS_GraphicAttribute::ID () const
103 {
104   return GetID();
105 }
106
107
108 //=======================================================================
109 //function : NewEmpty
110 //purpose  : Create new empty attribute
111 //=======================================================================
112 Handle(TDF_Attribute) SALOMEDS_GraphicAttribute::NewEmpty () const
113 {
114   return new SALOMEDS_GraphicAttribute ();
115 }
116
117 //=======================================================================
118 //function : SetVisibility
119 //purpose  : Set visibility of object in all views
120 //=======================================================================
121 void SALOMEDS_GraphicAttribute::SetVisibility( const TColStd_DataMapOfIntegerInteger& theMap )
122 {
123   myVisibility = theMap;
124 }
125
126 //=======================================================================
127 //function : SetVisibility
128 //purpose  : Get visibility of object in all views
129 //=======================================================================
130 const TColStd_DataMapOfIntegerInteger& SALOMEDS_GraphicAttribute::GetVisibility()
131 {
132   return myVisibility;
133 }
134
135 //=======================================================================
136 //function : Restore
137 //purpose  : Restore value of attribute with value of theWith one
138 //=======================================================================
139 void SALOMEDS_GraphicAttribute::Restore( const Handle(TDF_Attribute)& theWith )
140 {
141   Handle(SALOMEDS_GraphicAttribute) anAttr =
142     Handle(SALOMEDS_GraphicAttribute)::DownCast( theWith );
143
144   if ( !anAttr.IsNull() )
145     SetVisibility( anAttr->GetVisibility() );
146 }
147
148 //=======================================================================
149 //function : Paste
150 //purpose  : Paste value of current attribute to the value of entry one
151 //=======================================================================
152 void SALOMEDS_GraphicAttribute::Paste( const Handle(TDF_Attribute)& theInto,
153                                        const Handle(TDF_RelocationTable)& ) const
154 {
155   Handle(SALOMEDS_GraphicAttribute) anAttr =
156     Handle(SALOMEDS_GraphicAttribute)::DownCast( theInto );
157
158   if ( !anAttr.IsNull() )
159     anAttr->SetVisibility( myVisibility );
160 }
161
162 //=======================================================================
163 //function : Dump
164 //purpose  : Dump
165 //=======================================================================
166 Standard_OStream& SALOMEDS_GraphicAttribute::Dump( Standard_OStream& anOS ) const
167 {
168   anOS << "Visibility of object:" << endl;
169   TColStd_DataMapIteratorOfDataMapOfIntegerInteger anIter( myVisibility );
170   for ( ; anIter.More(); anIter.Next() )
171   {
172     char str[ 100 ];
173     
174     if ( GetVisibility( anIter.Key() ) )
175       sprintf( str, "Viewer ID = 0x%X State = VISIBLE\n", anIter.Key() );
176     else
177       sprintf( str, "Viewer ID = 0x%X State = INVISIBLE\n", anIter.Key() );
178       
179     anOS << str;
180   }
181   
182   anOS << "Integer";
183   return anOS;
184 }
185