Salome HOME
Synchronize adm files
[modules/gui.git] / src / LightApp / LightApp_Module.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:      LightApp_Module.cxx
24 // Created:   6/20/2005 16:30:56 AM
25 // Author:    OCC team
26
27 #include "LightApp_Module.h"
28
29 #include "CAM_Application.h"
30
31 #include "LightApp_Application.h"
32 #include "LightApp_DataModel.h"
33 #include "LightApp_DataObject.h"
34 #include "LightApp_Study.h"
35 #include "LightApp_Preferences.h"
36 #include "LightApp_Selection.h"
37 #include "LightApp_Operation.h"
38 #include "LightApp_SwitchOp.h"
39 #include "LightApp_UpdateFlags.h"
40 #include "LightApp_ShowHideOp.h"
41 #include "LightApp_SelectionMgr.h"
42
43 #include <SUIT_Study.h>
44 #include <SUIT_DataObject.h>
45 #include <SUIT_DataBrowser.h>
46 #include <SUIT_Operation.h>
47 #include <SUIT_ViewManager.h>
48 #include <SUIT_ResourceMgr.h>
49 #include <SUIT_ShortcutMgr.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_TreeModel.h>
52 #include <SUIT_Session.h>
53
54 #ifndef DISABLE_SALOMEOBJECT
55 #include <SALOME_ListIO.hxx>
56 #include <SALOME_ListIteratorOfListIO.hxx>
57 #endif
58
59 #ifndef DISABLE_VTKVIEWER
60 #ifndef DISABLE_SALOMEOBJECT
61   #include <SVTK_ViewWindow.h>
62   #include <SVTK_ViewModel.h>
63 #else
64   #include <VTKViewer_ViewWindow.h>
65 #endif
66   #include <VTKViewer_ViewModel.h>
67 #endif
68 #ifndef DISABLE_OCCVIEWER
69   #include <OCCViewer_ViewWindow.h>
70   #include <OCCViewer_ViewPort3d.h>
71 #ifndef DISABLE_SALOMEOBJECT
72   #include <SOCC_ViewModel.h>
73 #else
74   #include <OCCViewer_ViewModel.h>
75 #endif
76 #endif
77 #ifndef DISABLE_GLVIEWER
78   #include <GLViewer_ViewFrame.h>
79   #include <GLViewer_ViewPort.h>
80 #endif
81 #ifndef DISABLE_PLOT2DVIEWER
82   #include <Plot2d_ViewWindow.h>
83   #include <Plot2d_ViewFrame.h>
84 #ifndef DISABLE_SALOMEOBJECT
85   #include <SPlot2d_ViewModel.h>
86 #else
87   #include <Plot2d_ViewModel.h>
88 #endif
89 #endif
90
91 #include <QtxPopupMgr.h>
92
93 #include <QVariant>
94 #include <QString>
95 #include <QStringList>
96 #include <QAction>
97
98 #include <iostream>
99
100 /*!Constructor.*/
101 LightApp_Module::LightApp_Module( const QString& name )
102 : CAM_Module( name ),
103   myPopupMgr( 0 ),
104   mySwitchOp( 0 ),
105   myDisplay( -1 ),
106   myErase( -1 ),
107   myDisplayOnly( -1 ),
108   myEraseAll( -1 ),
109   myIsFirstActivate( true )
110 {
111 }
112
113 /*!Destructor.*/
114 LightApp_Module::~LightApp_Module()
115 {
116   if ( mySwitchOp )
117     delete mySwitchOp;
118 }
119
120 /*!Initialize module.*/
121 void LightApp_Module::initialize( CAM_Application* app )
122 {
123   CAM_Module::initialize( app );
124
125   SUIT_ResourceMgr* resMgr = app ? app->resourceMgr() : 0;
126   if ( resMgr )
127     resMgr->raiseTranslators( name() );
128 }
129
130 /*!NOT IMPLEMENTED*/
131 void LightApp_Module::windows( QMap<int, int>& ) const
132 {
133 }
134
135 /*!NOT IMPLEMENTED*/
136 void LightApp_Module::viewManagers( QStringList& ) const
137 {
138 }
139
140 /*!Context menu popup.*/
141 void LightApp_Module::contextMenuPopup( const QString& client, QMenu* menu, QString& /*title*/ )
142 {
143   LightApp_Selection* sel = createSelection();
144   sel->init( client, getApp()->selectionMgr() );
145
146   popupMgr()->setSelection( sel );
147   popupMgr()->setMenu( menu );
148   popupMgr()->updateMenu();
149 }
150
151 /*!Update object browser.
152  * For updating model or whole object browser use update() method can be used.
153 */
154 void LightApp_Module::updateObjBrowser( bool theIsUpdateDataModel, 
155                                         SUIT_DataObject* theDataObject )
156 {
157   bool upd = getApp()->objectBrowser()->autoUpdate();
158   getApp()->objectBrowser()->setAutoUpdate( false );
159
160   if( theIsUpdateDataModel ){
161     if( CAM_DataModel* aDataModel = dataModel() ){
162       if ( LightApp_DataModel* aModel = dynamic_cast<LightApp_DataModel*>( aDataModel ) ) {
163         //SUIT_DataObject* aParent = NULL;
164         //if(theDataObject && theDataObject != aDataModel->root())
165         //  aParent = theDataObject->parent();
166
167         LightApp_DataObject* anObject = dynamic_cast<LightApp_DataObject*>(theDataObject);
168         LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(getApp()->activeStudy());
169         aModel->update( anObject, aStudy );
170       }
171     }
172   }
173
174   getApp()->objectBrowser()->setAutoUpdate( upd );
175   getApp()->objectBrowser()->updateTree( 0, false );
176 }
177
178 /*!NOT IMPLEMENTED*/
179 void LightApp_Module::selectionChanged()
180 {
181 }
182
183 /*! \brief If return false, selection will be cleared at module activation
184  */
185 bool LightApp_Module::isSelectionCompatible()
186 {
187   // return true if selected objects belong to this module
188   bool isCompatible = true;
189 #ifndef DISABLE_SALOMEOBJECT
190   SALOME_ListIO selected;
191   if ( LightApp_SelectionMgr *Sel = getApp()->selectionMgr() )
192     Sel->selectedObjects( selected );
193
194   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
195   LightApp_DataObject* aRoot = dynamic_cast<LightApp_DataObject*>( dataModel()->root() );
196   if ( aStudy && aRoot ) {
197     // my data type
198     QString moduleDataType = aRoot->componentDataType();
199     // check data type of selection
200     SALOME_ListIteratorOfListIO It( selected );
201     for ( ; isCompatible && It.More(); It.Next()) {
202       Handle(SALOME_InteractiveObject)& io = It.Value();
203       isCompatible = ( aStudy->componentDataType( io->getEntry() ) == moduleDataType );
204     }
205   }
206 #endif
207   return isCompatible;
208 }
209
210 /*!Activate module.*/
211 bool LightApp_Module::activateModule( SUIT_Study* study )
212 {
213   bool res = CAM_Module::activateModule( study );
214
215   if ( !isSelectionCompatible() )// PAL19290, PAL18352
216     getApp()->selectionMgr()->clearSelected();
217
218   if ( res && application() && application()->resourceMgr() )
219     application()->resourceMgr()->raiseTranslators( name() );
220
221   connect( application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
222            this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
223   connect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
224            this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
225
226   if ( mySwitchOp == 0 )
227     mySwitchOp = new LightApp_SwitchOp( this );
228
229   // Enable Display and Erase actions
230   if ( action(myDisplay) )
231     action(myDisplay)->setEnabled(true);
232   if ( action(myErase) )
233     action(myErase)->setEnabled(true);
234
235   application()->shortcutMgr()->setSectionEnabled( moduleName() );
236
237   /*  BUG 0020498 : The Entry column is always shown at module activation
238       The registration of column is moved into LightApp_Application
239
240   QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
241   LightApp_DataModel* m = dynamic_cast<LightApp_DataModel*>( dataModel() );
242   if( m )
243   {
244     SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
245     m->registerColumn( getApp()->objectBrowser(), EntryCol, LightApp_DataObject::EntryId );
246     treeModel->setAppropriate( EntryCol, Qtx::Toggled );
247   }*/
248
249   if ( myIsFirstActivate ) {
250     updateModuleVisibilityState();
251     myIsFirstActivate = false;
252   }
253   
254   return res;
255 }
256
257 /*!Deactivate module.*/
258 bool LightApp_Module::deactivateModule( SUIT_Study* study )
259 {
260   delete mySwitchOp;
261   mySwitchOp = 0;
262
263   disconnect( application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
264               this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
265   disconnect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
266               this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
267
268   // abort all operations
269   MapOfOperation::const_iterator anIt;
270   for( anIt = myOperations.begin(); anIt != myOperations.end(); anIt++ ) {
271     anIt.value()->abort();
272   }
273
274   // Disable Display and Erase action
275   if ( action(myDisplay) )
276     action(myDisplay)->setEnabled(false);
277   if ( action(myErase) )
278     action(myErase)->setEnabled(false);
279
280   application()->shortcutMgr()->setSectionEnabled( moduleName(), false );
281   
282   /*  BUG 0020498 : The Entry column is always shown at module activation
283   QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
284   LightApp_DataModel* m = dynamic_cast<LightApp_DataModel*>( dataModel() );
285   if( m )
286   {
287     SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
288
289     treeModel->setAppropriate( EntryCol, Qtx::Shown );
290     m->unregisterColumn( getApp()->objectBrowser(), EntryCol );
291   }
292   */
293   return CAM_Module::deactivateModule( study );
294 }
295
296 /*! Redefined to reset internal flags valid for study instance */
297 void LightApp_Module::studyClosed( SUIT_Study* theStudy )
298 {
299   CAM_Module::studyClosed( theStudy );
300   
301   myIsFirstActivate = true;
302   
303   LightApp_Application* app = dynamic_cast<LightApp_Application*>(application());
304   if ( app ) {
305     SUIT_DataBrowser* ob = app->objectBrowser();
306     if ( ob && ob->model() )
307       disconnect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ),
308                   this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ) );
309   }
310 }
311
312 /*!NOT IMPLEMENTED*/
313 void LightApp_Module::MenuItem()
314 {
315 }
316
317 /*!NOT IMPLEMENTED*/
318 void LightApp_Module::createPreferences()
319 {
320 }
321
322 /*!NOT IMPLEMENTED*/
323 void LightApp_Module::preferencesChanged( const QString&, const QString& )
324 {
325 }
326
327 /*!NOT IMPLEMENTED*/
328 void LightApp_Module::message( const QString& )
329 {
330 }
331
332 /*!Gets application.*/
333 LightApp_Application* LightApp_Module::getApp() const
334 {
335   return (LightApp_Application*)application();
336 }
337
338 /*!
339  * \brief Update something in accordance with update flags
340  * \param theFlags - update flags
341 *
342 * Update viewer or/and object browser etc. in accordance with update flags ( see
343 * LightApp_UpdateFlags enumeration ). Derived modules can redefine this method for their
344 * own purposes
345 */
346 void LightApp_Module::update( const int theFlags )
347 {
348   if ( theFlags & UF_Model )
349   {
350     if( CAM_DataModel* aDataModel = dataModel() )
351       if( LightApp_DataModel* aModel = dynamic_cast<LightApp_DataModel*>( aDataModel ) )
352         aModel->update( 0, dynamic_cast<LightApp_Study*>( getApp()->activeStudy() ) );
353   }
354
355   if ( theFlags & UF_ObjBrowser )
356     getApp()->objectBrowser()->updateTree( 0 );
357
358   if ( theFlags & UF_Controls )
359     updateControls();
360   if ( theFlags & UF_Viewer )
361   {
362     if ( SUIT_ViewManager* viewMgr = getApp()->activeViewManager() )
363       if ( SUIT_ViewWindow* viewWnd = viewMgr->getActiveView() )
364       {
365 #ifndef DISABLE_VTKVIEWER
366 #ifndef DISABLE_SALOMEOBJECT
367         if ( viewWnd->inherits( "SVTK_ViewWindow" ) )
368           ( (SVTK_ViewWindow*)viewWnd )->Repaint();
369 #else
370         if ( viewWnd->inherits( "VTKViewer_ViewWindow" ) )
371           ( (VTKViewer_ViewWindow*)viewWnd )->Repaint();
372 #endif
373 #endif
374 #ifndef DISABLE_OCCVIEWER
375         if ( viewWnd->inherits( "OCCViewer_ViewWindow" ) )
376           ( (OCCViewer_ViewWindow*)viewWnd )->getViewPort()->onUpdate();
377 #endif
378 #ifndef DISABLE_PLOT2DVIEWER
379         if ( viewWnd->inherits( "Plot2d_ViewWindow" ) )
380           ( (Plot2d_ViewWindow*)viewWnd )->getViewFrame()->Repaint();
381 #endif
382 #ifndef DISABLE_GLVIEWER
383         if ( viewWnd->inherits( "GLViewer_ViewFrame" ) )
384           ( (GLViewer_ViewFrame*)viewWnd )->getViewPort()->onUpdate();
385 #endif
386       }
387   }
388 }
389 /*!
390  * \brief Updates controls
391 *
392 * Updates (i.e. disable/enable) controls states (menus, tool bars etc.). This method is
393 * called from update( UF_Controls ). You may redefine it in concrete module.
394 */
395 void LightApp_Module::updateControls()
396 {
397 }
398
399 /*!Create new instance of data model and return it.*/
400 CAM_DataModel* LightApp_Module::createDataModel()
401 {
402   return new LightApp_DataModel( this );
403 }
404
405 /*!Create and return instance of LightApp_Selection.*/
406 LightApp_Selection* LightApp_Module::createSelection() const
407 {
408   return new LightApp_Selection();
409 }
410
411 /*!NOT IMPLEMENTED*/
412 void LightApp_Module::onModelOpened()
413 {
414 }
415
416 /*!NOT IMPLEMENTED*/
417 void LightApp_Module::onModelSaved()
418 {
419 }
420
421 /*!NOT IMPLEMENTED*/
422 void LightApp_Module::onModelClosed()
423 {
424 }
425
426 /*!Gets popup manager.(create if not exist)*/
427 QtxPopupMgr* LightApp_Module::popupMgr()
428 {
429   if ( !myPopupMgr )
430   {
431     myPopupMgr = new QtxPopupMgr( 0, this );
432
433     QPixmap p;
434     SUIT_Desktop* d = application()->desktop();
435     
436     QAction 
437       *disp = createAction( -1, tr( "TOP_SHOW" ), p, tr( "MEN_SHOW" ), tr( "STB_SHOW" ),
438                             0, d, false, this, SLOT( onShowHide() ), QString("General:Show object(s)") ),
439       *erase = createAction( -1, tr( "TOP_HIDE" ), p, tr( "MEN_HIDE" ), tr( "STB_HIDE" ),
440                              0, d, false, this, SLOT( onShowHide() ) , QString("General:Hide object(s)") ),
441       *dispOnly = createAction( -1, tr( "TOP_DISPLAY_ONLY" ), p, tr( "MEN_DISPLAY_ONLY" ), tr( "STB_DISPLAY_ONLY" ),
442                                 0, d, false, this, SLOT( onShowHide() ) ),
443       *eraseAll = createAction( -1, tr( "TOP_ERASE_ALL" ), p, tr( "MEN_ERASE_ALL" ), tr( "STB_ERASE_ALL" ),
444                                 0, d, false, this, SLOT( onShowHide() ) );
445     myDisplay     = actionId( disp );
446     myErase       = actionId( erase );
447     myDisplayOnly = actionId( dispOnly );
448     myEraseAll    = actionId( eraseAll );
449
450     myPopupMgr->insert( disp, -1, 0 ); 
451     myPopupMgr->insert( erase, -1, 0 );
452     myPopupMgr->insert( dispOnly, -1, 0 );
453     myPopupMgr->insert( eraseAll, -1, 0 );
454     myPopupMgr->insert( separator(), -1, 0 );
455
456     QString oneAndNotActive = "( count( $component ) = 1 ) and ( not( activeModule in $component ) )";
457     QString uniform = "true in $canBeDisplayed and %1 and ( activeModule = '%2' )";
458     uniform = uniform.arg( oneAndNotActive ).arg( name() );
459     myPopupMgr->setRule( disp, /*QString( "( not isVisible ) and " ) + */ uniform, QtxPopupMgr::VisibleRule );
460     myPopupMgr->setRule( erase, /*QString( "( isVisible ) and " ) + */ uniform, QtxPopupMgr::VisibleRule );
461     myPopupMgr->setRule( dispOnly, uniform, QtxPopupMgr::VisibleRule );
462
463     QStringList viewers;
464
465 #ifndef DISABLE_OCCVIEWER
466 #ifndef DISABLE_SALOMEOBJECT
467     viewers.append( SOCC_Viewer::Type() );
468 #else
469     viewers.append( OCCViewer_Viewer::Type() );
470 #endif
471 #endif
472 #ifndef DISABLE_VTKVIEWER
473 #ifndef DISABLE_SALOMEOBJECT
474     viewers.append( SVTK_Viewer::Type() );
475 #else
476     viewers.append( VTKViewer_Viewer::Type() );
477 #endif
478 #endif
479 #ifndef DISABLE_PLOT2DVIEWER
480 #ifndef DISABLE_SALOMEOBJECT
481     viewers.append( SPlot2d_Viewer::Type() );
482 #else
483     viewers.append( Plot2d_Viewer::Type() );
484 #endif
485 #endif
486
487     if( !viewers.isEmpty() )
488     {
489       QString strViewers = "{ ", temp = "'%1' ";
490       QStringList::const_iterator anIt = viewers.begin(), aLast = viewers.end();
491       for( ; anIt!=aLast; anIt++ )
492         strViewers+=temp.arg( *anIt );
493       strViewers+="}";
494       myPopupMgr->setRule( eraseAll, QString( "client in %1" ).arg( strViewers ), QtxPopupMgr::VisibleRule );
495     }
496   }
497   return myPopupMgr;
498 }
499
500 /*!Gets preferences.*/
501 LightApp_Preferences* LightApp_Module::preferences() const
502 {
503   LightApp_Preferences* pref = 0;
504   if ( getApp() )
505     pref = getApp()->preferences();
506   return pref;
507 }
508
509 /*!Add preference to preferences.*/
510 int LightApp_Module::addPreference( const QString& label )
511 {
512   LightApp_Preferences* pref = preferences();
513   if ( !pref )
514     return -1;
515
516   int catId = pref->addPreference( moduleName(), -1 );
517   if ( catId == -1 )
518     return -1;
519
520   return pref->addPreference( label, catId );
521 }
522
523 /*!Add preference to preferences.*/
524 int LightApp_Module::addPreference( const QString& label, const int pId, const int type,
525                                     const QString& section, const QString& param )
526 {
527   LightApp_Preferences* pref = preferences();
528   if ( !pref )
529     return -1;
530
531   return pref->addPreference( moduleName(), label, pId, type, section, param );
532 }
533
534 /*!Gets property of preferences.*/
535 QVariant LightApp_Module::preferenceProperty( const int id, const QString& prop ) const
536 {
537   QVariant var;
538   LightApp_Preferences* pref = preferences();
539   if ( pref )
540     var = pref->itemProperty( prop, id );
541   return var;
542 }
543
544 /*!Set property of preferences.*/
545 void LightApp_Module::setPreferenceProperty( const int id, const QString& prop, const QVariant& var )
546 {
547   LightApp_Preferences* pref = preferences();
548   if ( pref )
549     pref->setItemProperty( prop, var, id );
550 }
551
552 /*!
553  * \brief Starts operation with given identifier
554   * \param id - identifier of operation to be started
555 *
556 * Module stores operations in map. This method starts operation by id.
557 * If operation isn't in map, then it will be created by createOperation method
558 * and will be inserted to map
559 */
560 void LightApp_Module::startOperation( const int id )
561 {
562   LightApp_Operation* op = 0;
563   if( myOperations.contains( id ) && reusableOperation( id ) )
564     op = myOperations[ id ];
565   else
566   {
567     op = createOperation( id );
568     if( op )
569     {
570       myOperations.insert( id, op );
571       op->setModule( this );
572       connect( op, SIGNAL( stopped( SUIT_Operation* ) ), this, SLOT( onOperationStopped( SUIT_Operation* ) ) );
573       connect( op, SIGNAL( destroyed() ), this, SLOT( onOperationDestroyed() ) );
574     }
575   }
576
577   if( op )
578   {
579     // be sure that operation has correct study pointer
580     op->setStudy( application() ? application()->activeStudy() : 0 );
581     op->start();
582   }
583 }
584
585 /*!
586  * \brief Creates operation with given identifier
587   * \param id - identifier of operation to be started
588   * \return Pointer on created operation or NULL if operation is not created
589 *
590 * Creates operation with given id. You should not call this method, it will be called
591 * automatically from startOperation. You may redefine this method in concrete module to
592 * create operations. 
593 */
594 LightApp_Operation* LightApp_Module::createOperation( const int id ) const
595 {
596   if( id==-1 )
597     return 0;
598
599   if( id==myDisplay )
600     return new LightApp_ShowHideOp( LightApp_ShowHideOp::DISPLAY );
601   else if( id==myErase )
602     return new LightApp_ShowHideOp( LightApp_ShowHideOp::ERASE );
603   else if( id==myDisplayOnly )
604     return new LightApp_ShowHideOp( LightApp_ShowHideOp::DISPLAY_ONLY );
605   else if( id==myEraseAll )
606     return new LightApp_ShowHideOp( LightApp_ShowHideOp::ERASE_ALL );
607   else
608     return 0;
609 }
610
611 /*!
612  * \brief Virtual protected slot called when operation stopped
613  * \param theOp - stopped operation
614 *
615 * Virtual protected slot called when operation stopped. Redefine this slot if you want to
616 * perform actions after stopping operation
617 */
618 void LightApp_Module::onOperationStopped( SUIT_Operation* /*theOp*/ )
619 {
620 }
621
622 /*!
623  * \brief Virtual protected slot called when operation destroyed
624   * \param theOp - destroyed operation
625 *
626 * Virtual protected slot called when operation destroyed. Redefine this slot if you want to
627 * perform actions after destroying operation. Base implementation removes pointer on
628 * destroyed operation from the map of operations
629 */
630 void LightApp_Module::onOperationDestroyed()
631 {
632   const QObject* s = sender();
633   if( s && s->inherits( "LightApp_Operation" ) )
634   {
635     const LightApp_Operation* op = ( LightApp_Operation* )s;
636     MapOfOperation::const_iterator anIt = myOperations.begin(),
637                                    aLast = myOperations.end();
638     for( ; anIt!=aLast; anIt++ )
639       if( anIt.value()==op )
640       {
641         myOperations.remove( anIt.key() );
642         break;
643       }
644   }
645 }
646
647 /*!
648   Must be redefined in order to use standard displayer mechanism
649   \return displayer of module
650 */
651 LightApp_Displayer* LightApp_Module::displayer()
652 {
653   return 0;
654 }
655
656 /*!
657   SLOT: called on activating of standard operations show/hide
658 */
659 void LightApp_Module::onShowHide()
660 {
661   if( !sender()->inherits( "QAction" ) || !popupMgr() )
662     return;
663
664   QAction* act = ( QAction* )sender();
665   int id = actionId( act );
666   if( id!=-1 )
667     startOperation( id );
668 }
669
670 /*!
671   virtual SLOT: called on view manager adding
672 */
673 void LightApp_Module::onViewManagerAdded( SUIT_ViewManager* )
674 {
675 }
676
677 /*!
678   virtual SLOT: called on view manager removing
679 */
680 void LightApp_Module::onViewManagerRemoved( SUIT_ViewManager* )
681 {
682 }
683
684 /*!
685   \brief Returns instance of operation by its id; if there is no operation
686   corresponding to this id, null pointer is returned
687   \param id - operation id 
688   \return operation instance
689 */
690 LightApp_Operation* LightApp_Module::operation( const int id ) const
691 {
692   return myOperations.contains( id ) ? myOperations[id] : 0;
693 }
694
695 /*!
696   virtual method called to manage the same operations
697 */
698 bool LightApp_Module::reusableOperation( const int id )
699 {
700  return true;
701
702
703 /*!
704   virtual method
705   \return true if module can copy the current selection
706 */
707 bool LightApp_Module::canCopy() const
708 {
709   return false;
710 }
711
712 /*!
713   virtual method
714   \return true if module can paste previously copied data
715 */
716 bool LightApp_Module::canPaste() const
717 {
718   return false;
719 }
720
721 /*!
722   virtual method
723   \brief Copies the current selection into clipboard
724 */
725 void LightApp_Module::copy()
726 {
727 }
728
729 /*!
730   virtual method
731   \brief Pastes the current data in the clipboard
732 */
733 void LightApp_Module::paste()
734 {
735 }
736
737 /*!
738   virtual method
739   \return true if module allows dragging the given object
740 */
741 bool LightApp_Module::isDraggable( const SUIT_DataObject* /*what*/ ) const
742 {
743   return false;
744 }
745
746 /*!
747   virtual method
748   \return true if module allows dropping one or more objects (currently selected) on the object \c where
749 */
750 bool LightApp_Module::isDropAccepted( const SUIT_DataObject* /*where*/ ) const
751 {
752   return false;
753 }
754
755 /*!
756   virtual method
757   Complete drag-n-drop operation by processing objects \a what being dragged, dropped to the line \a row
758   within the object \a where. The drop action being performed is specified by \a action.
759 */
760 void LightApp_Module::dropObjects( const DataObjectList& /*what*/, SUIT_DataObject* /*where*/,
761                                    const int /*row*/, Qt::DropAction /*action*/ )
762 {
763 }
764
765 /*!
766   \brief Return \c true if object can be renamed
767 */
768 bool LightApp_Module::renameAllowed( const QString& /*entry*/ ) const
769 {
770   return false;
771 }
772
773 /*!
774   Rename object by entry.
775   \param entry entry of the object
776   \param name new name of the object
777   \brief Return \c true if rename operation finished successfully, \c false otherwise.
778 */
779 bool LightApp_Module::renameObject( const QString& /*entry*/, const QString& /*name*/ )
780 {
781   return false;
782 }
783
784 /*!
785   Update visibility state for data objects
786 */
787 void LightApp_Module::updateModuleVisibilityState()
788 {
789   // update visibility state of objects
790   LightApp_Application* app = dynamic_cast<LightApp_Application*>(SUIT_Session::session()->activeApplication());
791   if ( !app ) return;
792   
793   SUIT_DataBrowser* ob = app->objectBrowser();
794   if ( !ob || !ob->model() ) return;
795
796   // connect to click on item
797   connect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ),
798            this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ), Qt::UniqueConnection );
799
800   SUIT_DataObject* rootObj = ob->root();
801   if ( !rootObj ) return;
802   
803   DataObjectList listObj = rootObj->children( true );
804   
805   SUIT_ViewModel* vmod = 0;
806   if ( SUIT_ViewManager* vman = app->activeViewManager() )
807     vmod = vman->getViewModel();
808   app->updateVisibilityState( listObj, vmod );
809 }
810
811 /*!
812  * \brief Virtual public slot
813  *
814  * This method is called after the object inserted into data view to update their visibility state
815  * This is default implementation
816  */
817 void LightApp_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
818 {
819   if ( !isActiveModule() ) return;
820
821   // change visibility of object
822   if ( !theObject || theColumn != SUIT_DataObject::VisibilityId ) return;
823
824   LightApp_Study* study = dynamic_cast<LightApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
825   if ( !study ) return;
826
827   LightApp_DataObject* lo = dynamic_cast<LightApp_DataObject*>( theObject );
828   if ( !lo ) return;
829   
830   // detect action index (from LightApp level)
831   int id = -1;
832   
833   if ( study->visibilityState( lo->entry() ) == Qtx::ShownState )
834     id = myErase;
835   else if ( study->visibilityState( lo->entry() ) == Qtx::HiddenState )
836     id = myDisplay;
837   
838   if ( id != -1 )
839     startOperation( id );
840 }