Back to index

salome-gui  6.5.0
SalomeApp_Module.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 // File:      SalomeApp_Module.cxx
00024 // Created:   10/25/2004 11:39:56 AM
00025 // Author:    Sergey LITONIN
00026 
00027 #include "SalomeApp_Module.h"
00028 #include "SalomeApp_DataModel.h"
00029 #include "SalomeApp_Application.h"
00030 #include "SalomeApp_Study.h"
00031 #include "SalomeApp_DataObject.h"
00032 
00033 #include "LightApp_Selection.h"
00034 
00035 #include "CAM_DataModel.h"
00036 
00037 // temporary commented
00038 //#include "OB_Browser.h"
00039 
00040 #include <SALOME_ListIO.hxx>
00041 #include <SALOME_ListIteratorOfListIO.hxx>
00042 #include <SALOME_InteractiveObject.hxx>
00043           
00044 #include <LightApp_DataObject.h>
00045 
00046 #include <SUIT_Session.h>
00047 #include <SUIT_DataBrowser.h>
00048 #include <SUIT_ViewManager.h>
00049 #include <SUIT_MessageBox.h>
00050 #include <SUIT_Desktop.h>
00051 
00052 #include <QString>
00053 
00055 SalomeApp_Module::SalomeApp_Module( const QString& name )
00056   : LightApp_Module( name ),
00057     myIsFirstActivate( true )
00058 {
00059 }
00060 
00062 SalomeApp_Module::~SalomeApp_Module()
00063 {
00064 }
00065 
00067 SalomeApp_Application* SalomeApp_Module::getApp() const
00068 {
00069   return (SalomeApp_Application*)application();
00070 }
00071 
00073 CAM_DataModel* SalomeApp_Module::createDataModel()
00074 {
00075   return new SalomeApp_DataModel(this);
00076 }
00077 
00079 LightApp_Selection* SalomeApp_Module::createSelection() const
00080 {
00081   return LightApp_Module::createSelection();
00082 }
00083 
00090 void SalomeApp_Module::extractContainers( const SALOME_ListIO& source, SALOME_ListIO& dest ) const
00091 {
00092   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
00093   if( !study )
00094   {
00095     dest = source;
00096     return;
00097   }
00098 
00099   SALOME_ListIteratorOfListIO anIt( source );
00100   for( ; anIt.More(); anIt.Next() )
00101   {
00102     Handle( SALOME_InteractiveObject ) obj = anIt.Value();
00103     if( obj->hasEntry() )
00104     {
00105       _PTR(SObject) SO = study->studyDS()->FindObjectID( obj->getEntry() );
00106       if( SO && QString( SO->GetID().c_str() ) == SO->GetFatherComponent()->GetID().c_str() )
00107       { //component is selected
00108         _PTR(SComponent) SC( SO->GetFatherComponent() );
00109         _PTR(ChildIterator) anIter ( study->studyDS()->NewChildIterator( SC ) );
00110         anIter->InitEx( true );
00111         while( anIter->More() )
00112         {
00113           _PTR(SObject) valSO ( anIter->Value() );
00114           _PTR(SObject) refSO;
00115           if( !valSO->ReferencedObject( refSO ) )
00116           {
00117             QString id = valSO->GetID().c_str(),
00118                     comp = SC->ComponentDataType().c_str(),
00119                     val = valSO->GetName().c_str();
00120 
00121             Handle( SALOME_InteractiveObject ) new_obj =
00122               new SALOME_InteractiveObject( id.toLatin1(), comp.toLatin1(), val.toLatin1() );
00123             dest.Append( new_obj );
00124           }
00125           anIter->Next();
00126         }
00127         continue;
00128       }
00129     }
00130     dest.Append( obj );
00131   }
00132 }
00133 
00140 void SalomeApp_Module::storeVisualParameters(int savePoint)
00141 {
00142 }
00143 
00144 
00146 bool SalomeApp_Module::activateModule( SUIT_Study* theStudy )
00147 {
00148   bool state = LightApp_Module::activateModule( theStudy );
00149 
00150   if (!myIsFirstActivate)
00151     return state;
00152   
00153   updateModuleVisibilityState();
00154 
00155   myIsFirstActivate = false;
00156   
00157   return state;
00158 }
00159 
00166 void SalomeApp_Module::restoreVisualParameters(int savePoint)
00167 {
00168 }
00169 
00171 void SalomeApp_Module::studyClosed( SUIT_Study* theStudy )
00172 {
00173   LightApp_Module::studyClosed( theStudy );
00174   
00175   myIsFirstActivate = true;
00176   
00177   LightApp_Application* app = dynamic_cast<LightApp_Application*>(application());
00178   if (!app)
00179     return;
00180   
00181   SUIT_DataBrowser* ob = app->objectBrowser();
00182   if (ob && ob->model())
00183     disconnect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ),
00184                 this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ) );
00185 }
00186 
00187 
00194 void SalomeApp_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
00195 {
00196   if (!isActiveModule())
00197     return;
00198   // change visibility of object
00199   if (!theObject || theColumn != SUIT_DataObject::VisibilityId )
00200     return;
00201 
00202   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
00203   if( !study )
00204     return;
00205 
00206   LightApp_DataObject* lo = dynamic_cast<LightApp_DataObject*>(theObject);
00207   if(!lo)
00208     return;
00209   
00210   // detect action index (from LightApp level)
00211   int id = -1;
00212   
00213   if ( study->visibilityState(lo->entry()) == Qtx::ShownState )
00214     id = myErase;
00215   else if ( study->visibilityState(lo->entry()) == Qtx::HiddenState )
00216     id = myDisplay;
00217   
00218   if ( id != -1 )
00219     startOperation( id );
00220 }
00221 
00222 
00226 void SalomeApp_Application::onStudyClosed( SUIT_Study* theStudy){
00227   LightApp_Application::onStudyClosed(theStudy);
00228 
00229   disconnect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
00230              this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
00231 }
00232 
00233 
00234 void SalomeApp_Module::updateModuleVisibilityState() {
00235 
00236   // update visibility state of objects
00237   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
00238   if (!app)
00239     return;
00240   
00241   SUIT_DataBrowser* ob = app->objectBrowser();
00242   if (!ob || !ob->model())
00243     return;
00244 
00245   // connect to click on item
00246   connect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ),
00247            this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ), Qt::UniqueConnection );
00248 
00249   SUIT_DataObject* rootObj = ob->root();
00250   if( !rootObj )
00251     return;
00252   
00253   DataObjectList listObj = rootObj->children( true );
00254   
00255   SUIT_ViewModel* vmod = 0;
00256   if ( SUIT_ViewManager* vman = app->activeViewManager() )
00257     vmod = vman->getViewModel();
00258   app->updateVisibilityState( listObj, vmod );
00259 }