1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00

0029436: Data Exchange - Extend Expand compounds functionality.

Extend permissions for expand in ShapeTool
Fix processing of subshapes
Fix misprints
Add test cases
This commit is contained in:
ika 2018-01-19 13:36:30 +03:00 committed by apn
parent b6cf8ffa35
commit 00dfcc765a
9 changed files with 145 additions and 18 deletions

View File

@ -34,7 +34,7 @@
//======================================================================= //=======================================================================
//function : Expand //function : Expand
//purpose : Convert Shape(compound) to assambly //purpose : Convert Shape to assembly
//======================================================================= //=======================================================================
Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const TDF_Label& Shape, Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const TDF_Label& Shape,
@ -48,16 +48,13 @@ Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const TDF_Label&
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(Doc); Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(Doc);
TopoDS_Shape aS = aShapeTool->GetShape(Shape); TopoDS_Shape aS = aShapeTool->GetShape(Shape);
if (!aS.IsNull() && aS.ShapeType() == TopAbs_COMPOUND && !aShapeTool->IsAssembly(Shape)) if (aShapeTool->Expand(Shape))
{ {
//convert compound to assembly(without attributes) //move attributes
aShapeTool->Expand(Shape);
//move attrributes
TDF_ChildIterator anIter(Shape, Standard_True); TDF_ChildIterator anIter(Shape, Standard_True);
for(; anIter.More(); anIter.Next()) for(; anIter.More(); anIter.Next())
{ {
TDF_Label aChild = anIter.Value(); TDF_Label aChild = anIter.Value();
TDF_LabelSequence aLayers; TDF_LabelSequence aLayers;
TDF_LabelSequence aColors; TDF_LabelSequence aColors;
Handle(TDataStd_Name) aName; Handle(TDataStd_Name) aName;
@ -85,6 +82,24 @@ Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const TDF_Label&
aChild.ForgetAttribute(TNaming_NamedShape::GetID()); aChild.ForgetAttribute(TNaming_NamedShape::GetID());
aChild.ForgetAttribute(XCAFDoc_ShapeMapTool::GetID()); aChild.ForgetAttribute(XCAFDoc_ShapeMapTool::GetID());
} }
else
{
// If new original shape is not created, try to process this child
// as subshape of new part
TDF_LabelSequence aUsers;
if (aShapeTool->GetUsers(aChild, aUsers) > 0)
{
for (Standard_Integer i = 1; i <= aUsers.Length(); i++)
{
TDF_Label aSubLabel = aUsers.Value(i);
setParams(Doc, aSubLabel, aColors, aLayers, aName);
//remove unnecessary links
aSubLabel.ForgetAttribute(XCAFDoc::ShapeRefGUID());
aSubLabel.ForgetAttribute(XCAFDoc_ShapeMapTool::GetID());
}
aChild.ForgetAllAttributes(Standard_False);
}
}
} }
//if assembly contains compound, expand it recursively(if flag recursively is true) //if assembly contains compound, expand it recursively(if flag recursively is true)
if(recursively) if(recursively)
@ -96,6 +111,8 @@ Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const TDF_Label&
TDF_Label aPart; TDF_Label aPart;
if(aShapeTool->GetReferredShape(aChild, aPart)) if(aShapeTool->GetReferredShape(aChild, aPart))
{ {
TopoDS_Shape aPartShape = aShapeTool->GetShape(aPart);
if (aPartShape.ShapeType() == TopAbs_COMPOUND)
Expand(Doc, aPart, recursively); Expand(Doc, aPart, recursively);
} }
} }
@ -107,7 +124,7 @@ Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const TDF_Label&
//======================================================================= //=======================================================================
//function : Expand //function : Expand
//purpose : Convert all compounds in Doc to assambly //purpose : Convert all compounds in Doc to assembly
//======================================================================= //=======================================================================
Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const Standard_Boolean recursively) Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const Standard_Boolean recursively)

View File

@ -35,7 +35,8 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Convert Shape(compound) to assembly //! Convert Shape (compound/compsolid/shell/wire) to assembly.
//! Only compounds expanded recursively
Standard_EXPORT static Standard_Boolean Expand (const TDF_Label& Doc, const TDF_Label& Shape, const Standard_Boolean recursively = Standard_True) ; Standard_EXPORT static Standard_Boolean Expand (const TDF_Label& Doc, const TDF_Label& Shape, const Standard_Boolean recursively = Standard_True) ;
//! Convert all compounds in Doc to assembly //! Convert all compounds in Doc to assembly

View File

@ -1804,11 +1804,17 @@ Standard_Boolean XCAFDoc_ShapeTool::FindSHUO (const TDF_LabelSequence& theLabels
Standard_Boolean XCAFDoc_ShapeTool::Expand (const TDF_Label& Shape) Standard_Boolean XCAFDoc_ShapeTool::Expand (const TDF_Label& Shape)
{ {
if(Shape.IsNull()) if (Shape.IsNull() || IsAssembly(Shape))
return Standard_False; return Standard_False;
TopoDS_Shape aShape = GetShape(Shape); TopoDS_Shape aShape = GetShape(Shape);
if(!aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND && !IsAssembly(Shape)) if (aShape.IsNull())
return Standard_False;
TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
Standard_Boolean isExpandedType = aShapeType == TopAbs_COMPOUND || aShapeType == TopAbs_COMPSOLID ||
aShapeType == TopAbs_SHELL || aShapeType == TopAbs_WIRE;
if (isExpandedType)
{ {
//set assembly attribute //set assembly attribute
TDataStd_UAttribute::Set ( Shape, XCAFDoc::AssemblyGUID() ); TDataStd_UAttribute::Set ( Shape, XCAFDoc::AssemblyGUID() );
@ -1818,7 +1824,6 @@ Standard_Boolean XCAFDoc_ShapeTool::Expand (const TDF_Label& Shape)
{ {
TopoDS_Shape aChildShape = anIter.Value(); TopoDS_Shape aChildShape = anIter.Value();
TDF_Label aChild = FindShape(aChildShape, Standard_True); TDF_Label aChild = FindShape(aChildShape, Standard_True);
TDF_TagSource aTag; TDF_TagSource aTag;
Handle(TDataStd_Name) anAttr; Handle(TDataStd_Name) anAttr;
//make part for child //make part for child
@ -1837,7 +1842,6 @@ Standard_Boolean XCAFDoc_ShapeTool::Expand (const TDF_Label& Shape)
aChild.FindAttribute(TDataStd_Name::GetID(), anAttr); aChild.FindAttribute(TDataStd_Name::GetID(), anAttr);
TopLoc_Location nulloc; TopLoc_Location nulloc;
SetShape(aPart, aChildShape.Located(nulloc)); SetShape(aPart, aChildShape.Located(nulloc));
} }
//set name to part //set name to part
if(!anAttr.IsNull()) if(!anAttr.IsNull())
@ -1895,7 +1899,8 @@ void XCAFDoc_ShapeTool::makeSubShape (const TDF_Label& Part, const TopoDS_Shape&
TCollection_AsciiString aName (Stream.str().c_str()); TCollection_AsciiString aName (Stream.str().c_str());
TDataStd_Name::Set(aSubLabel, TCollection_ExtendedString(aName)); TDataStd_Name::Set(aSubLabel, TCollection_ExtendedString(aName));
} }
MakeReference(aChildLabel, aSubLabel, aChildShape.Location()); // Create auxiliary link, it will be removed during moving attributes
MakeReference(aSubLabel, aChildLabel, aChildShape.Location());
} }
makeSubShape(Part, aChildShape); makeSubShape(Part, aChildShape);
} }

View File

@ -404,7 +404,7 @@ public:
//! Returns null attribute if no SHUO found //! Returns null attribute if no SHUO found
Standard_EXPORT static Standard_Boolean FindSHUO (const TDF_LabelSequence& Labels, Handle(XCAFDoc_GraphNode)& theSHUOAttr); Standard_EXPORT static Standard_Boolean FindSHUO (const TDF_LabelSequence& Labels, Handle(XCAFDoc_GraphNode)& theSHUOAttr);
//! Convert Shape (compound) to assembly //! Convert Shape (compound/compsolid/shell/wire) to assembly
Standard_EXPORT Standard_Boolean Expand (const TDF_Label& Shape) ; Standard_EXPORT Standard_Boolean Expand (const TDF_Label& Shape) ;
//! Make subshape for Part from Shape //! Make subshape for Part from Shape

View File

@ -484,7 +484,7 @@ static Standard_Integer Expand (Draw_Interpretor& di, Standard_Integer argc, con
if (argc == 3) if (argc == 3)
{ {
if(!XCAFDoc_Editor::Expand(Doc->Main(), recurs)){ if(!XCAFDoc_Editor::Expand(Doc->Main(), recurs)){
di << "The shape is assembly or not compaund\n"; di << "No suitable labels to expand\n";
return 1; return 1;
} }
} }
@ -502,7 +502,7 @@ static Standard_Integer Expand (Draw_Interpretor& di, Standard_Integer argc, con
if (!aLabel.IsNull()){ if (!aLabel.IsNull()){
if(!XCAFDoc_Editor::Expand(Doc->Main(), aLabel, recurs)){ if(!XCAFDoc_Editor::Expand(Doc->Main(), aLabel, recurs)){
di << "The shape is assembly or not compaund\n"; di << "The shape is assembly or not compound\n";
return 1; return 1;
} }
} }
@ -534,7 +534,7 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& di)
di.Add("XFileSet", "filename: Set the specified file to be the current one",__FILE__, SetCurWS, g); di.Add("XFileSet", "filename: Set the specified file to be the current one",__FILE__, SetCurWS, g);
di.Add("XFromShape", "shape: do fromshape command for all the files",__FILE__, FromShape, g); di.Add("XFromShape", "shape: do fromshape command for all the files",__FILE__, FromShape, g);
di.Add("XExpand", "XExpand Doc recursively(0/1) or XExpand Doc recursively(0/1) label1 abel2 ..." di.Add("XExpand", "XExpand Doc recursively(0/1) or XExpand Doc recursively(0/1) label1 label2 ..."
"or XExpand Doc recursively(0/1) shape1 shape2 ...",__FILE__, Expand, g); "or XExpand Doc recursively(0/1) shape1 shape2 ...",__FILE__, Expand, g);
} }

27
tests/bugs/xde/bug29436_1 Normal file
View File

@ -0,0 +1,27 @@
puts "=========="
puts "OCC29436"
puts "=========="
puts ""
########################################
# Extend Expand compounds functionality
########################################
pload ALL
XOpen [locate_data_file bug29436_compound.xbf] D
XExpand D 1 0:1:1:1
# check colors
set color [XGetShapeColor D 0:1:1:2]
if {$color != "GREEN"} {
puts "Error: metadata lost during expand"
}
set color [XGetShapeColor D 0:1:1:3]
if {$color != "GREEN"} {
puts "Error: metadata lost during expand"
}
set color [XGetShapeColor D 0:1:1:2:1]
if {$color != "CYAN1"} {
puts "Error: metadata lost during expand"
}
Close D

27
tests/bugs/xde/bug29436_2 Normal file
View File

@ -0,0 +1,27 @@
puts "=========="
puts "OCC29436"
puts "=========="
puts ""
########################################
# Extend Expand compounds functionality
########################################
pload ALL
XOpen [locate_data_file bug29436_compsolid.xbf] D
XExpand D 1 0:1:1:1
# check colors
set color [XGetShapeColor D 0:1:1:2]
if {$color != "RED"} {
puts "Error: metadata lost during expand"
}
set color [XGetShapeColor D 0:1:1:4]
if {$color != "RED"} {
puts "Error: metadata lost during expand"
}
set color [XGetShapeColor D 0:1:1:6]
if {$color != "RED"} {
puts "Error: metadata lost during expand"
}
Close D

23
tests/bugs/xde/bug29436_3 Normal file
View File

@ -0,0 +1,23 @@
puts "=========="
puts "OCC29436"
puts "=========="
puts ""
########################################
# Extend Expand compounds functionality
########################################
pload ALL
XOpen [locate_data_file bug29436_shell.xbf] D
XExpand D 1 0:1:1:1
# check colors
set color [XGetShapeColor D 0:1:1:2:1 c]
if {$color != "RED"} {
puts "Error: metadata lost during expand"
}
set color [XGetShapeColor D 0:1:1:4:1 c]
if {$color != "RED"} {
puts "Error: metadata lost during expand"
}
Close D

27
tests/bugs/xde/bug29436_4 Normal file
View File

@ -0,0 +1,27 @@
puts "=========="
puts "OCC29436"
puts "=========="
puts ""
########################################
# Extend Expand compounds functionality
########################################
pload ALL
XOpen [locate_data_file bug29436_wire.xbf] D
XExpand D 1 0:1:1:1
# check colors
set color [XGetShapeColor D 0:1:1:2 c]
if {$color != "RED"} {
puts "Error: metadata lost during expand"
}
set color [XGetShapeColor D 0:1:1:2:1]
if {$color != "RED"} {
puts "Error: metadata lost during expand"
}
set color [XGetShapeColor D 0:1:1:3:1]
if {$color != "RED"} {
puts "Error: metadata lost during expand"
}
#Close D