Salome HOME
Fix pb with Object Browser update, when several not-loaded components have data....
[modules/gui.git] / src / SUIT / SUIT_Study.cxx
1 #include "SUIT_Study.h"
2
3 #include "SUIT_Desktop.h"
4 #include "SUIT_Operation.h"
5 #include "SUIT_DataObject.h"
6 #include "SUIT_MessageBox.h"
7 #include "SUIT_Application.h"
8
9 /*!\class SUIT_Study
10  * Support study management. Object management. Operation management.
11  */
12
13 /*!Constructor.*/
14 SUIT_Study::SUIT_Study( SUIT_Application* app )
15 : QObject(),
16 myApp( app ),
17 myIsSaved( false ),
18 myIsModified( false ),
19 myName( "" )
20 {
21   static int _id = 0;
22
23   myId = ++_id;
24
25   myRoot = new SUIT_DataObject();
26   myOperations.setAutoDelete( false );
27 }
28
29 /*!Destructor.*/
30 SUIT_Study::~SUIT_Study()
31 {
32   delete myRoot;
33   myRoot = 0;
34 }
35
36 /*!
37  *\retval study id.
38  */
39 int SUIT_Study::id() const
40 {
41   return myId;
42 }
43
44 /*!
45  *\retval root data object.
46  */
47 SUIT_DataObject* SUIT_Study::root() const
48 {
49   return myRoot;
50 }
51
52 /*!
53  *\retval Application.
54  */
55 SUIT_Application* SUIT_Study::application() const
56 {
57   return myApp;
58 }
59
60 /*!
61  *\retval study name
62  */
63 QString SUIT_Study::studyName() const
64 {
65   return myName;
66 }
67
68 /*!
69  *\retval active operation.
70  */
71 SUIT_Operation* SUIT_Study::activeOperation() const
72 {
73   return myOperations.current();
74 }
75
76 /*!
77  *\retval TRUE - if study saved, else FALSE.
78  */
79 bool SUIT_Study::isSaved() const
80 {
81   return myIsSaved;
82 }
83
84 /*!
85  *\retval TRUE - if study modified, else FALSE.
86  */
87 bool SUIT_Study::isModified() const
88 {
89   return myIsModified;
90 }
91
92 /*!
93  *Close document. NOT IMPLEMENTED.
94  */
95 void SUIT_Study::closeDocument(bool permanently)
96 {
97 }
98
99 void SUIT_Study::createDocument()
100 {
101   /*! Custom document initialization to be performed \n
102    *  within onNewDoc() handler can be put here
103    */
104 }
105
106 /*!
107  * Open document. Sets file name. return true.
108  */
109 bool SUIT_Study::openDocument( const QString& fileName )
110 {
111   myName = fileName;
112   myIsSaved = true;
113   myIsModified = false;
114
115   return true;
116 }
117
118 /*!
119  * Save document as \a fileName. Set file name.
120  */
121 bool SUIT_Study::saveDocumentAs( const QString& fileName )
122 {
123   myName = fileName;
124   myIsSaved = true;
125   myIsModified = false;
126
127   return true;
128 }
129
130 /*!
131  *\retval TRUE - if document saved successful, else FALSE.
132  */
133 bool SUIT_Study::saveDocument()
134 {
135   return saveDocumentAs( myName );
136 }
137
138 /*!
139  *Abort all operations.
140  */
141 void SUIT_Study::abortAllOperations()
142 {
143   SUIT_Operation* aOperation = 0;
144   while ( aOperation = myOperations.current() )
145   {
146     aOperation->abort();
147     myOperations.pop();
148   }
149 }
150
151 /*!
152   Update study. NOT IMPLEMENTED HERE.
153  */
154 void SUIT_Study::update()
155 {
156 }
157
158 /*!
159   Emit study modified.
160  */
161 void SUIT_Study::sendChangesNotification()
162 {
163   emit studyModified( this );
164 }
165
166 /*!
167   Set study saved to \a on.
168  */
169 void SUIT_Study::setIsSaved( const bool on )
170 {
171   myIsSaved = on;
172 }
173
174 /*!
175   Set study modified to \a on.
176  */
177 void SUIT_Study::setIsModified( const bool on )
178 {
179   myIsModified = on;
180 }
181
182 /*!
183   Set root object.
184  */
185 void SUIT_Study::setRoot( SUIT_DataObject* obj )
186 {
187   if ( myRoot == obj )
188     return;
189
190   delete myRoot;
191   myRoot = obj;
192 }
193
194 /*!
195   Set study name.
196  */
197 void SUIT_Study::setStudyName( const QString& name )
198 {
199   myName = name;
200 }
201
202 /*!
203   Stop operation.
204  */
205 void SUIT_Study::stopOperation()
206 {
207   myOperations.pop();
208   if ( myOperations.current() )
209     myOperations.current()->resume();
210   myIsModified = true;
211 }
212
213 /*!
214  * Set can start operation \a theOperation.
215  *\retval FALSE - if can't start.
216  */
217 bool SUIT_Study::canStartOperation( SUIT_Operation* theOperation )
218 {
219   SUIT_Operation* anActiveOperation = (SUIT_Operation*)activeOperation();
220   if ( anActiveOperation )
221   {
222     if ( !theOperation->isGranted() )
223     {
224       if ( !anActiveOperation->isValid( theOperation ) )
225       {
226         // Ask user about existing operation
227         int anAnsw = SUIT_MessageBox::warn2( application()->desktop(), tr( "Operation launch" ), 
228                                              tr( "Previous operation is not finished and will be aborted." ),
229                                              tr( "Continue" ), tr( "Cancel" ), 0, 1, 1 );
230         if ( anAnsw == 1 )
231           return false;
232
233         anActiveOperation->abort();
234         myOperations.pop();
235         myOperations.push( theOperation );
236         return true;
237       }
238     }
239     anActiveOperation->suspend();
240   }
241   myOperations.push( theOperation );
242
243   return true;
244 }