]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_DataModel.cxx
Salome HOME
702ef7b335b767c327bee3ee850ffa897052c710
[modules/gui.git] / src / LightApp / LightApp_DataModel.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File:      LightApp_DataModel.cxx
20 // Created:   10/25/2004 10:36:06 AM
21 // Author:    Sergey LITONIN
22 // Copyright (C) CEA 2004
23
24 #include "LightApp_DataModel.h"
25 #include "LightApp_Study.h"
26 #include "LightApp_RootObject.h"
27 #include "LightApp_DataObject.h"
28 #include "LightApp_Module.h"
29 #include "LightApp_Application.h"
30
31 #include <OB_Browser.h>
32
33 #include <SUIT_Application.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_DataObject.h>
37
38 /*!
39   Constructor
40 */
41 LightApp_DataModel::LightApp_DataModel( CAM_Module* theModule )
42 : CAM_DataModel( theModule )
43 {
44 }
45
46 /*!
47   Destructor
48 */
49 LightApp_DataModel::~LightApp_DataModel()
50 {
51 }
52
53 /*!
54   Emit opened()
55 */
56 bool LightApp_DataModel::open( const QString&, CAM_Study* study, QStringList )
57 {
58   emit opened(); //TODO: is it really needed? to be removed maybe...
59   return true;
60 }
61
62 /*!
63   Emit saved()
64 */
65 bool LightApp_DataModel::save( QStringList& )
66 {
67   emit saved();
68   return true;
69 }
70
71 /*!
72   Emit saved()
73 */
74 bool LightApp_DataModel::saveAs( const QString&, CAM_Study*, QStringList& )
75 {
76   emit saved();
77   return true;
78 }
79
80 /*!
81   Emit closed()
82 */
83 bool LightApp_DataModel::close()
84 {
85   emit closed();
86   return true;
87 }
88
89 /*!
90   Build whole data model tree
91 */
92 void LightApp_DataModel::build()
93 {
94 }
95
96 /*!
97   Updates data model presentation in some widgets (for example, in object browser
98 */
99 void LightApp_DataModel::updateWidgets()
100 {
101   LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
102   if( app )
103     app->objectBrowser()->updateTree( 0, false );
104 }
105
106 /*!
107   Default behaviour of data model update for light modules
108 */
109 void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* )
110 {
111   LightApp_ModuleObject* modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
112   DataObjectList ch;
113   QMap<SUIT_DataObject*,int> aMap;
114   if( modelRoot )
115   {
116     ch = modelRoot->children();
117     for ( DataObjectListIterator it( ch ); it.current(); ++it )
118       it.current()->setParent( 0 );
119   }
120
121   build();
122
123   modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
124   if( modelRoot )
125   {
126     DataObjectList new_ch = modelRoot->children();
127     for ( DataObjectListIterator it1( new_ch ); it1.current(); ++it1 )
128       aMap.insert( it1.current(), 0 );
129   }
130
131   updateWidgets();
132
133   for( DataObjectListIterator it( ch ); it.current(); ++it )
134     if( !aMap.contains( it.current() ) )
135       delete it.current();
136 }
137
138 /*!
139   \return corresponding module 
140 */
141 LightApp_Module* LightApp_DataModel::getModule() const
142 {
143   return dynamic_cast<LightApp_Module*>( module() );
144 }
145
146 /*!
147   \return corresponding  study
148 */
149 LightApp_Study* LightApp_DataModel::getStudy() const
150 {
151   LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root()->root() );
152   if ( !aRoot )
153     return 0;
154   return aRoot->study();
155 }
156
157 /*!
158   default implementation, always returns false so as not to mask study's isModified()
159 */
160 bool LightApp_DataModel::isModified() const
161 {
162   return false;
163 }
164
165 /*!
166   default implementation, always returns true so as not to mask study's isSaved()
167 */
168 bool LightApp_DataModel::isSaved() const
169 {
170   return true;
171 }