]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Operation.cpp
Salome HOME
Providing Action class to have a common approach to start/finish/abort model transact...
[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 QString ModuleBase_Operation::id() const
54 {
55   return getDescription()->operationId();
56 }
57
58 bool ModuleBase_Operation::isValid() const
59 {
60   return true;
61 }
62
63 bool ModuleBase_Operation::canBeCommitted() const
64 {
65   return isValid();
66 }
67
68
69 void ModuleBase_Operation::start()
70 {
71   myIsModified = false;
72   /*
73   QString anId = getDescription()->operationId();
74   if (myIsEditing) {
75     anId = anId.append(EditSuffix());
76   }
77   ModelAPI_Session::get()->startOperation(anId.toStdString());
78
79   if (!myIsEditing) {
80     FeaturePtr aFeature = createFeature();
81     // if the feature is not created, there is no sense to start the operation
82     if (aFeature.get() == NULL) {
83       // it is necessary to abor the operation in the session and emit the aborted signal
84       // in order to update commands status in the workshop, to be exact the feature action
85       // to be unchecked
86       abort();
87       return;
88     }
89   }
90   /// Set current feature and remeber old current feature
91   if (myIsEditing) {
92     SessionPtr aMgr = ModelAPI_Session::get();
93     DocumentPtr aDoc = aMgr->activeDocument();
94     myCurrentFeature = aDoc->currentFeature(true);
95     aDoc->setCurrentFeature(feature(), false);
96   }
97
98   startOperation();
99   emit started();
100 */
101 }
102
103 void ModuleBase_Operation::postpone()
104 {
105   postponeOperation();
106   emit postponed();
107 }
108
109 void ModuleBase_Operation::resume()
110 {
111   resumeOperation();
112   emit resumed();
113 }
114
115 void ModuleBase_Operation::abort()
116 {
117 /*
118   // the viewer update should be blocked in order to avoid the features blinking before they are
119   // hidden
120   std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
121       new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
122   Events_Loop::loop()->send(aMsg);
123
124   // the widgets of property panel should not process any events come from data mode
125   // after abort clicked. Some signal such as redisplay/create influence on content
126   // of the object browser and viewer context. Therefore it influence to the current
127   // selection and if the active widget listens it, the attribute value is errnoneous
128   // changed.
129   if (myPropertyPanel)
130     myPropertyPanel->cleanContent();
131
132   SessionPtr aMgr = ModelAPI_Session::get();
133   if (myIsEditing) {
134     DocumentPtr aDoc = aMgr->activeDocument();
135     bool aIsOp = aMgr->isOperation();
136     if (!aIsOp)
137       aMgr->startOperation();
138     aDoc->setCurrentFeature(myCurrentFeature, true);
139     if (!aIsOp)
140       aMgr->finishOperation();
141     myCurrentFeature = FeaturePtr();
142   }
143   abortOperation();
144
145   stopOperation();
146   // is is necessary to deactivate current widgets before the model operation is aborted
147   // because abort removes the feature and activated filters should not check it
148   propertyPanel()->cleanContent();
149
150   aMgr->abortOperation();
151   emit stopped();
152   // the viewer update should be unblocked in order to avoid the features blinking before they are
153   // hidden
154   aMsg = std::shared_ptr<Events_Message>(
155                 new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
156
157   Events_Loop::loop()->send(aMsg);
158
159   emit aborted();
160 */
161 }
162
163 bool ModuleBase_Operation::commit()
164 {
165 /*  if (canBeCommitted()) {
166     // the widgets of property panel should not process any events come from data mode
167     // after commit clicked. Some signal such as redisplay/create influence on content
168     // of the object browser and viewer context. Therefore it influence to the current
169     // selection and if the active widget listens it, the attribute value is errnoneous
170     // changed.
171     if (myPropertyPanel)
172       myPropertyPanel->cleanContent();
173
174     SessionPtr aMgr = ModelAPI_Session::get();
175     /// Set current feature and remeber old current feature
176     if (myIsEditing) {
177       DocumentPtr aDoc = aMgr->activeDocument();
178       bool aIsOp = aMgr->isOperation();
179       if (!aIsOp)
180         aMgr->startOperation();
181       aDoc->setCurrentFeature(myCurrentFeature, true);
182       if (!aIsOp)
183         aMgr->finishOperation();
184       myCurrentFeature = FeaturePtr();
185     }
186     commitOperation();
187     aMgr->finishOperation();
188
189     stopOperation();
190     emit stopped();
191     emit committed();
192
193     afterCommitOperation();
194     return true;
195   }
196 */
197   return false;
198 }
199
200 void ModuleBase_Operation::onValuesChanged()
201 {
202   myIsModified = true;
203 }
204
205 void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) 
206
207   myPropertyPanel = theProp; 
208 }
209
210 bool ModuleBase_Operation::isGranted(QString theId) const
211 {
212   return false;
213 }