X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FPartSet%2FPartSet_Module.cpp;h=26da028d4defbeaad4d903e78c3b957ed78b7948;hb=a43d07a86c50cc5ca90f0e0f549cfd545a5dea07;hp=797fcd11602a123fecb98dfdaa01720fccb55adb;hpb=3190305afd2b86b05365e51589822856d6937a1b;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 797fcd116..26da028d4 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -63,6 +63,8 @@ #include #include #include +#include +#include #include #include @@ -95,6 +97,8 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) ModuleBase_IViewer* aViewer = theWshop->viewer(); connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)), this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*))); + + createActions(); } PartSet_Module::~PartSet_Module() @@ -139,7 +143,9 @@ void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation) // the selection is cleared after commit the create operation // in order to do not use the same selected objects in the restarted operation // for common behaviour, the selection is cleared even if the operation is not restarted - myWorkshop->viewer()->AISContext()->ClearSelected(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (!aContext.IsNull()) + aContext->ClearSelected(); /// Restart sketcher operations automatically FeaturePtr aFeature = theOperation->feature(); @@ -185,6 +191,45 @@ void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation) myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter); } +bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const +{ + bool aCanDisplay = false; + if (mySketchMgr->activeSketch()) { + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + + if (aFeature.get() != NULL) { + if (aFeature == mySketchMgr->activeSketch()) { + aCanDisplay = false; + } + else { + aCanDisplay = mySketchMgr->sketchOperationIdList().contains(aFeature->getKind().c_str()); + } + } + } + else { + aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject); + } + return aCanDisplay; + +void PartSet_Module::addViewerItems(QMenu* theMenu) const +{ + if (!isSketchOperationActive() && !isSketchFeatureOperationActive()) + return; + ModuleBase_ISelection* aSelection = myWorkshop->selection(); + QObjectPtrList aObjects = aSelection->selectedPresentations(); + if (aObjects.size() > 0) { + bool hasFeature = false; + foreach(ObjectPtr aObject, aObjects) + { + FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); + if (aFeature.get() != NULL) { + hasFeature = true; + } + } + if (hasFeature) + theMenu->addAction(action("DELETE_PARTSET_CMD")); + } +} void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) { @@ -210,13 +255,14 @@ void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) aPnt2dWgt->setPoint(aPoint->x(), aPoint->y()); PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(), aWgt->attributeID(), aPoint->x(), aPoint->y()); - theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt); + aPanel->activateNextWidget(aPnt2dWgt); } } } } else { // Start editing constraint if (theOperation->isEditOperation()) { + // TODO: #391 - to be removed std::string aId = theOperation->id().toStdString(); if (PartSet_SketcherMgr::sketchOperationIdList().contains(QString(aId.c_str()))) { if ((aId == SketchPlugin_ConstraintRadius::ID()) || @@ -285,30 +331,20 @@ void PartSet_Module::onEnterReleased() void PartSet_Module::onOperationActivatedByPreselection() { ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); - if (!aOperation) - return; - - // Set final definitions if they are necessary - //propertyPanelDefined(aOperation); + if(aOperation && isSketchFeatureOperationActive()) { + // Set final definitions if they are necessary + //propertyPanelDefined(aOperation); - /// Commit sketcher operations automatically - FeaturePtr aFeature = aOperation->feature(); - std::shared_ptr aSPFeature = - std::dynamic_pointer_cast(aFeature); - if (aSPFeature) { + /// Commit sketcher operations automatically aOperation->commit(); } } void PartSet_Module::onNoMoreWidgets() { - ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); - if (aOperation) { - /// Restart sketcher operations automatically - FeaturePtr aFeature = aOperation->feature(); - std::shared_ptr aSPFeature = - std::dynamic_pointer_cast(aFeature); - if (aSPFeature) { + if (isSketchFeatureOperationActive()) { + ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); + if (aOperation) { if (myRestartingMode != RM_Forbided) myRestartingMode = RM_LastFeatureUsed; aOperation->commit(); @@ -381,3 +417,149 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* return 0; } +bool PartSet_Module::isSketchOperationActive() const +{ + ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); + + bool isSketchOp = aOperation && aOperation->id().toStdString() == SketchPlugin_Sketch::ID(); + return isSketchOp; +} + +bool PartSet_Module::isSketchFeatureOperationActive() const +{ + bool isCurrentSketchOp = false; + ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); + if (aOperation) { + FeaturePtr aFeature = aOperation->feature(); + std::shared_ptr aSPFeature = + std::dynamic_pointer_cast(aFeature); + isCurrentSketchOp = aSPFeature.get() != NULL; + } + return isCurrentSketchOp; +} + +void PartSet_Module::createActions() +{ + QAction* aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this); + addAction("DELETE_PARTSET_CMD", aAction); +} + +QAction* PartSet_Module::action(const QString& theId) const +{ + if (myActions.contains(theId)) + return myActions[theId]; + return 0; +} + +void PartSet_Module::addAction(const QString& theId, QAction* theAction) +{ + if (myActions.contains(theId)) + qCritical("A command with Id = '%s' already defined!", qPrintable(theId)); + theAction->setData(theId); + connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool))); + myActions[theId] = theAction; +} + +void PartSet_Module::onAction(bool isChecked) +{ + QAction* aAction = static_cast(sender()); + QString anId = aAction->data().toString(); + + if (anId == "DELETE_PARTSET_CMD") { + deleteObjects(); + } +} + +void PartSet_Module::deleteObjects() +{ + bool isSketchOp = isSketchOperationActive(); + if (!isSketchOp && !isSketchFeatureOperationActive()) + return; + + XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + + XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr(); + if (!isSketchOp && anOpMgr->canStopOperation()) { + ModuleBase_Operation* aCurrentOp = anOpMgr->currentOperation(); + if (aCurrentOp) { + aCurrentOp->abort(); + } + } + // sketch feature should be skipped, only sub-features can be removed + // when sketch operation is active + CompositeFeaturePtr aSketch = mySketchMgr->activeSketch(); + + ModuleBase_ISelection* aSel = aConnector->selection(); + QObjectPtrList aSelectedObj = aSel->selectedPresentations(); + + std::set aRefFeatures; + foreach (ObjectPtr aObj, aSelectedObj) + { + //ResultPartPtr aPart = std::dynamic_pointer_cast(aObj); + //if (aPart) { + // TODO: check for what there is this condition. It is placed here historicaly because + // ther is this condition during remove features. + //} else { + FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); + if (aFeature.get() != NULL) { + aObj->document()->refsToFeature(aFeature, aRefFeatures, false); + } + //} + } + + if (!aRefFeatures.empty()) { + QStringList aRefNames; + std::set::const_iterator anIt = aRefFeatures.begin(), + aLast = aRefFeatures.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aFeature = (*anIt); + if (aFeature == aSketch) + continue; + aRefNames.append((*anIt)->name().c_str()); + } + if (!aRefNames.empty()) { + QString aNames = aRefNames.join(", "); + + QMainWindow* aDesktop = aWorkshop->desktop(); + QMessageBox::StandardButton aRes = QMessageBox::warning( + aDesktop, tr("Delete features"), + QString(tr("Selected features are used in the following features: %1.\ + These features will be deleted also. Would you like to continue?")).arg(aNames), + QMessageBox::No | QMessageBox::Yes, QMessageBox::No); + if (aRes != QMessageBox::Yes) + return; + } + } + + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->startOperation(); + std::set::const_iterator anIt = aRefFeatures.begin(), + aLast = aRefFeatures.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aRefFeature = (*anIt); + if (aRefFeature == aSketch) + continue; + aRefFeature->document()->removeFeature(aRefFeature); + } + + foreach (ObjectPtr aObj, aSelectedObj) + { + DocumentPtr aDoc = aObj->document(); + //ResultPartPtr aPart = std::dynamic_pointer_cast(aObj); + //if (aPart) { + // if (aDoc == aMgr->activeDocument()) { + // aDoc->close(); + // } + //} else { + //FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); + FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); + if (aFeature.get() != NULL) { + aDoc->removeFeature(aFeature); + } + //} + } + aWorkshop->displayer()->updateViewer(); + //myDisplayer->updateViewer(); + aMgr->finishOperation(); +}