mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0030828: Data Exchange - The commands getting shapes from XCAF document should be available in C++
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
This commit is contained in:
parent
53eae1a935
commit
c772c6caa4
@ -353,6 +353,47 @@ TopoDS_Shape XCAFDoc_ShapeTool::GetShape(const TDF_Label& L)
|
|||||||
return aShape;
|
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
|
//function : NewShape
|
||||||
//purpose :
|
//purpose :
|
||||||
|
@ -196,6 +196,15 @@ public:
|
|||||||
//! For component, returns new shape with correct location
|
//! For component, returns new shape with correct location
|
||||||
//! Returns Null shape if label does not contain shape
|
//! Returns Null shape if label does not contain shape
|
||||||
Standard_EXPORT static TopoDS_Shape GetShape (const TDF_Label& L);
|
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.
|
//! Creates new (empty) top-level shape.
|
||||||
//! Initially it holds empty TopoDS_Compound
|
//! Initially it holds empty TopoDS_Compound
|
||||||
|
@ -509,40 +509,37 @@ static Standard_Integer getFreeShapes (Draw_Interpretor& di, Standard_Integer ar
|
|||||||
return 0;
|
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) {
|
if ( theNbArgs !=3 )
|
||||||
di<<"Use: "<<argv[0]<<" shape DocName \n";
|
{
|
||||||
|
theDI <<"Use: "<< theArgVec[0]<<" shape DocName \n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle(TDocStd_Document) Doc;
|
Handle(TDocStd_Document) aDoc;
|
||||||
DDocStd::GetDocument(argv[2], Doc);
|
DDocStd::GetDocument(theArgVec[2], aDoc);
|
||||||
if ( Doc.IsNull() ) { di << argv[2] << " is not a document\n"; return 1; }
|
if ( aDoc.IsNull() )
|
||||||
|
{
|
||||||
|
theDI << "Error: " << theArgVec[2] << " is not a document\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
TDF_LabelSequence Labels;
|
Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
|
||||||
Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
|
TopoDS_Shape aShape = aSTool->GetOneShape();
|
||||||
STool->GetFreeShapes(Labels);
|
if (aShape.IsNull())
|
||||||
if ( Labels.Length() <=0 ) {
|
{
|
||||||
di << "Document " << argv[2] << " contain no shapes\n";
|
theDI << "Error: Document " << theArgVec[2] << " contain no shapes\n";
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
DBRep::Set (theArgVec[1], aShape);
|
||||||
if ( Labels.Length() ==1 ) {
|
theDI << theArgVec[1];
|
||||||
TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
|
|
||||||
DBRep::Set ( argv[1], S );
|
|
||||||
}
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
di << argv[1];
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
tests/bugs/xde/bug30828
Normal file
16
tests/bugs/xde/bug30828
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user