|
|
|||
File indexing completed on 2026-10-01 09:02: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 <TCollection_HAsciiString.hxx> 0025 #include <NCollection_Sequence.hxx> 0026 #include <NCollection_HSequence.hxx> 0027 #include <Interface_LineBuffer.hxx> 0028 #include <Standard_Integer.hxx> 0029 #include <Interface_FloatWriter.hxx> 0030 #include <Interface_CheckIterator.hxx> 0031 #include <NCollection_Array1.hxx> 0032 #include <NCollection_HArray1.hxx> 0033 #include <Standard_CString.hxx> 0034 #include <StepData_Logical.hxx> 0035 #include <Standard_OStream.hxx> 0036 class StepData_StepModel; 0037 class StepData_Protocol; 0038 class StepData_WriterLib; 0039 class TCollection_AsciiString; 0040 class TCollection_HAsciiString; 0041 class StepData_Field; 0042 class StepData_PDescr; 0043 class StepData_SelectMember; 0044 class StepData_FieldList; 0045 class StepData_ESDescr; 0046 class Standard_Transient; 0047 0048 //! manages atomic file writing, under control of StepModel (for 0049 //! general organisation of file) and each class of Transient 0050 //! (for its own parameters) : prepares text to be written then 0051 //! writes it 0052 //! A stream cannot be used because Step limits line length at 72 0053 //! In more, a specific object offers more appropriate functions 0054 class StepData_StepWriter 0055 { 0056 public: 0057 DEFINE_STANDARD_ALLOC 0058 0059 //! Creates an empty StepWriter from a StepModel. The StepModel 0060 //! provides the Number of Entities, as identifiers for File 0061 Standard_EXPORT StepData_StepWriter(const occ::handle<StepData_StepModel>& amodel); 0062 0063 //! ModeLabel controls how to display entity ids : 0064 //! 0 (D) gives entity number in the model 0065 //! 1 gives the already recorded label (else, its number) 0066 //! Warning : conflicts are not controlled 0067 Standard_EXPORT int& LabelMode(); 0068 0069 //! TypeMode controls the type form to use : 0070 //! 0 (D) for normal long form 0071 //! 1 for short form (if a type name has no short form, normal 0072 //! long form is then used) 0073 Standard_EXPORT int& TypeMode(); 0074 0075 //! Returns the embedded FloatWriter, which controls sending Reals 0076 //! Use this method to access FloatWriter in order to consult or 0077 //! change its options (MainFormat, FormatForRange,ZeroSuppress), 0078 //! because it is returned as the address of its field 0079 Standard_EXPORT Interface_FloatWriter& FloatWriter(); 0080 0081 //! Declares the Entity Number <numscope> to correspond to a Scope 0082 //! which contains the Entity Number <numin>. Several calls to the 0083 //! same <numscope> add Entities in this Scope, in this order. 0084 //! Error if <numin> is already declared in the Scope 0085 //! Warning : the declaration of the Scopes is assumed to be consistent, 0086 //! i.e. <numin> is not referenced from outside this Scope 0087 //! (not checked here) 0088 Standard_EXPORT void SetScope(const int numscope, const int numin); 0089 0090 //! Returns True if an Entity identified by its Number is in a Scope 0091 Standard_EXPORT bool IsInScope(const int num) const; 0092 0093 //! Sends the complete Model, included HEADER and DATA Sections 0094 //! Works with a WriterLib defined through a Protocol 0095 //! If <headeronly> is given True, only the HEADER Section is sent 0096 //! (used to Dump the Header of a StepModel) 0097 Standard_EXPORT void SendModel(const occ::handle<StepData_Protocol>& protocol, 0098 const bool headeronly = false); 0099 0100 //! Begins model header 0101 Standard_EXPORT void SendHeader(); 0102 0103 //! Begins data section; error if EndSec was not set 0104 Standard_EXPORT void SendData(); 0105 0106 //! Send an Entity of the Data Section. If it corresponds to a 0107 //! Scope, also Sends the Scope information and contained Items 0108 Standard_EXPORT void SendEntity(const int nument, const StepData_WriterLib& lib); 0109 0110 //! sets end of section; to be done before passing to next one 0111 Standard_EXPORT void EndSec(); 0112 0113 //! sets end of file; error is EndSec was not set 0114 Standard_EXPORT void EndFile(); 0115 0116 //! flushes current line; if empty, flushes it (defines a new 0117 //! empty line) if evenempty is True; else, skips it 0118 Standard_EXPORT void NewLine(const bool evenempty); 0119 0120 //! joins current line to last one, only if new length is 72 max 0121 //! if newline is True, a new current line begins; else, current 0122 //! line is set to the last line (once joined) itself an can be 0123 //! completed 0124 Standard_EXPORT void JoinLast(const bool newline); 0125 0126 //! asks that further indentations will begin at position of 0127 //! entity first opening bracket; else they begin at zero (def) 0128 //! for each sublist level, two more blancks are added at beginning 0129 //! (except for text continuation, which must begin at true zero) 0130 Standard_EXPORT void Indent(const bool onent); 0131 0132 //! begins an entity with an ident plus '=' (at beginning of line) 0133 //! entity ident is its Number given by the containing Model 0134 //! Warning : <ident> must be, either Number or Label, according LabelMode 0135 Standard_EXPORT void SendIdent(const int ident); 0136 0137 //! sets a begin of Scope (ends this line) 0138 Standard_EXPORT void SendScope(); 0139 0140 //! sets an end of Scope (on a separate line) 0141 Standard_EXPORT void SendEndscope(); 0142 0143 //! sets a comment mark : if mode is True, begins Comment zone, 0144 //! if mode is False, ends Comment zone (if one is begun) 0145 Standard_EXPORT void Comment(const bool mode); 0146 0147 //! sends a comment. Error if we are not inside a comment zone 0148 Standard_EXPORT void SendComment(const occ::handle<TCollection_HAsciiString>& text); 0149 0150 //! same as above but accepts a CString (ex.: "..." directly) 0151 Standard_EXPORT void SendComment(const char* const text); 0152 0153 //! sets entity's StepType, opens brackets, starts param no to 0 0154 //! params are separated by comma 0155 //! Remark : for a Multiple Type Entity (see Express ANDOR clause) 0156 //! StartComplex must be called before sending components, then 0157 //! each "Component" must be sent separately (one call to 0158 //! StartEntity for each one) : the Type which precedes is then 0159 //! automatically closed. Once all the components have been sent, 0160 //! EndComplex must be called, then and only then EndEntity 0161 Standard_EXPORT void StartEntity(const TCollection_AsciiString& atype); 0162 0163 //! sends the start of a complex entity, which is a simple open 0164 //! bracket (without increasing bracket level) 0165 //! It must be called JUST AFTER SendEntity and BEFORE sending 0166 //! components, each one begins by StartEntity 0167 Standard_EXPORT void StartComplex(); 0168 0169 //! sends the end of a complex entity : a simple closed bracket 0170 //! It must be called AFTER sending all the components and BEFORE 0171 //! the final call to EndEntity 0172 Standard_EXPORT void EndComplex(); 0173 0174 //! Sends the content of a field, controlled by its descriptor 0175 //! If the descriptor is not defined, follows the description 0176 //! detained by the field itself 0177 Standard_EXPORT void SendField(const StepData_Field& fild, 0178 const occ::handle<StepData_PDescr>& descr); 0179 0180 //! Sends a SelectMember, which cab be named or not 0181 Standard_EXPORT void SendSelect(const occ::handle<StepData_SelectMember>& sm, 0182 const occ::handle<StepData_PDescr>& descr); 0183 0184 //! Send the content of an entity as being a FieldList controlled 0185 //! by its descriptor. This includes start and end brackets but 0186 //! not the entity type 0187 Standard_EXPORT void SendList(const StepData_FieldList& list, 0188 const occ::handle<StepData_ESDescr>& descr); 0189 0190 //! open a sublist by a '(' 0191 Standard_EXPORT void OpenSub(); 0192 0193 //! open a sublist with its type then a '(' 0194 Standard_EXPORT void OpenTypedSub(const char* const subtype); 0195 0196 //! closes a sublist by a ')' 0197 Standard_EXPORT void CloseSub(); 0198 0199 //! prepares adding a parameter (that is, adds ',' except for 0200 //! first one); normally for internal use; can be used to send 0201 //! a totally empty parameter (with no literal value) 0202 Standard_EXPORT void AddParam(); 0203 0204 //! sends an integer parameter 0205 Standard_EXPORT void Send(const int val); 0206 0207 //! sends a real parameter (works with FloatWriter) 0208 Standard_EXPORT void Send(const double val); 0209 0210 //! sends a text given as string (it will be set between '...') 0211 Standard_EXPORT void Send(const TCollection_AsciiString& val); 0212 0213 //! sends a reference to an entity (its identifier with '#') 0214 //! REMARK 1 : a Null <val> is interpreted as "Undefined" 0215 //! REMARK 2 : for an HAsciiString which is not recorded in the 0216 //! Model, it is send as its String Content, between quotes 0217 Standard_EXPORT void Send(const occ::handle<Standard_Transient>& val); 0218 0219 //! sends a Boolean as .T. for True or .F. for False 0220 //! (it is an useful case of Enum, which is built-in) 0221 Standard_EXPORT void SendBoolean(const bool val); 0222 0223 //! sends a Logical as .T. or .F. or .U. according its Value 0224 //! (it is a standard case of Enum for Step, and is built-in) 0225 Standard_EXPORT void SendLogical(const StepData_Logical val); 0226 0227 //! sends a string exactly as it is given 0228 Standard_EXPORT void SendString(const TCollection_AsciiString& val); 0229 0230 //! sends a string exactly as it is given 0231 Standard_EXPORT void SendString(const char* const val); 0232 0233 //! sends an enum given by String (literal expression) 0234 //! adds '.' around it if not done 0235 //! Remark : val can be computed by class EnumTool from StepData: 0236 //! StepWriter.SendEnum (myenum.Text(enumval)); 0237 Standard_EXPORT void SendEnum(const TCollection_AsciiString& val); 0238 0239 //! sends an enum given by String (literal expression) 0240 //! adds '.' around it if not done 0241 Standard_EXPORT void SendEnum(const char* const val); 0242 0243 //! sends an array of real 0244 Standard_EXPORT void SendArrReal(const occ::handle<NCollection_HArray1<double>>& anArr); 0245 0246 //! sends an undefined (optional absent) parameter (by '$') 0247 Standard_EXPORT void SendUndef(); 0248 0249 //! sends a "Derived" parameter (by '*'). A Derived Parameter has 0250 //! been inherited from a Super-Type then redefined as being 0251 //! computed by a function. Hence its value in file is senseless. 0252 Standard_EXPORT void SendDerived(); 0253 0254 //! sends end of entity (closing bracket plus ';') 0255 //! Error if count of opened-closed brackets is not null 0256 Standard_EXPORT void EndEntity(); 0257 0258 //! Returns the check-list, which has received possible checks : 0259 //! for unknown entities, badly loaded ones, null or unknown 0260 //! references 0261 Standard_EXPORT Interface_CheckIterator CheckList() const; 0262 0263 //! Returns count of Lines 0264 Standard_EXPORT int NbLines() const; 0265 0266 //! Returns a Line given its rank in the File 0267 Standard_EXPORT occ::handle<TCollection_HAsciiString> Line(const int num) const; 0268 0269 //! writes result on an output defined as an OStream 0270 //! then clears it 0271 Standard_EXPORT bool Print(Standard_OStream& S); 0272 0273 //! Static helper function to prepare text for STEP file output while preserving 0274 //! existing ISO 10303-21 control directives. 0275 //! 0276 //! This function processes input text and escapes special characters (quotes, backslashes, 0277 //! newlines, tabs) for STEP file format compliance, while carefully preserving any existing 0278 //! control directives that may already be present in the input string. 0279 //! 0280 //! Supported control directive patterns that are preserved: 0281 //! - \X{HH}\ : Single byte character encoding (U+0000 to U+00FF) 0282 //! - \X2\{HHHH}...\X0\ : UTF-16 character encoding 0283 //! - \X4\{HHHHHHHH}...\X0\ : UTF-32 character encoding 0284 //! - \S\ : Latin codepoint character with current code page 0285 //! - \P{A-I}\ : Code page control directive 0286 //! - \N\ : Newline directive (preserved as-is) 0287 //! - \T\ : Tab directive (preserved as-is) 0288 //! 0289 //! Character escaping performed (only on non-directive content): 0290 //! - Single quote (') -> double quote ('') 0291 //! - Backslash (\) -> double backslash (\\) 0292 //! - Newline character -> \N\ directive 0293 //! - Tab character -> \T\ directive 0294 //! 0295 //! Example: 0296 //! Input: "text with \XA7\ and 'quotes'" 0297 //! Output: "text with \XA7\ and ''quotes''" 0298 //! 0299 //! @param theText The input text string to be processed 0300 //! @return Processed text with preserved control directives and escaped special characters 0301 Standard_EXPORT static TCollection_AsciiString CleanTextForSend( 0302 const TCollection_AsciiString& theText); 0303 0304 private: 0305 //! adds a string to current line; first flushes it if full 0306 //! (72 char); more allows to ask a reserve at end of line : flush 0307 //! is done if remaining length (to 72) is less than <more> 0308 Standard_EXPORT void AddString(const TCollection_AsciiString& str, const int more = 0); 0309 0310 //! Same as above, but the string is given by CString + Length 0311 Standard_EXPORT void AddString(const char* const str, const int lnstr, const int more = 0); 0312 0313 occ::handle<StepData_StepModel> themodel; 0314 occ::handle<NCollection_HSequence<occ::handle<TCollection_HAsciiString>>> thefile; 0315 Interface_LineBuffer thecurr; 0316 bool thesect; 0317 bool thecomm; 0318 bool thefirst; 0319 bool themult; 0320 int thelevel; 0321 bool theindent; 0322 int theindval; 0323 int thetypmode; 0324 Interface_FloatWriter thefloatw; 0325 Interface_CheckIterator thechecks; 0326 int thenum; 0327 int thelabmode; 0328 occ::handle<NCollection_HArray1<int>> thescopebeg; 0329 occ::handle<NCollection_HArray1<int>> thescopeend; 0330 occ::handle<NCollection_HArray1<int>> thescopenext; 0331 }; 0332 0333 #endif // _StepData_StepWriter_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|