Getting started with parsing stp files

1,131 views
Skip to first unread message

Victor Haefner

unread,
Jun 10, 2013, 3:01:12 PM6/10/13
to scl...@googlegroups.com
Hi all,

I have some troubles to get started. I would like to write an opengl viewer for cad data and hope that step is a good bet.
When parsing a stp file as described in the getting started example, I can not get the values from the attributes.
I tried the following:

...
    cout << "\nParse STEP File";
    int N = instance_list.InstanceCount();
    string* value = new string();
    for( int i = 0; i < N; i++ ) {
        SDAI_Application_instance* inst = instance_list.GetSTEPentity(i);
        string name = inst->EntityName();

        cout << "\n" << i << ": " << name << flush;

        for (int j=0; j<inst->AttributeCount(); j++) {
            STEPattribute attr = inst->attributes[j];
            attr.asStr(*value);
            cout << "\n ATT: " << attr.Name() << "  " << *value << flush;
        }
    }
...

value results in a segfault or rubbish.

When parsing the file I use a schema named 'AUTOMOTIVE_DESIGN'
The schema name of the file is AUTOMOTIVE_DESIGN_CC2 { 1 2 10303 214 -1 1 5 4 } (a cube exported from FreeCAD).
The parser says:

HEADER read:
ERROR: instance #8 'MECHANICAL_CONTEXT': Unknown ENTITY type.
        Data lost: ('',#2,'mechanical')

ERROR: instance #350 'PRODUCT_TYPE': Unknown ENTITY type.
        Data lost: ('part',$,(#7))


FIRST PASS complete:  359 instances created.
  2  ERRORS       0  WARNINGS
...

This could be the reason for the corrupted attributes.


I do not understand why it seams to me so difficult to parse stp files.. why are there different schemas?? how do all the CAD authoring tools handle this? If I want to import stp files, do I have to support all schemas? why isn't there one schema to support every possibility for stp files? .. I have quite some trouble to wrap my head around all this because there a many holes I try to fill at once, I am very gratefull for any hints.

Best regards,
Victor

Mark

unread,
Jun 10, 2013, 9:17:52 PM6/10/13
to scl...@googlegroups.com
Hi Victor


On Mon, Jun 10, 2013 at 3:01 PM, Victor Haefner <victor....@gmail.com> wrote:
Hi all,

I have some troubles to get started. I would like to write an opengl viewer for cad data and hope that step is a good bet.

STEP is complex, but I suspect it's nothing in comparison with the complexity of supporting multiple proprietary vendor formats.
 
When parsing a stp file as described in the getting started example, I can not get the values from the attributes.
I tried the following:

...
    cout << "\nParse STEP File";
    int N = instance_list.InstanceCount();
    string* value = new string();
    for( int i = 0; i < N; i++ ) {
        SDAI_Application_instance* inst = instance_list.GetSTEPentity(i);
        string name = inst->EntityName();

        cout << "\n" << i << ": " << name << flush;

        for (int j=0; j<inst->AttributeCount(); j++) {
            STEPattribute attr = inst->attributes[j];
            attr.asStr(*value);
            cout << "\n ATT: " << attr.Name() << "  " << *value << flush;
        }
    }
...

value results in a segfault or rubbish.

Looks right. Could you send me the complete code and a file (or file url)? If your file is large or you can't share it publicly, email me off-list.

When parsing the file I use a schema named 'AUTOMOTIVE_DESIGN'
The schema name of the file is AUTOMOTIVE_DESIGN_CC2 { 1 2 10303 214 -1 1 5 4 } (a cube exported from FreeCAD).

Google makes me think that CC2 is a draft (DIS) of AP214. I'm surprised that OCC is using a schema that old!

The schema in STEPcode is the 3rd edition of AP214.

The parser says:

HEADER read:
ERROR: instance #8 'MECHANICAL_CONTEXT': Unknown ENTITY type.
        Data lost: ('',#2,'mechanical')

ERROR: instance #350 'PRODUCT_TYPE': Unknown ENTITY type.
        Data lost: ('part',$,(#7))


FIRST PASS complete:  359 instances created.
  2  ERRORS       0  WARNINGS
...

This could be the reason for the corrupted attributes.

That is a possibility; you're lucky that only two weren't recognized.

Did you check whether the problem occurs with those instances?
 


I do not understand why it seams to me so difficult to parse stp files.. why are there different schemas?? how do all the CAD authoring tools handle this? If I want to import stp files, do I have to support all schemas? why isn't there one schema to support every possibility for stp files? .. I have quite some trouble to wrap my head around all this because there a many holes I try to fill at once, I am very gratefull for any hints.

IIRC, the research that culminated in STEP began in the early 80's when IGES was new. STEP is an extremely complex standard, and had to be split up so that progress could be made.

AP203 and AP214 are frequently used for MCAD; the former is simpler.

Aside from those, there are many other schemas for other applications  - EDA, CAM, FEA, etc. Big list: http://en.wikipedia.org/wiki/ISO_10303#Coverage_of_STEP_Application_Protocols_.28AP.29

Regards
Mark

Best regards,
Victor

--
You received this message because you are subscribed to the Google Groups "STEPcode - Developers Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scl-dev+u...@googlegroups.com.
To post to this group, send email to scl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scl-dev/8a7426c4-fc17-42f2-8681-e5a377f97ae0%40googlegroups.com?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Victor Haefner

unread,
Jun 11, 2013, 4:09:00 PM6/11/13
to scl...@googlegroups.com
Hello Mark,

Thank you for your reply, this was realy helpfull :) especially the list of APs. This could be an interesting introduction for newcommers like me when getting started..
The corrupted attributes are for all instances :/

I attached my file, it is exported with the current Ubuntu version of FreeCAD (a simple cube). I personally never used any CAD authoring tool, I'm comming from the Blender corner :)
The code is more or less the getting started code.

Best Regards,
Victor
test_214.stp
main.cpp

Victor Haefner

unread,
Jun 11, 2013, 6:48:19 PM6/11/13
to scl...@googlegroups.com
I think I got it, some pointer stuff :/

using this works:

        while(  attr = inst->NextAttribute()  ) {
            attr->asStr( value );
            cout << " ATT: " << attr->Name() << "  " << value << endl;
        }

instead of:

        /*for (int j=0; j<inst->AttributeCount(); j++) {
            STEPattribute attr = inst->attributes[j];
            attr.asStr(value);
            cout << " ATT: " << attr.Name() << "  " << value << endl;
        }*/

Best Regards,
Victor

Mark

unread,
Jun 12, 2013, 8:30:12 PM6/12/13
to scl...@googlegroups.com
Hi Victor

Thanks for reporting that. Both should behave the same, and I have created an issue for it: https://github.com/stepcode/stepcode/issues/238

Regards
Mark



Best Regards,
Victor

--
You received this message because you are subscribed to the Google Groups "STEPcode - Developers Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scl-dev+u...@googlegroups.com.
To post to this group, send email to scl...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages