Salome HOME
4cf18982dd5d82d638cc020863ba236d5dd02d80
[modules/gui.git] / src / LightApp / LightApp_ShowHideOp.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19
20 #include "LightApp_ShowHideOp.h"
21 #include "LightApp_Application.h"
22 #include "LightApp_DataOwner.h"
23 #include "LightApp_Module.h"
24 #include "LightApp_Study.h"
25 #include "LightApp_Displayer.h"
26 #include "CAM_Study.h"
27
28 #include "LightApp_SelectionMgr.h"
29 #include "LightApp_Selection.h"
30
31 #include <SALOME_ListIO.hxx>
32 #include <SALOME_ListIteratorOfListIO.hxx>
33
34 LightApp_ShowHideOp::LightApp_ShowHideOp( ActionType type )
35 : LightApp_Operation(),
36   myActionType( type )
37 {
38 }
39
40 LightApp_ShowHideOp::~LightApp_ShowHideOp()
41 {
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 = LightApp_Displayer::FindDisplayer( mod_name, true );
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 = LightApp_Displayer::FindDisplayer( app->moduleTitle( *anIt ), true );
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 }