From 34310fe4f26db0f23c2edfef1678e5b02f578204 Mon Sep 17 00:00:00 2001 From: adv Date: Wed, 4 Dec 2013 05:42:26 +0000 Subject: [PATCH] Delition of objects (Feature #90). --- src/HYDROData/HYDROData_CalculationCase.cxx | 7 ++ src/HYDROData/HYDROData_CalculationCase.h | 5 + src/HYDROData/HYDROData_Channel.cxx | 15 +++ src/HYDROData/HYDROData_Channel.h | 5 + src/HYDROData/HYDROData_Entity.cxx | 10 ++ src/HYDROData/HYDROData_Entity.h | 17 ++++ src/HYDROData/HYDROData_Image.cxx | 13 +++ src/HYDROData/HYDROData_Image.h | 6 ++ src/HYDROData/HYDROData_ImmersibleZone.cxx | 11 +++ src/HYDROData/HYDROData_ImmersibleZone.h | 5 + src/HYDROData/HYDROData_Object.cxx | 11 +++ src/HYDROData/HYDROData_Object.h | 19 ++-- src/HYDROData/HYDROData_Polyline3D.cxx | 15 +++ src/HYDROData/HYDROData_Polyline3D.h | 5 + src/HYDROData/HYDROData_Region.cxx | 12 +++ src/HYDROData/HYDROData_Region.h | 10 ++ src/HYDROData/HYDROData_Stream.cxx | 13 +++ src/HYDROData/HYDROData_Stream.h | 5 + src/HYDROData/HYDROData_Zone.cxx | 12 +++ src/HYDROData/HYDROData_Zone.h | 11 +++ src/HYDROGUI/HYDROGUI_DeleteOp.cxx | 95 +++++++++++-------- src/HYDROGUI/HYDROGUI_Tool.cxx | 100 ++++++++++++-------- src/HYDROGUI/HYDROGUI_Tool.h | 24 +++-- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 14 ++- 24 files changed, 344 insertions(+), 96 deletions(-) diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 3441d309..9d556eca 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -129,6 +129,13 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre return aResList; } +HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const +{ + HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects(); + aResSeq.Append( GetRegions() ); + return aResSeq; +} + void HYDROData_CalculationCase::SplitGeometryObjects() { // At first we remove previously created regions diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index 12e0704a..83d75bbe 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -56,6 +56,11 @@ public: */ HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + /** + * Returns the list of all reference objects of this object. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + public: // Public methods to work with Calculation diff --git a/src/HYDROData/HYDROData_Channel.cxx b/src/HYDROData/HYDROData_Channel.cxx index 40c496aa..3aab98b5 100644 --- a/src/HYDROData/HYDROData_Channel.cxx +++ b/src/HYDROData/HYDROData_Channel.cxx @@ -47,6 +47,21 @@ QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObje return aResList; } +HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const +{ + HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects(); + + Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine(); + if ( !aGuideLine.IsNull() ) + aResSeq.Append( aGuideLine ); + + Handle(HYDROData_Profile) aProfile = GetProfile(); + if ( !aProfile.IsNull() ) + aResSeq.Append( aProfile ); + + return aResSeq; +} + TopoDS_Shape HYDROData_Channel::GetTopShape() const { return getTopShape(); diff --git a/src/HYDROData/HYDROData_Channel.h b/src/HYDROData/HYDROData_Channel.h index c1aea49c..8ffa76a7 100644 --- a/src/HYDROData/HYDROData_Channel.h +++ b/src/HYDROData/HYDROData_Channel.h @@ -39,6 +39,11 @@ public: */ HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + /** + * Returns the list of all reference objects of this object. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + /** * Returns the top shape of the object. */ diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index f8238ec6..015cb0f7 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -89,6 +89,11 @@ void HYDROData_Entity::Remove() return myLab.ForgetAllAttributes( true ); } +bool HYDROData_Entity::CanRemove() +{ + return true; +} + HYDROData_Entity::HYDROData_Entity() { } @@ -121,6 +126,11 @@ Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const return aFather; } +HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const +{ + return HYDROData_SequenceOfObjects(); +} + void HYDROData_Entity::SetLabel(TDF_Label theLabel) { myLab = theLabel; diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index 02c19116..dd067a18 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -131,6 +131,14 @@ public: */ HYDRODATA_EXPORT virtual void Remove(); + /** + * Returns flag indicating that object can be removed or not. + * Reimplement this method in class which can't be removed + * separately with it parent object. + * Base implementaiton returns always TRUE. + */ + HYDRODATA_EXPORT virtual bool CanRemove(); + /** * Returns unique integer identifier of the object (may be used for ordering of objects) */ @@ -148,12 +156,21 @@ public: */ HYDRODATA_EXPORT TDF_Label& Label() { return myLab; } + /** * Returns father object. For object created under root document label * this method always return NULL object. */ HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const; + + /** + * Returns the list of all reference objects of this object. + * Base implementation always return empty list. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + + protected: friend class HYDROData_Iterator; diff --git a/src/HYDROData/HYDROData_Image.cxx b/src/HYDROData/HYDROData_Image.cxx index 58d86ccc..082f160c 100644 --- a/src/HYDROData/HYDROData_Image.cxx +++ b/src/HYDROData/HYDROData_Image.cxx @@ -218,6 +218,19 @@ QVariant HYDROData_Image::GetDataVariant() return aVarData; } +HYDROData_SequenceOfObjects HYDROData_Image::GetAllReferenceObjects() const +{ + HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects(); + + Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage(); + if ( !aRefImage.IsNull() ) + aResSeq.Append( aRefImage ); + + aResSeq.Append( GetReferenceObjects( 0 ) ); + + return aResSeq; +} + void HYDROData_Image::SetImage(const QImage& theImage) { if (theImage.isNull()) { diff --git a/src/HYDROData/HYDROData_Image.h b/src/HYDROData/HYDROData_Image.h index 633edbe8..66193e01 100644 --- a/src/HYDROData/HYDROData_Image.h +++ b/src/HYDROData/HYDROData_Image.h @@ -69,6 +69,12 @@ public: */ HYDRODATA_EXPORT virtual QVariant GetDataVariant(); + /** + * Returns the list of all reference objects of this object. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + + /** * Stores the image * \param theImage new image diff --git a/src/HYDROData/HYDROData_ImmersibleZone.cxx b/src/HYDROData/HYDROData_ImmersibleZone.cxx index 4ebe9772..cf4375de 100644 --- a/src/HYDROData/HYDROData_ImmersibleZone.cxx +++ b/src/HYDROData/HYDROData_ImmersibleZone.cxx @@ -75,6 +75,17 @@ QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTrea return aResList; } +HYDROData_SequenceOfObjects HYDROData_ImmersibleZone::GetAllReferenceObjects() const +{ + HYDROData_SequenceOfObjects aResSeq = HYDROData_NaturalObject::GetAllReferenceObjects(); + + Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline(); + if ( !aRefPolyline.IsNull() ) + aResSeq.Append( aRefPolyline ); + + return aResSeq; +} + TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const { TopoDS_Shape aResShape = TopoDS_Face(); diff --git a/src/HYDROData/HYDROData_ImmersibleZone.h b/src/HYDROData/HYDROData_ImmersibleZone.h index 04616f48..f7111a37 100644 --- a/src/HYDROData/HYDROData_ImmersibleZone.h +++ b/src/HYDROData/HYDROData_ImmersibleZone.h @@ -37,6 +37,11 @@ public: */ HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + /** + * Returns the list of all reference objects of this object. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + /** * Returns the top shape of the object. */ diff --git a/src/HYDROData/HYDROData_Object.cxx b/src/HYDROData/HYDROData_Object.cxx index f8c514b3..e8477db6 100644 --- a/src/HYDROData/HYDROData_Object.cxx +++ b/src/HYDROData/HYDROData_Object.cxx @@ -22,6 +22,17 @@ HYDROData_Object::~HYDROData_Object() { } +HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const +{ + HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects(); + + Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry(); + if ( !aRefBathymetry.IsNull() ) + aResSeq.Append( aRefBathymetry ); + + return aResSeq; +} + void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape ) { TNaming_Builder aBuilder( myLab.FindChild( DataTag_TopShape ) ); diff --git a/src/HYDROData/HYDROData_Object.h b/src/HYDROData/HYDROData_Object.h index 0fcd1384..053a39e4 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -33,6 +33,18 @@ protected: public: DEFINE_STANDARD_RTTI(HYDROData_Object); + /** + * Update the geometry object. + * Call this method whenever you made changes for object data. + */ + HYDRODATA_EXPORT virtual void Update(); + + /** + * Returns the list of all reference objects of this object. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + + /** * Sets the top(2d projection) shape of the object. */ @@ -54,13 +66,6 @@ public: HYDRODATA_EXPORT virtual TopoDS_Shape GetShape3D() const = 0; - /** - * Update the geometry object. - * Call this method whenever you made changes for object data. - */ - HYDRODATA_EXPORT virtual void Update(); - - /** * Set reference bathymetry object for geometry object. */ diff --git a/src/HYDROData/HYDROData_Polyline3D.cxx b/src/HYDROData/HYDROData_Polyline3D.cxx index 89f3be36..cf41020e 100644 --- a/src/HYDROData/HYDROData_Polyline3D.cxx +++ b/src/HYDROData/HYDROData_Polyline3D.cxx @@ -50,6 +50,21 @@ QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedO return aResList; } +HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const +{ + HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects(); + + Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY(); + if ( !aPolylineXY.IsNull() ) + aResSeq.Append( aPolylineXY ); + + Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ(); + if ( !aProfileUZ.IsNull() ) + aResSeq.Append( aProfileUZ ); + + return aResSeq; +} + TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const { return getTopShape(); diff --git a/src/HYDROData/HYDROData_Polyline3D.h b/src/HYDROData/HYDROData_Polyline3D.h index 73f21cbb..67e93e20 100644 --- a/src/HYDROData/HYDROData_Polyline3D.h +++ b/src/HYDROData/HYDROData_Polyline3D.h @@ -45,6 +45,11 @@ public: */ HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + /** + * Returns the list of all reference objects of this object. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + /** * Returns the top shape of the object. */ diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index 090171f9..d86d64c1 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -77,6 +77,18 @@ void HYDROData_Region::Remove() aFatherCalc->UpdateRegionsOrder(); } +bool HYDROData_Region::CanRemove() +{ + return false; +} + +HYDROData_SequenceOfObjects HYDROData_Region::GetAllReferenceObjects() const +{ + HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects(); + aResSeq.Append( GetZones() ); + return aResSeq; +} + bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone ) { if ( theZone.IsNull() ) diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index cfaf931f..e6769ebe 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -49,6 +49,16 @@ public: */ HYDRODATA_EXPORT virtual void Remove(); + /** + * Returns flag indicating that object can be removed or not. + */ + HYDRODATA_EXPORT virtual bool CanRemove(); + + /** + * Returns the list of all reference objects of this object. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + /** * Add new one reference zone for region. diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index 19c9900a..19362261 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -54,6 +54,19 @@ QStringList HYDROData_Stream::DumpToPython( MapOfTreatedObjects& theTreatedObjec return aResList; } +HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const +{ + HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects(); + + Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); + if ( !aHydAxis.IsNull() ) + aResSeq.Append( aHydAxis ); + + aResSeq.Append( GetProfiles() ); + + return aResSeq; +} + TopoDS_Shape HYDROData_Stream::GetTopShape() const { return getTopShape(); diff --git a/src/HYDROData/HYDROData_Stream.h b/src/HYDROData/HYDROData_Stream.h index c65e3193..ce9eb426 100644 --- a/src/HYDROData/HYDROData_Stream.h +++ b/src/HYDROData/HYDROData_Stream.h @@ -39,6 +39,11 @@ public: */ HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + /** + * Returns the list of all reference objects of this object. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + /** * Returns the top shape of the object. */ diff --git a/src/HYDROData/HYDROData_Zone.cxx b/src/HYDROData/HYDROData_Zone.cxx index fdbf91b0..a33c0ab4 100644 --- a/src/HYDROData/HYDROData_Zone.cxx +++ b/src/HYDROData/HYDROData_Zone.cxx @@ -63,6 +63,18 @@ QStringList HYDROData_Zone::DumpToPython( MapOfTreatedObjects& theTreatedObjects return aResList; } +bool HYDROData_Zone::CanRemove() +{ + return false; +} + +HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const +{ + HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects(); + aResSeq.Append( GetGeometryObjects() ); + return aResSeq; +} + void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape ) { TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) ); diff --git a/src/HYDROData/HYDROData_Zone.h b/src/HYDROData/HYDROData_Zone.h index c0472ea7..610b3e18 100644 --- a/src/HYDROData/HYDROData_Zone.h +++ b/src/HYDROData/HYDROData_Zone.h @@ -55,6 +55,17 @@ public: HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + /** + * Returns flag indicating that object can be removed or not. + */ + HYDRODATA_EXPORT virtual bool CanRemove(); + + /** + * Returns the list of all reference objects of this object. + */ + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + + /** * Sets the shape of the zone. */ diff --git a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx index deb1542d..f7534146 100644 --- a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx +++ b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx @@ -47,56 +47,75 @@ void HYDROGUI_DeleteOp::startOperation() { HYDROGUI_Operation::startOperation(); - HYDROData_SequenceOfObjects aFullSeq; // selected objects with their back-references - QStringList aFullNames; - HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() ); - if( !aSeq.IsEmpty() ) + if( aSeq.IsEmpty() ) { - for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) - { - Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); - if( !anObject.IsNull() ) - { - aFullSeq.Append( anObject ); - aFullNames.append( anObject->GetName() ); - - // collect the back-references - ObjectKind aKind = anObject->GetKind(); - if( aKind == KIND_IMAGE || aKind == KIND_POLYLINEXY ) - { - HYDROData_SequenceOfObjects anObjects; - QStringList aNames; - HYDROGUI_Tool::GetObjectBackReferences( module(), anObject, anObjects, aNames ); - aFullSeq.Append( anObjects ); - aFullNames.append( aNames ); - } - } - } + abort(); + return; + } + + bool anIsCanRemove = true; - aFullNames.removeDuplicates(); - aFullNames.sort(); + QStringList anObjNames; + for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) + { + Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); + if( anObject.IsNull() ) + continue; - QString aList = aFullNames.join( "\n" ); - int anAnswer = SUIT_MessageBox::question( module()->getApp()->desktop(), - tr( "DELETE_OBJECTS" ), - tr( "CONFIRM_DELETION" ).arg( aList ), - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No ); - if( anAnswer == QMessageBox::No ) + if ( !anObject->CanRemove() ) { - abort(); - return; + anIsCanRemove = false; + break; } + + anObjNames.append( anObject->GetName() ); + } + + if ( !anIsCanRemove ) + { + SUIT_MessageBox::critical( module()->getApp()->desktop(), + tr( "DELETE_OBJECTS" ), tr( "DELETE_OBJECTS_IMPOSIBLE" ) ); + abort(); + return; + } + + anObjNames.removeDuplicates(); + anObjNames.sort(); + + // check the back-references + QMap aBackObjects = + HYDROGUI_Tool::GetObjectsBackReferences( module(), anObjNames ); + + if ( !aBackObjects.isEmpty() ) + { + SUIT_MessageBox::critical( module()->getApp()->desktop(), + tr( "DELETE_OBJECTS" ), tr( "DELETED_OBJECTS_HAS_BACKREFERENCES" ) ); + abort(); + return; + } + + QString aNamesList = anObjNames.join( "\n" ); + int anAnswer = SUIT_MessageBox::question( module()->getApp()->desktop(), + tr( "DELETE_OBJECTS" ), + tr( "CONFIRM_DELETION" ).arg( aNamesList ), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No ); + if( anAnswer == QMessageBox::No ) + { + abort(); + return; } startDocOperation(); - for( Standard_Integer anIndex = 1, aLength = aFullSeq.Length(); anIndex <= aLength; anIndex++ ) + + for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) { - Handle(HYDROData_Entity) anObject = aFullSeq.Value( anIndex ); - if( !anObject.IsNull() && !anObject->IsRemoved() ) + Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); + if ( !anObject.IsNull() && !anObject->IsRemoved() ) anObject->Remove(); } + commitDocOperation(); module()->update( UF_Model | UF_Viewer | UF_OCCViewer ); diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 007e855f..ce0d25b3 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -501,66 +501,88 @@ void HYDROGUI_Tool::setOCCActionShown( HYDROGUI_Module* theModule, } } -void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Image)& theImage, +void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Entity)& theObj, HYDROData_SequenceOfObjects& theRefObjects, QStringList& theRefNames ) { - if( theImage.IsNull() ) + if( theObj.IsNull() ) return; - for( int anIndex = 0, aNbRef = theImage->NbReferences(); anIndex < aNbRef; anIndex++ ) + HYDROData_SequenceOfObjects anAllRefObjects = theObj->GetAllReferenceObjects(); + theRefObjects.Append( anAllRefObjects ); + + for( int i = 1, n = anAllRefObjects.Length(); i <= n; ++i ) { - Handle(HYDROData_Entity) aRefObj = theImage->Reference( anIndex ); - if( !aRefObj.IsNull() && !aRefObj->IsRemoved() ) - { - QString aName = aRefObj->GetName(); - if( !theRefNames.contains( aName ) ) - { - theRefObjects.Append( aRefObj ); - theRefNames.append( aRefObj->GetName() ); - if( aRefObj->GetKind() == KIND_IMAGE ) - { - Handle(HYDROData_Image) aRefImage = Handle(HYDROData_Image)::DownCast( aRefObj ); - if( !aRefImage.IsNull() ) - GetObjectReferences( aRefImage, theRefObjects, theRefNames ); - } - } - } + Handle(HYDROData_Entity) aRefObj = theRefObjects.Value( i ); + if( aRefObj.IsNull() || aRefObj->IsRemoved() ) + continue; + + QString aRefObjectName = aRefObj->GetName(); + if( theRefNames.contains( aRefObjectName ) ) + continue; + + theRefObjects.Append( aRefObj ); + theRefNames.append( aRefObjectName ); + + GetObjectReferences( aRefObj, theRefObjects, theRefNames ); } } -void HYDROGUI_Tool::GetObjectBackReferences( HYDROGUI_Module* theModule, - const Handle(HYDROData_Entity)& theObj, - HYDROData_SequenceOfObjects& theBackRefObjects, - QStringList& theBackRefNames ) +HYDROData_SequenceOfObjects HYDROGUI_Tool::GetObjectBackReferences( + HYDROGUI_Module* theModule, + const Handle(HYDROData_Entity)& theObj ) { if( theObj.IsNull() ) - return; + return HYDROData_SequenceOfObjects(); + + QString anObjName = theObj->GetName(); + + QMap aMapOfBackRefs = + GetObjectsBackReferences( theModule, QStringList() << anObjName ); + + return aMapOfBackRefs[ anObjName ]; +} + +QMap HYDROGUI_Tool::GetObjectsBackReferences( + HYDROGUI_Module* theModule, const QStringList& theObjectNames ) +{ + QMap aResMap; + + if( theObjectNames.isEmpty() ) + return aResMap; Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() ); if( aDocument.IsNull() ) - return; - - QString aName = theObj->GetName(); + return aResMap; - HYDROData_Iterator anIterator( aDocument, KIND_IMAGE ); + HYDROData_Iterator anIterator( aDocument ); for( ; anIterator.More(); anIterator.Next() ) { - Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anIterator.Current() ); - if( !anImage.IsNull() ) + Handle(HYDROData_Entity) anObject = anIterator.Current(); + if( anObject.IsNull() || anObject->IsRemoved() ) + continue; + + QString anObjectName = anObject->GetName(); + if ( theObjectNames.contains( anObjectName ) ) + continue; + + HYDROData_SequenceOfObjects aRefObjects = anObject->GetAllReferenceObjects(); + for ( int i = 1, n = aRefObjects.Length(); i <= n; ++i ) { - HYDROData_SequenceOfObjects aRefObjects; - QStringList aRefNames; - GetObjectReferences( anImage, aRefObjects, aRefNames ); - if( aRefNames.contains( aName ) ) - { - theBackRefObjects.Append( anImage ); - theBackRefNames.append( anImage->GetName() ); - } + Handle(HYDROData_Entity) aRefObject = aRefObjects.Value( i ); + if( aRefObject.IsNull() || aRefObject->IsRemoved() ) + continue; + + QString aRefObjectName = aRefObject->GetName(); + if ( !theObjectNames.contains( aRefObjectName ) ) + continue; + + aResMap[ aRefObjectName ].Append( anObject ); } } -} + return aResMap; +} QDockWidget* HYDROGUI_Tool::WindowDock( QWidget* wid ) { diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index 18a3d587..48c8e246 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -262,12 +262,12 @@ public: const bool isShown ); /** - * \brief Get the list of references (recursively) for the specified image object - * \param theImage image data object + * \brief Get the list of references (recursively) for the specified data object + * \param theObj data object * \param theRefObjects list of reference objects * \param theRefNames list of reference object names */ - static void GetObjectReferences( const Handle(HYDROData_Image)& theImage, + static void GetObjectReferences( const Handle(HYDROData_Entity)& theObj, HYDROData_SequenceOfObjects& theRefObjects, QStringList& theRefNames ); @@ -275,13 +275,19 @@ public: * \brief Get the list of back-references for the specified object * \param theModule module * \param theObj data object - * \param theBackRefObjects list of back-reference objects - * \param theBackRefNames list of back-reference object names + * \return list of back-reference objects + */ + static HYDROData_SequenceOfObjects GetObjectBackReferences( HYDROGUI_Module* theModule, + const Handle(HYDROData_Entity)& theObj ); + + /** + * \brief Get the map of back-references for the specified list of objects + * \param theModule module + * \param theObjectNames names of objects + * \return map of back-reference objects */ - static void GetObjectBackReferences( HYDROGUI_Module* theModule, - const Handle(HYDROData_Entity)& theObj, - HYDROData_SequenceOfObjects& theBackRefObjects, - QStringList& theBackRefNames ); + static QMap GetObjectsBackReferences( HYDROGUI_Module* theModule, + const QStringList& theObjectNames ); /** * \brief Get father dock window for widget diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index ab30bf09..0f4dd7e0 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -271,9 +271,17 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) CONFIRM_DELETION - The following objects (including the dependencies) will be deleted: -%1 -Do you want to continue? + Do you really want to delete following objects: +%1 ? + + + DELETE_OBJECTS_IMPOSIBLE + One or more selected objects can not be deleted separately from parent object. + + + DELETED_OBJECTS_HAS_BACKREFERENCES + One or more selected objects are used to create another ones. +First remove objects which are created on their basis. -- 2.39.2