Salome HOME
#refs 77 - reported by Hervé Legrand: double click in 3D viewer leads to crash when...
[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::isGranted(ModuleBase_IOperation* /*theOperation*/) const
35 {
36   return false;
37 }
38
39 boost::shared_ptr<ModelAPI_Document> ModuleBase_IOperation::document() const
40 {
41   return ModelAPI_PluginManager::get()->rootDocument();
42 }
43
44 void ModuleBase_IOperation::start()
45 {
46   document()->startOperation();
47
48   startOperation();
49   emit started();
50 }
51
52 void ModuleBase_IOperation::resume()
53 {
54   emit resumed();
55 }
56
57 void ModuleBase_IOperation::abort()
58 {
59   abortOperation();
60   emit aborted();
61
62   stopOperation();
63
64   document()->abortOperation();
65   emit stopped();
66 }
67
68 void ModuleBase_IOperation::commit()
69 {
70   commitOperation();
71   emit committed();
72
73   stopOperation();
74
75   document()->finishOperation();
76   emit stopped();
77   
78   afterCommitOperation();
79 }
80
81 void ModuleBase_IOperation::setRunning(bool theState)
82 {
83   if (!theState) {
84     abort();
85   }
86 }