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