-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathap242_styled_item.cc
More file actions
137 lines (112 loc) · 4.58 KB
/
Copy pathap242_styled_item.cc
File metadata and controls
137 lines (112 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/** \file ap242_styled_item.cc
** Test styled_item entity from AP242 schema
** This test verifies that the generated C++ code from the ap242treat schema
** can correctly handle styled_item entities, particularly the TREAT expression
** in the WR3 WHERE rule that was problematic in the original schema.
**
** The test:
** 1. Loads an AP242 STEP file containing styled_item instances
** 2. Verifies that styled_item entities are correctly parsed
** 3. Tests both simple cases (geometric_representation_item) and complex cases
** (set_representation_item that exercises the TREAT expression)
** 4. Validates the entity relationships and attributes
*/
#include "config.h"
#include "cleditor/STEPfile.h"
#include "clstepcore/sdai.h"
#include "clstepcore/STEPattribute.h"
#include "clstepcore/ExpDict.h"
#include "clstepcore/Registry.h"
#include "clutils/errordesc.h"
#include <iostream>
#include <string>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "schema.h"
using namespace std;
int main( int argc, char * argv[] ) {
if( argc != 2 ) {
cerr << "Usage: " << argv[0] << " <ap242_step_file>" << endl;
cerr << " Tests that AP242 styled_item entities are correctly handled" << endl;
return EXIT_FAILURE;
}
// Initialize the AP242 schema
Registry registry( SchemaInit );
InstMgr instance_list;
STEPfile sfile( registry, instance_list, "", false );
cout << "AP242 styled_item Test" << endl;
cout << "======================" << endl;
cout << "Reading STEP file: " << argv[1] << endl << endl;
// Read the STEP file
sfile.ReadExchangeFile( argv[1] );
// Check for errors
if( sfile.Error().severity() <= SEVERITY_INCOMPLETE ) {
cerr << "ERROR: Failed to read STEP file" << endl;
sfile.Error().PrintContents( cerr );
return EXIT_FAILURE;
}
cout << "File read successfully!" << endl;
cout << "Total instances: " << instance_list.InstanceCount() << endl << endl;
// Find styled_item entities
const EntityDescriptor * styled_item_desc = registry.FindEntity( "styled_item" );
if( !styled_item_desc ) {
cerr << "ERROR: styled_item entity not found in schema" << endl;
return EXIT_FAILURE;
}
cout << "Looking for styled_item entities..." << endl;
int styled_item_count = 0;
int total_entities = 0;
// Iterate through all instances
for( int i = 0; i < instance_list.InstanceCount(); i++ ) {
SDAI_Application_instance * inst = instance_list.GetApplication_instance( i );
if( !inst ) {
continue;
}
const EntityDescriptor * ed = inst->eDesc;
if( !ed ) {
continue;
}
total_entities++;
// Check if this is a styled_item or subtype
if( ed->IsA( styled_item_desc ) ) {
styled_item_count++;
cout << endl << "Found styled_item #" << styled_item_count << ":" << endl;
cout << " Entity type: " << ed->Name() << endl;
cout << " Instance ID: " << inst->StepFileId() << endl;
// Iterate through attributes to find name and item
STEPattributeList attrlist = inst->attributes;
for( int j = 0; j < attrlist.list_length(); j++ ) {
const char * attr_name = attrlist[j].Name();
if( attr_name ) {
cout << " Attribute[" << j << "]: " << attr_name;
// Print attribute value if available
if( attrlist[j].IsDerived() ) {
cout << " (derived)" << endl;
} else {
string val = attrlist[j].asStr();
if( !val.empty() ) {
cout << " = " << val << endl;
} else {
cout << endl;
}
}
}
}
}
}
cout << endl << "Total entities parsed: " << total_entities << endl;
cout << endl << "Test Results:" << endl;
cout << "=============" << endl;
cout << "Total styled_item instances found: " << styled_item_count << endl;
cout << endl;
// Validate results
if( styled_item_count == 0 ) {
cerr << "ERROR: No styled_item instances found!" << endl;
return EXIT_FAILURE;
}
cout << "SUCCESS: AP242 styled_item test passed!" << endl;
cout << "The generated C++ code correctly handles styled_item entities," << endl;
cout << "including the TREAT expression in the WR3 WHERE rule." << endl;
return EXIT_SUCCESS;
}