Warnings on vc14 were eliminated
[occt.git] / src / StepData / StepData_StepReaderData.hxx
1 // Created on: 1992-02-11
2 // Created by: Christian CAILLET
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _StepData_StepReaderData_HeaderFile
18 #define _StepData_StepReaderData_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <TColStd_Array1OfInteger.hxx>
24 #include <Interface_IndexedMapOfAsciiString.hxx>
25 #include <TColStd_DataMapOfIntegerInteger.hxx>
26 #include <Standard_Integer.hxx>
27 #include <Interface_FileReaderData.hxx>
28 #include <Standard_CString.hxx>
29 #include <Interface_ParamType.hxx>
30 #include <Standard_Boolean.hxx>
31 #include <TColStd_SequenceOfAsciiString.hxx>
32 #include <Standard_Real.hxx>
33 #include <Standard_Type.hxx>
34 #include <StepData_Logical.hxx>
35 class Interface_Check;
36 class TCollection_AsciiString;
37 class StepData_PDescr;
38 class Standard_Transient;
39 class StepData_SelectMember;
40 class StepData_Field;
41 class StepData_ESDescr;
42 class StepData_FieldList;
43 class StepData_SelectType;
44 class TCollection_HAsciiString;
45 class StepData_EnumTool;
46
47
48 class StepData_StepReaderData;
49 DEFINE_STANDARD_HANDLE(StepData_StepReaderData, Interface_FileReaderData)
50
51 //! Specific FileReaderData for Step
52 //! Contains litteral description of entities (for each one : type
53 //! as a string, ident, parameter list)
54 //! provides references evaluation, plus access to litteral data
55 //! and specific access methods (Boolean, XY, XYZ)
56 class StepData_StepReaderData : public Interface_FileReaderData
57 {
58
59 public:
60
61   
62   //! creates StepReaderData correctly dimensionned (necessary at
63   //! creation time, because it contains arrays)
64   //! nbheader is nb of records for Header, nbtotal for Header+Data
65   //! and nbpar gives the total count of parameters
66   Standard_EXPORT StepData_StepReaderData(const Standard_Integer nbheader, const Standard_Integer nbtotal, const Standard_Integer nbpar);
67   
68   //! Fills the fields of a record
69   Standard_EXPORT void SetRecord (const Standard_Integer num, const Standard_CString ident, const Standard_CString type, const Standard_Integer nbpar);
70   
71   //! Fills the fields of a parameter of a record. This is a variant
72   //! of AddParam, Adapted to STEP (optimized for specific values)
73   Standard_EXPORT void AddStepParam (const Standard_Integer num, const Standard_CString aval, const Interface_ParamType atype, const Standard_Integer nument = 0);
74   
75   //! Returns Record Type
76   Standard_EXPORT const TCollection_AsciiString& RecordType (const Standard_Integer num) const;
77   
78   //! Returns Record Type as a CString
79   //! was C++ : return const
80   Standard_EXPORT Standard_CString CType (const Standard_Integer num) const;
81   
82   //! Returns record identifier (Positive number)
83   //! If returned ident is not positive : Sub-List or Scope mark
84   Standard_EXPORT Standard_Integer RecordIdent (const Standard_Integer num) const;
85   
86   //! Returns SubList numero designated by a parameter (nump) in a
87   //! record (num), or zero if the parameter does not exist or is
88   //! not a SubList address. Zero too If aslast is True and nump
89   //! is not for the last parameter
90   Standard_EXPORT Standard_Integer SubListNumber (const Standard_Integer num, const Standard_Integer nump, const Standard_Boolean aslast) const;
91   
92   //! Returns True if <num> corresponds to a Complex Type Entity
93   //! (as can be defined by ANDOR Express clause)
94   Standard_EXPORT Standard_Boolean IsComplex (const Standard_Integer num) const;
95   
96   //! Returns the List of Types which correspond to a Complex Type
97   //! Entity. If not Complex, there is just one Type in it
98   //! For a SubList or a Scope mark, <types> remains empty
99   Standard_EXPORT void ComplexType (const Standard_Integer num, TColStd_SequenceOfAsciiString& types) const;
100   
101   //! Returns the Next "Componant" for a Complex Type Entity, of
102   //! which <num> is already a Componant (the first one or a next one)
103   //! Returns 0 for a Simple Type or for the last Componant
104   Standard_EXPORT Standard_Integer NextForComplex (const Standard_Integer num) const;
105   
106   //! Determines the first component which brings a given name, for
107   //! a Complex Type Entity
108   //! <num0> is the very first record of this entity
109   //! <num> is given the last NextNamedForComplex, starts at zero
110   //! it is returned as the newly found number
111   //! Hence, in the normal case, NextNamedForComplex starts by num0
112   //! if <num> is zero, else by NextForComplex(num)
113   //! If the alphabetic order is not respected, it restarts from
114   //! num0 and loops on NextForComplex until finding <name>
115   //! In case of "non-alphabetic order", <ach> is filled with a
116   //! Warning for this name
117   //! In case of "not-found at all", <ach> is filled with a Fail,
118   //! and <num> is returned as zero
119   //!
120   //! Returns True if alphabetic order, False else
121   Standard_EXPORT Standard_Boolean NamedForComplex (const Standard_CString name, const Standard_Integer num0, Standard_Integer& num, Handle(Interface_Check)& ach) const;
122   
123   //! Determines the first component which brings a given name, or
124   //! short name for a Complex Type Entity
125   //! <num0> is the very first record of this entity
126   //! <num> is given the last NextNamedForComplex, starts at zero
127   //! it is returned as the newly found number
128   //! Hence, in the normal case, NextNamedForComplex starts by num0
129   //! if <num> is zero, else by NextForComplex(num)
130   //! If the alphabetic order is not respected, it restarts from
131   //! num0 and loops on NextForComplex until finding <name>
132   //! In case of "non-alphabetic order", <ach> is filled with a
133   //! Warning for this name
134   //! In case of "not-found at all", <ach> is filled with a Fail,
135   //! and <num> is returned as zero
136   //!
137   //! Returns True if alphabetic order, False else
138   Standard_EXPORT Standard_Boolean NamedForComplex (const Standard_CString theName, const Standard_CString theShortName, const Standard_Integer num0, Standard_Integer& num, Handle(Interface_Check)& ach) const;
139
140   //! Checks Count of Parameters of record <num> to equate <nbreq>
141   //! If this Check is successful, returns True
142   //! Else, fills <ach> with an Error Message then returns False
143   //! <mess> is included in the Error message if given non empty
144   Standard_EXPORT Standard_Boolean CheckNbParams (const Standard_Integer num, const Standard_Integer nbreq, Handle(Interface_Check)& ach, const Standard_CString mess = "") const;
145   
146   //! reads parameter <nump> of record <num> as a sub-list (may be
147   //! typed, see ReadTypedParameter in this case)
148   //! Returns True if OK. Else (not a LIST), returns false and
149   //! feeds Check with appropriate check
150   //! If <optional> is True and Param is not defined, returns True
151   //! with <ach> not filled and <numsub> returned as 0
152   //! Works with SubListNumber with <aslast> false (no specific case
153   //! for last parameter)
154   Standard_EXPORT Standard_Boolean ReadSubList (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Standard_Integer& numsub, const Standard_Boolean optional = Standard_False, const Standard_Integer lenmin = 0, const Standard_Integer lenmax = 0) const;
155   
156   //! reads the content of a sub-list into a transient :
157   //! SelectNamed, or HArray1 of Integer,Real,String,Transient ...
158   //! recursive call if list of list ...
159   //! If a sub-list has mixed types, an HArray1OfTransient is
160   //! produced, it may contain SelectMember
161   //! Intended to be called by ReadField
162   //! The returned status is : negative if failed, 0 if empty.
163   //! Else the kind to be recorded in the field
164   Standard_EXPORT Standard_Integer ReadSub (const Standard_Integer numsub, const Standard_CString mess, Handle(Interface_Check)& ach, const Handle(StepData_PDescr)& descr, Handle(Standard_Transient)& val) const;
165   
166   //! Reads parameter <nump> of record <num> into a SelectMember,
167   //! self-sufficient (no Description needed)
168   //! If <val> is already created, it will be filled, as possible
169   //! And if reading does not match its own description, the result
170   //! will be False
171   //! If <val> is not it not yet created, it will be (SelectNamed)
172   //! Usefull if a field is defined as a SelectMember, directly
173   //! (SELECT with no Entity as member)
174   //! But SelectType also manages SelectMember (for SELECT with
175   //! some members as Entity, some other not)
176   Standard_EXPORT Standard_Boolean ReadMember (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Handle(StepData_SelectMember)& val) const;
177   
178   //! Safe variant for arbitrary type of argument
179   template <class T> 
180   Standard_Boolean ReadMember (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Handle(T)& val) const
181   {
182     Handle(StepData_SelectMember) aVal = val;
183     return ReadMember (num, nump, mess, ach, aVal) && ! (val = Handle(T)::DownCast(aVal)).IsNull();
184   }
185
186   //! reads parameter <nump> of record <num> into a Field,
187   //! controlled by a Parameter Descriptor (PDescr), which controls
188   //! its allowed type(s) and value
189   //! <ach> is filled if the read parameter does not match its
190   //! description (but the field is read anyway)
191   //! If the description is not defined, no control is done
192   //! Returns True when done
193   Standard_EXPORT Standard_Boolean ReadField (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, const Handle(StepData_PDescr)& descr, StepData_Field& fild) const;
194   
195   //! reads a list of fields controlled by an ESDescr
196   Standard_EXPORT Standard_Boolean ReadList (const Standard_Integer num, Handle(Interface_Check)& ach, const Handle(StepData_ESDescr)& descr, StepData_FieldList& list) const;
197   
198   //! Reads parameter <nump> of record <num> into a Transient Value
199   //! according to the type of the parameter :
200   //! Named for Integer,Boolean,Logical,Enum,Real : SelectNamed
201   //! Immediate Integer,Boolean,Logical,Enum,Real : SelectInt/Real
202   //! Text  : HAsciiString
203   //! Ident : the referenced Entity
204   //! Sub-List not processed, see ReadSub
205   //! This value is controlled by a Parameter Descriptor (PDescr),
206   //! which controls its allowed type and value
207   //! <ach> is filled if the read parameter does not match its
208   //! description (the select is nevertheless created if possible)
209   //!
210   //! Warning : val is in out, hence it is possible to predefine a specific
211   //! SelectMember then to fill it. If <val> is Null or if the
212   //! result is not a SelectMember, val itself is returned a new ref
213   //! For a Select with a Name, <val> must then be a SelectNamed
214   Standard_EXPORT Standard_Boolean ReadAny (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, const Handle(StepData_PDescr)& descr, Handle(Standard_Transient)& val) const;
215   
216   //! reads parameter <nump> of record <num> as a sub-list of
217   //! two Reals X,Y. Returns True if OK. Else, returns false and
218   //! feeds Check with appropriate Fails (parameter not a sub-list,
219   //! not two Reals in the sub-list) composed with "mess" which
220   //! gives the name of the parameter
221   Standard_EXPORT Standard_Boolean ReadXY (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Standard_Real& X, Standard_Real& Y) const;
222   
223   //! reads parameter <nump> of record <num> as a sub-list of
224   //! three Reals X,Y,Z. Return value and Check managed as by
225   //! ReadXY (demands a sub-list of three Reals)
226   Standard_EXPORT Standard_Boolean ReadXYZ (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const;
227   
228   //! reads parameter <nump> of record <num> as a single Real value.
229   //! Return value and Check managed as by ReadXY (demands a Real)
230   Standard_EXPORT Standard_Boolean ReadReal (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Standard_Real& val) const;
231   
232   //! Reads parameter <nump> of record <num> as a single Entity.
233   //! Return value and Check managed as by ReadReal (demands a
234   //! reference to an Entity). In Addition, demands read Entity
235   //! to be Kind of a required Type <atype>.
236   //! Remark that returned status is False and <ent> is Null if
237   //! parameter is not an Entity, <ent> remains Not Null is parameter
238   //! is an Entity but is not Kind of required type
239   Standard_EXPORT Standard_Boolean ReadEntity (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, const Handle(Standard_Type)& atype, Handle(Standard_Transient)& ent) const;
240   
241   //! Safe variant for arbitrary type of argument
242   template <class T> 
243   Standard_Boolean ReadEntity (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, const Handle(Standard_Type)& atype, Handle(T)& ent) const
244   {
245     Handle(Standard_Transient) anEnt = ent;
246     return ReadEntity (num, nump, mess, ach, atype, anEnt) && ! (ent = Handle(T)::DownCast(anEnt)).IsNull();
247   }
248
249   //! Same as above, but a SelectType checks Type Matching, and
250   //! records the read Entity (see method Value from SelectType)
251   Standard_EXPORT Standard_Boolean ReadEntity (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, StepData_SelectType& sel) const;
252   
253   //! reads parameter <nump> of record <num> as a single Integer.
254   //! Return value & Check managed as by ReadXY (demands an Integer)
255   Standard_EXPORT Standard_Boolean ReadInteger (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Standard_Integer& val) const;
256   
257   //! reads parameter <nump> of record <num> as a Boolean
258   //! Return value and Check managed as by ReadReal (demands a
259   //! Boolean enum, i.e. text ".T." for True or ".F." for False)
260   Standard_EXPORT Standard_Boolean ReadBoolean (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Standard_Boolean& flag) const;
261   
262   //! reads parameter <nump> of record <num> as a Logical
263   //! Return value and Check managed as by ReadBoolean (demands a
264   //! Logical enum, i.e. text ".T.", ".F.", or ".U.")
265   Standard_EXPORT Standard_Boolean ReadLogical (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, StepData_Logical& flag) const;
266   
267   //! reads parameter <nump> of record <num> as a String (text
268   //! between quotes, quotes are removed by the Read operation)
269   //! Return value and Check managed as by ReadXY (demands a String)
270   Standard_EXPORT Standard_Boolean ReadString (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Handle(TCollection_HAsciiString)& val) const;
271   
272   Standard_EXPORT Standard_Boolean ReadEnumParam (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Standard_CString& text) const;
273   
274   //! Fills a check with a fail message if enumeration value does
275   //! match parameter definition
276   //! Just a help to centralize message definitions
277   Standard_EXPORT void FailEnumValue (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach) const;
278   
279   //! Reads parameter <nump> of record <num> as an Enumeration (text
280   //! between dots) and converts it to an integer value, by an
281   //! EnumTool. Returns True if OK, false if : this parameter is not
282   //! enumeration, or is not recognized by the EnumTool (with fail)
283   Standard_EXPORT Standard_Boolean ReadEnum (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, const StepData_EnumTool& enumtool, Standard_Integer& val) const;
284   
285   //! Resolves a parameter which can be enclosed in a type def., as
286   //! TYPE(val). The parameter must then be read normally according
287   //! its type.  Parameter to be resolved is <nump> of record <num>
288   //! <mustbetyped> True  demands a typed parameter
289   //! <mustbetyped> False accepts a non-typed parameter as option
290   //! mess and ach as usual
291   //! <numr>,<numrp> are the resolved record and parameter numbers
292   //! = num,nump if no type,  else numrp=1
293   //! <typ> returns the recorded type, or empty string
294   //! Remark : a non-typed list is considered as "non-typed"
295   Standard_EXPORT Standard_Boolean ReadTypedParam (const Standard_Integer num, const Standard_Integer nump, const Standard_Boolean mustbetyped, const Standard_CString mess, Handle(Interface_Check)& ach, Standard_Integer& numr, Standard_Integer& numrp, TCollection_AsciiString& typ) const;
296   
297   //! Checks if parameter <nump> of record <num> is given as Derived
298   //! If this Check is successful (i.e. Param = "*"), returns True
299   //! Else, fills <ach> with a Message which contains <mess> and
300   //! returns False. According to <errstat>, this message is Warning
301   //! if errstat is False (Default), Fail if errstat is True
302   Standard_EXPORT Standard_Boolean CheckDerived (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, const Standard_Boolean errstat = Standard_False) const;
303   
304   //! Returns total count of Entities (including Header)
305   Standard_EXPORT virtual Standard_Integer NbEntities() const Standard_OVERRIDE;
306   
307   //! determines the first suitable record following a given one
308   //! that is, skips SCOPE,ENDSCOPE and SUBLIST records
309   //! Note : skips Header records, which are accessed separately
310   Standard_EXPORT Standard_Integer FindNextRecord (const Standard_Integer num) const Standard_OVERRIDE;
311   
312   //! determines reference numbers in EntityNumber fields
313   //! called by Prepare from StepReaderTool to prepare later using
314   //! by a StepModel. This method is attached to StepReaderData
315   //! because it needs a massive amount of data accesses to work
316   //!
317   //! If <withmap> is given False, the basic exploration algorithm
318   //! is activated, otherwise a map is used as far as it is possible
319   //! this option can be used only to test this algorithm
320   Standard_EXPORT void SetEntityNumbers (const Standard_Boolean withmap = Standard_True);
321   
322   //! determine first suitable record of Header
323   //! works as FindNextRecord, but treats only Header records
324   Standard_EXPORT Standard_Integer FindNextHeaderRecord (const Standard_Integer num) const;
325   
326   //! Works as SetEntityNumbers but for Header : more simple because
327   //! there are no Reference, only Sub-Lists
328   Standard_EXPORT void PrepareHeader();
329   
330   //! Returns the Global Check. It can record Fail messages about
331   //! Undefined References (detected by SetEntityNumbers)
332   Standard_EXPORT const Handle(Interface_Check) GlobalCheck() const;
333
334
335
336
337   DEFINE_STANDARD_RTTIEXT(StepData_StepReaderData,Interface_FileReaderData)
338
339 protected:
340
341
342
343
344 private:
345
346   
347   //! Searches for a Parameter of the record <num>, which refers to
348   //! the Ident <id> (form #nnn). [Used by SetEntityNumbers]
349   //! If found, returns its EntityNumber, else returns Zero.
350   Standard_EXPORT Standard_Integer FindEntityNumber (const Standard_Integer num, const Standard_Integer id) const;
351
352   TColStd_Array1OfInteger theidents;
353   TColStd_Array1OfInteger thetypes;
354   Interface_IndexedMapOfAsciiString thenametypes;
355   TColStd_DataMapOfIntegerInteger themults;
356   Standard_Integer thenbents;
357   Standard_Integer thelastn;
358   Standard_Integer thenbhead;
359   Standard_Integer thenbscop;
360   Handle(Interface_Check) thecheck;
361
362
363 };
364
365
366
367
368
369
370
371 #endif // _StepData_StepReaderData_HeaderFile