0022788: Exception during closing of document due to corrupted memory
[occt.git] / src / TNaming / TNaming_UsedShapes.cxx
1 // File:        TNaming_UsedShapes.cxx
2 // Created:     Tue Feb 18 15:33:00 1997
3 // Author:      Yves FRICAUD
4 //              <yfr@claquox.paris1.matra-dtv.fr>
5
6
7 #include <TNaming_UsedShapes.ixx>
8
9 #include <TDF_DeltaOnAddition.hxx>
10 #include <TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape.hxx>
11 #include <TNaming_RefShape.hxx>
12 #include <TNaming_PtrNode.hxx>
13 #define BUC60862
14
15 #ifdef BUC60862
16 #include <TopoDS_Shape.hxx>
17 #endif
18
19 #define BUC60921      //SRN 15/05/01 : Fixes the memory leak due to pointer to RefShape is not deleted
20
21 //=======================================================================
22 //function : GetID
23 //purpose  : 
24 //=======================================================================
25
26 const Standard_GUID& TNaming_UsedShapes::GetID() 
27 {
28   static Standard_GUID TNaming_UsedShapesID("c4ef4201-568f-11d1-8940-080009dc3333");
29   return TNaming_UsedShapesID;
30 }
31
32 //=======================================================================
33 //function : 
34 //purpose  : 
35 //=======================================================================
36
37 TNaming_UsedShapes::TNaming_UsedShapes() 
38 {
39 }
40
41
42 //=======================================================================
43 //function : Destroy
44 //purpose  : 
45 //=======================================================================
46
47 void TNaming_UsedShapes::Destroy() 
48 {
49   myMap.Clear();
50 }
51
52 //=======================================================================
53 //function : BackupCopy
54 //purpose  : No Backup
55 //=======================================================================
56
57 Handle(TDF_Attribute) TNaming_UsedShapes::BackupCopy() const
58 {
59   Handle(TNaming_UsedShapes) Att;
60   return Att;
61 }
62
63 //=======================================================================
64 //function : BeforeRemoval
65 //purpose  : 
66 //=======================================================================
67
68 void TNaming_UsedShapes::BeforeRemoval() 
69 {
70 #ifdef BUC60921
71   Destroy();
72 #else
73   myMap.Clear(); 
74 #endif 
75 }
76
77
78 //=======================================================================
79 //function : AfterUndo
80 //purpose  : After application of a TDF_Delta.
81 //=======================================================================
82
83 Standard_Boolean TNaming_UsedShapes::AfterUndo
84 (const Handle(TDF_AttributeDelta)& anAttDelta,
85  const Standard_Boolean forceIt)
86 {
87   if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
88     anAttDelta->Attribute()->BeforeRemoval();
89   }
90   return Standard_True;
91 }
92
93 //=======================================================================
94 //function : DeltaOnAddition
95 //purpose  : no delta
96 //=======================================================================
97
98 Handle(TDF_DeltaOnAddition) TNaming_UsedShapes::DeltaOnAddition() const
99
100   Handle(TDF_DeltaOnAddition) aDelta;
101   return aDelta; 
102 }
103 //=======================================================================
104 //function : DeltaOnRemoval
105 //purpose  : no delta
106 //=======================================================================
107
108 Handle(TDF_DeltaOnRemoval) TNaming_UsedShapes::DeltaOnRemoval() const
109 {  
110   Handle(TDF_DeltaOnRemoval) aDelta;
111   return aDelta;
112
113
114 //=======================================================================
115 //function : Restore
116 //purpose  : 
117 //=======================================================================
118
119 void TNaming_UsedShapes::Restore(const Handle(TDF_Attribute)& anAttribute) 
120 {
121 }
122
123 //=======================================================================
124 //function : NewEmpty 
125 //purpose  : 
126 //=======================================================================
127
128 Handle(TDF_Attribute) TNaming_UsedShapes::NewEmpty () const
129 {
130   return new TNaming_UsedShapes();
131 }
132
133 //=======================================================================
134 //function : Paste
135 //purpose  : 
136 //=======================================================================
137
138 void  TNaming_UsedShapes::Paste(const Handle(TDF_Attribute)&       into,
139                                 const Handle(TDF_RelocationTable)& Tab) const
140
141 }
142
143 //=======================================================================
144 //function : Dump
145 //purpose  : 
146 //=======================================================================
147
148 Standard_OStream& TNaming_UsedShapes::Dump(Standard_OStream& anOS) const
149 {
150 #ifdef BUC60862
151   anOS<<"The content of UsedShapes attribute:"<<endl;
152   TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape itr(myMap);
153   for (; itr.More(); itr.Next()) {
154     anOS<<"  ";
155     TopAbs::Print(itr.Key().ShapeType(),anOS);
156     anOS<<"  ";
157     itr.Value()->Label().EntryDump(anOS);
158     anOS << " Key_TShape   = " <<itr.Key().TShape()->This();
159     anOS << " Value_TShape = " <<itr.Value()->Shape().TShape()->This();    
160     anOS<<endl;
161   }
162 #endif
163   return anOS;
164 }
165
166 //=======================================================================
167 //function : References
168 //purpose  : 
169 //=======================================================================
170
171 void TNaming_UsedShapes::References(const Handle(TDF_DataSet)& aDataSet) const
172 {
173 }