1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: LightApp_DataModel.cxx
24 // Created: 10/25/2004 10:36:06 AM
25 // Author: Sergey LITONIN
27 #include "LightApp_DataModel.h"
28 #include "LightApp_Study.h"
29 #include "LightApp_DataObject.h"
30 #include "LightApp_Module.h"
31 #include "LightApp_Application.h"
33 #include <SUIT_TreeModel.h>
34 #include <SUIT_DataBrowser.h>
35 #include <SUIT_DataObject.h>
40 LightApp_DataModel::LightApp_DataModel( CAM_Module* theModule )
41 : CAM_DataModel( theModule )
45 myGroupId = qHash( module()->name() );
51 LightApp_DataModel::~LightApp_DataModel()
58 bool LightApp_DataModel::open( const QString&, CAM_Study* study, QStringList )
60 emit opened(); //TODO: is it really needed? to be removed maybe...
67 bool LightApp_DataModel::save( QStringList& )
76 bool LightApp_DataModel::saveAs( const QString&, CAM_Study*, QStringList& )
83 Does nothing by default. Should be redefined in light modules
84 that want to participate in "Dump study" operation.
86 bool LightApp_DataModel::dumpPython( const QString&, CAM_Study*, bool, QStringList& )
94 bool LightApp_DataModel::close()
101 Build whole data model tree
103 void LightApp_DataModel::build()
108 Updates data model presentation in some widgets (for example, in object browser
110 void LightApp_DataModel::updateWidgets()
112 LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
114 app->objectBrowser()->updateTree( 0, false );
118 Default behaviour of data model update for light modules
120 void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* )
122 // san: Previously modelRoot was casted to LightApp_ModuleObject*,
123 // BUT this is incorrect: in full SALOME the model root has different type.
124 // Hopefully LightApp_DataObject* is sufficient here.
125 LightApp_DataObject* modelRoot = dynamic_cast<LightApp_DataObject*>( root() );
127 QMap<SUIT_DataObject*,int> aMap;
130 ch = modelRoot->children();
131 QListIterator<SUIT_DataObject*> it( ch );
132 while ( it.hasNext() )
133 it.next()->setParent( 0 );
138 modelRoot = dynamic_cast<LightApp_DataObject*>( root() );
141 DataObjectList new_ch = modelRoot->children();
142 QListIterator<SUIT_DataObject*> it1( new_ch );
143 while ( it1.hasNext() )
144 aMap.insert( it1.next(), 0 );
149 QListIterator<SUIT_DataObject*> it( ch );
150 while ( it.hasNext() ) {
151 SUIT_DataObject* aDO = it.next();
152 if( !aMap.contains( aDO ) )
158 \return corresponding module
160 LightApp_Module* LightApp_DataModel::getModule() const
162 return dynamic_cast<LightApp_Module*>( module() );
166 \return corresponding study
168 LightApp_Study* LightApp_DataModel::getStudy() const
170 LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root()->root() );
173 return aRoot->study();
177 default implementation, always returns false so as not to mask study's isModified()
179 bool LightApp_DataModel::isModified() const
185 default implementation, always returns true so as not to mask study's isSaved()
187 bool LightApp_DataModel::isSaved() const
193 \return data model group id used for custom columns creation
195 int LightApp_DataModel::groupId() const
201 Register custom column in the object browser
202 \param browser - object browser where new column should be created
203 \param name - translated column name
204 \param custom_id - custom column identificator passed into data object's methods text(), icon() etc
206 void LightApp_DataModel::registerColumn( SUIT_DataBrowser* browser, const QString& name, const int custom_id )
208 SUIT_AbstractModel* m = dynamic_cast<SUIT_AbstractModel*>( browser ? browser->model() : 0 );
210 m->registerColumn( groupId(), name, custom_id );
214 Remove registered custom column from the object browser
215 \param browser - object browser where new column should be created
216 \param name - translated column name
218 void LightApp_DataModel::unregisterColumn( SUIT_DataBrowser* browser, const QString& name )
220 SUIT_AbstractModel* m = dynamic_cast<SUIT_AbstractModel*>( browser ? browser->model() : 0 );
222 m->unregisterColumn( groupId(), name );
226 Creates the data model's root (module object) using the study services.
227 This is important because different study classes use different moduel object classes.
228 Therefore creation of the module object cannot be done at the data model level
229 where the type of the current study instance should not be known.
230 The module object returned by this method should be then passed to the model's setRoot().
231 \return the module object instance corresponding to the study type
232 \sa CAM_DataModel class
234 CAM_ModuleObject* LightApp_DataModel::createModuleObject( SUIT_DataObject* theRoot ) const
236 LightApp_RootObject* aStudyRoot = dynamic_cast<LightApp_RootObject*>( theRoot );
240 LightApp_Study* aStudy = aStudyRoot->study();
242 return aStudy->createModuleObject( const_cast<LightApp_DataModel*>( this ),