1 // Copyright (C) 2007-2013 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
23 #include "CAM_DataModel.h"
25 #include "CAM_Module.h"
26 #include "CAM_DataObject.h"
30 \brief Base class for all data models used in CAM-based applications.
32 Represents data model of the CAM module. Provides necessary interface
33 (default implementation is empty).
39 Initialise data module by specified \a module.
41 CAM_DataModel::CAM_DataModel( CAM_Module* module )
52 CAM_DataModel::~CAM_DataModel()
57 \brief Initialize data model.
59 This method should be re-implemented in the successor classes
60 and can be used for creation of root data object.
61 Default implementation does nothing.
63 void CAM_DataModel::initialize()
68 \brief Get data model root object.
72 CAM_DataObject* CAM_DataModel::root() const
78 \brief Set data model root object.
80 This method should be used to specify custom root object instance.
82 Root object can be created in several ways, depending on application or module needs:
83 - in initialize() method
84 - while the data model is being loaded
85 - when the data model is updated and becomes non-empty
87 If root object is changed, this method emits rootChanged() signal.
89 \param newRoot new root object
91 void CAM_DataModel::setRoot( const CAM_DataObject* newRoot )
93 if ( myRoot == newRoot )
97 myRoot->disconnect( SIGNAL( destroyed( SUIT_DataObject* ) ),
98 this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
100 myRoot = (CAM_DataObject*)newRoot;
103 myRoot->connect( SIGNAL( destroyed( SUIT_DataObject* ) ),
104 this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
106 emit rootChanged( this );
111 \return module owning this data model
113 CAM_Module* CAM_DataModel::module() const
119 \brief Called when data object is destroyed.
121 Nullifies the root object if it is detroyed to avoid crashes.
123 \param obj object being destroyed
125 void CAM_DataModel::onDestroyed( SUIT_DataObject* obj )
132 \brief Load data model.
134 This method should be re-implemented in the successor classes.
135 Default implementation returns \c true.
137 \param name study name
139 \param files list of file names from which data should be loaded
140 \return \c true if data model is loaded successfully
142 bool CAM_DataModel::open( const QString& /*name*/,
143 CAM_Study* /*study*/,
144 QStringList /*files*/ )
150 \brief Save data model.
152 This method should be re-implemented in the successor classes.
153 Default implementation returns \c true.
155 \param files list of file names to which data should be saved
156 \return \c true if data model is saved successfully
158 bool CAM_DataModel::save( QStringList& )
164 \brief Save data to the new file.
166 This method should be re-implemented in the successor classes.
167 Default implementation returns \c true.
169 \param name study name
171 \param files resulting list of file names to which data is saved
172 \return \c true if data model is saved successfully
174 bool CAM_DataModel::saveAs( const QString& /*name*/,
175 CAM_Study* /*study*/,
176 QStringList& /*files*/ )
182 \brief Close data model.
184 This method should be re-implemented in the successor classes.
185 Default implementation returns \c true.
187 \return \c true if data model is closed successfully
189 bool CAM_DataModel::close()
195 \brief Create empty data model.
197 This method should be re-implemented in the successor classes.
198 Default implementation returns \c true.
200 \return \c true if data model is created successfully
202 bool CAM_DataModel::create( CAM_Study* )
208 \fn void CAM_DataModel::rootChanged( const CAM_DataModel* root );
209 \brief Emitted when the root data object is changed.
210 \param root new root data object