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);
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 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
216 aViewer->AddZLayer(myVisualLayerId);
217 mySketchMgr->startSketch(theOperation);
219 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
220 mySketchMgr->startNestedSketch(theOperation);
223 if (myDocumentShapeFilter.IsNull())
224 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
225 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
228 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
230 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
231 mySketchMgr->stopSketch(theOperation);
232 Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
233 aViewer->RemoveZLayer(myVisualLayerId);
236 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
237 mySketchMgr->stopNestedSketch(theOperation);
239 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
242 ModuleBase_Operation* PartSet_Module::currentOperation() const
244 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
245 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
246 return anOpMgr->currentOperation();
249 bool PartSet_Module::canUndo() const
251 bool aCanUndo = false;
252 SessionPtr aMgr = ModelAPI_Session::get();
253 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
254 aCanUndo = !aMgr->isOperation();
255 if (!aCanUndo) // check the enable state additionally by sketch manager
256 aCanUndo = aMgr->canUndo();
261 bool PartSet_Module::canRedo() const
263 bool aCanRedo = false;
264 SessionPtr aMgr = ModelAPI_Session::get();
265 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
266 aCanRedo = !aMgr->isOperation();
267 if (!aCanRedo) // check the enable state additionally by sketch manager
268 aCanRedo = aMgr->canRedo();
273 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
275 bool aCanDisplay = false;
276 if (!mySketchMgr->canDisplayObject())
278 CompositeFeaturePtr aSketchFeature = mySketchMgr->activeSketch();
279 if (aSketchFeature.get() != NULL) {
280 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
282 // MPV: the second and third conditions to avoid crash on exit for application
283 if (aFeature.get() != NULL && aFeature->data().get() && aFeature->data()->isValid()) {
284 if (aFeature == aSketchFeature) {
287 else if (aSketchFeature.get() && aSketchFeature->data().get() &&
288 aSketchFeature->data()->isValid()) {
289 for (int i = 0; i < aSketchFeature->numberOfSubs() && !aCanDisplay; i++) {
290 FeaturePtr aSubFeature = aSketchFeature->subFeature(i);
291 std::list<ResultPtr> aResults = aSubFeature->results();
292 std::list<ResultPtr>::const_iterator aIt;
293 for (aIt = aResults.begin(); aIt != aResults.end() && !aCanDisplay; ++aIt) {
294 if (theObject == (*aIt))
297 if (aSubFeature == theObject)
304 aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject);
309 void PartSet_Module::addViewerItems(QMenu* theMenu) const
311 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
312 if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
313 !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
316 ModuleBase_ISelection* aSelection = myWorkshop->selection();
317 QObjectPtrList aObjects = aSelection->selectedPresentations();
318 if (aObjects.size() > 0) {
319 bool hasFeature = false;
320 foreach(ObjectPtr aObject, aObjects)
322 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
323 if (aFeature.get() != NULL) {
328 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
329 XGUI_Workshop* aWorkshop = aConnector->workshop();
330 QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
331 theMenu->addAction(anAction);
335 if (mySketchMgr->canSetAuxiliary(isAuxiliary)) {
336 QAction* anAction = action("AUXILIARY_CMD");
337 theMenu->addAction(anAction);
338 anAction->setChecked(isAuxiliary);
342 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
344 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
345 if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
346 // we have to manually activate the sketch label in edit mode
347 aPanel->activateWidget(aPanel->modelWidgets().first());
351 // Restart last operation type
352 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
353 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
354 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
355 // Initialise new line with first point equal to end of previous
356 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
358 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
359 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
360 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
362 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
363 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
364 aWgt->attributeID(), aPoint->x(), aPoint->y());
365 aPanel->activateNextWidget(aPnt2dWgt);
370 // Start editing constraint
371 if (theOperation->isEditOperation()) {
372 // TODO: #391 - to be removed
373 std::string aId = theOperation->id().toStdString();
374 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
375 PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
376 // Find and activate widget for management of point for dimension line position
377 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
378 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
379 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
381 aPanel->activateWidget(aPntWgt);
391 void PartSet_Module::onSelectionChanged()
393 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
397 bool isSketcherOp = false;
398 // An edit operation is enable only if the current opeation is the sketch operation
399 if (mySketchMgr->activeSketch()) {
400 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
401 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
404 // Editing of constraints can be done on selection
405 ModuleBase_ISelection* aSelect = myWorkshop->selection();
406 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
407 if (aSelected.size() == 1) {
408 ModuleBase_ViewerPrs aPrs = aSelected.first();
409 ObjectPtr aObject = aPrs.object();
410 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
412 std::string aId = aFeature->getKind();
413 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
414 (aId == SketchPlugin_ConstraintLength::ID()) ||
415 (aId == SketchPlugin_ConstraintDistance::ID())) {
416 editFeature(aFeature);
423 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
425 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
426 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
427 anOpMgr->onKeyReleased(theEvent);
430 void PartSet_Module::onEnterReleased()
432 myRestartingMode = RM_EmptyFeatureUsed;
435 void PartSet_Module::onOperationActivatedByPreselection()
437 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
438 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
439 // Set final definitions if they are necessary
440 //propertyPanelDefined(aOperation);
442 /// Commit sketcher operations automatically
443 anOperation->commit();
447 void PartSet_Module::onNoMoreWidgets()
449 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
451 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
452 if (myRestartingMode != RM_Forbided)
453 myRestartingMode = RM_LastFeatureUsed;
454 anOperation->commit();
459 void PartSet_Module::onVertexSelected()
461 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
462 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
463 /// If last line finished on vertex the lines creation sequence has to be break
464 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
465 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
466 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
467 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
468 bool aFoundWidget = false;
469 bool aFoundObligatory = false;
470 for (; anIt != aLast && !aFoundObligatory; anIt++) {
472 aFoundWidget = *anIt == anActiveWidget;
474 aFoundObligatory = (*anIt)->isObligatory();
476 if (!aFoundObligatory)
477 myRestartingMode = RM_Forbided;
481 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
482 Config_WidgetAPI* theWidgetApi, std::string theParentId)
484 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
485 XGUI_Workshop* aWorkshop = aConnector->workshop();
486 ModuleBase_ModelWidget* aWgt = NULL;
487 if (theType == "sketch-start-label") {
488 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
489 aLabelWgt->setWorkshop(aWorkshop);
490 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
491 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
493 } else if (theType == "sketch-2dpoint_selector") {
494 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
495 aPointWgt->setWorkshop(aWorkshop);
496 aPointWgt->setSketch(mySketchMgr->activeSketch());
497 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
499 } if (theType == "point2ddistance") {
500 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
501 aDistanceWgt->setWorkshop(aWorkshop);
502 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
504 } if (theType == "sketch_shape_selector") {
505 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
506 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
507 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
508 aWgt = aShapeSelectorWgt;
509 } if (theType == "sketch_constraint_shape_selector") {
510 PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
511 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
512 aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
513 aWgt = aConstraintShapeSelectorWgt;
518 void PartSet_Module::createActions()
522 anAction = new QAction(tr("Auxiliary"), this);
523 anAction->setCheckable(true);
524 addAction("AUXILIARY_CMD", anAction);
527 QAction* PartSet_Module::action(const QString& theId) const
529 if (myActions.contains(theId))
530 return myActions[theId];
534 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
536 if (myActions.contains(theId))
537 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
538 theAction->setData(theId);
539 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
540 myActions[theId] = theAction;
543 void PartSet_Module::onAction(bool isChecked)
545 QAction* aAction = static_cast<QAction*>(sender());
546 QString anId = aAction->data().toString();
548 if (anId == "AUXILIARY_CMD") {
549 mySketchMgr->setAuxiliary(isChecked);
553 bool PartSet_Module::deleteObjects()
555 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
556 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
557 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
558 if (!isSketchOp && !isNestedOp)
561 // sketch feature should be skipped, only sub-features can be removed
562 // when sketch operation is active
563 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
565 // selected objects should be collected before the current operation abort because
566 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
567 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
568 XGUI_Workshop* aWorkshop = aConnector->workshop();
569 ModuleBase_ISelection* aSel = aConnector->selection();
570 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
572 // if there are no selected objects in the viewer, that means that the selection in another
573 // place cased this method. It is necessary to return the false value to understande in above
574 // method that delete is not processed
575 if (aSelectedObj.count() == 0)
578 // the active nested sketch operation should be aborted unconditionally
580 anOperation->abort();
582 std::set<FeaturePtr> aRefFeatures;
583 foreach (ObjectPtr aObj, aSelectedObj)
585 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
587 // TODO: check for what there is this condition. It is placed here historicaly because
588 // ther is this condition during remove features.
590 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
591 if (aFeature.get() != NULL) {
592 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
597 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
599 // according to #355 feature, it is not necessary to inform about dependencies during
600 // sketch delete operation
602 if (!aRefFeatures.empty()) {
603 QStringList aRefNames;
604 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
605 aLast = aRefFeatures.end();
606 for (; anIt != aLast; anIt++) {
607 FeaturePtr aFeature = (*anIt);
608 if (aFeature == aSketch)
610 aRefNames.append((*anIt)->name().c_str());
612 if (!aRefNames.empty()) {
613 QString aNames = aRefNames.join(", ");
614 aDescription += aNames.prepend(" ");
616 QMainWindow* aDesktop = aWorkshop->desktop();
617 QMessageBox::StandardButton aRes = QMessageBox::warning(
618 aDesktop, tr("Delete features"),
619 QString(tr("Selected features are used in the following features: %1.\
620 These features will be deleted also. Would you like to continue?")).arg(aNames),
621 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
622 if (aRes != QMessageBox::Yes)
627 SessionPtr aMgr = ModelAPI_Session::get();
628 aMgr->startOperation(aDescription.toStdString());
629 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
630 aLast = aRefFeatures.end();
631 for (; anIt != aLast; anIt++) {
632 FeaturePtr aRefFeature = (*anIt);
633 if (aRefFeature == aSketch)
635 aRefFeature->document()->removeFeature(aRefFeature);
638 foreach (ObjectPtr aObj, aSelectedObj)
640 DocumentPtr aDoc = aObj->document();
641 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
643 // if (aDoc == aMgr->activeDocument()) {
647 //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
648 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
649 if (aFeature.get() != NULL) {
650 aDoc->removeFeature(aFeature);
654 aWorkshop->displayer()->updateViewer();
655 //myDisplayer->updateViewer();
656 aMgr->finishOperation();
662 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
664 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
665 if (!anAIS.IsNull()) {
666 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
667 if (!aDim.IsNull()) {
668 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
669 aCtx->SetZLayer(aDim, myVisualLayerId);