Back to index

salome-gui  6.5.0
LightApp_ShowHideOp.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "LightApp_ShowHideOp.h"
00024 #include "LightApp_Application.h"
00025 #include "LightApp_Module.h"
00026 #include "LightApp_Study.h"
00027 #include "LightApp_Displayer.h"
00028 
00029 #include "LightApp_SelectionMgr.h"
00030 #include "LightApp_Selection.h"
00031 
00032 #ifndef DISABLE_SALOMEOBJECT
00033   #include <SALOME_ListIO.hxx>
00034   #include <SALOME_ListIteratorOfListIO.hxx>
00035 #endif
00036 
00040 LightApp_ShowHideOp::LightApp_ShowHideOp( ActionType type )
00041 : LightApp_Operation(),
00042   myActionType( type )
00043 {
00044 }
00045 
00049 LightApp_ShowHideOp::~LightApp_ShowHideOp()
00050 {
00051 }
00052 
00056 void LightApp_ShowHideOp::startOperation()
00057 {
00058   LightApp_Application* app = dynamic_cast<LightApp_Application*>( application() );
00059   LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
00060   if( !app || !study )
00061   {
00062     abort();
00063     return;
00064   }
00065 
00066   LightApp_SelectionMgr* mgr = app->selectionMgr();
00067   LightApp_Module* mod = dynamic_cast<LightApp_Module*>( app->activeModule() );
00068   if( !mod )
00069     return;
00070 
00071   LightApp_Selection* sel = mod->createSelection();
00072   if( !sel )
00073     return;
00074 
00075   sel->init( "", mgr );
00076   if( sel->count()==0 && myActionType!=ERASE_ALL )
00077   {
00078     abort();
00079     return;
00080   }
00081 
00082   QString mod_name;
00083   if( sel->count()>0 )
00084   {
00085     QString aStr =  sel->parameter( 0, "displayer" ).toString();
00086     mod_name = app->moduleTitle( aStr );
00087   }
00088   else if( app->activeModule() )
00089     mod_name = app->moduleTitle( app->activeModule()->name() );
00090 
00091   LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, true );
00092   if( !d )
00093   {
00094     abort();
00095     return;
00096   }
00097 
00098   if( myActionType==DISPLAY_ONLY || myActionType==ERASE_ALL )
00099   {
00100     //ERASE ALL
00101     QStringList comps;
00102     study->components( comps );
00103     QStringList::const_iterator anIt = comps.begin(), aLast = comps.end();
00104     for( ; anIt!=aLast; anIt++ )
00105     {
00106       LightApp_Displayer* disp = LightApp_Displayer::FindDisplayer( app->moduleTitle( *anIt ), true );
00107       if( disp )
00108         disp->EraseAll( false, false, 0 );
00109     }
00110     if( myActionType==ERASE_ALL )
00111     {
00112       d->UpdateViewer();
00113       commit();
00114       return;
00115     }
00116   }
00117 
00118   QStringList entries;
00119 
00120 #ifndef DISABLE_SALOMEOBJECT
00121   SALOME_ListIO selObjs;
00122   mgr->selectedObjects( selObjs );
00123   SALOME_ListIteratorOfListIO anIt( selObjs );
00124   for( ; anIt.More(); anIt.Next() )
00125     if( !anIt.Value().IsNull() )
00126 #else
00127   QStringList selObjs;
00128   mgr->selectedObjects( selObjs );
00129   QStringList::const_iterator anIt = selObjs.begin(), aLast = selObjs.end();
00130   for( ; ; anIt!=aLast )
00131 #endif
00132     {
00133       QString entry = 
00134 #ifndef DISABLE_SALOMEOBJECT
00135         anIt.Value()->getEntry();
00136 #else
00137         *anIt;
00138 #endif
00139 
00140       if( study->isComponent( entry ) )
00141         study->children( entry, entries );
00142       else
00143         entries.append( entry );
00144     }
00145 
00146   // be sure to use real obejct entries
00147   QStringList objEntries;
00148   QStringList::const_iterator it = entries.begin(), last = entries.end();
00149   for ( ; it!=last; ++it )
00150     objEntries.append( study->referencedToEntry( *it ) ); 
00151   
00152   if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY ) {
00153     d->Display( objEntries, false, 0 );
00154     mgr->setSelectedObjects(selObjs);
00155   }
00156   else if( myActionType==ERASE ) {
00157     d->Erase( objEntries, false, false, 0 );
00158   }
00159   
00160   d->UpdateViewer();
00161   commit();
00162 }