From 596e783958d8b0d8946cfbf57828745793a07afe Mon Sep 17 00:00:00 2001 From: dpasukhi Date: Mon, 21 Dec 2020 13:52:11 +0300 Subject: [PATCH] 0031949: JT Import - some colors are lost while reading XT representation from JT file Added checking to style of faces from SHELL and edges from WIRE RWMesh_CafReader::fillDocument() is virtual now --- src/RWMesh/RWMesh_CafReader.cxx | 52 ++++++++++++++++++--------------- src/RWMesh/RWMesh_CafReader.hxx | 5 ++-- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/RWMesh/RWMesh_CafReader.cxx b/src/RWMesh/RWMesh_CafReader.cxx index 80bcff768c..a5df98a8c8 100644 --- a/src/RWMesh/RWMesh_CafReader.cxx +++ b/src/RWMesh/RWMesh_CafReader.cxx @@ -415,14 +415,9 @@ Standard_Boolean RWMesh_CafReader::addShapeIntoDoc (CafDocumentTools& theTools, else { // store a plain list of sub-shapes in case if they have custom attributes (usually per-face color) - RWMesh_NodeAttributes aSubShapeAttribs; for (TopoDS_Iterator aSubShapeIter (theShape, Standard_True, Standard_False); aSubShapeIter.More(); aSubShapeIter.Next()) { - const TopoDS_Shape& aSubShape = aSubShapeIter.Value(); - if (myAttribMap.Find (aSubShape.Located (TopLoc_Location()), aSubShapeAttribs)) - { - addSubShapeIntoDoc (theTools, aSubShape, aNewRefLabel, aSubShapeAttribs); - } + addSubShapeIntoDoc(theTools, aSubShapeIter.Value(), aNewRefLabel); } } return Standard_True; @@ -434,8 +429,7 @@ Standard_Boolean RWMesh_CafReader::addShapeIntoDoc (CafDocumentTools& theTools, // ======================================================================= Standard_Boolean RWMesh_CafReader::addSubShapeIntoDoc (CafDocumentTools& theTools, const TopoDS_Shape& theShape, - const TDF_Label& theParentLabel, - const RWMesh_NodeAttributes& theAttribs) + const TDF_Label& theParentLabel) { if (theShape.IsNull() || myXdeDoc.IsNull()) @@ -443,17 +437,36 @@ Standard_Boolean RWMesh_CafReader::addSubShapeIntoDoc (CafDocumentTools& theTool return Standard_False; } + RWMesh_NodeAttributes aShapeAttribs; const TopAbs_ShapeEnum aShapeType = theShape.ShapeType(); + const Standard_Boolean aHasAttribs = myAttribMap.Find(theShape.Located(TopLoc_Location()), aShapeAttribs); + + // check for the attribute + // shell or wire may not contain an attribute, but its subshapes need to be checked + if (!aHasAttribs && aShapeType != TopAbs_SHELL && + aShapeType != TopAbs_WIRE) + { + return Standard_False; + } + + for (TopoDS_Iterator aSubShapeIter(theShape, Standard_True, Standard_False); aSubShapeIter.More(); aSubShapeIter.Next()) + { + addSubShapeIntoDoc(theTools, aSubShapeIter.Value(), theParentLabel); + } + + if (!aHasAttribs) + { + return Standard_False; + } + TDF_Label aNewLabel = theTools.ShapeTool->AddSubShape (theParentLabel, theShape); if (aNewLabel.IsNull()) { return Standard_False; } - { - Handle(XCAFDoc_ShapeMapTool) aShapeMapTool = XCAFDoc_ShapeMapTool::Set (aNewLabel); - aShapeMapTool->SetShape (theShape); - } + Handle(XCAFDoc_ShapeMapTool) aShapeMapTool = XCAFDoc_ShapeMapTool::Set(aNewLabel); + aShapeMapTool->SetShape(theShape); // if new label is a reference get referred shape TDF_Label aNewRefLabel = aNewLabel; @@ -461,19 +474,10 @@ Standard_Boolean RWMesh_CafReader::addSubShapeIntoDoc (CafDocumentTools& theTool // put attributes to the Product (shared across Instances) static const TCollection_AsciiString anEmptyString; - setShapeName (aNewRefLabel, aShapeType, theAttribs.Name, TDF_Label(), anEmptyString); - setShapeStyle (theTools, aNewRefLabel, theAttribs.Style); - setShapeNamedData (theTools, aNewRefLabel, theAttribs.NamedData); + setShapeName (aNewRefLabel, aShapeType, aShapeAttribs.Name, TDF_Label(), anEmptyString); + setShapeStyle (theTools, aNewRefLabel, aShapeAttribs.Style); + setShapeNamedData (theTools, aNewRefLabel, aShapeAttribs.NamedData); - RWMesh_NodeAttributes aSubShapeAttribs; - for (TopoDS_Iterator aSubShapeIter (theShape, Standard_True, Standard_False); aSubShapeIter.More(); aSubShapeIter.Next()) - { - const TopoDS_Shape& aSubShape = aSubShapeIter.Value(); - if (myAttribMap.Find (aSubShape.Located (TopLoc_Location()), aSubShapeAttribs)) - { - addSubShapeIntoDoc (theTools, aSubShape, theParentLabel, aSubShapeAttribs); - } - } return Standard_True; } diff --git a/src/RWMesh/RWMesh_CafReader.hxx b/src/RWMesh/RWMesh_CafReader.hxx index 863d1ab105..0776adb561 100644 --- a/src/RWMesh/RWMesh_CafReader.hxx +++ b/src/RWMesh/RWMesh_CafReader.hxx @@ -200,7 +200,7 @@ protected: protected: //! Fill document with new root shapes. - Standard_EXPORT void fillDocument(); + Standard_EXPORT virtual void fillDocument(); //! Append new shape into the document (recursively). Standard_EXPORT Standard_Boolean addShapeIntoDoc (CafDocumentTools& theTools, @@ -211,8 +211,7 @@ protected: //! Append new sub-shape into the document (recursively). Standard_EXPORT Standard_Boolean addSubShapeIntoDoc (CafDocumentTools& theTools, const TopoDS_Shape& theShape, - const TDF_Label& theParentLabel, - const RWMesh_NodeAttributes& theAttribs); + const TDF_Label& theParentLabel); //! Put name attribute onto the label. Standard_EXPORT void setShapeName (const TDF_Label& theLabel,