b311480e |
1 | // Created on: 2004-11-22 |
2 | // Created by: Pavel TELKOV |
973c2be1 |
3 | // Copyright (c) 2004-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
7fd59977 |
16 | // The original implementation Copyright: (C) RINA S.p.A |
17 | |
18 | #include <TObj_Assistant.hxx> |
19 | |
20 | #include <TObj_Common.hxx> |
21 | #include <TObj_Model.hxx> |
22 | #include <TColStd_SequenceOfTransient.hxx> |
23 | #include <TColStd_SequenceOfAsciiString.hxx> |
24 | #include <TColStd_IndexedMapOfTransient.hxx> |
ec357c5c |
25 | #include <Standard_Type.hxx> |
7fd59977 |
26 | |
27 | //======================================================================= |
28 | //function : getModels |
29 | //purpose : |
30 | //======================================================================= |
31 | |
32 | TColStd_SequenceOfTransient& TObj_Assistant::getModels() |
33 | { |
34 | static TColStd_SequenceOfTransient sModels; |
35 | return sModels; |
36 | } |
37 | |
38 | //======================================================================= |
39 | //function : getTypes |
40 | //purpose : |
41 | //======================================================================= |
42 | |
43 | TColStd_IndexedMapOfTransient& TObj_Assistant::getTypes() |
44 | { |
45 | static TColStd_IndexedMapOfTransient sTypes; |
46 | return sTypes; |
47 | } |
48 | |
49 | //======================================================================= |
50 | //function : getTypes |
51 | //purpose : |
52 | //======================================================================= |
53 | |
54 | Handle(TObj_Model)& TObj_Assistant::getCurrentModel() |
55 | { |
56 | static Handle(TObj_Model) sCurrentModel; |
57 | return sCurrentModel; |
58 | } |
59 | |
60 | //======================================================================= |
61 | //function : getVersion |
62 | //purpose : |
63 | //======================================================================= |
64 | |
65 | Standard_Integer& TObj_Assistant::getVersion() |
66 | { |
67 | static Standard_Integer sVersion = 0; |
68 | return sVersion; |
69 | } |
70 | |
71 | //======================================================================= |
72 | //function : FindModel |
73 | //purpose : |
74 | //======================================================================= |
75 | |
76 | Handle(TObj_Model) TObj_Assistant::FindModel |
77 | (const Standard_CString theName) |
78 | { |
79 | TCollection_ExtendedString aName( theName ); |
80 | Standard_Integer i = getModels().Length(); |
81 | Handle(TObj_Model) aModel; |
82 | for(; i > 0; i --) |
83 | { |
84 | aModel = Handle(TObj_Model)::DownCast(getModels().Value( i )); |
85 | if ( aName == aModel->GetModelName()->String() ) |
86 | break; |
87 | } |
88 | if (i == 0) |
89 | aModel.Nullify(); |
90 | |
91 | return aModel; |
92 | } |
93 | |
94 | //======================================================================= |
95 | //function : BindModel |
96 | //purpose : |
97 | //======================================================================= |
98 | |
99 | void TObj_Assistant::BindModel (const Handle(TObj_Model) theModel) |
100 | { |
101 | getModels().Append(theModel); |
102 | } |
103 | |
104 | //======================================================================= |
105 | //function : Clear |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | void TObj_Assistant::ClearModelMap () |
110 | { |
111 | getModels().Clear(); |
112 | } |
113 | |
114 | //======================================================================= |
115 | //function : FindType |
116 | //purpose : |
117 | //======================================================================= |
118 | |
119 | Handle(Standard_Type) TObj_Assistant::FindType |
120 | (const Standard_Integer theTypeIndex) |
121 | { |
122 | if(theTypeIndex > 0 && theTypeIndex <= getTypes().Extent()) |
123 | return Handle(Standard_Type)::DownCast(getTypes().FindKey(theTypeIndex)); |
124 | |
125 | return 0; |
126 | } |
127 | |
128 | //======================================================================= |
129 | //function : FindTypeIndex |
130 | //purpose : |
131 | //======================================================================= |
132 | |
133 | Standard_Integer TObj_Assistant::FindTypeIndex |
134 | (const Handle(Standard_Type)& theType) |
135 | { |
136 | if(!getTypes().Contains(theType)) |
137 | return 0; |
138 | |
139 | return getTypes().FindIndex(theType); |
140 | } |
141 | |
142 | //======================================================================= |
143 | //class : TObj_Assistant_UnknownType |
144 | //purpose : |
145 | //======================================================================= |
146 | |
147 | class TObj_Assistant_UnknownType : public MMgt_TShared |
148 | { |
149 | public: |
150 | |
151 | TObj_Assistant_UnknownType() {} |
152 | // Empty constructor |
153 | |
154 | // CASCADE RTTI |
ec357c5c |
155 | DEFINE_STANDARD_RTTI(TObj_Assistant_UnknownType, MMgt_TShared) |
7fd59977 |
156 | }; |
157 | |
158 | // Define handle class for TObj_Assistant_UnknownType |
159 | DEFINE_STANDARD_HANDLE(TObj_Assistant_UnknownType,MMgt_TShared) |
160 | |
7fd59977 |
161 | |
162 | //======================================================================= |
163 | //function : BindType |
164 | //purpose : |
165 | //======================================================================= |
166 | |
167 | Standard_Integer TObj_Assistant::BindType |
168 | (const Handle(Standard_Type)& theType) |
169 | { |
170 | if(theType.IsNull()) |
171 | { |
172 | Handle(Standard_Transient) anUnknownType; |
173 | anUnknownType = new TObj_Assistant_UnknownType; |
174 | return getTypes().Add(anUnknownType); |
175 | } |
176 | |
177 | return getTypes().Add(theType); |
178 | } |
179 | |
180 | //======================================================================= |
181 | //function : ClearTypeMap |
182 | //purpose : |
183 | //======================================================================= |
184 | |
185 | void TObj_Assistant::ClearTypeMap () |
186 | { |
187 | getTypes().Clear(); |
188 | } |
189 | |
190 | //======================================================================= |
191 | //function : SetCurrentModel |
192 | //purpose : |
193 | //======================================================================= |
194 | |
195 | void TObj_Assistant::SetCurrentModel (const Handle(TObj_Model)& theModel) |
196 | { |
197 | getCurrentModel() = theModel; |
198 | getVersion() = -1; |
199 | } |
200 | |
201 | //======================================================================= |
202 | //function : GetCurrentModel |
203 | //purpose : |
204 | //======================================================================= |
205 | |
206 | Handle(TObj_Model) TObj_Assistant::GetCurrentModel () |
207 | { |
208 | return getCurrentModel(); |
209 | } |
210 | |
211 | //======================================================================= |
212 | //function : UnSetCurrentModel |
213 | //purpose : |
214 | //======================================================================= |
215 | |
216 | void TObj_Assistant::UnSetCurrentModel () |
217 | { |
218 | getCurrentModel().Nullify(); |
219 | } |
220 | |
221 | //======================================================================= |
222 | //function : GetAppVersion |
223 | //purpose : |
224 | //======================================================================= |
225 | |
226 | Standard_Integer TObj_Assistant::GetAppVersion() |
227 | { |
228 | Standard_Integer& aVersion = getVersion(); |
229 | if (aVersion < 0) |
230 | { |
231 | Handle(TObj_Model)& aModel = getCurrentModel(); |
232 | if (!aModel.IsNull()) |
233 | aVersion = aModel->GetFormatVersion(); |
234 | } |
235 | return aVersion; |
236 | } |