Salome HOME
Fix for the issue #910: never fully remove the results, just make them disabled when...
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchCreator.cpp
index 3579f6e93832a1722a6b3bbe8373dff5f1529689..f7a52416e4597dfd8c20d04e28b7ab0743378680 100644 (file)
@@ -19,6 +19,7 @@
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Validator.h>
 
 #include <SketchPlugin_SketchEntity.h>
 #include <FeaturesPlugin_CompositeBoolean.h>
@@ -26,6 +27,7 @@
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_OperationFeature.h>
 #include <Config_WidgetAPI.h>
 
 #include <QLabel>
@@ -118,13 +120,17 @@ void PartSet_WidgetSketchCreator::onStarted()
       std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
     FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
 
-    ModuleBase_Operation* anOperation = myModule->createOperation("Sketch");
-    anOperation->setFeature(aSketch);
-    myModule->sendOperation(anOperation);
+    ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+                                                             (myModule->createOperation("Sketch"));
+    if (aFOperation)
+      aFOperation->setFeature(aSketch);
+    myModule->sendOperation(aFOperation);
     //connect(anOperation, SIGNAL(aborted()), aWorkshop->operationMgr(), SLOT(abortAllOperations()));
   } else {
     // Break current operation
-    QMessageBox::warning(this, tr("Extrusion Cut"),
+    std::string anOperationName = feature()->getKind();
+    QString aTitle = tr( anOperationName.c_str() );
+    QMessageBox::warning(this, aTitle,
         tr("There are no bodies found. Operation aborted."), QMessageBox::Ok);
     ModuleBase_Operation* aOp = myModule->workshop()->currentOperation();
     aOp->abort();
@@ -187,10 +193,17 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp)
       ResultPtr aRes = aSelAttr->context();
       GeomShapePtr aShape = aSelAttr->value();
       if (aRes.get()) {
-        AttributeSelectionListPtr aSelList = 
-          aCompFeature->data()->selectionList(FeaturesPlugin_CompositeBoolean::BOOLEAN_OBJECTS_ID());
+        std::string anObjectsAttribute = FeaturesPlugin_CompositeBoolean::BOOLEAN_OBJECTS_ID();
+        SessionPtr aMgr = ModelAPI_Session::get();
+        ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+        AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute);
+        std::string aValidatorID, anError;
+        AttributeSelectionListPtr aSelList = aCompFeature->data()->selectionList(anObjectsAttribute);
         aSelList->append(aRes, GeomShapePtr());
-        updateObject(aCompFeature);
+        if (aFactory->validate(anAttribute, aValidatorID, anError))
+          updateObject(aCompFeature);
+        else
+          aSelList->clear();
       }
     }
   }