X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLightApp%2FLightApp_Module.cxx;h=88b226a7b35c3bb191960bab619373fc9f320463;hb=cefbc12b9fc2e08b4b0583b031347ef8f113a387;hp=691d68b98bd74f83193496fc50e4413824c52a31;hpb=101fd10f1e736daa5d7f0f0ee5499b951460832a;p=modules%2Fgui.git diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 691d68b98..88b226a7b 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -1,7 +1,28 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + // File: LightApp_Module.cxx // Created: 6/20/2005 16:30:56 AM // Author: OCC team -// Copyright (C) CEA 2005 #include "LightApp_Module.h" @@ -17,11 +38,22 @@ #include "LightApp_SwitchOp.h" #include "LightApp_UpdateFlags.h" #include "LightApp_ShowHideOp.h" +#include "LightApp_SelectionMgr.h" -#include "SUIT_Operation.h" #include #include +#include +#include +#include #include +#include +#include +#include + +#ifndef DISABLE_SALOMEOBJECT +#include +#include +#endif #ifndef DISABLE_VTKVIEWER #ifndef DISABLE_SALOMEOBJECT @@ -55,13 +87,13 @@ #endif #endif -#include - #include -#include -#include -#include +#include +#include +#include + +#include /*!Constructor.*/ LightApp_Module::LightApp_Module( const QString& name ) @@ -103,38 +135,41 @@ void LightApp_Module::viewManagers( QStringList& ) const } /*!Context menu popup.*/ -void LightApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ ) +void LightApp_Module::contextMenuPopup( const QString& client, QMenu* menu, QString& /*title*/ ) { LightApp_Selection* sel = createSelection(); sel->init( client, getApp()->selectionMgr() ); - popupMgr()->updatePopup( menu, sel ); - delete sel; + + popupMgr()->setSelection( sel ); + popupMgr()->setMenu( menu ); + popupMgr()->updateMenu(); } /*!Update object browser. * For updating model or whole object browser use update() method can be used. */ void LightApp_Module::updateObjBrowser( bool theIsUpdateDataModel, - SUIT_DataObject* theDataObject ) + SUIT_DataObject* theDataObject ) { - SUIT_DataObject* aDataObject = theDataObject; + bool upd = getApp()->objectBrowser()->autoUpdate(); + getApp()->objectBrowser()->setAutoUpdate( false ); + if( theIsUpdateDataModel ){ if( CAM_DataModel* aDataModel = dataModel() ){ if ( LightApp_DataModel* aModel = dynamic_cast( aDataModel ) ) { - SUIT_DataObject* aParent = NULL; - if(theDataObject && theDataObject != aDataModel->root()) - aParent = theDataObject->parent(); + //SUIT_DataObject* aParent = NULL; + //if(theDataObject && theDataObject != aDataModel->root()) + // aParent = theDataObject->parent(); - LightApp_DataObject* anObject = dynamic_cast(theDataObject); - LightApp_Study* aStudy = dynamic_cast(getApp()->activeStudy()); + LightApp_DataObject* anObject = dynamic_cast(theDataObject); + LightApp_Study* aStudy = dynamic_cast(getApp()->activeStudy()); aModel->update( anObject, aStudy ); - - if(aParent && aParent->childPos(anObject) < 0) - aDataObject = dynamic_cast(aParent); } } } - getApp()->objectBrowser()->updateTree( aDataObject ); + + getApp()->objectBrowser()->setAutoUpdate( upd ); + getApp()->objectBrowser()->updateTree( 0, false ); } /*!NOT IMPLEMENTED*/ @@ -142,11 +177,41 @@ void LightApp_Module::selectionChanged() { } +/*! \brief If return false, selection will be cleared at module activation + */ +bool LightApp_Module::isSelectionCompatible() +{ + // return true if selected objects belong to this module + bool isCompatible = true; +#ifndef DISABLE_SALOMEOBJECT + SALOME_ListIO selected; + if ( LightApp_SelectionMgr *Sel = getApp()->selectionMgr() ) + Sel->selectedObjects( selected ); + + LightApp_Study* aStudy = dynamic_cast( getApp()->activeStudy() ); + LightApp_DataObject* aRoot = dynamic_cast( dataModel()->root() ); + if ( aStudy && aRoot ) { + // my data type + QString moduleDataType = aRoot->componentDataType(); + // check data type of selection + SALOME_ListIteratorOfListIO It( selected ); + for ( ; isCompatible && It.More(); It.Next()) { + Handle(SALOME_InteractiveObject)& io = It.Value(); + isCompatible = ( aStudy->componentDataType( io->getEntry() ) == moduleDataType ); + } + } +#endif + return isCompatible; +} + /*!Activate module.*/ bool LightApp_Module::activateModule( SUIT_Study* study ) { bool res = CAM_Module::activateModule( study ); + if ( !isSelectionCompatible() )// PAL19290, PAL18352 + getApp()->selectionMgr()->clearSelected(); + if ( res && application() && application()->resourceMgr() ) application()->resourceMgr()->raiseTranslators( name() ); @@ -158,6 +223,25 @@ bool LightApp_Module::activateModule( SUIT_Study* study ) if ( mySwitchOp == 0 ) mySwitchOp = new LightApp_SwitchOp( this ); + // Enable Display and Erase actions + if ( action(myDisplay) ) + action(myDisplay)->setEnabled(true); + if ( action(myErase) ) + action(myErase)->setEnabled(true); + + application()->shortcutMgr()->setSectionEnabled( moduleName() ); + + /* BUG 0020498 : The Entry column is always shown at module activation + The registration of column is moved into LightApp_Application + + QString EntryCol = QObject::tr( "ENTRY_COLUMN" ); + LightApp_DataModel* m = dynamic_cast( dataModel() ); + if( m ) + { + SUIT_AbstractModel* treeModel = dynamic_cast( getApp()->objectBrowser()->model() ); + m->registerColumn( getApp()->objectBrowser(), EntryCol, LightApp_DataObject::EntryId ); + treeModel->setAppropriate( EntryCol, Qtx::Toggled ); + }*/ return res; } @@ -168,17 +252,36 @@ bool LightApp_Module::deactivateModule( SUIT_Study* study ) mySwitchOp = 0; disconnect( application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ), - this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) ); + this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) ); disconnect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), - this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) ); + this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) ); // abort all operations MapOfOperation::const_iterator anIt; for( anIt = myOperations.begin(); anIt != myOperations.end(); anIt++ ) { - anIt.data()->abort(); + anIt.value()->abort(); } - return CAM_Module::activateModule( study ); + // Disable Display and Erase action + if ( action(myDisplay) ) + action(myDisplay)->setEnabled(false); + if ( action(myErase) ) + action(myErase)->setEnabled(false); + + application()->shortcutMgr()->setSectionEnabled( moduleName(), false ); + + /* BUG 0020498 : The Entry column is always shown at module activation + QString EntryCol = QObject::tr( "ENTRY_COLUMN" ); + LightApp_DataModel* m = dynamic_cast( dataModel() ); + if( m ) + { + SUIT_AbstractModel* treeModel = dynamic_cast( getApp()->objectBrowser()->model() ); + + treeModel->setAppropriate( EntryCol, Qtx::Shown ); + m->unregisterColumn( getApp()->objectBrowser(), EntryCol ); + } + */ + return CAM_Module::deactivateModule( study ); } /*!NOT IMPLEMENTED*/ @@ -196,6 +299,11 @@ void LightApp_Module::preferencesChanged( const QString&, const QString& ) { } +/*!NOT IMPLEMENTED*/ +void LightApp_Module::message( const QString& ) +{ +} + /*!Gets application.*/ LightApp_Application* LightApp_Module::getApp() const { @@ -218,8 +326,10 @@ void LightApp_Module::update( const int theFlags ) if( LightApp_DataModel* aModel = dynamic_cast( aDataModel ) ) aModel->update( 0, dynamic_cast( getApp()->activeStudy() ) ); } + if ( theFlags & UF_ObjBrowser ) getApp()->objectBrowser()->updateTree( 0 ); + if ( theFlags & UF_Controls ) updateControls(); if ( theFlags & UF_Viewer ) @@ -264,7 +374,7 @@ void LightApp_Module::updateControls() /*!Create new instance of data model and return it.*/ CAM_DataModel* LightApp_Module::createDataModel() { - return new LightApp_DataModel(this); + return new LightApp_DataModel( this ); } /*!Create and return instance of LightApp_Selection.*/ @@ -299,14 +409,14 @@ QtxPopupMgr* LightApp_Module::popupMgr() SUIT_Desktop* d = application()->desktop(); QAction - *disp = createAction( -1, tr( "TOP_DISPLAY" ), p, tr( "MEN_DISPLAY" ), tr( "STB_DISPLAY" ), - 0, d, false, this, SLOT( onShowHide() ) ), - *erase = createAction( -1, tr( "TOP_ERASE" ), p, tr( "MEN_ERASE" ), tr( "STB_ERASE" ), - 0, d, false, this, SLOT( onShowHide() ) ), + *disp = createAction( -1, tr( "TOP_SHOW" ), p, tr( "MEN_SHOW" ), tr( "STB_SHOW" ), + 0, d, false, this, SLOT( onShowHide() ), QString("General:Show object(s)") ), + *erase = createAction( -1, tr( "TOP_HIDE" ), p, tr( "MEN_HIDE" ), tr( "STB_HIDE" ), + 0, d, false, this, SLOT( onShowHide() ) , QString("General:Hide object(s)") ), *dispOnly = createAction( -1, tr( "TOP_DISPLAY_ONLY" ), p, tr( "MEN_DISPLAY_ONLY" ), tr( "STB_DISPLAY_ONLY" ), - 0, d, false, this, SLOT( onShowHide() ) ), + 0, d, false, this, SLOT( onShowHide() ) ), *eraseAll = createAction( -1, tr( "TOP_ERASE_ALL" ), p, tr( "MEN_ERASE_ALL" ), tr( "STB_ERASE_ALL" ), - 0, d, false, this, SLOT( onShowHide() ) ); + 0, d, false, this, SLOT( onShowHide() ) ); myDisplay = actionId( disp ); myErase = actionId( erase ); myDisplayOnly = actionId( dispOnly ); @@ -318,12 +428,12 @@ QtxPopupMgr* LightApp_Module::popupMgr() myPopupMgr->insert( eraseAll, -1, 0 ); myPopupMgr->insert( separator(), -1, 0 ); - QString oneAndNotActive = "( count( $component ) = 1 ) and ( component != activeModule )"; + QString oneAndNotActive = "( count( $component ) = 1 ) and ( not( activeModule in $component ) )"; QString uniform = "true in $canBeDisplayed and %1 and ( activeModule = '%2' )"; uniform = uniform.arg( oneAndNotActive ).arg( name() ); - myPopupMgr->setRule( disp, /*QString( "( not isVisible ) and " ) + */ uniform, true ); - myPopupMgr->setRule( erase, /*QString( "( isVisible ) and " ) + */ uniform, true ); - myPopupMgr->setRule( dispOnly, uniform, true ); + myPopupMgr->setRule( disp, /*QString( "( not isVisible ) and " ) + */ uniform, QtxPopupMgr::VisibleRule ); + myPopupMgr->setRule( erase, /*QString( "( isVisible ) and " ) + */ uniform, QtxPopupMgr::VisibleRule ); + myPopupMgr->setRule( dispOnly, uniform, QtxPopupMgr::VisibleRule ); QStringList viewers; @@ -356,7 +466,7 @@ QtxPopupMgr* LightApp_Module::popupMgr() for( ; anIt!=aLast; anIt++ ) strViewers+=temp.arg( *anIt ); strViewers+="}"; - myPopupMgr->setRule( eraseAll, QString( "client in %1" ).arg( strViewers ), true ); + myPopupMgr->setRule( eraseAll, QString( "client in %1" ).arg( strViewers ), QtxPopupMgr::VisibleRule ); } } return myPopupMgr; @@ -402,7 +512,7 @@ QVariant LightApp_Module::preferenceProperty( const int id, const QString& prop QVariant var; LightApp_Preferences* pref = preferences(); if ( pref ) - var = pref->itemProperty( id, prop ); + var = pref->itemProperty( prop, id ); return var; } @@ -411,7 +521,7 @@ void LightApp_Module::setPreferenceProperty( const int id, const QString& prop, { LightApp_Preferences* pref = preferences(); if ( pref ) - pref->setItemProperty( id, prop, var ); + pref->setItemProperty( prop, var, id ); } /*! @@ -425,7 +535,7 @@ void LightApp_Module::setPreferenceProperty( const int id, const QString& prop, void LightApp_Module::startOperation( const int id ) { LightApp_Operation* op = 0; - if( myOperations.contains( id ) ) + if( myOperations.contains( id ) && reusableOperation( id ) ) op = myOperations[ id ]; else { @@ -501,7 +611,7 @@ void LightApp_Module::onOperationDestroyed() MapOfOperation::const_iterator anIt = myOperations.begin(), aLast = myOperations.end(); for( ; anIt!=aLast; anIt++ ) - if( anIt.data()==op ) + if( anIt.value()==op ) { myOperations.remove( anIt.key() ); break; @@ -509,11 +619,18 @@ void LightApp_Module::onOperationDestroyed() } } +/*! + Must be redefined in order to use standard displayer mechanism + \return displayer of module +*/ LightApp_Displayer* LightApp_Module::displayer() { return 0; } +/*! + SLOT: called on activating of standard operations show/hide +*/ void LightApp_Module::onShowHide() { if( !sender()->inherits( "QAction" ) || !popupMgr() ) @@ -525,10 +642,116 @@ void LightApp_Module::onShowHide() startOperation( id ); } +/*! + virtual SLOT: called on view manager adding +*/ void LightApp_Module::onViewManagerAdded( SUIT_ViewManager* ) { } +/*! + virtual SLOT: called on view manager removing +*/ void LightApp_Module::onViewManagerRemoved( SUIT_ViewManager* ) { } + +/*! + \brief Returns instance of operation by its id; if there is no operation + corresponding to this id, null pointer is returned + \param id - operation id + \return operation instance +*/ +LightApp_Operation* LightApp_Module::operation( const int id ) const +{ + return myOperations.contains( id ) ? myOperations[id] : 0; +} + +/*! + virtual method called to manage the same operations +*/ +bool LightApp_Module::reusableOperation( const int id ) +{ + return true; +} + +/*! + virtual method + \return true if module can copy the current selection +*/ +bool LightApp_Module::canCopy() const +{ + return false; +} + +/*! + virtual method + \return true if module can paste previously copied data +*/ +bool LightApp_Module::canPaste() const +{ + return false; +} + +/*! + virtual method + \brief Copies the current selection into clipboard +*/ +void LightApp_Module::copy() +{ +} + +/*! + virtual method + \brief Pastes the current data in the clipboard +*/ +void LightApp_Module::paste() +{ +} + +/*! + virtual method + \return true if module allows dragging the given object +*/ +bool LightApp_Module::isDraggable( const SUIT_DataObject* /*what*/ ) const +{ + return false; +} + +/*! + virtual method + \return true if module allows dropping one or more objects (currently selected) on the object \c where +*/ +bool LightApp_Module::isDropAccepted( const SUIT_DataObject* /*where*/ ) const +{ + return false; +} + +/*! + virtual method + Complete drag-n-drop operation by processing objects \a what being dragged, dropped to the line \a row + within the object \a where. The drop action being performed is specified by \a action. +*/ +void LightApp_Module::dropObjects( const DataObjectList& /*what*/, SUIT_DataObject* /*where*/, + const int /*row*/, Qt::DropAction /*action*/ ) +{ +} + +/*! + \brief Return \c true if object can be renamed +*/ +bool LightApp_Module::renameAllowed( const QString& /*entry*/ ) const +{ + return false; +} + +/*! + Rename object by entry. + \param entry entry of the object + \param name new name of the object + \brief Return \c true if rename operation finished successfully, \c false otherwise. +*/ +bool LightApp_Module::renameObject( const QString& /*entry*/, const QString& /*name*/ ) +{ + return false; +}