]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Cancel ExtrusionCut if there are no bodies
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 10 Jun 2015 16:08:09 +0000 (19:08 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 10 Jun 2015 16:08:22 +0000 (19:08 +0300)
src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp
src/PartSet/PartSet_WidgetSketchCreator.cpp

index 6cd449d82f3c3b9281f3f452bf34f351f2ecc0e5..2f8704e023c1cb75e023ee3bc4df472ccbac3a29 100755 (executable)
@@ -55,7 +55,7 @@ std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_ExtrusionCut::addFeature(std::s
     data()->reference(SKETCH_OBJECT_ID())->setValue(aNew);
   }
    // set as current also after it becomes sub to set correctly enabled for other sketch subs
-  //document()->setCurrentFeature(aNew, false);
+  document()->setCurrentFeature(aNew, false);
   return aNew;
 }
 
index ac1d449d86782ac1b12548d767d33040dbd230b4..a2d51b7ccf6b4a75c9ad067f2f4ebe13a9430580 100644 (file)
@@ -15,6 +15,7 @@
 #include <GeomAPI_Face.h>
 
 #include <ModelAPI_Session.h>
+#include <ModelAPI_ResultBody.h>
 
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_Operation.h>
@@ -24,6 +25,7 @@
 #include <QLabel>
 #include <QLineEdit>
 #include <QFormLayout>
+#include <QMessageBox>
 
 PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, 
                                                          PartSet_Module* theModule,
@@ -89,13 +91,37 @@ void PartSet_WidgetSketchCreator::onStarted()
 {
   disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
 
-  CompositeFeaturePtr aCompFeature = 
-    std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
-  FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
+  // Check that model already has bodies
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_Displayer* aDisp = aWorkshop->displayer();
+  QObjectPtrList aObjList = aDisp->displayedObjects();
+  bool aHasBody = false;
+  ResultBodyPtr aBody;
+  foreach(ObjectPtr aObj, aObjList) {
+    aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
+    if (aBody.get() != NULL) {
+      aHasBody = true;
+      break;
+    }
+  }
 
-  ModuleBase_Operation* anOperation = myModule->createOperation("Sketch");
-  anOperation->setFeature(aSketch);
-  myModule->sendOperation(anOperation);
+  if (aHasBody) {
+    // Launch Sketch operation
+    CompositeFeaturePtr aCompFeature = 
+      std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+    FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
+
+    ModuleBase_Operation* anOperation = myModule->createOperation("Sketch");
+    anOperation->setFeature(aSketch);
+    myModule->sendOperation(anOperation);
+  } else {
+    // Break current operation
+    QMessageBox::warning(this, tr("Extrusion Cut"),
+        tr("There are no bodies found. Operation aborted."), QMessageBox::Ok);
+    ModuleBase_Operation* aOp = myModule->workshop()->currentOperation();
+    aOp->abort();
+  }
 }
 
 bool PartSet_WidgetSketchCreator::focusTo()