Salome HOME
Restore default value
[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 #include "ModuleBase_ModelWidget.h"
11
12 #include <ModelAPI_Document.h>
13 #include <ModelAPI_PluginManager.h>
14
15 #ifdef _DEBUG
16 #include <QDebug>
17 #endif
18
19 ModuleBase_IOperation::ModuleBase_IOperation(const QString& theId, QObject* theParent)
20  : QObject(theParent)
21 {
22   myDescription = new ModuleBase_OperationDescription(theId);
23 }
24
25 ModuleBase_IOperation::~ModuleBase_IOperation()
26 {
27   delete myDescription;
28 }
29
30 ModuleBase_OperationDescription* ModuleBase_IOperation::getDescription() const
31 {
32   return myDescription;
33 }
34
35 bool ModuleBase_IOperation::canBeCommitted() const
36 {
37   return true;
38 }
39
40 bool ModuleBase_IOperation::isGranted(ModuleBase_IOperation* /*theOperation*/) const
41 {
42   return false;
43 }
44
45 /*void ModuleBase_IOperation::setModelWidgets(const std::string& theXmlRepresentation,
46                                             QList<ModuleBase_ModelWidget*> theWidgets)
47 {
48   QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end();
49   for (; anIt != aLast; anIt++) {
50     QObject::connect(*anIt, SIGNAL(valuesChanged()),  this, SLOT(storeCustomValue()));
51   }
52   getDescription()->setModelWidgets(theXmlRepresentation, theWidgets);
53 }*/
54
55 boost::shared_ptr<ModelAPI_Document> ModuleBase_IOperation::document() const
56 {
57   return ModelAPI_PluginManager::get()->rootDocument();
58 }
59
60 void ModuleBase_IOperation::start()
61 {
62   document()->startOperation();
63
64   startOperation();
65   emit started();
66 }
67
68 void ModuleBase_IOperation::resume()
69 {
70   emit resumed();
71 }
72
73 void ModuleBase_IOperation::abort()
74 {
75   abortOperation();
76   emit aborted();
77
78   stopOperation();
79
80   document()->abortOperation();
81   emit stopped();
82 }
83
84 void ModuleBase_IOperation::commit()
85 {
86   commitOperation();
87   emit committed();
88
89   stopOperation();
90
91   document()->finishOperation();
92   emit stopped();
93   
94   afterCommitOperation();
95 }
96
97 void ModuleBase_IOperation::setRunning(bool theState)
98 {
99   if (!theState) {
100     abort();
101   }
102 }