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
// 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<XGUI_ModuleConnector*>(workshop());
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
ModuleBase_ISelection* aSel = aConnector->selection();
QObjectPtrList aSelectedObj = aSel->selectedPresentations();
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<FeaturePtr> aRefFeatures;
foreach (ObjectPtr aObj, aSelectedObj)
{
}
//}
}
- 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
#include <XGUI_ModuleConnector.h>
#include <XGUI_Displayer.h>
#include <XGUI_Workshop.h>
+#include <XGUI_ContextMenuMgr.h>
#include <XGUI_Selection.h>
#include <XGUI_SelectionMgr.h>
#include <ModuleBase_ModelWidget.h>
//#include <AIS_Shape.hxx>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Session.h>
#include <QMouseEvent>
#include <QApplication>
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<SketchPlugin_Feature> aSketchFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(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<ModelAPI_AttributeBoolean> aConstructionAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(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<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ if (aSketchFeature.get() != NULL) {
+ std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
- isConstruction = aConstructionAttr->value();
+ std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(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<SketchPlugin_Feature> aSketchFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(anOperation->feature());
- if (aSketchFeature.get() != NULL) {
- std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
- std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(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<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ if (aSketchFeature.get() != NULL) {
+ std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+
+ std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(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<GeomAPI_Pln>& thePln)
void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
{
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
-
ModuleBase_ISelection* aSelect = aWorkshop->selection();
QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
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<XGUI_ModuleConnector*>(aWorkshop);
FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),