973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
997e128f |
14 | #include <Standard_Transient.hxx> |
15 | #include <Standard_Type.hxx> |
7fd59977 |
16 | #include <Interface_DataMapIteratorOfDataMapOfTransientInteger.hxx> |
42cf5bc1 |
17 | #include <Interface_InterfaceModel.hxx> |
18 | #include <Interface_Protocol.hxx> |
42cf5bc1 |
19 | #include <StepData_Described.hxx> |
ec357c5c |
20 | #include <StepData_ECDescr.hxx> |
42cf5bc1 |
21 | #include <StepData_EDescr.hxx> |
22 | #include <StepData_ESDescr.hxx> |
23 | #include <StepData_PDescr.hxx> |
24 | #include <StepData_Protocol.hxx> |
25 | #include <StepData_StepModel.hxx> |
26 | #include <StepData_UndefinedEntity.hxx> |
7fd59977 |
27 | |
42cf5bc1 |
28 | #include <stdio.h> |
92efcf78 |
29 | IMPLEMENT_STANDARD_RTTIEXT(StepData_Protocol,Interface_Protocol) |
30 | |
7fd59977 |
31 | // Le Protocol de base reconnait UnknownEntity |
7fd59977 |
32 | //static TCollection_AsciiString thename("(DEFAULT)"); |
33 | static Standard_CString thename = "(DEFAULT)"; |
34 | |
35 | StepData_Protocol::StepData_Protocol () |
36 | { |
37 | } |
38 | |
39 | Standard_Integer StepData_Protocol::NbResources () const |
40 | { |
41 | return 0; |
42 | } |
43 | |
44 | |
45 | Handle(Interface_Protocol) StepData_Protocol::Resource |
46 | (const Standard_Integer /*num*/) const |
47 | { |
48 | Handle(Interface_Protocol) nulproto; |
49 | return nulproto; |
50 | } |
51 | |
52 | |
53 | Standard_Integer StepData_Protocol::CaseNumber |
54 | (const Handle(Standard_Transient)& obj) const |
55 | { |
56 | if (obj.IsNull()) return 0; |
57 | Standard_Integer num = TypeNumber (obj->DynamicType()); |
58 | if (num > 0) return num; |
59 | Handle(StepData_Described) dc = Handle(StepData_Described)::DownCast(obj); |
60 | if (dc.IsNull()) return 0; |
61 | return DescrNumber (dc->Description()); |
62 | } |
63 | |
64 | |
65 | Standard_Integer StepData_Protocol::TypeNumber |
66 | (const Handle(Standard_Type)& atype) const |
67 | { |
68 | if (atype == STANDARD_TYPE(StepData_UndefinedEntity)) return 1; |
69 | return 0; |
70 | } |
71 | |
72 | |
73 | Standard_CString StepData_Protocol::SchemaName () const |
74 | { |
75 | return thename; |
76 | } |
77 | |
78 | |
79 | Handle(Interface_InterfaceModel) StepData_Protocol::NewModel () const |
80 | { |
81 | return new StepData_StepModel; |
82 | } |
83 | |
84 | |
85 | Standard_Boolean StepData_Protocol::IsSuitableModel |
86 | (const Handle(Interface_InterfaceModel)& model) const |
87 | { |
88 | return model->IsKind(STANDARD_TYPE(StepData_StepModel)); |
89 | } |
90 | |
91 | |
92 | Handle(Standard_Transient) StepData_Protocol::UnknownEntity () const |
93 | { |
94 | return new StepData_UndefinedEntity; |
95 | } |
96 | |
97 | |
98 | Standard_Boolean StepData_Protocol::IsUnknownEntity |
99 | (const Handle(Standard_Transient)& ent) const |
100 | { |
101 | if (!ent.IsNull()) |
102 | return ent->IsKind(STANDARD_TYPE(StepData_UndefinedEntity)); |
103 | return Standard_False; |
104 | } |
105 | |
106 | |
107 | // #### Description pour LateBinding |
108 | |
109 | Standard_Integer StepData_Protocol::DescrNumber |
110 | (const Handle(StepData_EDescr)& adescr) const |
111 | { |
112 | if (thedscnum.IsBound(adescr)) return thedscnum.Find(adescr); |
113 | return 0; |
114 | } |
115 | |
116 | |
117 | void StepData_Protocol::AddDescr |
118 | (const Handle(StepData_EDescr)& adescr, const Standard_Integer CN) |
119 | { |
120 | Handle(StepData_ESDescr) sd = Handle(StepData_ESDescr)::DownCast(adescr); |
121 | thedscnum.Bind (adescr,CN); |
122 | |
123 | // Simple : memorisee selon son nom |
124 | // sinon que faire ? on memorise selon le numero passe en alpha-num ... |
125 | // (temporaire) |
997e128f |
126 | if (!sd.IsNull()) thedscnam.Bind(sd->TypeName(),sd); |
7fd59977 |
127 | char fonom[10]; |
128 | sprintf(fonom,"%d",CN); |
997e128f |
129 | thedscnam.Bind(fonom,adescr); |
7fd59977 |
130 | } |
131 | |
132 | |
133 | Standard_Boolean StepData_Protocol::HasDescr () const |
134 | { |
997e128f |
135 | return !thedscnam.IsEmpty(); |
7fd59977 |
136 | } |
137 | |
138 | |
139 | Handle(StepData_EDescr) StepData_Protocol::Descr |
140 | (const Standard_Integer num) const |
141 | { |
142 | Handle(StepData_EDescr) dsc; |
997e128f |
143 | if (thedscnam.IsEmpty()) return dsc; |
7fd59977 |
144 | char fonom[10]; |
145 | sprintf(fonom,"%d",num); |
997e128f |
146 | Handle(Standard_Transient) aTDsc; |
147 | if (thedscnam.Find(fonom, aTDsc)) |
148 | dsc = Handle(StepData_EDescr)::DownCast(aTDsc); |
149 | else |
150 | dsc.Nullify(); |
7fd59977 |
151 | return dsc; |
152 | } |
153 | |
154 | |
155 | Handle(StepData_EDescr) StepData_Protocol::Descr |
156 | (const Standard_CString name, const Standard_Boolean anylevel) const |
157 | { |
158 | Handle(StepData_EDescr) sd; |
997e128f |
159 | if (!thedscnam.IsEmpty()) { |
160 | Handle(Standard_Transient) aTSd; |
161 | if (thedscnam.Find(name, aTSd)) |
162 | return Handle(StepData_EDescr)::DownCast(aTSd); |
7fd59977 |
163 | } |
164 | if (!anylevel) return sd; |
165 | |
166 | Standard_Integer i, nb = NbResources(); |
167 | for (i = 1; i <= nb; i ++) { |
168 | Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i)); |
169 | if (sp.IsNull()) continue; |
170 | sd = sp->Descr (name,anylevel); |
171 | if (!sd.IsNull()) return sd; |
172 | } |
173 | return sd; |
174 | } |
175 | |
176 | |
177 | Handle(StepData_ESDescr) StepData_Protocol::ESDescr |
178 | (const Standard_CString name, const Standard_Boolean anylevel) const |
179 | { |
180 | return Handle(StepData_ESDescr)::DownCast(Descr(name,anylevel)); |
181 | } |
182 | |
183 | |
184 | Handle(StepData_ECDescr) StepData_Protocol::ECDescr |
185 | (const TColStd_SequenceOfAsciiString& names, const Standard_Boolean anylevel) const |
186 | { |
187 | Standard_Integer i, nb = names.Length(); |
188 | Handle(StepData_ECDescr) cd; |
189 | Interface_DataMapIteratorOfDataMapOfTransientInteger iter(thedscnum); |
190 | for (; iter.More(); iter.Next()) { |
191 | cd = Handle(StepData_ECDescr)::DownCast (iter.Key()); |
192 | if (cd.IsNull()) continue; |
193 | if (cd->NbMembers() != nb) continue; |
194 | Standard_Boolean ok = Standard_True; |
195 | for (i = 1; i <= nb; i ++) { |
196 | if (!names(i).IsEqual (cd->Member(i)->TypeName())) { ok = Standard_False; break; } |
197 | } |
198 | if (ok) return cd; |
199 | } |
200 | cd.Nullify(); |
201 | if (!anylevel) return cd; |
202 | |
203 | nb = NbResources(); |
204 | for (i = 1; i <= nb; i ++) { |
205 | Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i)); |
206 | if (sp.IsNull()) continue; |
207 | cd = sp->ECDescr (names,anylevel); |
208 | if (!cd.IsNull()) return cd; |
209 | } |
210 | return cd; |
211 | } |
212 | |
213 | |
214 | void StepData_Protocol::AddPDescr |
215 | (const Handle(StepData_PDescr)& pdescr) |
216 | { |
997e128f |
217 | thepdescr.Bind(pdescr->Name(),pdescr); |
7fd59977 |
218 | } |
219 | |
220 | |
221 | Handle(StepData_PDescr) StepData_Protocol::PDescr |
222 | (const Standard_CString name, const Standard_Boolean anylevel) const |
223 | { |
224 | Handle(StepData_PDescr) sd; |
997e128f |
225 | if (!thepdescr.IsEmpty()) { |
226 | Handle(Standard_Transient) aTSd; |
227 | if (thepdescr.Find(name, aTSd)) |
228 | return Handle(StepData_PDescr)::DownCast(aTSd); |
7fd59977 |
229 | } |
230 | if (!anylevel) return sd; |
231 | |
232 | Standard_Integer i, nb = NbResources(); |
233 | for (i = 1; i <= nb; i ++) { |
234 | Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i)); |
235 | if (sp.IsNull()) continue; |
236 | sd = sp->PDescr (name,anylevel); |
237 | if (!sd.IsNull()) return sd; |
238 | } |
239 | return sd; |
240 | } |
241 | |
242 | |
243 | void StepData_Protocol::AddBasicDescr |
244 | (const Handle(StepData_ESDescr)& esdescr) |
245 | { |
997e128f |
246 | thedscbas.Bind(esdescr->TypeName(),esdescr); |
7fd59977 |
247 | } |
248 | |
249 | |
250 | Handle(StepData_EDescr) StepData_Protocol::BasicDescr |
251 | (const Standard_CString name, const Standard_Boolean anylevel) const |
252 | { |
253 | Handle(StepData_EDescr) sd; |
997e128f |
254 | if (!thedscbas.IsEmpty()) { |
255 | Handle(Standard_Transient) aTSd; |
256 | if (thedscbas.Find(name, aTSd)) |
257 | return Handle(StepData_EDescr)::DownCast(aTSd); |
7fd59977 |
258 | } |
259 | if (!anylevel) return sd; |
260 | |
261 | Standard_Integer i, nb = NbResources(); |
262 | for (i = 1; i <= nb; i ++) { |
263 | Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i)); |
264 | if (sp.IsNull()) continue; |
265 | sd = sp->BasicDescr (name,anylevel); |
266 | if (!sd.IsNull()) return sd; |
267 | } |
268 | return sd; |
269 | } |