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>
27 #include <PartSet_FilterSketchEntity.h>
29 #include <ModelAPI_Object.h>
30 #include <ModelAPI_Events.h>
31 #include <ModelAPI_Validator.h>
32 #include <ModelAPI_Data.h>
33 #include <ModelAPI_Session.h>
34 #include <ModelAPI_ShapeValidator.h>
36 #include <GeomDataAPI_Point2D.h>
37 #include <GeomDataAPI_Point.h>
38 #include <GeomDataAPI_Dir.h>
40 #include <XGUI_Displayer.h>
41 #include <XGUI_Workshop.h>
42 #include <XGUI_OperationMgr.h>
43 #include <XGUI_PropertyPanel.h>
44 #include <XGUI_ModuleConnector.h>
45 #include <XGUI_ContextMenuMgr.h>
46 #include <XGUI_Tools.h>
48 #include <SketchPlugin_Feature.h>
49 #include <SketchPlugin_Sketch.h>
50 #include <SketchPlugin_Line.h>
51 //#include <SketchPlugin_Arc.h>
52 //#include <SketchPlugin_Circle.h>
53 #include <SketchPlugin_ConstraintLength.h>
54 #include <SketchPlugin_ConstraintDistance.h>
55 #include <SketchPlugin_ConstraintParallel.h>
56 #include <SketchPlugin_ConstraintPerpendicular.h>
57 #include <SketchPlugin_ConstraintRadius.h>
58 //#include <SketchPlugin_ConstraintRigid.h>
60 #include <Events_Loop.h>
61 #include <Config_PropManager.h>
63 #include <StdSelect_TypeOfFace.hxx>
64 #include <TopoDS_Vertex.hxx>
66 #include <TopoDS_Shape.hxx>
67 #include <BRep_Tool.hxx>
70 #include <QMouseEvent>
73 #include <QApplication>
74 #include <QMessageBox>
75 #include <QMainWindow>
77 #include <GeomAlgoAPI_FaceBuilder.h>
78 #include <GeomDataAPI_Dir.h>
84 /*!Create and return new instance of XGUI_Module*/
85 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
87 return new PartSet_Module(theWshop);
90 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
91 : ModuleBase_IModule(theWshop),
92 myRestartingMode(RM_None)
94 //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
95 mySketchMgr = new PartSet_SketcherMgr(this);
97 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
98 XGUI_Workshop* aWorkshop = aConnector->workshop();
100 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
101 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
102 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
103 this, SLOT(onOperationActivatedByPreselection()));
105 ModuleBase_IViewer* aViewer = theWshop->viewer();
106 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
107 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
112 PartSet_Module::~PartSet_Module()
114 if (!myDocumentShapeFilter.IsNull())
115 myDocumentShapeFilter.Nullify();
118 void PartSet_Module::registerValidators()
120 //Registering of validators
121 SessionPtr aMgr = ModelAPI_Session::get();
122 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
123 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
124 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
125 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
126 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
127 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
128 aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
129 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
130 aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
131 aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
133 aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge);
134 aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex",
135 new ModuleBase_ValidatorLinearEdgeOrVertex);
138 void PartSet_Module::registerFilters()
140 //Registering of selection filters
141 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
142 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
144 aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
145 aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
146 aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
147 Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
148 aFactory->registerFilter("NoConstructionSubShapesFilter",
149 new ModuleBase_FilterCustom(aSelectFilter));
150 aSelectFilter = new PartSet_FilterSketchEntity(workshop());
151 aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
154 void PartSet_Module::registerProperties()
156 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
158 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
159 Config_Prop::Integer, SKETCH_WIDTH);
162 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
164 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
165 mySketchMgr->commitNestedSketch(theOperation);
168 if (theOperation->isEditOperation())
170 // the selection is cleared after commit the create operation
171 // in order to do not use the same selected objects in the restarted operation
172 // for common behaviour, the selection is cleared even if the operation is not restarted
173 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
174 if (!aContext.IsNull())
175 aContext->ClearSelected();
177 /// Restart sketcher operations automatically
178 FeaturePtr aFeature = theOperation->feature();
179 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
180 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
181 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
182 myRestartingMode == RM_EmptyFeatureUsed)) {
183 myLastOperationId = theOperation->id();
184 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
186 launchOperation(myLastOperationId);
188 breakOperationSequence();
191 void PartSet_Module::breakOperationSequence()
193 myLastOperationId = "";
194 myLastFeature = FeaturePtr();
195 myRestartingMode = RM_None;
198 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
200 breakOperationSequence();
203 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
205 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
206 mySketchMgr->startSketch(theOperation);
208 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
209 mySketchMgr->startNestedSketch(theOperation);
212 if (myDocumentShapeFilter.IsNull())
213 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
214 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
217 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
219 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
220 mySketchMgr->stopSketch(theOperation);
222 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
223 mySketchMgr->stopNestedSketch(theOperation);
225 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
228 ModuleBase_Operation* PartSet_Module::currentOperation() const
230 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
231 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
232 return anOpMgr->currentOperation();
235 bool PartSet_Module::canUndo() const
237 bool aCanUndo = false;
238 SessionPtr aMgr = ModelAPI_Session::get();
239 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
240 aCanUndo = !aMgr->isOperation();
241 if (!aCanUndo) // check the enable state additionally by sketch manager
242 aCanUndo = aMgr->canUndo();
247 bool PartSet_Module::canRedo() const
249 bool aCanRedo = false;
250 SessionPtr aMgr = ModelAPI_Session::get();
251 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
252 aCanRedo = !aMgr->isOperation();
253 if (!aCanRedo) // check the enable state additionally by sketch manager
254 aCanRedo = aMgr->canRedo();
259 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
261 bool aCanDisplay = false;
262 if (!mySketchMgr->canDisplayObject())
264 CompositeFeaturePtr aSketchFeature = mySketchMgr->activeSketch();
265 if (aSketchFeature.get() != NULL) {
266 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
268 // MPV: the second and third conditions to avoid crash on exit for application
269 if (aFeature.get() != NULL && aFeature->data().get() && aFeature->data()->isValid()) {
270 if (aFeature == aSketchFeature) {
273 else if (aSketchFeature.get() && aSketchFeature->data().get() &&
274 aSketchFeature->data()->isValid()) {
275 for (int i = 0; i < aSketchFeature->numberOfSubs() && !aCanDisplay; i++) {
276 FeaturePtr aSubFeature = aSketchFeature->subFeature(i);
277 std::list<ResultPtr> aResults = aSubFeature->results();
278 std::list<ResultPtr>::const_iterator aIt;
279 for (aIt = aResults.begin(); aIt != aResults.end() && !aCanDisplay; ++aIt) {
280 if (theObject == (*aIt))
283 if (aSubFeature == theObject)
290 aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject);
295 void PartSet_Module::addViewerItems(QMenu* theMenu) const
297 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
298 if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
299 !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
302 ModuleBase_ISelection* aSelection = myWorkshop->selection();
303 QObjectPtrList aObjects = aSelection->selectedPresentations();
304 if (aObjects.size() > 0) {
305 bool hasFeature = false;
306 foreach(ObjectPtr aObject, aObjects)
308 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
309 if (aFeature.get() != NULL) {
314 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
315 XGUI_Workshop* aWorkshop = aConnector->workshop();
316 QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
317 theMenu->addAction(anAction);
321 if (mySketchMgr->canSetAuxiliary(isAuxiliary)) {
322 QAction* anAction = action("AUXILIARY_CMD");
323 theMenu->addAction(anAction);
324 anAction->setChecked(isAuxiliary);
328 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
330 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
331 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
332 // we have to manually activate the sketch label in edit mode
333 aPanel->activateWidget(aPanel->modelWidgets().first());
337 // Restart last operation type
338 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
339 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
340 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
341 // Initialise new line with first point equal to end of previous
342 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
344 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
345 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
346 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
348 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
349 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
350 aWgt->attributeID(), aPoint->x(), aPoint->y());
351 aPanel->activateNextWidget(aPnt2dWgt);
356 // Start editing constraint
357 if (theOperation->isEditOperation()) {
358 // TODO: #391 - to be removed
359 std::string aId = theOperation->id().toStdString();
360 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
361 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
362 // Find and activate widget for management of point for dimension line position
363 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
364 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
365 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
367 aPanel->activateWidget(aPntWgt);
377 void PartSet_Module::onSelectionChanged()
379 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
383 bool isSketcherOp = false;
384 // An edit operation is enable only if the current opeation is the sketch operation
385 if (mySketchMgr->activeSketch()) {
386 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
387 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
390 // Editing of constraints can be done on selection
391 ModuleBase_ISelection* aSelect = myWorkshop->selection();
392 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
393 if (aSelected.size() == 1) {
394 ModuleBase_ViewerPrs aPrs = aSelected.first();
395 ObjectPtr aObject = aPrs.object();
396 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
398 std::string aId = aFeature->getKind();
399 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
400 (aId == SketchPlugin_ConstraintLength::ID()) ||
401 (aId == SketchPlugin_ConstraintDistance::ID())) {
402 editFeature(aFeature);
409 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
411 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
412 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
413 anOpMgr->onKeyReleased(theEvent);
416 void PartSet_Module::onEnterReleased()
418 myRestartingMode = RM_EmptyFeatureUsed;
421 void PartSet_Module::onOperationActivatedByPreselection()
423 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
424 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
425 // Set final definitions if they are necessary
426 //propertyPanelDefined(aOperation);
428 /// Commit sketcher operations automatically
429 anOperation->commit();
433 void PartSet_Module::onNoMoreWidgets()
435 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
437 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
438 if (myRestartingMode != RM_Forbided)
439 myRestartingMode = RM_LastFeatureUsed;
440 anOperation->commit();
445 void PartSet_Module::onVertexSelected()
447 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
448 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
449 /// If last line finished on vertex the lines creation sequence has to be break
450 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
451 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
452 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
453 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
454 bool aFoundWidget = false;
455 bool aFoundObligatory = false;
456 for (; anIt != aLast && !aFoundObligatory; anIt++) {
458 aFoundWidget = *anIt == anActiveWidget;
460 aFoundObligatory = (*anIt)->isObligatory();
462 if (!aFoundObligatory)
463 myRestartingMode = RM_Forbided;
467 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
468 Config_WidgetAPI* theWidgetApi, std::string theParentId)
470 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
471 XGUI_Workshop* aWorkshop = aConnector->workshop();
472 ModuleBase_ModelWidget* aWgt = NULL;
473 if (theType == "sketch-start-label") {
474 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
475 aLabelWgt->setWorkshop(aWorkshop);
476 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
477 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
479 } else if (theType == "sketch-2dpoint_selector") {
480 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
481 aPointWgt->setWorkshop(aWorkshop);
482 aPointWgt->setSketch(mySketchMgr->activeSketch());
483 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
485 } if (theType == "point2ddistance") {
486 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
487 aDistanceWgt->setWorkshop(aWorkshop);
488 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
490 } if (theType == "sketch_shape_selector") {
491 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
492 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
493 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
494 aWgt = aShapeSelectorWgt;
495 } if (theType == "sketch_constraint_shape_selector") {
496 PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
497 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
498 aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
499 aWgt = aConstraintShapeSelectorWgt;
504 void PartSet_Module::createActions()
508 anAction = new QAction(tr("Auxiliary"), this);
509 anAction->setCheckable(true);
510 addAction("AUXILIARY_CMD", anAction);
513 QAction* PartSet_Module::action(const QString& theId) const
515 if (myActions.contains(theId))
516 return myActions[theId];
520 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
522 if (myActions.contains(theId))
523 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
524 theAction->setData(theId);
525 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
526 myActions[theId] = theAction;
529 void PartSet_Module::onAction(bool isChecked)
531 QAction* aAction = static_cast<QAction*>(sender());
532 QString anId = aAction->data().toString();
534 if (anId == "AUXILIARY_CMD") {
535 mySketchMgr->setAuxiliary(isChecked);
539 bool PartSet_Module::deleteObjects()
541 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
542 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
543 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
544 if (!isSketchOp && !isNestedOp)
547 // sketch feature should be skipped, only sub-features can be removed
548 // when sketch operation is active
549 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
551 // selected objects should be collected before the current operation abort because
552 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
553 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
554 XGUI_Workshop* aWorkshop = aConnector->workshop();
555 ModuleBase_ISelection* aSel = aConnector->selection();
556 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
558 // if there are no selected objects in the viewer, that means that the selection in another
559 // place cased this method. It is necessary to return the false value to understande in above
560 // method that delete is not processed
561 if (aSelectedObj.count() == 0)
565 anOperation->abort();
567 // the active nested sketch operation should be aborted unconditionally
568 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
569 anOperation->abort();
571 std::set<FeaturePtr> aRefFeatures;
572 foreach (ObjectPtr aObj, aSelectedObj)
574 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
576 // TODO: check for what there is this condition. It is placed here historicaly because
577 // ther is this condition during remove features.
579 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
580 if (aFeature.get() != NULL) {
581 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
586 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
588 // according to #355 feature, it is not necessary to inform about dependencies during
589 // sketch delete operation
591 if (!aRefFeatures.empty()) {
592 QStringList aRefNames;
593 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
594 aLast = aRefFeatures.end();
595 for (; anIt != aLast; anIt++) {
596 FeaturePtr aFeature = (*anIt);
597 if (aFeature == aSketch)
599 aRefNames.append((*anIt)->name().c_str());
601 if (!aRefNames.empty()) {
602 QString aNames = aRefNames.join(", ");
603 aDescription += aNames.prepend(" ");
605 QMainWindow* aDesktop = aWorkshop->desktop();
606 QMessageBox::StandardButton aRes = QMessageBox::warning(
607 aDesktop, tr("Delete features"),
608 QString(tr("Selected features are used in the following features: %1.\
609 These features will be deleted also. Would you like to continue?")).arg(aNames),
610 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
611 if (aRes != QMessageBox::Yes)
616 SessionPtr aMgr = ModelAPI_Session::get();
617 aMgr->startOperation(aDescription.toStdString());
618 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
619 aLast = aRefFeatures.end();
620 for (; anIt != aLast; anIt++) {
621 FeaturePtr aRefFeature = (*anIt);
622 if (aRefFeature == aSketch)
624 aRefFeature->document()->removeFeature(aRefFeature);
627 foreach (ObjectPtr aObj, aSelectedObj)
629 DocumentPtr aDoc = aObj->document();
630 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
632 // if (aDoc == aMgr->activeDocument()) {
636 //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
637 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
638 if (aFeature.get() != NULL) {
639 aDoc->removeFeature(aFeature);
643 aWorkshop->displayer()->updateViewer();
644 //myDisplayer->updateViewer();
645 aMgr->finishOperation();