Salome HOME
Issue #2250 Fatal error or sigsegv when I use the "Echap" key: Escape processed by...
[modules/shaper.git] / src / ModuleBase / ModuleBase_OperationFeature.cpp
index 82cf7906b46389333501c75b28d77f7769f83750..5a37bdd6731d6686aa78351976076bc08984e74c 100755 (executable)
@@ -1,11 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-/*
- * ModuleBase_OperationFeature.cpp
- *
- *  Created on: Apr 2, 2014
- *      Author: sbh
- */
+// Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "ModuleBase_OperationFeature.h"
 
@@ -49,8 +60,7 @@
 #endif
 
 ModuleBase_OperationFeature::ModuleBase_OperationFeature(const QString& theId, QObject* theParent)
-: ModuleBase_Operation(theId, theParent),
-  myIsEditing(false)
+: ModuleBase_Operation(theId, theParent), myIsEditing(false), myNeedToBeAborted(false)
 {
 }
 
@@ -102,6 +112,7 @@ bool ModuleBase_OperationFeature::isValid() const
     return true;
 
   std::string anError = ModelAPI_Tools::getFeatureError(myFeature);
+  //ModuleBase_Tools::translate(myFeature->getKind(), anError);
   return anError.empty();
 }
 
@@ -116,7 +127,8 @@ void ModuleBase_OperationFeature::startOperation()
 
   myVisualizedObjects.clear();
   // store hidden result features
-  std::list<ResultPtr> aResults = aFeature->results();
+  std::list<ResultPtr> aResults;
+  ModelAPI_Tools::allResults(aFeature, aResults);
   std::list<ResultPtr>::const_iterator aIt;
   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
     ObjectPtr anObject = *aIt;
@@ -139,7 +151,8 @@ void ModuleBase_OperationFeature::stopOperation()
     return;
 
   // store hidden result features
-  std::list<ResultPtr> aResults = aFeature->results();
+  std::list<ResultPtr> aResults;
+  ModelAPI_Tools::allResults(aFeature, aResults);
   std::list<ResultPtr>::const_iterator aIt;
   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
     ObjectPtr anObject = *aIt;
@@ -193,24 +206,28 @@ bool ModuleBase_OperationFeature::hasObject(ObjectPtr theObj) const
   if (aFeature) {
     if (aFeature == theObj)
       return true;
-    std::list<ResultPtr> aResults = aFeature->results();
+    std::list<ResultPtr> aResults;
+    ModelAPI_Tools::allResults(aFeature, aResults);
     std::list<ResultPtr>::const_iterator aIt;
     for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
-      if (theObj == (*aIt))
-        return true;
+      ResultPtr aResult = *aIt;
+      if (theObj == aResult)
+         return true;
     }
 #ifdef DEBUG_DO_NOT_ACTIVATE_SUB_FEATURE
     if (aFeature->isMacro()) {
-      // macro feature may refers to sub-features, which also should be deactivated when the operation
+      // macro feature may refers to sub-features,
+      // which also should be deactivated when the operation
       // is active, e.g. rectangle'lines.
       FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObj);
       std::list<AttributePtr> anAttributes = aFeature->data()->attributes(
                                               ModelAPI_AttributeRefList::typeId());
-      std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
+      std::list<AttributePtr>::const_iterator
+        anIt = anAttributes.begin(), aLast = anAttributes.end();
       bool aFoundObject = false;
       for (; anIt != aLast && !aFoundObject; anIt++) {
         std::shared_ptr<ModelAPI_AttributeRefList> aCurSelList =
-                                         std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anIt);
+                               std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anIt);
         for (int i = 0, aNb = aCurSelList->size(); i < aNb && !aFoundObject; i++) {
           ObjectPtr anObject = aCurSelList->object(i);
           FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
@@ -350,12 +367,12 @@ bool ModuleBase_OperationFeature::commit()
 
     afterCommitOperation();
 #ifdef DEBUG_OPERATION_START
-  qDebug("ModuleBase_OperationFeature::commit -- end : IMPOSSIBLE to commit");
+  qDebug("ModuleBase_OperationFeature::commit -- end");
 #endif
     return true;
   }
 #ifdef DEBUG_OPERATION_START
-  qDebug("ModuleBase_OperationFeature::commit -- end");
+  qDebug("ModuleBase_OperationFeature::commit -- end : IMPOSSIBLE to commit");
 #endif
   return false;
 }
@@ -443,29 +460,31 @@ FeaturePtr ModuleBase_OperationFeature::previousCurrentFeature()
   return myPreviousCurrentFeature;
 }
 
-void ModuleBase_OperationFeature::initSelection(ModuleBase_ISelection* theSelection,
-                                         ModuleBase_IViewer* theViewer)
+void ModuleBase_OperationFeature::initSelection(
+  const QList<ModuleBase_ViewerPrsPtr>& thePreSelected)
 {
-  QList<ModuleBase_ViewerPrsPtr> aPreSelected;
+  QObjectPtrList aCurrentFeatureResults;
+
   // Check that the selected result are not results of operation feature
   FeaturePtr aFeature = feature();
   if (aFeature) {
-    QList<ModuleBase_ViewerPrsPtr> aSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls);
-
-    std::list<ResultPtr> aResults = aFeature->results();
-    QObjectPtrList aResList;
+    std::list<ResultPtr> aResults;
+    ModelAPI_Tools::allResults(aFeature, aResults);
     std::list<ResultPtr>::const_iterator aIt;
     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
-      aResList.append(*aIt);
+      aCurrentFeatureResults.append(*aIt);
+  }
 
-    foreach (ModuleBase_ViewerPrsPtr aPrs, aSelected) {
-      if ((!aResList.contains(aPrs->object())) && (aPrs->object() != aFeature))
+  if (aCurrentFeatureResults.empty()) /// filtering of selection is not necessary
+    setPreselection(thePreSelected);
+  else { // create preselection list without results of current feature
+    QList<ModuleBase_ViewerPrsPtr> aPreSelected;
+    foreach (ModuleBase_ViewerPrsPtr aPrs, thePreSelected) {
+      if ((!aCurrentFeatureResults.contains(aPrs->object())) && (aPrs->object() != aFeature))
         aPreSelected.append(aPrs);
     }
-  } else
-    aPreSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls);
-
-  setPreselection(aPreSelected);
+    setPreselection(aPreSelected);
+  }
 }
 
 void ModuleBase_OperationFeature::setPreselection(const QList<ModuleBase_ViewerPrsPtr>& theValues)
@@ -479,7 +498,7 @@ void ModuleBase_OperationFeature::clearPreselection()
   myPreSelection.clear();
 }
 
-void ModuleBase_OperationFeature::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) 
+void ModuleBase_OperationFeature::setPropertyPanel(ModuleBase_IPropertyPanel* theProp)
 {
   ModuleBase_Operation::setPropertyPanel(theProp);
 
@@ -491,11 +510,12 @@ void ModuleBase_OperationFeature::setPropertyPanel(ModuleBase_IPropertyPanel* th
     for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
       ModuleBase_ModelWidget* aWgt = (*aWIt);
       connect(aWgt, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
+      connect(aWgt, SIGNAL(valueStateChanged(int)), this, SLOT(onValueStateChanged(int)));
     }
   }
 
   // Do not activate widgets by default if the current operation is editing operation
-  // Because we don't know which widget is going to be edited. 
+  // Because we don't know which widget is going to be edited.
   if (!isEditOperation()) {
     // 4. activate the first obligatory widget
     theProp->activateNextWidget(NULL);