Salome HOME
Merge remote-tracking branch 'remotes/origin/HigherLevelObjectsHistory'
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.cpp
index 4d54780f9941acda1717d3030d28b48f4efad6b7..b4f4a38b05296e9a20a94d30cabc41198ee4a188 100644 (file)
@@ -1,11 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-/*
- * ModuleBase_Operation.cpp
- *
- *  Created on: Apr 2, 2014
- *      Author: sbh
- */
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include "ModuleBase_Operation.h"
 
@@ -50,6 +60,16 @@ ModuleBase_Operation::~ModuleBase_Operation()
   delete myDescription;
 }
 
+const QStringList& ModuleBase_Operation::grantedOperationIds() const
+{
+  return myGrantedIds;
+}
+
+void ModuleBase_Operation::setGrantedOperationIds(const QStringList& theList)
+{
+  myGrantedIds = theList;
+}
+
 QString ModuleBase_Operation::id() const
 {
   return getDescription()->operationId();
@@ -65,39 +85,16 @@ bool ModuleBase_Operation::canBeCommitted() const
   return isValid();
 }
 
-
-void ModuleBase_Operation::start()
+bool ModuleBase_Operation::start()
 {
   myIsModified = false;
-  /*
-  QString anId = getDescription()->operationId();
-  if (myIsEditing) {
-    anId = anId.append(EditSuffix());
-  }
-  ModelAPI_Session::get()->startOperation(anId.toStdString());
-
-  if (!myIsEditing) {
-    FeaturePtr aFeature = createFeature();
-    // if the feature is not created, there is no sense to start the operation
-    if (aFeature.get() == NULL) {
-      // it is necessary to abor the operation in the session and emit the aborted signal
-      // in order to update commands status in the workshop, to be exact the feature action
-      // to be unchecked
-      abort();
-      return;
-    }
-  }
-  /// Set current feature and remeber old current feature
-  if (myIsEditing) {
-    SessionPtr aMgr = ModelAPI_Session::get();
-    DocumentPtr aDoc = aMgr->activeDocument();
-    myCurrentFeature = aDoc->currentFeature(true);
-    aDoc->setCurrentFeature(feature(), false);
-  }
+
+  ModelAPI_Session::get()->startOperation(id().toStdString());
 
   startOperation();
   emit started();
-*/
+
+  return true;
 }
 
 void ModuleBase_Operation::postpone()
@@ -114,75 +111,33 @@ void ModuleBase_Operation::resume()
 
 void ModuleBase_Operation::abort()
 {
-/*
   // the viewer update should be blocked in order to avoid the features blinking before they are
   // hidden
-  std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
-      new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
-  Events_Loop::loop()->send(aMsg);
-
-  // the widgets of property panel should not process any events come from data mode
-  // after abort clicked. Some signal such as redisplay/create influence on content
-  // of the object browser and viewer context. Therefore it influence to the current
-  // selection and if the active widget listens it, the attribute value is errnoneous
-  // changed.
-  if (myPropertyPanel)
-    myPropertyPanel->cleanContent();
-
-  SessionPtr aMgr = ModelAPI_Session::get();
-  if (myIsEditing) {
-    DocumentPtr aDoc = aMgr->activeDocument();
-    bool aIsOp = aMgr->isOperation();
-    if (!aIsOp)
-      aMgr->startOperation();
-    aDoc->setCurrentFeature(myCurrentFeature, true);
-    if (!aIsOp)
-      aMgr->finishOperation();
-    myCurrentFeature = FeaturePtr();
-  }
-  abortOperation();
+  //std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
+  //    new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
+  //Events_Loop::loop()->send(aMsg);
 
-  stopOperation();
-  // is is necessary to deactivate current widgets before the model operation is aborted
-  // because abort removes the feature and activated filters should not check it
-  propertyPanel()->cleanContent();
+  ModelAPI_Session::get()->abortOperation();
 
-  aMgr->abortOperation();
   emit stopped();
   // the viewer update should be unblocked in order to avoid the features blinking before they are
   // hidden
-  aMsg = std::shared_ptr<Events_Message>(
-                new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
-
-  Events_Loop::loop()->send(aMsg);
+  //aMsg = std::shared_ptr<Events_Message>(
+  //              new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
+  //Events_Loop::loop()->send(aMsg);
 
   emit aborted();
-*/
 }
 
 bool ModuleBase_Operation::commit()
 {
-/*  if (canBeCommitted()) {
-    // the widgets of property panel should not process any events come from data mode
-    // after commit clicked. Some signal such as redisplay/create influence on content
-    // of the object browser and viewer context. Therefore it influence to the current
-    // selection and if the active widget listens it, the attribute value is errnoneous
-    // changed.
-    if (myPropertyPanel)
-      myPropertyPanel->cleanContent();
+  if (canBeCommitted()) {
+    ModuleBase_IPropertyPanel* aPanel = propertyPanel();
+    if (aPanel)
+      aPanel->onAcceptData();
 
     SessionPtr aMgr = ModelAPI_Session::get();
-    /// Set current feature and remeber old current feature
-    if (myIsEditing) {
-      DocumentPtr aDoc = aMgr->activeDocument();
-      bool aIsOp = aMgr->isOperation();
-      if (!aIsOp)
-        aMgr->startOperation();
-      aDoc->setCurrentFeature(myCurrentFeature, true);
-      if (!aIsOp)
-        aMgr->finishOperation();
-      myCurrentFeature = FeaturePtr();
-    }
+
     commitOperation();
     aMgr->finishOperation();
 
@@ -193,7 +148,6 @@ bool ModuleBase_Operation::commit()
     afterCommitOperation();
     return true;
   }
-*/
   return false;
 }
 
@@ -202,12 +156,23 @@ void ModuleBase_Operation::onValuesChanged()
   myIsModified = true;
 }
 
-void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) 
-{ 
-  myPropertyPanel = theProp; 
+void ModuleBase_Operation::onValueStateChanged(int thePreviousState)
+{
+  if (propertyPanel()) {
+    ModuleBase_ModelWidget* aWidget = propertyPanel()->activeWidget();
+    if (aWidget) {
+      if (aWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP)
+        myIsModified = true;
+    }
+  }
+}
+
+void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp)
+{
+  myPropertyPanel = theProp;
 }
 
 bool ModuleBase_Operation::isGranted(QString theId) const
 {
-  return false;
+  return myGrantedIds.contains(theId);
 }