1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-18 14:27:39 +03:00

0030727: Data Exchange - Problems in Shape Tool

Add protection from return of not top-level shape by FindShape method.
Add protection against located roots into FindMainShape method.
Add new Draw command for FindMainShape.
Add flag findInstance to Draw command FindShape
This commit is contained in:
ika
2019-05-22 15:22:54 +03:00
committed by bugmaster
parent 47cd8af2d2
commit 7783ba1120
9 changed files with 97 additions and 25 deletions

View File

@@ -303,20 +303,26 @@ Standard_Boolean XCAFDoc_ShapeTool::FindShape (const TopoDS_Shape& S,
if (TNaming_Tool::HasLabel(Label(), S0)) {
int TransDef = 0;
L = TNaming_Tool::Label(Label(), S0, TransDef);
return Standard_True;
}
/*
TDF_ChildIDIterator it(myLabel,TNaming_NamedShape::GetID());
else
return Standard_False;
if (IsTopLevel(L))
return Standard_True;
// Try to find shape manually
TDF_ChildIDIterator it(Label(), TNaming_NamedShape::GetID());
for (; it.More(); it.Next()) {
TDF_Label aLabel = it.Value()->Label();
Handle(TNaming_NamedShape) NS;
if ( aLabel.FindAttribute(TNaming_NamedShape::GetID(), NS) &&
S0.IsSame ( TNaming_Tool::GetShape(NS) ) ) {
S0.IsSame ( TNaming_Tool::GetShape(NS) ) ) {
L = aLabel;
return Standard_True;
}
}
*/
L = TDF_Label();
return Standard_False;
}
@@ -1154,7 +1160,8 @@ TDF_Label XCAFDoc_ShapeTool::FindMainShape (const TopoDS_Shape &sub) const
TDF_ChildIterator it(Label());
for (; it.More(); it.Next()) {
TDF_Label L = it.Value();
if ( ! IsAssembly ( L ) && IsSubShape ( L, sub ) ) return L;
if ( IsSimpleShape( L ) && IsSubShape ( L, sub ) ) return L;
}
TDF_Label L0;
return L0;

View File

@@ -176,11 +176,11 @@ public:
//! Returns the label corresponding to shape S
//! (searches among top-level shapes, not including subcomponents
//! of assemblies)
//! If findInstance is False (default), searches for the
//! non-located shape (i.e. among original shapes)
//! If findInstance is True, searches for the shape with the same
//! location, including shape instances
//! of assemblies and subshapes)
//! If findInstance is False (default), seach for the
//! input shape without location
//! If findInstance is True, searches for the
//! input shape as is.
//! Return True if <S> is found.
Standard_EXPORT Standard_Boolean FindShape (const TopoDS_Shape& S, TDF_Label& L, const Standard_Boolean findInstance = Standard_False) const;

View File

@@ -163,8 +163,8 @@ static Standard_Integer removeShape (Draw_Interpretor& di, Standard_Integer argc
static Standard_Integer findShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc!=3) {
di<<"Use: "<<argv[0]<<" DocName Shape\n";
if (argc < 3) {
di << "Use: " << argv[0] << " DocName Shape [0/1]\n";
return 1;
}
Handle(TDocStd_Document) Doc;
@@ -177,7 +177,8 @@ static Standard_Integer findShape (Draw_Interpretor& di, Standard_Integer argc,
// XCAFDoc_ShapeTool myAssembly;
// myAssembly.Init(Doc);
Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
aLabel = myAssembly->FindShape(aShape);
Standard_Boolean findInstance = ((argc == 4) && argv[3][0] == '1');
aLabel = myAssembly->FindShape(aShape, findInstance);
TCollection_AsciiString Entry;
TDF_Tool::Entry(aLabel, Entry);
di << Entry.ToCString();
@@ -214,6 +215,32 @@ static Standard_Integer findSubShape(Draw_Interpretor& di, Standard_Integer argc
return 0;
}
static Standard_Integer findMainShape(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc != 3) {
di << "Use: " << argv[0] << " DocName SubShape\n";
return 1;
}
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[1], aDoc);
if (aDoc.IsNull()) {
di << argv[1] << " is not a document\n";
return 1;
}
TopoDS_Shape aShape;
aShape = DBRep::Get(argv[2]);
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
TDF_Label aLabel = aShapeTool->FindMainShape(aShape);
TCollection_AsciiString anEntry;
TDF_Tool::Entry(aLabel, anEntry);
di << anEntry.ToCString();
return 0;
}
static Standard_Integer addSubShape(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc != 4) {
@@ -935,12 +962,15 @@ void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di)
di.Add ("XRemoveShape","Doc Label \t: Remove shape from document",
__FILE__, removeShape, g);
di.Add ("XFindShape","Doc Shape \t: Find and print label with indicated top-level shape",
di.Add ("XFindShape","Doc Shape [findInstance (0/1), 0 by default]\t: Find and print label with indicated top-level shape",
__FILE__, findShape, g);
di.Add("XFindSubShape", "Doc Shape ParentLabel \t: Find subshape under given parent shape label",
__FILE__, findSubShape, g);
di.Add("XFindMainShape", "Doc SubShape \t: Find main shape for given subshape",
__FILE__, findMainShape, g);
di.Add("XAddSubShape", "Doc Shape ParentLabel \t: Add subshape under given parent shape label",
__FILE__, addSubShape, g);