0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / TObj / TObj_TNameContainer.cxx
1 // Created on: 2004-11-23
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 // The original implementation Copyright: (C) RINA S.p.A
17
18 #include <TObj_TNameContainer.hxx>
19 #include <Standard_GUID.hxx>
20
21
22 IMPLEMENT_STANDARD_RTTIEXT(TObj_TNameContainer,TDF_Attribute)
23
24 //=======================================================================
25 //function : TObj_TNameContainer
26 //purpose  : 
27 //=======================================================================
28
29 TObj_TNameContainer::TObj_TNameContainer()
30 {
31 }
32
33 //=======================================================================
34 //function : GetID
35 //purpose  : 
36 //=======================================================================
37
38 const Standard_GUID& TObj_TNameContainer::GetID()
39 {
40   static Standard_GUID theID ("3bbefb47-e618-11d4-ba38-0060b0ee18ea");
41   return theID;
42 }
43   
44 //=======================================================================
45 //function : ID
46 //purpose  : 
47 //=======================================================================
48
49 const Standard_GUID& TObj_TNameContainer::ID() const
50 {
51   return GetID();
52 }
53
54 //=======================================================================
55 //function : Set
56 //purpose  : 
57 //=======================================================================
58
59 Handle(TObj_TNameContainer) TObj_TNameContainer::Set(const TDF_Label& theLabel)
60 {
61   Handle(TObj_TNameContainer) A;
62   if (!theLabel.FindAttribute(TObj_TNameContainer::GetID(), A)) 
63   {
64     A = new TObj_TNameContainer;
65     theLabel.AddAttribute(A);
66   }
67   return A;
68 }
69
70 //=======================================================================
71 //function : RecordName
72 //purpose  : 
73 //=======================================================================
74
75 void TObj_TNameContainer::RecordName(const Handle(TCollection_HExtendedString)& theName,
76                                          const TDF_Label& theLabel)
77 {
78   if(!IsRegistered(theName)) 
79   {
80     Backup();
81     myMap.Bind(new TCollection_HExtendedString(theName->String()),theLabel);
82   }
83 }
84
85 //=======================================================================
86 //function : RemoveName
87 //purpose  : 
88 //=======================================================================
89
90 void TObj_TNameContainer::RemoveName(const Handle(TCollection_HExtendedString)& theName)
91 {
92   if(IsRegistered(theName)) 
93   {
94     Backup();
95     myMap.UnBind(theName);
96   }
97 }
98
99 void TObj_TNameContainer::Clear()
100 {
101   Backup();
102   myMap.Clear();
103 }
104
105 //=======================================================================
106 //function : CheckName
107 //purpose  : 
108 //=======================================================================
109
110 Standard_Boolean TObj_TNameContainer::IsRegistered(const Handle(TCollection_HExtendedString)& theName) const
111 {
112   return myMap.IsBound(theName);
113 }
114   
115 //=======================================================================
116 //function : NewEmpty
117 //purpose  : 
118 //=======================================================================
119
120 Handle(TDF_Attribute) TObj_TNameContainer::NewEmpty () const
121 {  
122   return new TObj_TNameContainer();
123 }
124
125 //=======================================================================
126 //function : Restore
127 //purpose  : 
128 //=======================================================================
129
130 void TObj_TNameContainer::Restore(const Handle(TDF_Attribute)& theWith) 
131 {
132   Handle(TObj_TNameContainer) R = Handle(TObj_TNameContainer)::DownCast (theWith);
133   
134   myMap = R->Get();
135 }
136
137 //=======================================================================
138 //function : Paste
139 //purpose  : 
140 //=======================================================================
141
142 void TObj_TNameContainer::Paste (const Handle(TDF_Attribute)& theInto,
143                                      const Handle(TDF_RelocationTable)& /* RT */) const
144
145   Handle(TObj_TNameContainer) R = Handle(TObj_TNameContainer)::DownCast (theInto);
146   R->Set(myMap);
147 }
148
149 //=======================================================================
150 //function : Get
151 //purpose  : 
152 //=======================================================================
153
154 const TObj_DataMapOfNameLabel& TObj_TNameContainer::Get() const
155 {
156   return myMap;
157 }
158
159 //=======================================================================
160 //function : Set
161 //purpose  : 
162 //=======================================================================
163
164 void TObj_TNameContainer::Set(const TObj_DataMapOfNameLabel& theMap)
165 {
166   Backup();
167   myMap.Assign (theMap);
168 }