]> SALOME platform Git repositories - modules/gui.git/blob - src/CAM/CAM_DataModel.cxx
Salome HOME
a9c5142fd061f98fdb5c65e2b1e7be5f749e7cef
[modules/gui.git] / src / CAM / CAM_DataModel.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "CAM_DataModel.h"
23
24 #include "CAM_Module.h"
25 #include "CAM_DataObject.h"
26
27 /*!
28   \class CAM_DataModel
29   \brief Base class for all data models used in CAM-based applications.
30   
31   Represents data model of the CAM module. Provides necessary interface
32   (default implementation is empty).
33 */
34
35 /*!
36   \brief Constructor.
37   
38   Initialise data module by specified \a module.
39 */
40 CAM_DataModel::CAM_DataModel( CAM_Module* module )
41 : myRoot( 0 ),
42   myModule( module )
43 {
44 }
45
46 /*!
47   \brief Destructor.
48
49   Does nothing.
50 */
51 CAM_DataModel::~CAM_DataModel()
52 {
53 }
54
55 /*!
56   \brief Initialize data model.
57
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.
61 */
62 void CAM_DataModel::initialize()
63 {
64 }
65
66 /*!
67   \brief Get data model root object.
68   \return root object
69   \sa setRoot()
70 */
71 CAM_DataObject* CAM_DataModel::root() const
72 {
73   return myRoot;
74 }
75
76 /*!
77   \brief Set data model root object.
78
79   This method should be used to specify custom root object instance.
80
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 
85
86   If root object is changed, this method emits rootChanged() signal.
87
88   \param newRoot new root object
89 */
90 void CAM_DataModel::setRoot( const CAM_DataObject* newRoot )
91 {
92   if ( myRoot == newRoot )
93     return;
94
95   if ( myRoot )
96     myRoot->disconnect( SIGNAL( destroyed( SUIT_DataObject* ) ), 
97                         this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
98
99   myRoot = (CAM_DataObject*)newRoot;
100
101   if ( myRoot )
102     myRoot->connect( SIGNAL( destroyed( SUIT_DataObject* ) ), 
103                      this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
104
105   emit rootChanged( this );
106 }
107
108 /*!
109   \brief Get module.
110   \return module owning this data model
111 */
112 CAM_Module* CAM_DataModel::module() const
113 {
114   return myModule;
115 }
116
117 /*!
118   \brief Called when data object is destroyed.
119
120   Nullifies the root object if it is detroyed to avoid crashes.
121   
122   \param obj object being destroyed
123 */
124 void CAM_DataModel::onDestroyed( SUIT_DataObject* obj )
125 {
126   if ( myRoot == obj )
127     myRoot = 0;
128 }
129
130 /*!
131   \brief Load data model.
132
133   This method should be re-implemented in the successor classes.
134   Default implementation returns \c true.
135
136   \param name study name
137   \param study study
138   \param files list of file names from which data should be loaded
139   \return \c true if data model is loaded successfully
140 */
141 bool CAM_DataModel::open( const QString& /*name*/, 
142                           CAM_Study*     /*study*/, 
143                           QStringList    /*files*/ )
144 {
145   return true;
146 }
147
148 /*!
149   \brief Save data model.
150
151   This method should be re-implemented in the successor classes.
152   Default implementation returns \c true.
153
154   \param files list of file names to which data should be saved
155   \return \c true if data model is saved successfully
156 */
157 bool CAM_DataModel::save( QStringList& )
158
159   return true; 
160 }
161
162 /*!
163   \brief Save data to the new file.
164
165   This method should be re-implemented in the successor classes.
166   Default implementation returns \c true.
167
168   \param name study name
169   \param study study
170   \param files resulting list of file names to which data is saved
171   \return \c true if data model is saved successfully
172 */
173 bool CAM_DataModel::saveAs( const QString& /*name*/,
174                             CAM_Study*     /*study*/,
175                             QStringList&   /*files*/ )
176 {
177   return true;
178 }
179
180 /*!
181   \brief Close data model.
182
183   This method should be re-implemented in the successor classes.
184   Default implementation returns \c true.
185
186   \return \c true if data model is closed successfully
187 */
188 bool CAM_DataModel::close()
189
190   return true; 
191 }
192
193 /*!
194   \brief Create empty data model.
195
196   This method should be re-implemented in the successor classes.
197   Default implementation returns \c true.
198
199   \return \c true if data model is created successfully
200 */
201 bool CAM_DataModel::create( CAM_Study* )
202
203   return true; 
204 }
205
206 /*!
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
210 */