My name is cristian and I'm new to the forum
In automotive environment (and molds too) the color of a surface is used to set accuracy in the milling machines, so a drawing is not needed to define the precision of the faces
From several days I'm going to modify FreeCAD in order to store the color (Quantity_color) information in the right class, and then make the data available for access by python
It's hard to do because in my app run in console (FreeCADCmd) and ViewObject property is not defined
In TopoShape.cpp my changes is :
Code: Select all
void TopoShape::importStep(const char *FileName)
{
try {
STEPCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile(encodeFilename(FileName).c_str()) != IFSelect_RetDone)
throw Base::Exception("Error in reading STEP");
Handle(Message_ProgressIndicator) pi = new ProgressIndicator(100);
aReader.Reader().WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading STEP file...");
pi->Show();
// old STEPCAFControl_Reader Root transfers :
// aReader.TransferRoots();
Handle(TDocStd_Document) hDoc;
TDF_LabelSequence Lab_Shapes, Lab_Faces;
char str[512];
XCAFApp_Application::GetApplication()->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
int nDocs = XCAFApp_Application::GetApplication()->NbDocuments();
sprintf(str, "nDocs:%d", nDocs);
pi->NewScope(100, str);
pi->Show();
if (!aReader.Transfer(hDoc)) {
pi->NewScope(100, "Transfer STEP file enttities failed!");
pi->Show();
} else {
// XCAFDoc_ColorType colType = XCAFDoc_ColorSurf;
Handle(XCAFDoc_ShapeTool) l_ShapeTool = XCAFDoc_DocumentTool::ShapeTool(hDoc->Main());
Handle(XCAFDoc_ColorTool) l_ColorTool = XCAFDoc_DocumentTool::ColorTool(hDoc->Main());
l_ShapeTool->GetShapes(Lab_Shapes);
int n = Lab_Shapes.Length();
sprintf(str, "Processing %d shape(s)...", n);
pi->NewScope(100, str);
pi->Show();
for (int i = 1; i <= n; i++) {
Quantity_Color colorG, colorS, colorC;
if( l_ColorTool->GetColor(Lab_Shapes.Value(i), XCAFDoc_ColorGen, colorG) ||
l_ColorTool->GetColor(Lab_Shapes.Value(i), XCAFDoc_ColorSurf, colorS) ||
l_ColorTool->GetColor(Lab_Shapes.Value(i), XCAFDoc_ColorCurv, colorC) ) {
sprintf(str, "Shape #%d color:%s-%s-%s", i+1, colorG.StringName(colorG.Name()), colorS.StringName(colorS.Name()), colorC.StringName(colorC.Name()));
pi->NewScope(100, str);
pi->Show();
}
}
}
}
catch (Standard_Failure& e) {
throw Base::Exception(e.GetMessageString());
}
}
Code: Select all
s = Part.Shape()
s.read(inFile)
doc = FreeCAD.newDocument('doc')
partFeature = doc.addObject("Part::Feature", "MainShape")
partFeature.Shape = s
#1 : there's no faces in the shape (please note original STEPControl_Reader was replaced by STEPCAFControl_Reader ).. why ?
#2 : how to read and store face's color ?
Thank you
Cristian