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
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 :
//! 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
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;
}
--- /dev/null
+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