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