Salome HOME
SUIT_Selector class now inherits QObject in order to simplify selectors deleting...
[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 SUIT_Study::SUIT_Study( SUIT_Application* app )
10 : QObject(),
11 myApp( app ),
12 myIsSaved( false ),
13 myIsModified( false ),
14 myName( "" )
15 {
16   static int _id = 0;
17
18   myId = ++_id;
19
20   myRoot = new SUIT_DataObject();
21   myOperations.setAutoDelete( false );
22 }
23
24 SUIT_Study::~SUIT_Study()
25 {
26   delete myRoot;
27   myRoot = 0;
28 }
29
30 int SUIT_Study::id() const
31 {
32   return myId;
33 }
34
35 SUIT_DataObject* SUIT_Study::root() const
36 {
37   return myRoot;
38 }
39
40 SUIT_Application* SUIT_Study::application() const
41 {
42   return myApp;
43 }
44
45 QString SUIT_Study::studyName() const
46 {
47   return myName;
48 }
49
50 SUIT_Operation* SUIT_Study::activeOperation() const
51 {
52   return myOperations.current();
53 }
54
55 bool SUIT_Study::isSaved() const
56 {
57   return myIsSaved;
58 }
59
60 bool SUIT_Study::isModified() const
61 {
62   return myIsModified;
63 }
64
65 void SUIT_Study::closeDocument()
66 {
67 }
68
69 void SUIT_Study::createDocument()
70 {
71   // Custom document initialization to be performed
72   // within onNewDoc() handler can be put here
73 }
74
75 bool SUIT_Study::openDocument( const QString& fileName )
76 {
77   myName = fileName;
78   myIsSaved = true;
79   myIsModified = false;
80
81   return true;
82 }
83
84 bool SUIT_Study::saveDocumentAs( const QString& fileName )
85 {
86   myName = fileName;
87   myIsSaved = true;
88   myIsModified = false;
89
90   return true;
91 }
92
93 bool SUIT_Study::saveDocument()
94 {
95   return saveDocumentAs( myName );
96 }
97
98 void SUIT_Study::abortAllOperations()
99 {
100   SUIT_Operation* aOperation = 0;
101   while ( aOperation = myOperations.current() )
102   {
103     aOperation->abort();
104     myOperations.pop();
105   }
106 }
107
108 void SUIT_Study::update()
109 {
110 }
111
112 void SUIT_Study::sendChangesNotification()
113 {
114   emit studyModified( this );
115 }
116
117 void SUIT_Study::setIsSaved( const bool on )
118 {
119   myIsSaved = on;
120 }
121
122 void SUIT_Study::setIsModified( const bool on )
123 {
124   myIsModified = on;
125 }
126
127 void SUIT_Study::setRoot( SUIT_DataObject* obj )
128 {
129   if ( myRoot == obj )
130     return;
131
132   delete myRoot;
133   myRoot = obj;
134 }
135
136 void SUIT_Study::setStudyName( const QString& name )
137 {
138   myName = name;
139 }
140
141 void SUIT_Study::stopOperation()
142 {
143   myOperations.pop();
144   if ( myOperations.current() )
145     myOperations.current()->resume();
146   myIsModified = true;
147 }
148
149 bool SUIT_Study::canStartOperation( SUIT_Operation* theOperation )
150 {
151   SUIT_Operation* anActiveOperation = (SUIT_Operation*)activeOperation();
152   if ( anActiveOperation )
153   {
154     if ( !theOperation->isGranted() )
155     {
156       if ( !anActiveOperation->isValid( theOperation ) )
157       {
158         // Ask user about existing operation
159         int anAnsw = SUIT_MessageBox::warn2( application()->desktop(), tr( "Operation launch" ), 
160                                              tr( "Previous operation is not finished and will be aborted." ),
161                                              tr( "Continue" ), tr( "Cancel" ), 0, 1, 1 );
162         if ( anAnsw == 1 )
163           return false;
164
165         anActiveOperation->abort();
166         myOperations.pop();
167         myOperations.push( theOperation );
168         return true;
169       }
170     }
171     anActiveOperation->suspend();
172   }
173   myOperations.push( theOperation );
174
175   return true;
176 }