]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_ShowHideOp.cxx
Salome HOME
Join modifications from branch BR_3_1_0deb
[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
62   QString mod_name;
63   if( sel.count()>0 )
64   {
65     QString aStr =  sel.param( 0, "component" ).toString();
66     mod_name = app->moduleTitle( aStr );
67   }
68   else if( app->activeModule() )
69     mod_name = app->moduleTitle( app->activeModule()->name() );
70
71   LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, true );
72   if( !d )
73   {
74     abort();
75     return;
76   }
77
78   if( myActionType==DISPLAY_ONLY || myActionType==ERASE_ALL )
79   {
80     //ERASE ALL
81     QStringList comps;
82     study->components( comps );
83     QStringList::const_iterator anIt = comps.begin(), aLast = comps.end();
84     for( ; anIt!=aLast; anIt++ )
85     {
86       LightApp_Displayer* disp = LightApp_Displayer::FindDisplayer( app->moduleTitle( *anIt ), true );
87       if( disp )
88         disp->EraseAll( false, false, 0 );
89     }
90     if( myActionType==ERASE_ALL )
91     {
92       d->UpdateViewer();
93       commit();
94       return;
95     }
96   }
97
98   SALOME_ListIO selObjs;
99   mgr->selectedObjects( selObjs );
100
101   QStringList entries;
102   SALOME_ListIteratorOfListIO anIt( selObjs );
103   for( ; anIt.More(); anIt.Next() )
104   {
105     if( anIt.Value().IsNull() )
106       continue;
107
108     if( study->isComponent( anIt.Value()->getEntry() ) )
109       study->children( anIt.Value()->getEntry(), entries );
110     else
111       entries.append( anIt.Value()->getEntry() );
112   }
113
114   for( QStringList::const_iterator it = entries.begin(), last = entries.end(); it!=last; it++ )
115   {
116     QString e = study->referencedToEntry( *it );
117     if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY )
118       d->Display( e, false, 0 );
119     else if( myActionType==ERASE )
120       d->Erase( e, false, false, 0 );
121   }
122   d->UpdateViewer();
123   commit();
124 }