Salome HOME
New item (FontItem), allowing to show information about font setting and to select...
[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(bool permanently)
66 {
67 }
68
69 void SUIT_Study::createDocument()
70 {
71   /*! Custom document initialization to be performed \n
72    *  within onNewDoc() handler can be put here
73    */
74 }
75
76 bool SUIT_Study::openDocument( const QString& fileName )
77 {
78   myName = fileName;
79   myIsSaved = true;
80   myIsModified = false;
81
82   return true;
83 }
84
85 bool SUIT_Study::saveDocumentAs( const QString& fileName )
86 {
87   myName = fileName;
88   myIsSaved = true;
89   myIsModified = false;
90
91   return true;
92 }
93
94 bool SUIT_Study::saveDocument()
95 {
96   return saveDocumentAs( myName );
97 }
98
99 void SUIT_Study::abortAllOperations()
100 {
101   SUIT_Operation* aOperation = 0;
102   while ( aOperation = myOperations.current() )
103   {
104     aOperation->abort();
105     myOperations.pop();
106   }
107 }
108
109 void SUIT_Study::update()
110 {
111 }
112
113 void SUIT_Study::sendChangesNotification()
114 {
115   emit studyModified( this );
116 }
117
118 void SUIT_Study::setIsSaved( const bool on )
119 {
120   myIsSaved = on;
121 }
122
123 void SUIT_Study::setIsModified( const bool on )
124 {
125   myIsModified = on;
126 }
127
128 void SUIT_Study::setRoot( SUIT_DataObject* obj )
129 {
130   if ( myRoot == obj )
131     return;
132
133   delete myRoot;
134   myRoot = obj;
135 }
136
137 void SUIT_Study::setStudyName( const QString& name )
138 {
139   myName = name;
140 }
141
142 void SUIT_Study::stopOperation()
143 {
144   myOperations.pop();
145   if ( myOperations.current() )
146     myOperations.current()->resume();
147   myIsModified = true;
148 }
149
150 bool SUIT_Study::canStartOperation( SUIT_Operation* theOperation )
151 {
152   SUIT_Operation* anActiveOperation = (SUIT_Operation*)activeOperation();
153   if ( anActiveOperation )
154   {
155     if ( !theOperation->isGranted() )
156     {
157       if ( !anActiveOperation->isValid( theOperation ) )
158       {
159         // Ask user about existing operation
160         int anAnsw = SUIT_MessageBox::warn2( application()->desktop(), tr( "Operation launch" ), 
161                                              tr( "Previous operation is not finished and will be aborted." ),
162                                              tr( "Continue" ), tr( "Cancel" ), 0, 1, 1 );
163         if ( anAnsw == 1 )
164           return false;
165
166         anActiveOperation->abort();
167         myOperations.pop();
168         myOperations.push( theOperation );
169         return true;
170       }
171     }
172     anActiveOperation->suspend();
173   }
174   myOperations.push( theOperation );
175
176   return true;
177 }