+bool HYDROGUI_DataModel::canUndo() const
+{
+ return getDocument()->CanUndo();
+}
+
+bool HYDROGUI_DataModel::canRedo() const
+{
+ return getDocument()->CanRedo();
+}
+
+QStringList HYDROGUI_DataModel::undoNames() const
+{
+ QStringList aNames;
+ for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetUndos() ); anIter.More(); anIter.Next() )
+ aNames.prepend( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
+ return aNames;
+}
+
+QStringList HYDROGUI_DataModel::redoNames() const
+{
+ QStringList aNames;
+ for( TDF_ListIteratorOfDeltaList anIter( getDocument()->GetRedos() ); anIter.More(); anIter.Next() )
+ aNames.append( HYDROGUI_Tool::ToQString( anIter.Value()->Name() ) );
+ return aNames;
+}
+
+void HYDROGUI_DataModel::clearUndos()
+{
+ getDocument()->ClearUndos();
+}
+
+void HYDROGUI_DataModel::clearRedos()
+{
+ getDocument()->ClearRedos();
+}
+
+bool HYDROGUI_DataModel::undo()
+{
+ try
+ {
+ getDocument()->Undo();
+ }
+ catch ( Standard_Failure )
+ {
+ return false;
+ }
+ return true;
+}
+
+bool HYDROGUI_DataModel::redo()
+{
+ try
+ {
+ getDocument()->Redo();
+ }
+ catch ( Standard_Failure )
+ {
+ return false;
+ }
+ return true;
+}
+
+bool HYDROGUI_DataModel::canCopy()
+{
+ HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
+ if( aSeq.Length() != 1 )
+ return false;
+
+ Handle(HYDROData_Entity) anObject = aSeq.First();
+ if( anObject.IsNull() )
+ return false;
+
+ ObjectKind aKind = anObject->GetKind();
+ if( aKind == KIND_IMAGE ||
+ aKind == KIND_POLYLINE ||
+ aKind == KIND_CALCULATION )
+ return true;
+
+ return false;
+}
+
+bool HYDROGUI_DataModel::canPaste()
+{
+ for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
+ {
+ Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
+ if( !anObject.IsNull() && !anObject->IsRemoved() )
+ return true;
+ }
+ return false;
+}
+
+bool HYDROGUI_DataModel::copy()
+{
+ HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() );
+ changeCopyingObjects( aSeq );
+ return true;
+}
+
+bool HYDROGUI_DataModel::paste()
+{
+ bool anIsChanged = false;
+ for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ )
+ {
+ Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex );
+ if( !anObject.IsNull() && !anObject->IsRemoved() )
+ {
+ ObjectKind aKind = anObject->GetKind();
+ Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
+ if( !aClone.IsNull() )
+ {
+ anObject->CopyTo( aClone );
+ anIsChanged = true;
+
+ // generate a new unique name for the clone object:
+ // case 1: Image_1 -> Image_2
+ // case 2: ImageObj -> ImageObj_1
+ QString aName = aClone->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 = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix );
+ aClone->SetName( aName );
+ }
+ }
+ }
+ return anIsChanged;
+}
+
+void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq )
+{
+ myCopyingObjects.Assign( theSeq );
+}
+
+QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind )
+{
+ switch( theObjectKind )
+ {
+ case KIND_IMAGE: return "IMAGES";
+ case KIND_POLYLINE: return "POLYLINES";
+ case KIND_VISUAL_STATE: return "VISUAL_STATES";
+ case KIND_BATHYMETRY: return "BATHYMETRIES";
+ case KIND_CALCULATION: return "CALCULATION_CASES";
+ case KIND_IMMERSIBLE_ZONE: return "IMMERSIBLE_ZONES";
+ default: break;
+ }
+ return QString();
+}
+
+Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const
+{
+ int aStudyId = module()->application()->activeStudy()->id();
+ return HYDROData_Document::Document( aStudyId );
+}
+
+LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
+ Handle(HYDROData_Entity) theModelObject,
+ const QString& theParentEntry,
+ const bool theIsBuildTree )
+{
+ HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
+
+ if ( theIsBuildTree )
+ {
+ buildObjectTree( theParent, aResObj, theParentEntry );
+ }
+
+ return aResObj;
+}
+
+LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent,
+ HYDROGUI_DataObject* theObject,
+ const QString& theParentEntry,
+ const bool theIsBuildTree )
+{
+ if ( theIsBuildTree )
+ {
+ buildObjectTree( theParent, theObject, theParentEntry );
+ }
+ return theObject;
+}
+
+LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent,
+ Handle(HYDROData_Zone) theModelObject,
+ const QString& theParentEntry,
+ const bool theIsBuildTree )
+{
+ return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
+}
+
+LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent,
+ Handle(HYDROData_Region) theModelObject,
+ const QString& theParentEntry,
+ const bool theIsBuildTree )