]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_ShowHideOp.cxx
Salome HOME
Improvement: now in rules you can use "canBeDisplayed" parameter. It is true, if...
[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 void LightApp_ShowHideOp::startOperation()
27 {
28   LightApp_Application* app = dynamic_cast<LightApp_Application*>( application() );
29   LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
30   if( !app || !study )
31   {
32     abort();
33     return;
34   }
35
36   LightApp_SelectionMgr* mgr = app->selectionMgr();
37   LightApp_Selection sel; sel.init( "", mgr );
38   if( sel.count()==0 && myActionType!=ERASE_ALL )
39   {
40     abort();
41     return;
42   }
43   QString aStr =  sel.param( 0, "component" ).toString();
44   QString mod_name = app->moduleTitle( aStr );//sel.param( 0, "component" ).toString() );
45   LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, true );
46   if( !d )
47   {
48     abort();
49     return;
50   }
51
52   if( myActionType==DISPLAY_ONLY || myActionType==ERASE_ALL )
53   {
54     //ERASE ALL
55     QStringList comps;
56     study->components( comps );
57     QStringList::const_iterator anIt = comps.begin(), aLast = comps.end();
58     for( ; anIt!=aLast; anIt++ )
59     {
60       LightApp_Displayer* disp = LightApp_Displayer::FindDisplayer( app->moduleTitle( *anIt ), true );
61       if( disp )
62         disp->EraseAll( false, false, 0 );
63     }
64     if( myActionType==ERASE_ALL )
65     {
66       d->UpdateViewer();
67       commit();
68       return;
69     }
70   }
71
72   SALOME_ListIO selObjs;
73   mgr->selectedObjects( selObjs );
74
75   QStringList entries;
76   SALOME_ListIteratorOfListIO anIt( selObjs );
77   for( ; anIt.More(); anIt.Next() )
78   {
79     if( anIt.Value().IsNull() )
80       continue;
81
82     if( study->isComponent( anIt.Value()->getEntry() ) )
83       study->children( anIt.Value()->getEntry(), entries );
84     else
85       entries.append( anIt.Value()->getEntry() );
86   }
87
88   for( QStringList::const_iterator it = entries.begin(), last = entries.end(); it!=last; it++ )
89   {
90     QString e = study->referencedToEntry( *it );
91     if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY )
92       d->Display( e, false, 0 );
93     else if( myActionType==ERASE )
94       d->Erase( e, false, false, 0 );
95   }
96   d->UpdateViewer();
97   commit();
98 }