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 <ModuleBase_ValidatorLinearEdge.h>
25 #include <ModuleBase_ValidatorLinearEdgeOrVertex.h>
26 #include <ModuleBase_ValidatorFace.h>
27 #include <ModuleBase_ValidatorNoConstructionSubShapes.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);
133 aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
135 aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge);
136 aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex",
137 new ModuleBase_ValidatorLinearEdgeOrVertex);
138 aFactory->registerValidator("ModuleBase_ValidatorFace", new ModuleBase_ValidatorFace);
140 aFactory->registerValidator("ModuleBase_ValidatorNoConstructionSubShapes",
141 new ModuleBase_ValidatorNoConstructionSubShapes);
143 aFactory->registerValidator("PartSet_SketchEntityValidator",
144 new PartSet_SketchEntityValidator);
147 void PartSet_Module::registerFilters()
149 //Registering of selection filters
150 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
151 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
153 //aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
154 //aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
155 //aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
156 //Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
157 //aFactory->registerFilter("NoConstructionSubShapesFilter",
158 // new ModuleBase_FilterCustom(aSelectFilter));
159 //Handle(SelectMgr_Filter) aSelectFilter = new PartSet_FilterSketchEntity(workshop());
160 //aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
163 void PartSet_Module::registerProperties()
165 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
167 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
168 Config_Prop::Integer, SKETCH_WIDTH);
171 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
173 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
174 mySketchMgr->commitNestedSketch(theOperation);
177 if (theOperation->isEditOperation())
179 // the selection is cleared after commit the create operation
180 // in order to do not use the same selected objects in the restarted operation
181 // for common behaviour, the selection is cleared even if the operation is not restarted
182 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
183 if (!aContext.IsNull())
184 aContext->ClearSelected();
186 /// Restart sketcher operations automatically
187 FeaturePtr aFeature = theOperation->feature();
188 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
189 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
190 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
191 myRestartingMode == RM_EmptyFeatureUsed)) {
192 myLastOperationId = theOperation->id();
193 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
195 launchOperation(myLastOperationId);
197 breakOperationSequence();
200 void PartSet_Module::breakOperationSequence()
202 myLastOperationId = "";
203 myLastFeature = FeaturePtr();
204 myRestartingMode = RM_None;
207 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
209 breakOperationSequence();
212 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
214 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
215 mySketchMgr->startSketch(theOperation);
217 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
218 mySketchMgr->startNestedSketch(theOperation);
221 if (myDocumentShapeFilter.IsNull())
222 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
223 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
226 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
228 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
229 mySketchMgr->stopSketch(theOperation);
231 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
232 mySketchMgr->stopNestedSketch(theOperation);
234 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
237 ModuleBase_Operation* PartSet_Module::currentOperation() const
239 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
240 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
241 return anOpMgr->currentOperation();
244 bool PartSet_Module::canUndo() const
246 bool aCanUndo = false;
247 SessionPtr aMgr = ModelAPI_Session::get();
248 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
249 aCanUndo = !aMgr->isOperation();
250 if (!aCanUndo) // check the enable state additionally by sketch manager
251 aCanUndo = aMgr->canUndo();
256 bool PartSet_Module::canRedo() const
258 bool aCanRedo = false;
259 SessionPtr aMgr = ModelAPI_Session::get();
260 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
261 aCanRedo = !aMgr->isOperation();
262 if (!aCanRedo) // check the enable state additionally by sketch manager
263 aCanRedo = aMgr->canRedo();
268 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
270 bool aCanDisplay = false;
271 if (!mySketchMgr->canDisplayObject())
273 CompositeFeaturePtr aSketchFeature = mySketchMgr->activeSketch();
274 if (aSketchFeature.get() != NULL) {
275 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
277 // MPV: the second and third conditions to avoid crash on exit for application
278 if (aFeature.get() != NULL && aFeature->data().get() && aFeature->data()->isValid()) {
279 if (aFeature == aSketchFeature) {
282 else if (aSketchFeature.get() && aSketchFeature->data().get() &&
283 aSketchFeature->data()->isValid()) {
284 for (int i = 0; i < aSketchFeature->numberOfSubs() && !aCanDisplay; i++) {
285 FeaturePtr aSubFeature = aSketchFeature->subFeature(i);
286 std::list<ResultPtr> aResults = aSubFeature->results();
287 std::list<ResultPtr>::const_iterator aIt;
288 for (aIt = aResults.begin(); aIt != aResults.end() && !aCanDisplay; ++aIt) {
289 if (theObject == (*aIt))
292 if (aSubFeature == theObject)
299 aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject);
304 void PartSet_Module::addViewerItems(QMenu* theMenu) const
306 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
307 if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
308 !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
311 ModuleBase_ISelection* aSelection = myWorkshop->selection();
312 QObjectPtrList aObjects = aSelection->selectedPresentations();
313 if (aObjects.size() > 0) {
314 bool hasFeature = false;
315 foreach(ObjectPtr aObject, aObjects)
317 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
318 if (aFeature.get() != NULL) {
323 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
324 XGUI_Workshop* aWorkshop = aConnector->workshop();
325 QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
326 theMenu->addAction(anAction);
330 if (mySketchMgr->canSetAuxiliary(isAuxiliary)) {
331 QAction* anAction = action("AUXILIARY_CMD");
332 theMenu->addAction(anAction);
333 anAction->setChecked(isAuxiliary);
337 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
339 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
340 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
341 // we have to manually activate the sketch label in edit mode
342 aPanel->activateWidget(aPanel->modelWidgets().first());
346 // Restart last operation type
347 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
348 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
349 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
350 // Initialise new line with first point equal to end of previous
351 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
353 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
354 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
355 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
357 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
358 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
359 aWgt->attributeID(), aPoint->x(), aPoint->y());
360 aPanel->activateNextWidget(aPnt2dWgt);
365 // Start editing constraint
366 if (theOperation->isEditOperation()) {
367 // TODO: #391 - to be removed
368 std::string aId = theOperation->id().toStdString();
369 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
370 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
371 // Find and activate widget for management of point for dimension line position
372 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
373 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
374 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
376 aPanel->activateWidget(aPntWgt);
386 void PartSet_Module::onSelectionChanged()
388 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
392 bool isSketcherOp = false;
393 // An edit operation is enable only if the current opeation is the sketch operation
394 if (mySketchMgr->activeSketch()) {
395 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
396 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
399 // Editing of constraints can be done on selection
400 ModuleBase_ISelection* aSelect = myWorkshop->selection();
401 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
402 if (aSelected.size() == 1) {
403 ModuleBase_ViewerPrs aPrs = aSelected.first();
404 ObjectPtr aObject = aPrs.object();
405 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
407 std::string aId = aFeature->getKind();
408 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
409 (aId == SketchPlugin_ConstraintLength::ID()) ||
410 (aId == SketchPlugin_ConstraintDistance::ID())) {
411 editFeature(aFeature);
418 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
420 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
421 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
422 anOpMgr->onKeyReleased(theEvent);
425 void PartSet_Module::onEnterReleased()
427 myRestartingMode = RM_EmptyFeatureUsed;
430 void PartSet_Module::onOperationActivatedByPreselection()
432 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
433 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
434 // Set final definitions if they are necessary
435 //propertyPanelDefined(aOperation);
437 /// Commit sketcher operations automatically
438 anOperation->commit();
442 void PartSet_Module::onNoMoreWidgets()
444 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
446 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
447 if (myRestartingMode != RM_Forbided)
448 myRestartingMode = RM_LastFeatureUsed;
449 anOperation->commit();
454 void PartSet_Module::onVertexSelected()
456 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
457 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
458 /// If last line finished on vertex the lines creation sequence has to be break
459 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
460 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
461 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
462 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
463 bool aFoundWidget = false;
464 bool aFoundObligatory = false;
465 for (; anIt != aLast && !aFoundObligatory; anIt++) {
467 aFoundWidget = *anIt == anActiveWidget;
469 aFoundObligatory = (*anIt)->isObligatory();
471 if (!aFoundObligatory)
472 myRestartingMode = RM_Forbided;
476 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
477 Config_WidgetAPI* theWidgetApi, std::string theParentId)
479 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
480 XGUI_Workshop* aWorkshop = aConnector->workshop();
481 ModuleBase_ModelWidget* aWgt = NULL;
482 if (theType == "sketch-start-label") {
483 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
484 aLabelWgt->setWorkshop(aWorkshop);
485 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
486 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
488 } else if (theType == "sketch-2dpoint_selector") {
489 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
490 aPointWgt->setWorkshop(aWorkshop);
491 aPointWgt->setSketch(mySketchMgr->activeSketch());
492 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
494 } if (theType == "point2ddistance") {
495 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
496 aDistanceWgt->setWorkshop(aWorkshop);
497 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
499 } if (theType == "sketch_shape_selector") {
500 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
501 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
502 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
503 aWgt = aShapeSelectorWgt;
504 } if (theType == "sketch_constraint_shape_selector") {
505 PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
506 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
507 aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
508 aWgt = aConstraintShapeSelectorWgt;
513 void PartSet_Module::createActions()
517 anAction = new QAction(tr("Auxiliary"), this);
518 anAction->setCheckable(true);
519 addAction("AUXILIARY_CMD", anAction);
522 QAction* PartSet_Module::action(const QString& theId) const
524 if (myActions.contains(theId))
525 return myActions[theId];
529 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
531 if (myActions.contains(theId))
532 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
533 theAction->setData(theId);
534 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
535 myActions[theId] = theAction;
538 void PartSet_Module::onAction(bool isChecked)
540 QAction* aAction = static_cast<QAction*>(sender());
541 QString anId = aAction->data().toString();
543 if (anId == "AUXILIARY_CMD") {
544 mySketchMgr->setAuxiliary(isChecked);
548 bool PartSet_Module::deleteObjects()
550 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
551 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
552 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
553 if (!isSketchOp && !isNestedOp)
556 // sketch feature should be skipped, only sub-features can be removed
557 // when sketch operation is active
558 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
560 // selected objects should be collected before the current operation abort because
561 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
562 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
563 XGUI_Workshop* aWorkshop = aConnector->workshop();
564 ModuleBase_ISelection* aSel = aConnector->selection();
565 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
567 // if there are no selected objects in the viewer, that means that the selection in another
568 // place cased this method. It is necessary to return the false value to understande in above
569 // method that delete is not processed
570 if (aSelectedObj.count() == 0)
573 // the active nested sketch operation should be aborted unconditionally
575 anOperation->abort();
577 std::set<FeaturePtr> aRefFeatures;
578 foreach (ObjectPtr aObj, aSelectedObj)
580 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
582 // TODO: check for what there is this condition. It is placed here historicaly because
583 // ther is this condition during remove features.
585 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
586 if (aFeature.get() != NULL) {
587 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
592 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
594 // according to #355 feature, it is not necessary to inform about dependencies during
595 // sketch delete operation
597 if (!aRefFeatures.empty()) {
598 QStringList aRefNames;
599 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
600 aLast = aRefFeatures.end();
601 for (; anIt != aLast; anIt++) {
602 FeaturePtr aFeature = (*anIt);
603 if (aFeature == aSketch)
605 aRefNames.append((*anIt)->name().c_str());
607 if (!aRefNames.empty()) {
608 QString aNames = aRefNames.join(", ");
609 aDescription += aNames.prepend(" ");
611 QMainWindow* aDesktop = aWorkshop->desktop();
612 QMessageBox::StandardButton aRes = QMessageBox::warning(
613 aDesktop, tr("Delete features"),
614 QString(tr("Selected features are used in the following features: %1.\
615 These features will be deleted also. Would you like to continue?")).arg(aNames),
616 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
617 if (aRes != QMessageBox::Yes)
622 SessionPtr aMgr = ModelAPI_Session::get();
623 aMgr->startOperation(aDescription.toStdString());
624 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
625 aLast = aRefFeatures.end();
626 for (; anIt != aLast; anIt++) {
627 FeaturePtr aRefFeature = (*anIt);
628 if (aRefFeature == aSketch)
630 aRefFeature->document()->removeFeature(aRefFeature);
633 foreach (ObjectPtr aObj, aSelectedObj)
635 DocumentPtr aDoc = aObj->document();
636 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
638 // if (aDoc == aMgr->activeDocument()) {
642 //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
643 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
644 if (aFeature.get() != NULL) {
645 aDoc->removeFeature(aFeature);
649 aWorkshop->displayer()->updateViewer();
650 //myDisplayer->updateViewer();
651 aMgr->finishOperation();