mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-03 17:56:21 +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:
parent
47cd8af2d2
commit
7783ba1120
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
35
tests/bugs/xde/bug30727
Normal file
35
tests/bugs/xde/bug30727
Normal file
@ -0,0 +1,35 @@
|
||||
puts "==============================================="
|
||||
puts "0030727: Data Exchange - Problems in Shape Tool"
|
||||
puts "==============================================="
|
||||
puts ""
|
||||
|
||||
pload DCAF
|
||||
|
||||
box b 1 1 1
|
||||
copy b bb
|
||||
ttranslate bb 2 0 0
|
||||
XNewDoc D
|
||||
XAddShape D bb
|
||||
explode bb f
|
||||
explode b f
|
||||
|
||||
set result [XFindMainShape D b_1]
|
||||
if {$result != "0:1:1:2"} {
|
||||
puts "Error: wrong result of FindMainShape"
|
||||
}
|
||||
|
||||
set result [XFindMainShape D bb_1]
|
||||
if {$result != ""} {
|
||||
puts "Error: wrong result of FindMainShape"
|
||||
}
|
||||
|
||||
XAddSubShape D b_1 0:1:1:2
|
||||
compound b_1 b_2 c
|
||||
XAddShape D c
|
||||
|
||||
set result [XGetTopLevelShapes D]
|
||||
if {$result != "0:1:1:1 0:1:1:2 0:1:1:3 0:1:1:4 0:1:1:5 "} {
|
||||
puts "Error: wrong result of FindMainShape"
|
||||
}
|
||||
Close D
|
||||
|
@ -12,7 +12,7 @@ CHECKSHAPE : Wires = 0 ( 0 ) Faces = 0 ( 0 ) Shells = 0 ( 0 ) So
|
||||
NBSHAPES : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 732 ( 732 )
|
||||
STATSHAPE : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 732 ( 732 ) FreeWire = 1612 ( 1613 )
|
||||
TOLERANCE : MaxTol = 0.6032674714 ( 0.6032674714 ) AvgTol = 0.001484585226 ( 0.001489802052 )
|
||||
LABELS : N0Labels = 4 ( 7 ) N1Labels = 11017 ( 18087 ) N2Labels = 0 ( 0 ) TotalLabels = 11021 ( 18094 ) NameLabels = 10620 ( 13085 ) ColorLabels = 11018 ( 18086 ) LayerLabels = 10517 ( 17934 )
|
||||
LABELS : N0Labels = 4 ( 7 ) N1Labels = 11017 ( 18087 ) N2Labels = 0 ( 0 ) TotalLabels = 11021 ( 18094 ) NameLabels = 10620 ( 13085 ) ColorLabels = 11018 ( 18086 ) LayerLabels = 10917 ( 17934 )
|
||||
PROPS : Centroid = 0 ( 0 ) Volume = 0 ( 0 ) Area = 0 ( 0 )
|
||||
NCOLORS : NColors = 17 ( 17 )
|
||||
COLORS : Colors = BLUE1 CYAN1 DARKGOLDENROD1 DARKSLATEGRAY1 GREEN GREEN4 LIGHTPINK1 MAGENTA1 MEDIUMPURPLE1 MEDIUMSPRINGGREEN PURPLE RED RED3 ROYALBLUE2 SEAGREEN2 WHITE YELLOW ( BLUE1 CYAN1 DARKGOLDENROD1 DARKSLATEGRAY1 GREEN GREEN4 LIGHTPINK1 MAGENTA1 MEDIUMPURPLE1 MEDIUMSPRINGGREEN PURPLE RED RED3 ROYALBLUE2 SEAGREEN2 WHITE YELLOW )
|
||||
|
@ -11,8 +11,8 @@ TPSTAT : Faulties = 0 ( 13 ) Warnings = 290 ( 688 ) Summary = 290 ( 7
|
||||
CHECKSHAPE : Wires = 0 ( 0 ) Faces = 0 ( 0 ) Shells = 0 ( 0 ) Solids = 0 ( 0 )
|
||||
NBSHAPES : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 200 ( 200 )
|
||||
STATSHAPE : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 200 ( 200 ) FreeWire = 0 ( 0 )
|
||||
TOLERANCE : MaxTol = 4.399371441e-006 ( 1.000236438e-007 ) AvgTol = 7.220418185e-007 ( 1.000013342e-007 )
|
||||
LABELS : N0Labels = 22 ( 23 ) N1Labels = 271 ( 279 ) N2Labels = 0 ( 0 ) TotalLabels = 293 ( 302 ) NameLabels = 22 ( 23 ) ColorLabels = 289 ( 290 ) LayerLabels = 89 ( 290 )
|
||||
TOLERANCE : MaxTol = 4.399371441e-006 ( 1.000236438e-007 ) AvgTol = 7.221372722e-007 ( 1.000013342e-007 )
|
||||
LABELS : N0Labels = 22 ( 23 ) N1Labels = 271 ( 279 ) N2Labels = 0 ( 0 ) TotalLabels = 293 ( 302 ) NameLabels = 22 ( 23 ) ColorLabels = 289 ( 290 ) LayerLabels = 289 ( 290 )
|
||||
PROPS : Centroid = 0 ( 0 ) Volume = 0 ( 0 ) Area = 0 ( 0 )
|
||||
NCOLORS : NColors = 2 ( 2 )
|
||||
COLORS : Colors = RED WHITE ( RED WHITE )
|
||||
|
@ -12,7 +12,7 @@ CHECKSHAPE : Wires = 0 ( 0 ) Faces = 0 ( 0 ) Shells = 0 ( 0 ) So
|
||||
NBSHAPES : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 9 ( 9 )
|
||||
STATSHAPE : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 9 ( 9 ) FreeWire = 477 ( 477 )
|
||||
TOLERANCE : MaxTol = 0.002386883227 ( 0.002386886993 ) AvgTol = 1.573802585e-006 ( 1.573804825e-006 )
|
||||
LABELS : N0Labels = 2053 ( 2148 ) N1Labels = 381 ( 253 ) N2Labels = 0 ( 0 ) TotalLabels = 2434 ( 2401 ) NameLabels = 2053 ( 2148 ) ColorLabels = 1932 ( 2306 ) LayerLabels = 1559 ( 2306 )
|
||||
LABELS : N0Labels = 2053 ( 2148 ) N1Labels = 381 ( 253 ) N2Labels = 0 ( 0 ) TotalLabels = 2434 ( 2401 ) NameLabels = 2053 ( 2148 ) ColorLabels = 1932 ( 2306 ) LayerLabels = 1932 ( 2306 )
|
||||
PROPS : Centroid = 0 ( 0 ) Volume = 0 ( 0 ) Area = 0 ( 0 )
|
||||
NCOLORS : NColors = 13 ( 13 )
|
||||
COLORS : Colors = BLUE1 CYAN1 CYAN3 DARKORANGE2 DEEPPINK4 GREEN GREEN4 LIGHTPINK2 MAGENTA1 MATRAGRAY RED SIENNA3 YELLOW ( BLUE1 CYAN1 CYAN3 DARKORANGE2 DEEPPINK4 GREEN GREEN4 LIGHTPINK2 MAGENTA1 MATRAGRAY RED SIENNA3 YELLOW )
|
||||
|
@ -13,11 +13,11 @@ CHECKSHAPE : Wires = 0 ( 0 ) Faces = 0 ( 0 ) Shells = 0 ( 0 ) So
|
||||
NBSHAPES : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 73 ( 73 )
|
||||
STATSHAPE : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 73 ( 73 ) FreeWire = 409 ( 414 )
|
||||
TOLERANCE : MaxTol = 0.6679845366 ( 0.6679845366 ) AvgTol = 0.004409841859 ( 0.004584996449 )
|
||||
LABELS : N0Labels = 4 ( 7 ) N1Labels = 804 ( 1805 ) N2Labels = 0 ( 0 ) TotalLabels = 808 ( 1812 ) NameLabels = 744 ( 1292 ) ColorLabels = 804 ( 1802 ) LayerLabels = 208 ( 884 )
|
||||
LABELS : N0Labels = 4 ( 7 ) N1Labels = 804 ( 1805 ) N2Labels = 0 ( 0 ) TotalLabels = 808 ( 1812 ) NameLabels = 744 ( 1292 ) ColorLabels = 804 ( 1802 ) LayerLabels = 272 ( 884 )
|
||||
PROPS : Centroid = 0 ( 0 ) Volume = 0 ( 0 ) Area = 0 ( 0 )
|
||||
NCOLORS : NColors = 6 ( 7 )
|
||||
COLORS : Colors = CYAN1 GREEN MAGENTA1 MAGENTA4 RED WHITE ( BLUE1 CYAN1 GREEN MAGENTA1 MAGENTA4 RED WHITE )
|
||||
NLAYERS : NLayers = 6 ( 10 )
|
||||
LAYERS : Layers = 200 214 240 4 51 7 ( 192 200 214 221 239 240 255 4 51 7 )
|
||||
NLAYERS : NLayers = 7 ( 10 )
|
||||
LAYERS : Layers = 200 214 240 255 4 51 7 ( 192 200 214 221 239 240 255 4 51 7 )
|
||||
|
||||
}
|
||||
|
@ -13,11 +13,11 @@ CHECKSHAPE : Wires = 0 ( 0 ) Faces = 0 ( 0 ) Shells = 0 ( 0 ) So
|
||||
NBSHAPES : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 211 ( 211 )
|
||||
STATSHAPE : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 211 ( 211 ) FreeWire = 255 ( 267 )
|
||||
TOLERANCE : MaxTol = 0.9498862984 ( 0.9498862984 ) AvgTol = 0.00820696295 ( 0.008218042456 )
|
||||
LABELS : N0Labels = 3 ( 6 ) N1Labels = 454 ( 1943 ) N2Labels = 0 ( 0 ) TotalLabels = 457 ( 1949 ) NameLabels = 393 ( 870 ) ColorLabels = 454 ( 1940 ) LayerLabels = 386 ( 1923 )
|
||||
LABELS : N0Labels = 3 ( 6 ) N1Labels = 454 ( 1943 ) N2Labels = 0 ( 0 ) TotalLabels = 457 ( 1949 ) NameLabels = 393 ( 870 ) ColorLabels = 454 ( 1940 ) LayerLabels = 450 ( 1923 )
|
||||
PROPS : Centroid = 0 ( 0 ) Volume = 0 ( 0 ) Area = 0 ( 0 )
|
||||
NCOLORS : NColors = 5 ( 7 )
|
||||
COLORS : Colors = CYAN1 GREEN MAGENTA1 RED WHITE ( BLUE1 CYAN1 GREEN MAGENTA1 RED WHITE YELLOW )
|
||||
NLAYERS : NLayers = 3 ( 6 )
|
||||
LAYERS : Layers = 200 240 4 ( 192 200 239 240 255 4 )
|
||||
NLAYERS : NLayers = 4 ( 6 )
|
||||
LAYERS : Layers = 200 240 255 4 ( 192 200 239 240 255 4 )
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user