From: ouv Date: Tue, 6 Aug 2013 11:34:00 +0000 (+0000) Subject: Undo/Redo operation. X-Git-Tag: BR_hydro_v_0_1~133 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ea51c1575cfdc7e3ad0b8cc1db55d9d83626b12d;p=modules%2Fhydro.git Undo/Redo operation. --- diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index 3960c4a4..6062fd6d 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -4,6 +4,8 @@ #include +#include + IMPLEMENT_STANDARD_HANDLE(HYDROData_Document,MMgt_TShared) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,MMgt_TShared) @@ -129,10 +131,21 @@ void HYDROData_Document::StartOperation() myDoc->NewCommand(); } -void HYDROData_Document::CommitOperation() +void HYDROData_Document::CommitOperation(const TCollection_ExtendedString& theName) { myDoc->CommitCommand(); myTransactionsAfterSave++; + + if( theName.Length() != 0 ) + { + const TDF_DeltaList& aList = GetUndos(); + if( !aList.IsEmpty() ) + { + Handle(TDF_Delta) aDelta = aList.Last(); + if( !aDelta.IsNull() ) + aDelta->SetName( theName ); + } + } } void HYDROData_Document::AbortOperation() @@ -155,6 +168,16 @@ bool HYDROData_Document::CanUndo() return myDoc->GetAvailableUndos() > 0; } +const TDF_DeltaList& HYDROData_Document::GetUndos() +{ + return myDoc->GetUndos(); +} + +void HYDROData_Document::ClearUndos() +{ + return myDoc->ClearUndos(); +} + void HYDROData_Document::Undo() { myDoc->Undo(); @@ -166,6 +189,16 @@ bool HYDROData_Document::CanRedo() return myDoc->GetAvailableRedos() > 0; } +const TDF_DeltaList& HYDROData_Document::GetRedos() +{ + return myDoc->GetRedos(); +} + +void HYDROData_Document::ClearRedos() +{ + return myDoc->ClearRedos(); +} + void HYDROData_Document::Redo() { myDoc->Redo(); diff --git a/src/HYDROData/HYDROData_Document.h b/src/HYDROData/HYDROData_Document.h index 00a90729..fbda6994 100644 --- a/src/HYDROData/HYDROData_Document.h +++ b/src/HYDROData/HYDROData_Document.h @@ -59,7 +59,8 @@ public: //! Starts a new operation (opens a tansaction) HYDRODATA_EXPORT void StartOperation(); //! Finishes the previously started operation (closes the transaction) - HYDRODATA_EXPORT void CommitOperation(); + HYDRODATA_EXPORT void CommitOperation( + const TCollection_ExtendedString& theName = TCollection_ExtendedString()); //! Aborts the operation HYDRODATA_EXPORT void AbortOperation(); //! Returns true if operation has been started, but not yet finished or aborted @@ -69,10 +70,19 @@ public: //! Returns True if there are available Undos HYDRODATA_EXPORT bool CanUndo(); + //! Returns a list of stored undo actions + HYDRODATA_EXPORT const TDF_DeltaList& GetUndos(); + //! Clears a list of stored undo actions + HYDRODATA_EXPORT void ClearUndos(); //! Undoes last operation HYDRODATA_EXPORT void Undo(); + //! Returns True if there are available Redos HYDRODATA_EXPORT bool CanRedo(); + //! Returns a list of stored undo actions + HYDRODATA_EXPORT const TDF_DeltaList& GetRedos(); + //! Clears a list of stored undo actions + HYDRODATA_EXPORT void ClearRedos(); //! Redoes last operation HYDRODATA_EXPORT void Redo(); diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index 30e21ed8..9d395a6a 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -22,8 +22,9 @@ #include "HYDROGUI_DataModel.h" -#include "HYDROGUI_Module.h" #include "HYDROGUI_DataObject.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_Tool.h" #include #include @@ -46,6 +47,9 @@ #include +#include +#include + HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule ) : LightApp_DataModel( theModule ) { @@ -100,8 +104,6 @@ bool HYDROGUI_DataModel::save( QStringList& theFileList ) if( !module()->application()->activeStudy() ) return false; - const int aStudyId = module()->application()->activeStudy()->id(); - LightApp_DataModel::save( theFileList ); QString aTmpDir; @@ -117,7 +119,7 @@ bool HYDROGUI_DataModel::save( QStringList& theFileList ) 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" ) ); @@ -258,6 +260,74 @@ Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEn 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 ) { diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index 84a07b79..07cca59b 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -23,6 +23,7 @@ #ifndef HYDROGUI_DATAMODEL_H #define HYDROGUI_DATAMODEL_H +#include #include #include @@ -141,7 +142,31 @@ public: Handle(HYDROData_Object) objectByEntry( const QString& theEntry, const ObjectKind theObjectKind ); + /** + * Check if it is possible to perform 'undo' operation + */ + bool canUndo() const; + bool canRedo() const; + + /** + * Returns the list of names of available 'undo' actions + */ + QStringList undoNames() const; + QStringList redoNames() const; + + void clearUndos(); + void clearRedos(); + + bool undo(); + bool redo(); + + protected: + /** + * Returns the document for the current study + */ + Handle(HYDROData_Document) getDocument() const; + /** * Creates the GUI data object according to the model object. * \param theParent a created object will be appended as a child of this object diff --git a/src/HYDROGUI/HYDROGUI_Displayer.cxx b/src/HYDROGUI/HYDROGUI_Displayer.cxx index fd75ba44..66cb4c11 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.cxx +++ b/src/HYDROGUI/HYDROGUI_Displayer.cxx @@ -88,7 +88,7 @@ void HYDROGUI_Displayer::EraseAll( const int theViewerId ) if( GraphicsView_Object* anObject = anIter.next() ) { aViewPort->removeItem( anObject ); - delete anObject; + //delete anObject; // ouv: to do } } } @@ -152,7 +152,7 @@ void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs, if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) ) { aViewPort->removeItem( aPrs ); - delete aPrs; + //delete aPrs; // ouv: to do } } } diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index a1f390c9..fbfe8d5f 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -47,6 +47,7 @@ HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule ) myPreviewPrs( 0 ), myPointType( HYDROGUI_PrsImage::None ) { + setName( tr( "IMPORT_IMAGE" ) ); } HYDROGUI_ImportImageOp::~HYDROGUI_ImportImageOp() @@ -63,7 +64,7 @@ void HYDROGUI_ImportImageOp::startOperation() HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const { - HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), tr( "IMPORT_IMAGE" ) ); + HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), getName() ); connect( aPanel, SIGNAL( createPreview( QString ) ), this, SLOT( onCreatePreview( QString ) ) ); connect( aPanel, SIGNAL( activatePointSelection( int ) ), @@ -71,7 +72,7 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const return aPanel; } -void HYDROGUI_ImportImageOp::OnApply() +void HYDROGUI_ImportImageOp::onApply() { HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel(); @@ -125,13 +126,13 @@ void HYDROGUI_ImportImageOp::OnApply() module()->update( UF_Model | UF_Viewer ); } } - commit(); + HYDROGUI_Operation::onApply(); } -void HYDROGUI_ImportImageOp::OnCancel() +void HYDROGUI_ImportImageOp::onCancel() { closePreview(); - abort(); + HYDROGUI_Operation::onCancel(); } void HYDROGUI_ImportImageOp::onCreatePreview( QString theFileName ) diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.h b/src/HYDROGUI/HYDROGUI_ImportImageOp.h index 66537e25..3e6964eb 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.h @@ -45,8 +45,8 @@ protected: virtual HYDROGUI_InputPanel* createInputPanel() const; protected slots: - virtual void OnApply(); - virtual void OnCancel(); + virtual void onApply(); + virtual void onCancel(); void onCreatePreview( QString ); void onActivatePointSelection( int ); diff --git a/src/HYDROGUI/HYDROGUI_InputPanel.cxx b/src/HYDROGUI/HYDROGUI_InputPanel.cxx index 269e5ca3..2186f279 100644 --- a/src/HYDROGUI/HYDROGUI_InputPanel.cxx +++ b/src/HYDROGUI/HYDROGUI_InputPanel.cxx @@ -63,9 +63,9 @@ HYDROGUI_InputPanel::HYDROGUI_InputPanel( HYDROGUI_Module* theModule, const QStr aBtnsLayout->addStretch( 1 ); aBtnsLayout->addWidget( myHelp, 0 ); - connect( myApply, SIGNAL( clicked() ), this, SLOT( OnApply() ) ); - connect( myCancel, SIGNAL( clicked() ), this, SLOT( OnCancel() ) ); - connect( myHelp, SIGNAL( clicked() ), this, SLOT( OnHelp() ) ); + connect( myApply, SIGNAL( clicked() ), this, SLOT( onApply() ) ); + connect( myCancel, SIGNAL( clicked() ), this, SLOT( onCancel() ) ); + connect( myHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) ); } HYDROGUI_InputPanel::~HYDROGUI_InputPanel() @@ -77,17 +77,17 @@ HYDROGUI_Module* HYDROGUI_InputPanel::module() const return myModule; } -void HYDROGUI_InputPanel::OnApply() +void HYDROGUI_InputPanel::onApply() { emit panelApply(); } -void HYDROGUI_InputPanel::OnCancel() +void HYDROGUI_InputPanel::onCancel() { emit panelCancel(); } -void HYDROGUI_InputPanel::OnHelp() +void HYDROGUI_InputPanel::onHelp() { } diff --git a/src/HYDROGUI/HYDROGUI_InputPanel.h b/src/HYDROGUI/HYDROGUI_InputPanel.h index 24603ea4..b05302e8 100644 --- a/src/HYDROGUI/HYDROGUI_InputPanel.h +++ b/src/HYDROGUI/HYDROGUI_InputPanel.h @@ -53,9 +53,9 @@ signals: void panelCancel(); protected slots: - void OnApply(); - void OnCancel(); - void OnHelp(); + void onApply(); + void onCancel(); + void onHelp(); private: HYDROGUI_Module* myModule; diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 670246be..3993bfc4 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -73,20 +73,36 @@ void HYDROGUI_Module::initialize( CAM_Application* theApp ) { LightApp_Module::initialize( theApp ); - CreateActions(); - CreateMenus(); - CreatePopups(); - CreateToolbars(); + createActions(); + createUndoRedoActions(); + createMenus(); + createPopups(); + createToolbars(); setMenuShown( false ); + setToolShown( false ); myDisplayer = new HYDROGUI_Displayer( this ); } bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy ) { + bool aRes = LightApp_Module::activateModule( theStudy ); + setMenuShown( true ); - return LightApp_Module::activateModule( theStudy ); + setToolShown( true ); + + updateCommandsStatus(); + + return aRes; +} + +bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy ) +{ + setMenuShown( false ); + setToolShown( false ); + + return LightApp_Module::deactivateModule( theStudy ); } void HYDROGUI_Module::windows( QMap& theMap ) const @@ -136,6 +152,16 @@ void HYDROGUI_Module::update( const int flags ) QApplication::restoreOverrideCursor(); } +void HYDROGUI_Module::updateCommandsStatus() +{ + LightApp_Module::updateCommandsStatus(); + + updateUndoRedoControls(); + + // to do + //action( ... )->setEnabled( ... ); +} + HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const { return (HYDROGUI_DataModel*)dataModel(); diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index a93a3f44..fdb8d03e 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -53,6 +53,7 @@ public: virtual void viewManagers( QStringList& ) const; virtual void update( const int ); + virtual void updateCommandsStatus(); HYDROGUI_DataModel* getDataModel() const; HYDROGUI_Displayer* getDisplayer() const; @@ -64,12 +65,17 @@ protected: public slots: virtual bool activateModule( SUIT_Study* ); + virtual bool deactivateModule( SUIT_Study* ); protected: virtual LightApp_Operation* createOperation( const int ) const; protected slots: void onOperation(); + + bool onUndo( int theNumActions ); + bool onRedo( int theNumActions ); + virtual void onViewManagerAdded( SUIT_ViewManager* ); virtual void onViewManagerRemoved( SUIT_ViewManager* ); virtual void onViewCreated( SUIT_ViewWindow* ); @@ -84,13 +90,16 @@ private: bool isUpdateEnabled() const; private: - void CreateActions(); - void CreateMenus(); - void CreatePopups(); - void CreateToolbars(); + void createActions(); + void createMenus(); + void createPopups(); + void createToolbars(); + + void createUndoRedoActions(); + void updateUndoRedoControls(); private: - QAction* CreateAction( const int theId, const QString& theSuffix, + QAction* createAction( const int theId, const QString& theSuffix, const QString& theImg = QString::null, const int theKey = 0, const bool isToggle = false, const QString& theSlot = QString::null ); diff --git a/src/HYDROGUI/HYDROGUI_Operation.cxx b/src/HYDROGUI/HYDROGUI_Operation.cxx index 29336412..5b1a90e9 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.cxx +++ b/src/HYDROGUI/HYDROGUI_Operation.cxx @@ -21,8 +21,10 @@ // #include "HYDROGUI_Operation.h" -#include "HYDROGUI_Module.h" + #include "HYDROGUI_InputPanel.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_Tool.h" #include #include @@ -34,7 +36,9 @@ #include HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule ) -: LightApp_Operation(), myModule( theModule ), myPanel( 0 ) +: LightApp_Operation(), + myModule( theModule ), + myPanel( 0 ) { } @@ -42,6 +46,16 @@ HYDROGUI_Operation::~HYDROGUI_Operation() { } +void HYDROGUI_Operation::setName( const QString& theName ) +{ + myName = theName; +} + +const QString& HYDROGUI_Operation::getName() const +{ + return myName; +} + SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const { return myModule->getApp()->selectionMgr(); @@ -77,7 +91,7 @@ void HYDROGUI_Operation::abortOperation() void HYDROGUI_Operation::commitOperation() { - doc()->CommitOperation(); + doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) ); LightApp_Operation::commitOperation(); @@ -90,8 +104,8 @@ HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const if( !myPanel ) { ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel(); - connect( myPanel, SIGNAL( panelApply() ), this, SLOT( OnApply() ) ); - connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( OnCancel() ) ); + connect( myPanel, SIGNAL( panelApply() ), this, SLOT( onApply() ) ); + connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) ); } return myPanel; } @@ -102,16 +116,14 @@ Handle_HYDROData_Document HYDROGUI_Operation::doc() const return HYDROData_Document::Document( aStudyId ); } -void HYDROGUI_Operation::OnApply() +void HYDROGUI_Operation::onApply() { - doc()->CommitOperation(); - inputPanel()->hide(); + commit(); } -void HYDROGUI_Operation::OnCancel() +void HYDROGUI_Operation::onCancel() { - doc()->AbortOperation(); - inputPanel()->hide(); + abort(); } Handle_HYDROData_Object HYDROGUI_Operation::FindObjectByName( const QString& theName, int theKind ) const diff --git a/src/HYDROGUI/HYDROGUI_Operation.h b/src/HYDROGUI/HYDROGUI_Operation.h index 2afd8dac..2f983751 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.h +++ b/src/HYDROGUI/HYDROGUI_Operation.h @@ -39,6 +39,9 @@ public: HYDROGUI_Operation( HYDROGUI_Module* theModule ); virtual ~HYDROGUI_Operation(); + void setName( const QString& theName ); + const QString& getName() const; + HYDROGUI_InputPanel* inputPanel() const; SUIT_SelectionMgr* selectionMgr() const; HYDROGUI_Module* module() const; @@ -54,12 +57,13 @@ protected: Handle_HYDROData_Object FindObjectByName( const QString& theName, int theKind ) const; protected slots: - virtual void OnApply(); - virtual void OnCancel(); + virtual void onApply(); + virtual void onCancel(); private: HYDROGUI_Module* myModule; HYDROGUI_InputPanel* myPanel; + QString myName; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 8f717cad..de4b15ab 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -26,23 +26,28 @@ #include "HYDROGUI_ImportImageOp.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_TwoImagesOp.h" +#include "HYDROGUI_UpdateFlags.h" #include +#include + #include #include +#include #include +#include -QAction* HYDROGUI_Module::CreateAction( const int theId, const QString& theSuffix, const QString& theImg, +QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg, const int theKey, const bool isToggle, const QString& theSlot ) { QString aSlot = theSlot; if( aSlot.isEmpty() ) aSlot = SLOT( onOperation() ); - SUIT_ResourceMgr* aMgr = application()->resourceMgr(); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); std::string anImg = theImg.toStdString(); - QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aMgr->loadPixmap( "HYDROGUI", tr( anImg.c_str() ) ); + QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) ); std::string aMenu = ( "MEN_" + theSuffix ).toStdString(); std::string aDesktop = ( "DSK_" + theSuffix ).toStdString(); std::string aToolbar = ( "STB_" + theSuffix ).toStdString(); @@ -52,28 +57,76 @@ QAction* HYDROGUI_Module::CreateAction( const int theId, const QString& theSuffi theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() ); } -void HYDROGUI_Module::CreateActions() +void HYDROGUI_Module::createActions() { - CreateAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I ); - CreateAction( FuseId, "FUSE_IMAGES" ); - CreateAction( CutId, "CUT_IMAGES" ); + createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I ); + createAction( FuseId, "FUSE_IMAGES" ); + createAction( CutId, "CUT_IMAGES" ); } -void HYDROGUI_Module::CreateMenus() +void HYDROGUI_Module::createMenus() { - int aHydroMenuIndex = 6; // Edit menu id == 5, View menu id == 10 - int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenuIndex ); + int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 ); + createMenu( UndoId, anEditMenu ); + createMenu( RedoId, anEditMenu ); + + int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10 + int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu ); createMenu( ImportImageId, aHydroId, -1, -1 ); createMenu( FuseId, aHydroId, -1, -1 ); createMenu( CutId, aHydroId, -1, -1 ); } -void HYDROGUI_Module::CreatePopups() +void HYDROGUI_Module::createPopups() { } -void HYDROGUI_Module::CreateToolbars() +void HYDROGUI_Module::createToolbars() { + int aToolBar = createTool( tr( "HYDRO_TOOLBAR" ) ); + createTool( UndoId, aToolBar ); + createTool( RedoId, aToolBar ); +} + +void HYDROGUI_Module::createUndoRedoActions() +{ + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + + QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ), + aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ), + Qt::CTRL + Qt::Key_Z, application()->desktop() ); + + QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ), + aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ), + Qt::CTRL + Qt::Key_Y, application()->desktop() ); + + registerAction( UndoId, anEditUndo ); + registerAction( RedoId, anEditRedo ); + + anEditUndo->setComment( tr( "STB_UNDO" ) ); + anEditRedo->setComment( tr( "STB_REDO" ) ); + + connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) ); + connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) ); +} + +void HYDROGUI_Module::updateUndoRedoControls() +{ + HYDROGUI_DataModel* aModel = getDataModel(); + + QtxListAction* aUndoAction = (QtxListAction*)action( UndoId ); + QtxListAction* aRedoAction = (QtxListAction*)action( RedoId ); + + bool aCanUndo = aModel->canUndo(); + bool aCanRedo = aModel->canRedo(); + + if( aCanUndo ) + aUndoAction->addNames( aModel->undoNames() ); + aUndoAction->setEnabled( aCanUndo ); + + if( aCanRedo ) + aRedoAction->addNames( aModel->redoNames() ); + aRedoAction->setEnabled( aCanRedo ); } void HYDROGUI_Module::onOperation() @@ -84,6 +137,50 @@ void HYDROGUI_Module::onOperation() startOperation( anId ); } +bool HYDROGUI_Module::onUndo( int theNumActions ) +{ + QApplication::setOverrideCursor( Qt::WaitCursor ); + bool anIsOk = true; + HYDROGUI_DataModel* aModel = getDataModel(); + if( aModel ) + { + while( theNumActions > 0 ) + { + if( !aModel->undo() ) + { + anIsOk = false; + break; + } + theNumActions--; + } + update( UF_All | UF_GV_Init | UF_GV_Forced ); + } + QApplication::restoreOverrideCursor(); + return anIsOk; +} + +bool HYDROGUI_Module::onRedo( int theNumActions ) +{ + QApplication::setOverrideCursor( Qt::WaitCursor ); + bool anIsOk = true; + HYDROGUI_DataModel* aModel = getDataModel(); + if( aModel ) + { + while( theNumActions > 0 ) + { + if( !aModel->redo() ) + { + anIsOk = false; + break; + } + theNumActions--; + } + update( UF_All | UF_GV_Init | UF_GV_Forced ); + } + QApplication::restoreOverrideCursor(); + return anIsOk; +} + LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const { LightApp_Operation* anOp = 0; @@ -94,10 +191,10 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const anOp = new HYDROGUI_ImportImageOp( aModule ); break; case FuseId: - anOp = new HYDROGUI_TwoImagesOp( aModule, tr( "FUSE_OP" ) ); + anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse ); break; case CutId: - anOp = new HYDROGUI_TwoImagesOp( aModule, tr( "CUT_OP" ) ); + anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut ); break; } diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 8828917f..2200cb61 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -27,6 +27,9 @@ enum OperationId { FirstId, + UndoId, + RedoId, + ImportImageId, FuseId, CutId, diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 5bfab0b2..edcf41b3 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -40,6 +40,92 @@ #include #include +#include + +// Definition of this id allows to use 'latin1' (Qt alias for 'ISO-8859-1') +// encoding instead of default 'System' +#define USE_LATIN1_ENCODING + +QString HYDROGUI_Tool::ToQString( const TCollection_AsciiString& src ) +{ +#ifdef USE_LATIN1_ENCODING + QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1 +#else + QTextCodec* codec = QTextCodec::codecForLocale(); +#endif + QString res; + if ( !src.IsEmpty() ) + res = codec ? codec->toUnicode( (char*)src.ToCString(), src.Length() ) : + QString( (char*)src.ToCString() ); + return res; +} + +QString HYDROGUI_Tool::ToQString( const TCollection_ExtendedString& src ) +{ + return QString( (QChar*)src.ToExtString(), src.Length() ); +} + +QString HYDROGUI_Tool::ToQString( const Handle(TCollection_HAsciiString)& src ) +{ + if( src.IsNull() ) + return QString(); + else + return ToQString( src->String() ); +} + +QString HYDROGUI_Tool::ToQString( const Handle(TCollection_HExtendedString)& src ) +{ + if( src.IsNull() ) + return QString(); + return ToQString( src->String() ); +} + +TCollection_AsciiString HYDROGUI_Tool::ToAsciiString( const QString& src ) +{ + TCollection_AsciiString res; + if( !src.isNull() ) + { +#ifdef USE_LATIN1_ENCODING + QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1 +#else + QTextCodec* codec = QTextCodec::codecForLocale(); +#endif + if( codec ) + { + QByteArray str = codec->fromUnicode( src ); + res = TCollection_AsciiString( (Standard_CString)str.constData() ); + } + else + res = TCollection_AsciiString( src.toLatin1().data() ); + } + return res; +} + +TCollection_ExtendedString HYDROGUI_Tool::ToExtString( const QString& src ) +{ + if( src.isEmpty() ) + return TCollection_ExtendedString(); + + Standard_Integer len = src.length(); + Standard_ExtString extStr = new Standard_ExtCharacter[ ( len + 1 ) * 2 ]; + memcpy( (void*)extStr, src.unicode(), len * 2 ); + ((short*)extStr)[ len ] = 0; + + TCollection_ExtendedString trg( extStr ); + delete [] extStr; + return trg; +} + +Handle(TCollection_HAsciiString) HYDROGUI_Tool::ToHAsciiString( const QString& src ) +{ + return new TCollection_HAsciiString( ToAsciiString( src ) ); +} + +Handle(TCollection_HExtendedString) HYDROGUI_Tool::ToHExtString( const QString& src ) +{ + return new TCollection_HExtendedString( ToExtString( src ) ); +} + void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule, SUIT_ViewManager* theViewManager ) { @@ -50,14 +136,14 @@ void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule, aWorkstack->setActiveWindow( aViewWindow ); } -void HYDROGUI_Tool::GetPrsSubObjects( const HYDROGUI_DataModel* theGUIModel, +void HYDROGUI_Tool::GetPrsSubObjects( const HYDROGUI_DataModel* theModel, const int theViewerId, // currently unused HYDROData_SequenceOfObjects& theSeq ) { - if( !theGUIModel ) + if( !theModel ) return; - const int aStudyId = theGUIModel->module()->application()->activeStudy()->id(); + const int aStudyId = theModel->module()->application()->activeStudy()->id(); Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId ); if( aDocument.IsNull() ) diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index 29bd4de7..a419734c 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -27,6 +27,11 @@ #include +#include +#include +#include +#include + class SUIT_ViewManager; class HYDROGUI_DataModel; @@ -40,6 +45,46 @@ class HYDROGUI_Prs; class HYDROGUI_Tool { public: + /** + * \brief Convert \a TCollection_AsciiString to \a QString + */ + static QString ToQString( const TCollection_AsciiString& ); + + /** + * \brief Convert \a TCollection_ExtendedString to \a QString + */ + static QString ToQString( const TCollection_ExtendedString& ); + + /** + * \brief Convert \a Handle_TCollection_HAsciiString to \a QString + */ + static QString ToQString( const Handle(TCollection_HAsciiString)& ); + + /** + * \brief Convert \a Handle_TCollection_HExtendedString to \a QString + */ + static QString ToQString( const Handle(TCollection_HExtendedString)& ); + + /** + * \brief Convert \a QString to \a TCollection_AsciiString + */ + static TCollection_AsciiString ToAsciiString( const QString& ); + + /** + * \brief Convert \a QString to \a TCollection_ExtendedString + */ + static TCollection_ExtendedString ToExtString( const QString& ); + + /** + * \brief Convert \a QString to \a Handle_TCollection_HAsciiString + */ + static Handle(TCollection_HAsciiString) ToHAsciiString( const QString& ); + + /** + * \brief Convert \a QString to \a Handle_TCollection_HExtendedString + */ + static Handle(TCollection_HExtendedString) ToHExtString( const QString& ); + /** * \brief Set the specified view manager to be active on the desktop. * \param theModule module @@ -50,11 +95,11 @@ public: /** * \brief Get sub-objects to build presentations. - * \param theGUIModel data model + * \param theModel data model * \param theViewerId viewer id * \param theSeq sequence of sub-objects */ - static void GetPrsSubObjects( const HYDROGUI_DataModel* theGUIModel, + static void GetPrsSubObjects( const HYDROGUI_DataModel* theModel, const int theViewerId, HYDROData_SequenceOfObjects& theSeq ); diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index 0339fe9d..f91ca6cb 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -29,9 +29,17 @@ #include -HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const QString& theTitle ) - : HYDROGUI_Operation( theModule ), myTitle( theTitle ) +HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType ) +: HYDROGUI_Operation( theModule ), + myType( theType ) { + QString aName; + switch( myType ) + { + case Fuse: aName = tr( "FUSE" ); break; + case Cut: aName = tr( "CUT" ); break; + } + setName( aName ); } HYDROGUI_TwoImagesOp::~HYDROGUI_TwoImagesOp() @@ -40,10 +48,10 @@ HYDROGUI_TwoImagesOp::~HYDROGUI_TwoImagesOp() HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const { - return new HYDROGUI_TwoImagesDlg( module(), myTitle ); + return new HYDROGUI_TwoImagesDlg( module(), getName() ); } -void HYDROGUI_TwoImagesOp::OnApply() +void HYDROGUI_TwoImagesOp::onApply() { HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast( inputPanel() ); QString aName1, aName2; diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h index 5b98368a..2fc1e0cc 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h @@ -30,17 +30,20 @@ class HYDROGUI_TwoImagesOp : public HYDROGUI_Operation Q_OBJECT public: - HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const QString& theTitle ); + enum OperationType { Fuse, Cut }; + +public: + HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType ); virtual ~HYDROGUI_TwoImagesOp(); protected: virtual HYDROGUI_InputPanel* createInputPanel() const; protected slots: - virtual void OnApply(); + virtual void onApply(); private: - QString myTitle; + int myType; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_UpdateFlags.h b/src/HYDROGUI/HYDROGUI_UpdateFlags.h index 33773f20..0bbaaaab 100644 --- a/src/HYDROGUI/HYDROGUI_UpdateFlags.h +++ b/src/HYDROGUI/HYDROGUI_UpdateFlags.h @@ -23,6 +23,8 @@ #ifndef HYDROGUI_UPDATEFLAGS_H #define HYDROGUI_UPDATEFLAGS_H +#include + /** * \enum HYDRO_UpdateFlags * Enumeration for update flags. First byte is reserved for LightApp_Module. @@ -31,6 +33,7 @@ */ typedef enum { + UF_All = UF_Forced | UF_Model | UF_Viewer | UF_ObjBrowser | UF_Controls, UF_GV_Init = 0x00000020, //!< initial update (used with UF_Viewer) UF_GV_Forced = 0x00000040, //!< to force recomputing all presentations (used with UF_Viewer) } HYDRO_UpdateFlags; diff --git a/src/HYDROGUI/resources/HYDROGUI_images.ts b/src/HYDROGUI/resources/HYDROGUI_images.ts index 02f6bb27..cbfb166d 100644 --- a/src/HYDROGUI/resources/HYDROGUI_images.ts +++ b/src/HYDROGUI/resources/HYDROGUI_images.ts @@ -10,5 +10,13 @@ BROWSE_ICO icon_browse.png + + REDO_ICO + icon_redo.png + + + UNDO_ICO + icon_undo.png + diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 4d462fd0..0e20be6e 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -97,6 +97,18 @@ DSK_IMPORT_IMAGE Import image + + DSK_REDO + Redo + + + DSK_UNDO + Undo + + + HYDRO_TOOLBAR + HYDRO toolbar + MEN_CUT_IMAGES Cut images @@ -113,6 +125,14 @@ MEN_IMPORT_IMAGE Import image + + MEN_REDO + Redo + + + MEN_UNDO + Undo + STB_CUT_IMAGES Cut images @@ -125,5 +145,24 @@ STB_IMPORT_IMAGE Import image + + STB_REDO + Redo + + + STB_UNDO + Undo + + + + HYDROGUI_TwoImagesOp + + CUT + Cut + + + FUSE + Fuse + diff --git a/src/HYDROGUI/resources/icon_redo.png b/src/HYDROGUI/resources/icon_redo.png new file mode 100644 index 00000000..d51beffe Binary files /dev/null and b/src/HYDROGUI/resources/icon_redo.png differ diff --git a/src/HYDROGUI/resources/icon_undo.png b/src/HYDROGUI/resources/icon_undo.png new file mode 100644 index 00000000..d39b13ab Binary files /dev/null and b/src/HYDROGUI/resources/icon_undo.png differ