//=======================================================================
//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,
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(Doc);
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)
- aShapeTool->Expand(Shape);
- //move attrributes
+ //move attributes
TDF_ChildIterator anIter(Shape, Standard_True);
for(; anIter.More(); anIter.Next())
{
TDF_Label aChild = anIter.Value();
-
TDF_LabelSequence aLayers;
TDF_LabelSequence aColors;
Handle(TDataStd_Name) aName;
aChild.ForgetAttribute(TNaming_NamedShape::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(recursively)
TDF_Label aPart;
if(aShapeTool->GetReferredShape(aChild, aPart))
{
- Expand(Doc, aPart, recursively);
+ TopoDS_Shape aPartShape = aShapeTool->GetShape(aPart);
+ if (aPartShape.ShapeType() == TopAbs_COMPOUND)
+ Expand(Doc, aPart, recursively);
}
}
}
//=======================================================================
//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)
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) ;
//! Convert all compounds in Doc to assembly
Standard_Boolean XCAFDoc_ShapeTool::Expand (const TDF_Label& Shape)
{
- if(Shape.IsNull())
+ if (Shape.IsNull() || IsAssembly(Shape))
return Standard_False;
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
TDataStd_UAttribute::Set ( Shape, XCAFDoc::AssemblyGUID() );
{
TopoDS_Shape aChildShape = anIter.Value();
TDF_Label aChild = FindShape(aChildShape, Standard_True);
-
TDF_TagSource aTag;
Handle(TDataStd_Name) anAttr;
//make part for child
aChild.FindAttribute(TDataStd_Name::GetID(), anAttr);
TopLoc_Location nulloc;
SetShape(aPart, aChildShape.Located(nulloc));
-
}
//set name to part
if(!anAttr.IsNull())
TCollection_AsciiString aName (Stream.str().c_str());
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);
}
//! Returns null attribute if no SHUO found
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) ;
//! Make subshape for Part from Shape
if (argc == 3)
{
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;
}
}
if (!aLabel.IsNull()){
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;
}
}
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("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);
}
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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