Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / ModuleBase / ModuleBase_IOperation.cpp
1 /*
2  * ModuleBase_IOperation.cpp
3  *
4  *  Created on: May 5, 2014
5  *      Author: nds
6  */
7
8 #include "ModuleBase_IOperation.h"
9 #include "ModuleBase_OperationDescription.h"
10
11 #include <ModelAPI_Document.h>
12 #include <ModelAPI_PluginManager.h>
13
14 #ifdef _DEBUG
15 #include <QDebug>
16 #endif
17
18 ModuleBase_IOperation::ModuleBase_IOperation(const QString& theId, QObject* theParent)
19  : QObject(theParent)
20 {
21   myDescription = new ModuleBase_OperationDescription(theId);
22 }
23
24 ModuleBase_IOperation::~ModuleBase_IOperation()
25 {
26   delete myDescription;
27 }
28
29 ModuleBase_OperationDescription* ModuleBase_IOperation::getDescription() const
30 {
31   return myDescription;
32 }
33
34 bool ModuleBase_IOperation::canBeCommitted() const
35 {
36   return true;
37 }
38
39 bool ModuleBase_IOperation::isGranted(ModuleBase_IOperation* /*theOperation*/) const
40 {
41   return false;
42 }
43
44 boost::shared_ptr<ModelAPI_Document> ModuleBase_IOperation::document() const
45 {
46   return ModelAPI_PluginManager::get()->rootDocument();
47 }
48
49 void ModuleBase_IOperation::start()
50 {
51   document()->startOperation();
52
53   startOperation();
54   emit started();
55 }
56
57 void ModuleBase_IOperation::resume()
58 {
59   emit resumed();
60 }
61
62 void ModuleBase_IOperation::abort()
63 {
64   abortOperation();
65   emit aborted();
66
67   stopOperation();
68
69   document()->abortOperation();
70   emit stopped();
71 }
72
73 void ModuleBase_IOperation::commit()
74 {
75   commitOperation();
76   emit committed();
77
78   stopOperation();
79
80   document()->finishOperation();
81   emit stopped();
82   
83   afterCommitOperation();
84 }
85
86 void ModuleBase_IOperation::setRunning(bool theState)
87 {
88   if (!theState) {
89     abort();
90   }
91 }