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>
70 #include <AIS_Dimension.hxx>
73 #include <QMouseEvent>
76 #include <QApplication>
77 #include <QMessageBox>
78 #include <QMainWindow>
80 #include <GeomAlgoAPI_FaceBuilder.h>
81 #include <GeomDataAPI_Dir.h>
87 /*!Create and return new instance of XGUI_Module*/
88 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
90 return new PartSet_Module(theWshop);
93 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
94 : ModuleBase_IModule(theWshop),
95 myRestartingMode(RM_None), myVisualLayerId(0)
97 //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
98 mySketchMgr = new PartSet_SketcherMgr(this);
100 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
101 XGUI_Workshop* aWorkshop = aConnector->workshop();
103 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
104 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
105 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
106 this, SLOT(onOperationActivatedByPreselection()));
108 ModuleBase_IViewer* aViewer = theWshop->viewer();
109 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
110 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
115 PartSet_Module::~PartSet_Module()
117 if (!myDocumentShapeFilter.IsNull())
118 myDocumentShapeFilter.Nullify();
121 void PartSet_Module::registerValidators()
123 //Registering of validators
124 SessionPtr aMgr = ModelAPI_Session::get();
125 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
126 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
127 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
128 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
129 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
130 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
131 aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
132 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
133 aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
135 aFactory->registerValidator("GeomValidators_Edge", new GeomValidators_Edge);
136 aFactory->registerValidator("GeomValidators_EdgeOrVertex",
137 new GeomValidators_EdgeOrVertex);
138 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
140 aFactory->registerValidator("GeomValidators_ConstructionComposite",
141 new GeomValidators_ConstructionComposite);
143 aFactory->registerValidator("PartSet_SketchEntityValidator",
144 new PartSet_SketchEntityValidator);
146 aFactory->registerValidator("PartSet_SameTypeAttr",
147 new PartSet_SameTypeAttrValidator);
150 void PartSet_Module::registerFilters()
152 //Registering of selection filters
153 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
154 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
156 //aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
157 //aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
158 //aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
159 //Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
160 //aFactory->registerFilter("NoConstructionSubShapesFilter",
161 // new ModuleBase_FilterCustom(aSelectFilter));
162 //Handle(SelectMgr_Filter) aSelectFilter = new PartSet_FilterSketchEntity(workshop());
163 //aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
166 void PartSet_Module::registerProperties()
168 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
170 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
171 Config_Prop::Integer, SKETCH_WIDTH);
174 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
176 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
177 mySketchMgr->commitNestedSketch(theOperation);
180 if (theOperation->isEditOperation())
182 // the selection is cleared after commit the create operation
183 // in order to do not use the same selected objects in the restarted operation
184 // for common behaviour, the selection is cleared even if the operation is not restarted
185 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
186 if (!aContext.IsNull())
187 aContext->ClearSelected();
189 /// Restart sketcher operations automatically
190 FeaturePtr aFeature = theOperation->feature();
191 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
192 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
193 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
194 myRestartingMode == RM_EmptyFeatureUsed)) {
195 myLastOperationId = theOperation->id();
196 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
198 launchOperation(myLastOperationId);
200 breakOperationSequence();
203 void PartSet_Module::breakOperationSequence()
205 myLastOperationId = "";
206 myLastFeature = FeaturePtr();
207 myRestartingMode = RM_None;
210 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
212 breakOperationSequence();
215 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
217 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
218 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
219 aViewer->AddZLayer(myVisualLayerId);
220 mySketchMgr->startSketch(theOperation);
222 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
223 mySketchMgr->startNestedSketch(theOperation);
226 if (myDocumentShapeFilter.IsNull())
227 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
228 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
231 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
233 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
234 mySketchMgr->stopSketch(theOperation);
235 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
236 aViewer->RemoveZLayer(myVisualLayerId);
239 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
240 mySketchMgr->stopNestedSketch(theOperation);
242 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
245 ModuleBase_Operation* PartSet_Module::currentOperation() const
247 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
248 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
249 return anOpMgr->currentOperation();
252 bool PartSet_Module::canUndo() const
254 bool aCanUndo = false;
255 SessionPtr aMgr = ModelAPI_Session::get();
256 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
257 aCanUndo = !aMgr->isOperation();
258 if (!aCanUndo) // check the enable state additionally by sketch manager
259 aCanUndo = aMgr->canUndo();
264 bool PartSet_Module::canRedo() const
266 bool aCanRedo = false;
267 SessionPtr aMgr = ModelAPI_Session::get();
268 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
269 aCanRedo = !aMgr->isOperation();
270 if (!aCanRedo) // check the enable state additionally by sketch manager
271 aCanRedo = aMgr->canRedo();
276 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
278 bool aCanDisplay = false;
279 if (!mySketchMgr->canDisplayObject())
281 CompositeFeaturePtr aSketchFeature = mySketchMgr->activeSketch();
282 if (aSketchFeature.get() != NULL) {
283 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
285 // MPV: the second and third conditions to avoid crash on exit for application
286 if (aFeature.get() != NULL && aFeature->data().get() && aFeature->data()->isValid()) {
287 if (aFeature == aSketchFeature) {
290 else if (aSketchFeature.get() && aSketchFeature->data().get() &&
291 aSketchFeature->data()->isValid()) {
292 for (int i = 0; i < aSketchFeature->numberOfSubs() && !aCanDisplay; i++) {
293 FeaturePtr aSubFeature = aSketchFeature->subFeature(i);
294 std::list<ResultPtr> aResults = aSubFeature->results();
295 std::list<ResultPtr>::const_iterator aIt;
296 for (aIt = aResults.begin(); aIt != aResults.end() && !aCanDisplay; ++aIt) {
297 if (theObject == (*aIt))
300 if (aSubFeature == theObject)
307 aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject);
312 void PartSet_Module::addViewerItems(QMenu* theMenu) const
314 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
315 if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
316 !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
319 ModuleBase_ISelection* aSelection = myWorkshop->selection();
320 QObjectPtrList aObjects = aSelection->selectedPresentations();
321 if (aObjects.size() > 0) {
322 bool hasFeature = false;
323 foreach(ObjectPtr aObject, aObjects)
325 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
326 if (aFeature.get() != NULL) {
331 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
332 XGUI_Workshop* aWorkshop = aConnector->workshop();
333 QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
334 theMenu->addAction(anAction);
338 if (mySketchMgr->canSetAuxiliary(isAuxiliary)) {
339 QAction* anAction = action("AUXILIARY_CMD");
340 theMenu->addAction(anAction);
341 anAction->setChecked(isAuxiliary);
345 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
347 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
348 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
349 // we have to manually activate the sketch label in edit mode
350 aPanel->activateWidget(aPanel->modelWidgets().first());
354 // Restart last operation type
355 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
356 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
357 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
358 // Initialise new line with first point equal to end of previous
359 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
361 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
362 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
363 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
365 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
366 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
367 aWgt->attributeID(), aPoint->x(), aPoint->y());
368 aPanel->activateNextWidget(aPnt2dWgt);
373 // Start editing constraint
374 if (theOperation->isEditOperation()) {
375 // TODO: #391 - to be removed
376 std::string aId = theOperation->id().toStdString();
377 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
378 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
379 // Find and activate widget for management of point for dimension line position
380 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
381 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
382 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
384 aPanel->activateWidget(aPntWgt);
394 void PartSet_Module::onSelectionChanged()
396 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
400 bool isSketcherOp = false;
401 // An edit operation is enable only if the current opeation is the sketch operation
402 if (mySketchMgr->activeSketch()) {
403 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
404 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
407 // Editing of constraints can be done on selection
408 ModuleBase_ISelection* aSelect = myWorkshop->selection();
409 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
410 if (aSelected.size() == 1) {
411 ModuleBase_ViewerPrs aPrs = aSelected.first();
412 ObjectPtr aObject = aPrs.object();
413 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
415 std::string aId = aFeature->getKind();
416 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
417 (aId == SketchPlugin_ConstraintLength::ID()) ||
418 (aId == SketchPlugin_ConstraintDistance::ID())) {
419 editFeature(aFeature);
426 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
428 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
429 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
430 anOpMgr->onKeyReleased(theEvent);
433 void PartSet_Module::onEnterReleased()
435 myRestartingMode = RM_EmptyFeatureUsed;
438 void PartSet_Module::onOperationActivatedByPreselection()
440 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
441 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
442 // Set final definitions if they are necessary
443 //propertyPanelDefined(aOperation);
445 /// Commit sketcher operations automatically
446 anOperation->commit();
450 void PartSet_Module::onNoMoreWidgets()
452 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
454 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
455 if (myRestartingMode != RM_Forbided)
456 myRestartingMode = RM_LastFeatureUsed;
457 anOperation->commit();
462 void PartSet_Module::onVertexSelected()
464 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
465 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
466 /// If last line finished on vertex the lines creation sequence has to be break
467 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
468 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
469 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
470 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
471 bool aFoundWidget = false;
472 bool aFoundObligatory = false;
473 for (; anIt != aLast && !aFoundObligatory; anIt++) {
475 aFoundWidget = *anIt == anActiveWidget;
477 aFoundObligatory = (*anIt)->isObligatory();
479 if (!aFoundObligatory)
480 myRestartingMode = RM_Forbided;
484 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
485 Config_WidgetAPI* theWidgetApi, std::string theParentId)
487 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
488 XGUI_Workshop* aWorkshop = aConnector->workshop();
489 ModuleBase_ModelWidget* aWgt = NULL;
490 if (theType == "sketch-start-label") {
491 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
492 aLabelWgt->setWorkshop(aWorkshop);
493 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
494 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
496 } else if (theType == "sketch-2dpoint_selector") {
497 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
498 aPointWgt->setWorkshop(aWorkshop);
499 aPointWgt->setSketch(mySketchMgr->activeSketch());
500 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
502 } if (theType == "point2ddistance") {
503 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
504 aDistanceWgt->setWorkshop(aWorkshop);
505 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
507 } if (theType == "sketch_shape_selector") {
508 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
509 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
510 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
511 aWgt = aShapeSelectorWgt;
512 } if (theType == "sketch_constraint_shape_selector") {
513 PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
514 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
515 aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
516 aWgt = aConstraintShapeSelectorWgt;
521 void PartSet_Module::createActions()
525 anAction = new QAction(tr("Auxiliary"), this);
526 anAction->setCheckable(true);
527 addAction("AUXILIARY_CMD", anAction);
530 QAction* PartSet_Module::action(const QString& theId) const
532 if (myActions.contains(theId))
533 return myActions[theId];
537 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
539 if (myActions.contains(theId))
540 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
541 theAction->setData(theId);
542 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
543 myActions[theId] = theAction;
546 void PartSet_Module::onAction(bool isChecked)
548 QAction* aAction = static_cast<QAction*>(sender());
549 QString anId = aAction->data().toString();
551 if (anId == "AUXILIARY_CMD") {
552 mySketchMgr->setAuxiliary(isChecked);
556 bool PartSet_Module::deleteObjects()
558 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
559 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
560 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
561 if (!isSketchOp && !isNestedOp)
564 // sketch feature should be skipped, only sub-features can be removed
565 // when sketch operation is active
566 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
568 // selected objects should be collected before the current operation abort because
569 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
570 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
571 XGUI_Workshop* aWorkshop = aConnector->workshop();
572 ModuleBase_ISelection* aSel = aConnector->selection();
573 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
575 // if there are no selected objects in the viewer, that means that the selection in another
576 // place cased this method. It is necessary to return the false value to understande in above
577 // method that delete is not processed
578 if (aSelectedObj.count() == 0)
581 // the active nested sketch operation should be aborted unconditionally
583 anOperation->abort();
585 std::set<FeaturePtr> aRefFeatures;
586 foreach (ObjectPtr aObj, aSelectedObj)
588 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
590 // TODO: check for what there is this condition. It is placed here historicaly because
591 // ther is this condition during remove features.
593 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
594 if (aFeature.get() != NULL) {
595 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
600 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
602 // according to #355 feature, it is not necessary to inform about dependencies during
603 // sketch delete operation
605 if (!aRefFeatures.empty()) {
606 QStringList aRefNames;
607 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
608 aLast = aRefFeatures.end();
609 for (; anIt != aLast; anIt++) {
610 FeaturePtr aFeature = (*anIt);
611 if (aFeature == aSketch)
613 aRefNames.append((*anIt)->name().c_str());
615 if (!aRefNames.empty()) {
616 QString aNames = aRefNames.join(", ");
617 aDescription += aNames.prepend(" ");
619 QMainWindow* aDesktop = aWorkshop->desktop();
620 QMessageBox::StandardButton aRes = QMessageBox::warning(
621 aDesktop, tr("Delete features"),
622 QString(tr("Selected features are used in the following features: %1.\
623 These features will be deleted also. Would you like to continue?")).arg(aNames),
624 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
625 if (aRes != QMessageBox::Yes)
630 SessionPtr aMgr = ModelAPI_Session::get();
631 aMgr->startOperation(aDescription.toStdString());
632 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
633 aLast = aRefFeatures.end();
634 for (; anIt != aLast; anIt++) {
635 FeaturePtr aRefFeature = (*anIt);
636 if (aRefFeature == aSketch)
638 aRefFeature->document()->removeFeature(aRefFeature);
641 foreach (ObjectPtr aObj, aSelectedObj)
643 DocumentPtr aDoc = aObj->document();
644 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
646 // if (aDoc == aMgr->activeDocument()) {
650 //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
651 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
652 if (aFeature.get() != NULL) {
653 aDoc->removeFeature(aFeature);
657 aWorkshop->displayer()->updateViewer();
658 //myDisplayer->updateViewer();
659 aMgr->finishOperation();
665 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
667 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
668 if (!anAIS.IsNull()) {
669 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
670 if (!aDim.IsNull()) {
671 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
672 aCtx->SetZLayer(aDim, myVisualLayerId);