#include "HYDROGUI_DataModel.h"
-#include "HYDROGUI_Module.h"
#include "HYDROGUI_DataObject.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_Tool.h"
+#include <HYDROData_Bathymetry.h>
#include <HYDROData_Document.h>
#include <HYDROData_Image.h>
#include <HYDROData_Iterator.h>
+#include <HYDROData_Polyline.h>
+#include <HYDROData_VisualState.h>
#include <CAM_Application.h>
#include <CAM_DataObject.h>
#include <HYDROData_Document.h>
+#include <TDF_Delta.hxx>
+#include <TDF_ListIteratorOfDeltaList.hxx>
+
HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
: LightApp_DataModel( theModule )
{
if( !module()->application()->activeStudy() )
return false;
- const int aStudyId = module()->application()->activeStudy()->id();
-
LightApp_DataModel::save( theFileList );
QString aTmpDir;
aFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf";
QString aFullPath = aTmpDir + aFileName;
- Data_DocError res = HYDROData_Document::Document( aStudyId )->Save( (char*)aFullPath.toLatin1().constData() );
+ Data_DocError res = getDocument()->Save( (char*)aFullPath.toLatin1().constData() );
if( res != DocError_OK )
{
module()->application()->putInfo( tr( "SAVE_ERROR" ) );
bool HYDROGUI_DataModel::isModified() const
{
- int aStudyId = module()->application()->activeStudy()->id();
- return HYDROData_Document::Document( aStudyId )->IsModified();
+ return getDocument()->IsModified();
}
bool HYDROGUI_DataModel::isSaved() const
if( !aStudyRoot )
return;
- if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
- anObjectBrowser->setAutoOpenLevel( 3 );
-
// create root object if not exist
CAM_DataObject* aRootObj = root();
if( !aRootObj )
Handle(HYDROData_Image) anImageObj =
Handle(HYDROData_Image)::DownCast( anIterator.Current() );
if( !anImageObj.IsNull() )
- createObject( anImageRootObj, anImageObj );
+ {
+ if( LightApp_DataObject* anImageDataObj = createObject( anImageRootObj, anImageObj ) )
+ {
+ for( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ )
+ {
+ Handle(HYDROData_Image) aRefImageObj = anImageObj->Reference( anIndex );
+ if( !aRefImageObj.IsNull() && !aRefImageObj->IsRemoved() )
+ createObject( anImageDataObj, aRefImageObj, anImageDataObj->entry() );
+ }
+ }
+ }
+ }
+
+ LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, "BATHYMETRIES" );
+
+ anIterator = HYDROData_Iterator( aDocument, KIND_BATHYMETRY );
+ for( ; anIterator.More(); anIterator.Next() )
+ {
+ Handle(HYDROData_Bathymetry) aBathymetryObj =
+ Handle(HYDROData_Bathymetry)::DownCast( anIterator.Current() );
+ if( !aBathymetryObj.IsNull() )
+ createObject( aBathymetryRootObj, aBathymetryObj );
+ }
+
+ LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, "POLYLINES" );
+
+ anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE );
+ for( ; anIterator.More(); anIterator.Next() )
+ {
+ Handle(HYDROData_Polyline) aPolylineObj =
+ Handle(HYDROData_Polyline)::DownCast( anIterator.Current() );
+ if( !aPolylineObj.IsNull() )
+ createObject( aPolylineRootObj, aPolylineObj );
+ }
+
+ LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, "VISUAL_STATES" );
+
+ anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE );
+ for( ; anIterator.More(); anIterator.Next() )
+ {
+ Handle(HYDROData_VisualState) aVisualStateObj =
+ Handle(HYDROData_VisualState)::DownCast( anIterator.Current() );
+ if( !aVisualStateObj.IsNull() )
+ createObject( aVisualStateRootObj, aVisualStateObj );
+ }
+
+ if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
+ {
+ anObjectBrowser->setAutoOpenLevel( 3 );
+ anObjectBrowser->openLevels();
}
}
Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
const ObjectKind theObjectKind )
{
- const int aStudyId = module()->application()->activeStudy()->id();
- Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
+ QString anEntry = theEntry;
+ if( anEntry.indexOf( "_" ) != -1 ) // reference object
+ anEntry = anEntry.section( "_", -1 );
+
+ Handle(HYDROData_Document) aDocument = getDocument();
if( !aDocument.IsNull() )
{
HYDROData_Iterator anIterator( aDocument, theObjectKind );
Handle(HYDROData_Object) anObject = anIterator.Current();
if( !anObject.IsNull() )
{
- QString anEntry = HYDROGUI_DataObject::dataObjectEntry( anObject );
- if( anEntry == theEntry )
+ QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
+ if( anEntryRef == anEntry )
return anObject;
}
}
return NULL;
}
+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;
+}
+
+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_Object) theModelObject )
+ Handle(HYDROData_Object) theModelObject,
+ const QString& theParentEntry )
{
- return new HYDROGUI_DataObject( theParent, theModelObject );
+ return new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
}
LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,