0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / StepData / StepData_PDescr.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <Interface_Check.hxx>
16 #include <Standard_Type.hxx>
17 #include <StepData_EDescr.hxx>
18 #include <StepData_Field.hxx>
19 #include <StepData_PDescr.hxx>
20
21 IMPLEMENT_STANDARD_RTTIEXT(StepData_PDescr,Standard_Transient)
22
23 #define KindInteger 1
24 #define KindBoolean 2
25 #define KindLogical 3
26 #define KindEnum    4
27 #define KindReal    5
28 #define KindString  6
29 #define KindEntity  7
30
31 StepData_PDescr::StepData_PDescr  ()
32     : thesel (0), thekind (0), thearit (0),
33       theopt (Standard_False), theder (Standard_False), thefnum (0)
34       {  }
35
36     void  StepData_PDescr::SetName (const Standard_CString name)
37       {  thename.Clear();  thename.AssignCat (name);  }
38
39     Standard_CString  StepData_PDescr::Name () const
40       {  return thename.ToCString();  }
41
42     Standard_Integer  StepData_PDescr::Kind () const
43       {  return thekind;  }
44
45     void  StepData_PDescr::SetSelect ()
46       {  thesel = 4;  }
47
48     void  StepData_PDescr::AddMember (const Handle(StepData_PDescr)& member)
49 {
50   if (member.IsNull()) return;
51   if (thenext.IsNull()) thenext = member;
52   else thenext->AddMember (member);
53   if (thesel == 3) return;
54   if (thekind < KindEntity && thenext->Kind() >= KindEntity) thesel = 3;
55   else if (thekind <  KindEntity && (thesel == 2 || thesel == 4)) thesel = 3;
56   else if (thekind >= KindEntity && (thesel == 1 || thesel == 4)) thesel = 2;
57 }
58
59     void  StepData_PDescr::SetMemberName (const Standard_CString memname)
60       {  thesnam.Clear();  thesnam.AssignCat (memname);  }
61
62     void  StepData_PDescr::SetInteger ()
63       {  thekind = KindInteger;  }
64
65     void  StepData_PDescr::SetReal ()
66       {  thekind = KindReal;  }
67
68     void  StepData_PDescr::SetString ()
69       {  thekind = KindString;  }
70
71     void  StepData_PDescr::SetBoolean ()
72       {  thekind = KindBoolean;  }
73
74     void  StepData_PDescr::SetLogical ()
75       {  thekind = KindLogical;  }
76
77     void  StepData_PDescr::SetEnum ()
78       {  thekind = KindEnum;  }
79
80     void  StepData_PDescr::AddEnumDef (const Standard_CString enumdef)
81       {  theenum.AddDefinition (enumdef);  }
82
83     void  StepData_PDescr::SetType  (const Handle(Standard_Type)& atype)
84       {  thekind = KindEntity;  thetype = atype;  thednam.Clear();  }
85
86     void  StepData_PDescr::SetDescr (const Standard_CString dscnam)
87       {  thekind = KindEntity;  thetype.Nullify();
88          thednam.Clear();  thednam.AssignCat(dscnam);  }
89
90     void  StepData_PDescr::AddArity (const Standard_Integer arity)
91       {  thearit += arity;  }
92
93     void  StepData_PDescr::SetArity (const Standard_Integer arity)
94       {  thearit = arity;  }
95
96
97     void  StepData_PDescr::SetFrom  (const Handle(StepData_PDescr)& other)
98 {
99   if (other.IsNull()) return;
100   thekind = other->Kind();
101   Standard_Integer i, maxenum = other->EnumMax ();
102   for (i = 0; i <= maxenum; i ++)    AddEnumDef (other->EnumText(i));
103 //  ne sont pas reprises : les SELECT
104   thetype = other->Type();
105   thearit = other->Arity();
106   thefrom = other;
107   theopt  = other->IsOptional ();
108   theder  = other->IsDerived  ();
109   thefnam.Clear();  thefnam.AssignCat (other->FieldName());
110   thefnum = other->FieldRank ();
111 }
112
113     void  StepData_PDescr::SetOptional (const Standard_Boolean opt)
114       {  theopt = opt;  }
115
116     void  StepData_PDescr::SetDerived  (const Standard_Boolean der)
117       {  theder = der;  }
118
119     void  StepData_PDescr::SetField
120   (const Standard_CString name, const Standard_Integer rank)
121 {
122   thefnam.Clear();  thefnam.AssignCat (name);
123   thefnum = rank;
124 }
125
126 //    ######  INTERRO  ######
127
128     Standard_Boolean  StepData_PDescr::IsSelect  () const
129 {
130   if (!thefrom.IsNull()) return thefrom->IsSelect();
131   return (thesel > 0);
132 }
133
134     Handle(StepData_PDescr)  StepData_PDescr::Member (const Standard_CString name) const
135 {
136   if (!thefrom.IsNull()) return thefrom->Member (name);
137   Handle(StepData_PDescr) descr;
138   if (thesnam.IsEqual (name)) return this;
139   if (thenext.IsNull()) return descr;  // null
140   return thenext->Member (name);
141 }
142
143     Standard_Boolean  StepData_PDescr::IsInteger () const
144       {  return (thekind == KindInteger);  }
145
146     Standard_Boolean  StepData_PDescr::IsReal    () const
147       {  return (thekind == KindReal);     }
148
149     Standard_Boolean  StepData_PDescr::IsString  () const
150       {  return (thekind == KindString);   }
151
152     Standard_Boolean  StepData_PDescr::IsBoolean () const
153       {  return (thekind == KindBoolean || thekind == KindLogical);  }
154
155     Standard_Boolean  StepData_PDescr::IsLogical () const
156       {  return (thekind == KindLogical);  }
157
158     Standard_Boolean  StepData_PDescr::IsEnum    () const
159       {  return (thekind == KindEnum);     }
160
161     Standard_Integer  StepData_PDescr::EnumMax   () const
162       {  return theenum.MaxValue();  }
163
164     Standard_Integer  StepData_PDescr::EnumValue (const Standard_CString name) const
165       {  return theenum.Value (name);  }
166
167     Standard_CString  StepData_PDescr::EnumText  (const Standard_Integer val)  const
168       {  return theenum.Text  (val).ToCString();   }
169
170     Standard_Boolean  StepData_PDescr::IsEntity  () const
171       {  return (thekind == KindEntity);  }
172
173     Standard_Boolean  StepData_PDescr::IsType    (const Handle(Standard_Type)& atype) const
174 {
175   if (atype.IsNull()) return Standard_False;
176   if (!thetype.IsNull()) {
177     if (atype->SubType(thetype)) return Standard_True;
178   }
179   if (!thenext.IsNull()) return thenext->IsType(atype);
180   if (!thefrom.IsNull()) return thefrom->IsType(atype);
181   return Standard_False;
182 }
183
184     Handle(Standard_Type)  StepData_PDescr::Type () const
185       {  return thetype;  }
186
187     Standard_Boolean  StepData_PDescr::IsDescr
188   (const Handle(StepData_EDescr)& descr) const
189 {
190   if (descr.IsNull()) return Standard_False;
191   if (thednam.Length() > 0) {
192     if (descr->Matches (thednam.ToCString())) return Standard_True;
193   }
194   if (!thenext.IsNull()) return thenext->IsDescr (descr);
195   if (!thefrom.IsNull()) return thefrom->IsDescr (descr);
196   return Standard_False;
197 }
198
199     Standard_CString  StepData_PDescr::DescrName () const
200       {  return thednam.ToCString();  }
201
202
203     Standard_Integer  StepData_PDescr::Arity () const
204       {  return thearit;  }
205
206     Handle(StepData_PDescr)  StepData_PDescr::Simple () const
207 {
208   if (thearit == 0) return this;
209   if (thefrom.IsNull()) return this;
210   return thefrom;
211 }
212
213     Standard_Boolean  StepData_PDescr::IsOptional () const
214       {  return theopt;  }
215
216     Standard_Boolean  StepData_PDescr::IsDerived  () const
217       {  return theder;  }
218
219     Standard_Boolean  StepData_PDescr::IsField    () const
220       {  return (thefnum > 0);  }
221
222     Standard_CString  StepData_PDescr::FieldName  () const
223       {  return thefnam.ToCString ();  }
224
225     Standard_Integer  StepData_PDescr::FieldRank  () const
226       {  return thefnum;  }
227
228
229 void StepData_PDescr::Check(const StepData_Field& /*afild*/,
230                             Handle(Interface_Check)& /*ach*/) const
231 {
232 //  pour l instant ...
233 }