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 <GeomValidators_Edge.h>
25 #include <GeomValidators_EdgeOrVertex.h>
26 #include <GeomValidators_Face.h>
27 #include <GeomValidators_ConstructionComposite.h>
29 #include <PartSet_FilterSketchEntity.h>
31 #include <ModelAPI_Object.h>
32 #include <ModelAPI_Events.h>
33 #include <ModelAPI_Validator.h>
34 #include <ModelAPI_Data.h>
35 #include <ModelAPI_Session.h>
36 #include <ModelAPI_ShapeValidator.h>
38 #include <GeomDataAPI_Point2D.h>
39 #include <GeomDataAPI_Point.h>
40 #include <GeomDataAPI_Dir.h>
42 #include <XGUI_Displayer.h>
43 #include <XGUI_Workshop.h>
44 #include <XGUI_OperationMgr.h>
45 #include <XGUI_PropertyPanel.h>
46 #include <XGUI_ModuleConnector.h>
47 #include <XGUI_ContextMenuMgr.h>
48 #include <XGUI_Tools.h>
50 #include <SketchPlugin_Feature.h>
51 #include <SketchPlugin_Sketch.h>
52 #include <SketchPlugin_Line.h>
53 //#include <SketchPlugin_Arc.h>
54 //#include <SketchPlugin_Circle.h>
55 #include <SketchPlugin_ConstraintLength.h>
56 #include <SketchPlugin_ConstraintDistance.h>
57 #include <SketchPlugin_ConstraintParallel.h>
58 #include <SketchPlugin_ConstraintPerpendicular.h>
59 #include <SketchPlugin_ConstraintRadius.h>
60 //#include <SketchPlugin_ConstraintRigid.h>
62 #include <Events_Loop.h>
63 #include <Config_PropManager.h>
65 #include <StdSelect_TypeOfFace.hxx>
66 #include <TopoDS_Vertex.hxx>
68 #include <TopoDS_Shape.hxx>
69 #include <BRep_Tool.hxx>
72 #include <QMouseEvent>
75 #include <QApplication>
76 #include <QMessageBox>
77 #include <QMainWindow>
79 #include <GeomAlgoAPI_FaceBuilder.h>
80 #include <GeomDataAPI_Dir.h>
86 /*!Create and return new instance of XGUI_Module*/
87 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
89 return new PartSet_Module(theWshop);
92 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
93 : ModuleBase_IModule(theWshop),
94 myRestartingMode(RM_None)
96 //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
97 mySketchMgr = new PartSet_SketcherMgr(this);
99 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
100 XGUI_Workshop* aWorkshop = aConnector->workshop();
102 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
103 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
104 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
105 this, SLOT(onOperationActivatedByPreselection()));
107 ModuleBase_IViewer* aViewer = theWshop->viewer();
108 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
109 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
114 PartSet_Module::~PartSet_Module()
116 if (!myDocumentShapeFilter.IsNull())
117 myDocumentShapeFilter.Nullify();
120 void PartSet_Module::registerValidators()
122 //Registering of validators
123 SessionPtr aMgr = ModelAPI_Session::get();
124 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
125 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
126 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
127 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
128 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
129 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
130 aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
131 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
132 aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
134 aFactory->registerValidator("GeomValidators_Edge", new GeomValidators_Edge);
135 aFactory->registerValidator("GeomValidators_EdgeOrVertex",
136 new GeomValidators_EdgeOrVertex);
137 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
139 aFactory->registerValidator("GeomValidators_ConstructionComposite",
140 new GeomValidators_ConstructionComposite);
142 aFactory->registerValidator("PartSet_SketchEntityValidator",
143 new PartSet_SketchEntityValidator);
146 void PartSet_Module::registerFilters()
148 //Registering of selection filters
149 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
150 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
152 //aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
153 //aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
154 //aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
155 //Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
156 //aFactory->registerFilter("NoConstructionSubShapesFilter",
157 // new ModuleBase_FilterCustom(aSelectFilter));
158 //Handle(SelectMgr_Filter) aSelectFilter = new PartSet_FilterSketchEntity(workshop());
159 //aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
162 void PartSet_Module::registerProperties()
164 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
166 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
167 Config_Prop::Integer, SKETCH_WIDTH);
170 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
172 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
173 mySketchMgr->commitNestedSketch(theOperation);
176 if (theOperation->isEditOperation())
178 // the selection is cleared after commit the create operation
179 // in order to do not use the same selected objects in the restarted operation
180 // for common behaviour, the selection is cleared even if the operation is not restarted
181 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
182 if (!aContext.IsNull())
183 aContext->ClearSelected();
185 /// Restart sketcher operations automatically
186 FeaturePtr aFeature = theOperation->feature();
187 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
188 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
189 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
190 myRestartingMode == RM_EmptyFeatureUsed)) {
191 myLastOperationId = theOperation->id();
192 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
194 launchOperation(myLastOperationId);
196 breakOperationSequence();
199 void PartSet_Module::breakOperationSequence()
201 myLastOperationId = "";
202 myLastFeature = FeaturePtr();
203 myRestartingMode = RM_None;
206 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
208 breakOperationSequence();
211 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
213 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
214 mySketchMgr->startSketch(theOperation);
216 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
217 mySketchMgr->startNestedSketch(theOperation);
220 if (myDocumentShapeFilter.IsNull())
221 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
222 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
225 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
227 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
228 mySketchMgr->stopSketch(theOperation);
230 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
231 mySketchMgr->stopNestedSketch(theOperation);
233 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
236 ModuleBase_Operation* PartSet_Module::currentOperation() const
238 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
239 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
240 return anOpMgr->currentOperation();
243 bool PartSet_Module::canUndo() const
245 bool aCanUndo = false;
246 SessionPtr aMgr = ModelAPI_Session::get();
247 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
248 aCanUndo = !aMgr->isOperation();
249 if (!aCanUndo) // check the enable state additionally by sketch manager
250 aCanUndo = aMgr->canUndo();
255 bool PartSet_Module::canRedo() const
257 bool aCanRedo = false;
258 SessionPtr aMgr = ModelAPI_Session::get();
259 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
260 aCanRedo = !aMgr->isOperation();
261 if (!aCanRedo) // check the enable state additionally by sketch manager
262 aCanRedo = aMgr->canRedo();
267 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
269 bool aCanDisplay = false;
270 if (!mySketchMgr->canDisplayObject())
272 CompositeFeaturePtr aSketchFeature = mySketchMgr->activeSketch();
273 if (aSketchFeature.get() != NULL) {
274 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
276 // MPV: the second and third conditions to avoid crash on exit for application
277 if (aFeature.get() != NULL && aFeature->data().get() && aFeature->data()->isValid()) {
278 if (aFeature == aSketchFeature) {
281 else if (aSketchFeature.get() && aSketchFeature->data().get() &&
282 aSketchFeature->data()->isValid()) {
283 for (int i = 0; i < aSketchFeature->numberOfSubs() && !aCanDisplay; i++) {
284 FeaturePtr aSubFeature = aSketchFeature->subFeature(i);
285 std::list<ResultPtr> aResults = aSubFeature->results();
286 std::list<ResultPtr>::const_iterator aIt;
287 for (aIt = aResults.begin(); aIt != aResults.end() && !aCanDisplay; ++aIt) {
288 if (theObject == (*aIt))
291 if (aSubFeature == theObject)
298 aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject);
303 void PartSet_Module::addViewerItems(QMenu* theMenu) const
305 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
306 if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
307 !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
310 ModuleBase_ISelection* aSelection = myWorkshop->selection();
311 QObjectPtrList aObjects = aSelection->selectedPresentations();
312 if (aObjects.size() > 0) {
313 bool hasFeature = false;
314 foreach(ObjectPtr aObject, aObjects)
316 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
317 if (aFeature.get() != NULL) {
322 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
323 XGUI_Workshop* aWorkshop = aConnector->workshop();
324 QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
325 theMenu->addAction(anAction);
329 if (mySketchMgr->canSetAuxiliary(isAuxiliary)) {
330 QAction* anAction = action("AUXILIARY_CMD");
331 theMenu->addAction(anAction);
332 anAction->setChecked(isAuxiliary);
336 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
338 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
339 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
340 // we have to manually activate the sketch label in edit mode
341 aPanel->activateWidget(aPanel->modelWidgets().first());
345 // Restart last operation type
346 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
347 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
348 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
349 // Initialise new line with first point equal to end of previous
350 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
352 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
353 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
354 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
356 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
357 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
358 aWgt->attributeID(), aPoint->x(), aPoint->y());
359 aPanel->activateNextWidget(aPnt2dWgt);
364 // Start editing constraint
365 if (theOperation->isEditOperation()) {
366 // TODO: #391 - to be removed
367 std::string aId = theOperation->id().toStdString();
368 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
369 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
370 // Find and activate widget for management of point for dimension line position
371 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
372 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
373 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
375 aPanel->activateWidget(aPntWgt);
385 void PartSet_Module::onSelectionChanged()
387 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
391 bool isSketcherOp = false;
392 // An edit operation is enable only if the current opeation is the sketch operation
393 if (mySketchMgr->activeSketch()) {
394 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
395 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
398 // Editing of constraints can be done on selection
399 ModuleBase_ISelection* aSelect = myWorkshop->selection();
400 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
401 if (aSelected.size() == 1) {
402 ModuleBase_ViewerPrs aPrs = aSelected.first();
403 ObjectPtr aObject = aPrs.object();
404 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
406 std::string aId = aFeature->getKind();
407 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
408 (aId == SketchPlugin_ConstraintLength::ID()) ||
409 (aId == SketchPlugin_ConstraintDistance::ID())) {
410 editFeature(aFeature);
417 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
419 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
420 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
421 anOpMgr->onKeyReleased(theEvent);
424 void PartSet_Module::onEnterReleased()
426 myRestartingMode = RM_EmptyFeatureUsed;
429 void PartSet_Module::onOperationActivatedByPreselection()
431 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
432 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
433 // Set final definitions if they are necessary
434 //propertyPanelDefined(aOperation);
436 /// Commit sketcher operations automatically
437 anOperation->commit();
441 void PartSet_Module::onNoMoreWidgets()
443 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
445 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
446 if (myRestartingMode != RM_Forbided)
447 myRestartingMode = RM_LastFeatureUsed;
448 anOperation->commit();
453 void PartSet_Module::onVertexSelected()
455 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
456 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
457 /// If last line finished on vertex the lines creation sequence has to be break
458 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
459 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
460 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
461 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
462 bool aFoundWidget = false;
463 bool aFoundObligatory = false;
464 for (; anIt != aLast && !aFoundObligatory; anIt++) {
466 aFoundWidget = *anIt == anActiveWidget;
468 aFoundObligatory = (*anIt)->isObligatory();
470 if (!aFoundObligatory)
471 myRestartingMode = RM_Forbided;
475 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
476 Config_WidgetAPI* theWidgetApi, std::string theParentId)
478 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
479 XGUI_Workshop* aWorkshop = aConnector->workshop();
480 ModuleBase_ModelWidget* aWgt = NULL;
481 if (theType == "sketch-start-label") {
482 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
483 aLabelWgt->setWorkshop(aWorkshop);
484 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
485 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
487 } else if (theType == "sketch-2dpoint_selector") {
488 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
489 aPointWgt->setWorkshop(aWorkshop);
490 aPointWgt->setSketch(mySketchMgr->activeSketch());
491 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
493 } if (theType == "point2ddistance") {
494 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
495 aDistanceWgt->setWorkshop(aWorkshop);
496 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
498 } if (theType == "sketch_shape_selector") {
499 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
500 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
501 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
502 aWgt = aShapeSelectorWgt;
503 } if (theType == "sketch_constraint_shape_selector") {
504 PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
505 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
506 aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
507 aWgt = aConstraintShapeSelectorWgt;
512 void PartSet_Module::createActions()
516 anAction = new QAction(tr("Auxiliary"), this);
517 anAction->setCheckable(true);
518 addAction("AUXILIARY_CMD", anAction);
521 QAction* PartSet_Module::action(const QString& theId) const
523 if (myActions.contains(theId))
524 return myActions[theId];
528 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
530 if (myActions.contains(theId))
531 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
532 theAction->setData(theId);
533 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
534 myActions[theId] = theAction;
537 void PartSet_Module::onAction(bool isChecked)
539 QAction* aAction = static_cast<QAction*>(sender());
540 QString anId = aAction->data().toString();
542 if (anId == "AUXILIARY_CMD") {
543 mySketchMgr->setAuxiliary(isChecked);
547 bool PartSet_Module::deleteObjects()
549 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
550 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
551 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
552 if (!isSketchOp && !isNestedOp)
555 // sketch feature should be skipped, only sub-features can be removed
556 // when sketch operation is active
557 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
559 // selected objects should be collected before the current operation abort because
560 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
561 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
562 XGUI_Workshop* aWorkshop = aConnector->workshop();
563 ModuleBase_ISelection* aSel = aConnector->selection();
564 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
566 // if there are no selected objects in the viewer, that means that the selection in another
567 // place cased this method. It is necessary to return the false value to understande in above
568 // method that delete is not processed
569 if (aSelectedObj.count() == 0)
572 // the active nested sketch operation should be aborted unconditionally
574 anOperation->abort();
576 std::set<FeaturePtr> aRefFeatures;
577 foreach (ObjectPtr aObj, aSelectedObj)
579 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
581 // TODO: check for what there is this condition. It is placed here historicaly because
582 // ther is this condition during remove features.
584 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
585 if (aFeature.get() != NULL) {
586 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
591 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
593 // according to #355 feature, it is not necessary to inform about dependencies during
594 // sketch delete operation
596 if (!aRefFeatures.empty()) {
597 QStringList aRefNames;
598 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
599 aLast = aRefFeatures.end();
600 for (; anIt != aLast; anIt++) {
601 FeaturePtr aFeature = (*anIt);
602 if (aFeature == aSketch)
604 aRefNames.append((*anIt)->name().c_str());
606 if (!aRefNames.empty()) {
607 QString aNames = aRefNames.join(", ");
608 aDescription += aNames.prepend(" ");
610 QMainWindow* aDesktop = aWorkshop->desktop();
611 QMessageBox::StandardButton aRes = QMessageBox::warning(
612 aDesktop, tr("Delete features"),
613 QString(tr("Selected features are used in the following features: %1.\
614 These features will be deleted also. Would you like to continue?")).arg(aNames),
615 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
616 if (aRes != QMessageBox::Yes)
621 SessionPtr aMgr = ModelAPI_Session::get();
622 aMgr->startOperation(aDescription.toStdString());
623 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
624 aLast = aRefFeatures.end();
625 for (; anIt != aLast; anIt++) {
626 FeaturePtr aRefFeature = (*anIt);
627 if (aRefFeature == aSketch)
629 aRefFeature->document()->removeFeature(aRefFeature);
632 foreach (ObjectPtr aObj, aSelectedObj)
634 DocumentPtr aDoc = aObj->document();
635 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
637 // if (aDoc == aMgr->activeDocument()) {
641 //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
642 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
643 if (aFeature.get() != NULL) {
644 aDoc->removeFeature(aFeature);
648 aWorkshop->displayer()->updateViewer();
649 //myDisplayer->updateViewer();
650 aMgr->finishOperation();