Exportieren von farbigen STEP-Dateien in OpenCASCADE
English
Deutsch
OCCUtils stellt einen einfachen Weg zum Exportieren eines STEP mit farbigen Elementen bereit:
make_colored_step.cpp
#include <occutils/ExtendedSTEP.hxx>
#include <occutils/Primitive.hxx>
TopoDS_Shape cube = Primitive::MakeCube(5 /* mm */);
STEP::ExtendedSTEPExporter stepExporter;
stepExporter.AddShapeWithColor(cube, Quantity_NOC_RED);
stepExporter.Write("ColoredCube.step");Die resultierende STEP-Datei sieht so aus:

Du kannst auch nicht farbige Shapes hinzufügen:
add_shape_no_color.cpp
stepExporter.AddShape(myShape);Es ist möglich, es ohne OCCUtils zu tun, aber es könnte dein Leben erschweren, da es ziemlich schwer ist, es korrekt zum Laufen zu bringen.
Hier ist ein minimales Beispiel:
minimal_colored_step.cpp
// Globale Anwendung abrufen
Handle(TDocStd_Application) application = XCAFApp_Application::GetApplication();
// Dokument erstellen
Handle(TDocStd_Document) document;
application->NewDocument("MDTV-XCAF", document);
// Shape- und Color-Tools abrufen
Handle(XCAFDoc_ShapeTool) shapeTool = XCAFDoc_DocumentTool::ShapeTool(document->Main());
Handle(XCAFDoc_ColorTool) colorTool = XCAFDoc_DocumentTool::ColorTool(document->Main());
// Shape erstellen
// WICHTIG: Verwende NICHT shapeTool->AddShape(TopoDS_Shape)!
// Dies wird die Farbe NICHT bewahren!
TDF_Label partLabel = shapeTool->NewShape();
shapeTool->SetShape(partLabel, filletedBody);
//TDF_Label redColor = colorTool->AddColor();
colorTool->SetColor(partLabel, Quantity_NOC_RED, XCAFDoc_ColorGen);
STEPCAFControl_Writer writer;
writer.SetColorMode(true);
writer.Perform(document, "ColoredShape.step");Welche Farben kannst du verwenden?
Definiere entweder die Quantity_Color selbst mit RGB-Werten (von 0.0 bis 1.0) so:
color_rgb.cpp
Quantity_Color red(1.0 /* R */, 0.0 /* G */, 0.0 /* B */, Quantity_TypeOfColor::Quantity_TOC_RGB);alternativ kannst du dasselbe im HSL-Farbraum tun:
color_hsl.cpp
Quantity_Color brownishOrange(1.0 /* H */, 0.5 /* L */, 0.5 /* S */, Quantity_TypeOfColor::Quantity_TOC_HLS);or you can use the predefined colors in the Quantity_NameOfColor enum - see Overview of all standard colors available in OpenCASCADE for a table of all available colors.
Check out similar posts by category:
C/C++, OpenCASCADE
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow