Salome HOME
e6cefd5c01bc2c85172685669a80a40091634b05
[modules/gui.git] / src / LightApp / LightApp_ShowHideOp.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "LightApp_ShowHideOp.h"
23 #include "LightApp_Application.h"
24 #include "LightApp_Module.h"
25 #include "LightApp_Study.h"
26 #include "LightApp_Displayer.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_Module* mod = dynamic_cast<LightApp_Module*>( app->activeModule() );
67   if( !mod )
68     return;
69
70   LightApp_Selection* sel = mod->createSelection();
71   if( !sel )
72     return;
73
74   sel->init( "", mgr );
75   if( sel->count()==0 && myActionType!=ERASE_ALL )
76   {
77     abort();
78     return;
79   }
80
81   QString mod_name;
82   if( sel->count()>0 )
83   {
84     QString aStr =  sel->parameter( 0, "displayer" ).toString();
85     mod_name = app->moduleTitle( aStr );
86   }
87   else if( app->activeModule() )
88     mod_name = app->moduleTitle( app->activeModule()->name() );
89
90   LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, true );
91   if( !d )
92   {
93     abort();
94     return;
95   }
96
97   if( myActionType==DISPLAY_ONLY || myActionType==ERASE_ALL )
98   {
99     //ERASE ALL
100     QStringList comps;
101     study->components( comps );
102     QStringList::const_iterator anIt = comps.begin(), aLast = comps.end();
103     for( ; anIt!=aLast; anIt++ )
104     {
105       LightApp_Displayer* disp = LightApp_Displayer::FindDisplayer( app->moduleTitle( *anIt ), true );
106       if( disp )
107         disp->EraseAll( false, false, 0 );
108     }
109     if( myActionType==ERASE_ALL )
110     {
111       d->UpdateViewer();
112       commit();
113       return;
114     }
115   }
116
117   QStringList entries;
118
119 #ifndef DISABLE_SALOMEOBJECT
120   SALOME_ListIO selObjs;
121   mgr->selectedObjects( selObjs );
122   SALOME_ListIteratorOfListIO anIt( selObjs );
123   for( ; anIt.More(); anIt.Next() )
124     if( !anIt.Value().IsNull() )
125 #else
126   QStringList selObjs;
127   mgr->selectedObjects( selObjs );
128   QStringList::const_iterator anIt = selObjs.begin(), aLast = selObjs.end();
129   for( ; ; anIt!=aLast )
130 #endif
131     {
132       QString entry = 
133 #ifndef DISABLE_SALOMEOBJECT
134         anIt.Value()->getEntry();
135 #else
136         *anIt;
137 #endif
138
139       if( study->isComponent( entry ) )
140         study->children( entry, entries );
141       else
142         entries.append( entry );
143     }
144
145   for( QStringList::const_iterator it = entries.begin(), last = entries.end(); it!=last; it++ )
146   {
147     QString e = study->referencedToEntry( *it );
148     if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY )
149       d->Display( e, false, 0 );
150     else if( myActionType==ERASE )
151       d->Erase( e, false, false, 0 );
152   }
153   d->UpdateViewer();
154   commit();
155 }