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