From: vsv Date: Wed, 10 Jun 2015 16:08:09 +0000 (+0300) Subject: Cancel ExtrusionCut if there are no bodies X-Git-Tag: V_1.3.0~251 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7a9f064633a57e79683a8fe75c228a0c76d383a0;p=modules%2Fshaper.git Cancel ExtrusionCut if there are no bodies --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp index 6cd449d82..2f8704e02 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp @@ -55,7 +55,7 @@ std::shared_ptr 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; } diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index ac1d449d8..a2d51b7cc 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -24,6 +25,7 @@ #include #include #include +#include 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(myFeature); - FeaturePtr aSketch = aCompFeature->addFeature("Sketch"); + // Check that model already has bodies + XGUI_ModuleConnector* aConnector = dynamic_cast(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(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(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()