0028824: Possibility to build OCCT 7.1.0 and above using Visual Studio 2008
[occt.git] / src / IGESData / IGESData_IGESWriter.hxx
1 // Created on: 1992-04-07
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 _IGESData_IGESWriter_HeaderFile
18 #define _IGESData_IGESWriter_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <TColStd_HSequenceOfHAsciiString.hxx>
25 #include <Standard_Character.hxx>
26 #include <IGESData_Array1OfDirPart.hxx>
27 #include <TColStd_Array1OfInteger.hxx>
28 #include <Standard_Integer.hxx>
29 #include <IGESData_ReadStage.hxx>
30 #include <Interface_LineBuffer.hxx>
31 #include <Interface_FloatWriter.hxx>
32 #include <Standard_CString.hxx>
33 #include <Standard_Boolean.hxx>
34 #include <Standard_Real.hxx>
35 #include <Standard_OStream.hxx>
36
37 class IGESData_IGESModel;
38 class Interface_InterfaceMismatch;
39 class Interface_FloatWriter;
40 class IGESData_Protocol;
41 class IGESData_GlobalSection;
42 class IGESData_IGESEntity;
43 class TCollection_HAsciiString;
44 class gp_XY;
45 class gp_XYZ;
46
47 //! manages atomic file writing, under control of IGESModel :
48 //! prepare text to be sent then sends it
49 //! takes into account distinction between successive Sections
50 class IGESData_IGESWriter 
51 {
52 public:
53
54   DEFINE_STANDARD_ALLOC
55
56   
57   //! Creates an IGESWriter, empty ready to work
58   //! (see the methods SendModel and Print)
59   Standard_EXPORT IGESData_IGESWriter(const Handle(IGESData_IGESModel)& amodel);
60   
61   //! Default constructor (not used) to satisfy the compiler
62   Standard_EXPORT IGESData_IGESWriter();
63   
64   //! Constructor by copy (not used) to satisfy the compiler
65   Standard_EXPORT IGESData_IGESWriter(const IGESData_IGESWriter& other);
66   
67   //! Returns the embedded FloatWriter, which controls sending Reals
68   //! Use this method to access FloatWriter in order to consult or
69   //! change its options (MainFormat, FormatForRange,ZeroSuppress),
70   //! because it is returned as the address of its field
71   Standard_EXPORT Interface_FloatWriter& FloatWriter();
72   
73   //! Returns the write mode, in order to be read and/or changed
74   //! Write Mode controls the way final print works
75   //! 0 (D) : Normal IGES, 10 : FNES
76   Standard_EXPORT Standard_Integer& WriteMode();
77   
78   //! Sends an additionnal Starting Line : this is the way used to
79   //! send comments in an IGES File (at beginning of the file).
80   //! If the line is more than 72 char.s long, it is splited into
81   //! as many lines as required to send it completely
82   Standard_EXPORT void SendStartLine (const Standard_CString startline);
83   
84   //! Sends the complete IGESModel (Global Section, Entities as
85   //! Directory Entries & Parameter Lists, etc...)
86   //! i.e. fills a list of texts. Once filled, it can be sent by
87   //! method Print
88   Standard_EXPORT void SendModel (const Handle(IGESData_Protocol)& protocol);
89   
90   //! declares sending of S section (only a declaration)
91   //! error if state is not initial
92   Standard_EXPORT void SectionS();
93   
94   //! prepares sending of header, from a GlobalSection (stores it)
95   //! error if SectionS was not called just before
96   //! takes in account special characters (Separator, EndMark)
97   Standard_EXPORT void SectionG (const IGESData_GlobalSection& header);
98   
99   //! prepares sending of list of entities, as Sections D (directory
100   //! list) and P (Parameters lists, one per entity)
101   //! Entities will be then processed, one after the other
102   //! error if SectionG has not be called just before
103   Standard_EXPORT void SectionsDP();
104   
105   //! declares sending of T section (only a declaration)
106   //! error if does not follow Entities sending
107   Standard_EXPORT void SectionT();
108   
109   //! translates directory part of an Entity into a litteral DirPart
110   //! Some infos are computed after sending parameters
111   //! Error if not in sections DP or Stage not "Dir"
112   Standard_EXPORT void DirPart (const Handle(IGESData_IGESEntity)& anent);
113   
114   //! sends own parameters of the entity, by sending firstly its
115   //! type, then calling specific method WriteOwnParams
116   //! Error if not in sections DP or Stage not "Own"
117   Standard_EXPORT void OwnParams (const Handle(IGESData_IGESEntity)& anent);
118   
119   //! sends associativity list, as complement of parameters list
120   //! error if not in sections DP or Stage not "Associativity"
121   Standard_EXPORT void Associativities (const Handle(IGESData_IGESEntity)& anent);
122   
123   //! sends property list, as complement of parameters list
124   //! error if not in sections DP or Stage not "Property"
125   Standard_EXPORT void Properties (const Handle(IGESData_IGESEntity)& anent);
126   
127   //! declares end of sending an entity (ends param list by ';')
128   Standard_EXPORT void EndEntity();
129   
130   //! sends a void parameter, that is null text
131   Standard_EXPORT void SendVoid();
132   
133   //! sends an Integer parameter
134   Standard_EXPORT void Send (const Standard_Integer val);
135   
136   //! sends a Boolean parameter as an Integer value 0(False)/1(True)
137   Standard_EXPORT void SendBoolean (const Standard_Boolean val);
138   
139   //! sends a Real parameter. Works with FloatWriter
140   Standard_EXPORT void Send (const Standard_Real val);
141   
142   //! sends a Text parameter under Hollerith form
143   Standard_EXPORT void Send (const Handle(TCollection_HAsciiString)& val);
144   
145   //! sends a Reference to an Entity (if its Number is N, its
146   //! pointer is 2*N-1)
147   //! If <val> is Null, "0" will be sent
148   //! If <negative> is True, "Pointer" is sent as negative
149   Standard_EXPORT void Send (const Handle(IGESData_IGESEntity)& val, const Standard_Boolean negative = Standard_False);
150
151   //! Helper method to avoid ambiguity of calls to above methods Send() for
152   //! classes derived from IGESData_IGESEntity, for VC++ 10 and 11 compillers
153   template <class T> 
154   void Send (const Handle(T)& val, Standard_Boolean negative = Standard_False, 
155              typename opencascade::std::enable_if<opencascade::std::is_base_of<IGESData_IGESEntity, T>::value>::type * = 0)
156   { 
157     Send ((const Handle(IGESData_IGESEntity)&)val, negative);
158   }
159   
160   //! sends a parameter under its exact form given as a string
161   Standard_EXPORT void SendString (const Handle(TCollection_HAsciiString)& val);
162   
163   //! Sends a XY, interpreted as a couple of 2 Reals (X & Y)
164   Standard_EXPORT void Send (const gp_XY& val);
165   
166   //! Sends a XYZ, interpreted as a couple of 2 Reals (X , Y & Z)
167   Standard_EXPORT void Send (const gp_XYZ& val);
168   
169   //! Returns the list of strings for a section given its rank
170   //! 1 : Start (if not empty)  2 : Global  3 or 4 : Parameters
171   //! RQ: no string list for Directory section
172   //! An empty section gives a null handle
173   Standard_EXPORT Handle(TColStd_HSequenceOfHAsciiString) SectionStrings (const Standard_Integer numsec) const;
174   
175   //! Writes result on an output defined as an OStream
176   //! resolves stored infos at this time; in particular, numbers of
177   //! lines used to adress P-section from D-section and final totals
178   //! Takes WriteMode into account
179   Standard_EXPORT Standard_Boolean Print (Standard_OStream& S) const;
180
181 private:
182   
183   //! Basic action of adding a string to current parameter list as a
184   //! line; manages size limit (64 or 72 according Sestion G or P)
185   //! <more>, if precised, requires that <more> characters will
186   //! remain free on the current line once this AddString done
187   Standard_EXPORT void AddString (const Handle(TCollection_HAsciiString)& val, const Standard_Integer more = 0);
188   
189   //! Basic action of adding a string to current parameter list as a
190   //! line. Manages size limit (64 or 72 according Sestion G or P)
191   //! <val> is the string and <lnval> its length. If <lnval> is not
192   //! given, it is computed by strlen(val).
193   //! <more>, if precised, requires that <more> characters will
194   //! remain free on the current line once this AddString done
195   Standard_EXPORT void AddString (const Standard_CString val, const Standard_Integer lnval = 0, const Standard_Integer more = 0);
196   
197   //! Adds a string defined as a single character (for instance, the
198   //! parameter separator). Manages size limit
199   //! <more>, if precised, requires that <more> characters will
200   //! remain free on the current line once this AddString done
201   Standard_EXPORT void AddChar (const Standard_Character val, const Standard_Integer more = 0);
202
203
204 private:
205   
206   Handle(IGESData_IGESModel) themodel;
207   Handle(TColStd_HSequenceOfHAsciiString) thestar;
208   Handle(TColStd_HSequenceOfHAsciiString) thehead;
209   Standard_Character thesep;
210   Standard_Character theendm;
211   IGESData_Array1OfDirPart thedirs;
212   TColStd_Array1OfInteger thepnum;
213   Handle(TColStd_HSequenceOfHAsciiString) thepars;
214   Standard_Integer thesect;
215   IGESData_ReadStage thestep;
216   Interface_LineBuffer thecurr;
217   Standard_Integer themodew;
218   Interface_FloatWriter thefloatw;
219 };
220
221 #endif // _IGESData_IGESWriter_HeaderFile