Back to index

salome-gui  6.5.0
LightApp_DataModel.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:      LightApp_DataModel.cxx
00024 // Created:   10/25/2004 10:36:06 AM
00025 // Author:    Sergey LITONIN
00026 //
00027 #include "LightApp_DataModel.h"
00028 #include "LightApp_Study.h"
00029 #include "LightApp_DataObject.h"
00030 #include "LightApp_Module.h"
00031 #include "LightApp_Application.h"
00032 
00033 #include <SUIT_TreeModel.h>
00034 #include <SUIT_DataBrowser.h>
00035 #include <SUIT_DataObject.h>
00036 
00040 LightApp_DataModel::LightApp_DataModel( CAM_Module* theModule )
00041 : CAM_DataModel( theModule )
00042 {
00043   myGroupId = 0;
00044   if( module() )
00045         myGroupId = qHash( module()->name() );
00046 }
00047 
00051 LightApp_DataModel::~LightApp_DataModel()
00052 {
00053 }
00054 
00058 bool LightApp_DataModel::open( const QString&, CAM_Study* study, QStringList )
00059 {
00060   emit opened(); //TODO: is it really needed? to be removed maybe...
00061   return true;
00062 }
00063 
00067 bool LightApp_DataModel::save( QStringList& )
00068 {
00069   emit saved();
00070   return true;
00071 }
00072 
00076 bool LightApp_DataModel::saveAs( const QString&, CAM_Study*, QStringList& )
00077 {
00078   emit saved();
00079   return true;
00080 }
00081 
00086 bool LightApp_DataModel::dumpPython( const QString&, CAM_Study*, bool, QStringList& )
00087 {
00088   return true;
00089 }
00090 
00094 bool LightApp_DataModel::close()
00095 {
00096   emit closed();
00097   return true;
00098 }
00099 
00103 void LightApp_DataModel::build()
00104 {
00105 }
00106 
00110 void LightApp_DataModel::updateWidgets()
00111 {
00112   LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
00113   if ( app )
00114     app->objectBrowser()->updateTree( 0, false );
00115 }
00116 
00120 void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* )
00121 {
00122   // san: Previously modelRoot was casted to LightApp_ModuleObject*,
00123   // BUT this is incorrect: in full SALOME the model root has different type.
00124   // Hopefully LightApp_DataObject* is sufficient here.
00125   LightApp_DataObject* modelRoot = dynamic_cast<LightApp_DataObject*>( root() );
00126   DataObjectList ch;
00127   QMap<SUIT_DataObject*,int> aMap;
00128   if( modelRoot )
00129   {
00130     ch = modelRoot->children();
00131     QListIterator<SUIT_DataObject*> it( ch );
00132     while ( it.hasNext() )
00133       it.next()->setParent( 0 );
00134   }
00135 
00136   build();
00137 
00138   modelRoot = dynamic_cast<LightApp_DataObject*>( root() );
00139   if( modelRoot )
00140   {
00141     DataObjectList new_ch = modelRoot->children();
00142     QListIterator<SUIT_DataObject*> it1( new_ch );
00143     while ( it1.hasNext() )
00144       aMap.insert( it1.next(), 0 );
00145   }
00146 
00147   updateWidgets();
00148 
00149   QListIterator<SUIT_DataObject*> it( ch );
00150   while ( it.hasNext() ) {
00151     SUIT_DataObject* aDO = it.next();
00152     if( !aMap.contains( aDO ) )
00153       delete aDO;
00154   }
00155 }
00156 
00160 LightApp_Module* LightApp_DataModel::getModule() const
00161 {
00162   return dynamic_cast<LightApp_Module*>( module() );
00163 }
00164 
00168 LightApp_Study* LightApp_DataModel::getStudy() const
00169 {
00170   LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root()->root() );
00171   if ( !aRoot )
00172     return 0;
00173   return aRoot->study();
00174 }
00175 
00179 bool LightApp_DataModel::isModified() const
00180 {
00181   return false;
00182 }
00183 
00187 bool LightApp_DataModel::isSaved() const
00188 {
00189   return true;
00190 }
00191 
00195 int LightApp_DataModel::groupId() const
00196 {
00197   return myGroupId;
00198 }
00199 
00206 void LightApp_DataModel::registerColumn( SUIT_DataBrowser* browser, const QString& name, const int custom_id )
00207 {
00208   SUIT_AbstractModel* m = dynamic_cast<SUIT_AbstractModel*>( browser ? browser->model() : 0 );
00209   if( m )
00210     m->registerColumn( groupId(), name, custom_id );
00211 }
00212 
00218 void LightApp_DataModel::unregisterColumn( SUIT_DataBrowser* browser, const QString& name )
00219 {
00220   SUIT_AbstractModel* m = dynamic_cast<SUIT_AbstractModel*>( browser ? browser->model() : 0 );
00221   if( m )
00222     m->unregisterColumn( groupId(), name );
00223 }
00224 
00234 CAM_ModuleObject* LightApp_DataModel::createModuleObject( SUIT_DataObject* theRoot ) const
00235 {
00236   LightApp_RootObject* aStudyRoot = dynamic_cast<LightApp_RootObject*>( theRoot );
00237   if ( !aStudyRoot )
00238     return 0;
00239 
00240   LightApp_Study* aStudy = aStudyRoot->study();
00241   if ( aStudy )
00242     return aStudy->createModuleObject( const_cast<LightApp_DataModel*>( this ), 
00243                                    theRoot );
00244   return 0;
00245 }