X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetSketchCreator.cpp;h=308dd965f0f544f8e1d579071a0bb958266e6715;hb=33c5fdce3cd63dd95a738439a0399dd982abcd73;hp=a5d9cddb13958f9ebfd58a3aad2afd58ea5f32a2;hpb=ed4ac37cbf8f2c8e5665ff6251c9e21e4b8c497e;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index a5d9cddb1..308dd965f 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -7,6 +7,8 @@ #include "PartSet_WidgetSketchCreator.h" #include "PartSet_Module.h" +#include + #include #include #include @@ -19,6 +21,8 @@ #include #include #include +#include +#include #include #include @@ -26,8 +30,11 @@ #include #include #include +#include #include +#include + #include #include #include @@ -37,7 +44,7 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule, const Config_WidgetAPI* theData, const std::string& theParentId) -: ModuleBase_ModelWidget(theParent, theData, theParentId), myModule(theModule) +: ModuleBase_ModelWidget(theParent, theData, theParentId), myModule(theModule), myUseBody(true) { QFormLayout* aLayout = new QFormLayout(this); ModuleBase_Tools::adjustMargins(aLayout); @@ -55,6 +62,13 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, myTextLine->setToolTip(aToolTip); myTextLine->installEventFilter(this); + myLabel->setToolTip(aToolTip); + + QString aUseBody = QString::fromStdString(theData->getProperty(USE_BODY)); + if(!aUseBody.isEmpty()) { + myUseBody = QVariant(aUseBody).toBool(); + } + aLayout->addRow(myLabel, myTextLine); } @@ -69,7 +83,7 @@ QList PartSet_WidgetSketchCreator::getControls() const return aControls; } -bool PartSet_WidgetSketchCreator::restoreValue() +bool PartSet_WidgetSketchCreator::restoreValueCustom() { CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast(myFeature); @@ -102,13 +116,15 @@ void PartSet_WidgetSketchCreator::onStarted() XGUI_Workshop* aWorkshop = aConnector->workshop(); XGUI_Displayer* aDisp = aWorkshop->displayer(); QObjectPtrList aObjList = aDisp->displayedObjects(); - bool aHasBody = false; + bool aHasBody = !myUseBody; ResultBodyPtr aBody; - foreach(ObjectPtr aObj, aObjList) { - aBody = std::dynamic_pointer_cast(aObj); - if (aBody.get() != NULL) { - aHasBody = true; - break; + if(!aHasBody) { + foreach(ObjectPtr aObj, aObjList) { + aBody = std::dynamic_pointer_cast(aObj); + if (aBody.get() != NULL) { + aHasBody = true; + break; + } } } @@ -116,15 +132,28 @@ void PartSet_WidgetSketchCreator::onStarted() // 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); + /// add sketch feature without current feature change. + /// it is important to do not change the current feature in order to + /// after sketch edition, the extrusion cut feature becomes current + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr aDoc = aMgr->activeDocument(); + FeaturePtr aPreviousCurrentFeature = aDoc->currentFeature(false); + FeaturePtr aSketch = aCompFeature->addFeature("Sketch"); + aDoc->setCurrentFeature(aPreviousCurrentFeature, false); + + // start edit operation for the sketch + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (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(); @@ -138,12 +167,14 @@ bool PartSet_WidgetSketchCreator::focusTo() if (aCompFeature->numberOfSubs() == 0) return ModuleBase_ModelWidget::focusTo(); - connect(myModule, SIGNAL(operationResumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*))); + connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*))); SessionPtr aMgr = ModelAPI_Session::get(); + // Open transaction that is general for the previous nested one: it will be closed on nested commit bool aIsOp = aMgr->isOperation(); - // Open transaction if it was closed before - if (!aIsOp) - aMgr->startOperation(); + if (!aIsOp) { + const static std::string aNestedOpID("Parameters modification"); + aMgr->startOperation(aNestedOpID, true); + } restoreValue(); return false; @@ -158,10 +189,14 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) if (aSketchFeature->numberOfSubs() == 0) { // Abort operation SessionPtr aMgr = ModelAPI_Session::get(); - bool aIsOp = aMgr->isOperation(); // Close transaction - if (aIsOp) - aMgr->abortOperation(); + /* + bool aIsOp = aMgr->isOperation(); + if (aIsOp) { + const static std::string aNestedOpID("Parameters cancelation"); + aMgr->startOperation(aNestedOpID, true); + } + */ theOp->abort(); } else { // Hide sketcher result @@ -172,20 +207,36 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) } aSketchFeature->setDisplayed(false); - // Add Selected body were created the sketcher to list of selected objects - DataPtr aData = aSketchFeature->data(); - AttributeSelectionPtr aSelAttr = - std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - if (aSelAttr.get()) { - ResultPtr aRes = aSelAttr->context(); - GeomShapePtr aShape = aSelAttr->value(); - if (aRes.get()) { - AttributeSelectionListPtr aSelList = - aCompFeature->data()->selectionList(FeaturesPlugin_CompositeBoolean::BOOLEAN_OBJECTS_ID()); - aSelList->append(aRes, GeomShapePtr()); - updateObject(aCompFeature); + if(myUseBody) { + // Add Selected body were created the sketcher to list of selected objects + DataPtr aData = aSketchFeature->data(); + AttributeSelectionPtr aSelAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (aSelAttr.get()) { + ResultPtr aRes = aSelAttr->context(); + GeomShapePtr aShape = aSelAttr->value(); + if (aRes.get()) { + 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()); + if (aFactory->validate(anAttribute, aValidatorID, anError)) + updateObject(aCompFeature); + else + aSelList->clear(); + } } } + else { + // this is a workarount to display the feature results in the operation selection mode + // if this is absent, sketch point/line local selection is available on extrusion cut result + static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); + ModelAPI_EventCreator::get()->sendUpdated(feature(), anUpdateEvent); + updateObject(feature()); + } } }