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 | |
7fd59977 |
14 | |
42cf5bc1 |
15 | #include <Interface_Macros.hxx> |
16 | #include <Standard_Type.hxx> |
17 | #include <StepData_Described.hxx> |
18 | #include <StepData_ESDescr.hxx> |
19 | #include <StepData_PDescr.hxx> |
20 | #include <StepData_Simple.hxx> |
21 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
22 | |
92efcf78 |
23 | IMPLEMENT_STANDARD_RTTIEXT(StepData_ESDescr,StepData_EDescr) |
24 | |
7fd59977 |
25 | StepData_ESDescr::StepData_ESDescr (const Standard_CString name) |
997e128f |
26 | : thenom (name) { } |
7fd59977 |
27 | |
28 | void StepData_ESDescr::SetNbFields (const Standard_Integer nb) |
29 | { |
30 | Standard_Integer minb,i, oldnb = NbFields(); |
997e128f |
31 | thenames.Clear(); |
7fd59977 |
32 | if (nb == 0) { thedescr.Nullify(); return; } |
33 | Handle(TColStd_HArray1OfTransient) li = new TColStd_HArray1OfTransient(1,nb); |
34 | if (oldnb == 0) { thedescr = li; return; } |
35 | minb = (oldnb > nb ? nb : oldnb); |
36 | for (i = 1; i <= minb; i ++) { |
37 | DeclareAndCast(StepData_PDescr,pde,thedescr->Value(i)); |
997e128f |
38 | if (!pde.IsNull()) thenames.Bind(pde->Name(),i); |
7fd59977 |
39 | li->SetValue (i, pde); |
40 | } |
41 | thedescr = li; |
42 | } |
43 | |
44 | |
45 | void StepData_ESDescr::SetField |
46 | (const Standard_Integer num, const Standard_CString name, |
47 | const Handle(StepData_PDescr)& descr) |
48 | { |
49 | if (num < 1 || num > NbFields()) return; |
50 | Handle(StepData_PDescr) pde = new StepData_PDescr; |
51 | pde->SetFrom (descr); |
52 | pde->SetName (name); |
53 | thedescr->SetValue (num,pde); |
997e128f |
54 | thenames.Bind(name,num); |
7fd59977 |
55 | } |
56 | |
57 | void StepData_ESDescr::SetBase (const Handle(StepData_ESDescr)& base) |
58 | { |
59 | thebase = base; |
60 | // il faut CUMULER les fields de la base et ses supers |
61 | } |
62 | |
63 | void StepData_ESDescr::SetSuper (const Handle(StepData_ESDescr)& super) |
64 | { |
65 | Handle(StepData_ESDescr) sup = super->Base(); |
66 | if (sup.IsNull()) sup = super; |
67 | if (!thebase.IsNull()) thebase->SetSuper (sup); |
68 | else thesuper = sup; |
69 | } |
70 | |
71 | Standard_CString StepData_ESDescr::TypeName () const |
72 | { return thenom.ToCString(); } |
73 | |
74 | const TCollection_AsciiString& StepData_ESDescr::StepType () const |
75 | { return thenom; } |
76 | |
77 | Handle(StepData_ESDescr) StepData_ESDescr::Base () const |
78 | { return thebase; } |
79 | |
80 | Handle(StepData_ESDescr) StepData_ESDescr::Super () const |
81 | { return thesuper; } |
82 | |
83 | Standard_Boolean StepData_ESDescr::IsSub (const Handle(StepData_ESDescr)& other) const |
84 | { |
85 | Handle(StepData_ESDescr) oth = other->Base(); |
86 | if (oth.IsNull()) oth = other; |
87 | if (!thebase.IsNull()) return thebase->IsSub (oth); |
88 | Handle(Standard_Transient) t1 = this; |
89 | if (oth == t1) return Standard_True; |
90 | if (oth == thesuper) return Standard_True; |
91 | else if (thesuper.IsNull()) return Standard_False; |
92 | return thesuper->IsSub (oth); |
93 | } |
94 | |
95 | |
96 | Standard_Integer StepData_ESDescr::NbFields () const |
97 | { return (thedescr.IsNull() ? 0 : thedescr->Length()); } |
98 | |
99 | Standard_Integer StepData_ESDescr::Rank (const Standard_CString name) const |
100 | { |
101 | Standard_Integer rank; |
997e128f |
102 | if (!thenames.Find(name, rank)) |
103 | return 0; |
7fd59977 |
104 | return rank; |
105 | } |
106 | |
107 | Standard_CString StepData_ESDescr::Name (const Standard_Integer num) const |
108 | { |
109 | if (num < 1) return ""; |
110 | if (num > NbFields()) return ""; |
111 | DeclareAndCast(StepData_PDescr,pde,thedescr->Value(num)); |
112 | return pde->Name(); |
113 | } |
114 | |
115 | Handle(StepData_PDescr) StepData_ESDescr::Field (const Standard_Integer num) const |
116 | { return GetCasted(StepData_PDescr,thedescr->Value(num)); } |
117 | |
118 | Handle(StepData_PDescr) StepData_ESDescr::NamedField |
119 | (const Standard_CString name) const |
120 | { |
121 | Handle(StepData_PDescr) pde; |
122 | Standard_Integer rank = Rank(name); |
123 | if (rank > 0) pde = GetCasted(StepData_PDescr,thedescr->Value(rank)); |
124 | return pde; |
125 | } |
126 | |
127 | |
128 | Standard_Boolean StepData_ESDescr::Matches (const Standard_CString name) const |
129 | { |
130 | if (thenom.IsEqual(name)) return Standard_True; |
131 | if (thesuper.IsNull()) return Standard_False; |
132 | return thesuper->Matches (name); |
133 | } |
134 | |
135 | Standard_Boolean StepData_ESDescr::IsComplex () const |
136 | { return Standard_False; } |
137 | |
138 | Handle(StepData_Described) StepData_ESDescr::NewEntity () const |
139 | { |
140 | Handle(StepData_Simple) ent = new StepData_Simple(this); |
141 | return ent; |
142 | } |