42cf5bc1 |
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_StepWriter_HeaderFile |
18 | #define _StepData_StepWriter_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
24 | #include <TColStd_HSequenceOfHAsciiString.hxx> |
25 | #include <Interface_LineBuffer.hxx> |
26 | #include <Standard_Boolean.hxx> |
27 | #include <Standard_Integer.hxx> |
28 | #include <Interface_FloatWriter.hxx> |
29 | #include <Interface_CheckIterator.hxx> |
30 | #include <TColStd_HArray1OfInteger.hxx> |
31 | #include <Standard_CString.hxx> |
32 | #include <Standard_Real.hxx> |
33 | #include <StepData_Logical.hxx> |
34 | #include <TColStd_HArray1OfReal.hxx> |
35 | #include <Standard_OStream.hxx> |
36 | class StepData_StepModel; |
37 | class Interface_InterfaceMismatch; |
38 | class Interface_FloatWriter; |
39 | class StepData_Protocol; |
40 | class StepData_WriterLib; |
41 | class TCollection_AsciiString; |
42 | class TCollection_HAsciiString; |
43 | class StepData_Field; |
44 | class StepData_PDescr; |
45 | class StepData_SelectMember; |
46 | class StepData_FieldList; |
47 | class StepData_ESDescr; |
48 | class Standard_Transient; |
49 | class Interface_CheckIterator; |
50 | |
51 | |
52 | //! manages atomic file writing, under control of StepModel (for |
53 | //! general organisation of file) and each class of Transient |
54 | //! (for its own parameters) : prepares text to be written then |
55 | //! writes it |
56 | //! A stream cannot be used because Step limits line length at 72 |
57 | //! In more, a specific object offers more appropriate functions |
58 | class StepData_StepWriter |
59 | { |
60 | public: |
61 | |
62 | DEFINE_STANDARD_ALLOC |
63 | |
64 | |
65 | //! Creates an empty StepWriter from a StepModel. The StepModel |
66 | //! provides the Number of Entities, as identifiers for File |
67 | Standard_EXPORT StepData_StepWriter(const Handle(StepData_StepModel)& amodel); |
68 | |
69 | //! ModeLabel controls how to display entity ids : |
70 | //! 0 (D) gives entity number in the model |
71 | //! 1 gives the already recorded label (else, its number) |
72 | //! Warning : conflicts are not controlled |
73 | Standard_EXPORT Standard_Integer& LabelMode(); |
74 | |
75 | //! TypeMode controls the type form to use : |
76 | //! 0 (D) for normal long form |
77 | //! 1 for short form (if a type name has no short form, normal |
78 | //! long form is then used) |
79 | Standard_EXPORT Standard_Integer& TypeMode(); |
80 | |
81 | //! Returns the embedded FloatWriter, which controls sending Reals |
82 | //! Use this method to access FloatWriter in order to consult or |
83 | //! change its options (MainFormat, FormatForRange,ZeroSuppress), |
84 | //! because it is returned as the address of its field |
85 | Standard_EXPORT Interface_FloatWriter& FloatWriter(); |
86 | |
87 | //! Declares the Entity Number <numscope> to correspond to a Scope |
88 | //! which contains the Entity Number <numin>. Several calls to the |
89 | //! same <numscope> add Entities in this Scope, in this order. |
90 | //! Error if <numin> is already declared in the Scope |
91 | //! Warning : the declaration of the Scopes is assumed to be consistent, |
92 | //! i.e. <numin> is not referenced from outside this Scope |
93 | //! (not checked here) |
94 | Standard_EXPORT void SetScope (const Standard_Integer numscope, const Standard_Integer numin); |
95 | |
96 | //! Returns True if an Entity identified by its Number is in a Scope |
97 | Standard_EXPORT Standard_Boolean IsInScope (const Standard_Integer num) const; |
98 | |
99 | //! Sends the complete Model, included HEADER and DATA Sections |
100 | //! Works with a WriterLib defined through a Protocol |
101 | //! If <headeronly> is given True, only the HEADER Section is sent |
102 | //! (used to Dump the Header of a StepModel) |
103 | Standard_EXPORT void SendModel (const Handle(StepData_Protocol)& protocol, const Standard_Boolean headeronly = Standard_False); |
104 | |
105 | //! Begins model header |
106 | Standard_EXPORT void SendHeader(); |
107 | |
108 | //! Begins data section; error if EndSec was not set |
109 | Standard_EXPORT void SendData(); |
110 | |
111 | //! Send an Entity of the Data Section. If it corresponds to a |
112 | //! Scope, also Sends the Scope informations and contained Items |
113 | Standard_EXPORT void SendEntity (const Standard_Integer nument, const StepData_WriterLib& lib); |
114 | |
115 | //! sets end of section; to be done before passing to next one |
116 | Standard_EXPORT void EndSec(); |
117 | |
118 | //! sets end of file; error is EndSec was not set |
119 | Standard_EXPORT void EndFile(); |
120 | |
121 | //! flushes current line; if empty, flushes it (defines a new |
122 | //! empty line) if evenempty is True; else, skips it |
123 | Standard_EXPORT void NewLine (const Standard_Boolean evenempty); |
124 | |
125 | //! joins current line to last one, only if new length is 72 max |
126 | //! if newline is True, a new current line begins; else, current |
127 | //! line is set to the last line (once joined) itself an can be |
128 | //! completed |
129 | Standard_EXPORT void JoinLast (const Standard_Boolean newline); |
130 | |
131 | //! asks that further indentations will begin at position of |
132 | //! entity first opening bracket; else they begin at zero (def) |
133 | //! for each sublist level, two more blancks are added at beginning |
134 | //! (except for text continuation, which must begin at true zero) |
135 | Standard_EXPORT void Indent (const Standard_Boolean onent); |
136 | |
137 | //! begins an entity with an ident plus '=' (at beginning of line) |
138 | //! entity ident is its Number given by the containing Model |
139 | //! Warning : <ident> must be, either Number or Label, according LabelMode |
140 | Standard_EXPORT void SendIdent (const Standard_Integer ident); |
141 | |
142 | //! sets a begin of Scope (ends this line) |
143 | Standard_EXPORT void SendScope(); |
144 | |
145 | //! sets an end of Scope (on a separate line) |
146 | Standard_EXPORT void SendEndscope(); |
147 | |
148 | //! sets a comment mark : if mode is True, begins Comment zone, |
149 | //! if mode is False, ends Comment zone (if one is begun) |
150 | Standard_EXPORT void Comment (const Standard_Boolean mode); |
151 | |
152 | //! sends a comment. Error if we are not inside a comment zone |
153 | Standard_EXPORT void SendComment (const Handle(TCollection_HAsciiString)& text); |
154 | |
155 | //! same as above but accepts a CString (ex.: "..." directly) |
156 | Standard_EXPORT void SendComment (const Standard_CString text); |
157 | |
158 | //! sets entity's StepType, opens brakets, starts param no to 0 |
159 | //! params are separated by comma |
160 | //! Remark : for a Multiple Type Entity (see Express ANDOR clause) |
161 | //! StartComplex must be called before sending componants, then |
162 | //! each "Componant" must be send separately (one call to |
163 | //! StartEntity for each one) : the Type which preceeds is then |
164 | //! automaticaly closed. Once all the componants have been sent, |
165 | //! EndComplex must be called, then and only then EndEntity |
166 | Standard_EXPORT void StartEntity (const TCollection_AsciiString& atype); |
167 | |
168 | //! sends the start of a complex entity, which is a simple open |
169 | //! bracket (without increasing braket level) |
170 | //! It must be called JUST AFTER SendEntity and BEFORE sending |
171 | //! componants, each one begins by StartEntity |
172 | Standard_EXPORT void StartComplex(); |
173 | |
174 | //! sends the end of a complex entity : a simple closed bracket |
175 | //! It must be called AFTER sending all the componants and BEFORE |
176 | //! the final call to EndEntity |
177 | Standard_EXPORT void EndComplex(); |
178 | |
179 | //! Sends the content of a field, controlled by its descriptor |
180 | //! If the descriptor is not defined, follows the description |
181 | //! detained by the field itself |
182 | Standard_EXPORT void SendField (const StepData_Field& fild, const Handle(StepData_PDescr)& descr); |
183 | |
184 | //! Sends a SelectMember, which cab be named or not |
185 | Standard_EXPORT void SendSelect (const Handle(StepData_SelectMember)& sm, const Handle(StepData_PDescr)& descr); |
186 | |
187 | //! Send the content of an entity as being a FieldList controlled |
188 | //! by its descriptor. This includes start and end brackets but |
189 | //! not the entity type |
190 | Standard_EXPORT void SendList (const StepData_FieldList& list, const Handle(StepData_ESDescr)& descr); |
191 | |
192 | //! open a sublist by a '(' |
193 | Standard_EXPORT void OpenSub(); |
194 | |
195 | //! open a sublist with its type then a '(' |
196 | Standard_EXPORT void OpenTypedSub (const Standard_CString subtype); |
197 | |
198 | //! closes a sublist by a ')' |
199 | Standard_EXPORT void CloseSub(); |
200 | |
201 | //! prepares adding a parameter (that is, adds ',' except for |
202 | //! first one); normally for internal use; can be used to send |
203 | //! a totally empty parameter (with no litteral value) |
204 | Standard_EXPORT void AddParam(); |
205 | |
206 | //! sends an integer parameter |
207 | Standard_EXPORT void Send (const Standard_Integer val); |
208 | |
209 | //! sends a real parameter (wroks with FloatWriter) |
210 | Standard_EXPORT void Send (const Standard_Real val); |
211 | |
212 | //! sends a text given as string (it will be set between '...') |
213 | Standard_EXPORT void Send (const TCollection_AsciiString& val); |
214 | |
215 | //! sends a reference to an entity (its identifier with '#') |
216 | //! REMARK 1 : a Null <val> is interpreted as "Undefined" |
217 | //! REMARK 2 : for an HAsciiString which is not recorded in the |
218 | //! Model, it is send as its String Content, between quotes |
219 | Standard_EXPORT void Send (const Handle(Standard_Transient)& val); |
220 | |
221 | //! sends a Boolean as .T. for True or .F. for False |
222 | //! (it is an useful case of Enum, which is built-in) |
223 | Standard_EXPORT void SendBoolean (const Standard_Boolean val); |
224 | |
225 | //! sends a Logical as .T. or .F. or .U. according its Value |
226 | //! (it is a standard case of Enum for Step, and is built-in) |
227 | Standard_EXPORT void SendLogical (const StepData_Logical val); |
228 | |
229 | //! sends a string exactly as it is given |
230 | Standard_EXPORT void SendString (const TCollection_AsciiString& val); |
231 | |
232 | //! sends a string exactly as it is given |
233 | Standard_EXPORT void SendString (const Standard_CString val); |
234 | |
235 | //! sends an enum given by String (litteral expression) |
236 | //! adds '.' around it if not done |
237 | //! Remark : val can be computed by class EnumTool from StepData: |
238 | //! StepWriter.SendEnum (myenum.Text(enumval)); |
239 | Standard_EXPORT void SendEnum (const TCollection_AsciiString& val); |
240 | |
241 | //! sends an enum given by String (litteral expression) |
242 | //! adds '.' around it if not done |
243 | Standard_EXPORT void SendEnum (const Standard_CString val); |
244 | |
245 | //! sends an array of real |
246 | Standard_EXPORT void SendArrReal (const Handle(TColStd_HArray1OfReal)& anArr); |
247 | |
248 | //! sends an undefined (optionnal absent) parameter (by '$') |
249 | Standard_EXPORT void SendUndef(); |
250 | |
251 | //! sends a "Derived" parameter (by '*'). A Derived Parameter has |
252 | //! been inherited from a Super-Type then redefined as being |
253 | //! computed by a function. Hence its value in file is senseless. |
254 | Standard_EXPORT void SendDerived(); |
255 | |
256 | //! sends end of entity (closing bracket plus ';') |
257 | //! Error if count of opened-closed brackets is not null |
258 | Standard_EXPORT void EndEntity(); |
259 | |
260 | //! Returns the check-list, which has received possible checks : |
261 | //! for unknown entities, badly loaded ones, null or unknown |
262 | //! references |
263 | Standard_EXPORT Interface_CheckIterator CheckList() const; |
264 | |
265 | //! Returns count of Lines |
266 | Standard_EXPORT Standard_Integer NbLines() const; |
267 | |
268 | //! Returns a Line given its rank in the File |
269 | Standard_EXPORT Handle(TCollection_HAsciiString) Line (const Standard_Integer num) const; |
270 | |
271 | //! writes result on an output defined as an OStream |
272 | //! then clears it |
273 | Standard_EXPORT Standard_Boolean Print (Standard_OStream& S); |
274 | |
275 | |
276 | |
277 | |
278 | protected: |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | private: |
285 | |
286 | |
287 | //! adds a string to current line; first flushes it if full |
288 | //! (72 char); more allows to ask a reserve at end of line : flush |
289 | //! is done if remaining length (to 72) is less than <more> |
290 | Standard_EXPORT void AddString (const TCollection_AsciiString& str, const Standard_Integer more = 0); |
291 | |
292 | //! Same as above, but the string is given by CString + Length |
293 | Standard_EXPORT void AddString (const Standard_CString str, const Standard_Integer lnstr, const Standard_Integer more = 0); |
294 | |
295 | |
296 | Handle(StepData_StepModel) themodel; |
297 | Handle(TColStd_HSequenceOfHAsciiString) thefile; |
298 | Interface_LineBuffer thecurr; |
299 | Standard_Boolean thesect; |
300 | Standard_Boolean thecomm; |
301 | Standard_Boolean thefirst; |
302 | Standard_Boolean themult; |
303 | Standard_Integer thelevel; |
304 | Standard_Boolean theindent; |
305 | Standard_Integer theindval; |
306 | Standard_Integer thetypmode; |
307 | Interface_FloatWriter thefloatw; |
308 | Interface_CheckIterator thechecks; |
309 | Standard_Integer thenum; |
310 | Standard_Integer thelabmode; |
311 | Handle(TColStd_HArray1OfInteger) thescopebeg; |
312 | Handle(TColStd_HArray1OfInteger) thescopeend; |
313 | Handle(TColStd_HArray1OfInteger) thescopenext; |
314 | |
315 | |
316 | }; |
317 | |
318 | |
319 | |
320 | |
321 | |
322 | |
323 | |
324 | #endif // _StepData_StepWriter_HeaderFile |