Changed behavior of XCAFDoc_ShapeTool::RemoveShape(const TDF_Label& L) function. Now if L is a location for a shape then function will also removes the label with a shape.
Added Boolean argument to the XCAFDoc_ShapeTool::RemoveShape function which allow to choose either to delete an instance or a complete shape. (Standard_True by default, removes complete shape).
---Purpose: Adds a new top-level (creates and returns a new label)
-- For internal use. Used by public method AddShape.
- RemoveShape (me; L: Label from TDF) returns Boolean;
+ RemoveShape (me; L: Label from TDF;
+ removeCompletely: Boolean = Standard_True)
+ returns Boolean;
---Purpose: Removes shape (whole label and all its sublabels)
+ -- If removeCompletely is true, removes complete shape
+ -- If removeCompletely is false, removes instance(location) only
-- Returns False (and does nothing) if shape is not free
-- or is not top-level shape
//purpose :
//=======================================================================
-Standard_Boolean XCAFDoc_ShapeTool::RemoveShape (const TDF_Label& L) const
+Standard_Boolean XCAFDoc_ShapeTool::RemoveShape (const TDF_Label& L,
+ const Standard_Boolean removeCompletely) const
{
if ( ! IsTopLevel ( L ) || ! IsFree ( L ) ) return Standard_False;
+
+ Handle(TDataStd_TreeNode) aNode;
+ TDF_Label aLabel;
+ if (removeCompletely &&
+ L.FindAttribute (XCAFDoc::ShapeRefGUID(), aNode) &&
+ aNode->HasFather() &&
+ L.IsAttribute (XCAFDoc_Location::GetID()))
+ {
+ aLabel = aNode->Father()->Label();
+ }
+
L.ForgetAllAttributes (Standard_True);
+
+ if (removeCompletely && !aLabel.IsNull())
+ {
+ return RemoveShape(aLabel);
+ }
return Standard_True;
}
static Standard_Integer removeShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (argc!=3) {
- di<<"Use: "<<argv[0]<<" DocName Label"<<"\n";
+ if (argc != 3 && argc != 4)
+ {
+ di<<"Use: "<<argv[0]<<" DocName Label [int removeCompletely (1/0)]"<<"\n";
return 1;
}
Handle(TDocStd_Document) Doc;
// XCAFDoc_ShapeTool myAssembly;
// myAssembly.Init(Doc);
Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
- myAssembly->RemoveShape(aLabel);
+ Standard_Boolean removeCompletely = Standard_True;
+ if ( argc == 4 && atoi(argv[3]) == 0 )
+ removeCompletely = Standard_False;
+ myAssembly->RemoveShape(aLabel, removeCompletely);
return 0;
}