Skip to content

Commit 46739c9

Browse files
author
Nicholas Reed
committed
Add strict flag to STEPread functions; affects handling of missing attributes. SCL git de3495d and 373d415.
1 parent aa5db69 commit 46739c9

File tree

9 files changed

+60
-20
lines changed

9 files changed

+60
-20
lines changed

src/cleditor/STEPfile.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Severity STEPfile::ReadHeader( istream & in ) {
169169
fileid = HeaderId( const_cast<char *>( keywd.c_str() ) );
170170

171171
//read the values from the istream
172-
objsev = obj->STEPread( fileid, 0, ( InstMgr * )0, in );
172+
objsev = obj->STEPread( fileid, 0, ( InstMgr * )0, in, NULL, true, _strict );
173173
if( !cmtStr.empty() ) {
174174
obj->AddP21Comment( cmtStr );
175175
}
@@ -1200,7 +1200,7 @@ SDAI_Application_instance * STEPfile::ReadInstance( istream & in, ostream & out,
12001200
if( c == '(' ) {
12011201
// TODO
12021202
sev = obj->STEPread( fileid, idIncrNum, &instances(), in, currSch.c_str(),
1203-
useTechCor );
1203+
useTechCor, _strict );
12041204

12051205
ReadTokenSeparator( in, &cmtStr );
12061206

@@ -1247,7 +1247,7 @@ SDAI_Application_instance * STEPfile::ReadInstance( istream & in, ostream & out,
12471247
// (WORKING_SESSION included)
12481248

12491249
sev = obj->STEPread( fileid, idIncrNum, &instances(), in, currSch.c_str(),
1250-
useTechCor );
1250+
useTechCor, _strict );
12511251

12521252
ReadTokenSeparator( in, &cmtStr );
12531253

src/cleditor/STEPfile.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class STEPfile {
7777

7878
int _maxErrorCount;
7979

80+
bool _strict; ///< If false, "missing and required" attributes are replaced with a generic value when file is read
81+
8082
protected:
8183

8284
//file type information
@@ -156,7 +158,7 @@ class STEPfile {
156158
void Renumber();
157159

158160
//constructors
159-
STEPfile( Registry & r, InstMgr & i, const std::string filename = "" );
161+
STEPfile( Registry & r, InstMgr & i, const std::string filename = "", bool strict = true );
160162
virtual ~STEPfile();
161163

162164
protected:

src/cleditor/STEPfile.inline.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ extern void HeaderSchemaInit( Registry & reg );
2323

2424
//constructor & destructor
2525

26-
STEPfile::STEPfile( Registry & r, InstMgr & i, const std::string filename ) :
27-
_reg( r ), _instances( i ),
28-
_headerId( 0 ), _maxErrorCount( 5000 ),
29-
_fileName( "" ), _entsNotCreated( 0 ), _entsInvalid( 0 ),
30-
_entsIncomplete( 0 ), _entsWarning( 0 ),
31-
_errorCount( 0 ), _warningCount( 0 ),
32-
_fileIdIncr( 0 )
26+
STEPfile::STEPfile( Registry & r, InstMgr & i, const std::string filename, bool strict ) :
27+
_instances( i ), _reg( r ), _fileIdIncr( 0 ), _headerId( 0 ),
28+
_entsNotCreated( 0 ), _entsInvalid( 0 ), _entsIncomplete( 0 ),
29+
_entsWarning( 0 ), _errorCount( 0 ), _warningCount( 0 ),
30+
_maxErrorCount( 5000 ), _strict( strict )
3331
{
3432
SetFileType( VERSION_CURRENT );
3533
SetFileIdIncrement();

src/clstepcore/STEPattribute.cc

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Severity STEPattribute::StrToVal( const char * s, InstMgr * instances, int addFi
195195
** value <= SEVERITY_INPUT_ERROR is fatal read error
196196
******************************************************************/
197197
Severity STEPattribute::STEPread( istream & in, InstMgr * instances, int addFileId,
198-
const char * currSch ) {
198+
const char * currSch, bool strict ) {
199199

200200
// The attribute has been redefined by the attribute pointed
201201
// to by _redefAttr so write the redefined value.
@@ -239,6 +239,47 @@ Severity STEPattribute::STEPread( istream & in, InstMgr * instances, int addFile
239239
}
240240
if( Nullable() ) {
241241
_error.severity( SEVERITY_NULL );
242+
} else if ( !strict ) {
243+
std::string fillerValue;
244+
// we aren't in strict mode, so find out the type of the missing attribute and insert a suitable value.
245+
ErrorDescriptor err; //this will be discarded
246+
switch( attrBaseType ) {
247+
case INTEGER_TYPE: {
248+
fillerValue = "'0',";
249+
ReadInteger( *( ptr.i ), fillerValue.c_str(), &err, ",)" );
250+
break;
251+
}
252+
case REAL_TYPE: {
253+
fillerValue = "'0.0',";
254+
ReadReal( *( ptr.r ), fillerValue.c_str(), &err, ",)" );
255+
break;
256+
}
257+
case NUMBER_TYPE: {
258+
fillerValue = "'0',";
259+
ReadNumber( *( ptr.r ), fillerValue.c_str(), &err, ",)" );
260+
break;
261+
}
262+
case STRING_TYPE: {
263+
fillerValue = "'',";
264+
*(ptr.S) = "''";
265+
break;
266+
}
267+
default: { //do not know what a good value would be for other types
268+
_error.severity( SEVERITY_INCOMPLETE );
269+
_error.AppendToDetailMsg( " missing and required\n" );
270+
return _error.severity();
271+
}
272+
}
273+
if( err.severity() <= SEVERITY_INCOMPLETE ) {
274+
_error.severity( SEVERITY_BUG );
275+
_error.AppendToDetailMsg( " Error in STEPattribute::STEPread()\n" );
276+
return _error.severity();
277+
}
278+
//create a warning. SEVERITY_WARNING makes more sense to me, but is considered more severe than SEVERITY_INCOMPLETE
279+
_error.severity( SEVERITY_USERMSG );
280+
_error.AppendToDetailMsg( " missing and required. For compatibility, replacing with " );
281+
_error.AppendToDetailMsg( fillerValue.substr( 0, fillerValue.length()-1 ) );
282+
_error.AppendToDetailMsg( ".\n" );
242283
} else {
243284
_error.severity( SEVERITY_INCOMPLETE );
244285
_error.AppendToDetailMsg( " missing and required\n" );

src/clstepcore/STEPattribute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class STEPattribute {
128128
Severity StrToVal( const char * s, InstMgr * instances = 0,
129129
int addFileId = 0 );
130130
Severity STEPread( istream & in = cin, InstMgr * instances = 0,
131-
int addFileId = 0, const char * = NULL );
131+
int addFileId = 0, const char * = NULL, bool strict = true );
132132

133133
const char * asStr( std::string &, const char * = 0 ) const;
134134
// return the attr value as a string

src/clstepcore/STEPcomplex.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,8 @@ STEPcomplex::AppendEntity( STEPcomplex * stepc ) {
278278
}
279279

280280
// READ
281-
Severity
282-
STEPcomplex::STEPread( int id, int addFileId, class InstMgr * instance_set,
283-
istream & in, const char * currSch, bool useTechCor ) {
281+
Severity STEPcomplex::STEPread( int id, int addFileId, class InstMgr * instance_set,
282+
istream & in, const char * currSch, bool /*useTechCor*/, bool /*strict*/ ) {
284283
char c;
285284
std::string typeNm;
286285
STEPcomplex * stepc = 0;

src/clstepcore/STEPcomplex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class STEPcomplex : public SDAI_Application_instance {
3434
virtual Severity STEPread( int id, int addFileId,
3535
class InstMgr * instance_set,
3636
istream & in = cin, const char * currSch = NULL,
37-
bool useTechCor = true );
37+
bool useTechCor = true, bool strict = true );
3838

3939
virtual void STEPread_error( char c, int index, istream & in );
4040

src/clstepcore/sdaiApplication_instance.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ void SDAI_Application_instance::STEPread_error( char c, int i, istream & in ) {
505505

506506
Severity SDAI_Application_instance::STEPread( int id, int idIncr,
507507
InstMgr * instance_set, istream & in,
508-
const char * currSch, bool useTechCor ) {
508+
const char * currSch, bool useTechCor, bool strict ) {
509509
STEPfile_id = id;
510510
char c = '\0';
511511
char errStr[BUFSIZ];
@@ -569,7 +569,7 @@ Severity SDAI_Application_instance::STEPread( int id, int idIncr,
569569
// aren't written or read => there won't be a delimiter either
570570
// i++;
571571
} else {
572-
attributes[i].STEPread( in, instance_set, idIncr, currSch );
572+
attributes[i].STEPread( in, instance_set, idIncr, currSch, strict );
573573
in >> c; // read the , or ) following the attr read
574574

575575
severe = attributes[i].Error().severity();

src/clstepcore/sdaiApplication_instance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class SDAI_Application_instance : public SDAI_DAObject_SDAI {
9595
virtual Severity STEPread( int id, int addFileId,
9696
class InstMgr * instance_set,
9797
istream & in = cin, const char * currSch = NULL,
98-
bool useTechCor = true );
98+
bool useTechCor = true, bool strict = true );
9999
virtual void STEPread_error( char c, int index, istream & in );
100100

101101
// WRITE

0 commit comments

Comments
 (0)