Salome HOME
6de670118bc3595a26d9ab3e5b0abb5e382596c4
[modules/gui.git] / src / LightApp / LightApp_DataModel.cxx
1 // File:      LightApp_DataModel.cxx
2 // Created:   10/25/2004 10:36:06 AM
3 // Author:    Sergey LITONIN
4 // Copyright (C) CEA 2004
5
6 #include "LightApp_DataModel.h"
7 #include "LightApp_Study.h"
8 #include "LightApp_RootObject.h"
9 #include "LightApp_DataObject.h"
10 #include "LightApp_Module.h"
11 #include "LightApp_Application.h"
12
13 #include <OB_Browser.h>
14
15 #include <SUIT_Application.h>
16 #include <SUIT_ResourceMgr.h>
17 #include <SUIT_Session.h>
18 #include <SUIT_DataObject.h>
19
20 /*!
21   Constructor
22 */
23 LightApp_DataModel::LightApp_DataModel( CAM_Module* theModule )
24 : CAM_DataModel( theModule )
25 {
26 }
27
28 /*!
29   Destructor
30 */
31 LightApp_DataModel::~LightApp_DataModel()
32 {
33 }
34
35 /*!
36   Emit opened()
37 */
38 bool LightApp_DataModel::open( const QString&, CAM_Study* study, QStringList )
39 {
40   emit opened(); //TODO: is it really needed? to be removed maybe...
41   return true;
42 }
43
44 /*!
45   Emit saved()
46 */
47 bool LightApp_DataModel::save( QStringList& )
48 {
49   emit saved();
50   return true;
51 }
52
53 /*!
54   Emit saved()
55 */
56 bool LightApp_DataModel::saveAs( const QString&, CAM_Study*, QStringList& )
57 {
58   emit saved();
59   return true;
60 }
61
62 /*!
63   Emit closed()
64 */
65 bool LightApp_DataModel::close()
66 {
67   emit closed();
68   return true;
69 }
70
71 /*!
72   Build whole data model tree
73 */
74 void LightApp_DataModel::build()
75 {
76 }
77
78 /*!
79   Updates data model presentation in some widgets (for example, in object browser
80 */
81 void LightApp_DataModel::updateWidgets()
82 {
83   LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
84   if( app )
85     app->objectBrowser()->updateTree( 0, false );
86 }
87
88 /*!
89   Default behaviour of data model update for light modules
90 */
91 void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* )
92 {
93   LightApp_ModuleObject* modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
94   DataObjectList ch;
95   if( modelRoot )
96   {
97     ch = modelRoot->children();
98     for ( DataObjectListIterator it( ch ); it.current(); ++it )
99       it.current()->setParent( 0 );
100   }
101   build();
102   updateWidgets();
103   for( DataObjectListIterator it( ch ); it.current(); ++it )
104     delete it.current();
105 }
106
107 /*!
108   \return corresponding module 
109 */
110 LightApp_Module* LightApp_DataModel::getModule() const
111 {
112   return dynamic_cast<LightApp_Module*>( module() );
113 }
114
115 /*!
116   \return corresponding  study
117 */
118 LightApp_Study* LightApp_DataModel::getStudy() const
119 {
120   LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root()->root() );
121   if ( !aRoot )
122     return 0;
123   return aRoot->study();
124 }
125
126 /*!
127   default implementation, always returns false so as not to mask study's isModified()
128 */
129 bool LightApp_DataModel::isModified() const
130 {
131   return false;
132 }
133
134 /*!
135   default implementation, always returns true so as not to mask study's isSaved()
136 */
137 bool LightApp_DataModel::isSaved() const
138 {
139   return true;
140 }