OCC and STEP assembly structure support and STEP file size

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
easyw-fc
Posts: 2851
Joined: Thu Jul 09, 2015 9:34 am

OCC and STEP assembly structure support and STEP file size

Postby easyw-fc » Wed Oct 19, 2016 7:22 pm

Hi, recently I tried OCC Assistant for android and then I tested it for windows and I noticed that opening the included STEP example file 'as1-oc-214.stp' this STEP file has an assembly structure...
1) the STEP file inside the OCC Assistant displays the assembly structure
2) if saved the STEP file will conserve the assembly structure
3) opening the file i.e. with DesignSparks, it will display correctly the assembly structure...

The same file when open in FC will lose the assembly structure and if saved the structure will be lost...
Moreover the file dimension, if saved in OCC Assistant will save about 2 and half size of the file exported to STEP by FC (169KB vs 425KB)

Then here come my question... is it possible to adopt OCC Assistant way to export STEP in FreeCAD to conserve assembly structure and get a better file size?
here the header of the two files:

Code: Select all

ISO-10303-21;
HEADER;
FILE_DESCRIPTION(('FreeCAD Model'),'2;1');
FILE_NAME('C:/cad_assistant/samples/as1-oc-214-fc.step',
  '2016-10-19T21:10:41',('Author'),(''),
  'Open CASCADE STEP processor 7.0','FreeCAD','Unknown');
FILE_SCHEMA(('AUTOMOTIVE_DESIGN_CC2 { 1 2 10303 214 -1 1 5 4 }'));
ENDSEC;
DATA;
#1 = APPLICATION_PROTOCOL_DEFINITION('committee draft',
  'automotive_design',1997,#2);
#2 = APPLICATION_CONTEXT(
  'core data for automotive mechanical design processes');

Code: Select all

ISO-10303-21;
HEADER;
FILE_DESCRIPTION((
    'CAx-IF test model AS1: Geometric Validation Properties'),'2;1');
FILE_NAME('Open CASCADE Shape Model','2016-10-19T21:00:57',('abv'),(
    'Open CASCADE'),'Open CASCADE STEP processor 7.0',
  'Open CASCADE 6.8 DRAW','Unknown');
FILE_SCHEMA(('AUTOMOTIVE_DESIGN_CC2 { 1 2 10303 214 -1 1 5 4 }'));
ENDSEC;
DATA;
#1 = APPLICATION_PROTOCOL_DEFINITION('committee draft',
  'automotive_design',1997,#2);
#2 = APPLICATION_CONTEXT(
  'core data for automotive mechanical design processes');
that OCC Assistant way to manage STEP file may be also useful for the job that @vejmarie is doing for multi-threading here
viewtopic.php?f=10&t=16952&start=10
vejmarie wrote: I am able to build the STEP tree and translate that into FreeCAD GUI as Compound and parts respecting the STEP format. This means easier selection of sub assemblies (which was not possible before), and faster browsing into the STEP. I am currently working on improving read time. I expect to issue some PR within the week, if I am lucky and have enough time. Next step will be export ;)
Maurice
Last edited by easyw-fc on Fri Oct 21, 2016 8:31 pm, edited 1 time in total.
triplus
Posts: 9464
Joined: Mon Dec 12, 2011 4:45 pm

Re: OCC and STEP assembly structure support

Postby triplus » Wed Oct 19, 2016 9:07 pm

In the discussion about FreeCAD assembly infrastructure @ickby wrote:
4. What if document formats allow to reuse subassemblies at multiple positions? I think STEP does that (need to double check that) and so we would loose an easy import/export and must change the document structure
viewtopic.php?f=10&t=17864#p140617

I don't know if this is directly related to your proposal but it does look like STEP assembly support is related to FreeCAD assembly infrastructure that yet has to materialize.
User avatar
easyw-fc
Posts: 2851
Joined: Thu Jul 09, 2015 9:34 am

Re: OCC and STEP assembly structure support

Postby easyw-fc » Wed Oct 19, 2016 9:35 pm

triplus wrote:I don't know if this is directly related to your proposal but it does look like STEP assembly support is related to FreeCAD assembly infrastructure that yet has to materialize.
referring to an old post of @jriegel
viewtopic.php?t=5086#p39985
We have some general shortcomings in FreeCAD about STEP. At the moment we use the OCC high level step importer, which transfer the product structure in a OCC OCAF document (which we not use besides STEP import). OCC transfers only the things it has target objects in its data model. Colors and names are transported to an extend but e.g. no additional attributes or newer protocols like STEP-NC of IFC. This bugs me a long time already, since STEP is the only reasonably well defined and good standardized exchange format!
one problem is to get the assembly information inside STEP file ...
OCC didn't considered those, but may be they have improved this import export part for STEP format...
occ-step-assembly.png
occ-step-assembly.png (92.79 KiB) Viewed 3294 times
What I would like to achieve in FreeCAD is:
1) obtaining a smaller file size for STEP format when exporting it from FreeCAD (which would improve also saving and loading time)
2) read and write the structure of the assembly tree for a STEP file
The 'assembly tree' in STEP would be something like a visual representations of connected objects...
@vejmarie is working in this direction
vejmarie wrote: I can read the STEP and create the tree. Each STEP assembly is a Compound and included Shaped are declared as TopoDS_Shape and Part::Feature within the UI. The Tree support sub assemblies (which mean you can have assembly within assemblies). Tree Nodes are TopoDS_Compound while they are declared as Part::Compound.
I posted what I've found with OCC Assistant hoping it could be of some help for some developers...
STEP import/export is a very important feature for CAD interchange ...

Maurice
User avatar
easyw-fc
Posts: 2851
Joined: Thu Jul 09, 2015 9:34 am

Re: OCC and STEP assembly structure support and STEP file size

Postby easyw-fc » Fri Oct 21, 2016 8:23 pm

an update:
I noticed that with CAD Assistant from OCC it is possible to export STEP with or without 'pcurves' option
cada-pcurves.png
cada-pcurves.png (49.99 KiB) Viewed 3243 times
This option is the one that will make the STEP file size 2.5 times smaller when is OFF...
Is there a way to apply this option also when exporting from FreeCAD to STEP?
that would be a big improvement in size when saving a STEP library; moreover that will increase also performance in loading and saving time...

Thank you
Maurice
User avatar
easyw-fc
Posts: 2851
Joined: Thu Jul 09, 2015 9:34 am

Re: OCC and STEP assembly structure support and STEP file size

Postby easyw-fc » Fri Oct 21, 2016 9:29 pm

second update:
I found in the FC code
FreeCAD-master\src\Mod\Part\App\AppPart.cpp

Code: Select all

    // write.surfacecurve.mode (STEP-only):
    // This parameter indicates whether parametric curves (curves in parametric space of surface) should be
    // written into the STEP file. This parameter can be set to Off in order to minimize the size of the resulting
    // STEP file.
    // Off (0) : writes STEP files without pcurves. This mode decreases the size of the resulting file.
    // On (1) : (default) writes pcurves to STEP file
    int writesurfacecurve = hGenGrp->GetInt("WriteSurfaceCurveMode", 1);
    Interface_Static::SetIVal("write.surfacecurve.mode", writesurfacecurve);
It would be very GREAT to have an option to opt for writing or not pcurves
The best would be in the Edit - Preferences Menu
STEP-export-option.png
STEP-export-option.png (50.74 KiB) Viewed 3231 times
Would it be possible to add it to wish list?
Thank you
Maurice
triplus
Posts: 9464
Joined: Mon Dec 12, 2011 4:45 pm

Re: OCC and STEP assembly structure support and STEP file size

Postby triplus » Fri Oct 21, 2016 9:49 pm

Nice find Maurice!

That i guess is the problem with such parameters. They don't have a GUI counterpart and are usually not documented. More or less they don't exist! You can already do some tests if you want. To see if it affects performance and the exported file size. Go to Tools -> Edit parameters ... Preferences -> Mod -> Part -> General and add New integer item named WriteSurfaceCurveMode to it. You can use this two values after:
  • 0 writes STEP files without pcurves. This mode decreases the size of the resulting file.
  • 1 (default) writes pcurves to STEP file
Use both values and compare the results.
User avatar
easyw-fc
Posts: 2851
Joined: Thu Jul 09, 2015 9:34 am

Re: OCC and STEP assembly structure support and STEP file size

Postby easyw-fc » Fri Oct 21, 2016 10:13 pm

triplus wrote:Nice find Maurice!

That i guess is the problem with such parameters. They don't have a GUI counterpart and are usually not documented. More or less they don't exist! You can already do some tests if you want. To see if it affects performance and the exported file size. Go to Tools -> Edit parameters ... Preferences -> Mod -> Part -> General and add New integer item named WriteSurfaceCurveMode to it. You can use this two values after:
  • 0 writes STEP files without pcurves. This mode decreases the size of the resulting file.
  • 1 (default) writes pcurves to STEP file
Use both values and compare the results.
thank you @triplus
GREAT! it works very well! :D
FC-STEP-no-pcurves.png
FC-STEP-no-pcurves.png (136.09 KiB) Viewed 3215 times
the best now would be to have a check box on the STEP export preferences!!! :D
Feeling very happy :D
Maurice
triplus
Posts: 9464
Joined: Mon Dec 12, 2011 4:45 pm

Re: OCC and STEP assembly structure support and STEP file size

Postby triplus » Fri Oct 21, 2016 10:25 pm

easyw-fc wrote:the best now would be to have a check box on the STEP export preferences!!! :D
Write pcurves option indeed should be available in STEP export dialog in the future. Create a feature request on the issue tracker and hopefully it will be added soon.
easyw-fc wrote:Feeling very happy :D
As you should after a good job done!
User avatar
easyw-fc
Posts: 2851
Joined: Thu Jul 09, 2015 9:34 am

Re: OCC and STEP assembly structure support and STEP file size

Postby easyw-fc » Fri Oct 21, 2016 10:49 pm

triplus wrote:Write pcurves option indeed should be available in STEP export dialog in the future. Create a feature request on the issue tracker and hopefully it will be added soon.
Done here
http://www.freecadweb.org/tracker/view.php?id=2744
(hoping I have created the FR it in the right way ;) )
Maurice
User avatar
easyw-fc
Posts: 2851
Joined: Thu Jul 09, 2015 9:34 am

Re: OCC and STEP assembly structure support and STEP file size

Postby easyw-fc » Sat Oct 22, 2016 10:15 am

triplus wrote: Write pcurves option indeed should be available in STEP export dialog in the future.
Hi @triplus ... is it possible to set this var
WriteSurfaceCurveMode
using Python?
That woul be useful on a macro I use...
Thanks again
Maurice