diff --git a/src/BinMNaming/BinMNaming_NamedShapeDriver.cxx b/src/BinMNaming/BinMNaming_NamedShapeDriver.cxx index b66fd4ad28..4f0a04a1c8 100644 --- a/src/BinMNaming/BinMNaming_NamedShapeDriver.cxx +++ b/src/BinMNaming/BinMNaming_NamedShapeDriver.cxx @@ -184,39 +184,49 @@ Standard_Boolean BinMNaming_NamedShapeDriver::Paste BinTools_ShapeSet& aShapeSet = (BinTools_ShapeSet&) myShapeSet; - for (Standard_Integer i = 1; i <= aNbShapes; i++) { + NCollection_List anOldShapes, aNewShapes; + for (Standard_Integer i = 1; i <= aNbShapes; i++) + { TopoDS_Shape anOldShape, aNewShape; - - if ( anEvol != TNaming_PRIMITIVE ) - if(TranslateFrom(theSource, anOldShape, aShapeSet)) return Standard_False; - if (anEvol != TNaming_DELETE) - if(TranslateFrom(theSource, aNewShape, aShapeSet)) return Standard_False; + if (anEvol != TNaming_PRIMITIVE) + if (TranslateFrom (theSource, anOldShape, aShapeSet)) return Standard_False; - switch (anEvol) { - case TNaming_PRIMITIVE : - aBuilder.Generated(aNewShape); - break; - case TNaming_GENERATED : - aBuilder.Generated(anOldShape, aNewShape); - break; - case TNaming_MODIFY : - aBuilder.Modify(anOldShape, aNewShape); - break; - case TNaming_DELETE : - aBuilder.Delete (anOldShape); - break; - case TNaming_SELECTED : - aBuilder.Select(aNewShape, anOldShape); - break; - case TNaming_REPLACE : - aBuilder.Modify(anOldShape, aNewShape); // for compatibility aBuilder.Replace(anOldShape, aNewShape); - break; - default : - throw Standard_DomainError("TNaming_Evolution:: Evolution Unknown"); + if (anEvol != TNaming_DELETE) + if (TranslateFrom (theSource, aNewShape, aShapeSet)) return Standard_False; + + // Here we add shapes in reverse order because TNaming_Builder also adds them in reverse order. + anOldShapes.Prepend (anOldShape); + aNewShapes.Prepend (aNewShape); + } + + for (NCollection_List::Iterator anOldIt (anOldShapes), aNewIt (aNewShapes); + anOldIt.More() && aNewIt.More(); + anOldIt.Next(), aNewIt.Next()) + { + switch (anEvol) + { + case TNaming_PRIMITIVE: + aBuilder.Generated (aNewIt.Value ()); + break; + case TNaming_GENERATED: + aBuilder.Generated (anOldIt.Value(), aNewIt.Value()); + break; + case TNaming_MODIFY: + aBuilder.Modify (anOldIt.Value(), aNewIt.Value()); + break; + case TNaming_DELETE: + aBuilder.Delete (anOldIt.Value()); + break; + case TNaming_SELECTED: + aBuilder.Select (aNewIt.Value(), anOldIt.Value()); + break; + case TNaming_REPLACE: + aBuilder.Modify (anOldIt.Value(), aNewIt.Value()); // for compatibility aBuilder.Replace(anOldShape, aNewShape); + break; + default: + throw Standard_DomainError("TNaming_Evolution:: Evolution Unknown"); } - anOldShape.Nullify(); - aNewShape.Nullify(); } return Standard_True; } diff --git a/src/XmlMNaming/XmlMNaming_NamedShapeDriver.cxx b/src/XmlMNaming/XmlMNaming_NamedShapeDriver.cxx index b48da1c5af..294a5df51a 100644 --- a/src/XmlMNaming/XmlMNaming_NamedShapeDriver.cxx +++ b/src/XmlMNaming/XmlMNaming_NamedShapeDriver.cxx @@ -121,7 +121,7 @@ Standard_Boolean XmlMNaming_NamedShapeDriver::Paste Standard_Integer upper = NewPShapes.Upper(); if (OldPShapes.Upper() > upper) upper = OldPShapes.Upper(); - for (Standard_Integer i = lower; i <= upper; i++) + for (Standard_Integer i = upper; i >= lower; --i) { const XmlMNaming_Shape1 aNewPShape = NewPShapes.Value(i); const XmlMNaming_Shape1 anOldPShape = OldPShapes.Value(i); diff --git a/tests/bugs/caf/bug28425 b/tests/bugs/caf/bug28425 new file mode 100644 index 0000000000..320b8513fb --- /dev/null +++ b/tests/bugs/caf/bug28425 @@ -0,0 +1,56 @@ +puts "===========" +puts "OCC28425" +puts "===========" +puts "" +############################################################ +# Open/save NamedShape changes order of shapes +############################################################ + +pload QAcommands + +vertex v 1 2 3 +box b 10 20 30 + +# Test bin document +NewDocument D1 BinOcaf +BuildNamedShape D1 0:1 PRIMITIVE v b +GetNewShapes D1 0:1 s +set info [whatis s_1] +if { [regexp "SOLID" $info] != 1 } { + puts "Error: first shape should be solid" +} else { + puts "OK: order of shapes is correct" +} +SaveAs D1 test.cbf +Close D1 +Open test.cbf D2 +GetNewShapes D2 0:1 s +set info [whatis s_1] +if { [regexp "SOLID" $info] != 1 } { + puts "Error: first shape should be solid" +} else { + puts "OK: order of shapes is correct" +} +Close D2 + +# Test xml document +NewDocument D1 XmlOcaf +BuildNamedShape D1 0:1 PRIMITIVE v b +GetNewShapes D1 0:1 s +set info [whatis s_1] +if { [regexp "SOLID" $info] != 1 } { + puts "Error: first shape should be solid" +} else { + puts "OK: order of shapes is correct" +} +SaveAs D1 test.xml +Close D1 +Open test.xml D2 +GetNewShapes D2 0:1 s +set info [whatis s_1] +if { [regexp "SOLID" $info] != 1 } { + puts "Error: first shape should be solid" +} else { + puts "OK: order of shapes is correct" +} +Close D2