STEP/IGES color

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
cristian.a73
Posts: 41
Joined: Wed Jul 18, 2018 4:15 pm

STEP/IGES color

Post by cristian.a73 »

Hi community
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());
    }
}
python code :

Code: Select all

    s = Part.Shape()
    s.read(inFile)
    doc = FreeCAD.newDocument('doc')
    partFeature = doc.addObject("Part::Feature", "MainShape")
    partFeature.Shape = s
Now I've these problem :

#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
User avatar
easyw-fc
Veteran
Posts: 3629
Joined: Thu Jul 09, 2015 9:34 am

Re: STEP/IGES color

Post by easyw-fc »

cristian.a73 wrote: Thu Jul 19, 2018 2:42 pm Hi community
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

....

Now I've these problem :

#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
from @wmayer post
It is also possible to export STEP models with color information from the command line.
https://forum.freecadweb.org/viewtopic. ... 94#p187294
User avatar
cristian.a73
Posts: 41
Joined: Wed Jul 18, 2018 4:15 pm

Re: STEP/IGES color

Post by cristian.a73 »

easyw-fc wrote: Fri Jul 20, 2018 7:34 am
from @wmayer post
It is also possible to export STEP models with color information from the command line.
https://forum.freecadweb.org/viewtopic. ... 94#p187294
Thank you for your reply
Exporting the face's color, by a such easy way as you written, is very usefully... but please note I'm going to import data without GUI
Is there a same simple way to import face's color like that ? it's could be great
Last edited by cristian.a73 on Fri Jul 20, 2018 6:14 pm, edited 1 time in total.
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: STEP/IGES color

Post by chrisb »

cristian.a73 wrote: Fri Jul 20, 2018 1:31 pm (quoted and even more quoted text)
Cristian, quoting is good, but please concentrate on what is important being quoted.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: STEP/IGES color

Post by wmayer »

#1 : there's no faces in the shape (please note original STEPControl_Reader was replaced by STEPCAFControl_Reader ).. why ?
I strongly recommend not to make changes in the TopoShape class as we don't want to have a dependency to the OCAF framework in the Part module. Instead have a look at the sources of the Import module. This module handles reading & writing of STEP files with additional information.
#2 : how to read and store face's color ?
To store faces use the above mentioned methods. To read colors in there is currently no way to keep them but it shouldn't be too difficult to get them. Under Mod/Import/App/ImportOCAF.h you will find the class ImportOCAF with the virtual method applyColors which at the moment does nothing.
freecad-heini-1
Veteran
Posts: 7788
Joined: Tue Jan 07, 2014 11:10 am
Contact:

Re: STEP/IGES color

Post by freecad-heini-1 »

cristian.a73 wrote: Thu Jul 19, 2018 2:42 pm 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.
Hi Cristian, please can you give me a bit more background information concerning the colors for molds for milling / edm, a link to a webpage or something else. Thank you so much.
Best regards
Wilfried
User avatar
cristian.a73
Posts: 41
Joined: Wed Jul 18, 2018 4:15 pm

Re: STEP/IGES color

Post by cristian.a73 »

to wmayer :
simple tip, great help
Due to my entry level skill in Freecad.sourceCode I was focuset out by python code Shape.read -> TopoShape.import...now I'm goindo to use ImportOCAF and store colors info as you written... a big thank you


to freecad-heini-1 :
Is not easy to find out informations about this on the net...what I've is a paper with a table of colors and info in italian language, but the base idea is simple : avoid 2d drawing sheet of the files with complex surface where possible
...and mill by high accuracy only the needed surfaces
Still you can full avoid 2D drawing sheet by PMI in the cad (geometric tolerance and quotations...even if not all the editor support it [SolidEdge,SolidWorks,Catia,NX,ProE,Cimatron] ), and file 3D PDF as neutral document but this take place more rarely than colors usage

Hope this help

Thank you, sincerely
Cristian

http://cristianandreon.eu
http://cnconline.info

Image
polymer
Posts: 278
Joined: Fri Sep 12, 2014 8:49 am

Re: STEP/IGES color

Post by polymer »

User avatar
cristian.a73
Posts: 41
Joined: Wed Jul 18, 2018 4:15 pm

Re: STEP/IGES color

Post by cristian.a73 »

polymer wrote: Fri Aug 24, 2018 6:39 pm Maybe this is usefull: https://www.meusburger.com/EN/US/media/ ... rds_IN.pdf
Yessss!!!
Thank you
freecad-heini-1
Veteran
Posts: 7788
Joined: Tue Jan 07, 2014 11:10 am
Contact:

Re: STEP/IGES color

Post by freecad-heini-1 »

polymer wrote: Fri Aug 24, 2018 6:39 pm Maybe this is usefull: https://www.meusburger.com/EN/US/media/ ... rds_IN.pdf
Great. Thank you so much Polymer and Cristian.
Post Reply