1 // Copyright (C) 2007-2008 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.
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
22 #include "CAM_DataModel.h"
24 #include "CAM_Module.h"
25 #include "CAM_DataObject.h"
29 \brief Base class for all data models used in CAM-based applications.
31 Represents data model of the CAM module. Provides necessary interface
32 (default implementation is empty).
38 Initialise data module by specified \a module.
40 CAM_DataModel::CAM_DataModel( CAM_Module* module )
51 CAM_DataModel::~CAM_DataModel()
56 \brief Initialize data model.
58 This method should be re-implemented in the successor classes
59 and can be used for creation of root data object.
60 Default implementation does nothing.
62 void CAM_DataModel::initialize()
67 \brief Get data model root object.
71 CAM_DataObject* CAM_DataModel::root() const
77 \brief Set data model root object.
79 This method should be used to specify custom root object instance.
81 Root object can be created in several ways, depending on application or module needs:
82 - in initialize() method
83 - while the data model is being loaded
84 - when the data model is updated and becomes non-empty
86 If root object is changed, this method emits rootChanged() signal.
88 \param newRoot new root object
90 void CAM_DataModel::setRoot( const CAM_DataObject* newRoot )
92 if ( myRoot == newRoot )
96 myRoot->disconnect( SIGNAL( destroyed( SUIT_DataObject* ) ),
97 this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
99 myRoot = (CAM_DataObject*)newRoot;
102 myRoot->connect( SIGNAL( destroyed( SUIT_DataObject* ) ),
103 this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
105 emit rootChanged( this );
110 \return module owning this data model
112 CAM_Module* CAM_DataModel::module() const
118 \brief Called when data object is destroyed.
120 Nullifies the root object if it is detroyed to avoid crashes.
122 \param obj object being destroyed
124 void CAM_DataModel::onDestroyed( SUIT_DataObject* obj )
131 \brief Load data model.
133 This method should be re-implemented in the successor classes.
134 Default implementation returns \c true.
136 \param name study name
138 \param files list of file names from which data should be loaded
139 \return \c true if data model is loaded successfully
141 bool CAM_DataModel::open( const QString& /*name*/,
142 CAM_Study* /*study*/,
143 QStringList /*files*/ )
149 \brief Save data model.
151 This method should be re-implemented in the successor classes.
152 Default implementation returns \c true.
154 \param files list of file names to which data should be saved
155 \return \c true if data model is saved successfully
157 bool CAM_DataModel::save( QStringList& )
163 \brief Save data to the new file.
165 This method should be re-implemented in the successor classes.
166 Default implementation returns \c true.
168 \param name study name
170 \param files resulting list of file names to which data is saved
171 \return \c true if data model is saved successfully
173 bool CAM_DataModel::saveAs( const QString& /*name*/,
174 CAM_Study* /*study*/,
175 QStringList& /*files*/ )
181 \brief Close data model.
183 This method should be re-implemented in the successor classes.
184 Default implementation returns \c true.
186 \return \c true if data model is closed successfully
188 bool CAM_DataModel::close()
194 \brief Create empty data model.
196 This method should be re-implemented in the successor classes.
197 Default implementation returns \c true.
199 \return \c true if data model is created successfully
201 bool CAM_DataModel::create( CAM_Study* )
207 \fn void CAM_DataModel::rootChanged( const CAM_DataModel* root );
208 \brief Emitted when the root data object is changed.
209 \param root new root data object