1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_Operation.cpp
6 * Created on: Apr 2, 2014
10 #include "ModuleBase_Operation.h"
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"
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>
30 #include <GeomAPI_Pnt2d.h>
32 #include <Events_Loop.h>
40 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
45 myDescription = new ModuleBase_OperationDescription(theId);
48 ModuleBase_Operation::~ModuleBase_Operation()
53 QString ModuleBase_Operation::id() const
55 return getDescription()->operationId();
58 bool ModuleBase_Operation::isValid() const
63 bool ModuleBase_Operation::canBeCommitted() const
69 void ModuleBase_Operation::start()
73 QString anId = getDescription()->operationId();
75 anId = anId.append(EditSuffix());
77 ModelAPI_Session::get()->startOperation(anId.toStdString());
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
90 /// Set current feature and remeber old current feature
92 SessionPtr aMgr = ModelAPI_Session::get();
93 DocumentPtr aDoc = aMgr->activeDocument();
94 myCurrentFeature = aDoc->currentFeature(true);
95 aDoc->setCurrentFeature(feature(), false);
103 void ModuleBase_Operation::postpone()
109 void ModuleBase_Operation::resume()
115 void ModuleBase_Operation::abort()
118 // the viewer update should be blocked in order to avoid the features blinking before they are
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);
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
130 myPropertyPanel->cleanContent();
132 SessionPtr aMgr = ModelAPI_Session::get();
134 DocumentPtr aDoc = aMgr->activeDocument();
135 bool aIsOp = aMgr->isOperation();
137 aMgr->startOperation();
138 aDoc->setCurrentFeature(myCurrentFeature, true);
140 aMgr->finishOperation();
141 myCurrentFeature = FeaturePtr();
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();
150 aMgr->abortOperation();
152 // the viewer update should be unblocked in order to avoid the features blinking before they are
154 aMsg = std::shared_ptr<Events_Message>(
155 new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
157 Events_Loop::loop()->send(aMsg);
163 bool ModuleBase_Operation::commit()
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
172 myPropertyPanel->cleanContent();
174 SessionPtr aMgr = ModelAPI_Session::get();
175 /// Set current feature and remeber old current feature
177 DocumentPtr aDoc = aMgr->activeDocument();
178 bool aIsOp = aMgr->isOperation();
180 aMgr->startOperation();
181 aDoc->setCurrentFeature(myCurrentFeature, true);
183 aMgr->finishOperation();
184 myCurrentFeature = FeaturePtr();
187 aMgr->finishOperation();
193 afterCommitOperation();
200 void ModuleBase_Operation::onValuesChanged()
205 void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp)
207 myPropertyPanel = theProp;
210 bool ModuleBase_Operation::isGranted(QString theId) const