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
*/
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
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();
*/
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.
*/
return myLab.ForgetAllAttributes( true );
}
+bool HYDROData_Entity::CanRemove()
+{
+ return true;
+}
+
HYDROData_Entity::HYDROData_Entity()
{
}
return aFather;
}
+HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const
+{
+ return HYDROData_SequenceOfObjects();
+}
+
void HYDROData_Entity::SetLabel(TDF_Label theLabel)
{
myLab = theLabel;
*/
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)
*/
*/
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;
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()) {
*/
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
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();
*/
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.
*/
{
}
+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 ) );
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.
*/
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.
*/
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();
*/
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.
*/
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() )
*/
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.
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();
*/
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.
*/
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 ) );
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.
*/
{
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<QString,HYDROData_SequenceOfObjects> 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 );
}
}
-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<QString,HYDROData_SequenceOfObjects> aMapOfBackRefs =
+ GetObjectsBackReferences( theModule, QStringList() << anObjName );
+
+ return aMapOfBackRefs[ anObjName ];
+}
+
+QMap<QString,HYDROData_SequenceOfObjects> HYDROGUI_Tool::GetObjectsBackReferences(
+ HYDROGUI_Module* theModule, const QStringList& theObjectNames )
+{
+ QMap<QString,HYDROData_SequenceOfObjects> 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 )
{
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 );
* \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<QString,HYDROData_SequenceOfObjects> GetObjectsBackReferences( HYDROGUI_Module* theModule,
+ const QStringList& theObjectNames );
/**
* \brief Get father dock window for widget
</message>
<message>
<source>CONFIRM_DELETION</source>
- <translation>The following objects (including the dependencies) will be deleted:
-%1
-Do you want to continue?</translation>
+ <translation>Do you really want to delete following objects:
+%1 ?</translation>
+ </message>
+ <message>
+ <source>DELETE_OBJECTS_IMPOSIBLE</source>
+ <translation>One or more selected objects can not be deleted separately from parent object.</translation>
+ </message>
+ <message>
+ <source>DELETED_OBJECTS_HAS_BACKREFERENCES</source>
+ <translation>One or more selected objects are used to create another ones.
+First remove objects which are created on their basis.</translation>
</message>
</context>