|
| 1 | + |
| 2 | +extern void SchemaInit( class Registry & ); |
| 3 | +#include "scl_version_string.h" |
| 4 | +#include <STEPfile.h> |
| 5 | +#include <sdai.h> |
| 6 | +#include <STEPattribute.h> |
| 7 | +#include <ExpDict.h> |
| 8 | +#include <Registry.h> |
| 9 | +#include <errordesc.h> |
| 10 | +#include <algorithm> |
| 11 | +#include <string> |
| 12 | +#include <unistd.h> |
| 13 | + |
| 14 | +#include "SdaiTEST_ARRAY_BOUNDS_EXPR.h" |
| 15 | + |
| 16 | +int main( int argc, char * argv[] ) { |
| 17 | + |
| 18 | + if ( argc != 2 ) { |
| 19 | + cerr << "Wrong number of args. Use: " << argv[0] << " file.stp" << endl; |
| 20 | + exit(1); |
| 21 | + } |
| 22 | + |
| 23 | + Registry registry( SchemaInit ); |
| 24 | + InstMgr instance_list; |
| 25 | + STEPfile sfile( registry, instance_list, "", false ); |
| 26 | + |
| 27 | + sfile.ReadExchangeFile( argv[1] ); |
| 28 | + Severity readSev = sfile.Error().severity(); |
| 29 | + if( readSev != SEVERITY_NULL ) { |
| 30 | + sfile.Error().PrintContents(cout); |
| 31 | + abort(); |
| 32 | + } |
| 33 | + |
| 34 | + // Keeps track of the last processed ent id |
| 35 | + int search_index = 0; |
| 36 | + |
| 37 | + //find structured_mesh, find the array attribute, and check its bounds as much as possible. need an instance to check 100%. |
| 38 | + const EntityDescriptor* ed = registry.FindEntity("Structured_mesh"); |
| 39 | + AttrDescItr aditr( ed->ExplicitAttr() ); |
| 40 | + const AttrDescriptor* attrDesc = aditr.NextAttrDesc(); |
| 41 | + int descAggrCount = 0; |
| 42 | + while( attrDesc != 0 ) { |
| 43 | + if( ( attrDesc->NonRefType() == ARRAY_TYPE ) && ( attrDesc->AggrElemType() == sdaiINTEGER ) ) { |
| 44 | + cout << "Array attribute: " << attrDesc->Name(); |
| 45 | + const AggrTypeDescriptor* atd = (const AggrTypeDescriptor*) attrDesc->DomainType(); |
| 46 | + if( !( atd->Bound1Type() == bound_constant ) || !( atd->Bound2Type() == bound_runtime ) ) { |
| 47 | + cerr << "Invalid bounds. Exiting." << endl; |
| 48 | + abort(); |
| 49 | + } |
| 50 | + cout << " -- bound 1 is a constant (" << atd->Bound1() << "). bound 2 depends upon the instance." << endl; |
| 51 | + descAggrCount++; |
| 52 | + } |
| 53 | + attrDesc = aditr.NextAttrDesc(); |
| 54 | + } |
| 55 | + if( descAggrCount != 1 ) { |
| 56 | + cerr << "Expected 1 aggregate attribute descriptor, found " << descAggrCount <<". Exiting." << endl; |
| 57 | + abort(); |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + // Loop over the instances in the file, check the bound for each |
| 62 | + SdaiStructured_mesh* ent; |
| 63 | + while ( ENTITY_NULL != (ent = (SdaiStructured_mesh*) |
| 64 | + instance_list.GetApplication_instance( "Structured_mesh", search_index ) ) ) { |
| 65 | + SDAI_Integer b2; |
| 66 | + int instAggrCnt = 0; |
| 67 | + IntAggregate* vertex_counts = ent->vertex_counts_(); |
| 68 | + int cnt = ent->AttributeCount(); |
| 69 | + STEPattributeList &sal = ent->attributes; |
| 70 | + int id = ent->StepFileId(); |
| 71 | + |
| 72 | + cout << "Ent #" << id << " - "; |
| 73 | + if( cnt != 3 ) { |
| 74 | + cerr << "Expected 3 attributes, found " << cnt << ". Exiting." << endl; |
| 75 | + abort(); |
| 76 | + } |
| 77 | + if( id > 2 ) { |
| 78 | + cerr << "Expected 2 instances, found " << cnt << ". Exiting." << endl; |
| 79 | + abort(); |
| 80 | + } |
| 81 | + //loop over the attributes |
| 82 | + for( int i = 0; i < cnt; i++ ) { |
| 83 | + if( ( sal[i].aDesc->NonRefType() == ARRAY_TYPE ) && ( sal[i].aDesc->AggrElemType() == sdaiINTEGER ) ) { |
| 84 | + b2 = ( (AggrTypeDescriptor*) sal[i].aDesc->DomainType() )->Bound2Runtime(ent); |
| 85 | + cout << "bound 2: " << b2 << " values: "; |
| 86 | + instAggrCnt++; |
| 87 | + if( ( ( id == 1 ) && ( b2 != 3 ) ) || ( ( id == 2 ) && ( b2 != 5 ) ) ) { |
| 88 | + cerr << "Instance " << id << ": value " << b2 << " is invalid for bound 2."; |
| 89 | + cerr << " Expecting 3 for instance #1 or 5 for #2." << endl; |
| 90 | + abort(); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + int node = 0; |
| 96 | + int aggrValues[2][5] = {{1,2,3,-1,-1},{9,34,0,3,999999}}; |
| 97 | + IntNode* aggrNode = (IntNode*) vertex_counts->GetHead(); |
| 98 | + while( aggrNode != 0 ) { |
| 99 | + if( node >= b2 ) { |
| 100 | + cerr << "Instance " << id << ": Number of values exceeds upper bound. Exiting." << endl; |
| 101 | + abort(); |
| 102 | + } |
| 103 | + cout << aggrNode->value << " "; |
| 104 | + if( aggrValues[id-1][node] != aggrNode->value ) { |
| 105 | + cerr << "Instance " << id << ": aggregate value " << aggrNode->value << " at index " << node << " is incorrect. Exiting." << endl; |
| 106 | + abort(); |
| 107 | + } |
| 108 | + aggrNode = (IntNode*) aggrNode->NextNode(); |
| 109 | + node++; |
| 110 | + } |
| 111 | + cout << endl; |
| 112 | + |
| 113 | + if( instAggrCnt != 1 ) { |
| 114 | + cerr << "Expected 1 aggregate attribute in this instance, found " << instAggrCnt << ". Exiting." << endl; |
| 115 | + abort(); |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + MgrNode* mnode = instance_list.FindFileId( id ); |
| 120 | + search_index = instance_list.GetIndex( mnode ) + 1; |
| 121 | + } |
| 122 | +} |
0 commit comments