[Bug report] XmlXCAF and BinXCAF fail to store/retrieve colors in XDE assembly

Reproducer in Draw:
Take as1-oc-214.stp from www.cax-if.org
> pload ALL
> NewDoc d XmlXCAF
> ReadStep d as1-oc-214.stp
> XShow d # you will see correct colors
> SaveAs d C:/temp/as1-oc-214.stp
# Rename C:/temp/as1-oc-214.stp with as1.stp
> Open C:/temp/as1.stp d2
> XShow d2 # No colors

The same fails if to use NewDoc d BinXCAF. The same works well if to use NewDoc d MDTV-XCAF. So the assumption is that storage/retrieval of some XDE attributes in Xml/Bin format is missing or incorrect. Using XDumpDF on d2 produced by different formats gives no clues – the structure is the same, and I did not have time to dig deeper.

Hope this will be helpful.


Pawel's picture

Hello Roman,

I had a similar issue after saving an XDE document as binary (BinXCAF):
- loading & displaying step - OK
- saving xbf file - OK
- loading xbf file - no colors !?

I found a workaround for this which was updating assembly structure top-down (see below) - probably a similar OCC bug.

void XDEAssemblyManager::UpdateAllAssemblies(const TDF_Label & label)
for (TDF_ChildIterator labelIterator (label, Standard_False); labelIterator.More(); labelIterator.Next())
if( XCAFDoc_DocumentTool::ShapeTool (label.Root())->IsAssembly(labelIterator.Value()))
XCAFDoc_DocumentTool::ShapeTool (label.Root())->UpdateAssembly(labelIterator.Value());


Maybe it works for you.


Pawel's picture

... I meant updating the assembly structure after it was loaded from an xbf file

Roman Lygin's picture

Hi Pawel,

Thanks for a hint, that's interesting indeed. My assumption was/is that the difference is somewhere in the format (Xml/Bin vs MDTV-XCAF), and it's really interesting why the problem can be worked-around with enforcing assembly update (which means that the file is stored/retrieved in full).

This currently only affects the CAD Exchanger test framework so I simply chose to load a test model saved in MDTV-XCAF format.


Forum supervisor's picture

Hello Roman,

Thank you for reporting this bug.
The problem is now registered with the reference number OCC21803.

Here is the corrected script to reproduce the problem:

pload OCAF
pload XDE
ReadStep d as1-oc-214.stp
Format d XmlXCAF
XSave d as1.xml
Format d BinXCAF
XSave d as1.xbf
file rename as1.xml as2.xml
file rename as1.xbf as2.xbf
Open as2.xml d1
Open as2.xbf d2
XShow d1
XShow d2

Best regards,
Forum supervisor

Roman Lygin's picture

Hello folks,

Thanks for considering this. The original Draw sequence was closer to the original C++ code I used but yours seems to be more universal.
Will look forward to a fix available.

Roman Lygin's picture

I have come across this issue again :-(
The root cause seems to be in the way locations are stored. When storing/retrieving XCAFDoc_Location attribute in Xml and in Binary format, a duplication of location datum elements happen (instead of sharing).

XCAFPrs::CollectStyleSettings() uses locations stored via XCAFDoc_Location attributes. When exploring the assembly via TopoDS_Iterator inside XCAFPrs::DispatchStyles(), as locations are not shared, different hash-codes are generated and subshapes cannot be found in the XCAFPrs_DataMapOfShapeStyle map (populated by CollectStyleSettings()).

Here is another, more simple, test script that shows the problem. It creates an assembly of an edge and its translated instance. Dump in the end should show 2 locations, while with the bug there are 4 (2 pairs).
Instead of XShow you can use WriteIges (which uses essentially the same algorithm as DispatchStyles()) and inspect the IGES files to see that names and colors are lost.

Hope this helps.

pload OCAF
pload XDE
line l 0 0 0 1 0 0
mkedge e1 l 0 1
copy e1 e2
ttranslate e2 0 1 0
compound e1 e2 comp
NewDocument d XmlXCAF
XAddShape d comp 1 #create as assembly
XSetColor d 0:1:1:2 1 0 0
XSetColor d 0:1:1:1:2 0 1 0
set dir C:/temp
XShow d #Fine as no store/retrieval happened yet
Format d XmlXCAF
XSave d ${dir}/as1.xml
Format d BinXCAF
XSave d ${dir}/as1.xbf
Format d MDTV-XCAF
XSave d ${dir}/as1.dxc
file rename -force ${dir}/as1.xml ${dir}/as2.xml
file rename -force ${dir}/as1.xbf ${dir}/as2.xbf
file rename -force ${dir}/as1.dxc ${dir}/as2.dxc
Open ${dir}/as2.xml dx
Open ${dir}/as2.xbf db
Open ${dir}/as2.dxc dm
XShow dx
XShow db
XShow dm
XGetShape r dx 0:1:1:1
XGetShape r1 dx 0:1:1:1:1
XGetShape r2 dx 0:1:1:1:2
compound r r1 r2 comp
dump comp