From b7cfe34e526dd0643ab16f913fcf8bd06f4ff198 Mon Sep 17 00:00:00 2001 From: asl Date: Mon, 28 Sep 2015 16:34:20 +0300 Subject: [PATCH] refs #638: zone name should not be changed when it is moved into another region --- src/HYDROData/HYDROData_CalculationCase.cxx | 2 +- src/HYDROData/HYDROData_Entity.cxx | 38 ++++++++++++--------- src/HYDROData/HYDROData_Entity.h | 3 +- src/HYDROData/HYDROData_Region.cxx | 2 +- src/HYDROData/HYDROData_Stream.cxx | 5 +-- src/HYDROData/HYDROData_Stream.h | 3 +- src/HYDROData/test_HYDROData_Bathymetry.cxx | 2 +- src/HYDROData/test_HYDROData_Entity.cxx | 2 +- src/HYDROData/test_HYDROData_Image.cxx | 2 +- src/HYDROData/test_HYDROData_PolylineXY.cxx | 2 +- src/HYDROGUI/HYDROGUI_DataModel.cxx | 2 +- src/HYDROPy/HYDROData_Entity.sip | 18 ---------- 12 files changed, 35 insertions(+), 46 deletions(-) diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index be8f1a8b..55bb858b 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -691,7 +691,7 @@ bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRe if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab ) { Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover ); - theRegion->CopyTo( aNewRegion ); + theRegion->CopyTo( aNewRegion, true ); aFatherCalc->RemoveRegion( theRegion, theLandCover ); diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index bd47a090..95d7426c 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -167,7 +167,8 @@ HYDROData_Entity::~HYDROData_Entity() { } -void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination ) const +void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination, + bool isGenerateNewName ) const { Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); if ( aDocument.IsNull() ) { @@ -177,23 +178,26 @@ void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination ) TDF_CopyLabel aCopy(myLab, theDestination->Label()); aCopy.Perform(); - // generate a new unique name for the clone object: - // case 1: Image_1 -> Image_2 - // case 2: ImageObj -> ImageObj_1 - QString aName = theDestination->GetName(); - QString aPrefix = aName; - if( aName.contains( '_' ) ) { // case 1 - QString aSuffix = aName.section( '_', -1 ); - bool anIsInteger = false; - aSuffix.toInt( &anIsInteger ); - if( anIsInteger ) - aPrefix = aName.section( '_', 0, -2 ); - } else { // case 2 - aPrefix = aName; - } + if( isGenerateNewName ) + { + // generate a new unique name for the clone object: + // case 1: Image_1 -> Image_2 + // case 2: ImageObj -> ImageObj_1 + QString aName = theDestination->GetName(); + QString aPrefix = aName; + if( aName.contains( '_' ) ) { // case 1 + QString aSuffix = aName.section( '_', -1 ); + bool anIsInteger = false; + aSuffix.toInt( &anIsInteger ); + if( anIsInteger ) + aPrefix = aName.section( '_', 0, -2 ); + } else { // case 2 + aPrefix = aName; + } - aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix ); - theDestination->SetName( aName ); + aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix ); + theDestination->SetName( aName ); + } } Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index 8e493729..f02cb5eb 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -195,7 +195,8 @@ public: * Objects must be the same type. * \param theDestination initialized object (from any document) - target of copying */ - HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination ) const; + HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination, + bool isGenerateNewName ) const; /** * Returns the label of this object. diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index 20a86e42..c82d17e9 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -107,7 +107,7 @@ bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone ) if ( !aFatherRegion.IsNull() && aFatherRegion->Label() != myLab ) { Handle(HYDROData_Zone) aNewZone = addNewZone( aDocument, "", TopoDS_Face(), QStringList() ); - theZone->CopyTo( aNewZone ); + theZone->CopyTo( aNewZone, false ); // To prevent changing of stored shape aNewZone->SetShape( theZone->GetShape() ); diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index 6f77d56d..24231090 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -1007,7 +1007,8 @@ bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpol return isOK; } -void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination ) const +void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination, + bool isGenerateNewName ) const { // Get the document Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); @@ -1016,7 +1017,7 @@ void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination ) } // Call base method - HYDROData_Entity::CopyTo( theDestination ); + HYDROData_Entity::CopyTo( theDestination, isGenerateNewName ); Handle(HYDROData_Stream) aStreamCopy = Handle(HYDROData_Stream)::DownCast( theDestination ); diff --git a/src/HYDROData/HYDROData_Stream.h b/src/HYDROData/HYDROData_Stream.h index 6ebf6427..fd4ffca5 100644 --- a/src/HYDROData/HYDROData_Stream.h +++ b/src/HYDROData/HYDROData_Stream.h @@ -136,7 +136,8 @@ public: /** * */ - HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination ) const; + HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination, + bool isGenerateNewName ) const; /** diff --git a/src/HYDROData/test_HYDROData_Bathymetry.cxx b/src/HYDROData/test_HYDROData_Bathymetry.cxx index dbc229fd..e3b2509a 100755 --- a/src/HYDROData/test_HYDROData_Bathymetry.cxx +++ b/src/HYDROData/test_HYDROData_Bathymetry.cxx @@ -185,7 +185,7 @@ void test_HYDROData_Bathymetry::testCopy() Handle(HYDROData_Bathymetry) aBathymetry2 = Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) ); - aBathymetry1->CopyTo( aBathymetry2 ); + aBathymetry1->CopyTo( aBathymetry2, true ); if ( anIsFileCreated ) { diff --git a/src/HYDROData/test_HYDROData_Entity.cxx b/src/HYDROData/test_HYDROData_Entity.cxx index a6850801..e55530bb 100644 --- a/src/HYDROData/test_HYDROData_Entity.cxx +++ b/src/HYDROData/test_HYDROData_Entity.cxx @@ -57,7 +57,7 @@ void test_HYDROData_Entity::testCopy() Handle(HYDROData_Entity) aCopy = aDoc->CreateObject(KIND_IMAGE); // object for copy CPPUNIT_ASSERT(aCopy->GetName().isEmpty()); - anObj->CopyTo(aCopy); + anObj->CopyTo(aCopy, true); // check the copied object has same name as original CPPUNIT_ASSERT_EQUAL(aName.toStdString(), aCopy->GetName().toStdString()); diff --git a/src/HYDROData/test_HYDROData_Image.cxx b/src/HYDROData/test_HYDROData_Image.cxx index 689c7a64..ddeeeb87 100644 --- a/src/HYDROData/test_HYDROData_Image.cxx +++ b/src/HYDROData/test_HYDROData_Image.cxx @@ -154,7 +154,7 @@ void test_HYDROData_Image::testCopy() // copy image to the new one Handle(HYDROData_Image) anImage3 = Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE)); - anImage1->CopyTo(anImage3); + anImage1->CopyTo(anImage3, true); // check all fields are correctly copied CPPUNIT_ASSERT(anImage1->Image() == anImage3->Image()); diff --git a/src/HYDROData/test_HYDROData_PolylineXY.cxx b/src/HYDROData/test_HYDROData_PolylineXY.cxx index 6c019831..99b61069 100644 --- a/src/HYDROData/test_HYDROData_PolylineXY.cxx +++ b/src/HYDROData/test_HYDROData_PolylineXY.cxx @@ -66,7 +66,7 @@ void test_HYDROData_PolylineXY::testCopy() Handle(HYDROData_PolylineXY) aPolyline2 = Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY)); - aPolyline1->CopyTo(aPolyline2); + aPolyline1->CopyTo(aPolyline2, true); aDoc->Close(); diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index 88bb35b2..1478a747 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -679,7 +679,7 @@ bool HYDROGUI_DataModel::paste() Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind ); if( !aClone.IsNull() ) { - anObject->CopyTo( aClone ); + anObject->CopyTo( aClone, true ); anIsChanged = true; // remove Z layer diff --git a/src/HYDROPy/HYDROData_Entity.sip b/src/HYDROPy/HYDROData_Entity.sip index 9dc1676e..7ef4fd13 100644 --- a/src/HYDROPy/HYDROData_Entity.sip +++ b/src/HYDROPy/HYDROData_Entity.sip @@ -216,24 +216,6 @@ public: */ virtual void Remove(); - - /** - * Copies all properties of this to the destinated object. - * Objects must be the same type. - * \param theDestination initialized object (from any document) - target of copying - */ - void CopyTo( HYDROData_Entity theDestination ) const [void ( const Handle_HYDROData_Entity& )]; - %MethodCode - Handle(HYDROData_Entity) aCopyTo = createHandle( a0 ); - if ( !aCopyTo.IsNull() ) - { - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Entity::CopyTo( aCopyTo ): - sipCpp->CopyTo( aCopyTo ); - Py_END_ALLOW_THREADS - } - %End - /** * Returns father object. For object created under root document label * this method always return NULL object. -- 2.39.2