]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_ShowHideOp.cxx
Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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 #ifndef DISABLE_SALOMEOBJECT
32   #include <SALOME_ListIO.hxx>
33   #include <SALOME_ListIteratorOfListIO.hxx>
34 #endif
35
36 /*!
37   Constructor
38 */
39 LightApp_ShowHideOp::LightApp_ShowHideOp( ActionType type )
40 : LightApp_Operation(),
41   myActionType( type )
42 {
43 }
44
45 /*!
46   Destructor
47 */
48 LightApp_ShowHideOp::~LightApp_ShowHideOp()
49 {
50 }
51
52 /*!
53   Makes show/hide operation
54 */
55 void LightApp_ShowHideOp::startOperation()
56 {
57   LightApp_Application* app = dynamic_cast<LightApp_Application*>( application() );
58   LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
59   if( !app || !study )
60   {
61     abort();
62     return;
63   }
64
65   LightApp_SelectionMgr* mgr = app->selectionMgr();
66   LightApp_Selection sel; sel.init( "", mgr );
67   if( sel.count()==0 && myActionType!=ERASE_ALL )
68   {
69     abort();
70     return;
71   }
72
73   QString mod_name;
74   if( sel.count()>0 )
75   {
76     QString aStr =  sel.param( 0, "component" ).toString();
77     mod_name = app->moduleTitle( aStr );
78   }
79   else if( app->activeModule() )
80     mod_name = app->moduleTitle( app->activeModule()->name() );
81
82   LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, true );
83   if( !d )
84   {
85     abort();
86     return;
87   }
88
89   if( myActionType==DISPLAY_ONLY || myActionType==ERASE_ALL )
90   {
91     //ERASE ALL
92     QStringList comps;
93     study->components( comps );
94     QStringList::const_iterator anIt = comps.begin(), aLast = comps.end();
95     for( ; anIt!=aLast; anIt++ )
96     {
97       LightApp_Displayer* disp = LightApp_Displayer::FindDisplayer( app->moduleTitle( *anIt ), true );
98       if( disp )
99         disp->EraseAll( false, false, 0 );
100     }
101     if( myActionType==ERASE_ALL )
102     {
103       d->UpdateViewer();
104       commit();
105       return;
106     }
107   }
108
109   QStringList entries;
110
111 #ifndef DISABLE_SALOMEOBJECT
112   SALOME_ListIO selObjs;
113   mgr->selectedObjects( selObjs );
114   SALOME_ListIteratorOfListIO anIt( selObjs );
115   for( ; anIt.More(); anIt.Next() )
116     if( !anIt.Value().IsNull() )
117 #else
118   QStringList selObjs;
119   mgr->selectedObjects( selObjs );
120   QStringList::const_iterator anIt = selObjs.begin(), aLast = selObjs.end();
121   for( ; ; anIt!=aLast )
122 #endif
123     {
124       QString entry = 
125 #ifndef DISABLE_SALOMEOBJECT
126         anIt.Value()->getEntry();
127 #else
128         *anIt;
129 #endif
130
131       if( study->isComponent( entry ) )
132         study->children( entry, entries );
133       else
134         entries.append( entry );
135     }
136
137   for( QStringList::const_iterator it = entries.begin(), last = entries.end(); it!=last; it++ )
138   {
139     QString e = study->referencedToEntry( *it );
140     if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY )
141       d->Display( e, false, 0 );
142     else if( myActionType==ERASE )
143       d->Erase( e, false, false, 0 );
144   }
145   d->UpdateViewer();
146   commit();
147 }