1 // Created on: 1992-04-06
2 // Created by: Christian CAILLET
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _IGESData_ParamReader_HeaderFile
18 #define _IGESData_ParamReader_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Integer.hxx>
25 #include <IGESData_ReadStage.hxx>
26 #include <Interface_ParamType.hxx>
27 #include <Standard_CString.hxx>
28 #include <IGESData_Status.hxx>
29 #include <IGESData_ParamCursor.hxx>
30 #include <Standard_Type.hxx>
31 #include <TColStd_HArray1OfInteger.hxx>
32 #include <TColStd_HArray1OfReal.hxx>
33 #include <Interface_HArray1OfHAsciiString.hxx>
34 #include <IGESData_HArray1OfIGESEntity.hxx>
36 class Interface_ParamList;
37 class Interface_Check;
38 class IGESData_IGESEntity;
39 class IGESData_IGESReaderData;
43 class TCollection_HAsciiString;
44 class Interface_EntityList;
47 //! access to a list of parameters, with management of read stage
48 //! (owned parameters, properties, associativities) and current
49 //! parameter number, read errors (which feed a Check), plus
50 //! convenient facilities to read parameters, in particular :
51 //! - first parameter is ignored (it repeats entity type), hence
52 //! number 1 gives 2nd parameter, etc...
53 //! - lists are not explicit, list-reading methods are provided
54 //! which manage a current param. number
55 //! - interpretation is made as possible (texts, reals, entities ...)
56 //! (in particular, Reading a Real accepts an Integer)
57 class IGESData_ParamReader
64 //! Prepares a ParamReader, stage "Own", current param = 1
65 //! It considers a part of the list, from <base> (excluded) for
66 //! <nbpar> parameters; <nbpar> = 0 commands to take list length.
67 //! Default is (1 to skip type)
68 Standard_EXPORT IGESData_ParamReader(const Handle(Interface_ParamList)& list, const Handle(Interface_Check)& ach, const Standard_Integer base = 1, const Standard_Integer nbpar = 0, const Standard_Integer num = 0);
70 //! Returns the entity number in the file
71 Standard_EXPORT Standard_Integer EntityNumber() const;
73 //! resets state (stage, current param number, check with no fail)
74 Standard_EXPORT void Clear();
76 //! returns the current parameter number
77 //! This notion is involved by the organisation of an IGES list of
78 //! parameter : it can be ended by two lists (Associativities and
79 //! Properties), which can be empty, or even absent. Hence, it is
80 //! necessary to know, at the end of specific reading, how many
81 //! parameters have been read : the optional lists follow
82 Standard_EXPORT Standard_Integer CurrentNumber() const;
84 //! sets current parameter number to a new value
85 //! must be done at end of each step : set on first parameter
86 //! following last read one; is done by some Read... methods
87 //! (must be done directly if these method are not used)
88 //! num greater than NbParams means that following lists are empty
89 //! If current num is not managed, it remains at 1, which probably
90 //! will cause error when successive steps of reading are made
91 Standard_EXPORT void SetCurrentNumber (const Standard_Integer num);
93 //! gives current stage (Own-Props-Assocs-End, begins at Own)
94 Standard_EXPORT IGESData_ReadStage Stage() const;
96 //! passes to next stage (must be linked with setting Current)
97 Standard_EXPORT void NextStage();
99 //! passes directly to the end of reading process
100 Standard_EXPORT void EndAll();
102 //! returns number of parameters (minus the first one)
103 //! following method skip the first parameter (1 gives the 2nd)
104 Standard_EXPORT Standard_Integer NbParams() const;
106 //! returns type of parameter; note that "Ident" or "Sub" cannot
107 //! be encountered, they correspond to "Integer", see also below
108 Standard_EXPORT Interface_ParamType ParamType (const Standard_Integer num) const;
110 //! returns literal value of a parameter, as it was in file
111 Standard_EXPORT Standard_CString ParamValue (const Standard_Integer num) const;
113 //! says if a parameter is defined (not void)
114 //! See also DefinedElseSkip
115 Standard_EXPORT Standard_Boolean IsParamDefined (const Standard_Integer num) const;
117 //! says if a parameter can be regarded as an entity reference
118 //! (see Prepare from IGESReaderData for more explanation)
119 //! Note that such a parameter can seen as be a plain Integer too
120 Standard_EXPORT Standard_Boolean IsParamEntity (const Standard_Integer num) const;
122 //! returns entity number corresponding to a parameter if there is
123 //! otherwise zero (according criterium IsParamEntity)
124 Standard_EXPORT Standard_Integer ParamNumber (const Standard_Integer num) const;
126 //! directly returns entity referenced by a parameter
127 Standard_EXPORT Handle(IGESData_IGESEntity) ParamEntity (const Handle(IGESData_IGESReaderData)& IR, const Standard_Integer num);
129 //! Creates a ParamCursor from the Current Number, to read one
130 //! parameter, and to advance Current Number after reading
131 Standard_EXPORT IGESData_ParamCursor Current() const;
133 //! Creates a ParamCursor from the Current Number, to read a list
134 //! of "nb" items, and to advance Current Number after reading
135 //! By default, each item is made of one parameter
136 //! If size is given, it precises the number of params per item
137 Standard_EXPORT IGESData_ParamCursor CurrentList (const Standard_Integer nb, const Standard_Integer size = 1) const;
139 //! Allows to simply process a parameter which can be defaulted.
140 //! Waits on the Current Number a defined parameter or skips it :
141 //! If the parameter <num> is defined, changes nothing and returns True
142 //! Hence, the next reading with current cursor will concern <num>
143 //! If it is void, advances Current Position by one, and returns False
144 //! The next reading will concern <num+1> (except if <num> = NbParams)
146 //! This allows to process Default values as follows (C++) :
147 //! if (PR.DefinedElseSkip()) {
148 //! .. PR.Read... (current parameter);
150 //! <current parameter> = default value
151 //! .. nothing else to do with ParamReader
154 Standard_EXPORT Standard_Boolean DefinedElseSkip();
156 Standard_EXPORT Standard_Boolean ReadInteger (const IGESData_ParamCursor& PC, Standard_Integer& val);
158 //! Reads an Integer value designated by PC
159 //! The method Current designates the current parameter and
160 //! advances the Current Number by one after reading
161 //! Note that if a count (not 1) is given, it is ignored
162 //! If it is not an Integer, fills Check with a Fail (using mess)
163 //! and returns False
164 Standard_EXPORT Standard_Boolean ReadInteger (const IGESData_ParamCursor& PC, const Standard_CString mess, Standard_Integer& val);
166 Standard_EXPORT Standard_Boolean ReadBoolean (const IGESData_ParamCursor& PC, const Message_Msg& amsg, Standard_Boolean& val, const Standard_Boolean exact = Standard_True);
168 //! Reads a Boolean value from parameter "num"
169 //! A Boolean is given as an Integer value 0 (False) or 1 (True)
170 //! Anyway, an Integer is demanded (else, Check is filled)
171 //! If exact is given True, those precise values are demanded
172 //! Else, Correction is done, as False for 0 or <0, True for >0
173 //! (with a Warning error message, and return is True)
174 //! In case of error (not an Integer, or not 0/1 and exact True),
175 //! Check is filled with a Fail (using mess) and return is False
176 Standard_EXPORT Standard_Boolean ReadBoolean (const IGESData_ParamCursor& PC, const Standard_CString mess, Standard_Boolean& val, const Standard_Boolean exact = Standard_True);
178 Standard_EXPORT Standard_Boolean ReadReal (const IGESData_ParamCursor& PC, Standard_Real& val);
180 //! Reads a Real value from parameter "num"
181 //! An Integer is accepted (Check is filled with a Warning
182 //! message) and causes return to be True (as normal case)
183 //! In other cases, Check is filled with a Fail and return is False
184 Standard_EXPORT Standard_Boolean ReadReal (const IGESData_ParamCursor& PC, const Standard_CString mess, Standard_Real& val);
186 Standard_EXPORT Standard_Boolean ReadXY (const IGESData_ParamCursor& PC, Message_Msg& amsg, gp_XY& val);
188 //! Reads a couple of Real values (X,Y) from parameter "num"
189 //! Integers are accepted (Check is filled with a Warning
190 //! message) and cause return to be True (as normal case)
191 //! In other cases, Check is filled with a Fail and return is False
192 Standard_EXPORT Standard_Boolean ReadXY (const IGESData_ParamCursor& PC, const Standard_CString mess, gp_XY& val);
194 Standard_EXPORT Standard_Boolean ReadXYZ (const IGESData_ParamCursor& PC, Message_Msg& amsg, gp_XYZ& val);
196 //! Reads a triplet of Real values (X,Y,Z) from parameter "num"
197 //! Integers are accepted (Check is filled with a Warning
198 //! message) and cause return to be True (as normal case)
199 //! In other cases, Check is filled with a Fail and return is False
201 Standard_EXPORT Standard_Boolean ReadXYZ (const IGESData_ParamCursor& PC, const Standard_CString mess, gp_XYZ& val);
203 Standard_EXPORT Standard_Boolean ReadText (const IGESData_ParamCursor& thePC, const Message_Msg& theMsg, Handle(TCollection_HAsciiString)& theVal);
205 //! Reads a Text value from parameter "num", as a String from
206 //! Collection, that is, Hollerith text without leading "nnnH"
207 //! If it is not a String, fills Check with a Fail (using mess)
208 //! and returns False
209 Standard_EXPORT Standard_Boolean ReadText (const IGESData_ParamCursor& PC, const Standard_CString mess, Handle(TCollection_HAsciiString)& val);
211 Standard_EXPORT Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, IGESData_Status& aStatus, Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul = Standard_False);
213 //! Reads an IGES entity from parameter "num"
214 //! An Entity is known by its reference, which has the form of an
215 //! odd Integer Value (a number in the Directory)
216 //! If <canbenul> is given True, a Reference can also be Null :
217 //! in this case, the result is a Null Handle with no Error
218 //! If <canbenul> is False, a Null Reference causes an Error
219 //! If the parameter cannot refer to an entity (or null), fills
220 //! Check with a Fail (using mess) and returns False
221 Standard_EXPORT Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, const Standard_CString mess, Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul = Standard_False);
223 Standard_EXPORT Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, IGESData_Status& aStatus, const Handle(Standard_Type)& type, Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul = Standard_False);
225 //! Safe variant for arbitrary type of argument
227 Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, IGESData_Status& aStatus, const Handle(Standard_Type)& type, Handle(T)& val, const Standard_Boolean canbenul = Standard_False)
229 Handle(IGESData_IGESEntity) aVal = val;
230 Standard_Boolean aRes = ReadEntity (IR, PC, aStatus, type, aVal, canbenul);
231 val = Handle(T)::DownCast(aVal);
232 return aRes && (canbenul || ! val.IsNull());
235 //! Works as ReadEntity without Type, but in addition checks the
236 //! Type of the Entity, which must be "kind of" a given <type>
237 //! Then, gives the same fail cases as ReadEntity without Type,
238 //! plus the case "Incorrect Type"
239 //! (in such a case, returns False and givel <val> = Null)
240 Standard_EXPORT Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, const Standard_CString mess, const Handle(Standard_Type)& type, Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul = Standard_False);
242 //! Safe variant for arbitrary type of argument
244 Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, const Standard_CString mess, const Handle(Standard_Type)& type, Handle(T)& val, const Standard_Boolean canbenul = Standard_False)
246 Handle(IGESData_IGESEntity) aVal = val;
247 Standard_Boolean aRes = ReadEntity (IR, PC, mess, type, aVal, canbenul);
248 val = Handle(T)::DownCast(aVal);
249 return aRes && (canbenul || ! val.IsNull());
252 Standard_EXPORT Standard_Boolean ReadInts (const IGESData_ParamCursor& PC, const Message_Msg& amsg, Handle(TColStd_HArray1OfInteger)& val, const Standard_Integer index = 1);
254 //! Reads a list of Integer values, defined by PC (with a count of
255 //! parameters). PC can start from Current Number and command it
256 //! to advance after reading (use method CurrentList to do this)
257 //! The list is given as a HArray1, numered from "index"
258 //! If all params are not Integer, Check is filled (using mess)
259 //! and return value is False
260 Standard_EXPORT Standard_Boolean ReadInts (const IGESData_ParamCursor& PC, const Standard_CString mess, Handle(TColStd_HArray1OfInteger)& val, const Standard_Integer index = 1);
262 Standard_EXPORT Standard_Boolean ReadReals (const IGESData_ParamCursor& PC, Message_Msg& amsg, Handle(TColStd_HArray1OfReal)& val, const Standard_Integer index = 1);
264 //! Reads a list of Real values defined by PC
265 //! Same conditions as for ReadInts, for PC and index
266 //! An Integer parameter is accepted, if at least one parameter is
267 //! Integer, Check is filled with a "Warning" message
268 //! If all params are neither Real nor Integer, Check is filled
269 //! (using mess) and return value is False
270 Standard_EXPORT Standard_Boolean ReadReals (const IGESData_ParamCursor& PC, const Standard_CString mess, Handle(TColStd_HArray1OfReal)& val, const Standard_Integer index = 1);
272 Standard_EXPORT Standard_Boolean ReadTexts (const IGESData_ParamCursor& PC, const Message_Msg& amsg, Handle(Interface_HArray1OfHAsciiString)& val, const Standard_Integer index = 1);
274 //! Reads a list of Hollerith Texts, defined by PC
275 //! Texts are read as Hollerith texts without leading "nnnH"
276 //! Same conditions as for ReadInts, for PC and index
277 //! If all params are not Text, Check is filled (using mess)
278 //! and return value is False
279 Standard_EXPORT Standard_Boolean ReadTexts (const IGESData_ParamCursor& PC, const Standard_CString mess, Handle(Interface_HArray1OfHAsciiString)& val, const Standard_Integer index = 1);
281 Standard_EXPORT Standard_Boolean ReadEnts (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, const Message_Msg& amsg, Handle(IGESData_HArray1OfIGESEntity)& val, const Standard_Integer index = 1);
283 //! Reads a list of Entities defined by PC
284 //! Same conditions as for ReadInts, for PC and index
285 //! The list is given as a HArray1, numered from "index"
286 //! If all params cannot be read as Entities, Check is filled
287 //! (using mess) and return value is False
288 //! Remark : Null references are accepted, they are ignored
289 //! (negative pointers too : they provoke a Warning message)
290 //! If the caller wants to check them, a loop on ReadEntity should
292 Standard_EXPORT Standard_Boolean ReadEnts (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, const Standard_CString mess, Handle(IGESData_HArray1OfIGESEntity)& val, const Standard_Integer index = 1);
294 Standard_EXPORT Standard_Boolean ReadEntList (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, Message_Msg& amsg, Interface_EntityList& val, const Standard_Boolean ord = Standard_True);
296 //! Reads a list of Entities defined by PC
297 //! Same conditions as for ReadEnts, for PC
298 //! The list is given as an EntityList
299 //! (index has no meaning; the EntityList starts from clear)
300 //! If "ord" is given True (default), entities will be added to
301 //! the list in their original order
302 //! Remark : Negative or Null Pointers are ignored
303 //! Else ("ord" False), order is not guaranteed (faster mode)
304 //! If all params cannot be read as Entities, same as above
305 //! Warning Give "ord" to False ONLY if order is not significant
306 Standard_EXPORT Standard_Boolean ReadEntList (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, const Standard_CString mess, Interface_EntityList& val, const Standard_Boolean ord = Standard_True);
308 Standard_EXPORT Standard_Boolean ReadingReal (const Standard_Integer num, Standard_Real& val);
310 //! Routine which reads a Real parameter, given its number
311 //! Same conditions as ReadReal for mess, val, and return value
312 Standard_EXPORT Standard_Boolean ReadingReal (const Standard_Integer num, const Standard_CString mess, Standard_Real& val);
314 Standard_EXPORT Standard_Boolean ReadingEntityNumber (const Standard_Integer num, Standard_Integer& val);
316 //! Routine which reads an Entity Number (which allows to read the
317 //! Entity in the IGESReaderData by BoundEntity), given its number
318 //! in the list of Parameters
319 //! Same conditions as ReadEntity for mess, val, and return value
320 //! In particular, returns True and val to zero means Null Entity,
321 //! and val not zero means Entity read by BoundEntity
322 Standard_EXPORT Standard_Boolean ReadingEntityNumber (const Standard_Integer num, const Standard_CString mess, Standard_Integer& val);
324 Standard_EXPORT void SendFail (const Message_Msg& amsg);
326 Standard_EXPORT void SendWarning (const Message_Msg& amsg);
328 Standard_EXPORT void AddFail (const Standard_CString afail, const Standard_CString bfail = "");
330 //! feeds the Check with a new fail (as a String or as a CString)
331 Standard_EXPORT void AddFail (const Handle(TCollection_HAsciiString)& af, const Handle(TCollection_HAsciiString)& bf);
333 Standard_EXPORT void AddWarning (const Standard_CString awarn, const Standard_CString bwarn = "");
335 //! feeds the Check with a new Warning message
336 Standard_EXPORT void AddWarning (const Handle(TCollection_HAsciiString)& aw, const Handle(TCollection_HAsciiString)& bw);
338 Standard_EXPORT void Mend (const Standard_CString pref = "");
340 //! says if fails have been recorded into the Check
341 Standard_EXPORT Standard_Boolean HasFailed() const;
343 //! returns the Check
344 //! Note that any error signaled above is also recorded into it
345 Standard_EXPORT const Handle(Interface_Check)& Check() const;
347 //! returns the check in a way which allows to work on it directly
348 //! (i.e. messages added to the Check are added to ParamReader too)
349 Standard_EXPORT Handle(Interface_Check)& CCheck();
351 //! Returns True if the Check is Empty
352 //! Else, it has to be recorded with the Read Entity
353 Standard_EXPORT Standard_Boolean IsCheckEmpty() const;
367 Standard_EXPORT Standard_Boolean PrepareRead (const IGESData_ParamCursor& PC, const Standard_Boolean several, const Standard_Integer size = 1);
369 //! Prepares work for Read... methods which call it to begin
370 //! The required count of parameters must not overpass NbParams.
371 //! If several is given False, PC count must be one.
372 //! If size is given, the TermSize from ParmCursor must be a
373 //! multiple count of this size.
374 //! If one of above condition is not satisfied, a Fail Message is
375 //! recorded into Check, using the root "mess" and return is False
376 Standard_EXPORT Standard_Boolean PrepareRead (const IGESData_ParamCursor& PC, const Standard_CString mess, const Standard_Boolean several, const Standard_Integer size = 1);
378 //! Gets the first parameter number to be read, determined from
379 //! ParamCursor data read by PrepareRead (Start + Offset)
380 //! Then commands to skip 1 parameter (default) or nb if given
381 Standard_EXPORT Standard_Integer FirstRead (const Standard_Integer nb = 1);
383 //! Gets the next parameter number to be read. Skips to next Item
384 //! if TermSize has been read.
385 //! Then commands to skip 1 parameter (default) or nb if given
386 Standard_EXPORT Standard_Integer NextRead (const Standard_Integer nb = 1);
388 //! internal method which builds a Fail message from an
389 //! identification "idm" and a diagnostic ("afail")
390 //! Also feeds LastReadStatus
391 //! <af> for final message, bf (can be different) for original
392 Standard_EXPORT void AddFail (const Standard_CString idm, const Handle(TCollection_HAsciiString)& af, const Handle(TCollection_HAsciiString)& bf);
394 //! Same as above but with CString
395 //! <bf> empty means = <af>
396 Standard_EXPORT void AddFail (const Standard_CString idm, const Standard_CString afail, const Standard_CString bfail);
398 //! internal method which builds a Warning message from an
399 //! identification "idm" and a diagnostic
400 //! <aw> is final message, bw is original (can be different)
401 //! Also feeds LastReadStatus
402 Standard_EXPORT void AddWarning (const Standard_CString idm, const Handle(TCollection_HAsciiString)& aw, const Handle(TCollection_HAsciiString)& bw);
404 //! Same as above but with CString
405 //! <bw> empty means = <aw>
406 Standard_EXPORT void AddWarning (const Standard_CString idm, const Standard_CString aw, const Standard_CString bw);
409 Handle(Interface_ParamList) theparams;
410 Handle(Interface_Check) thecheck;
411 Standard_Integer thebase;
412 Standard_Integer thenbpar;
413 Standard_Integer thecurr;
414 IGESData_ReadStage thestage;
415 Standard_Boolean thelast;
416 Standard_Integer theindex;
417 Standard_Integer thenbitem;
418 Standard_Integer theitemsz;
419 Standard_Integer theoffset;
420 Standard_Integer thetermsz;
421 Standard_Integer themaxind;
422 Standard_Integer thenbterm;
423 Standard_Integer pbrealint;
424 Standard_Integer pbrealform;
425 Standard_Integer thenum;
436 #endif // _IGESData_ParamReader_HeaderFile