1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <StepData_Protocol.ixx>
15 #include <StepData_StepModel.hxx>
16 #include <StepData_UndefinedEntity.hxx>
17 #include <StepData_Described.hxx>
18 #include <Interface_DataMapIteratorOfDataMapOfTransientInteger.hxx>
22 // Le Protocol de base reconnait UnknownEntity
24 //static TCollection_AsciiString thename("(DEFAULT)");
25 static Standard_CString thename = "(DEFAULT)";
27 StepData_Protocol::StepData_Protocol ()
31 Standard_Integer StepData_Protocol::NbResources () const
37 Handle(Interface_Protocol) StepData_Protocol::Resource
38 (const Standard_Integer /*num*/) const
40 Handle(Interface_Protocol) nulproto;
45 Standard_Integer StepData_Protocol::CaseNumber
46 (const Handle(Standard_Transient)& obj) const
48 if (obj.IsNull()) return 0;
49 Standard_Integer num = TypeNumber (obj->DynamicType());
50 if (num > 0) return num;
51 Handle(StepData_Described) dc = Handle(StepData_Described)::DownCast(obj);
52 if (dc.IsNull()) return 0;
53 return DescrNumber (dc->Description());
57 Standard_Integer StepData_Protocol::TypeNumber
58 (const Handle(Standard_Type)& atype) const
60 if (atype == STANDARD_TYPE(StepData_UndefinedEntity)) return 1;
65 Standard_CString StepData_Protocol::SchemaName () const
71 Handle(Interface_InterfaceModel) StepData_Protocol::NewModel () const
73 return new StepData_StepModel;
77 Standard_Boolean StepData_Protocol::IsSuitableModel
78 (const Handle(Interface_InterfaceModel)& model) const
80 return model->IsKind(STANDARD_TYPE(StepData_StepModel));
84 Handle(Standard_Transient) StepData_Protocol::UnknownEntity () const
86 return new StepData_UndefinedEntity;
90 Standard_Boolean StepData_Protocol::IsUnknownEntity
91 (const Handle(Standard_Transient)& ent) const
94 return ent->IsKind(STANDARD_TYPE(StepData_UndefinedEntity));
95 return Standard_False;
99 // #### Description pour LateBinding
101 Standard_Integer StepData_Protocol::DescrNumber
102 (const Handle(StepData_EDescr)& adescr) const
104 if (thedscnum.IsBound(adescr)) return thedscnum.Find(adescr);
109 void StepData_Protocol::AddDescr
110 (const Handle(StepData_EDescr)& adescr, const Standard_Integer CN)
112 Handle(StepData_ESDescr) sd = Handle(StepData_ESDescr)::DownCast(adescr);
113 thedscnum.Bind (adescr,CN);
115 // Simple : memorisee selon son nom
116 // sinon que faire ? on memorise selon le numero passe en alpha-num ...
118 if (thedscnam.IsNull()) thedscnam = new Dico_DictionaryOfTransient;
119 if (!sd.IsNull()) thedscnam->SetItem (sd->TypeName(),sd);
121 sprintf(fonom,"%d",CN);
122 thedscnam->SetItem (fonom,adescr);
126 Standard_Boolean StepData_Protocol::HasDescr () const
128 return !thedscnam.IsNull();
132 Handle(StepData_EDescr) StepData_Protocol::Descr
133 (const Standard_Integer num) const
135 Handle(StepData_EDescr) dsc;
136 if (thedscnam.IsNull()) return dsc;
138 sprintf(fonom,"%d",num);
139 if (!thedscnam->GetItem (fonom,dsc)) dsc.Nullify();
144 Handle(StepData_EDescr) StepData_Protocol::Descr
145 (const Standard_CString name, const Standard_Boolean anylevel) const
147 Handle(StepData_EDescr) sd;
148 if (!thedscnam.IsNull()) {
149 if (thedscnam->GetItem (name,sd)) return sd;
151 if (!anylevel) return sd;
153 Standard_Integer i, nb = NbResources();
154 for (i = 1; i <= nb; i ++) {
155 Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i));
156 if (sp.IsNull()) continue;
157 sd = sp->Descr (name,anylevel);
158 if (!sd.IsNull()) return sd;
164 Handle(StepData_ESDescr) StepData_Protocol::ESDescr
165 (const Standard_CString name, const Standard_Boolean anylevel) const
167 return Handle(StepData_ESDescr)::DownCast(Descr(name,anylevel));
171 Handle(StepData_ECDescr) StepData_Protocol::ECDescr
172 (const TColStd_SequenceOfAsciiString& names, const Standard_Boolean anylevel) const
174 Standard_Integer i, nb = names.Length();
175 Handle(StepData_ECDescr) cd;
176 Interface_DataMapIteratorOfDataMapOfTransientInteger iter(thedscnum);
177 for (; iter.More(); iter.Next()) {
178 cd = Handle(StepData_ECDescr)::DownCast (iter.Key());
179 if (cd.IsNull()) continue;
180 if (cd->NbMembers() != nb) continue;
181 Standard_Boolean ok = Standard_True;
182 for (i = 1; i <= nb; i ++) {
183 if (!names(i).IsEqual (cd->Member(i)->TypeName())) { ok = Standard_False; break; }
188 if (!anylevel) return cd;
191 for (i = 1; i <= nb; i ++) {
192 Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i));
193 if (sp.IsNull()) continue;
194 cd = sp->ECDescr (names,anylevel);
195 if (!cd.IsNull()) return cd;
201 void StepData_Protocol::AddPDescr
202 (const Handle(StepData_PDescr)& pdescr)
204 if (thepdescr.IsNull()) thepdescr = new Dico_DictionaryOfTransient;
205 thepdescr->SetItem (pdescr->Name(),pdescr);
209 Handle(StepData_PDescr) StepData_Protocol::PDescr
210 (const Standard_CString name, const Standard_Boolean anylevel) const
212 Handle(StepData_PDescr) sd;
213 if (!thepdescr.IsNull()) {
214 if (thepdescr->GetItem (name,sd)) return sd;
216 if (!anylevel) return sd;
218 Standard_Integer i, nb = NbResources();
219 for (i = 1; i <= nb; i ++) {
220 Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i));
221 if (sp.IsNull()) continue;
222 sd = sp->PDescr (name,anylevel);
223 if (!sd.IsNull()) return sd;
229 void StepData_Protocol::AddBasicDescr
230 (const Handle(StepData_ESDescr)& esdescr)
232 if (thedscbas.IsNull()) thedscbas = new Dico_DictionaryOfTransient;
233 thedscbas->SetItem (esdescr->TypeName(),esdescr);
237 Handle(StepData_EDescr) StepData_Protocol::BasicDescr
238 (const Standard_CString name, const Standard_Boolean anylevel) const
240 Handle(StepData_EDescr) sd;
241 if (!thedscbas.IsNull()) {
242 if (thedscbas->GetItem (name,sd)) return sd;
244 if (!anylevel) return sd;
246 Standard_Integer i, nb = NbResources();
247 for (i = 1; i <= nb; i ++) {
248 Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i));
249 if (sp.IsNull()) continue;
250 sd = sp->BasicDescr (name,anylevel);
251 if (!sd.IsNull()) return sd;