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