1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ModuleBase_Operation.h"
22 #include "ModuleBase_OperationDescription.h"
23 #include "ModuleBase_ModelWidget.h"
24 #include "ModuleBase_ViewerPrs.h"
25 #include "ModuleBase_IPropertyPanel.h"
26 #include "ModuleBase_ISelection.h"
27 #include "ModuleBase_IViewer.h"
29 #include <ModelAPI_AttributeDouble.h>
30 #include <ModelAPI_Document.h>
31 #include <ModelAPI_Feature.h>
32 #include <ModelAPI_Data.h>
33 #include <ModelAPI_Document.h>
34 #include <ModelAPI_Events.h>
35 #include <ModelAPI_Result.h>
36 #include <ModelAPI_Object.h>
37 #include <ModelAPI_Validator.h>
38 #include <ModelAPI_Session.h>
40 #include <GeomAPI_Pnt2d.h>
42 #include <Events_Loop.h>
43 #include <Config_WidgetAPI.h>
44 #include <Config_Keywords.h>
52 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
55 myPropertyPanel(NULL),
56 myHideFacesVisibilityState(false)
58 myDescription = new ModuleBase_OperationDescription(theId);
61 ModuleBase_Operation::~ModuleBase_Operation()
66 const QStringList& ModuleBase_Operation::grantedOperationIds() const
71 void ModuleBase_Operation::setGrantedOperationIds(const QStringList& theList)
73 myGrantedIds = theList;
76 QString ModuleBase_Operation::id() const
78 return getDescription()->operationId();
81 bool ModuleBase_Operation::isValid() const
86 bool ModuleBase_Operation::canBeCommitted() const
91 bool ModuleBase_Operation::start()
95 ModelAPI_Session::get()->startOperation(id().toStdString());
103 void ModuleBase_Operation::postpone()
109 void ModuleBase_Operation::resume()
115 void ModuleBase_Operation::abort()
117 // the viewer update should be blocked in order to avoid the features blinking before they are
119 //std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
120 // new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
121 //Events_Loop::loop()->send(aMsg);
123 ModelAPI_Session::get()->abortOperation();
126 // the viewer update should be unblocked in order to avoid the features blinking before they are
128 //aMsg = std::shared_ptr<Events_Message>(
129 // new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
130 //Events_Loop::loop()->send(aMsg);
135 bool ModuleBase_Operation::commit()
137 if (canBeCommitted()) {
138 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
140 aPanel->onAcceptData();
142 SessionPtr aMgr = ModelAPI_Session::get();
145 aMgr->finishOperation();
151 afterCommitOperation();
157 void ModuleBase_Operation::onValuesChanged()
162 void ModuleBase_Operation::onValueStateChanged(int thePreviousState)
164 if (propertyPanel()) {
165 ModuleBase_ModelWidget* aWidget = propertyPanel()->activeWidget();
167 if (aWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP)
173 void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp)
175 myPropertyPanel = theProp;
178 bool ModuleBase_Operation::isGranted(QString theId) const
180 return myGrantedIds.contains(theId);
183 bool ModuleBase_Operation::isModified() const
185 if (myDescription->hasXmlRepresentation()) {
186 Config_WidgetAPI aWidgetApi(myDescription->xmlRepresentation().toStdString());
187 if (!aWidgetApi.getBooleanAttribute(ABORT_CONFIRMATION, true))
190 //if (myPropertyPanel)
191 // return myPropertyPanel->isModified();
193 // Most of operation causes creation of a feature