Salome HOME
Synchronize adm files
[modules/gui.git] / src / LightApp / LightApp_ShowHideOp.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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
23 #include "LightApp_ShowHideOp.h"
24 #include "LightApp_Application.h"
25 #include "LightApp_Module.h"
26 #include "LightApp_Study.h"
27 #include "LightApp_Displayer.h"
28
29 #include "LightApp_SelectionMgr.h"
30 #include "LightApp_Selection.h"
31
32 #ifndef DISABLE_SALOMEOBJECT
33   #include <SALOME_ListIO.hxx>
34   #include <SALOME_ListIteratorOfListIO.hxx>
35 #endif
36
37 /*!
38   Constructor
39 */
40 LightApp_ShowHideOp::LightApp_ShowHideOp( ActionType type )
41 : LightApp_Operation(),
42   myActionType( type )
43 {
44 }
45
46 /*!
47   Destructor
48 */
49 LightApp_ShowHideOp::~LightApp_ShowHideOp()
50 {
51 }
52
53 /*!
54   Makes show/hide operation
55 */
56 void LightApp_ShowHideOp::startOperation()
57 {
58   LightApp_Application* app = dynamic_cast<LightApp_Application*>( application() );
59   LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
60   if( !app || !study )
61   {
62     abort();
63     return;
64   }
65
66   LightApp_SelectionMgr* mgr = app->selectionMgr();
67   LightApp_Module* mod = dynamic_cast<LightApp_Module*>( app->activeModule() );
68   if( !mod )
69     return;
70
71   LightApp_Selection* sel = mod->createSelection();
72   if( !sel )
73     return;
74
75   sel->init( "", mgr );
76   if( sel->count()==0 && myActionType!=ERASE_ALL )
77   {
78     abort();
79     return;
80   }
81
82   QString mod_name;
83   if( sel->count()>0 )
84   {
85     QString aStr =  sel->parameter( 0, "displayer" ).toString();
86     mod_name = app->moduleTitle( aStr );
87   }
88   else if( app->activeModule() )
89     mod_name = app->moduleTitle( app->activeModule()->name() );
90
91   LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, true );
92   if( !d )
93   {
94     abort();
95     return;
96   }
97
98   if( myActionType==DISPLAY_ONLY || myActionType==ERASE_ALL )
99   {
100     //ERASE ALL
101     QStringList comps;
102     study->components( comps );
103     QStringList::const_iterator anIt = comps.begin(), aLast = comps.end();
104     for( ; anIt!=aLast; anIt++ )
105     {
106       LightApp_Displayer* disp = LightApp_Displayer::FindDisplayer( app->moduleTitle( *anIt ), false );
107       if( disp )
108         disp->EraseAll( false, false, 0 );
109     }
110     if( myActionType==ERASE_ALL )
111     {
112       d->UpdateViewer();
113       commit();
114       return;
115     }
116   }
117
118   QStringList entries;
119
120 #ifndef DISABLE_SALOMEOBJECT
121   SALOME_ListIO selObjs;
122   mgr->selectedObjects( selObjs );
123   SALOME_ListIteratorOfListIO anIt( selObjs );
124   for( ; anIt.More(); anIt.Next() )
125     if( !anIt.Value().IsNull() )
126 #else
127   QStringList selObjs;
128   mgr->selectedObjects( selObjs );
129   QStringList::const_iterator anIt = selObjs.begin(), aLast = selObjs.end();
130   for( ; ; anIt!=aLast )
131 #endif
132     {
133       QString entry = 
134 #ifndef DISABLE_SALOMEOBJECT
135         anIt.Value()->getEntry();
136 #else
137         *anIt;
138 #endif
139
140       if( study->isComponent( entry ) )
141         study->children( entry, entries );
142       else
143         entries.append( entry );
144     }
145
146   // be sure to use real object entries
147   QStringList objEntries;
148   QStringList::const_iterator it = entries.begin(), last = entries.end();
149   for ( ; it!=last; ++it )
150     objEntries.append( study->referencedToEntry( *it ) ); 
151   
152   if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY ) {
153     d->Display( objEntries, false, 0 );
154     mgr->setSelectedObjects(selObjs);
155   }
156   else if( myActionType==ERASE ) {
157     d->Erase( objEntries, false, false, 0 );
158   }
159   
160   d->UpdateViewer();
161   commit();
162 }