How to write 3D annotation information into STEP-file

TLohi

CAD practitioner
Hi,

I'am tyring to add 3D annotation information to STEP file. Basically I want to add Annotation, that contains points location, orientation and name to vertex or cartesian point. Any Ideas how to achieve this using OCCT?
 

TLohi

CAD practitioner
Here is what I have tried


TopoDS_Shape box = BRepPrimAPI_MakeBox(10,10,10);
std::shared_ptr<STEPControl_Writer> writer = std::make_shared<STEPControl_Writer>();
Interface_Static::SetCVal("write.step.schema", "AP242DIS");
writer->Transfer(box, STEPControl_AsIs);

Handle(XSControl_WorkSession) ws = writer->WS();
Handle(StepData_StepModel) model = Handle(StepData_StepModel)::DownCast(ws->Model());
Interface_Graph graph = ws->Graph();
Handle(StepRepr_DescriptiveRepresentationItem) descriptiveRepresentationItem = nullptr;

for (int i = 1; i <= model->NbEntities(); i++){
Handle(Standard_Transient) entity = model->Entity(i);
if(!entity->IsKind(STANDARD_TYPE(StepRepr_PropertyDefinition))){
continue;
}
Handle(StepRepr_PropertyDefinition) propertyDefinition = Handle(StepRepr_PropertyDefinition)::DownCast(entity);

Handle(StepRepr_PropertyDefinitionRepresentation) propertyDefinitionRepresentation = nullptr;
Interface_EntityIterator itPDR = graph.Sharings(propertyDefinition);
for (; itPDR.More(); itPDR.Next()){
propertyDefinitionRepresentation = Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(itPDR.Value());
if(!propertyDefinitionRepresentation.IsNull()){
break;
}
}
if (propertyDefinitionRepresentation.IsNull()){
continue;
}
Handle(StepRepr_Representation) repr = propertyDefinitionRepresentation->UsedRepresentation();

Handle(StepRepr_DescriptiveRepresentationItem) descRepr = new StepRepr_DescriptiveRepresentationItem();
descRepr->Init(new TCollection_HAsciiString("equivalent unicode string"), new TCollection_HAsciiString(
"COR\\wCoordinate Note\\nUser Defined\\nUser Defined\\n-\\nx=10\\ny=10\\nz=10"));
GeomToStep_MakeCartesianPoint geomStepMaker(gp_Pnt(-1,-1,-1));
Handle(StepGeom_CartesianPoint) stepGeomTo3D = geomStepMaker.Value();
stepGeomTo3D->SetName(new TCollection_HAsciiString("point"));

Handle(StepRepr_HArray1OfRepresentationItem) CSs = new StepRepr_HArray1OfRepresentationItem(1,2);
CSs->SetValue(1, stepGeomTo3D);
CSs->SetValue(2, descRepr);

Handle(StepGeom_GeometricRepresentationContext)reprContext = new StepGeom_GeometricRepresentationContext();
reprContext->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), 3);

Handle(StepRepr_Representation) repr2 = new StepRepr_Representation();
repr2->Init(new TCollection_HAsciiString(), CSs, reprContext);
propertyDefinitionRepresentation->SetUsedRepresentation(repr2);

model->AddEntity(descRepr);
model->AddEntity(stepGeomTo3D);
model->AddEntity(reprContext);
model->AddEntity(propertyDefinition);
model->AddEntity(propertyDefinitionRepresentation);
model->AddEntity(repr2);
}

std::string path = "C:/stp/shape_withCS.stp";
writer->Write(path.c_str());
sorry, ":" + "D" is presented as :D and I don't know how to stop this
 
Last edited:

JSlyadne

Administrator
Staff member
Here is what I have tried



sorry, ":" + "D" is presented as :D and I don't know how to stop this
Hey TLohi!

Can't say that I'm experienced a lot in STEP translator of OCCT, I've never tried it by myself even (only in very trivial way), but I still prefer to leave a couple of thoughts I have which might be give you more ideas where to go.

You deal with STEPControl_Writer class what means that it's you who will be responsible for proper initialization all required STEP entities, like ANNOTATION_PLACEHOLDER_OCCURRENCE, GEOMETRIC_SET, ANNOTATION_PLANE, TESSELLATED_ANNOTATION_OCCURRENCE and so on, and setting the proper references between them. I don't have a good reason why you might need to mess around such a low level routine, only if you're not a guru of ISO standard of STEP format. Instead, OCCT offers XDE, extended data structure based on OCAF for storing meta data such as colors, layers and PMIs, and STEPCAFControl_Writer that extends basic STEPControl_Writer with possibility to treat the mentioned meta data.

So that, if you still prefer to stick to STEPControl_Writer, you might want to dig into STEPCAFControl_Writer to get an idea what is missed in your piece of code.

If you feel STEPCAFControl_Writer suits you, you'll need to create an XDE document and feed it by shapes and annotations with a help of XCAFDoc_DimTolTool and other related classes of TKXCAF package. As far as I understand, the annotations represent as XCAFDimTolObjects_GeomToleranceObject objects in OCCT. Some insight you can find in Draw commands, see ...\src\XDEDRAW\XDEDRAW_GDTs.cxx.
 

TLohi

CAD practitioner
Hey TLohi!

Can't say that I'm experienced a lot in STEP translator of OCCT, I've never tried it by myself even (only in very trivial way), but I still prefer to leave a couple of thoughts I have which might be give you more ideas where to go.

You deal with STEPControl_Writer class what means that it's you who will be responsible for proper initialization all required STEP entities, like ANNOTATION_PLACEHOLDER_OCCURRENCE, GEOMETRIC_SET, ANNOTATION_PLANE, TESSELLATED_ANNOTATION_OCCURRENCE and so on, and setting the proper references between them. I don't have a good reason why you might need to mess around such a low level routine, only if you're not a guru of ISO standard of STEP format. Instead, OCCT offers XDE, extended data structure based on OCAF for storing meta data such as colors, layers and PMIs, and STEPCAFControl_Writer that extends basic STEPControl_Writer with possibility to treat the mentioned meta data.

So that, if you still prefer to stick to STEPControl_Writer, you might want to dig into STEPCAFControl_Writer to get an idea what is missed in your piece of code.

If you feel STEPCAFControl_Writer suits you, you'll need to create an XDE document and feed it by shapes and annotations with a help of XCAFDoc_DimTolTool and other related classes of TKXCAF package. As far as I understand, the annotations represent as XCAFDimTolObjects_GeomToleranceObject objects in OCCT. Some insight you can find in Draw commands, see ...\src\XDEDRAW\XDEDRAW_GDTs.cxx.
Hi,
Thanks for help.

Yeah, dealing with low level STEP stuff is hard.
Actually I tried doing annotations with StepCAFControl_Writer and XCAF but I haven't had any success so far. Maybe I should do deeper dive into TKXCAF package.
 
Top