]> OCCT Git - occt.git/commitdiff
0030828: Data Exchange - The commands getting shapes from XCAF document should be...
authordorlov <dorlov@opencascade.com>
Thu, 19 Jan 2023 16:20:59 +0000 (16:20 +0000)
committervglukhik <vglukhik@opencascade.com>
Fri, 17 Mar 2023 23:04:14 +0000 (23:04 +0000)
Added two new overloaded methods XCAFDoc_ShapeTool::GetOneShape: one returns TopoDS_Shape from TDF_LabelSequence and the other from a sequence of all top-level shapes which are free

src/XCAFDoc/XCAFDoc_ShapeTool.cxx
src/XCAFDoc/XCAFDoc_ShapeTool.hxx
src/XDEDRAW/XDEDRAW_Shapes.cxx
tests/bugs/xde/bug30828 [new file with mode: 0644]

index 85e3ecc0e39a539eb149a6060fbb7941f7954ded..67b7691d5728ffebc3e55fe331efbb01db169c8d 100644 (file)
@@ -353,6 +353,47 @@ TopoDS_Shape XCAFDoc_ShapeTool::GetShape(const TDF_Label& L)
   return aShape;
 }
 
+//=======================================================================
+//function : GetShapes
+//purpose  : 
+//=======================================================================
+TopoDS_Shape XCAFDoc_ShapeTool::GetOneShape(const TDF_LabelSequence& theLabels)
+{
+  TopoDS_Shape aShape;
+  if (theLabels.Length() == 1)
+  {
+    return GetShape(theLabels.Value(1));
+  }
+  TopoDS_Compound aCompound;
+  BRep_Builder aBuilder;
+  aBuilder.MakeCompound(aCompound);
+  for (TDF_LabelSequence::Iterator anIt(theLabels); anIt.More(); anIt.Next())
+  {
+    TopoDS_Shape aFreeShape;
+    if (!GetShape(anIt.Value(), aFreeShape))
+    {
+      continue;
+    }
+    aBuilder.Add(aCompound, aFreeShape);
+  }
+  if (aCompound.NbChildren() > 0)
+  {
+    aShape = aCompound;
+  }
+  return aShape;
+}
+
+//=======================================================================
+//function : GetOneShape
+//purpose  :
+//=======================================================================
+TopoDS_Shape XCAFDoc_ShapeTool::GetOneShape() const
+{
+  TDF_LabelSequence aLabels;
+  GetFreeShapes(aLabels);
+  return GetOneShape(aLabels);
+}
+
 //=======================================================================
 //function : NewShape
 //purpose  : 
index 100b0f6b10b84f0b6aa157fe8b32fc0a32051b22..752688afa6febe54f980eadc7441d1ee61aadda9 100644 (file)
@@ -196,6 +196,15 @@ public:
   //! For component, returns new shape with correct location
   //! Returns Null shape if label does not contain shape
   Standard_EXPORT static TopoDS_Shape GetShape (const TDF_Label& L);
+
+  //! Gets shape from a sequence of shape's labels
+  //! @param[in] theLabels a sequence of labels to get shapes from
+  //! @return original shape in case of one label and a compound of shapes in case of more
+  Standard_EXPORT static TopoDS_Shape GetOneShape(const TDF_LabelSequence& theLabels);
+
+  //! Gets shape from a sequence of all top-level shapes which are free
+  //! @return original shape in case of one label and a compound of shapes in case of more
+  Standard_EXPORT TopoDS_Shape GetOneShape() const;
   
   //! Creates new (empty) top-level shape.
   //! Initially it holds empty TopoDS_Compound
index dc0edf0b5e4a6d540d69ba0bc3dbb134e67fc611..eeb7a8bb3e8e1bc30b615e6204b1056f944564bf 100644 (file)
@@ -509,40 +509,37 @@ static Standard_Integer getFreeShapes (Draw_Interpretor& di, Standard_Integer ar
   return 0;
 }
 
-static Standard_Integer getOneShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+//=======================================================================
+//function : getOneShape
+//purpose  :
+//=======================================================================
+static Standard_Integer getOneShape (Draw_Interpretor& theDI, 
+                                     Standard_Integer theNbArgs, 
+                                     const char** theArgVec)
 {
-  if (argc!=3) {
-    di<<"Use: "<<argv[0]<<" shape DocName \n";
+  if ( theNbArgs !=3 )
+  {
+    theDI <<"Use: "<< theArgVec[0]<<" shape DocName \n";
     return 1;
   }
   
-  Handle(TDocStd_Document) Doc;   
-  DDocStd::GetDocument(argv[2], Doc);
-  if ( Doc.IsNull() ) { di << argv[2] << " is not a document\n"; return 1; }
-
-  TDF_LabelSequence Labels;
-  Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
-  STool->GetFreeShapes(Labels);
-  if ( Labels.Length() <=0 ) {
-    di << "Document " << argv[2] << " contain no shapes\n";
-    return 0;
-  }
-  
-  if ( Labels.Length() ==1 ) {
-    TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
-    DBRep::Set ( argv[1], S );
+  Handle(TDocStd_Document) aDoc;   
+  DDocStd::GetDocument(theArgVec[2], aDoc);
+  if ( aDoc.IsNull() )
+  { 
+    theDI << "Error: " << theArgVec[2] << " is not a document\n";
+    return 1;
   }
-  else {
-    TopoDS_Compound C;
-    BRep_Builder B;
-    B.MakeCompound ( C );
-    for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
-      TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
-      B.Add ( C, S );
-    }
-    DBRep::Set ( argv[1], C );
+
+  Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
+  TopoDS_Shape aShape = aSTool->GetOneShape();
+  if (aShape.IsNull())
+  {
+    theDI << "Error: Document " << theArgVec[2] << " contain no shapes\n";
+    return 1;
   }
-  di << argv[1];
+  DBRep::Set (theArgVec[1], aShape);
+  theDI << theArgVec[1];
   return 0;
 }
 
diff --git a/tests/bugs/xde/bug30828 b/tests/bugs/xde/bug30828
new file mode 100644 (file)
index 0000000..ea34f27
--- /dev/null
@@ -0,0 +1,16 @@
+puts "======="
+puts "0030828: Data Exchange - The commands getting shapes from XCAF document should be available in C++"
+puts "======="
+
+pload OCAF
+XNewDoc D
+box b1 10 10 10
+XAddShape D b1 1 
+XGetOneShape b D
+checknbshapes b -shape 34 
+box b2 10 10 10
+ttranslate b2 20 0 0 
+XAddShape D b2 1
+XGetOneShape c D
+checknbshapes c -shape 69 -compound 1
+Close D -silent