From fcdb829c2503c44114a0360f1133f595c51a6b64 Mon Sep 17 00:00:00 2001 From: ika Date: Thu, 21 Jun 2018 15:57:39 +0300 Subject: [PATCH] 0029890: Data Exchange - Problem in Expand Compounds XCAFDoc_ShapeTool::Expand method now avoids creation of subshapes under assemblies. XCAFDoc_ShapeTool::AddSubShape now avoids creation subshapes under all labels except for simple parts. --- src/XCAFDoc/XCAFDoc_ShapeTool.cxx | 14 ++++++++-- src/XCAFDoc/XCAFDoc_ShapeTool.hxx | 3 ++- tests/bugs/xde/bug29890_1 | 19 +++++++++++++ tests/bugs/xde/bug29890_2 | 45 +++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 tests/bugs/xde/bug29890_1 create mode 100644 tests/bugs/xde/bug29890_2 diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx index 480a1d9ad9..553b15d69f 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx @@ -1097,6 +1097,9 @@ TDF_Label XCAFDoc_ShapeTool::AddSubShape (const TDF_Label &shapeL, const TopoDS_Shape &sub) const { TDF_Label L; + if (!IsSimpleShape(shapeL) || !IsTopLevel(shapeL)) + return L; + if ( FindSubShape ( shapeL, sub, L ) ) return L; if (!IsSubShape(shapeL, sub)) @@ -1833,7 +1836,7 @@ Standard_Boolean XCAFDoc_ShapeTool::Expand (const TDF_Label& theShapeL) TopoDS_Iterator anIter(aShape); for(; anIter.More(); anIter.Next()) { - TopoDS_Shape aChildShape = anIter.Value(); + const TopoDS_Shape& aChildShape = anIter.Value(); TDF_Label aChild, aPart; // Find child shape as subshape of expanded shape @@ -1895,11 +1898,18 @@ void XCAFDoc_ShapeTool::makeSubShape (const TDF_Label& theMainShapeL, { TopoDS_Iterator anIter(theShape); Standard_Boolean isCompoundPart = (GetShape(thePart).ShapeType() == TopAbs_COMPOUND); + Standard_Boolean isAssembly = IsAssembly(thePart); for(; anIter.More(); anIter.Next()) { - TopoDS_Shape aChildShape = anIter.Value(); + const TopoDS_Shape& aChildShape = anIter.Value(); TDF_Label aChildLabel; FindSubShape(theMainShapeL, aChildShape, aChildLabel); if(!aChildLabel.IsNull()) { + if (isAssembly) { + aChildLabel.ForgetAllAttributes(); + makeSubShape(theMainShapeL, thePart, aChildShape, theLoc); + continue; + } + //get name Handle(TDataStd_Name) anAttr; aChildLabel.FindAttribute(TDataStd_Name::GetID(), anAttr); diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.hxx b/src/XCAFDoc/XCAFDoc_ShapeTool.hxx index db5871973a..2df242a5dc 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.hxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.hxx @@ -432,7 +432,8 @@ private: Standard_EXPORT static void MakeReference (const TDF_Label& L, const TDF_Label& refL, const TopLoc_Location& loc); //! Auxiliary method for Expand - //! Make subshape for thePart from theShape after expanding theMainShapeL + //! Add declared under expanded theMainShapeL subshapes to new part label thePart + //! Recursively iterate all subshapes of shape from thePart, current shape to iterate its subshapes is theShape. Standard_EXPORT void makeSubShape(const TDF_Label& theMainShapeL, const TDF_Label& thePart, const TopoDS_Shape& theShape, const TopLoc_Location& theLoc); XCAFDoc_DataMapOfShapeLabel myShapeLabels; diff --git a/tests/bugs/xde/bug29890_1 b/tests/bugs/xde/bug29890_1 new file mode 100644 index 0000000000..09b33e4530 --- /dev/null +++ b/tests/bugs/xde/bug29890_1 @@ -0,0 +1,19 @@ +puts "==========" +puts "OCC29890" +puts "==========" +puts "" +############################## +# Problem in Expand Compounds +############################## +pload ALL + +# Open file and expand +XOpen [locate_data_file bug29890.xbf] D +XExpand D 1 0:1:1:1238 + +# Check +set children [Children D 0:1:1:1239] +if {$children != "0:1:1:1239:1 0:1:1:1239:3 "} { + puts "Error: wrong expand compounds." +} +Close D diff --git a/tests/bugs/xde/bug29890_2 b/tests/bugs/xde/bug29890_2 new file mode 100644 index 0000000000..39db5e8225 --- /dev/null +++ b/tests/bugs/xde/bug29890_2 @@ -0,0 +1,45 @@ +puts "==========" +puts "OCC29890" +puts "==========" +puts "" +############################## +# Problem in Expand Compounds +############################## +pload ALL + +# Add subshape to assembly +box b 1 1 1 +compound b comp +XNewDoc D +XAddShape D comp +explode comp f +set sub1 [XAddSubShape D comp_1 0:1:1:1] +if {$sub1 != ""} { + puts "Error: inconsistent model after add subshape to assembly." +} +Close D + +# Add subshape to reference +box b 1 1 1 +ttranslate b 1 0 0 +XNewDoc D +XAddShape D b +explode b f +set sub2 [XAddSubShape D b_1 0:1:1:1] +if {$sub2 != ""} { + puts "Error: inconsistent model after add subshape to reference." +} +Close D + +# Add subshape to subshape +box b 1 1 1 +XNewDoc D +XAddShape D b +explode b f +XAddSubShape D b_1 0:1:1:1 +explode b_1 e +set sub3 [XAddSubShape D b_1_1 0:1:1:1:1] +if {$sub3 != ""} { + puts "Error: inconsistent model after add subshape to subshape." +} +Close D