0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IFSelect / IFSelect_SessionFile.hxx
CommitLineData
42cf5bc1 1// Created on: 1993-11-03
2// Created by: Christian CAILLET
3// Copyright (c) 1993-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 _IFSelect_SessionFile_HeaderFile
18#define _IFSelect_SessionFile_HeaderFile
19
997e128f 20#include <NCollection_DataMap.hxx>
42cf5bc1 21#include <Standard.hxx>
22#include <Standard_DefineAlloc.hxx>
23#include <Standard_Handle.hxx>
24
42cf5bc1 25#include <TColStd_HArray1OfInteger.hxx>
26#include <TColStd_SequenceOfAsciiString.hxx>
27#include <Standard_Integer.hxx>
28#include <TCollection_AsciiString.hxx>
29#include <Standard_CString.hxx>
997e128f 30
42cf5bc1 31class IFSelect_WorkSession;
42cf5bc1 32class Standard_Transient;
33
42cf5bc1 34//! A SessionFile is intended to manage access between a
35//! WorkSession and an Ascii Form, to be considered as a Dump.
36//! It allows to write the File from the WorkSession, and later
37//! read the File to the WorkSession, by keeping required
38//! descriptions (such as dependances).
39//!
40//! The produced File is under an Ascii Form, then it may be
41//! easily consulted.
42//! It is possible to cumulate reading of several Files. But in
43//! case of Names conflict, the newer Names are forgottens.
44//!
0177fe26 45//! The Dump supports the description of XSTEP functionalities
42cf5bc1 46//! (Sharing an Interface File, with Selections, Dispatches,
47//! Modifiers ...) but does not refer to the Interface File
48//! which is currently loaded.
49//!
50//! SessionFile works with a library of SessionDumper type objects
51//!
52//! The File is Produced as follows :
21c7c457 53//! SessionFile produces all general Information (such as Int and
42cf5bc1 54//! Text Parameters, Types and Inputs of Selections, Dispatches,
55//! Modifiers ...) and calls the SessionDumpers to produce all
56//! the particular Data : creation arguments, parameters to be set
57//! It is Read in the same terms :
21c7c457 58//! SessionFile reads and interprets all general Information,
42cf5bc1 59//! and calls the SessionDumpers to recognize Types and for a
60//! recognized Type create the corresponding Object with its
61//! particular parameters as they were written.
62//! The best way to work is to have one SessionDumper for each
63//! consistent set of classes (e.g. a package).
64class IFSelect_SessionFile
65{
66public:
67
68 DEFINE_STANDARD_ALLOC
69
42cf5bc1 70 //! Creates a SessionFile, ready to read Files in order to load
71 //! them into a given WorkSession.
72 //! The following Read Operations must then be called.
73 //! It is also possible to perform a Write, which produces a
74 //! complete File of all the content of the WorkSession.
75 Standard_EXPORT IFSelect_SessionFile(const Handle(IFSelect_WorkSession)& WS);
76
77 //! Creates a SessionFile which Writes the content of a WorkSession
78 //! to a File (directly calls Write)
79 //! Then, IsDone aknowledges on the result of the Operation.
80 //! But such a SessionFile may not Read a File to a WorkSession.
81 Standard_EXPORT IFSelect_SessionFile(const Handle(IFSelect_WorkSession)& WS, const Standard_CString filename);
82
83 //! Clears the lines recorded whatever for writing or for reading
84 Standard_EXPORT void ClearLines();
85
86 //! Returns the count of recorded lines
87 Standard_EXPORT Standard_Integer NbLines() const;
88
89 //! Returns a line given its rank in the list of recorded lines
90 Standard_EXPORT const TCollection_AsciiString& Line (const Standard_Integer num) const;
91
92 //! Adds a line to the list of recorded lines
93 Standard_EXPORT void AddLine (const Standard_CString line);
94
95 //! Removes the last line. Can be called recursively.
96 //! Does nothing if the list is empty
97 Standard_EXPORT void RemoveLastLine();
98
99 //! Writes the recorded lines to a file named <name> then clears
100 //! the list of lines.
101 //! Returns False (with no clearing) if the file could not be
102 //! created
103 Standard_EXPORT Standard_Boolean WriteFile (const Standard_CString name);
104
105 //! Reads the recorded lines from a file named <name>, after
106 //! having cleared the list (stops if RecognizeFile fails)
107 //! Returns False (with no clearing) if the file could not be read
108 Standard_EXPORT Standard_Boolean ReadFile (const Standard_CString name);
109
110 //! Recognizes the header line. returns True if OK, False else
111 Standard_EXPORT Standard_Boolean RecognizeFile (const Standard_CString headerline);
112
113 //! Performs a Write Operation from a WorkSession to a File
114 //! i.e. calls WriteSession then WriteEnd, and WriteFile
115 //! Returned Value is : 0 for OK, -1 File could not be created,
116 //! >0 Error during Write (see WriteSession)
117 //! IsDone can be called too (will return True for OK)
118 Standard_EXPORT Standard_Integer Write (const Standard_CString filename);
119
120 //! Performs a Read Operation from a file to a WorkSession
121 //! i.e. calls ReadFile, then ReadSession and ReadEnd
122 //! Returned Value is : 0 for OK, -1 File could not be opened,
123 //! >0 Error during Read (see WriteSession)
124 //! IsDone can be called too (will return True for OK)
125 Standard_EXPORT Standard_Integer Read (const Standard_CString filename);
126
127 //! Prepares the Write operation from a WorkSession (IFSelect) to
128 //! a File, i.e. fills the list of lines (the file itself remains
129 //! to be written; or NbLines/Line may be called)
130 //! Important Remark : this excludes the reading of the last line,
131 //! which is performed by WriteEnd
132 //! Returns 0 if OK, status > 0 in case of error
133 Standard_EXPORT Standard_Integer WriteSession();
134
135 //! Writes the trailing line. It is separate from WriteSession,
136 //! in order to allow to redefine WriteSession without touching
137 //! WriteEnd (WriteSession defines the body of the file)
138 //! WriteEnd fills the list of lines. Returns a status of error,
139 //! 0 if OK, >0 else
140 Standard_EXPORT Standard_Integer WriteEnd();
141
142 //! Writes a line to the File. If <follow> is given, it is added
143 //! at the following of the line. '\n' must be added for the end.
144 Standard_EXPORT void WriteLine (const Standard_CString line, const Standard_Character follow = 0);
145
146 //! Writes the Parameters own to each type of Item. Uses the
147 //! Library of SessionDumpers
148 //! Returns True if Done, False if <item> could not be treated
149 //! (hence it remains written with no Own Parameter)
150 Standard_EXPORT Standard_Boolean WriteOwn (const Handle(Standard_Transient)& item);
151
152 //! Performs a Read Operation from a File to a WorkSession, i.e.
153 //! reads the list of line (which must have already been loaded,
154 //! by ReadFile or by calls to AddLine)
155 //! Important Remark : this excludes the reading of the last line,
156 //! which is performed by ReadEnd
157 //! Returns 0 for OK, >0 status for Read Error (not a suitable
158 //! File, or WorkSession given as Immutable at Creation Time)
159 //! IsDone can be called too (will return True for OK)
160 Standard_EXPORT Standard_Integer ReadSession();
161
162 //! Reads the end of a file (its last line). Returns 0 if OK,
163 //! status >0 in case of error (not a suitable end line).
164 Standard_EXPORT Standard_Integer ReadEnd();
165
166 //! Reads a Line and splits it into a set of alphanumeric items,
167 //! which can then be queried by NbParams/ParamValue ...
168 Standard_EXPORT Standard_Boolean ReadLine();
169
170 //! Internal routine which processes a line into words
171 //! and prepares its exploration
172 Standard_EXPORT void SplitLine (const Standard_CString line);
173
174 //! Tries to Read an Item, by calling the Library of Dumpers
175 //! Sets the list of parameters of the line to be read from the
176 //! first own one
177 Standard_EXPORT Standard_Boolean ReadOwn (Handle(Standard_Transient)& item);
178
179 //! Adds an Item to the WorkSession, taken as Name the first
180 //! item of the read Line. If this Name is not a Name but a Number
181 //! or if this Name is already recorded in the WorkSession, it
182 //! adds the Item but with no Name. Then the Name is recorded
183 //! in order to be used by the method ItemValue
184 //! <active> commands to make <item> active or not in the session
185 Standard_EXPORT void AddItem (const Handle(Standard_Transient)& item, const Standard_Boolean active = Standard_True);
0177fe26 186
187 //! Returns True if the last Read or Write operation has been correctly performed.
188 //! Else returns False.
42cf5bc1 189 Standard_EXPORT Standard_Boolean IsDone() const;
0177fe26 190
42cf5bc1 191 //! Returns the WorkSession on which a SessionFile works.
192 //! Remark that it is returned as Immutable.
193 Standard_EXPORT Handle(IFSelect_WorkSession) WorkSession() const;
0177fe26 194
42cf5bc1 195 //! At beginning of writing an Item, writes its basics :
196 //! - either its name in the session if it has one
0177fe26 197 //! - or its relative number of item in the file, else (preceded by a '_')
42cf5bc1 198 //! - then, its Dynamic Type (in the sense of cdl : pk_class)
199 //! This basic description can be followed by the parameters
200 //! which are used in the definition of the item.
201 Standard_EXPORT void NewItem (const Standard_Integer ident, const Handle(Standard_Transient)& par);
0177fe26 202
42cf5bc1 203 //! Sets Parameters to be sent as Own if <mode> is True (their
0177fe26 204 //! Name or Number or Void Mark or Text Value is preceded by a
42cf5bc1 205 //! Column sign ':') else they are sent normally
206 //! Hence, the Own Parameter are clearly identified in the File
207 Standard_EXPORT void SetOwn (const Standard_Boolean mode);
208
209 //! During a Write action, commands to send a Void Parameter
210 //! i.e. a Parameter which is present but undefined
211 //! Its form will be the dollar sign : $
212 Standard_EXPORT void SendVoid();
0177fe26 213
42cf5bc1 214 //! During a Write action, commands to send the identification of
215 //! a Parameter : if it is Null (undefined) it is send as Void ($)
0177fe26 216 //! if it is Named in the WorkSession, its Name is sent preceded
217 //! by ':', else a relative Ident Number is sent preceded by '#'
42cf5bc1 218 //! (relative to the present Write, i.e. starting at one, without
219 //! skip, and counted part from Named Items)
220 Standard_EXPORT void SendItem (const Handle(Standard_Transient)& par);
0177fe26 221
42cf5bc1 222 //! During a Write action, commands to send a Text without
223 //! interpretation. It will be sent as well
224 Standard_EXPORT void SendText (const Standard_CString text);
225
226 //! Sets the rank of Last General Parameter to a new value. It is
227 //! followed by the Fist Own Parameter of the item.
228 //! Used by SessionFile after reading general parameters.
229 Standard_EXPORT void SetLastGeneral (const Standard_Integer lastgen);
0177fe26 230
231 //! During a Read operation, SessionFile processes sequentially the Items to read.
232 //! For each one, it gives access to the list
42cf5bc1 233 //! of its Parameters : they were defined by calls to
234 //! SendVoid/SendParam/SendText during Writing the File.
235 //! NbParams returns the count of Parameters for the line
236 //! currently read.
237 Standard_EXPORT Standard_Integer NbParams() const;
0177fe26 238
42cf5bc1 239 //! Returns True if a Parameter, given its rank in the Own List
240 //! (see NbOwnParams), is Void. Returns also True if <num> is
241 //! out of range (undefined parameters)
242 Standard_EXPORT Standard_Boolean IsVoid (const Standard_Integer num) const;
243
244 //! Returns True if a Parameter, in the Own List (see NbOwnParams)
245 //! is a Text (between "..."). Else it is an Item (Parameter,
246 //! Selection, Dispatch ...), which can be Void.
247 Standard_EXPORT Standard_Boolean IsText (const Standard_Integer num) const;
248
249 //! Returns a Parameter (alphanumeric item of a line) as it
250 //! has been read
251 Standard_EXPORT const TCollection_AsciiString& ParamValue (const Standard_Integer num) const;
252
253 //! Returns the content of a Text Parameter (without the quotes).
254 //! Returns an empty string if the Parameter is not a Text.
255 Standard_EXPORT TCollection_AsciiString TextValue (const Standard_Integer num) const;
256
257 //! Returns a Parameter as an Item. Returns a Null Handle if the
258 //! Parameter is a Text, or if it is defined as Void
259 Standard_EXPORT Handle(Standard_Transient) ItemValue (const Standard_Integer num) const;
260
261 //! Specific Destructor (closes the File if not yet done)
262 Standard_EXPORT void Destroy();
263~IFSelect_SessionFile()
264{
265 Destroy();
266}
267
42cf5bc1 268protected:
269
42cf5bc1 270 Handle(IFSelect_WorkSession) thesess;
271 Handle(TColStd_HArray1OfInteger) thenums;
997e128f 272 NCollection_DataMap<TCollection_AsciiString, Standard_Integer> thenames;
42cf5bc1 273 Standard_Integer thenl;
274 TColStd_SequenceOfAsciiString theline;
275
42cf5bc1 276private:
277
42cf5bc1 278 Standard_Boolean themode;
279 TColStd_SequenceOfAsciiString thelist;
280 TCollection_AsciiString thebuff;
281 Standard_Integer thelastgen;
282 Standard_Boolean thedone;
283 Standard_Boolean theownflag;
284 Standard_Integer thenewnum;
285
42cf5bc1 286};
287
42cf5bc1 288#endif // _IFSelect_SessionFile_HeaderFile