Salome HOME
af08c48fd0d23ab1fe601447a8c084a49e278dd5
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_Operation.cpp
5  *
6  *  Created on: Apr 2, 2014
7  *      Author: sbh
8  */
9
10 #include "ModuleBase_Operation.h"
11
12 #include "ModuleBase_OperationDescription.h"
13 #include "ModuleBase_ModelWidget.h"
14 #include "ModuleBase_ViewerPrs.h"
15 #include "ModuleBase_IPropertyPanel.h"
16 #include "ModuleBase_ISelection.h"
17 #include "ModuleBase_IViewer.h"
18
19 #include <ModelAPI_AttributeDouble.h>
20 #include <ModelAPI_Document.h>
21 #include <ModelAPI_Feature.h>
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Document.h>
24 #include <ModelAPI_Events.h>
25 #include <ModelAPI_Result.h>
26 #include <ModelAPI_Object.h>
27 #include <ModelAPI_Validator.h>
28 #include <ModelAPI_Session.h>
29
30 #include <GeomAPI_Pnt2d.h>
31
32 #include <Events_Loop.h>
33
34 #include <QTimer>
35
36 #ifdef _DEBUG
37 #include <QDebug>
38 #endif
39
40 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
41     : QObject(theParent),
42       myIsModified(false),
43       myPropertyPanel(NULL)
44 {
45   myDescription = new ModuleBase_OperationDescription(theId);
46 }
47
48 ModuleBase_Operation::~ModuleBase_Operation()
49 {
50   delete myDescription;
51 }
52
53 const QStringList& ModuleBase_Operation::grantedOperationIds() const
54 {
55   return myGrantedIds;
56 }
57
58 void ModuleBase_Operation::setGrantedOperationIds(const QStringList& theList)
59 {
60   myGrantedIds = theList;
61 }
62
63 QString ModuleBase_Operation::id() const
64 {
65   return getDescription()->operationId();
66 }
67
68 bool ModuleBase_Operation::isValid() const
69 {
70   return true;
71 }
72
73 bool ModuleBase_Operation::canBeCommitted() const
74 {
75   return isValid();
76 }
77
78 bool ModuleBase_Operation::start()
79 {
80   myIsModified = false;
81
82   ModelAPI_Session::get()->startOperation(id().toStdString());
83
84   startOperation();
85   emit started();
86
87   return true;
88 }
89
90 void ModuleBase_Operation::postpone()
91 {
92   postponeOperation();
93   emit postponed();
94 }
95
96 void ModuleBase_Operation::resume()
97 {
98   resumeOperation();
99   emit resumed();
100 }
101
102 void ModuleBase_Operation::abort()
103 {
104   // the viewer update should be blocked in order to avoid the features blinking before they are
105   // hidden
106   //std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
107   //    new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
108   //Events_Loop::loop()->send(aMsg);
109
110   ModelAPI_Session::get()->abortOperation();
111
112   emit stopped();
113   // the viewer update should be unblocked in order to avoid the features blinking before they are
114   // hidden
115   //aMsg = std::shared_ptr<Events_Message>(
116   //              new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
117   //Events_Loop::loop()->send(aMsg);
118
119   emit aborted();
120 }
121
122 bool ModuleBase_Operation::commit()
123 {
124   if (canBeCommitted()) {
125     SessionPtr aMgr = ModelAPI_Session::get();
126
127     commitOperation();
128     aMgr->finishOperation();
129
130     stopOperation();
131     emit stopped();
132     emit committed();
133
134     afterCommitOperation();
135     return true;
136   }
137   return false;
138 }
139
140 void ModuleBase_Operation::onValuesChanged()
141 {
142   myIsModified = true;
143 }
144
145 void ModuleBase_Operation::onValueStateChanged(int thePreviousState)
146 {
147   if (propertyPanel()) {
148     ModuleBase_ModelWidget* aWidget = propertyPanel()->activeWidget();
149     if (aWidget) {
150       if (aWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP)
151         myIsModified = true;
152     }
153   }
154 }
155
156 void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) 
157
158   myPropertyPanel = theProp; 
159 }
160
161 bool ModuleBase_Operation::isGranted(QString theId) const
162 {
163   return myGrantedIds.contains(theId);
164 }