From fb1766a3fb7d2b3e6862e040d528d96a5732f200 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 5 Mar 2015 11:29:28 +0300 Subject: [PATCH] Construction elements are auxiliary entities: Construction attribute change for multi-selected features --- src/PartSet/PartSet_Module.cpp | 24 +++--- src/PartSet/PartSet_Module.h | 8 +- src/PartSet/PartSet_SketcherMgr.cpp | 114 +++++++++++++++++++++------- src/XGUI/XGUI_OperationMgr.cpp | 4 - src/XGUI/XGUI_OperationMgr.h | 3 - 5 files changed, 105 insertions(+), 48 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 999344074..39520d8af 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -516,8 +516,9 @@ void PartSet_Module::onAction(bool isChecked) bool PartSet_Module::deleteObjects() { ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); - bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation); - if (!isSketchOp && !PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) + bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation), + isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation); + if (!isSketchOp && !isNestedOp) return false; // sketch feature should be skipped, only sub-features can be removed @@ -527,6 +528,7 @@ bool PartSet_Module::deleteObjects() // selected objects should be collected before the current operation abort because // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); + XGUI_Workshop* aWorkshop = aConnector->workshop(); ModuleBase_ISelection* aSel = aConnector->selection(); QObjectPtrList aSelectedObj = aSel->selectedPresentations(); @@ -536,14 +538,13 @@ bool PartSet_Module::deleteObjects() if (aSelectedObj.count() == 0) return false; - XGUI_Workshop* aWorkshop = aConnector->workshop(); - XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr(); - if (!isSketchOp && anOpMgr->canStopOperation()) { - ModuleBase_Operation* aCurrentOp = anOpMgr->currentOperation(); - if (aCurrentOp) { - aCurrentOp->abort(); - } - } + if (isNestedOp) + anOperation->abort(); + + // the active nested sketch operation should be aborted unconditionally + if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) + anOperation->abort(); + std::set aRefFeatures; foreach (ObjectPtr aObj, aSelectedObj) { @@ -558,7 +559,8 @@ bool PartSet_Module::deleteObjects() } //} } - QString aDescription = tr("Delete"); + + QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text(); /** // according to #355 feature, it is not necessary to inform about dependencies during // sketch delete operation diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 5a4429857..67484a6d7 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -80,6 +80,10 @@ public: /// \param theOperation a stopped operation virtual void operationStopped(ModuleBase_Operation* theOperation); + /// Returns action according to the given ID + /// \param theId an action identifier, it should be uniqued in the bounds of the module + QAction* action(const QString& theId) const; + /// Returns True if there are available Undos and the sketch manager allows undo /// \return the boolean result virtual bool canUndo() const; @@ -145,10 +149,6 @@ protected slots: /// Put the created actions into an internal map void createActions(); - /// Returns action according to the given ID - /// \param theId an action identifier, it should be uniqued in the bounds of the module - QAction* action(const QString& theId) const; - /// Add action to the internal map /// \param theId - string ID of the item /// \param theAction - action to add diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 1cfe39ac0..3b9e813c2 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ //#include #include +#include #include #include @@ -734,44 +736,105 @@ bool PartSet_SketcherMgr::canDisplayObject() const bool PartSet_SketcherMgr::canChangeConstruction(bool& isConstruction) const { + bool anEnabled = false; ModuleBase_Operation* anOperation = getCurrentOperation(); - bool anEnabled = PartSet_SketcherMgr::isNestedCreateOperation(anOperation) && - PartSet_SketcherMgr::isEntityOperation(anOperation); - if (anEnabled) { - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(anOperation->feature()); - if (aSketchFeature.get() != NULL) { - std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID(); + bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) || + PartSet_SketcherMgr::isNestedSketchOperation(anOperation); + if (!isActiveSketch) + return anEnabled; - std::shared_ptr aConstructionAttr = - std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); + QObjectPtrList anObjects; + // 1. change construction type of a created feature + if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) && + PartSet_SketcherMgr::isEntityOperation(anOperation) ) { + anObjects.append(anOperation->feature()); + } + else { + if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) + anOperation->abort(); + // 2. change construction type of selected sketch entities + ModuleBase_ISelection* aSelection = myModule->workshop()->selection(); + anObjects = aSelection->selectedPresentations(); + } + anEnabled = anObjects.size() > 0; + + bool isNotConstructedFound = false; + if (anObjects.size() > 0) { + QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); + for (; anIt != aLast && !isNotConstructedFound; anIt++) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); + if (aFeature.get() != NULL) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(aFeature); + if (aSketchFeature.get() != NULL) { + std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID(); - isConstruction = aConstructionAttr->value(); + std::shared_ptr aConstructionAttr = + std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); + isNotConstructedFound = !aConstructionAttr->value(); + } + } } } + isConstruction = anObjects.size() && !isNotConstructedFound; return anEnabled; } void PartSet_SketcherMgr::setConstruction(const bool isChecked) { ModuleBase_Operation* anOperation = getCurrentOperation(); - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(anOperation->feature()); - if (aSketchFeature.get() != NULL) { - std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID(); - std::shared_ptr aConstructionAttr = - std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); - aConstructionAttr->setValue(isChecked); + bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) || + PartSet_SketcherMgr::isNestedSketchOperation(anOperation); + if (!isActiveSketch) + return; - // ModuleBase_ModelWidget::updateObject - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - - static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); - ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent); - Events_Loop::loop()->flush(anEvent); + QObjectPtrList anObjects; + bool isUseTransaction = false; + // 1. change construction type of a created feature + if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) && + PartSet_SketcherMgr::isEntityOperation(anOperation) ) { + anObjects.append(anOperation->feature()); + } + else { + isUseTransaction = true; + // 2. change construction type of selected sketch entities + ModuleBase_ISelection* aSelection = myModule->workshop()->selection(); + anObjects = aSelection->selectedPresentations(); + } + + QAction* anAction = myModule->action("CONSTRUCTION_CMD"); + SessionPtr aMgr = ModelAPI_Session::get(); + if (isUseTransaction) { + if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) + anOperation->abort(); + aMgr->startOperation(anAction->text().toStdString()); } + storeSelection(); + + if (anObjects.size() > 0) { + QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); + if (aFeature.get() != NULL) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(aFeature); + if (aSketchFeature.get() != NULL) { + std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID(); + + std::shared_ptr aConstructionAttr = + std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); + aConstructionAttr->setValue(isChecked); + } + } + } + } + if (isUseTransaction) { + aMgr->finishOperation(); + } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + restoreSelection(); } void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr& thePln) @@ -969,7 +1032,6 @@ void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation, void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly) { ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); - ModuleBase_ISelection* aSelect = aWorkshop->selection(); QList aHighlighted = aSelect->getHighlighted(); @@ -992,12 +1054,12 @@ void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly) FeaturePtr aFeature = anIt.key(); getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, myCurrentSelection); } - qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str()); + //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str()); } void PartSet_SketcherMgr::restoreSelection() { - qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str()); + //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str()); ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(), diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index e767d7f96..1fe9717fb 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -301,10 +301,6 @@ bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent) commitOperation(); } break; - case Qt::Key_Delete: { // the delete button is occupied by the workshop Delete action, - // so this button process is realized here - emit keyDeleteReleased(); - } default: isAccepted = false; break; diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 609d8fde4..eb0e7541a 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -135,9 +135,6 @@ signals: /// Signal is emitted after the key released click. void keyEnterReleased(); - /// Signal is emitted after the key delete released click. - void keyDeleteReleased(); - protected: /// Commits the current operatin if it is valid bool commitOperation(); -- 2.39.2