Skip to content

Commit

Permalink
0033317: Data Exchange, Step Export - Ignoring color attached to the …
Browse files Browse the repository at this point in the history
…reference shape label

Fixed problem with pure referencing.
  To export reference label to step we convert it to the assembly with one part.
  All attributes attached to the label should be moved to the new part.
  For working with it new map contains only pure reference labels, that converted to the part
  was implemented to the STEPCAFControl_Writer.
Updated code style of the STEPCAFControl_Writer
Improved ability to export labels from different documents
Removed OCCT_Debug macros to print in Trace gravity
  • Loading branch information
dpasukhi authored and vglukhik committed Feb 4, 2023
1 parent b0afa94 commit 47263fa
Show file tree
Hide file tree
Showing 13 changed files with 2,500 additions and 2,405 deletions.
4,514 changes: 2,285 additions & 2,229 deletions src/STEPCAFControl/STEPCAFControl_Writer.cxx

Large diffs are not rendered by default.

285 changes: 149 additions & 136 deletions src/STEPCAFControl/STEPCAFControl_Writer.hxx

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions src/XCAFDoc/XCAFDoc_ColorTool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Standard_Boolean XCAFDoc_ColorTool::IsColor (const TDF_Label& lab) const
//=======================================================================

Standard_Boolean XCAFDoc_ColorTool::GetColor (const TDF_Label& lab,
Quantity_Color& col) const
Quantity_Color& col)
{
Quantity_ColorRGBA aCol;
Standard_Boolean isDone = GetColor(lab, aCol);
Expand All @@ -104,10 +104,8 @@ Standard_Boolean XCAFDoc_ColorTool::GetColor (const TDF_Label& lab,
//=======================================================================

Standard_Boolean XCAFDoc_ColorTool::GetColor(const TDF_Label& lab,
Quantity_ColorRGBA& col) const
Quantity_ColorRGBA& col)
{
if (lab.Father() != Label()) return Standard_False;

Handle(XCAFDoc_Color) ColorAttribute;
if (!lab.FindAttribute(XCAFDoc_Color::GetID(), ColorAttribute))
return Standard_False;
Expand Down Expand Up @@ -514,7 +512,7 @@ XCAFDoc_ColorTool::XCAFDoc_ColorTool()
//purpose :
//=======================================================================

Standard_Boolean XCAFDoc_ColorTool::IsVisible (const TDF_Label& L) const
Standard_Boolean XCAFDoc_ColorTool::IsVisible (const TDF_Label& L)
{
Handle(TDataStd_UAttribute) aUAttr;
return (!L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr));
Expand Down
10 changes: 5 additions & 5 deletions src/XCAFDoc/XCAFDoc_ColorTool.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public:
//! Returns color defined by label lab
//! Returns False if the label is not in colortable
//! or does not define a color
Standard_EXPORT Standard_Boolean GetColor (const TDF_Label& lab, Quantity_Color& col) const;
Standard_EXPORT static Standard_Boolean GetColor (const TDF_Label& lab, Quantity_Color& col);

//! Returns color defined by label lab
//! Returns False if the label is not in colortable
//! or does not define a color
Standard_EXPORT Standard_Boolean GetColor(const TDF_Label& lab, Quantity_ColorRGBA& col) const;
Standard_EXPORT static Standard_Boolean GetColor(const TDF_Label& lab, Quantity_ColorRGBA& col);

//! Finds a color definition in a colortable and returns
//! its label if found
Expand Down Expand Up @@ -150,11 +150,11 @@ public:

//! Returns color assigned to <L> as <type>
//! Returns False if no such color is assigned
Standard_EXPORT Standard_Boolean GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_Color& color);
Standard_EXPORT static Standard_Boolean GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_Color& color);

//! Returns color assigned to <L> as <type>
//! Returns False if no such color is assigned
Standard_EXPORT Standard_Boolean GetColor(const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);
Standard_EXPORT static Standard_Boolean GetColor(const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);

//! Sets a link with GUID defined by <type> (see
//! XCAFDoc::ColorRefGUID()) from label <L> to color
Expand Down Expand Up @@ -198,7 +198,7 @@ public:
Standard_EXPORT Standard_Boolean GetColor(const TopoDS_Shape& S, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color);

//! Return TRUE if object on this label is visible, FALSE if invisible.
Standard_EXPORT Standard_Boolean IsVisible (const TDF_Label& L) const;
Standard_EXPORT static Standard_Boolean IsVisible (const TDF_Label& L);

//! Set the visibility of object on label. Do nothing if there no any object.
//! Set UAttribute with corresponding GUID.
Expand Down
6 changes: 3 additions & 3 deletions src/XCAFDoc/XCAFDoc_DimTolTool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ TDF_Label XCAFDoc_DimTolTool::SetDimTol(const TDF_Label& L,

Standard_Boolean XCAFDoc_DimTolTool::GetRefShapeLabel(const TDF_Label& theL,
TDF_LabelSequence& theShapeLFirst,
TDF_LabelSequence& theShapeLSecond) const
TDF_LabelSequence& theShapeLSecond)
{
theShapeLFirst.Clear();
theShapeLSecond.Clear();
Expand Down Expand Up @@ -855,7 +855,7 @@ Standard_Boolean XCAFDoc_DimTolTool::GetDatum(const TDF_Label& theDatumL,
//=======================================================================

Standard_Boolean XCAFDoc_DimTolTool::GetDatumOfTolerLabels(const TDF_Label& theDimTolL,
TDF_LabelSequence& theDatums) const
TDF_LabelSequence& theDatums)
{
Handle(XCAFDoc_GraphNode) aNode;
if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
Expand All @@ -874,7 +874,7 @@ Standard_Boolean XCAFDoc_DimTolTool::GetDatumOfTolerLabels(const TDF_Label& theD
//=======================================================================

Standard_Boolean XCAFDoc_DimTolTool::GetDatumWithObjectOfTolerLabels(const TDF_Label& theDimTolL,
TDF_LabelSequence& theDatums) const
TDF_LabelSequence& theDatums)
{
Handle(XCAFDoc_GraphNode) aNode;
if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
Expand Down
14 changes: 7 additions & 7 deletions src/XCAFDoc/XCAFDoc_DimTolTool.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ public:

//! Gets all shape labels referred by theL label of the GD&T table.
//! Returns False if there are no shape labels added to the sequences.
Standard_EXPORT Standard_Boolean GetRefShapeLabel (const TDF_Label& theL,
TDF_LabelSequence& theShapeLFirst,
TDF_LabelSequence& theShapeLSecond) const;
Standard_EXPORT static Standard_Boolean GetRefShapeLabel (const TDF_Label& theL,
TDF_LabelSequence& theShapeLFirst,
TDF_LabelSequence& theShapeLSecond);

//! Returns dimension tolerance assigned to theDimTolL label.
//! Returns False if no such dimension tolerance is assigned.
Expand Down Expand Up @@ -215,12 +215,12 @@ public:
Handle(TCollection_HAsciiString)& theIdentification) const;

//! Returns all Datum labels defined for theDimTolL label.
Standard_EXPORT Standard_Boolean GetDatumOfTolerLabels (const TDF_Label& theDimTolL,
TDF_LabelSequence& theDatums) const;
Standard_EXPORT static Standard_Boolean GetDatumOfTolerLabels (const TDF_Label& theDimTolL,
TDF_LabelSequence& theDatums);

//! Returns all Datum labels with XCAFDimTolObjects_DatumObject defined for label theDimTolL.
Standard_EXPORT Standard_Boolean GetDatumWithObjectOfTolerLabels (const TDF_Label& theDimTolL,
TDF_LabelSequence& theDatums) const;
Standard_EXPORT static Standard_Boolean GetDatumWithObjectOfTolerLabels (const TDF_Label& theDimTolL,
TDF_LabelSequence& theDatums);

//! Returns all GeomToleranses labels defined for theDatumL label.
Standard_EXPORT Standard_Boolean GetTolerOfDatumLabels (const TDF_Label& theDatumL,
Expand Down
16 changes: 8 additions & 8 deletions src/XCAFDoc/XCAFDoc_LayerTool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -416,20 +416,20 @@ Handle(TColStd_HSequenceOfExtendedString) XCAFDoc_LayerTool::GetLayers(const TDF
//function : GetShapesOfLayer
//purpose :
//=======================================================================

void XCAFDoc_LayerTool::GetShapesOfLayer(const TDF_Label& layerL,
TDF_LabelSequence& ShLabels) const
void XCAFDoc_LayerTool::GetShapesOfLayer(const TDF_Label& theLayerL,
TDF_LabelSequence& theShLabels)
{
ShLabels.Clear();
theShLabels.Clear();
Handle(XCAFDoc_GraphNode) aGNode;
if ( layerL.FindAttribute( XCAFDoc::LayerRefGUID(), aGNode) ) {
for (Standard_Integer i = 1; i <= aGNode->NbChildren(); i++) {
ShLabels.Append( aGNode->GetChild(i)->Label() );
if (theLayerL.FindAttribute(XCAFDoc::LayerRefGUID(), aGNode))
{
for (Standard_Integer aChildInd = 1; aChildInd <= aGNode->NbChildren(); aChildInd++)
{
theShLabels.Append(aGNode->GetChild(aChildInd)->Label());
}
}
}


//=======================================================================
//function : IsVisible
//purpose :
Expand Down
2 changes: 1 addition & 1 deletion src/XCAFDoc/XCAFDoc_LayerTool.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public:
Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetLayers (const TDF_Label& L);

//! Return sequanese of shape labels that assigned with layers to <ShLabels>.
Standard_EXPORT void GetShapesOfLayer (const TDF_Label& layerL, TDF_LabelSequence& ShLabels) const;
Standard_EXPORT static void GetShapesOfLayer (const TDF_Label& theLayerL, TDF_LabelSequence& theShLabels);

//! Return TRUE if layer is visible, FALSE if invisible.
Standard_EXPORT Standard_Boolean IsVisible (const TDF_Label& layerL) const;
Expand Down
2 changes: 1 addition & 1 deletion src/XCAFDoc/XCAFDoc_MaterialTool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Standard_Boolean XCAFDoc_MaterialTool::GetMaterial(const TDF_Label& MatL,
Handle(TCollection_HAsciiString)& aDescription,
Standard_Real& aDensity,
Handle(TCollection_HAsciiString)& aDensName,
Handle(TCollection_HAsciiString)& aDensValType) const
Handle(TCollection_HAsciiString)& aDensValType)
{
Handle(XCAFDoc_Material) MatAttr;
if(!MatL.FindAttribute(XCAFDoc_Material::GetID(),MatAttr)) {
Expand Down
2 changes: 1 addition & 1 deletion src/XCAFDoc/XCAFDoc_MaterialTool.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public:

//! Returns Material assigned to <MatL>
//! Returns False if no such Material is assigned
Standard_EXPORT Standard_Boolean GetMaterial (const TDF_Label& MatL, Handle(TCollection_HAsciiString)& aName, Handle(TCollection_HAsciiString)& aDescription, Standard_Real& aDensity, Handle(TCollection_HAsciiString)& aDensName, Handle(TCollection_HAsciiString)& aDensValType) const;
Standard_EXPORT static Standard_Boolean GetMaterial (const TDF_Label& MatL, Handle(TCollection_HAsciiString)& aName, Handle(TCollection_HAsciiString)& aDescription, Standard_Real& aDensity, Handle(TCollection_HAsciiString)& aDensName, Handle(TCollection_HAsciiString)& aDensValType);

//! Find referred material and return density from it
//! if no material --> return 0
Expand Down
10 changes: 3 additions & 7 deletions src/XCAFDoc/XCAFDoc_VisMaterialTool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ const Handle(XCAFDoc_ShapeTool)& XCAFDoc_VisMaterialTool::ShapeTool()
//function : GetMaterial
//purpose :
//=======================================================================
Handle(XCAFDoc_VisMaterial) XCAFDoc_VisMaterialTool::GetMaterial (const TDF_Label& theMatLabel) const
Handle(XCAFDoc_VisMaterial) XCAFDoc_VisMaterialTool::GetMaterial(const TDF_Label& theMatLabel)
{
Handle(XCAFDoc_VisMaterial) aMatAttrib;
if (theMatLabel.Father() == Label())
{
theMatLabel.FindAttribute (XCAFDoc_VisMaterial::GetID(), aMatAttrib);
}
theMatLabel.FindAttribute(XCAFDoc_VisMaterial::GetID(), aMatAttrib);
return aMatAttrib;
}

Expand Down Expand Up @@ -214,8 +211,7 @@ Standard_Boolean XCAFDoc_VisMaterialTool::GetShapeMaterial (const TDF_Label& the
Handle(XCAFDoc_VisMaterial) XCAFDoc_VisMaterialTool::GetShapeMaterial (const TDF_Label& theShapeLabel)
{
TDF_Label aMatLabel;
return Label().HasChild() // do not waste time on shape attributes if materials map is empty
&& GetShapeMaterial (theShapeLabel, aMatLabel)
return GetShapeMaterial (theShapeLabel, aMatLabel)
? GetMaterial (aMatLabel)
: Handle(XCAFDoc_VisMaterial)();
}
Expand Down
4 changes: 2 additions & 2 deletions src/XCAFDoc/XCAFDoc_VisMaterialTool.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public:
Standard_Boolean IsMaterial (const TDF_Label& theLabel) const { return !GetMaterial (theLabel).IsNull(); }

//! Returns Material defined by specified Label, or NULL if the label is not in Material Table.
Standard_EXPORT Handle(XCAFDoc_VisMaterial) GetMaterial (const TDF_Label& theMatLabel) const;
Standard_EXPORT static Handle(XCAFDoc_VisMaterial) GetMaterial (const TDF_Label& theMatLabel);

//! Adds Material definition to a Material Table and returns its Label.
Standard_EXPORT TDF_Label AddMaterial (const Handle(XCAFDoc_VisMaterial)& theMat,
Expand Down Expand Up @@ -88,7 +88,7 @@ public:
Standard_EXPORT static Standard_Boolean GetShapeMaterial (const TDF_Label& theShapeLabel, TDF_Label& theMaterialLabel);

//! Returns material assigned to the shape label.
Standard_EXPORT Handle(XCAFDoc_VisMaterial) GetShapeMaterial (const TDF_Label& theShapeLabel);
Standard_EXPORT static Handle(XCAFDoc_VisMaterial) GetShapeMaterial (const TDF_Label& theShapeLabel);

//! Sets a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material label.
//! @param theShape [in] shape
Expand Down
32 changes: 32 additions & 0 deletions tests/bugs/step/bug33317
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
puts "========================"
puts "0033317: Data Exchange, Step Export - Ignoring color attached to the reference shape label"
puts "========================"

pload OCAF

Close D -silent
Close D1 -silent

set TempFilename ${imagedir}/${casename}_temp.stp

# Open document
XOpen [locate_data_file bug33317_solids_7_7_0.xml] D

# Get colors
set colors_old [XGetShapeColor D 0:1:1:1 generic]

# Write to STEP
WriteStep D ${TempFilename}

# Read and check
ReadStep D1 ${TempFilename}

set colors_new [XGetShapeColor D1 0:1:1:1:1 generic]
if { [string equal ${colors_new} ${colors_old}] == -1 } {
puts "ERROR: OCC33317 is reproduced while STEP export."
}

# Clear temp file
file delete -force $TempFilename
Close D
Close D1

0 comments on commit 47263fa

Please sign in to comment.