1 -- Created on: 1992-02-11
2 -- Created by: Christian CAILLET
3 -- Copyright (c) 1992-1999 Matra Datavision
4 -- Copyright (c) 1999-2012 OPEN CASCADE SAS
6 -- The content of this file is subject to the Open CASCADE Technology Public
7 -- License Version 6.5 (the "License"). You may not use the content of this file
8 -- except in compliance with the License. Please obtain a copy of the License
9 -- at http://www.opencascade.org and read it completely before using this file.
11 -- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 -- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 -- The Original Code and all software distributed under the License is
15 -- distributed on an "AS IS" basis, without warranty of any kind, and the
16 -- Initial Developer hereby disclaims all such warranties, including without
17 -- limitation, any warranties of merchantability, fitness for a particular
18 -- purpose or non-infringement. Please see the License for the specific terms
19 -- and conditions governing the rights and limitations under the License.
23 class StepWriter from StepData
25 ---Purpose : manages atomic file writing, under control of StepModel (for
26 -- general organisation of file) and each class of Transient
27 -- (for its own parameters) : prepares text to be written then
29 -- A stream cannot be used because Step limits line length at 72
30 -- In more, a specific object offers more appropriate functions
32 uses Integer, Boolean, Real, Character, Transient, Logical from StepData, -- OStream,
33 AsciiString from TCollection, HAsciiString from TCollection,
34 HSequenceOfHAsciiString, HArray1OfInteger,
35 LineBuffer, FloatWriter, CheckIterator,
36 StepModel, WriterLib, Protocol from StepData,
37 SelectMember from StepData, Field from StepData, PDescr from StepData,
38 FieldList from StepData, ESDescr from StepData,
39 HArray1OfReal from TColStd
41 raises InterfaceMismatch
45 Create (amodel : StepModel) returns StepWriter;
46 ---Purpose : Creates an empty StepWriter from a StepModel. The StepModel
47 -- provides the Number of Entities, as identifiers for File
49 -- Options for Sending Forms --
51 LabelMode (me : in out) returns Integer;
52 ---Purpose : ModeLabel controls how to display entity ids :
53 -- 0 (D) gives entity number in the model
54 -- 1 gives the already recorded label (else, its number)
55 -- Warning : conflicts are not controlled
58 TypeMode (me : in out) returns Integer;
59 ---Purpose : TypeMode controls the type form to use :
60 -- 0 (D) for normal long form
61 -- 1 for short form (if a type name has no short form, normal
62 -- long form is then used)
65 FloatWriter (me : in out) returns FloatWriter;
66 ---Purpose : Returns the embedded FloatWriter, which controls sending Reals
67 -- Use this method to access FloatWriter in order to consult or
68 -- change its options (MainFormat, FormatForRange,ZeroSuppress),
69 -- because it is returned as the address of its field
72 -- -- Description of Scopes -- -- (to be done before sending)
74 SetScope (me : in out; numscope,numin : Integer)
75 ---Purpose : Declares the Entity Number <numscope> to correspond to a Scope
76 -- which contains the Entity Number <numin>. Several calls to the
77 -- same <numscope> add Entities in this Scope, in this order.
78 raises InterfaceMismatch;
79 ---Purpose: Error if <numin> is already declared in the Scope
80 -- Warning : the declaration of the Scopes is assumed to be consistent,
81 -- i.e. <numin> is not referenced from outside this Scope
84 IsInScope (me; num : Integer) returns Boolean;
85 ---Purpose : Returns True if an Entity identified by its Number is in a Scope
87 -- -- Sending Parts of a Model -- --
89 SendModel (me : in out; protocol : Protocol from StepData;
90 headeronly : Boolean = Standard_False)
91 ---Purpose : Sends the complete Model, included HEADER and DATA Sections
92 -- Works with a WriterLib defined through a Protocol
93 -- If <headeronly> is given True, only the HEADER Section is sent
94 -- (used to Dump the Header of a StepModel)
95 raises InterfaceMismatch;
96 -- Error if any of the called Send's falls in Error
98 SendHeader (me : in out);
99 ---Purpose : Begins model header
101 SendData (me : in out) raises InterfaceMismatch;
102 ---Purpose : Begins data section; error if EndSec was not set
104 SendEntity (me : in out; nument : Integer; lib : WriterLib)
105 ---Purpose : Send an Entity of the Data Section. If it corresponds to a
106 -- Scope, also Sends the Scope informations and contained Items
107 raises InterfaceMismatch;
108 -- Error if any of the called Send's falls in Error
110 EndSec (me : in out);
111 ---Purpose : sets end of section; to be done before passing to next one
113 EndFile (me : in out) raises InterfaceMismatch;
114 ---Purpose : sets end of file; error is EndSec was not set
116 -- -- Managing line -- --
118 AddString (me : in out; str : AsciiString from TCollection; more : Integer = 0)
120 ---Purpose : adds a string to current line; first flushes it if full
121 -- (72 char); more allows to ask a reserve at end of line : flush
122 -- is done if remaining length (to 72) is less than <more>
124 AddString (me : in out; str : CString; lnstr : Integer; more : Integer = 0)
126 ---Purpose : Same as above, but the string is given by CString + Length
129 NewLine (me : in out; evenempty : Boolean);
130 ---Purpose : flushes current line; if empty, flushes it (defines a new
131 -- empty line) if evenempty is True; else, skips it
133 JoinLast (me : in out; newline : Boolean);
134 ---Purpose : joins current line to last one, only if new length is 72 max
135 -- if newline is True, a new current line begins; else, current
136 -- line is set to the last line (once joined) itself an can be
139 Indent (me : in out; onent : Boolean);
140 ---Purpose : asks that further indentations will begin at position of
141 -- entity first opening bracket; else they begin at zero (def)
142 -- for each sublist level, two more blancks are added at beginning
143 -- (except for text continuation, which must begin at true zero)
145 -- -- Sending entities -- --
147 SendIdent (me : in out; ident : Integer);
148 ---Purpose : begins an entity with an ident plus '=' (at beginning of line)
149 -- entity ident is its Number given by the containing Model
150 -- Warning : <ident> must be, either Number or Label, according LabelMode
152 SendScope (me : in out);
153 ---Purpose : sets a begin of Scope (ends this line)
155 SendEndscope (me : in out);
156 ---Purpose : sets an end of Scope (on a separate line)
158 Comment (me : in out; mode : Boolean);
159 ---Purpose : sets a comment mark : if mode is True, begins Comment zone,
160 -- if mode is False, ends Comment zone (if one is begun)
162 SendComment (me : in out; text : HAsciiString from TCollection)
163 raises InterfaceMismatch;
164 ---Purpose : sends a comment. Error if we are not inside a comment zone
166 SendComment (me : in out; text : CString) raises InterfaceMismatch;
167 ---Purpose : same as above but accepts a CString (ex.: "..." directly)
169 StartEntity (me : in out; atype : AsciiString from TCollection);
170 ---Purpose : sets entity's StepType, opens brakets, starts param no to 0
171 -- params are separated by comma
172 -- Remark : for a Multiple Type Entity (see Express ANDOR clause)
173 -- StartComplex must be called before sending componants, then
174 -- each "Componant" must be send separately (one call to
175 -- StartEntity for each one) : the Type which preceeds is then
176 -- automaticaly closed. Once all the componants have been sent,
177 -- EndComplex must be called, then and only then EndEntity
179 StartComplex (me : in out);
180 ---Purpose : sends the start of a complex entity, which is a simple open
181 -- bracket (without increasing braket level)
182 -- It must be called JUST AFTER SendEntity and BEFORE sending
183 -- componants, each one begins by StartEntity
185 EndComplex (me : in out);
186 ---Purpose : sends the end of a complex entity : a simple closed bracket
187 -- It must be called AFTER sending all the componants and BEFORE
188 -- the final call to EndEntity
190 -- -- Sending Parameters -- --
192 SendField (me : in out; fild : Field; descr : PDescr);
193 ---Purpose : Sends the content of a field, controlled by its descriptor
194 -- If the descriptor is not defined, follows the description
195 -- detained by the field itself
197 SendSelect (me : in out; sm : SelectMember; descr : PDescr);
198 ---Purpose : Sends a SelectMember, which cab be named or not
200 SendList (me : in out; list : FieldList; descr : ESDescr);
201 ---Purpose : Send the content of an entity as being a FieldList controlled
202 -- by its descriptor. This includes start and end brackets but
203 -- not the entity type
205 OpenSub (me : in out);
206 ---Purpose : open a sublist by a '('
208 OpenTypedSub (me : in out; subtype : CString);
209 ---Purpose : open a sublist with its type then a '('
211 CloseSub (me : in out);
212 ---Purpose : closes a sublist by a ')'
214 AddParam (me : in out);
215 ---Purpose : prepares adding a parameter (that is, adds ',' except for
216 -- first one); normally for internal use; can be used to send
217 -- a totally empty parameter (with no litteral value)
219 Send (me : in out; val : Integer);
220 ---Purpose : sends an integer parameter
222 Send (me : in out; val : Real);
223 ---Purpose : sends a real parameter (wroks with FloatWriter)
225 Send (me : in out; val : AsciiString from TCollection);
226 ---Purpose : sends a text given as string (it will be set between '...')
228 Send (me : in out; val : Transient);
229 ---Purpose : sends a reference to an entity (its identifier with '#')
230 -- REMARK 1 : a Null <val> is interpreted as "Undefined"
231 -- REMARK 2 : for an HAsciiString which is not recorded in the
232 -- Model, it is send as its String Content, between quotes
234 SendBoolean (me : in out; val : Boolean);
235 ---Purpose : sends a Boolean as .T. for True or .F. for False
236 -- (it is an useful case of Enum, which is built-in)
238 SendLogical (me : in out; val : Logical from StepData);
239 ---Purpose : sends a Logical as .T. or .F. or .U. according its Value
240 -- (it is a standard case of Enum for Step, and is built-in)
242 SendString (me : in out; val : AsciiString from TCollection);
243 ---Purpose : sends a string exactly as it is given
245 SendString (me : in out; val : CString);
246 ---Purpose : sends a string exactly as it is given
248 SendEnum (me : in out; val : AsciiString from TCollection);
249 ---Purpose : sends an enum given by String (litteral expression)
250 -- adds '.' around it if not done
251 -- Remark : val can be computed by class EnumTool from StepData:
252 -- StepWriter.SendEnum (myenum.Text(enumval));
254 SendEnum (me : in out; val : CString);
255 ---Purpose : sends an enum given by String (litteral expression)
256 -- adds '.' around it if not done
258 SendArrReal(me : in out; anArr : HArray1OfReal from TColStd);
259 ---Purpose : sends an array of real
261 SendUndef (me : in out);
262 ---Purpose : sends an undefined (optionnal absent) parameter (by '$')
264 SendDerived (me : in out);
265 ---Purpose : sends a "Derived" parameter (by '*'). A Derived Parameter has
266 -- been inherited from a Super-Type then redefined as being
267 -- computed by a function. Hence its value in file is senseless.
269 EndEntity (me : in out) raises InterfaceMismatch;
270 ---Purpose : sends end of entity (closing bracket plus ';')
271 -- Error if count of opened-closed brackets is not null
273 -- -- Printing on an output -- --
275 CheckList (me) returns CheckIterator;
276 ---Purpose : Returns the check-list, which has received possible checks :
277 -- for unknown entities, badly loaded ones, null or unknown
280 NbLines (me) returns Integer;
281 ---Purpose : Returns count of Lines
283 Line (me; num : Integer) returns HAsciiString from TCollection;
284 ---Purpose : Returns a Line given its rank in the File
286 Print (me : in out; S : in out OStream) returns Boolean;
287 ---Purpose : writes result on an output defined as an OStream
292 themodel : StepModel;
293 thefile : HSequenceOfHAsciiString;
294 thecurr : LineBuffer;
295 thesect : Boolean; -- False at very start or after EndSec
296 thecomm : Boolean; -- are we in inside a comment
297 thefirst : Boolean; -- True on first parameter, False on following ones
298 themult : Boolean; -- True after sending first type (for Multiple Type)
299 thelevel : Integer; -- current sublist level
300 theindent : Boolean; -- True to indent at entity opening bracket
301 theindval : Integer; -- position of entity opening bracket
303 thetypmode : Integer;
304 thefloatw : FloatWriter; -- control of sending Reals
306 thechecks : CheckIterator;
309 thelabmode : Integer;
310 thescopebeg : HArray1OfInteger;
311 thescopeend : HArray1OfInteger;
312 thescopenext : HArray1OfInteger;