From 00dfcc765ab38e91df547c9e8dfa70a87a6eb836 Mon Sep 17 00:00:00 2001 From: ika Date: Fri, 19 Jan 2018 13:36:30 +0300 Subject: [PATCH] 0029436: Data Exchange - Extend Expand compounds functionality. Extend permissions for expand in ShapeTool Fix processing of subshapes Fix misprints Add test cases --- src/XCAFDoc/XCAFDoc_Editor.cxx | 33 +++++++++++++++++++++++-------- src/XCAFDoc/XCAFDoc_Editor.hxx | 3 ++- src/XCAFDoc/XCAFDoc_ShapeTool.cxx | 15 +++++++++----- src/XCAFDoc/XCAFDoc_ShapeTool.hxx | 2 +- src/XDEDRAW/XDEDRAW_Common.cxx | 6 +++--- tests/bugs/xde/bug29436_1 | 27 +++++++++++++++++++++++++ tests/bugs/xde/bug29436_2 | 27 +++++++++++++++++++++++++ tests/bugs/xde/bug29436_3 | 23 +++++++++++++++++++++ tests/bugs/xde/bug29436_4 | 27 +++++++++++++++++++++++++ 9 files changed, 145 insertions(+), 18 deletions(-) create mode 100644 tests/bugs/xde/bug29436_1 create mode 100644 tests/bugs/xde/bug29436_2 create mode 100644 tests/bugs/xde/bug29436_3 create mode 100644 tests/bugs/xde/bug29436_4 diff --git a/src/XCAFDoc/XCAFDoc_Editor.cxx b/src/XCAFDoc/XCAFDoc_Editor.cxx index 89ce9da326..0c3f492da0 100644 --- a/src/XCAFDoc/XCAFDoc_Editor.cxx +++ b/src/XCAFDoc/XCAFDoc_Editor.cxx @@ -34,7 +34,7 @@ //======================================================================= //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, @@ -48,16 +48,13 @@ Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const TDF_Label& 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; @@ -85,6 +82,24 @@ Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const TDF_Label& 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) @@ -96,7 +111,9 @@ Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const TDF_Label& 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); } } } @@ -107,7 +124,7 @@ Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& Doc, const TDF_Label& //======================================================================= //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) diff --git a/src/XCAFDoc/XCAFDoc_Editor.hxx b/src/XCAFDoc/XCAFDoc_Editor.hxx index 341faeed04..2f9c78df2c 100644 --- a/src/XCAFDoc/XCAFDoc_Editor.hxx +++ b/src/XCAFDoc/XCAFDoc_Editor.hxx @@ -35,7 +35,8 @@ public: 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 diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx index fac6a7146e..5be7fe6f40 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx @@ -1804,11 +1804,17 @@ Standard_Boolean XCAFDoc_ShapeTool::FindSHUO (const TDF_LabelSequence& theLabels 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() ); @@ -1818,7 +1824,6 @@ Standard_Boolean XCAFDoc_ShapeTool::Expand (const TDF_Label& Shape) { TopoDS_Shape aChildShape = anIter.Value(); TDF_Label aChild = FindShape(aChildShape, Standard_True); - TDF_TagSource aTag; Handle(TDataStd_Name) anAttr; //make part for child @@ -1837,7 +1842,6 @@ Standard_Boolean XCAFDoc_ShapeTool::Expand (const TDF_Label& Shape) aChild.FindAttribute(TDataStd_Name::GetID(), anAttr); TopLoc_Location nulloc; SetShape(aPart, aChildShape.Located(nulloc)); - } //set name to part if(!anAttr.IsNull()) @@ -1895,7 +1899,8 @@ void XCAFDoc_ShapeTool::makeSubShape (const TDF_Label& Part, const TopoDS_Shape& 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); } diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.hxx b/src/XCAFDoc/XCAFDoc_ShapeTool.hxx index 204cb52fee..ca73092c11 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.hxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.hxx @@ -404,7 +404,7 @@ public: //! 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 diff --git a/src/XDEDRAW/XDEDRAW_Common.cxx b/src/XDEDRAW/XDEDRAW_Common.cxx index 2902446b43..9d9b338fe9 100644 --- a/src/XDEDRAW/XDEDRAW_Common.cxx +++ b/src/XDEDRAW/XDEDRAW_Common.cxx @@ -484,7 +484,7 @@ static Standard_Integer Expand (Draw_Interpretor& di, Standard_Integer argc, con 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; } } @@ -502,7 +502,7 @@ static Standard_Integer Expand (Draw_Interpretor& di, Standard_Integer argc, con 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; } } @@ -534,7 +534,7 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& di) 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); } diff --git a/tests/bugs/xde/bug29436_1 b/tests/bugs/xde/bug29436_1 new file mode 100644 index 0000000000..8229140101 --- /dev/null +++ b/tests/bugs/xde/bug29436_1 @@ -0,0 +1,27 @@ +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 diff --git a/tests/bugs/xde/bug29436_2 b/tests/bugs/xde/bug29436_2 new file mode 100644 index 0000000000..23b418380b --- /dev/null +++ b/tests/bugs/xde/bug29436_2 @@ -0,0 +1,27 @@ +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 diff --git a/tests/bugs/xde/bug29436_3 b/tests/bugs/xde/bug29436_3 new file mode 100644 index 0000000000..24dda16745 --- /dev/null +++ b/tests/bugs/xde/bug29436_3 @@ -0,0 +1,23 @@ +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 diff --git a/tests/bugs/xde/bug29436_4 b/tests/bugs/xde/bug29436_4 new file mode 100644 index 0000000000..e70924da01 --- /dev/null +++ b/tests/bugs/xde/bug29436_4 @@ -0,0 +1,27 @@ +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