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 // the display should be possible almost always, with exception of some specific cases
280 bool aCanDisplay = true;
282 if (mySketchMgr->activeSketch()) {
283 aCanDisplay = mySketchMgr->canDisplayObject(theObject);
288 void PartSet_Module::addViewerItems(QMenu* theMenu) const
290 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
291 if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
292 !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
295 ModuleBase_ISelection* aSelection = myWorkshop->selection();
296 QObjectPtrList aObjects = aSelection->selectedPresentations();
297 if (aObjects.size() > 0) {
298 bool hasFeature = false;
299 foreach(ObjectPtr aObject, aObjects)
301 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
302 if (aFeature.get() != NULL) {
307 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
308 XGUI_Workshop* aWorkshop = aConnector->workshop();
309 QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
310 theMenu->addAction(anAction);
314 if (mySketchMgr->canSetAuxiliary(isAuxiliary)) {
315 QAction* anAction = action("AUXILIARY_CMD");
316 theMenu->addAction(anAction);
317 anAction->setChecked(isAuxiliary);
321 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
323 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
324 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
325 // we have to manually activate the sketch label in edit mode
326 aPanel->activateWidget(aPanel->modelWidgets().first());
330 // Restart last operation type
331 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
332 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
333 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
334 // Initialise new line with first point equal to end of previous
335 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
337 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
338 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
339 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
341 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
342 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
343 aWgt->attributeID(), aPoint->x(), aPoint->y());
344 aPanel->activateNextWidget(aPnt2dWgt);
349 // Start editing constraint
350 if (theOperation->isEditOperation()) {
351 // TODO: #391 - to be removed
352 std::string aId = theOperation->id().toStdString();
353 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
354 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
355 // Find and activate widget for management of point for dimension line position
356 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
357 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
358 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
360 aPanel->activateWidget(aPntWgt);
370 void PartSet_Module::onSelectionChanged()
372 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
376 bool isSketcherOp = false;
377 // An edit operation is enable only if the current opeation is the sketch operation
378 if (mySketchMgr->activeSketch()) {
379 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
380 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
383 // Editing of constraints can be done on selection
384 ModuleBase_ISelection* aSelect = myWorkshop->selection();
385 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
386 if (aSelected.size() == 1) {
387 ModuleBase_ViewerPrs aPrs = aSelected.first();
388 ObjectPtr aObject = aPrs.object();
389 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
391 std::string aId = aFeature->getKind();
392 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
393 (aId == SketchPlugin_ConstraintLength::ID()) ||
394 (aId == SketchPlugin_ConstraintDistance::ID())) {
395 editFeature(aFeature);
402 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
404 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
405 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
406 anOpMgr->onKeyReleased(theEvent);
409 void PartSet_Module::onEnterReleased()
411 myRestartingMode = RM_EmptyFeatureUsed;
414 void PartSet_Module::onOperationActivatedByPreselection()
416 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
417 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
418 // Set final definitions if they are necessary
419 //propertyPanelDefined(aOperation);
421 /// Commit sketcher operations automatically
422 anOperation->commit();
426 void PartSet_Module::onNoMoreWidgets()
428 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
430 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
431 if (myRestartingMode != RM_Forbided)
432 myRestartingMode = RM_LastFeatureUsed;
433 anOperation->commit();
438 void PartSet_Module::onVertexSelected()
440 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
441 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
442 /// If last line finished on vertex the lines creation sequence has to be break
443 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
444 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
445 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
446 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
447 bool aFoundWidget = false;
448 bool aFoundObligatory = false;
449 for (; anIt != aLast && !aFoundObligatory; anIt++) {
451 aFoundWidget = *anIt == anActiveWidget;
453 aFoundObligatory = (*anIt)->isObligatory();
455 if (!aFoundObligatory)
456 myRestartingMode = RM_Forbided;
460 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
461 Config_WidgetAPI* theWidgetApi, std::string theParentId)
463 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
464 XGUI_Workshop* aWorkshop = aConnector->workshop();
465 ModuleBase_ModelWidget* aWgt = NULL;
466 if (theType == "sketch-start-label") {
467 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
468 aLabelWgt->setWorkshop(aWorkshop);
469 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
470 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
472 } else if (theType == "sketch-2dpoint_selector") {
473 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
474 aPointWgt->setWorkshop(aWorkshop);
475 aPointWgt->setSketch(mySketchMgr->activeSketch());
476 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
478 } if (theType == "point2ddistance") {
479 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
480 aDistanceWgt->setWorkshop(aWorkshop);
481 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
483 } if (theType == "sketch_shape_selector") {
484 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
485 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
486 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
487 aWgt = aShapeSelectorWgt;
488 } if (theType == "sketch_constraint_shape_selector") {
489 PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
490 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
491 aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
492 aWgt = aConstraintShapeSelectorWgt;
497 void PartSet_Module::createActions()
501 anAction = new QAction(tr("Auxiliary"), this);
502 anAction->setCheckable(true);
503 addAction("AUXILIARY_CMD", anAction);
506 QAction* PartSet_Module::action(const QString& theId) const
508 if (myActions.contains(theId))
509 return myActions[theId];
513 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
515 if (myActions.contains(theId))
516 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
517 theAction->setData(theId);
518 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
519 myActions[theId] = theAction;
522 void PartSet_Module::onAction(bool isChecked)
524 QAction* aAction = static_cast<QAction*>(sender());
525 QString anId = aAction->data().toString();
527 if (anId == "AUXILIARY_CMD") {
528 mySketchMgr->setAuxiliary(isChecked);
532 bool PartSet_Module::deleteObjects()
534 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
535 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
536 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
537 if (!isSketchOp && !isNestedOp)
540 // sketch feature should be skipped, only sub-features can be removed
541 // when sketch operation is active
542 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
544 // selected objects should be collected before the current operation abort because
545 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
546 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
547 XGUI_Workshop* aWorkshop = aConnector->workshop();
548 ModuleBase_ISelection* aSel = aConnector->selection();
549 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
551 // if there are no selected objects in the viewer, that means that the selection in another
552 // place cased this method. It is necessary to return the false value to understande in above
553 // method that delete is not processed
554 if (aSelectedObj.count() == 0)
557 // the active nested sketch operation should be aborted unconditionally
559 anOperation->abort();
561 std::set<FeaturePtr> aRefFeatures;
562 foreach (ObjectPtr aObj, aSelectedObj)
564 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
566 // TODO: check for what there is this condition. It is placed here historicaly because
567 // ther is this condition during remove features.
569 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
570 if (aFeature.get() != NULL) {
571 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
576 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
578 // according to #355 feature, it is not necessary to inform about dependencies during
579 // sketch delete operation
581 if (!aRefFeatures.empty()) {
582 QStringList aRefNames;
583 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
584 aLast = aRefFeatures.end();
585 for (; anIt != aLast; anIt++) {
586 FeaturePtr aFeature = (*anIt);
587 if (aFeature == aSketch)
589 aRefNames.append((*anIt)->name().c_str());
591 if (!aRefNames.empty()) {
592 QString aNames = aRefNames.join(", ");
593 aDescription += aNames.prepend(" ");
595 QMainWindow* aDesktop = aWorkshop->desktop();
596 QMessageBox::StandardButton aRes = QMessageBox::warning(
597 aDesktop, tr("Delete features"),
598 QString(tr("Selected features are used in the following features: %1.\
599 These features will be deleted also. Would you like to continue?")).arg(aNames),
600 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
601 if (aRes != QMessageBox::Yes)
606 SessionPtr aMgr = ModelAPI_Session::get();
607 aMgr->startOperation(aDescription.toStdString());
608 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
609 aLast = aRefFeatures.end();
610 for (; anIt != aLast; anIt++) {
611 FeaturePtr aRefFeature = (*anIt);
612 if (aRefFeature == aSketch)
614 aRefFeature->document()->removeFeature(aRefFeature);
617 foreach (ObjectPtr aObj, aSelectedObj)
619 DocumentPtr aDoc = aObj->document();
620 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
622 // if (aDoc == aMgr->activeDocument()) {
626 //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
627 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
628 if (aFeature.get() != NULL) {
629 aDoc->removeFeature(aFeature);
633 aWorkshop->displayer()->updateViewer();
634 //myDisplayer->updateViewer();
635 aMgr->finishOperation();
641 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
643 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
644 if (!anAIS.IsNull()) {
645 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
646 if (!aDim.IsNull()) {
647 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
648 aCtx->SetZLayer(aDim, myVisualLayerId);