0030811: Data Exchange, RWGltf_CafReader - fix inaccessibility of properties
authorkgv <kgv@opencascade.com>
Wed, 26 Jun 2019 08:26:31 +0000 (11:26 +0300)
committerapn <apn@opencascade.com>
Wed, 26 Jun 2019 15:49:23 +0000 (18:49 +0300)
Added missing Standard_EXPORT and getters.
Fixed metadata loss.

src/RWGltf/RWGltf_CafReader.cxx
src/RWGltf/RWGltf_GltfJsonParser.cxx
src/RWGltf/RWGltf_GltfJsonParser.pxx
src/RWGltf/RWGltf_GltfLatePrimitiveArray.hxx
src/RWMesh/RWMesh_CafReader.cxx
src/RWMesh/RWMesh_CafReader.hxx

index f17c3db..635b2a5 100644 (file)
@@ -215,6 +215,7 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
   aDoc.SetFilePath (theFile);
   aDoc.SetProbeHeader (theToProbe);
   aDoc.SetExternalFiles (myExternalFiles);
+  aDoc.SetMetadata (myMetadata);
   aDoc.SetErrorPrefix (anErrPrefix);
   aDoc.SetCoordinateSystemConverter (myCoordSysConverter);
   if (!theToProbe)
index 154f331..3eda428 100644 (file)
@@ -250,18 +250,23 @@ void RWGltf_GltfJsonParser::gltfParseAsset()
     }
   }
 
+  if (myMetadata == NULL)
+  {
+    return;
+  }
+
   if (const RWGltf_JsonValue* aGenerator = findObjectMember (*anAsset, "generator"))
   {
     if (aGenerator->IsString())
     {
-      myMetadata.Add ("generator", aGenerator->GetString());
+      myMetadata->Add ("generator", aGenerator->GetString());
     }
   }
   if (const RWGltf_JsonValue* aCopyRight = findObjectMember (*anAsset, "copyright"))
   {
     if (aCopyRight->IsString())
     {
-      myMetadata.Add ("copyright", aCopyRight->GetString());
+      myMetadata->Add ("copyright", aCopyRight->GetString());
     }
   }
 }
index 92e605f..29f985d 100644 (file)
@@ -87,6 +87,9 @@ public:
   //! Set list for storing external files.
   void SetExternalFiles (NCollection_IndexedMap<TCollection_AsciiString>& theExternalFiles) { myExternalFiles = &theExternalFiles; }
 
+  //! Set metadata map.
+  void SetMetadata (TColStd_IndexedDataMapOfStringString& theMetadata) { myMetadata = &theMetadata; }
+
   //! Return transformation from glTF to OCCT coordinate system.
   const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const { return myCSTrsf; }
 
@@ -105,9 +108,6 @@ public:
   //! Parse glTF document.
   Standard_EXPORT bool Parse (const Handle(Message_ProgressIndicator)& theProgress);
 
-  //! Return metadata map.
-  const TColStd_IndexedDataMapOfStringString& Metadata() const { return myMetadata; }
-
   //! Return face list for loading triangulation.
   NCollection_Vector<TopoDS_Face>& FaceList() { return myFaceList; }
 
@@ -387,8 +387,8 @@ protected:
   NCollection_IndexedMap<TCollection_AsciiString>*
                                    myExternalFiles; //!< list of external file references
   RWMesh_CoordinateSystemConverter myCSTrsf;        //!< transformation from glTF to OCCT coordinate system
+  TColStd_IndexedDataMapOfStringString* myMetadata; //!< file metadata
 
-  TColStd_IndexedDataMapOfStringString myMetadata; //!< file metadata
   NCollection_DataMap<TCollection_AsciiString, Handle(RWGltf_MaterialMetallicRoughness)> myMaterialsPbr;
   NCollection_DataMap<TCollection_AsciiString, Handle(RWGltf_MaterialCommon)> myMaterialsCommon;
   NCollection_DataMap<TCollection_AsciiString, TopoDS_Shape> myShapeMap[2];
index 07eb60e..595ddb9 100644 (file)
@@ -79,12 +79,15 @@ public:
   //! Add primitive array data element.
   Standard_EXPORT RWGltf_GltfPrimArrayData& AddPrimArrayData (RWGltf_GltfArrayType theType);
 
+  //! Return bounding box defined within glTF file, or VOID if not specified.
+  const Bnd_Box& BoundingBox() const { return myBox; }
+
   //! This method sets input bounding box and assigns a FAKE data to underlying Poly_Triangulation
   //! as Min/Max corners of bounding box, so that standard tools like BRepBndLib::Add()
   //! can be used transparently for computing bounding box of this face.
   Standard_EXPORT void SetBoundingBox (const Bnd_Box& theBox);
 
-private:
+protected:
 
   NCollection_Sequence<RWGltf_GltfPrimArrayData> myData;
   Handle(RWGltf_MaterialMetallicRoughness) myMaterialPbr;    //!< PBR material
index f087fb8..cfb8f20 100644 (file)
@@ -90,13 +90,10 @@ Standard_Boolean RWMesh_CafReader::perform (const TCollection_AsciiString& theFi
                                             const Standard_Boolean theToProbe)
 {
   Standard_Integer aNewRootsLower = 1;
-  Handle(XCAFDoc_ShapeTool) aShapeTool = !myXdeDoc.IsNull()
-                                       ? XCAFDoc_DocumentTool::ShapeTool (myXdeDoc->Main())
-                                       : Handle(XCAFDoc_ShapeTool)();
   if (!myXdeDoc.IsNull())
   {
     TDF_LabelSequence aRootLabels;
-    aShapeTool->GetFreeShapes (aRootLabels);
+    XCAFDoc_DocumentTool::ShapeTool (myXdeDoc->Main())->GetFreeShapes (aRootLabels);
     aNewRootsLower = aRootLabels.Upper() + 1;
   }
 
@@ -118,28 +115,11 @@ Standard_Boolean RWMesh_CafReader::perform (const TCollection_AsciiString& theFi
     myExtraStatus |= RWMesh_CafReaderStatusEx_Partial;
   }
 
-  BRep_Builder aBuilder;
-  TopoDS_Shape aShape;
-  if (myRootShapes.Size() > 1)
-  {
-    TopoDS_Compound aCompound;
-    aBuilder.MakeCompound (aCompound);
-    for (TopTools_SequenceOfShape::Iterator aRootIter (myRootShapes); aRootIter.More(); aRootIter.Next())
-    {
-      aBuilder.Add (aCompound, aRootIter.Value());
-    }
-    aShape = aCompound;
-  }
-  else if (!myRootShapes.IsEmpty())
-  {
-    aShape = myRootShapes.First();
-  }
-
+  TopLoc_Location aDummyLoc;
   Standard_Integer aNbNodes = 0, aNbElems = 0, aNbFaces = 0;
-  if (!aShape.IsNull())
+  for (TopTools_SequenceOfShape::Iterator aRootIter (myRootShapes); aRootIter.More(); aRootIter.Next())
   {
-    TopLoc_Location aDummyLoc;
-    for (TopExp_Explorer aFaceIter (aShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
+    for (TopExp_Explorer aFaceIter (aRootIter.Value(), TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
     {
       const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
       if (const Handle(Poly_Triangulation)& aPolyTri = BRep_Tool::Triangulation (aFace, aDummyLoc))
@@ -155,40 +135,39 @@ Standard_Boolean RWMesh_CafReader::perform (const TCollection_AsciiString& theFi
     return Standard_False;
   }
 
-  if (myToFillDoc
-  && !myXdeDoc.IsNull())
-  {
-    const Standard_Boolean wasAutoNaming = aShapeTool->AutoNaming();
-    aShapeTool->SetAutoNaming (Standard_False);
-    const TCollection_AsciiString aRootName; // = generateRootName (theFile);
-    for (TopTools_SequenceOfShape::Iterator aRootIter (myRootShapes); aRootIter.More(); aRootIter.Next())
-    {
-      addShapeIntoDoc (aRootIter.Value(), TDF_Label(), aRootName);
-    }
-    aShapeTool->UpdateAssemblies();
-    aShapeTool->SetAutoNaming (wasAutoNaming);
-  }
-  if (!myXdeDoc.IsNull())
-  {
-    generateNames (theFile, aNewRootsLower, Standard_False);
-  }
+  fillDocument();
+  generateNames (theFile, aNewRootsLower, Standard_False);
 
   aLoadingTimer.Stop();
 
-  TCollection_AsciiString aStats = TCollection_AsciiString("[") + aNbNodes + " nodes] [" + aNbElems + " 2d elements]";
-  if (!isDone)
+  Message::DefaultMessenger()->Send (TCollection_AsciiString ("Mesh ") + theFile
+                                   + "\n[" + aNbNodes + " nodes] [" + aNbElems + " 2d elements]"
+                                   + "\n[" + (!isDone ? "PARTIALLY " : "") + "read in " + aLoadingTimer.ElapsedTime() + " s]", Message_Info);
+  return Standard_True;
+}
+
+// =======================================================================
+// function : fillDocument
+// purpose  :
+// =======================================================================
+void RWMesh_CafReader::fillDocument()
+{
+  if (!myToFillDoc
+    || myXdeDoc.IsNull()
+    || myRootShapes.IsEmpty())
   {
-    Message::DefaultMessenger()->Send (TCollection_AsciiString ("Mesh ") + theFile
-                                     + "\n" + aStats
-                                     + "\n[PARTIALLY read in " + aLoadingTimer.ElapsedTime() + " s]", Message_Info);
+    return;
   }
-  else
+
+  const Standard_Boolean wasAutoNaming = XCAFDoc_ShapeTool::AutoNaming();
+  XCAFDoc_ShapeTool::SetAutoNaming (Standard_False);
+  const TCollection_AsciiString aRootName; // = generateRootName (theFile);
+  for (TopTools_SequenceOfShape::Iterator aRootIter (myRootShapes); aRootIter.More(); aRootIter.Next())
   {
-    Message::DefaultMessenger()->Send (TCollection_AsciiString ("Mesh ") + theFile
-                                     + "\n" + aStats
-                                     + "\n[read in " + aLoadingTimer.ElapsedTime() + " s]", Message_Info);
+    addShapeIntoDoc (aRootIter.Value(), TDF_Label(), aRootName);
   }
-  return Standard_True;
+  XCAFDoc_DocumentTool::ShapeTool (myXdeDoc->Main())->UpdateAssemblies();
+  XCAFDoc_ShapeTool::SetAutoNaming (wasAutoNaming);
 }
 
 // =======================================================================
index ef5b58b..8658a21 100644 (file)
@@ -173,18 +173,21 @@ protected:
   //! @param theFile    file to read
   //! @param optional   progress indicator
   //! @param theToProbe flag indicating that mesh data should be skipped and only basing information to be read
-  virtual Standard_Boolean perform (const TCollection_AsciiString& theFile,
-                                    const Handle(Message_ProgressIndicator)& theProgress,
-                                    const Standard_Boolean theToProbe);
+  Standard_EXPORT virtual Standard_Boolean perform (const TCollection_AsciiString& theFile,
+                                                    const Handle(Message_ProgressIndicator)& theProgress,
+                                                    const Standard_Boolean theToProbe);
 
   //! Read the mesh from specified file - interface to be implemented by sub-classes.
-  virtual Standard_Boolean performMesh (const TCollection_AsciiString& theFile,
-                                        const Handle(Message_ProgressIndicator)& theProgress,
-                                        const Standard_Boolean theToProbe) = 0;
+  Standard_EXPORT virtual Standard_Boolean performMesh (const TCollection_AsciiString& theFile,
+                                                        const Handle(Message_ProgressIndicator)& theProgress,
+                                                        const Standard_Boolean theToProbe) = 0;
 
 //! @name tools for filling XDE document
 protected:
 
+  //! Fill document with new root shapes.
+  Standard_EXPORT void fillDocument();
+
   //! Append new shape into the document (recursively).
   Standard_EXPORT Standard_Boolean addShapeIntoDoc (const TopoDS_Shape& theShape,
                                                     const TDF_Label& theLabel,