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