Salome HOME
PAL10479
[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       app->addModule( m );
35   }
36
37   if( m )
38   {
39     m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
40     m->setMenuShown( false );
41     m->setToolShown( false );
42   }
43   return m ? m->displayer() : 0;
44 }
45
46 void LightApp_ShowHideOp::startOperation()
47 {
48   LightApp_Application* app = dynamic_cast<LightApp_Application*>( application() );
49   LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
50   if( !app || !study )
51   {
52     abort();
53     return;
54   }
55
56   LightApp_SelectionMgr* mgr = app->selectionMgr();
57   LightApp_Selection sel; sel.init( "", mgr );
58   if( sel.count()==0 && myActionType!=ERASE_ALL )
59   {
60     abort();
61     return;
62   }
63   QString aStr =  sel.param( 0, "component" ).toString();
64   QString mod_name = app->moduleTitle( aStr );//sel.param( 0, "component" ).toString() );
65   LightApp_Displayer* d = displayer( mod_name );
66   if( !d )
67   {
68     abort();
69     return;
70   }
71
72   if( myActionType==DISPLAY_ONLY || myActionType==ERASE_ALL )
73   {
74     //ERASE ALL
75     QStringList comps;
76     study->components( comps );
77     QStringList::const_iterator anIt = comps.begin(), aLast = comps.end();
78     for( ; anIt!=aLast; anIt++ )
79     {
80       LightApp_Displayer* disp = displayer( app->moduleTitle( *anIt ) );
81       if( disp )
82         disp->EraseAll( false, false, 0 );
83     }
84     if( myActionType==ERASE_ALL )
85     {
86       d->UpdateViewer();
87       commit();
88       return;
89     }
90   }
91
92   SALOME_ListIO selObjs;
93   mgr->selectedObjects( selObjs );
94
95   QStringList entries;
96   SALOME_ListIteratorOfListIO anIt( selObjs );
97   for( ; anIt.More(); anIt.Next() )
98   {
99     if( anIt.Value().IsNull() )
100       continue;
101
102     if( study->isComponent( anIt.Value()->getEntry() ) )
103       study->children( anIt.Value()->getEntry(), entries );
104     else
105       entries.append( anIt.Value()->getEntry() );
106   }
107
108   for( QStringList::const_iterator it = entries.begin(), last = entries.end(); it!=last; it++ )
109   {
110     QString e = study->referencedToEntry( *it );
111     if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY )
112       d->Display( e, false, 0 );
113     else if( myActionType==ERASE )
114       d->Erase( e, false, false, 0 );
115   }
116   d->UpdateViewer();
117   commit();
118 }