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.
15 #include <Dico_DictionaryOfInteger.hxx>
16 #include <Interface_Macros.hxx>
17 #include <Standard_Type.hxx>
18 #include <StepData_Described.hxx>
19 #include <StepData_ESDescr.hxx>
20 #include <StepData_PDescr.hxx>
21 #include <StepData_Simple.hxx>
22 #include <TCollection_AsciiString.hxx>
24 IMPLEMENT_STANDARD_RTTIEXT(StepData_ESDescr,StepData_EDescr)
26 StepData_ESDescr::StepData_ESDescr (const Standard_CString name)
27 : thenom (name) { thenames = new Dico_DictionaryOfInteger; }
29 void StepData_ESDescr::SetNbFields (const Standard_Integer nb)
31 Standard_Integer minb,i, oldnb = NbFields();
33 if (nb == 0) { thedescr.Nullify(); return; }
34 Handle(TColStd_HArray1OfTransient) li = new TColStd_HArray1OfTransient(1,nb);
35 if (oldnb == 0) { thedescr = li; return; }
36 minb = (oldnb > nb ? nb : oldnb);
37 for (i = 1; i <= minb; i ++) {
38 DeclareAndCast(StepData_PDescr,pde,thedescr->Value(i));
39 if (!pde.IsNull()) thenames->SetItem (pde->Name(),i);
40 li->SetValue (i, pde);
46 void StepData_ESDescr::SetField
47 (const Standard_Integer num, const Standard_CString name,
48 const Handle(StepData_PDescr)& descr)
50 if (num < 1 || num > NbFields()) return;
51 Handle(StepData_PDescr) pde = new StepData_PDescr;
54 thedescr->SetValue (num,pde);
55 thenames->SetItem (name,num);
58 void StepData_ESDescr::SetBase (const Handle(StepData_ESDescr)& base)
61 // il faut CUMULER les fields de la base et ses supers
64 void StepData_ESDescr::SetSuper (const Handle(StepData_ESDescr)& super)
66 Handle(StepData_ESDescr) sup = super->Base();
67 if (sup.IsNull()) sup = super;
68 if (!thebase.IsNull()) thebase->SetSuper (sup);
72 Standard_CString StepData_ESDescr::TypeName () const
73 { return thenom.ToCString(); }
75 const TCollection_AsciiString& StepData_ESDescr::StepType () const
78 Handle(StepData_ESDescr) StepData_ESDescr::Base () const
81 Handle(StepData_ESDescr) StepData_ESDescr::Super () const
84 Standard_Boolean StepData_ESDescr::IsSub (const Handle(StepData_ESDescr)& other) const
86 Handle(StepData_ESDescr) oth = other->Base();
87 if (oth.IsNull()) oth = other;
88 if (!thebase.IsNull()) return thebase->IsSub (oth);
89 Handle(Standard_Transient) t1 = this;
90 if (oth == t1) return Standard_True;
91 if (oth == thesuper) return Standard_True;
92 else if (thesuper.IsNull()) return Standard_False;
93 return thesuper->IsSub (oth);
97 Standard_Integer StepData_ESDescr::NbFields () const
98 { return (thedescr.IsNull() ? 0 : thedescr->Length()); }
100 Standard_Integer StepData_ESDescr::Rank (const Standard_CString name) const
102 Standard_Integer rank;
103 if (!thenames->GetItem (name,rank)) return 0;
107 Standard_CString StepData_ESDescr::Name (const Standard_Integer num) const
109 if (num < 1) return "";
110 if (num > NbFields()) return "";
111 DeclareAndCast(StepData_PDescr,pde,thedescr->Value(num));
115 Handle(StepData_PDescr) StepData_ESDescr::Field (const Standard_Integer num) const
116 { return GetCasted(StepData_PDescr,thedescr->Value(num)); }
118 Handle(StepData_PDescr) StepData_ESDescr::NamedField
119 (const Standard_CString name) const
121 Handle(StepData_PDescr) pde;
122 Standard_Integer rank = Rank(name);
123 if (rank > 0) pde = GetCasted(StepData_PDescr,thedescr->Value(rank));
128 Standard_Boolean StepData_ESDescr::Matches (const Standard_CString name) const
130 if (thenom.IsEqual(name)) return Standard_True;
131 if (thesuper.IsNull()) return Standard_False;
132 return thesuper->Matches (name);
135 Standard_Boolean StepData_ESDescr::IsComplex () const
136 { return Standard_False; }
138 Handle(StepData_Described) StepData_ESDescr::NewEntity () const
140 Handle(StepData_Simple) ent = new StepData_Simple(this);