]> OCCT Git - occt.git/commitdiff
0031949: JT Import - some colors are lost while reading XT representation from JT...
authordpasukhi <dpasukhi@opencascade.com>
Mon, 21 Dec 2020 10:52:11 +0000 (13:52 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 28 Apr 2021 15:31:04 +0000 (18:31 +0300)
Added checking to style of faces from SHELL and edges from WIRE
RWMesh_CafReader::fillDocument() is virtual now

src/RWMesh/RWMesh_CafReader.cxx
src/RWMesh/RWMesh_CafReader.hxx

index 80bcff768cbf1fa2e71710fd69014a8f397dd802..a5df98a8c8349626956320a90ca39a1fa3132059 100644 (file)
@@ -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,37 +437,47 @@ Standard_Boolean RWMesh_CafReader::addSubShapeIntoDoc (CafDocumentTools& theTool
     return Standard_False;
   }
 
+  RWMesh_NodeAttributes aShapeAttribs;
   const TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
-  TDF_Label aNewLabel = theTools.ShapeTool->AddSubShape (theParentLabel, theShape);
-  if (aNewLabel.IsNull())
+  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())
   {
-    Handle(XCAFDoc_ShapeMapTool) aShapeMapTool = XCAFDoc_ShapeMapTool::Set (aNewLabel);
-    aShapeMapTool->SetShape (theShape);
+    return Standard_False;
   }
 
+  Handle(XCAFDoc_ShapeMapTool) aShapeMapTool = XCAFDoc_ShapeMapTool::Set(aNewLabel);
+  aShapeMapTool->SetShape(theShape);
+
   // if new label is a reference get referred shape
   TDF_Label aNewRefLabel = aNewLabel;
   theTools.ShapeTool->GetReferredShape (aNewLabel, aNewRefLabel);
 
   // 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;
 }
 
index 863d1ab10562f0cb820fbd1fec228cce592662c6..0776adb5618fffbbd1641546e8193959ebe1bdd0 100644 (file)
@@ -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,