1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0026216: New functionality. Converting the compound to assembly.

Added new functionality for converting the compound to assembly.
Added new drw command XExpand.
Changed DumpShape and DumpAssembly
Added test.

test changed
This commit is contained in:
ink
2015-08-19 12:37:28 +03:00
committed by bugmaster
parent d33a8cde96
commit 5f07d05d0e
10 changed files with 599 additions and 18 deletions

View File

@@ -1221,20 +1221,44 @@ static void DumpAssembly(Standard_OStream& theDumpLog,
const Standard_Integer level,
const Standard_Boolean deep)
{
TopoDS_Shape S;
XCAFDoc_ShapeTool::GetShape(L, S);
if(S.IsNull())
return;
for (Standard_Integer i=0; i<level; i++)
theDumpLog<<"\t";
TCollection_AsciiString Entry;
TDF_Tool::Entry(L, Entry);
if(XCAFDoc_ShapeTool::IsAssembly(L))
{
theDumpLog<<"ASSEMBLY ";
}
else if (XCAFDoc_ShapeTool::IsSimpleShape(L))
{
if(L.Father().Father().Father().IsRoot())
theDumpLog<<"PART ";
}
else
{
theDumpLog<<"INSTANCE ";
}
TopAbs::Print(S.ShapeType(), theDumpLog);
theDumpLog<<"ASSEMBLY "<<Entry;
theDumpLog<<" "<<Entry;
if(XCAFDoc_ShapeTool::IsReference(L))
{
Handle(TDataStd_TreeNode) aRef;
L.FindAttribute(XCAFDoc::ShapeRefGUID(), aRef);
TDF_Tool::Entry(aRef->Father()->Label(), Entry);
theDumpLog<<" (refers to "<<Entry<<")";
}
Handle(TDataStd_Name) Name;
if (L.FindAttribute(TDataStd_Name::GetID(), Name))
theDumpLog<<" "<<Name->Get();
theDumpLog<<" \""<<Name->Get()<<"\" ";
if (deep) {
TopoDS_Shape S;
XCAFDoc_ShapeTool::GetShape(L, S);
theDumpLog<<"("<<*(void**)&S.TShape();
if (! S.Location().IsIdentity())
theDumpLog<<", "<< *(void**)&S.Location();
@@ -1243,18 +1267,12 @@ static void DumpAssembly(Standard_OStream& theDumpLog,
theDumpLog<<endl;
Handle(TDataStd_TreeNode) Node;
TDF_ChildIDIterator NodeIterator(L, XCAFDoc::ShapeRefGUID());
TDF_ChildIterator NodeIterator(L);
for (; NodeIterator.More(); NodeIterator.Next()) {
Node = Handle(TDataStd_TreeNode)::DownCast(NodeIterator.Value());
if (Node->HasFather()) {
if (Node->Father()->Label().HasChild())
DumpAssembly(theDumpLog, Node->Father()->Label(), level+1, deep);
else {
XCAFDoc_ShapeTool::DumpShape(theDumpLog, Node->Father()->Label(), level+1, deep);
theDumpLog<<endl;
}
}
DumpAssembly(theDumpLog, NodeIterator.Value(), level+1, deep);
}
if(level == 0)
theDumpLog<<endl;
}
//=======================================================================
@@ -1296,16 +1314,35 @@ void XCAFDoc_ShapeTool::DumpShape(Standard_OStream& theDumpLog, const TDF_Label&
for (Standard_Integer i=0; i<level; i++)
theDumpLog<<"\t";
if (S.ShapeType() == TopAbs_COMPOUND) theDumpLog<<"ASSEMBLY";
else TopAbs::Print(S.ShapeType(), theDumpLog);
if(XCAFDoc_ShapeTool::IsAssembly(L))
{
theDumpLog<<"ASSEMBLY ";
}
else if (XCAFDoc_ShapeTool::IsSimpleShape(L))
{
if(L.Father().Father().Father().IsRoot())
theDumpLog<<"PART ";
}
else
{
theDumpLog<<"INSTANCE ";
}
TopAbs::Print(S.ShapeType(), theDumpLog);
TCollection_AsciiString Entry;
TDF_Tool::Entry(L, Entry);
theDumpLog<<" "<<Entry;
if(XCAFDoc_ShapeTool::IsReference(L))
{
Handle(TDataStd_TreeNode) aRef;
L.FindAttribute(XCAFDoc::ShapeRefGUID(), aRef);
TDF_Tool::Entry(aRef->Father()->Label(), Entry);
theDumpLog<<" (refers to "<<Entry<<")";
}
//cout<<endl;
Handle(TDataStd_Name) Name;
if (L.FindAttribute(TDataStd_Name::GetID(),Name))
theDumpLog<<" "<<Name->Get();
theDumpLog<<" \""<<Name->Get()<<"\" ";
if (deep) {
theDumpLog<<"("<<*(void**)&S.TShape();
@@ -1796,3 +1833,107 @@ Standard_Boolean XCAFDoc_ShapeTool::FindSHUO (const TDF_LabelSequence& theLabels
}
return ( !theSHUOAttr.IsNull() );
}
//=======================================================================
//function : Expand
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_ShapeTool::Expand (const TDF_Label& Shape)
{
if(Shape.IsNull())
return Standard_False;
TopoDS_Shape aShape = GetShape(Shape);
if(!aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND && !IsAssembly(Shape))
{
//set assembly attribute
TDataStd_UAttribute::Set ( Shape, XCAFDoc::AssemblyGUID() );
TopoDS_Iterator anIter(aShape);
for(; anIter.More(); anIter.Next())
{
TopoDS_Shape aChildShape = anIter.Value();
TDF_Label aChild = FindShape(aChildShape, Standard_True);
TDF_TagSource aTag;
Handle(TDataStd_Name) anAttr;
//make part for child
TDF_Label aPart = aTag.NewChild(Label());
//make child (if color isn't set or if it is compound)
if(aChild.IsNull())
{
TopLoc_Location nulloc;
aChild = aTag.NewChild(Shape);
SetShape(aChild, aChildShape);
SetShape(aPart, aChildShape.Located(nulloc));
}
else
{
//get name
aChild.FindAttribute(TDataStd_Name::GetID(), anAttr);
TopLoc_Location nulloc;
SetShape(aPart, aChildShape.Located(nulloc));
}
//set name to part
if(!anAttr.IsNull())
{
TDataStd_Name::Set(aPart, anAttr->Get());
}
else
{
Standard_SStream Stream;
TopAbs::Print(aChildShape.ShapeType(), Stream);
TCollection_AsciiString aName (Stream.str().c_str());
TDataStd_Name::Set(aPart, TCollection_ExtendedString(aName));
}
MakeReference(aChild, aPart, aChildShape.Location());
makeSubShape(aPart, aChildShape);
}
return Standard_True;
}
return Standard_False;
}
//=======================================================================
//function : makeSubShape
//purpose :
//=======================================================================
void XCAFDoc_ShapeTool::makeSubShape (const TDF_Label& Part, const TopoDS_Shape& Shape)
{
TDF_TagSource aTag;
TopoDS_Iterator anIter(Shape);
for(; anIter.More(); anIter.Next())
{
TopoDS_Shape aChildShape = anIter.Value();
TDF_Label aChildLabel = FindShape(aChildShape,Standard_True);
if(!aChildLabel.IsNull())
{
//get name
Handle(TDataStd_Name) anAttr;
aChildLabel.FindAttribute(TDataStd_Name::GetID(), anAttr);
TopLoc_Location nulloc;
//make subshape
TDF_Label aSubLabel = aTag.NewChild(Part);
SetShape(aSubLabel, aChildShape.Located(nulloc));
//set name to sub shape
if(!anAttr.IsNull())
{
TDataStd_Name::Set(aSubLabel, anAttr->Get());
}
else
{
Standard_SStream Stream;
TopAbs::Print(aChildShape.ShapeType(), Stream);
TCollection_AsciiString aName (Stream.str().c_str());
TDataStd_Name::Set(aSubLabel, TCollection_ExtendedString(aName));
}
MakeReference(aChildLabel, aSubLabel, aChildShape.Location());
}
makeSubShape(Part, aChildShape);
}
}