]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_IOperation.cpp
Salome HOME
Issue #83: renamed PluginManager to Session
[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_Session.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 /*void ModuleBase_IOperation::setModelWidgets(const std::string& theXmlRepresentation,
43  QList<ModuleBase_ModelWidget*> theWidgets)
44  {
45  QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end();
46  for (; anIt != aLast; anIt++) {
47  QObject::connect(*anIt, SIGNAL(valuesChanged()),  this, SLOT(storeCustomValue()));
48  }
49  getDescription()->setModelWidgets(theXmlRepresentation, theWidgets);
50  }*/
51
52 boost::shared_ptr<ModelAPI_Document> ModuleBase_IOperation::document() const
53 {
54   return ModelAPI_Session::get()->rootDocument();
55 }
56
57 void ModuleBase_IOperation::start()
58 {
59   document()->startOperation();
60
61   startOperation();
62   emit started();
63 }
64
65 void ModuleBase_IOperation::resume()
66 {
67   emit resumed();
68 }
69
70 void ModuleBase_IOperation::abort()
71 {
72   abortOperation();
73   emit aborted();
74
75   stopOperation();
76
77   document()->abortOperation();
78   emit stopped();
79 }
80
81 bool ModuleBase_IOperation::commit()
82 {
83   if (canBeCommitted()) {
84     commitOperation();
85     emit committed();
86
87     stopOperation();
88
89     document()->finishOperation();
90     emit stopped();
91
92     afterCommitOperation();
93     return true;
94   }
95   return false;
96 }
97
98 void ModuleBase_IOperation::setRunning(bool theState)
99 {
100   if (!theState) {
101     abort();
102   }
103 }