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