1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSet_Module.h"
4 #include <PartSet_WidgetSketchLabel.h>
5 #include <PartSet_Validators.h>
6 #include <PartSet_Tools.h>
7 #include <PartSet_WidgetPoint2d.h>
8 #include <PartSet_WidgetPoint2dDistance.h>
9 #include <PartSet_WidgetShapeSelector.h>
10 #include <PartSet_WidgetConstraintShapeSelector.h>
11 #include <PartSet_SketcherMgr.h>
13 #include <ModuleBase_Operation.h>
14 #include <ModuleBase_IViewer.h>
15 #include <ModuleBase_IViewWindow.h>
16 #include <ModuleBase_IPropertyPanel.h>
17 #include <ModuleBase_WidgetEditor.h>
18 #include <ModuleBase_FilterFactory.h>
19 #include <ModuleBase_FilterLinearEdge.h>
20 #include <ModuleBase_FilterFace.h>
21 #include <ModuleBase_FilterMulti.h>
22 #include <ModuleBase_FilterCustom.h>
23 #include <ModuleBase_FilterNoConsructionSubShapes.h>
24 #include <PartSet_FilterSketchEntity.h>
26 #include <ModelAPI_Object.h>
27 #include <ModelAPI_Events.h>
28 #include <ModelAPI_Validator.h>
29 #include <ModelAPI_Data.h>
30 #include <ModelAPI_Session.h>
31 #include <ModelAPI_ShapeValidator.h>
33 #include <GeomDataAPI_Point2D.h>
34 #include <GeomDataAPI_Point.h>
35 #include <GeomDataAPI_Dir.h>
37 #include <XGUI_Displayer.h>
38 #include <XGUI_Workshop.h>
39 #include <XGUI_OperationMgr.h>
40 #include <XGUI_PropertyPanel.h>
41 #include <XGUI_ModuleConnector.h>
42 #include <XGUI_ContextMenuMgr.h>
43 #include <XGUI_Tools.h>
45 #include <SketchPlugin_Feature.h>
46 #include <SketchPlugin_Sketch.h>
47 #include <SketchPlugin_Line.h>
48 //#include <SketchPlugin_Arc.h>
49 //#include <SketchPlugin_Circle.h>
50 #include <SketchPlugin_ConstraintLength.h>
51 #include <SketchPlugin_ConstraintDistance.h>
52 #include <SketchPlugin_ConstraintParallel.h>
53 #include <SketchPlugin_ConstraintPerpendicular.h>
54 #include <SketchPlugin_ConstraintRadius.h>
55 //#include <SketchPlugin_ConstraintRigid.h>
57 #include <Events_Loop.h>
58 #include <Config_PropManager.h>
60 #include <StdSelect_TypeOfFace.hxx>
61 #include <TopoDS_Vertex.hxx>
63 #include <TopoDS_Shape.hxx>
64 #include <BRep_Tool.hxx>
67 #include <QMouseEvent>
70 #include <QApplication>
71 #include <QMessageBox>
72 #include <QMainWindow>
74 #include <GeomAlgoAPI_FaceBuilder.h>
75 #include <GeomDataAPI_Dir.h>
81 /*!Create and return new instance of XGUI_Module*/
82 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
84 return new PartSet_Module(theWshop);
87 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
88 : ModuleBase_IModule(theWshop),
89 myRestartingMode(RM_None)
91 //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
92 mySketchMgr = new PartSet_SketcherMgr(this);
94 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
95 XGUI_Workshop* aWorkshop = aConnector->workshop();
97 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
98 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
99 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
100 this, SLOT(onOperationActivatedByPreselection()));
102 ModuleBase_IViewer* aViewer = theWshop->viewer();
103 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
104 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
109 PartSet_Module::~PartSet_Module()
111 if (!myDocumentShapeFilter.IsNull())
112 myDocumentShapeFilter.Nullify();
115 void PartSet_Module::registerValidators()
117 //Registering of validators
118 SessionPtr aMgr = ModelAPI_Session::get();
119 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
120 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
121 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
122 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
123 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
124 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
125 aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
126 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
127 aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
128 aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
131 void PartSet_Module::registerFilters()
133 //Registering of selection filters
134 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
135 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
137 aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
138 aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
139 aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
140 Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
141 aFactory->registerFilter("NoConstructionSubShapesFilter",
142 new ModuleBase_FilterCustom(aSelectFilter));
143 aSelectFilter = new PartSet_FilterSketchEntity(workshop());
144 aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
147 void PartSet_Module::registerProperties()
149 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
151 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
152 Config_Prop::Integer, SKETCH_WIDTH);
155 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
157 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
158 mySketchMgr->commitNestedSketch(theOperation);
161 if (theOperation->isEditOperation())
163 // the selection is cleared after commit the create operation
164 // in order to do not use the same selected objects in the restarted operation
165 // for common behaviour, the selection is cleared even if the operation is not restarted
166 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
167 if (!aContext.IsNull())
168 aContext->ClearSelected();
170 /// Restart sketcher operations automatically
171 FeaturePtr aFeature = theOperation->feature();
172 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
173 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
174 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
175 myRestartingMode == RM_EmptyFeatureUsed)) {
176 myLastOperationId = theOperation->id();
177 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
179 launchOperation(myLastOperationId);
181 breakOperationSequence();
184 void PartSet_Module::breakOperationSequence()
186 myLastOperationId = "";
187 myLastFeature = FeaturePtr();
188 myRestartingMode = RM_None;
191 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
193 breakOperationSequence();
196 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
198 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
199 mySketchMgr->startSketch(theOperation);
201 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
202 mySketchMgr->startNestedSketch(theOperation);
205 if (myDocumentShapeFilter.IsNull())
206 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
207 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
210 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
212 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
213 mySketchMgr->stopSketch(theOperation);
215 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
216 mySketchMgr->stopNestedSketch(theOperation);
218 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
221 bool PartSet_Module::canUndo() const
223 bool aCanUndo = false;
224 SessionPtr aMgr = ModelAPI_Session::get();
225 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
226 aCanUndo = !aMgr->isOperation();
227 if (!aCanUndo) // check the enable state additionally by sketch manager
228 aCanUndo = aMgr->canUndo();
233 bool PartSet_Module::canRedo() const
235 bool aCanRedo = false;
236 SessionPtr aMgr = ModelAPI_Session::get();
237 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
238 aCanRedo = !aMgr->isOperation();
239 if (!aCanRedo) // check the enable state additionally by sketch manager
240 aCanRedo = aMgr->canRedo();
245 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
247 bool aCanDisplay = false;
248 if (!mySketchMgr->canDisplayObject())
250 CompositeFeaturePtr aSketchFeature = mySketchMgr->activeSketch();
251 if (aSketchFeature.get() != NULL) {
252 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
254 // MPV: the second and third conditions to avoid crash on exit for application
255 if (aFeature.get() != NULL && aFeature->data().get() && aFeature->data()->isValid()) {
256 if (aFeature == aSketchFeature) {
259 else if (aSketchFeature.get() && aSketchFeature->data().get() &&
260 aSketchFeature->data()->isValid()) {
261 for (int i = 0; i < aSketchFeature->numberOfSubs() && !aCanDisplay; i++) {
262 FeaturePtr aSubFeature = aSketchFeature->subFeature(i);
263 std::list<ResultPtr> aResults = aSubFeature->results();
264 std::list<ResultPtr>::const_iterator aIt;
265 for (aIt = aResults.begin(); aIt != aResults.end() && !aCanDisplay; ++aIt) {
266 if (theObject == (*aIt))
269 if (aSubFeature == theObject)
276 aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject);
281 void PartSet_Module::addViewerItems(QMenu* theMenu) const
283 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
284 if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
285 !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
288 ModuleBase_ISelection* aSelection = myWorkshop->selection();
289 QObjectPtrList aObjects = aSelection->selectedPresentations();
290 if (aObjects.size() > 0) {
291 bool hasFeature = false;
292 foreach(ObjectPtr aObject, aObjects)
294 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
295 if (aFeature.get() != NULL) {
300 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
301 XGUI_Workshop* aWorkshop = aConnector->workshop();
302 QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
303 theMenu->addAction(anAction);
307 if (mySketchMgr->canSetAuxiliary(isAuxiliary)) {
308 QAction* anAction = action("AUXILIARY_CMD");
309 theMenu->addAction(anAction);
310 anAction->setChecked(isAuxiliary);
314 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
316 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
317 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
318 // we have to manually activate the sketch label in edit mode
319 aPanel->activateWidget(aPanel->modelWidgets().first());
323 // Restart last operation type
324 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
325 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
326 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
327 // Initialise new line with first point equal to end of previous
328 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
330 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
331 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
332 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
334 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
335 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
336 aWgt->attributeID(), aPoint->x(), aPoint->y());
337 aPanel->activateNextWidget(aPnt2dWgt);
342 // Start editing constraint
343 if (theOperation->isEditOperation()) {
344 // TODO: #391 - to be removed
345 std::string aId = theOperation->id().toStdString();
346 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
347 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
348 // Find and activate widget for management of point for dimension line position
349 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
350 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
351 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
353 aPanel->activateWidget(aPntWgt);
363 void PartSet_Module::onSelectionChanged()
365 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
369 bool isSketcherOp = false;
370 // An edit operation is enable only if the current opeation is the sketch operation
371 if (mySketchMgr->activeSketch()) {
372 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
373 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
376 // Editing of constraints can be done on selection
377 ModuleBase_ISelection* aSelect = myWorkshop->selection();
378 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
379 if (aSelected.size() == 1) {
380 ModuleBase_ViewerPrs aPrs = aSelected.first();
381 ObjectPtr aObject = aPrs.object();
382 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
384 std::string aId = aFeature->getKind();
385 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
386 (aId == SketchPlugin_ConstraintLength::ID()) ||
387 (aId == SketchPlugin_ConstraintDistance::ID())) {
388 editFeature(aFeature);
395 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
397 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
398 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
399 anOpMgr->onKeyReleased(theEvent);
402 void PartSet_Module::onEnterReleased()
404 myRestartingMode = RM_EmptyFeatureUsed;
407 void PartSet_Module::onOperationActivatedByPreselection()
409 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
410 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
411 // Set final definitions if they are necessary
412 //propertyPanelDefined(aOperation);
414 /// Commit sketcher operations automatically
415 anOperation->commit();
419 void PartSet_Module::onNoMoreWidgets()
421 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
423 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
424 if (myRestartingMode != RM_Forbided)
425 myRestartingMode = RM_LastFeatureUsed;
426 anOperation->commit();
431 void PartSet_Module::onVertexSelected()
433 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
434 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
435 /// If last line finished on vertex the lines creation sequence has to be break
436 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
437 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
438 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
439 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
440 bool aFoundWidget = false;
441 bool aFoundObligatory = false;
442 for (; anIt != aLast && !aFoundObligatory; anIt++) {
444 aFoundWidget = *anIt == anActiveWidget;
446 aFoundObligatory = (*anIt)->isObligatory();
448 if (!aFoundObligatory)
449 myRestartingMode = RM_Forbided;
453 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
454 Config_WidgetAPI* theWidgetApi, std::string theParentId)
456 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
457 XGUI_Workshop* aWorkshop = aConnector->workshop();
458 ModuleBase_ModelWidget* aWgt = NULL;
459 if (theType == "sketch-start-label") {
460 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
461 aLabelWgt->setWorkshop(aWorkshop);
462 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
463 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
465 } else if (theType == "sketch-2dpoint_selector") {
466 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
467 aPointWgt->setWorkshop(aWorkshop);
468 aPointWgt->setSketch(mySketchMgr->activeSketch());
469 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
471 } if (theType == "point2ddistance") {
472 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
473 aDistanceWgt->setWorkshop(aWorkshop);
474 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
476 } if (theType == "sketch_shape_selector") {
477 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
478 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
479 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
480 aWgt = aShapeSelectorWgt;
481 } if (theType == "sketch_constraint_shape_selector") {
482 PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
483 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
484 aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
485 aWgt = aConstraintShapeSelectorWgt;
490 void PartSet_Module::createActions()
494 anAction = new QAction(tr("Auxiliary"), this);
495 anAction->setCheckable(true);
496 addAction("AUXILIARY_CMD", anAction);
499 QAction* PartSet_Module::action(const QString& theId) const
501 if (myActions.contains(theId))
502 return myActions[theId];
506 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
508 if (myActions.contains(theId))
509 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
510 theAction->setData(theId);
511 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
512 myActions[theId] = theAction;
515 void PartSet_Module::onAction(bool isChecked)
517 QAction* aAction = static_cast<QAction*>(sender());
518 QString anId = aAction->data().toString();
520 if (anId == "AUXILIARY_CMD") {
521 mySketchMgr->setAuxiliary(isChecked);
525 bool PartSet_Module::deleteObjects()
527 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
528 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
529 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
530 if (!isSketchOp && !isNestedOp)
533 // sketch feature should be skipped, only sub-features can be removed
534 // when sketch operation is active
535 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
537 // selected objects should be collected before the current operation abort because
538 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
539 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
540 XGUI_Workshop* aWorkshop = aConnector->workshop();
541 ModuleBase_ISelection* aSel = aConnector->selection();
542 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
544 // if there are no selected objects in the viewer, that means that the selection in another
545 // place cased this method. It is necessary to return the false value to understande in above
546 // method that delete is not processed
547 if (aSelectedObj.count() == 0)
551 anOperation->abort();
553 // the active nested sketch operation should be aborted unconditionally
554 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
555 anOperation->abort();
557 std::set<FeaturePtr> aRefFeatures;
558 foreach (ObjectPtr aObj, aSelectedObj)
560 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
562 // TODO: check for what there is this condition. It is placed here historicaly because
563 // ther is this condition during remove features.
565 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
566 if (aFeature.get() != NULL) {
567 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
572 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
574 // according to #355 feature, it is not necessary to inform about dependencies during
575 // sketch delete operation
577 if (!aRefFeatures.empty()) {
578 QStringList aRefNames;
579 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
580 aLast = aRefFeatures.end();
581 for (; anIt != aLast; anIt++) {
582 FeaturePtr aFeature = (*anIt);
583 if (aFeature == aSketch)
585 aRefNames.append((*anIt)->name().c_str());
587 if (!aRefNames.empty()) {
588 QString aNames = aRefNames.join(", ");
589 aDescription += aNames.prepend(" ");
591 QMainWindow* aDesktop = aWorkshop->desktop();
592 QMessageBox::StandardButton aRes = QMessageBox::warning(
593 aDesktop, tr("Delete features"),
594 QString(tr("Selected features are used in the following features: %1.\
595 These features will be deleted also. Would you like to continue?")).arg(aNames),
596 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
597 if (aRes != QMessageBox::Yes)
602 SessionPtr aMgr = ModelAPI_Session::get();
603 aMgr->startOperation(aDescription.toStdString());
604 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
605 aLast = aRefFeatures.end();
606 for (; anIt != aLast; anIt++) {
607 FeaturePtr aRefFeature = (*anIt);
608 if (aRefFeature == aSketch)
610 aRefFeature->document()->removeFeature(aRefFeature);
613 foreach (ObjectPtr aObj, aSelectedObj)
615 DocumentPtr aDoc = aObj->document();
616 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
618 // if (aDoc == aMgr->activeDocument()) {
622 //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
623 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
624 if (aFeature.get() != NULL) {
625 aDoc->removeFeature(aFeature);
629 aWorkshop->displayer()->updateViewer();
630 //myDisplayer->updateViewer();
631 aMgr->finishOperation();