Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-04 08:46:20

0001 // Created on: 1992-02-11
0002 // Created by: Christian CAILLET
0003 // Copyright (c) 1992-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _StepData_StepWriter_HeaderFile
0018 #define _StepData_StepWriter_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <TColStd_HSequenceOfHAsciiString.hxx>
0025 #include <Interface_LineBuffer.hxx>
0026 #include <Standard_Integer.hxx>
0027 #include <Interface_FloatWriter.hxx>
0028 #include <Interface_CheckIterator.hxx>
0029 #include <TColStd_HArray1OfInteger.hxx>
0030 #include <Standard_CString.hxx>
0031 #include <StepData_Logical.hxx>
0032 #include <TColStd_HArray1OfReal.hxx>
0033 #include <Standard_OStream.hxx>
0034 class StepData_StepModel;
0035 class StepData_Protocol;
0036 class StepData_WriterLib;
0037 class TCollection_AsciiString;
0038 class TCollection_HAsciiString;
0039 class StepData_Field;
0040 class StepData_PDescr;
0041 class StepData_SelectMember;
0042 class StepData_FieldList;
0043 class StepData_ESDescr;
0044 class Standard_Transient;
0045 
0046 //! manages atomic file writing, under control of StepModel (for
0047 //! general organisation of file) and each class of Transient
0048 //! (for its own parameters) : prepares text to be written then
0049 //! writes it
0050 //! A stream cannot be used because Step limits line length at 72
0051 //! In more, a specific object offers more appropriate functions
0052 class StepData_StepWriter
0053 {
0054 public:
0055   DEFINE_STANDARD_ALLOC
0056 
0057   //! Creates an empty StepWriter from a StepModel. The StepModel
0058   //! provides the Number of Entities, as identifiers for File
0059   Standard_EXPORT StepData_StepWriter(const Handle(StepData_StepModel)& amodel);
0060 
0061   //! ModeLabel controls how to display entity ids :
0062   //! 0 (D) gives entity number in the model
0063   //! 1 gives the already recorded label (else, its number)
0064   //! Warning : conflicts are not controlled
0065   Standard_EXPORT Standard_Integer& LabelMode();
0066 
0067   //! TypeMode  controls the type form to use :
0068   //! 0 (D) for normal long form
0069   //! 1 for short form (if a type name has no short form, normal
0070   //! long form is then used)
0071   Standard_EXPORT Standard_Integer& TypeMode();
0072 
0073   //! Returns the embedded FloatWriter, which controls sending Reals
0074   //! Use this method to access FloatWriter in order to consult or
0075   //! change its options (MainFormat, FormatForRange,ZeroSuppress),
0076   //! because it is returned as the address of its field
0077   Standard_EXPORT Interface_FloatWriter& FloatWriter();
0078 
0079   //! Declares the Entity Number <numscope> to correspond to a Scope
0080   //! which contains the Entity Number <numin>. Several calls to the
0081   //! same <numscope> add Entities in this Scope, in this order.
0082   //! Error if <numin> is already declared in the Scope
0083   //! Warning : the declaration of the Scopes is assumed to be consistent,
0084   //! i.e. <numin> is not referenced from outside this Scope
0085   //! (not checked here)
0086   Standard_EXPORT void SetScope(const Standard_Integer numscope, const Standard_Integer numin);
0087 
0088   //! Returns True if an Entity identified by its Number is in a Scope
0089   Standard_EXPORT Standard_Boolean IsInScope(const Standard_Integer num) const;
0090 
0091   //! Sends the complete Model, included HEADER and DATA Sections
0092   //! Works with a WriterLib defined through a Protocol
0093   //! If <headeronly> is given True, only the HEADER Section is sent
0094   //! (used to Dump the Header of a StepModel)
0095   Standard_EXPORT void SendModel(const Handle(StepData_Protocol)& protocol,
0096                                  const Standard_Boolean           headeronly = Standard_False);
0097 
0098   //! Begins model header
0099   Standard_EXPORT void SendHeader();
0100 
0101   //! Begins data section; error if EndSec was not set
0102   Standard_EXPORT void SendData();
0103 
0104   //! Send an Entity of the Data Section. If it corresponds to a
0105   //! Scope, also Sends the Scope information and contained Items
0106   Standard_EXPORT void SendEntity(const Standard_Integer nument, const StepData_WriterLib& lib);
0107 
0108   //! sets end of section; to be done before passing to next one
0109   Standard_EXPORT void EndSec();
0110 
0111   //! sets end of file; error is EndSec was not set
0112   Standard_EXPORT void EndFile();
0113 
0114   //! flushes current line; if empty, flushes it (defines a new
0115   //! empty line) if evenempty is True; else, skips it
0116   Standard_EXPORT void NewLine(const Standard_Boolean evenempty);
0117 
0118   //! joins current line to last one, only if new length is 72 max
0119   //! if newline is True, a new current line begins; else, current
0120   //! line is set to the last line (once joined) itself an can be
0121   //! completed
0122   Standard_EXPORT void JoinLast(const Standard_Boolean newline);
0123 
0124   //! asks that further indentations will begin at position of
0125   //! entity first opening bracket; else they begin at zero (def)
0126   //! for each sublist level, two more blancks are added at beginning
0127   //! (except for text continuation, which must begin at true zero)
0128   Standard_EXPORT void Indent(const Standard_Boolean onent);
0129 
0130   //! begins an entity with an ident plus '=' (at beginning of line)
0131   //! entity ident is its Number given by the containing Model
0132   //! Warning : <ident> must be, either Number or Label, according LabelMode
0133   Standard_EXPORT void SendIdent(const Standard_Integer ident);
0134 
0135   //! sets a begin of Scope (ends this line)
0136   Standard_EXPORT void SendScope();
0137 
0138   //! sets an end of Scope  (on a separate line)
0139   Standard_EXPORT void SendEndscope();
0140 
0141   //! sets a comment mark : if mode is True, begins Comment zone,
0142   //! if mode is False, ends Comment zone (if one is begun)
0143   Standard_EXPORT void Comment(const Standard_Boolean mode);
0144 
0145   //! sends a comment. Error if we are not inside a comment zone
0146   Standard_EXPORT void SendComment(const Handle(TCollection_HAsciiString)& text);
0147 
0148   //! same as above but accepts a CString (ex.: "..." directly)
0149   Standard_EXPORT void SendComment(const Standard_CString text);
0150 
0151   //! sets entity's StepType, opens brackets, starts param no to 0
0152   //! params are separated by comma
0153   //! Remark : for a Multiple Type Entity (see Express ANDOR clause)
0154   //! StartComplex must be called before sending components, then
0155   //! each "Component" must be sent separately (one call to
0156   //! StartEntity for each one) : the Type which precedes is then
0157   //! automatically closed. Once all the components have been sent,
0158   //! EndComplex must be called, then and only then EndEntity
0159   Standard_EXPORT void StartEntity(const TCollection_AsciiString& atype);
0160 
0161   //! sends the start of a complex entity, which is a simple open
0162   //! bracket (without increasing bracket level)
0163   //! It must be called JUST AFTER SendEntity and BEFORE sending
0164   //! components, each one begins by StartEntity
0165   Standard_EXPORT void StartComplex();
0166 
0167   //! sends the end of a complex entity : a simple closed bracket
0168   //! It must be called AFTER sending all the components and BEFORE
0169   //! the final call to EndEntity
0170   Standard_EXPORT void EndComplex();
0171 
0172   //! Sends the content of a field, controlled by its descriptor
0173   //! If the descriptor is not defined, follows the description
0174   //! detained by the field itself
0175   Standard_EXPORT void SendField(const StepData_Field& fild, const Handle(StepData_PDescr)& descr);
0176 
0177   //! Sends a SelectMember, which cab be named or not
0178   Standard_EXPORT void SendSelect(const Handle(StepData_SelectMember)& sm,
0179                                   const Handle(StepData_PDescr)&       descr);
0180 
0181   //! Send the content of an entity as being a FieldList controlled
0182   //! by its descriptor. This includes start and end brackets but
0183   //! not the entity type
0184   Standard_EXPORT void SendList(const StepData_FieldList&       list,
0185                                 const Handle(StepData_ESDescr)& descr);
0186 
0187   //! open a sublist by a '('
0188   Standard_EXPORT void OpenSub();
0189 
0190   //! open a sublist with its type then a '('
0191   Standard_EXPORT void OpenTypedSub(const Standard_CString subtype);
0192 
0193   //! closes a sublist by a ')'
0194   Standard_EXPORT void CloseSub();
0195 
0196   //! prepares adding a parameter (that is, adds ',' except for
0197   //! first one); normally for internal use; can be used to send
0198   //! a totally empty parameter (with no literal value)
0199   Standard_EXPORT void AddParam();
0200 
0201   //! sends an integer parameter
0202   Standard_EXPORT void Send(const Standard_Integer val);
0203 
0204   //! sends a real parameter (works with FloatWriter)
0205   Standard_EXPORT void Send(const Standard_Real val);
0206 
0207   //! sends a text given as string (it will be set between '...')
0208   Standard_EXPORT void Send(const TCollection_AsciiString& val);
0209 
0210   //! sends a reference to an entity (its identifier with '#')
0211   //! REMARK 1 : a Null <val> is interpreted as "Undefined"
0212   //! REMARK 2 : for an HAsciiString which is not recorded in the
0213   //! Model, it is send as its String Content, between quotes
0214   Standard_EXPORT void Send(const Handle(Standard_Transient)& val);
0215 
0216   //! sends a Boolean as .T. for True or .F. for False
0217   //! (it is an useful case of Enum, which is built-in)
0218   Standard_EXPORT void SendBoolean(const Standard_Boolean val);
0219 
0220   //! sends a Logical as .T. or .F. or .U. according its Value
0221   //! (it is a standard case of Enum for Step, and is built-in)
0222   Standard_EXPORT void SendLogical(const StepData_Logical val);
0223 
0224   //! sends a string exactly as it is given
0225   Standard_EXPORT void SendString(const TCollection_AsciiString& val);
0226 
0227   //! sends a string exactly as it is given
0228   Standard_EXPORT void SendString(const Standard_CString val);
0229 
0230   //! sends an enum given by String (literal expression)
0231   //! adds '.' around it if not done
0232   //! Remark : val can be computed by class EnumTool from StepData:
0233   //! StepWriter.SendEnum (myenum.Text(enumval));
0234   Standard_EXPORT void SendEnum(const TCollection_AsciiString& val);
0235 
0236   //! sends an enum given by String (literal expression)
0237   //! adds '.' around it if not done
0238   Standard_EXPORT void SendEnum(const Standard_CString val);
0239 
0240   //! sends an array of real
0241   Standard_EXPORT void SendArrReal(const Handle(TColStd_HArray1OfReal)& anArr);
0242 
0243   //! sends an undefined (optional absent) parameter (by '$')
0244   Standard_EXPORT void SendUndef();
0245 
0246   //! sends a "Derived" parameter (by '*'). A Derived Parameter has
0247   //! been inherited from a Super-Type then redefined as being
0248   //! computed by a function. Hence its value in file is senseless.
0249   Standard_EXPORT void SendDerived();
0250 
0251   //! sends end of entity (closing bracket plus ';')
0252   //! Error if count of opened-closed brackets is not null
0253   Standard_EXPORT void EndEntity();
0254 
0255   //! Returns the check-list, which has received possible checks :
0256   //! for unknown entities, badly loaded ones, null or unknown
0257   //! references
0258   Standard_EXPORT Interface_CheckIterator CheckList() const;
0259 
0260   //! Returns count of Lines
0261   Standard_EXPORT Standard_Integer NbLines() const;
0262 
0263   //! Returns a Line given its rank in the File
0264   Standard_EXPORT Handle(TCollection_HAsciiString) Line(const Standard_Integer num) const;
0265 
0266   //! writes result on an output defined as an OStream
0267   //! then clears it
0268   Standard_EXPORT Standard_Boolean Print(Standard_OStream& S);
0269 
0270 protected:
0271 private:
0272   //! adds a string to current line; first flushes it if full
0273   //! (72 char); more allows to ask a reserve at end of line : flush
0274   //! is done if remaining length (to 72) is less than <more>
0275   Standard_EXPORT void AddString(const TCollection_AsciiString& str,
0276                                  const Standard_Integer         more = 0);
0277 
0278   //! Same as above, but the string is given by CString + Length
0279   Standard_EXPORT void AddString(const Standard_CString str,
0280                                  const Standard_Integer lnstr,
0281                                  const Standard_Integer more = 0);
0282 
0283   Handle(StepData_StepModel)              themodel;
0284   Handle(TColStd_HSequenceOfHAsciiString) thefile;
0285   Interface_LineBuffer                    thecurr;
0286   Standard_Boolean                        thesect;
0287   Standard_Boolean                        thecomm;
0288   Standard_Boolean                        thefirst;
0289   Standard_Boolean                        themult;
0290   Standard_Integer                        thelevel;
0291   Standard_Boolean                        theindent;
0292   Standard_Integer                        theindval;
0293   Standard_Integer                        thetypmode;
0294   Interface_FloatWriter                   thefloatw;
0295   Interface_CheckIterator                 thechecks;
0296   Standard_Integer                        thenum;
0297   Standard_Integer                        thelabmode;
0298   Handle(TColStd_HArray1OfInteger)        thescopebeg;
0299   Handle(TColStd_HArray1OfInteger)        thescopeend;
0300   Handle(TColStd_HArray1OfInteger)        thescopenext;
0301 };
0302 
0303 #endif // _StepData_StepWriter_HeaderFile