For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Exporting list of named points to STEP

Bernd Noetenhuber's picture
Forums: 

In our project, would like to export a list of named points so that they are readable by "standard CAD software". In particular, we have a list of points like

"Point Kevin" : (1, 2, 3)
"Point John" : (3, 4, 5)
...

that we want to export to a STEP file. See below for the code we have come up with so far. Maybe someone could give us some pointers as to

(1) whether this approach makes any sense (i.e. creating a vertex for every point and exporting a geometric curve set), or how to improve upon it

(2) how to add the naming information (each point has a name) to the file exported.

thx
Bernd

---------------- CODE -----------------

STEPControl_Writer writer;

STEPControl_StepModelType type = STEPControl_GeometricCurveSet;

gp_Pnt aPnt1(0, 1, 2);
TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(aPnt1);
IFSelect_ReturnStatus status = writer.Transfer( vertex , type );

gp_Pnt aPnt2(9, 7, 5);
TopoDS_Vertex vertex2 = BRepBuilderAPI_MakeVertex(aPnt2);
status = writer.Transfer( vertex2 , type );

writer.Write("C:\\Users\\noetenhub\\Desktop\\test.stp");

Dennis G.'s picture

Hello Bernd,

I think that the easiest way to keep the naming information is to use the OpenCascade Application Framework.
First you need to implement the OCAF structure to your program. This is quite easy, as described on Romans OCC Blog: http://opencascade.blogspot.com/2008/12/adding-colors-and-names-to-your.html

Once your program is ready to use the application framework you can append TopoDS_Shapes via the XCAFDoc_ShapeTool to your TDocStd_Document; on the same TDF_Label you can then append the TDataStd_Name of the vertex. Finally you export the TDocStd_Document via the STEPCAFControl_Writer

The code could look like this:

------------------------ Improved Code ------------------------------
STEPCAFControl_Writer writer;

Handle(TDocStd_Document) theTDoc;
myXCAFApp->NewDocument("XmlXCAF", theTDoc);
Handle(XCAFDoc_ShapeTool) sTool = XCAFDoc_DocumentTool::ShapeTool(theTDoc->Main());

gp_Pnt aPnt1(0, 1, 2);
TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(aPnt1);
TDF_Label shpLab = sTool->AddShape(vertex); // create new Label and add Vertex

Handle(TDataStd_Name) shpNm;
TCollection_ExtendedString theName("Point John");
shpNm->Set(shpLab, theName); // add the Name to the Label which already contains the TopoDS_Vertex

STEPCAFControl_Writer wrtr;
wrtr.SetNameMode(1);
wrtr.Transfer(theTDoc);
wrtr.Write("FileName.stp");

----------------------------------------------

The above code is not tested. I hope it helps.

Cheers,

Dennis

Bernd Noetenhuber's picture

Thank you for the quick reply! We got it to work this way! However, two problems remain:

(1) The STEP file generated specifies two identical vertices (#16, #18) instead of one, see below for the output file.

(2) The name is attached to the "product" (see http://img130.imageshack.us/img130/2374/catiascreenshotpointjoh.png for a screenshot of the tree in CATIA) rather than to the points themselves. Is there a way to "push down" the name to the actual points (currently generically named "CARTESIAN_POINT")?

Thank you,
Bernd

----------------- STEP file --------------

ISO-10303-21;
HEADER;
FILE_DESCRIPTION(('Open CASCADE Model'),'2;1');
FILE_NAME('Open CASCADE Shape Model','2009-11-25T10:43:34',('Author'),(
'Open CASCADE'),'Open CASCADE STEP processor 6.3','Open CASCADE 6.3'
,'Unknown');
FILE_SCHEMA(('AUTOMOTIVE_DESIGN_CC2 { 1 2 10303 214 -1 1 5 4 }'));
ENDSEC;
DATA;
#1 = APPLICATION_PROTOCOL_DEFINITION('committee draft',
'automotive_design',1997,#2);
#2 = APPLICATION_CONTEXT(
'core data for automotive mechanical design processes');
#3 = SHAPE_DEFINITION_REPRESENTATION(#4,#10);
#4 = PRODUCT_DEFINITION_SHAPE('','',#5);
#5 = PRODUCT_DEFINITION('design','',#6,#9);
#6 = PRODUCT_DEFINITION_FORMATION('','',#7);
#7 = PRODUCT('Point_John','Point_John','',(#8));
#8 = MECHANICAL_CONTEXT('',#2,'mechanical');
#9 = PRODUCT_DEFINITION_CONTEXT('part definition',#2,'design');
#10 = SHAPE_REPRESENTATION('',(#11,#15,#17),#19);
#11 = AXIS2_PLACEMENT_3D('',#12,#13,#14);
#12 = CARTESIAN_POINT('Hines Claus',(0.E+000,0.E+000,0.E+000));
#13 = DIRECTION('',(0.E+000,0.E+000,1.));
#14 = DIRECTION('',(1.,0.E+000,-0.E+000));
#15 = GEOMETRIC_CURVE_SET('',(#16));
#16 = CARTESIAN_POINT('',(0.E+000,1.,2.));
#17 = GEOMETRIC_CURVE_SET('',(#18));
#18 = CARTESIAN_POINT('',(0.E+000,1.,2.));
#19 = ( GEOMETRIC_REPRESENTATION_CONTEXT(3)
GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#23)) GLOBAL_UNIT_ASSIGNED_CONTEXT(
(#20,#21,#22)) REPRESENTATION_CONTEXT('Context #1',
'3D Context with UNIT and UNCERTAINTY') );
#20 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );
#21 = ( NAMED_UNIT(*) PLANE_ANGLE_UNIT() SI_UNIT($,.RADIAN.) );
#22 = ( NAMED_UNIT(*) SI_UNIT($,.STERADIAN.) SOLID_ANGLE_UNIT() );
#23 = UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(1.E-007),#20,
'distance_accuracy_value','confusion accuracy');
#24 = PRODUCT_TYPE('part',$,(#7));
ENDSEC;
END-ISO-10303-21;

Dennis G.'s picture

Okay, good to know. Up to now I didn't realize that this procedure names the PRODUCT. I haven't used it, but perhaps you might want to take a look at the TNaming package. Especially the classes TNaming_NamedShape, TNaming_Name and TNaming_Naming. As I understand this classes allow the naming of topological elements of a model.
If you are successful with this approach, I would appreciate it if you would reply to this post.

Viele Grüße,

Dennis

Zia ul Azam's picture

Hello,

I am also facing the similar problem. I also want to set the name of CARTESIAN_POINT in STEP file but right now I am only able to write the name to GEOMETRIC_CURVE_SET because when I extract the entity using FinderProcess and set the name, the name only gets set to GEOMETRIC_CURVE_SET but not CARTESIAN_POINT.

Please note that I am using STEPControl_Writer and the STEPControl_StepModelType is set as STEPControl_AsIs. I have tested other model types but they also not work.

Following is the short code snippet for reference:

TopoDS_Shape shape; // assume some shape is there to be wrtitten i.e point in this case

const STEPControl_StepModelType modelType = STEPControl_AsIs;

STEPControl_Writer writer;

IFSelect_ReturnStatus status = writer.Transfer(shape, modelType, Standard_False);

Handle(StepRepr_RepresentationItem) representationItem = STEPConstruct::FindEntity(FinderProcess(), shape);

const Handle(TCollection_HAsciiString)& name = new TCollection_HAsciiString("Point Name");

representationItem->SetName(name);

...

writer.WS()->ComputeGraph(Standard_True);

const IFSelect_ReturnStatus status = writer.Write(someFilePath);

The relevant section of output STEP file is :

#15 = GEOMETRIC_CURVE_SET('Point Name',(#16));
#16 = CARTESIAN_POINT('',(0.E+000,1.,2.));

I am looking forward for a response. Thank you.

Regards,

Zia ul Azam

Benjamin Bihler's picture

CATIA does not associate the name from #15 with #16 in the following lines:

#15 = GEOMETRIC_CURVE_SET('Point Name',(#16));
#16 = CARTESIAN_POINT('',(0.E+000,1.,2.));

Therefore in CATIA the cartesian point will be named "CARTESIAN_POINT #16" instead of "Point Name" which is ugly!!! Is this a CATIA problem? Or should the OCCT STEP export write the name also into entity #16? Does anyone know a CAD program that can associate the STEP names exported by OCCT with the correct geometric primitives?

Benjamin Bihler's picture

Has anyone ever been able to write STEP files with OCCT that contained names which were correctly interpreted by any CAD software? At least OCCT -> CATIA seems not to work at all!?!?

qa qa's picture

Have you ever tried OnShape? It is based on the Parasolid kernel.

qa qa

Benjamin Bihler's picture

Thanks for the hint! Onshape indeed interprets the names in a different way. There they are correctly assigned to the geometric primitives. :-)

If I have understood the OCCT STEP export code correctly, there is no way to write the names also into the definition of the geometric primitives. Therefore there is probably no way to transfer geometry names from OCCT to CATIA. :-(

Benjamin

Andrey BETENEV's picture

Hello Benjamin,

Currently OCCT STEP translator does not assign names to geometric entities; this can be implemented if needed, provided that there is clear understanding on what should be written.

Andrey

Benjamin Bihler's picture

Hello Andrey,

thanks for your answer. Then at least I have not overlooked anything.

We will check whether we can make a clear proposal on what to write for making CATIA read in the STEP names correctly.

Benjamin

Zia ul Azam's picture

Hello,

I have found a way to pass names to geometric entities. If the dynamic type of a shape's corresponding STEP entity is checked then it gives a useful hint about which corresponding OCCT classes have to be considered to extract the required geometric entities. Then the names can be set of these extracted geometric entities. Here is a short code snippet to clear the idea.

STEPControl_Writer writer;

const Handle(XSControl_WorkSession)& writerWorkSession = writer.WS();

STEPConstruct_Styles style(writerWorkSession);

ShapeDefinition shapeDefinition ... ; // assume a ShapeDefinition class with name and shape itself as fields

Handle(StepRepr_RepresentationItem) representationItem = STEPConstruct::FindEntity(style.FinderProcess(), shapeDefinition.shape);

Standard_OStream& stream = std::cout;

representationItem->DynamicType()->Print(stream); // for vertex and wires it is StepShape_GeometricCurveSet

const Handle(TCollection_HAsciiString)& name = new TCollection_HAsciiString(shapeDefinition.name);

if (representationItem->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) // StepShape_GeometricSet is super class of ...CurveSet

{   

Handle(StepShape_GeometricSet) geometricSet = Handle(StepShape_GeometricSet)::DownCast(representationItem);

for (int index = 1; index <= geometricSet->NbElements(); ++index)

{

StepShape_GeometricSetSelect entity =  geometricSet->ElementsValue(index);

Handle(StepGeom_Point) point =  entity.Point();

Handle(StepGeom_Curve) curve = entity.Curve();

Handle(StepGeom_Surface) surface = entity.Surface();

// now you can set names of the above extracted primitives

// e.g for the point

if (!point.IsNull())

{

point->SetName(name);

}



}

}

I hope this helps.

Regards,

Zia ul Azam

Benjamin Bihler's picture

Andrey, would you propose that I register an issue in the bug tracker for that? If there was a configuration setting "assign names to geometric entities" which would lead to an automatic assignment like the one described by Zia, then by activating this setting the STEP files export could be easily adapted to be optimal for CATIA users. On the other hand if wires are always exported as edges and the names can only be assigned to one of those edges like mentioned in the last post, then this "solution" is perhaps no solution at all. :-(

Please share your opinion. Thank you.

Andrey BETENEV's picture

Sure the optimal way to proceed is to register an issue and submit a patch for it. Regarding the wires, the situation is not fully clear to me but I am sure this can be solved some way.

Zia ul Azam's picture

Hello,

I am facing a problem when writing the name of a wire. The STEP writer separates a wire into edges when writing to the STEP file.

The following forum post refers to the same problem: https://www.opencascade.com/content/save-wire-step-file

When I try to write the name of the extracted entity from finder process for corresponding wire then (in the same way as my posted solution above):

- checking its dynamic type which is StepShape_GeometricCurveSet

​- extracting curve from StepShape_GeometricShapeSelect

​- downcasting curve to StepGeom_TrimmedCurve and setting the name of the BasisCurve of TrimmedCurve

This way I am only able to set the name for only one of the edges of the wire because I only get one extracted entity from finder process for the wire.

Can anybody suggest a hint about where to look in order to set the name of all the edges of a wire?

Thank you.

Regards,

Zia ul Azam

Zia ul Azam's picture

Hi,

I have registered an issue for this workaround at: https://tracker.dev.opencascade.org/view.php?id=29375

This workaround for setting names of underlying geometric entities should be available in OCCT so that the exported names can be viewed in CATIA.

Regards,

Zia