How to save .step file with TopoDs_Shape and color them

Hello,
I am trying to split part with a .STEP file,I can get the TopoDs_Shape but when i save it the file was no color. I dont know why,Is me lost the color when i load it?
This is my code:

string ShapeToStep1(TopoDS_Shape shape) {
string route = "E:/Share/1/test.step";
const Standard_CString aFileName = route.c_str();
STEPControl_StepModelType type = STEPControl_AsIs;
STEPControl_Writer aWriter;
aWriter.Transfer(shape, STEPControl_AsIs);
aWriter.Write(aFileName);

return aFileName;
}

Dmitrii Pasukhin's picture

Hello,

STEPControl_Writer doesn't support any data instead of geometry. TopoDS_Shape contains only geometry. To work with color and other attributes you need to work with TDocStd_Document.

Please take a look into Extended Data Exchange (XDE) - Open CASCADE Technology Documentation

If you need an example how to attache a color into TopoDS_Shape, let me know. But in TopoDS_Shape you can't store any attributes.

Best regards, Dmitrii,

qifei9527's picture

Thanks,
I can save .step file with right color when i use STEPCAFControl_Writer,But when the TDF_Lable has TopoDs_Shape more than one how can i save .step with the part of label with them original color?

Dmitrii Pasukhin's picture

Please look into XCadDoc_Editor. I suggest, you need to create a new document and copy needed TDF_Label into new Doc (all reference attributes will be copy too)

If you will have some problem, with XcafDoc_Editor, let me know. This class has no very often usage.

Best regard, Dmitrii.

qifei9527's picture

Thanks,I will try it
I found anther one question .when i save the part of assemb with STEPCAFControl_Writer. The parts of them get wrong location.

Attachments: 
Dmitrii Pasukhin's picture

It is a normal case.You need to calculate global transform all all parents and update own transformation.

It is necessary to keep the same position on the scene.

Best regards, Dmitrii.

 

qifei9527's picture

You means get some information for TDF_Label?and how to change the part location? I dont know how to do this,Can you give me some specific method,Thanks

Dmitrii Pasukhin's picture

So, To change position of root you need to get Handle(XCafDoc_ShapeTool) from the document and then call aShTool->SetLocation(theRootL, theLocation, theNewRootL);

theNewRootL - label with moved location.

Best regards, Dmitrii.

 

qifei9527's picture

Sorry,I can't find any function about SetLocation(theRootL, theLocation, theNewRootL) in OCCT.
thanks.

Dmitrii Pasukhin's picture

It was implemented into OCCT 7.7.0

If you use older version, please copy-past a code to your solution from new version.

Best regards, Dmitrii.

qifei9527's picture

sorry,I'm still can't find this function.Is it contained by TDocStd_Document.hxx or XCAFDoc_ShapeTool.hxx?I only can find TopLoc_Location GetLocation (const TDF_Label &L).

Dmitrii Pasukhin's picture
qifei9527's picture

I think when i get the part label i'm already get wrong location or lost shape location.The location for .STEP what i saved was moved to origin.How do i get the original location.
Here is my code:

bool test(Standard_CString fileloc) {
Handle(TDocStd_Document) aDocument = ReadSTEPToDocument(fileloc);
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDocument->Main());
TDF_LabelSequence aRootLabels;
aShapeTool->GetFreeShapes(aRootLabels);
TDF_Label labelMain;
std::vector vecShapelabels;
for (TDF_LabelSequence::Iterator aRootIter(aRootLabels); aRootIter.More(); aRootIter.Next())
{
const TDF_Label& aRootLabel = aRootIter.Value();

if (XCAFDoc_ShapeTool::IsAssembly(aRootLabel))
{
if (labelMain.IsNull())
{
labelMain = aRootLabel;
}
}
GetAssemblyShapes(aRootLabel, vecShapelabels);
char* namee;
std::vector vecShapelabels11;
for (auto it_ls = vecShapelabels.begin(); it_ls != vecShapelabels.end(); ++it_ls)
{

std::string sss = "test.STEP";

auto L2 = aShapeTool->GetLocation(*it_ls);
TDF_Label anewlabel;
bool setloc = aShapeTool->SetLocation(*it_ls, L2, anewlabel);
WriteStepByXDE(sss.c_str(), anewlabel);


}
}
return true;
}

Thanks.

Attachments: 
qifei9527's picture

I found I can't get any location from TDF_Label by GetLocation (const TDF_Label& L).This function always return false When i use SetLocation (const TDF_Label& theShapeLabel, const TopLoc_Location& theLoc, TDF_Label& theRefLabel) By a TopLoc_Location like jpg2.

Attachments: 
Webeye IoT's picture

is there any visual studio .sln file to read the step file and .d file. i want to read both the file. in open cascade

Dmitrii Pasukhin's picture

Hello,

Can you describe your goal a little detailed?

OCCT repo contains a few .step to test. Moreover, you be able to dowload installed solution from Download - Open CASCADE Technology

Best regards, Dmitrii.