Managing shapes names with STEP import/export

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Post Reply
gillesfouca
Posts: 13
Joined: Tue Jan 22, 2013 11:10 am

Managing shapes names with STEP import/export

Post by gillesfouca »

Hello,

I need to write a Python macro to :
  • read a STEP file representing an assembly, with the names associated to B-Rep (sub)shapes (solids' - faces' - edges' - vertices' names),
  • process this file in FreeCAD (find contacts between solids)
  • in FreeCAD GUI : read/write access to the shapes' name (for debugging purposes, and for developing an interactive process)
  • write contacts information between shapes to a text output (with the name of the contact entity, e.g. face X of solid 1 / face Y of solid 2), to use the result in an external program
I found a way to manage the STEP names in OpenCascade (see C++ program bellow). I just need to find how to do the equivalent of this C++ code in FreeCAD : get the names associated to B-Rep shapes in the STEP file, and access shapes with their name (select shape by name, or get the name of a shape), and write the name of shapes when exporting the STEP file.

Has someone worked on this feature ?

Could you tell me the best way to do so ?

Thanks in advance

Best regards

Gilles

Example of program output :

Code: Select all


      ...    Step File Reading : Cube.STEP
      ...    STEP File   Read    ...
Elapsed time:  0 Hour(s) 0 Minute(s) 0.032 Second(s)
CPU user   time: 0.015625 seconds
CPU kernel time: 0 seconds
      ... Step File loaded  ...
Elapsed time:  0 Hour(s) 0 Minute(s) 0.032 Second(s)
CPU user   time: 0.015625 seconds
CPU kernel time: 0 seconds
   491 records (entities,sub-lists,scopes), 1111 parameters

      ... Parameters prepared ... Elapsed time:  0 Hour(s) 0 Minute(s) 0.063 Sec
ond(s)
CPU user   time: 0.03125 seconds
CPU kernel time: 0 seconds
      ...   Objets analysed  ...
Elapsed time:  0 Hour(s) 0 Minute(s) 0.079 Second(s)
CPU user   time: 0.03125 seconds
CPU kernel time: 0 seconds
  STEP Loading done : 277 Entities

*******************************************************************
******        Statistics on Transfer (Write)                 ******

*******************************************************************
******        Transfer Mode = 0  I.E.  As Is       ******
******        Transferring Shape, ShapeType = 2                      ******
** WorkSession : Sending all data
 Step File Name : Cube.STEP_out_MISSING_NAMES.step(405 ents)  Write  Done
1 STEP Writer entities of type"StepBasic_ApplicationContext"
1 STEP Writer entities of type"StepBasic_ApplicationProtocolDefinition"
1 STEP Writer entities of type"StepBasic_Product"
1 STEP Writer entities of type"StepBasic_ProductContext"
1 STEP Writer entities of type"StepBasic_ProductDefinition"
1 STEP Writer entities of type"StepBasic_ProductDefinitionContext"
1 STEP Writer entities of type"StepBasic_ProductDefinitionFormation"
1 STEP Writer entities of type"StepBasic_ProductRelatedProductCategory"
1 STEP Writer entities of type"StepBasic_SiUnitAndLengthUnit"
1 STEP Writer entities of type"StepBasic_SiUnitAndPlaneAngleUnit"
1 STEP Writer entities of type"StepBasic_SiUnitAndSolidAngleUnit"
1 STEP Writer entities of type"StepBasic_UncertaintyMeasureWithUnit"
7 STEP Writer entities of type"StepGeom_Axis2Placement3d"
51 STEP Writer entities of type"StepGeom_CartesianPoint"
50 STEP Writer entities of type"StepGeom_Direction"
1 STEP Writer entities of type"StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUn
certaintyAssCtx"
24 STEP Writer entities of type"StepGeom_GeometricRepresentationContextAndParame
tricRepresentationContext"
36 STEP Writer entities of type"StepGeom_Line"
24 STEP Writer entities of type"StepGeom_Pcurve"
6 STEP Writer entities of type"StepGeom_Plane"
12 STEP Writer entities of type"StepGeom_SurfaceCurve"
36 STEP Writer entities of type"StepGeom_Vector"
24 STEP Writer entities of type"StepRepr_DefinitionalRepresentation"
1 STEP Writer entities of type"StepRepr_ProductDefinitionShape"
1 STEP Writer entities of type"StepShape_AdvancedBrepShapeRepresentation"
6 STEP Writer entities of type"StepShape_AdvancedFace"
1 STEP Writer entities of type"StepShape_ClosedShell"
12 STEP Writer entities of type"StepShape_EdgeCurve"
6 STEP Writer entities of type"StepShape_EdgeLoop"
6 STEP Writer entities of type"StepShape_FaceBound"
1 STEP Writer entities of type"StepShape_ManifoldSolidBrep"
24 STEP Writer entities of type"StepShape_OrientedEdge"
1 STEP Writer entities of type"StepShape_ShapeDefinitionRepresentation"
8 STEP Writer entities of type"StepShape_VertexPoint"
4 STEP Writer entities of type"StepVisual_ColourRgb"
1 STEP Writer entities of type"StepVisual_DraughtingPreDefinedColour"
7 STEP Writer entities of type"StepVisual_FillAreaStyle"
7 STEP Writer entities of type"StepVisual_FillAreaStyleColour"
1 STEP Writer entities of type"StepVisual_MechanicalDesignGeometricPresentationR
epresentation"
6 STEP Writer entities of type"StepVisual_OverRidingStyledItem"
7 STEP Writer entities of type"StepVisual_PresentationStyleAssignment"
1 STEP Writer entities of type"StepVisual_StyledItem"
7 STEP Writer entities of type"StepVisual_SurfaceSideStyle"
7 STEP Writer entities of type"StepVisual_SurfaceStyleFillArea"
7 STEP Writer entities of type"StepVisual_SurfaceStyleUsage"
The read Entity is already named : input name "DEMO_CUBE_WITH_NAME" is copied to
 the written output
The read Entity is already named : input name "CUBE_Face4" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Face5" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Face2" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Face1" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Face3" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Face6" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge4" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge7" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge9" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge10" is copied to the wri
tten output
The read Entity is already named : input name "CUBE_Edge1" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge6" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge5" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge7" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge2" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge8" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge11" is copied to the wri
tten output
The read Entity is already named : input name "CUBE_Edge6" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge3" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge10" is copied to the wri
tten output
The read Entity is already named : input name "CUBE_Edge12" is copied to the wri
tten output
The read Entity is already named : input name "CUBE_Edge8" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge9" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge5" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge11" is copied to the wri
tten output
The read Entity is already named : input name "CUBE_Edge12" is copied to the wri
tten output
The read Entity is already named : input name "CUBE_Edge4" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge3" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge2" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_Edge1" is copied to the writ
ten output
The read Entity is already named : input name "CUBE_VERTEX6" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX3" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX2" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX3" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX8" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX2" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX8" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX6" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX3" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX7" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX1" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX7" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX2" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX1" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX2" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX3" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX7" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX4" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX5" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX4" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX1" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX5" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX1" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX7" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX4" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX6" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX8" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX6" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX5" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX8" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX5" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX4" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX8" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX2" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX2" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX1" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX1" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX5" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX5" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX8" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX6" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX3" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX4" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX6" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX7" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX4" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX3" is copied to the wr
itten output
The read Entity is already named : input name "CUBE_VERTEX7" is copied to the wr
itten output
** WorkSession : Sending all data
 Step File Name : Cube.STEP_out.step(405 ents)  Write  Done
Press a key to terminate

Input STEP File describing a Cube with names shapes (the name of every solid, face, edge, vertex is defined in this STEP file) :

Code: Select all

ISO-10303-21;
HEADER;
FILE_DESCRIPTION (( 'STEP AP214' ),
    '1' );
FILE_NAME ('Cube.STEP',
    '2010-05-06T11:35:27',
    ( '' ),
    ( '' ),
    'SwSTEP 2.0',
    'SolidWorks 2007',
    '' );
FILE_SCHEMA (( 'AUTOMOTIVE_DESIGN' ));
ENDSEC;

DATA;
#1 =( LENGTH_UNIT ( ) NAMED_UNIT ( * ) SI_UNIT ( .MILLI., .METRE. ) );
#2 =( NAMED_UNIT ( * ) PLANE_ANGLE_UNIT ( ) SI_UNIT ( $, .RADIAN. ) );
#3 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, -1.000000000000000000 ) ) ;
#4 = DIRECTION ( 'NONE',  ( -1.000000000000000000, 0.0000000000000000000, 0.0000000000000000000 ) ) ;
#5 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 38.84564393939393800, 0.0000000000000000000 ) ) ;
#6 =( NAMED_UNIT ( * ) SI_UNIT ( $, .STERADIAN. ) SOLID_ANGLE_UNIT ( ) );
#7 = STYLED_ITEM ( 'NONE', ( #8 ), #275 ) ;
#8 = PRESENTATION_STYLE_ASSIGNMENT (( #34 ) ) ;
#9 =( LENGTH_UNIT ( ) NAMED_UNIT ( * ) SI_UNIT ( .MILLI., .METRE. ) );
#10 = MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION (  '', ( #7 ), #14 ) ;
#11 = PRESENTATION_LAYER_ASSIGNMENT (  '', '', ( #7 ) ) ;
#12 =( NAMED_UNIT ( * ) SI_UNIT ( $, .STERADIAN. ) SOLID_ANGLE_UNIT ( ) );
#13 =( NAMED_UNIT ( * ) PLANE_ANGLE_UNIT ( ) SI_UNIT ( $, .RADIAN. ) );
#14 =( GEOMETRIC_REPRESENTATION_CONTEXT ( 3 ) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT ( ( #17 ) ) GLOBAL_UNIT_ASSIGNED_CONTEXT ( ( #9, #13, #12 ) ) REPRESENTATION_CONTEXT ( 'NONE', 'WORKASPACE' ) );
#15 = AXIS2_PLACEMENT_3D ( 'NONE', #5, #3, #4 ) ;
#16 = PLANE ( 'NONE',  #15 ) ;
#17 = UNCERTAINTY_MEASURE_WITH_UNIT (LENGTH_MEASURE( 1.000000000000000100E-005 ), #9, 'distance_accuracy_value', 'NONE');
#18 = UNCERTAINTY_MEASURE_WITH_UNIT (LENGTH_MEASURE( 1.000000000000000100E-005 ), #1, 'distance_accuracy_value', 'NONE');
#19 =( GEOMETRIC_REPRESENTATION_CONTEXT ( 3 ) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT ( ( #18 ) ) GLOBAL_UNIT_ASSIGNED_CONTEXT ( ( #1, #2, #6 ) ) REPRESENTATION_CONTEXT ( 'NONE', 'WORKASPACE' ) );
#20 = APPLICATION_PROTOCOL_DEFINITION ( 'draft international standard', 'automotive_design', 1998, #22 ) ;
#21 = PRODUCT_CONTEXT ( 'NONE', #22, 'mechanical' ) ;
#22 = APPLICATION_CONTEXT ( 'automotive_design' ) ;
#23 = PLANE ( 'NONE',  #28 ) ;
#24 = PRODUCT ( 'Cube', 'Cube', '', ( #21 ) ) ;
#25 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, -1.000000000000000000 ) ) ;
#26 = DIRECTION ( 'NONE',  ( 1.000000000000000000, 0.0000000000000000000, 0.0000000000000000000 ) ) ;
#27 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 18.84564393939393800, 20.00000000000000000 ) ) ;
#28 = AXIS2_PLACEMENT_3D ( 'NONE', #27, #26, #25 ) ;
#29 = SURFACE_STYLE_FILL_AREA ( #30 ) ;
#30 = FILL_AREA_STYLE ('',( #41 ) ) ;
#31 =( LENGTH_UNIT ( ) NAMED_UNIT ( * ) SI_UNIT ( .MILLI., .METRE. ) );
#32 = MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION (  '', ( #47 ), #45 ) ;
#33 = PRESENTATION_LAYER_ASSIGNMENT (  '', '', ( #47 ) ) ;
#34 = SURFACE_STYLE_USAGE ( .BOTH. , #35 ) ;
#35 = SURFACE_SIDE_STYLE ('',( #36 ) ) ;
#36 = SURFACE_STYLE_FILL_AREA ( #37 ) ;
#37 = FILL_AREA_STYLE ('',( #38 ) ) ;
#38 = FILL_AREA_STYLE_COLOUR ( '', #39 ) ;
#39 = COLOUR_RGB ( '',0.0000000000000000000, 0.0000000000000000000, 0.6274509803921568500 ) ;
#40 = FACE_OUTER_BOUND ( 'NONE', #276, .T. ) ;
#41 = FILL_AREA_STYLE_COLOUR ( '', #42 ) ;
#42 = COLOUR_RGB ( '',0.7529411764705882200, 0.7529411764705882200, 0.7529411764705882200 ) ;
#43 = UNCERTAINTY_MEASURE_WITH_UNIT (LENGTH_MEASURE( 1.000000000000000100E-005 ), #31, 'distance_accuracy_value', 'NONE');
#44 =( NAMED_UNIT ( * ) PLANE_ANGLE_UNIT ( ) SI_UNIT ( $, .RADIAN. ) );
#45 =( GEOMETRIC_REPRESENTATION_CONTEXT ( 3 ) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT ( ( #43 ) ) GLOBAL_UNIT_ASSIGNED_CONTEXT ( ( #31, #44, #46 ) ) REPRESENTATION_CONTEXT ( 'NONE', 'WORKASPACE' ) );
#46 =( NAMED_UNIT ( * ) SI_UNIT ( $, .STERADIAN. ) SOLID_ANGLE_UNIT ( ) );
#47 = STYLED_ITEM ( 'NONE', ( #48 ), #274 ) ;
#48 = PRESENTATION_STYLE_ASSIGNMENT (( #49 ) ) ;
#49 = SURFACE_STYLE_USAGE ( .BOTH. , #50 ) ;
#50 = SURFACE_SIDE_STYLE ('',( #29 ) ) ;
#51 =( NAMED_UNIT ( * ) SI_UNIT ( $, .STERADIAN. ) SOLID_ANGLE_UNIT ( ) );
#52 = PRODUCT_DEFINITION_SHAPE ( 'NONE', 'NONE',  #60 ) ;
#53 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, 0.0000000000000000000 ) ) ;
#54 = ADVANCED_BREP_SHAPE_REPRESENTATION ( 'Cube', ( #274, #68 ), #61 ) ;
#55 =( NAMED_UNIT ( * ) PLANE_ANGLE_UNIT ( ) SI_UNIT ( $, .RADIAN. ) );
#56 =( LENGTH_UNIT ( ) NAMED_UNIT ( * ) SI_UNIT ( .MILLI., .METRE. ) );
#57 = UNCERTAINTY_MEASURE_WITH_UNIT (LENGTH_MEASURE( 1.000000000000000100E-005 ), #56, 'distance_accuracy_value', 'NONE');
#58 = PRODUCT_RELATED_PRODUCT_CATEGORY ( 'part', '', ( #24 ) ) ;
#59 = PRODUCT_DEFINITION_FORMATION_WITH_SPECIFIED_SOURCE ( 'ANY', '', #24, .NOT_KNOWN. ) ;
#60 = PRODUCT_DEFINITION ( 'UNKNOWN', '', #59, #63 ) ;
#61 =( GEOMETRIC_REPRESENTATION_CONTEXT ( 3 ) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT ( ( #57 ) ) GLOBAL_UNIT_ASSIGNED_CONTEXT ( ( #56, #55, #51 ) ) REPRESENTATION_CONTEXT ( 'NONE', 'WORKASPACE' ) );
#62 = SHAPE_DEFINITION_REPRESENTATION ( #52, #54 ) ;
#63 = PRODUCT_DEFINITION_CONTEXT ( 'detailed design', #65, 'design' ) ;
#64 = APPLICATION_PROTOCOL_DEFINITION ( 'draft international standard', 'automotive_design', 1998, #65 ) ;
#65 = APPLICATION_CONTEXT ( 'automotive_design' ) ;
#66 = DIRECTION ( 'NONE',  ( 1.000000000000000000, 0.0000000000000000000, 0.0000000000000000000 ) ) ;
#67 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, 1.000000000000000000 ) ) ;
#68 = AXIS2_PLACEMENT_3D ( 'NONE', #53, #67, #66 ) ;
#69 = PRESENTATION_LAYER_ASSIGNMENT (  '', '', ( #70 ) ) ;
#70 = STYLED_ITEM ( 'NONE', ( #71 ), #128 ) ;
#71 = PRESENTATION_STYLE_ASSIGNMENT (( #72 ) ) ;
#72 = SURFACE_STYLE_USAGE ( .BOTH. , #73 ) ;
#73 = SURFACE_SIDE_STYLE ('',( #74 ) ) ;
#74 = SURFACE_STYLE_FILL_AREA ( #112 ) ;
#75 = PRESENTATION_STYLE_ASSIGNMENT (( #76 ) ) ;
#76 = SURFACE_STYLE_USAGE ( .BOTH. , #77 ) ;
#77 = SURFACE_SIDE_STYLE ('',( #78 ) ) ;
#78 = SURFACE_STYLE_FILL_AREA ( #79 ) ;
#79 = FILL_AREA_STYLE ('',( #86 ) ) ;
#80 = COLOUR_RGB ( '',1.000000000000000000, 0.5019607843137254800, 0.5019607843137254800 ) ;
#81 = FACE_OUTER_BOUND ( 'NONE', #254, .T. ) ;
#82 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 1.000000000000000000, 0.0000000000000000000 ) ) ;
#83 = VECTOR ( 'NONE', #82, 1000.000000000000000 ) ;
#84 = CARTESIAN_POINT ( 'NONE',  ( 20.00000000000000000, 18.84564393939393800, 20.00000000000000000 ) ) ;
#85 = LINE ( 'NONE', #84, #83 ) ;
#86 = FILL_AREA_STYLE_COLOUR ( '', #80 ) ;
#87 = CARTESIAN_POINT ( 'NONE',  ( 20.00000000000000000, 18.84564393939393800, 0.0000000000000000000 ) ) ;
#88 = DIRECTION ( 'NONE',  ( 1.000000000000000000, 0.0000000000000000000, 0.0000000000000000000 ) ) ;
#89 = VECTOR ( 'NONE', #88, 1000.000000000000000 ) ;
#90 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 18.84564393939393800, 0.0000000000000000000 ) ) ;
#91 = LINE ( 'NONE', #90, #89 ) ;
#92 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, 1.000000000000000000 ) ) ;
#93 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 1.000000000000000000, 0.0000000000000000000 ) ) ;
#94 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 18.84564393939393800, 20.00000000000000000 ) ) ;
#95 = AXIS2_PLACEMENT_3D ( 'NONE', #94, #93, #92 ) ;
#96 = PLANE ( 'NONE',  #95 ) ;
#97 =( GEOMETRIC_REPRESENTATION_CONTEXT ( 3 ) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT ( ( #98 ) ) GLOBAL_UNIT_ASSIGNED_CONTEXT ( ( #132, #131, #130 ) ) REPRESENTATION_CONTEXT ( 'NONE', 'WORKASPACE' ) );
#98 = UNCERTAINTY_MEASURE_WITH_UNIT (LENGTH_MEASURE( 1.000000000000000100E-005 ), #132, 'distance_accuracy_value', 'NONE');
#99 = DIRECTION ( 'NONE',  ( 1.000000000000000000, 0.0000000000000000000, 0.0000000000000000000 ) ) ;
#100 = VECTOR ( 'NONE', #99, 1000.000000000000000 ) ;
#101 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 18.84564393939393800, 20.00000000000000000 ) ) ;
#102 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 38.84564393939393800, 20.00000000000000000 ) ) ;
#103 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, -1.000000000000000000, 0.0000000000000000000 ) ) ;
#104 = VECTOR ( 'NONE', #103, 1000.000000000000000 ) ;
#105 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 18.84564393939393800, 20.00000000000000000 ) ) ;
#106 = LINE ( 'NONE', #105, #104 ) ;
#107 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 38.84564393939393800, 0.0000000000000000000 ) ) ;
#108 = CARTESIAN_POINT ( 'NONE',  ( 20.00000000000000000, 38.84564393939393800, 20.00000000000000000 ) ) ;
#109 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, -1.000000000000000000 ) ) ;
#110 = VECTOR ( 'NONE', #109, 1000.000000000000000 ) ;
#111 = CARTESIAN_POINT ( 'NONE',  ( 20.00000000000000000, 38.84564393939393800, 20.00000000000000000 ) ) ;
#112 = FILL_AREA_STYLE ('',( #118 ) ) ;
#113 = COLOUR_RGB ( '',1.000000000000000000, 0.5019607843137254800, 0.5019607843137254800 ) ;
#114 = FACE_OUTER_BOUND ( 'NONE', #232, .T. ) ;
#115 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, -1.000000000000000000 ) ) ;
#116 = VECTOR ( 'NONE', #115, 1000.000000000000000 ) ;
#117 = CARTESIAN_POINT ( 'NONE',  ( 20.00000000000000000, 18.84564393939393800, 20.00000000000000000 ) ) ;
#118 = FILL_AREA_STYLE_COLOUR ( '', #113 ) ;
#119 =( NAMED_UNIT ( * ) PLANE_ANGLE_UNIT ( ) SI_UNIT ( $, .RADIAN. ) );
#120 =( LENGTH_UNIT ( ) NAMED_UNIT ( * ) SI_UNIT ( .MILLI., .METRE. ) );
#121 = MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION (  '', ( #70 ), #171 ) ;
#122 = ORIENTED_EDGE ( 'NONE', *, *, #231, .T. ) ;
#123 = EDGE_CURVE ( 'CUBE_Edge5', #227, #124, #127, .T. ) ;
#124 = VERTEX_POINT ( 'CUBE_VERTEX1', #208 ) ;
#125 = ORIENTED_EDGE ( 'NONE', *, *, #126, .F. ) ;
#126 = EDGE_CURVE ( 'CUBE_Edge6', #124, #249, #207, .T. ) ;
#127 = LINE ( 'NONE', #101, #100 ) ;
#128 = ADVANCED_FACE ( 'CUBE_Face2', ( #114 ), #170, .F. ) ;
#129 = ORIENTED_EDGE ( 'NONE', *, *, #123, .F. ) ;
#130 =( NAMED_UNIT ( * ) SI_UNIT ( $, .STERADIAN. ) SOLID_ANGLE_UNIT ( ) );
#131 =( NAMED_UNIT ( * ) PLANE_ANGLE_UNIT ( ) SI_UNIT ( $, .RADIAN. ) );
#132 =( LENGTH_UNIT ( ) NAMED_UNIT ( * ) SI_UNIT ( .MILLI., .METRE. ) );
#133 = MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION (  '', ( #135 ), #97 ) ;
#134 = PRESENTATION_LAYER_ASSIGNMENT (  '', '', ( #135 ) ) ;
#135 = STYLED_ITEM ( 'NONE', ( #136 ), #245 ) ;
#136 = PRESENTATION_STYLE_ASSIGNMENT (( #137 ) ) ;
#137 = SURFACE_STYLE_USAGE ( .BOTH. , #138 ) ;
#138 = SURFACE_SIDE_STYLE ('',( #139 ) ) ;
#139 = SURFACE_STYLE_FILL_AREA ( #140 ) ;
#140 = FILL_AREA_STYLE ('',( #147 ) ) ;
#141 = COLOUR_RGB ( '',0.0000000000000000000, 0.0000000000000000000, 1.000000000000000000 ) ;
#142 = FACE_OUTER_BOUND ( 'NONE', #246, .T. ) ;
#143 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, -1.000000000000000000 ) ) ;
#144 = VECTOR ( 'NONE', #143, 1000.000000000000000 ) ;
#145 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 38.84564393939393800, 20.00000000000000000 ) ) ;
#146 = LINE ( 'NONE', #145, #144 ) ;
#147 = FILL_AREA_STYLE_COLOUR ( '', #141 ) ;
#148 = UNCERTAINTY_MEASURE_WITH_UNIT (LENGTH_MEASURE( 1.000000000000000100E-005 ), #120, 'distance_accuracy_value', 'NONE');
#149 =( NAMED_UNIT ( * ) SI_UNIT ( $, .STERADIAN. ) SOLID_ANGLE_UNIT ( ) );
#150 = LINE ( 'NONE', #111, #110 ) ;
#151 = CARTESIAN_POINT ( 'NONE',  ( 20.00000000000000000, 38.84564393939393800, 0.0000000000000000000 ) ) ;
#152 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 1.000000000000000000, 0.0000000000000000000 ) ) ;
#153 = VECTOR ( 'NONE', #152, 1000.000000000000000 ) ;
#154 = CARTESIAN_POINT ( 'NONE',  ( 20.00000000000000000, 18.84564393939393800, 0.0000000000000000000 ) ) ;
#155 = LINE ( 'NONE', #154, #153 ) ;
#156 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, -1.000000000000000000 ) ) ;
#157 = VECTOR ( 'NONE', #156, 1000.000000000000000 ) ;
#158 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 18.84564393939393800, 20.00000000000000000 ) ) ;
#159 = LINE ( 'NONE', #158, #157 ) ;
#160 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 18.84564393939393800, 0.0000000000000000000 ) ) ;
#161 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, -1.000000000000000000, 0.0000000000000000000 ) ) ;
#162 = VECTOR ( 'NONE', #161, 1000.000000000000000 ) ;
#163 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 18.84564393939393800, 0.0000000000000000000 ) ) ;
#164 = LINE ( 'NONE', #163, #162 ) ;
#165 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 18.84564393939393800, 20.00000000000000000 ) ) ;
#166 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, 1.000000000000000000 ) ) ;
#167 = DIRECTION ( 'NONE',  ( -1.000000000000000000, 0.0000000000000000000, 0.0000000000000000000 ) ) ;
#168 = CARTESIAN_POINT ( 'NONE',  ( 20.00000000000000000, 18.84564393939393800, 20.00000000000000000 ) ) ;
#169 = AXIS2_PLACEMENT_3D ( 'NONE', #168, #167, #166 ) ;
#170 = PLANE ( 'NONE',  #169 ) ;
#171 =( GEOMETRIC_REPRESENTATION_CONTEXT ( 3 ) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT ( ( #148 ) ) GLOBAL_UNIT_ASSIGNED_CONTEXT ( ( #120, #119, #149 ) ) REPRESENTATION_CONTEXT ( 'NONE', 'WORKASPACE' ) );
#172 = MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION (  '', ( #174 ), #19 ) ;
#173 = PRESENTATION_LAYER_ASSIGNMENT (  '', '', ( #174 ) ) ;
#174 = STYLED_ITEM ( 'NONE', ( #175 ), #267 ) ;
#175 = PRESENTATION_STYLE_ASSIGNMENT (( #176 ) ) ;
#176 = SURFACE_STYLE_USAGE ( .BOTH. , #177 ) ;
#177 = SURFACE_SIDE_STYLE ('',( #178 ) ) ;
#178 = SURFACE_STYLE_FILL_AREA ( #179 ) ;
#179 = FILL_AREA_STYLE ('',( #186 ) ) ;
#180 = COLOUR_RGB ( '',1.000000000000000000, 0.0000000000000000000, 0.5019607843137254800 ) ;
#181 = FACE_OUTER_BOUND ( 'NONE', #268, .T. ) ;
#182 = DIRECTION ( 'NONE',  ( -1.000000000000000000, 0.0000000000000000000, 0.0000000000000000000 ) ) ;
#183 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, -1.000000000000000000 ) ) ;
#184 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 38.84564393939393800, 20.00000000000000000 ) ) ;
#185 = AXIS2_PLACEMENT_3D ( 'NONE', #184, #183, #182 ) ;
#186 = FILL_AREA_STYLE_COLOUR ( '', #180 ) ;
#187 = PLANE ( 'NONE',  #185 ) ;
#188 =( GEOMETRIC_REPRESENTATION_CONTEXT ( 3 ) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT ( ( #189 ) ) GLOBAL_UNIT_ASSIGNED_CONTEXT ( ( #192, #191, #190 ) ) REPRESENTATION_CONTEXT ( 'NONE', 'WORKASPACE' ) );
#189 = UNCERTAINTY_MEASURE_WITH_UNIT (LENGTH_MEASURE( 1.000000000000000100E-005 ), #192, 'distance_accuracy_value', 'NONE');
#190 =( NAMED_UNIT ( * ) SI_UNIT ( $, .STERADIAN. ) SOLID_ANGLE_UNIT ( ) );
#191 =( NAMED_UNIT ( * ) PLANE_ANGLE_UNIT ( ) SI_UNIT ( $, .RADIAN. ) );
#192 =( LENGTH_UNIT ( ) NAMED_UNIT ( * ) SI_UNIT ( .MILLI., .METRE. ) );
#193 = MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION (  '', ( #195 ), #188 ) ;
#194 = PRESENTATION_LAYER_ASSIGNMENT (  '', '', ( #195 ) ) ;
#195 = STYLED_ITEM ( 'NONE', ( #196 ), #261 ) ;
#196 = PRESENTATION_STYLE_ASSIGNMENT (( #197 ) ) ;
#197 = SURFACE_STYLE_USAGE ( .BOTH. , #198 ) ;
#198 = SURFACE_SIDE_STYLE ('',( #199 ) ) ;
#199 = SURFACE_STYLE_FILL_AREA ( #200 ) ;
#200 = FILL_AREA_STYLE ('',( #206 ) ) ;
#201 = COLOUR_RGB ( '',1.000000000000000000, 0.5019607843137254800, 0.5019607843137254800 ) ;
#202 = FACE_OUTER_BOUND ( 'NONE', #262, .T. ) ;
#203 = DIRECTION ( 'NONE',  ( -1.000000000000000000, 0.0000000000000000000, 0.0000000000000000000 ) ) ;
#204 = VECTOR ( 'NONE', #203, 1000.000000000000000 ) ;
#205 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 38.84564393939393800, 20.00000000000000000 ) ) ;
#206 = FILL_AREA_STYLE_COLOUR ( '', #201 ) ;
#207 = LINE ( 'NONE', #117, #116 ) ;
#208 = CARTESIAN_POINT ( 'NONE',  ( 20.00000000000000000, 18.84564393939393800, 20.00000000000000000 ) ) ;
#209 = LINE ( 'NONE', #205, #204 ) ;
#210 = DIRECTION ( 'NONE',  ( -1.000000000000000000, 0.0000000000000000000, 0.0000000000000000000 ) ) ;
#211 = VECTOR ( 'NONE', #210, 1000.000000000000000 ) ;
#212 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 38.84564393939393800, 0.0000000000000000000 ) ) ;
#213 = LINE ( 'NONE', #212, #211 ) ;
#214 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, 0.0000000000000000000, -1.000000000000000000 ) ) ;
#215 = DIRECTION ( 'NONE',  ( 0.0000000000000000000, -1.000000000000000000, 0.0000000000000000000 ) ) ;
#216 = CARTESIAN_POINT ( 'NONE',  ( 0.0000000000000000000, 38.84564393939393800, 20.00000000000000000 ) ) ;
#217 = AXIS2_PLACEMENT_3D ( 'NONE', #216, #215, #214 ) ;
#218 = PLANE ( 'NONE',  #217 ) ;
#219 =( GEOMETRIC_REPRESENTATION_CONTEXT ( 3 ) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT ( ( #220 ) ) GLOBAL_UNIT_ASSIGNED_CONTEXT ( ( #223, #222, #221 ) ) REPRESENTATION_CONTEXT ( 'NONE', 'WORKASPACE' ) );
#220 = UNCERTAINTY_MEASURE_WITH_UNIT (LENGTH_MEASURE( 1.000000000000000100E-005 ), #223, 'distance_accuracy_value', 'NONE');
#221 =( NAMED_UNIT ( * ) SI_UNIT ( $, .STERADIAN. ) SOLID_ANGLE_UNIT ( ) );
#222 =( NAMED_UNIT ( * ) PLANE_ANGLE_UNIT ( ) SI_UNIT ( $, .RADIAN. ) );
#223 =( LENGTH_UNIT ( ) NAMED_UNIT ( * ) SI_UNIT ( .MILLI., .METRE. ) );
#224 = MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION (  '', ( #226 ), #219 ) ;
#225 = PRESENTATION_LAYER_ASSIGNMENT (  '', '', ( #226 ) ) ;
#226 = STYLED_ITEM ( 'NONE', ( #75 ), #253 ) ;
#227 = VERTEX_POINT ( 'CUBE_VERTEX2', #165 ) ;
#228 = ORIENTED_EDGE ( 'NONE', *, *, #241, .F. ) ;
#229 = EDGE_CURVE ( 'CUBE_Edge4', #240, #230, #164, .T. ) ;
#230 = VERTEX_POINT ( 'CUBE_VERTEX3', #160 ) ;
#231 = EDGE_CURVE ( 'CUBE_Edge7', #227, #230, #159, .T. ) ;
#232 = EDGE_LOOP ( 'NONE', ( #233, #236, #250, #252 ) ) ;
#233 = ORIENTED_EDGE ( 'NONE', *, *, #234, .T. ) ;
#234 = EDGE_CURVE ( 'CUBE_Edge2', #249, #235, #155, .T. ) ;
#235 = VERTEX_POINT ( 'CUBE_VERTEX4', #151 ) ;
#236 = ORIENTED_EDGE ( 'NONE', *, *, #237, .F. ) ;
#237 = EDGE_CURVE ( 'CUBE_Edge8', #238, #235, #150, .T. ) ;
#238 = VERTEX_POINT ( 'CUBE_VERTEX5', #108 ) ;
#239 = ORIENTED_EDGE ( 'NONE', *, *, #231, .F. ) ;
#240 = VERTEX_POINT ( 'CUBE_VERTEX6', #107 ) ;
#241 = EDGE_CURVE ( 'CUBE_Edge9', #242, #227, #106, .T. ) ;
#242 = VERTEX_POINT ( 'CUBE_VERTEX8', #102 ) ;
#243 = ORIENTED_EDGE ( 'NONE', *, *, #244, .T. ) ;
#244 = EDGE_CURVE ( 'CUBE_Edge10', #242, #240, #146, .T. ) ;
#245 = ADVANCED_FACE ( 'CUBE_Face5', ( #142 ), #96, .F. ) ;
#246 = EDGE_LOOP ( 'NONE', ( #247, #125, #129, #122 ) ) ;
#247 = ORIENTED_EDGE ( 'NONE', *, *, #248, .T. ) ;
#248 = EDGE_CURVE ( 'CUBE_Edge1', #230, #249, #91, .T. ) ;
#249 = VERTEX_POINT ( 'CUBE_VERTEX7', #87 ) ;
#250 = ORIENTED_EDGE ( 'NONE', *, *, #251, .F. ) ;
#251 = EDGE_CURVE ( 'CUBE_Edge11', #124, #238, #85, .T. ) ;
#252 = ORIENTED_EDGE ( 'NONE', *, *, #126, .T. ) ;
#253 = ADVANCED_FACE ( 'CUBE_Face1', ( #81 ), #218, .F. ) ;
#254 = EDGE_LOOP ( 'NONE', ( #255, #257, #258, #260 ) ) ;
#255 = ORIENTED_EDGE ( 'NONE', *, *, #256, .T. ) ;
#256 = EDGE_CURVE ( 'CUBE_Edge3', #235, #240, #213, .T. ) ;
#257 = ORIENTED_EDGE ( 'NONE', *, *, #244, .F. ) ;
#258 = ORIENTED_EDGE ( 'NONE', *, *, #259, .F. ) ;
#259 = EDGE_CURVE ( 'CUBE_Edge12', #238, #242, #209, .T. ) ;
#260 = ORIENTED_EDGE ( 'NONE', *, *, #237, .T. ) ;
#261 = ADVANCED_FACE ( 'CUBE_Face3', ( #202 ), #187, .F. ) ;
#262 = EDGE_LOOP ( 'NONE', ( #263, #264, #265, #266 ) ) ;
#263 = ORIENTED_EDGE ( 'NONE', *, *, #241, .T. ) ;
#264 = ORIENTED_EDGE ( 'NONE', *, *, #123, .T. ) ;
#265 = ORIENTED_EDGE ( 'NONE', *, *, #251, .T. ) ;
#266 = ORIENTED_EDGE ( 'NONE', *, *, #259, .T. ) ;
#267 = ADVANCED_FACE ( 'CUBE_Face6', ( #181 ), #16, .T. ) ;
#268 = EDGE_LOOP ( 'NONE', ( #269, #270, #271, #272 ) ) ;
#269 = ORIENTED_EDGE ( 'NONE', *, *, #229, .F. ) ;
#270 = ORIENTED_EDGE ( 'NONE', *, *, #256, .F. ) ;
#271 = ORIENTED_EDGE ( 'NONE', *, *, #234, .F. ) ;
#272 = ORIENTED_EDGE ( 'NONE', *, *, #248, .F. ) ;
#273 = CLOSED_SHELL ( 'NONE', ( #275, #245, #128, #253, #261, #267 ) ) ;
#274 = MANIFOLD_SOLID_BREP ( 'DEMO_CUBE_WITH_NAME', #273 ) ;
#275 = ADVANCED_FACE ( 'CUBE_Face4', ( #40 ), #23, .F. ) ;
#276 = EDGE_LOOP ( 'NONE', ( #277, #239, #228, #243 ) ) ;
#277 = ORIENTED_EDGE ( 'NONE', *, *, #229, .T. ) ;
ENDSEC;
END-ISO-10303-21;
C++ OpenCascade Source code of the program :

Code: Select all

// STEPCAFControl_Writer.cpp : Defines the entry point for the console application.
// Author : Gilles Foucault
// Creation date : 2012/9/20
// 

#include "stdafx.h"

// Function  STEP_GetEntityName :
// Returns the name of a shape read in a STEP file
// e.g. #274 = MANIFOLD_SOLID_BREP ( 'DEMO_CUBE_WITH_NAME', #273 ) ; 
//    --> the name of the TopoDS_Solid in the reader will be "DEMO_CUBE_WITH_NAME"
// Parameters :
//   const TopoDS_Shape & theShape : the shape
//   STEPCAFControl_Reader * aReader : the Reader
//	 char * acName : char array to write the name into (the memory should be pre-allocated !)
// Return values :
//   void
void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * aReader, char * acName)
{
	const Handle(XSControl_WorkSession)& theSession = aReader->Reader().WS();
	const Handle(XSControl_TransferReader)& aTransferReader =
		theSession->TransferReader();

	Handle(Standard_Transient) anEntity =
		aTransferReader->EntityFromShapeResult(theShape, 1);

	if (anEntity.IsNull()) {
		// as just mapped
		anEntity = aTransferReader->EntityFromShapeResult (theShape,-1);
	}

	if (anEntity.IsNull()) {
		// as anything
		anEntity = aTransferReader->EntityFromShapeResult (theShape,4);
	}

	if (anEntity.IsNull()) {
		cout<<"Warning: XSInterVertex_STEPReader::ReadAttributes()\nentity not found"<<endl;
	}
	else
	{
		Handle(StepRepr_RepresentationItem) aReprItem;
		aReprItem =
			Handle(StepRepr_RepresentationItem)::DownCast(anEntity);

		if (aReprItem.IsNull()) {
			cout<<"Error: STEPReader::ReadAttributes():\nStepRepr_RepresentationItem Is NULL"<<endl;
		}
		else
			strcpy(acName, aReprItem->Name()->ToCString());
	}
}

// Function "StepShape_SetName" :
// Parameters :
// Template type : The type corresponding to the down-cast of the writer representation e.g. 
//     For a solid : StepShape_ManifoldSolidBrep, a face : StepShape_AdvancedFace, etc.
// Handle(StepRepr_RepresentationItem) r = the STEP Writter representation entity obtained by 
//		STEPConstruct::FindEntity(writer.Writer().WS()->TransferWriter()->FinderProcess(), shape)
// STEPCAFControl_Reader & reader = the STEP Reader of the input file
// TopoDS_Shape & shape = the shape that has to be named either from the defined name in the Reader, or with a string "prefix+i"
// char * prefix = name's prefix to set a new name (if the shapes's name undefined in the reader)
// int i = ID to append to the prefix (used to obtain unique names)
// Return values :
//   0 : failure (r is nul or not convertible into Handle_StepShape_TypeX
//   1 : the shape's name is already defined in the input file, and has been copied to the writer
//   2 : the shape's name is undefined in the input file, and has been initialised with "prefix"+i in the writer
template <class Handle_StepShape_TypeX>
int StepShape_SetName (Handle(StepRepr_RepresentationItem) r, 
										STEPCAFControl_Reader & reader, TopoDS_Shape & shape, char * prefix, int i)
{
	if (r.IsNull() == Standard_False)
	{
		// cast the StepRepr_RepresentationItem to a StepShape_AdvancedFace of the STEP Writer : variable "x"
		Handle_StepShape_TypeX x = Handle_StepShape_TypeX::DownCast(r);
		if (r.IsNull() == Standard_True)
		{
			std::cerr << "Failed to Down-cast StepRepr_RepresentationItem into "<< x->DynamicType()->Name()<<std::endl;
			return 0;
		}
		char readerName[512];
		// map the TopoDS_Face to the name of the OCAF STEP Reader (variable "readerName"), 
		// (the TopoDS_Face is mapped to a STEP Reader StepRepr_RepresentationItem 
		// inside the function STEP_GetEntityName(), and its name is retrieved )
		STEP_GetEntityName(shape, &reader, readerName);				
		if (strlen(readerName) > 0  && strcmp("NONE", readerName) != 0 )
		{
			// Associate the STEP Reader face's name to the STEP Writer face name
			Handle(TCollection_HAsciiString) newid = new TCollection_HAsciiString(readerName);
			x->SetName(newid);
			std::cout << "The read Entity is already named : input name \""<< readerName<<"\" is copied to the written output "<<std::endl;
			return 1;
		}
		else
		{
			// Associate a non-empty name to the entity
			char newName[512] = "";
			sprintf(newName, "%s#%d", prefix, i);
			Handle(TCollection_HAsciiString) newid = new TCollection_HAsciiString(newName);
			x->SetName(newid);	
			std::cout << "The name of the read Entity is undefined : the name is set to \""<< newName<<"\" in the written output"<<std::endl;
			return 2;
		}
	}
	return 0;
}

int main(int argc, char** argv)
{
	char *filename = argv[1];

	STEPCAFControl_Reader reader;
	IFSelect_ReturnStatus stat = reader.ReadFile(filename);

	// The various ways of reading a file are available here too :
	// to read it by the reader, to take it from a WorkSession ...
	Handle(TDocStd_Document) aDoc;
	{
		Handle(XCAFApp_Application) anApp = XCAFApp_Application::GetApplication();
		anApp->NewDocument("MDTV-XCAF", aDoc);
	}
	if ( !reader.Transfer ( aDoc ) ) {
		std::cout<<"Cannot read any relevant data from the STEP file"<<endl;
		// abandon ..
	}
	// Here, the Document has been filled from a STEP file,
	// it is ready to use
	Standard_Boolean ok = reader.Transfer(aDoc);
	Handle (XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());	
	STEPControl_StepModelType mode = STEPControl_AsIs;
	STEPCAFControl_Writer writer;

	Interface_Static::SetCVal("write.step.schema", "AP214IS");
	Interface_Static::SetCVal("write.step.product.name", "productInfo" );

	// configure STEP interface
	writer.SetColorMode(Standard_True);
	writer.SetLayerMode(Standard_True);
	writer.SetNameMode (Standard_True);

	// Translating document (conversion) to STEP Writer
	if ( !writer.Transfer ( aDoc, mode ) ) {
		std::cerr << "The document cannot be translated or gives no result" << endl;
		return Standard_False;
	}

	// This is just to see the difference of STEP Files with and without names :
	// Write the File (WITHOUT names associated to Faces/Edges/Vertices) 
	ok=Standard_True;
	char outfilename2[256]="";
	sprintf(outfilename2, "%s_out_MISSING_NAMES.step", filename);
	stat = writer.Write(outfilename2);
	if (stat!=IFSelect_RetDone) ok = Standard_False;

	// List interesting stuff : class names of the StepRepr_Items in the STEP Writer :-)
	// These class names have to be used to map TopoDS_Entities to classes of the STEP Writer
	std::map <std::string, int> TransientCounter;
	Handle(StepData_StepModel) stpDataModel = writer.Writer().Model();
	for (int i=1; i<=stpDataModel->NbEntities(); i++)
	{

		Handle(Standard_Transient) e = stpDataModel->Entity(i);

		if (TransientCounter.find((e->DynamicType())->Name()) == TransientCounter.end())
			TransientCounter[(e->DynamicType())->Name()] = 1;
		else
			TransientCounter[(e->DynamicType())->Name()] += 1;
	}
	for (std::map <std::string, int>::iterator it=TransientCounter.begin(); it != TransientCounter.end(); it++)
	{
		std::cout<<it->second<<" STEP Writer entities of type\""<<it->first << "\""<<std::endl;
	}

	////// Begin Hack to associate names to Faces/Edges/Vertices /////
	const Handle(XSControl_WorkSession)& theSession = writer.Writer().WS();
	const Handle(XSControl_TransferWriter)& aTransferWriter =
		theSession->TransferWriter();
	const Handle(Transfer_FinderProcess) FP = aTransferWriter->FinderProcess();

	// Browse "Products" in the sequence of objects in the assembly document
	TDF_LabelSequence labelSequence;
	myAssembly->GetShapes(labelSequence);
	for (int iLabelSeq=1; iLabelSeq<=labelSequence.Length(); iLabelSeq++)
	{
		TopoDS_Shape result	= myAssembly->GetShape(labelSequence.Value(iLabelSeq));
		TopoDS_Solid aSolid; aSolid.Nullify();

		try {
			aSolid=TopoDS::Solid(result);
		}
		catch(Standard_Failure)
		{
		}
		if (!aSolid.IsNull())
		{
			int i=0;
			{
				// map the TopoDS_Solid to a StepRepr_RepresentationItem of the STEP Writer : variable "r"
				Handle(StepRepr_RepresentationItem) r = STEPConstruct::FindEntity(FP, aSolid);
				StepShape_SetName<Handle_StepShape_ManifoldSolidBrep> (r, reader, aSolid, "My Solid", i++);
			}

			for(TopExp_Explorer faceExplorer(aSolid, TopAbs_FACE); faceExplorer.More();
				faceExplorer.Next())
			{
				TopoDS_Face aFace = TopoDS::Face(faceExplorer.Current());
				Handle(StepRepr_RepresentationItem) r = STEPConstruct::FindEntity(FP, aFace);
				StepShape_SetName<Handle_StepShape_AdvancedFace> (r, reader, aFace, "My Face", i++);
			}

			for(TopExp_Explorer edgeExplorer(aSolid, TopAbs_EDGE); edgeExplorer.More();edgeExplorer.Next()){
				TopoDS_Edge anEdge = TopoDS::Edge(edgeExplorer.Current());
				Handle(StepRepr_RepresentationItem) r = STEPConstruct::FindEntity(FP, anEdge);
				StepShape_SetName<Handle_StepShape_EdgeCurve> (r, reader, anEdge, "My Edge", i++);
			}

			for(TopExp_Explorer vertexExplorer(aSolid, TopAbs_VERTEX); vertexExplorer.More();vertexExplorer.Next()){
				TopoDS_Vertex aVertex = TopoDS::Vertex(vertexExplorer.Current());
				Handle(StepRepr_RepresentationItem) r = STEPConstruct::FindEntity(FP, aVertex);
				StepShape_SetName<Handle_StepShape_VertexPoint> (r, reader, aVertex, "My Vertex", i++);
			}
		}
	}
	////// END of the Hack to associate names to Faces/Edges/Vertices /////

	// edit STEP header
	APIHeaderSection_MakeHeader makeHeader(writer.Writer().Model());

	char outfilename[256]="";
	sprintf(outfilename, "%s_out.step", filename);
	Handle(TCollection_HAsciiString) headerFileName = new TCollection_HAsciiString(outfilename);
	Handle(TCollection_HAsciiString) headerAuthor      = new TCollection_HAsciiString("Gilles Foucault");
	Handle(TCollection_HAsciiString) headerOrganization = new TCollection_HAsciiString("UJF");
	Handle(TCollection_HAsciiString) headerOriginatingSystem = new TCollection_HAsciiString("STEP CAF CONTROL WRITER");
	Handle(TCollection_HAsciiString) fileDescription = new TCollection_HAsciiString("My Model");

	makeHeader.SetName(headerFileName);
	makeHeader.SetAuthorValue (1, headerAuthor);
	makeHeader.SetOrganizationValue (1, headerOrganization);
	makeHeader.SetOriginatingSystem(headerOriginatingSystem);
	makeHeader.SetDescriptionValue(1, fileDescription);

	// Writing the File (With names associated to Faces/Edges/Vertices)
	ok=Standard_True;
	stat = writer.Write(outfilename);
	if (stat!=IFSelect_RetDone) ok = Standard_False;

	std::cout << "Press a key to terminate\n";
	char c;
	std::cin >> c;

	return 0;
}

Code: Select all

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once


#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>



#include <TopoDS.hxx>
#include <TopoDS_CompSolid.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Compound.hxx>

#include <ShapeAnalysis_Wire.hxx>
#include <ShapeAnalysis.hxx>
#include <ShapeExtend_WireData.hxx>
#include <ShapeAnalysis_Curve.hxx>
#include <BRepTopAdaptor_FClass2d.hxx>

#include <TColgp_SequenceOfPnt2d.hxx>
#include <TColgp_SequenceOfPnt.hxx>

#include <BRep_Tool.hxx>
#include <BRepLib.hxx>

#include <BRepTools.hxx>
#include <BRepMesh.hxx>
#include <BRep_Builder.hxx>
#include <Poly_Triangulation.hxx>
#include <Poly_PolygonOnTriangulation.hxx>
#include <Poly_Polygon3D.hxx>

#include <BRepAlgoAPI_Fuse.hxx>

#include <BRepBuilderAPI_MakeSolid.hxx>
#include <BRepBuilderAPI_MakeShell.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_Transform.hxx>


#include <BRepFilletAPI_MakeFillet.hxx>

#include <BRepOffsetAPI_MakeThickSolid.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>

#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepPrimAPI_MakePrism.hxx>

#include <GC_MakeArcOfCircle.hxx>
#include <GC_MakeSegment.hxx>

#include <GCE2d_MakeSegment.hxx>

#include <gp.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax2d.hxx>
#include <gp_Dir.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Trsf.hxx>
#include <gp_Vec.hxx>

#include <Geom_CylindricalSurface.hxx>
#include <Geom_ConicalSurface.hxx>
#include <Geom_SphericalSurface.hxx>
#include <Geom_ToroidalSurface.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Surface.hxx>
#include <Geom_TrimmedCurve.hxx>

#include <Geom2d_Ellipse.hxx>
#include <Geom2d_TrimmedCurve.hxx>

#include <TopExp_Explorer.hxx>
#include <BRepTools_WireExplorer.hxx>

#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Compound.hxx>

#include <TopTools_ListOfShape.hxx>

#include <Interface_Static.hxx>
#include <APIHeaderSection_MakeHeader.hxx>
#include <TransferBRep_ShapeMapper.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <TDocStd_Document.hxx>
#include <XCAFApp_Application.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <StepData_StepModel.hxx>
#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
#include <StepShape_AdvancedFace.hxx>
#include <StepShape_OrientedEdge.hxx>
#include <StepShape_VertexPoint.hxx>
#include <StepShape_ManifoldSolidBrep.hxx>
#include <StepShape_EdgeCurve.hxx>
#include <STEPConstruct.hxx>
#include <XSControl_TransferWriter.hxx>
#include <Transfer_FinderProcess.hxx>
#include <Transfer_TransientMapper.hxx>
#include <TDF_LabelSequence.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <TDataStd_Name.hxx>
#include <STEPCAFControl_Writer.hxx>
#include <STEPControl_Reader.hxx>
#include <XSControl_WorkSession.hxx>
#include <XSControl_TransferReader.hxx>
#include <StepRepr_RepresentationItem.hxx>
#include <TCollection_HAsciiString.hxx>
#include <TopTools_HSequenceOfShape.hxx>

#include <iostream>
#include <map>

#include <stdio.h>
#include <vector>
#include <set>
#include <utility>
#include <list>
#include <algorithm>
#include <time.h>

Code: Select all

// stdafx.cpp : source file that includes just the standard includes
// STEPCAFControl_Writer.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
thatcadguy
Posts: 34
Joined: Mon Dec 17, 2012 6:22 pm
Location: CA, USA
Contact:

Re: Managing shapes names with STEP import/export

Post by thatcadguy »

I would also like to know how to do this. I have a script that generates a large assembly and OpenCascade gives each shape long-winded generic names.
User avatar
jriegel
Site Admin
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Managing shapes names with STEP import/export

Post by jriegel »

Hi,
we have here some fundamental problems.

First of all; its not possible so far in FreeCAD to set generic (user defined) names on subelements like faces, edges or vertexes. I'm not aware the big ones offer such a feature. And I don't think thats necessary. But I'm open for (good) arguments in that case ;)

Nevertheless, I don't think the naming in STEP is intended to give generic name, rather its a tool to transport links and references. Thats something we could resolve in a input processor to our own linking system (as all CADs do). The input processor of OpenCascade has some limitations, since the library itself is not containing all the concepts transported in STEP. So we will surly end up writing a STEP input processor on our own (e.g. based on stepcode.org) to handle all the data in STEP we have objects and features in FreeCAD.

But that have to be done.....
Stop whining - start coding!
gillesfouca
Posts: 13
Joined: Tue Jan 22, 2013 11:10 am

Re: Managing shapes names with STEP import/export

Post by gillesfouca »

jriegel wrote:Hi,
we have here some fundamental problems.

First of all; its not possible so far in FreeCAD to set generic (user defined) names on subelements like faces, edges or vertexes. I'm not aware the big ones offer such a feature.

SolidWorks supports name attribute on solids in STEP import/export : you can define the name of solids/faces/edges/vertices in the gui and this name is linked when exporting the part in STEP format. When importing a STEP file in SolidWorks, the names of faces are transferred. (see also screenshot showing SolidWorks after importing "Cube.STEP" file).
http://www.g-scop.fr/~foucault/images/Img001.png
In CATIA V5, the name of solids is correctly handled when importing STEP files (I did not find how to get the names of faces, edges, and vertices).
http://www.g-scop.fr/~foucault/images/Img002.png
jriegel wrote:And I don't think thats necessary. But I'm open for (good) arguments in that case ;)
This is necessary for passing information attached to B-Rep entities in downstream applications, here are some examples :
  • a STEP file representing an bolted assembly has to be prepared for Finite Element Analysis.
    The user needs to transform each bolt with a specific finite-element mesh generation procedure :
    the contact surface between the screw head and the tighten plate is meshed independently, and a contact model is defined on it ; the screw is meshed with a particular method, and a pre-load is applied to it, etc.
    To this end, the label of functional parts (screw, head, washer) composing the bolts are used to create a functional model, the label of faces representing bolts and its contacts with plates have to be transferred to the downstream FEA application to be processed.
  • in Virtual Reality, when simulating the assembly/disassembly of a product, we need to recognize kinematic joints between the handled component and the assembly : prismatic, revolute, planar... We need to associate constraints between the different faces/edges/vertices of mating components. To facilitate this process, we want to detect potential contacts in the CAD (with OpenCascade or FreeCAD), and then transfer this contacts information to the VR process (using labels, kinematical constraints between entities, and other useful informations for assembly/disassembly simulation).
jriegel wrote:Nevertheless, I don't think the naming in STEP is intended to give generic name, rather its a tool to transport links and references.
I do not agree, OpenCascade supports names in STEP entities because it is necessary to transfer links to entities (both geometric and non-geometric entities such as boundary conditions, loads, physical properties) in external applications.
jriegel wrote:Thats something we could resolve in a input processor to our own linking system (as all CADs do). The input processor of OpenCascade has some limitations, since the library itself is not containing all the concepts transported in STEP.


I do not agree, OpenCascade input/output processor handles names of STEP enities, the example code included in my initial post shows how OpenCascade reads names, and how it can write names in STEP.
jriegel wrote:So we will surly end up writing a STEP input processor on our own (e.g. based on stepcode.org) to handle all the data in STEP we have objects and features in FreeCAD.

But that have to be done.....
Could we at first try to read name attributes using the example code of my initial post, and store names as an attribute of B-Rep entities ?
User avatar
jriegel
Site Admin
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Managing shapes names with STEP import/export

Post by jriegel »

Ok, now I see what you want to do...

You use the names to do additional linking outside the STEP file. STEP has the concepts of kinematics or contact definitions (somewhere) and is build to use objects to indicate such information. Its surly not the preferred way to transport information about a face or vertex, since using informal definitions about some special names is very fragile. But I surly know that this kind of hacking is very useful.

So in FreeCAD we have a "name" for each vertex, edge, face, solid. But only the one of the solid (object) is generic. The rest is internal generated. You see the name in the status bar pre-selection message or when you select, e.g. vertex. This names are not written out at the moment (as far as I know). But the code is here:
https://sourceforge.net/p/free-cad/code ... tGuiPy.cpp
Write out our names should be pretty easy, read in names not so. As I said. Setting names on sub-elements is not implemented yet

We will rework the naming in the nearer future to get the parametric in PartDesign better working. Maybe we can consider generic names also:
http://www.freecadweb.org/wiki/index.ph ... ng_project
Stop whining - start coding!
gillesfouca
Posts: 13
Joined: Tue Jan 22, 2013 11:10 am

Re: Managing shapes names with STEP import/export

Post by gillesfouca »

jriegel wrote:You use the names to do additional linking outside the STEP file.


exactly.
jriegel wrote: Its surly not the preferred way to transport information about a face or vertex, since using informal definitions about some special names is very fragile.


I assume you consider cases where the topology of the B-Rep is modified during the import in the downstream application (during healing process or conformity process for example), then the name attribute is lost during the topology transformation. For example, if a Face is split into 2 sub-faces during the import in an application, then the name attribute is not necessarily copied to the 2 new faces (or the name attribute is not unique anymore).

In our context, we assume the downstream application is based on OpenCascade, and the imported STEP topology is identical to the original one.
jriegel wrote:But I surly know that this kind of hacking is very useful.


indeed.
jriegel wrote: So in FreeCAD we have a "name" for each vertex, edge, face, solid. But only the one of the solid (object) is generic. The rest is internal generated. You see the name in the status bar pre-selection message or when you select, e.g. vertex. This names are not written out at the moment (as far as I know). But the code is here:
https://sourceforge.net/p/free-cad/code ... tGuiPy.cpp
Write out our names should be pretty easy, read in names not so. As I said. Setting names on sub-elements is not implemented yet
Yes, writing "TNaming generic" names in STEP export is very useful for us.
I have read the C++ code of AppImportGuiPy.cpp : it seems easy to copy some code from my example to write names of each solid, face, edge, vertex.

Visual C++ 8 is already installed on my computer, Python 2.6 also, then I'm going to try to compile on windows and discover the FreeCAD code.
User avatar
jriegel
Site Admin
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Managing shapes names with STEP import/export

Post by jriegel »

We provide a LibPack on our download page which include all needed Libraries to compile FreeCAD on Windows. Thats the easiest way.

And we do not use TNaming! We have our own naming.

If you use anyway OCC for downstream why not directly integrate it as module in FreeCAD? You would getting around the hassle of mapping data?
Stop whining - start coding!
gillesfouca
Posts: 13
Joined: Tue Jan 22, 2013 11:10 am

Re: Managing shapes names with STEP import/export

Post by gillesfouca »

jriegel wrote:And we do not use TNaming! We have our own naming.
Ok, thanks for this clarification.
jriegel wrote:If you use anyway OCC for downstream why not directly integrate it as module in FreeCAD? You would getting around the hassle of mapping data?
Many tools based on OCC are not integrated into FreeCAD.

We consider data mapping to plain STEP AP214 files which are supported by CAD, CAE, CVE codes and not integrated into FreeCAD (simpoly (an old home-made tool based on OCC), Salome-ASTER, SAMCEF Field http://www.opencascade.com/customers/su ... n/samtech/, a pre-existing home-made OCC-based CVE http://www.springerreference.com/docs/h ... 73078.html, other non-OCC based software although the topology can be transformed during STEP Import).
User avatar
Epy
Posts: 34
Joined: Sun Nov 10, 2013 6:02 am
Location: CA, USA
Contact:

Re: Managing shapes names with STEP import/export

Post by Epy »

Has any progress been made in this area? I'm using FreeCAD to make a large assembly of shapes and I want to name each shape. In C++, I can do this by setting the name before transferring the shape to the STEPControl_Writer:

Code: Select all

STEPControl_Writer scw;
Interface_Static::SetCVal("write.step.product.name", "Test shape #1");
scw.Transfer(b3, STEPControl_AsIs);
scw.Write("test_1.stp");
Post Reply