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