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