]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_ShowHideOp.cxx
Salome HOME
new menu item "Erase all"
[modules/gui.git] / src / LightApp / LightApp_ShowHideOp.cxx
1
2 #include "LightApp_ShowHideOp.h"
3 #include "LightApp_Application.h"
4 #include "LightApp_DataOwner.h"
5 #include "LightApp_Module.h"
6 #include "LightApp_Study.h"
7 #include "LightApp_Displayer.h"
8 #include "CAM_Study.h"
9
10 #include "LightApp_SelectionMgr.h"
11 #include "LightApp_Selection.h"
12
13 #include <SALOME_ListIO.hxx>
14 #include <SALOME_ListIteratorOfListIO.hxx>
15
16 LightApp_ShowHideOp::LightApp_ShowHideOp( ActionType type )
17 : LightApp_Operation(),
18   myActionType( type )
19 {
20 }
21
22 LightApp_ShowHideOp::~LightApp_ShowHideOp()
23 {
24 }
25
26 LightApp_Displayer* LightApp_ShowHideOp::displayer( const QString& mod_name ) const
27 {
28   LightApp_Application* app = dynamic_cast<LightApp_Application*>( application() );
29   LightApp_Module* m = dynamic_cast<LightApp_Module*>( app ? app->module( mod_name ) : 0 );
30   if( !m )
31   {
32     m = dynamic_cast<LightApp_Module*>( app->loadModule( mod_name ) );
33     if( m )
34     {
35       app->addModule( m );
36       m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
37       m->setMenuShown( false );
38       m->setToolShown( false );
39     }
40   }
41   return m ? m->displayer() : 0;
42 }
43
44 void LightApp_ShowHideOp::startOperation()
45 {
46   LightApp_Application* app = dynamic_cast<LightApp_Application*>( application() );
47   LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
48   if( !app || !study )
49   {
50     abort();
51     return;
52   }
53
54   LightApp_SelectionMgr* mgr = app->selectionMgr();
55   LightApp_Selection sel; sel.init( "", mgr );
56   if( sel.count()==0 && myActionType!=ERASE_ALL )
57   {
58     abort();
59     return;
60   }
61   QString aStr =  sel.param( 0, "component" ).toString();
62   QString mod_name = app->moduleTitle( aStr );//sel.param( 0, "component" ).toString() );
63   LightApp_Displayer* d = displayer( mod_name );
64   if( !d )
65   {
66     abort();
67     return;
68   }
69
70   if( myActionType==DISPLAY_ONLY || myActionType==ERASE_ALL )
71   {
72     //ERASE ALL
73     QStringList comps;
74     study->components( comps );
75     QStringList::const_iterator anIt = comps.begin(), aLast = comps.end();
76     for( ; anIt!=aLast; anIt++ )
77     {
78       LightApp_Displayer* disp = displayer( app->moduleTitle( *anIt ) );
79       if( disp )
80         disp->EraseAll( false, false, 0 );
81     }
82     if( myActionType==ERASE_ALL )
83     {
84       d->UpdateViewer();
85       commit();
86       return;
87     }
88   }
89
90   SALOME_ListIO selObjs;
91   mgr->selectedObjects( selObjs );
92
93   QStringList entries;
94   SALOME_ListIteratorOfListIO anIt( selObjs );
95   for( ; anIt.More(); anIt.Next() )
96   {
97     if( anIt.Value().IsNull() )
98       continue;
99
100     if( study->isComponent( anIt.Value()->getEntry() ) )
101       study->children( anIt.Value()->getEntry(), entries );
102     else
103       entries.append( anIt.Value()->getEntry() );
104   }
105
106   for( QStringList::const_iterator it = entries.begin(), last = entries.end(); it!=last; it++ )
107   {
108     QString e = study->referencedToEntry( *it );
109     if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY )
110       d->Display( e, false, 0 );
111     else if( myActionType==ERASE )
112       d->Erase( e, false, false, 0 );
113   }
114   d->UpdateViewer();
115   commit();
116 }