1 #ifndef _STEPFILE_H
2 #define _STEPFILE_H
3 
4 /*
5 * NIST STEP Core Class Library
6 * cleditor/STEPfile.h
7 * April 1997
8 * Peter Carr
9 * K. C. Morris
10 * David Sauder
11 
12 * Development of this software was funded by the United States Government,
13 * and is not subject to copyright.
14 */
15 
16 #include <sc_export.h>
17 #include <string>
18 #include <instmgr.h>
19 #include <Registry.h>
20 #include <fstream>
21 #include <dirobj.h>
22 #include <errordesc.h>
23 #include <time.h>
24 
25 #include <read_func.h>
26 
27 //error reporting level
28 #define READ_COMPLETE    10
29 #define READ_INCOMPLETE  20
30 
31 enum  FileTypeCode {
32     VERSION_OLD     = -1,
33     VERSION_UNKNOWN =  0,
34     VERSION_CURRENT =  1,
35     WORKING_SESSION =  2
36 };
37 
38 class SC_EDITOR_EXPORT STEPfile {
39     protected:
40         //data members
41 
42         InstMgr & _instances;
43         Registry & _reg;
44 
instances()45         InstMgr & instances()  {
46             return _instances;
47         }
reg()48         Registry & reg() {
49             return _reg;
50         }
51         int _fileIdIncr;   ///< Increment value to be added to FileId Numbers on input
52 
53 //header information
54         InstMgr * _headerInstances;
55         Registry * _headerRegistry;
56 
57         int _headerId;     ///< STEPfile_id given to SDAI_Application_instance from header section
58 
59 //file information
60         DirObj * _currentDir;
61         std::string _fileName;
62 
63         //the following are used to compute read/write progress
64         std::ifstream::pos_type _iFileSize; ///< input file size
65         std::ifstream::pos_type _iFileCurrentPosition; ///< input file position (from ifstream::tellg())
66         bool _iFileStage1Done; ///< set immediately before ReadData1() returns
67         int _oFileInstsWritten; ///< number of instances that have been written
68 
69 //error information
70         ErrorDescriptor _error;
71 
72         // new errors
73         int _entsNotCreated; ///< num entities not created in first pass
74         int _entsInvalid;    ///< num entities that had invalid attr values
75         int _entsIncomplete; /**< num entities that had missing attr values
76                                   (includes entities that had invalid values
77                                   for required attrs)*/
78         int _entsWarning;    /**< num entities that may have had problems
79                                   with attrs - reported as an attr user msg */
80 
81         // old errors
82         int _errorCount;
83         int _warningCount;
84 
85         int _maxErrorCount;
86 
87         bool _strict;       ///< If false, "missing and required" attributes are replaced with a generic value when file is read
88         bool _verbose;      ///< Defaults to false; if true, info is always printed to stdout.
89 
90     protected:
91 
92 //file type information
93         FileTypeCode _fileType;
94         char ENTITY_NAME_DELIM;
95         std::string FILE_DELIM;
96         std::string END_FILE_DELIM;
97 
98 //public member functions
99     public:
100 
101 //public access to member variables
102 //header information
HeaderInstances()103         InstMgr * HeaderInstances() {
104             return _headerInstances;
105         }
HeaderRegistry()106         const Registry * HeaderRegistry() {
107             return _headerRegistry;
108         }
109 // to create header instances
110         SDAI_Application_instance * HeaderDefaultFileName();
111         SDAI_Application_instance * HeaderDefaultFileDescription();
112         SDAI_Application_instance * HeaderDefaultFileSchema();
113 
114 //file information
FileName()115         std::string FileName() const {
116             return _fileName;
117         }
118         std::string SetFileName( const std::string name = "" );
119         std::string TruncFileName( const std::string name ) const;
120         float GetReadProgress() const;
121         float GetWriteProgress() const;
122 
123 //error information
Error()124         ErrorDescriptor & Error() { /* const */
125             return _error;
126         }
ErrorCount()127         int ErrorCount() const  {
128             return _errorCount;
129         }
WarningCount()130         int WarningCount() const {
131             return _warningCount;
132         }
133         Severity AppendEntityErrorMsg( ErrorDescriptor * e );
134 
135 //version information
FileType()136         FileTypeCode FileType() const   {
137             return _fileType;
138         }
FileType(FileTypeCode ft)139         void FileType( FileTypeCode ft ) {
140             _fileType = ft;
141         }
142         int SetFileType( FileTypeCode ft = VERSION_CURRENT );
143 
144 //Reading and Writing
145         Severity ReadExchangeFile( const std::string filename = "", bool useTechCor = 1 );
146         Severity AppendExchangeFile( const std::string filename = "", bool useTechCor = 1 );
147 
148         Severity ReadWorkingFile( const std::string filename = "", bool useTechCor = 1 );
149         Severity AppendWorkingFile( const std::string filename = "", bool useTechCor = 1 );
150 
151         Severity AppendFile( istream * in, bool useTechCor = 1 ) ;
152 
153         Severity WriteExchangeFile( ostream & out, int validate = 1,
154                                     int clearError = 1, int writeComments = 1 );
155         Severity WriteExchangeFile( const std::string filename = "", int validate = 1,
156                                     int clearError = 1, int writeComments = 1 );
157         Severity WriteValuePairsFile( ostream & out, int validate = 1,
158                                       int clearError = 1,
159                                       int writeComments = 1, int mixedCase = 1 );
160 
161         Severity WriteWorkingFile( ostream & out, int clearError = 1,
162                                    int writeComments = 1 );
163         Severity WriteWorkingFile( const std::string filename = "", int clearError = 1,
164                                    int writeComments = 1 );
165 
166         stateEnum EntityWfState( char c );
167 
168         void Renumber();
169 
170 //constructors
171         STEPfile( Registry & r, InstMgr & i, const std::string filename = "", bool strict = true );
172         virtual ~STEPfile();
173 
174     protected:
175 //member functions
176         std::string schemaName(); /**< Returns and copies out schema name from header instances.
177                                              Called by ReadExchangeFile */
178         istream * OpenInputFile( const std::string filename = "" );
179         void CloseInputFile( istream * in );
180 
181         Severity ReadHeader( istream & in );
182 
183         Severity HeaderVerifyInstances( InstMgr * im );
184         void HeaderMergeInstances( InstMgr * im );
185 
186         int HeaderId( int increment = 1 );
187         int HeaderId( const char * nm = "\0" );
188 
189         int ReadData1( istream & in ); /**< First pass, to create instances */
190         int ReadData2( istream & in, bool useTechCor = true ); /**< Second pass, to read instances */
191 
192 // obsolete
193         int ReadWorkingData1( istream & in );
194         int ReadWorkingData2( istream & in, bool useTechCor = true );
195 
196         void ReadRestOfFile( istream & in );
197 
198         /// create instance - used by ReadData1()
199         SDAI_Application_instance  *  CreateInstance( istream & in, ostream & out );
200         /// create complex instance - used by CreateInstance()
201         SDAI_Application_instance  * CreateSubSuperInstance( istream & in, int fileid,
202                 ErrorDescriptor & );
203 
204         // read the instance - used by ReadData2()
205         SDAI_Application_instance  * ReadInstance( istream & in, ostream & out,
206                 std::string & cmtStr, bool useTechCor = true );
207 
208         ///  reading scopes are still incomplete, CreateScopeInstances and ReadScopeInstances are stubs
209         Severity CreateScopeInstances( istream & in, SDAI_Application_instance_ptr  ** scopelist );
210         Severity ReadScopeInstances( istream & in );
211 //    Severity ReadSubSuperInstance(istream& in);
212 
213         int FindDataSection( istream & in );
214         int FindHeaderSection( istream & in );
215 
216 // writing working session files
217         void WriteWorkingData( ostream & out, int writeComments = 1 );
218 
219 //called by WriteExchangeFile
220         ofstream * OpenOutputFile( const std::string filename = "" );
221         void CloseOutputFile( ostream * out );
222 
223         void WriteHeader( ostream & out );
224         void WriteHeaderInstance( SDAI_Application_instance * obj, ostream & out );
225         void WriteHeaderInstanceFileName( ostream & out );
226         void WriteHeaderInstanceFileDescription( ostream & out );
227         void WriteHeaderInstanceFileSchema( ostream & out );
228 
229         void WriteData( ostream & out, int writeComments = 1 );
230         void WriteValuePairsData( ostream & out, int writeComments = 1,
231                                   int mixedCase = 1 );
232 
233         int IncrementFileId( int fileid );
FileIdIncr()234         int FileIdIncr() {
235             return _fileIdIncr;
236         }
237         void SetFileIdIncrement();
238         void MakeBackupFile();
239 
240 //    void ReadWhiteSpace(istream& in);
241 };
242 
243 //inline functions
244 
245 #endif  /*  _STEPFILE_H  */
246