Salome HOME
Issue #371: show external edges in different color. Also hide rigid constraint for...
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
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_SketcherMgr.h>
11
12 #include <ModuleBase_Operation.h>
13 #include <ModuleBase_IViewer.h>
14 #include <ModuleBase_IViewWindow.h>
15 #include <ModuleBase_IPropertyPanel.h>
16 #include <ModuleBase_WidgetEditor.h>
17 #include <ModuleBase_FilterFactory.h>
18 #include <ModuleBase_FilterLinearEdge.h>
19 #include <ModuleBase_FilterFace.h>
20 #include <ModuleBase_FilterMulti.h>
21 #include <ModuleBase_FilterCustom.h>
22 #include <ModuleBase_FilterNoConsructionSubShapes.h>
23
24 #include <ModelAPI_Object.h>
25 #include <ModelAPI_Events.h>
26 #include <ModelAPI_Validator.h>
27 #include <ModelAPI_Data.h>
28 #include <ModelAPI_Session.h>
29
30 #include <GeomDataAPI_Point2D.h>
31 #include <GeomDataAPI_Point.h>
32 #include <GeomDataAPI_Dir.h>
33
34 #include <XGUI_Displayer.h>
35 #include <XGUI_Workshop.h>
36 #include <XGUI_OperationMgr.h>
37 #include <XGUI_PropertyPanel.h>
38 #include <XGUI_ModuleConnector.h>
39 #include <XGUI_Tools.h>
40
41 #include <SketchPlugin_Feature.h>
42 #include <SketchPlugin_Sketch.h>
43 #include <SketchPlugin_Line.h>
44 //#include <SketchPlugin_Arc.h>
45 //#include <SketchPlugin_Circle.h>
46 #include <SketchPlugin_ConstraintLength.h>
47 #include <SketchPlugin_ConstraintDistance.h>
48 #include <SketchPlugin_ConstraintParallel.h>
49 #include <SketchPlugin_ConstraintPerpendicular.h>
50 #include <SketchPlugin_ConstraintRadius.h>
51 //#include <SketchPlugin_ConstraintRigid.h>
52
53 #include <Events_Loop.h>
54 #include <Config_PropManager.h>
55
56 #include <StdSelect_TypeOfFace.hxx>
57 #include <TopoDS_Vertex.hxx>
58 #include <TopoDS.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <BRep_Tool.hxx>
61
62 #include <QObject>
63 #include <QMouseEvent>
64 #include <QString>
65 #include <QTimer>
66 #include <QApplication>
67 #include <QMessageBox>
68 #include <QMainWindow>
69
70 #include <GeomAlgoAPI_FaceBuilder.h>
71 #include <GeomDataAPI_Dir.h>
72
73 #ifdef _DEBUG
74 #include <QDebug>
75 #endif
76
77 /*!Create and return new instance of XGUI_Module*/
78 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
79 {
80   return new PartSet_Module(theWshop);
81 }
82
83 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
84   : ModuleBase_IModule(theWshop), 
85   myRestartingMode(RM_None)
86 {
87   //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
88   mySketchMgr = new PartSet_SketcherMgr(this);
89
90   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
91   XGUI_Workshop* aWorkshop = aConnector->workshop();
92
93   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
94   connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
95   connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
96           this, SLOT(onOperationActivatedByPreselection()));
97
98   ModuleBase_IViewer* aViewer = theWshop->viewer();
99   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
100           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
101
102   createActions();
103 }
104
105 PartSet_Module::~PartSet_Module()
106 {
107   if (!myDocumentShapeFilter.IsNull())
108     myDocumentShapeFilter.Nullify();
109 }
110
111 void PartSet_Module::registerValidators()
112 {
113   //Registering of validators
114   SessionPtr aMgr = ModelAPI_Session::get();
115   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
116   aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
117   aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
118   aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
119   aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
120   aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
121   aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
122   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
123   aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
124 }
125
126 void PartSet_Module::registerFilters()
127 {
128   //Registering of selection filters
129   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
130   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
131
132   aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
133   aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
134   aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
135   Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
136   aFactory->registerFilter("NoConstructionSubShapesFilter",
137             new ModuleBase_FilterCustom(aSelectFilter));
138 }
139
140 void PartSet_Module::registerProperties()
141 {
142   Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
143                                    PLANE_SIZE);
144   Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
145                                    Config_Prop::Integer, SKETCH_WIDTH);
146 }
147
148 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation) 
149 {
150   if (theOperation->isEditOperation())
151     return;
152   // the selection is cleared after commit the create operation
153   // in order to do not use the same selected objects in the restarted operation
154   // for common behaviour, the selection is cleared even if the operation is not restarted
155   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
156   if (!aContext.IsNull())
157     aContext->ClearSelected();
158
159   /// Restart sketcher operations automatically
160   FeaturePtr aFeature = theOperation->feature();
161   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
162             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
163   if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
164                      myRestartingMode == RM_EmptyFeatureUsed)) {
165     myLastOperationId = theOperation->id();
166     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
167     
168     launchOperation(myLastOperationId);
169   }
170   breakOperationSequence();
171 }
172
173 void PartSet_Module::breakOperationSequence()
174 {
175   myLastOperationId = "";
176   myLastFeature = FeaturePtr();
177   myRestartingMode = RM_None;
178 }
179
180 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
181 {
182   breakOperationSequence();
183 }
184
185 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
186 {
187   if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
188     mySketchMgr->startSketch(theOperation);
189   }
190   if (myDocumentShapeFilter.IsNull())
191     myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
192   myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
193 }
194
195 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
196 {
197   if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
198     mySketchMgr->stopSketch(theOperation);
199   }
200   myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
201 }
202
203 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
204 {
205   bool aCanDisplay = false;
206   if (mySketchMgr->activeSketch()) {
207     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
208
209     if (aFeature.get() != NULL) {
210       if (aFeature == mySketchMgr->activeSketch()) {
211         aCanDisplay = false;
212       }
213       else {
214         aCanDisplay = mySketchMgr->sketchOperationIdList().contains(aFeature->getKind().c_str());
215       }
216     }
217   }
218   else {
219     aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject);
220   }
221   return aCanDisplay;
222 }
223
224 void PartSet_Module::addViewerItems(QMenu* theMenu) const
225 {
226   if (!isSketchOperationActive() && !isSketchFeatureOperationActive())
227     return;
228   ModuleBase_ISelection* aSelection = myWorkshop->selection();
229   QObjectPtrList aObjects = aSelection->selectedPresentations();
230   if (aObjects.size() > 0) {
231     bool hasFeature = false;
232     foreach(ObjectPtr aObject, aObjects)
233     {
234       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
235       if (aFeature.get() != NULL) {
236         hasFeature = true;
237       }
238     }
239     if (hasFeature)
240       theMenu->addAction(action("DELETE_PARTSET_CMD"));
241   }
242 }
243
244 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
245 {
246   ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
247   if ((theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) && 
248     (theOperation->isEditOperation())) {
249     // we have to manually activate the sketch label in edit mode
250       aPanel->activateWidget(aPanel->modelWidgets().first());
251       return;
252   }
253
254   // Restart last operation type 
255   if ((theOperation->id() == myLastOperationId) && myLastFeature) {
256     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
257     if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
258       // Initialise new line with first point equal to end of previous
259       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
260       if (aPnt2dWgt) {
261         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
262         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
263           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
264         if (aPoint) {
265           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
266           PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(), 
267             aWgt->attributeID(), aPoint->x(), aPoint->y());
268           aPanel->activateNextWidget(aPnt2dWgt);
269         }
270       }
271     }
272   } else {
273     // Start editing constraint
274     if (theOperation->isEditOperation()) {
275       // TODO: #391 - to be removed
276       std::string aId = theOperation->id().toStdString();
277       if (PartSet_SketcherMgr::sketchOperationIdList().contains(QString(aId.c_str()))) {
278         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
279             (aId == SketchPlugin_ConstraintLength::ID()) || 
280             (aId == SketchPlugin_ConstraintDistance::ID())) {
281           // Find and activate widget for management of point for dimension line position
282           QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
283           foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
284             PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
285             if (aPntWgt) {
286               aPanel->activateWidget(aPntWgt);
287               return;
288             }
289           }
290         } 
291       }
292     }
293   }
294 }
295
296
297 void PartSet_Module::onSelectionChanged()
298 {
299   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
300   if (!aOperation)
301     return;
302
303   bool isSketcherOp = false;
304   // An edit operation is enable only if the current opeation is the sketch operation
305   if (mySketchMgr->activeSketch()) {
306     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
307       isSketcherOp = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
308   }
309   if (isSketcherOp) {
310     // Editing of constraints can be done on selection
311     ModuleBase_ISelection* aSelect = myWorkshop->selection();
312     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
313     if (aSelected.size() == 1) {
314       ModuleBase_ViewerPrs aPrs = aSelected.first();
315       ObjectPtr aObject = aPrs.object();
316       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
317       if (aFeature) {
318         std::string aId = aFeature->getKind();
319         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
320             (aId == SketchPlugin_ConstraintLength::ID()) || 
321             (aId == SketchPlugin_ConstraintDistance::ID())) {
322           editFeature(aFeature);
323         }
324       }
325     }
326   } 
327 }
328
329 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
330 {
331   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
332   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
333   anOpMgr->onKeyReleased(theEvent);
334 }
335
336 void PartSet_Module::onEnterReleased()
337 {
338   myRestartingMode = RM_EmptyFeatureUsed;
339 }
340
341 void PartSet_Module::onOperationActivatedByPreselection()
342 {
343   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
344   if(aOperation && isSketchFeatureOperationActive()) {
345     // Set final definitions if they are necessary
346     //propertyPanelDefined(aOperation);
347
348     /// Commit sketcher operations automatically
349     aOperation->commit();
350   }
351 }
352
353 void PartSet_Module::onNoMoreWidgets()
354 {
355   if (isSketchFeatureOperationActive()) {
356     ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
357     if (aOperation) {
358       if (myRestartingMode != RM_Forbided)
359         myRestartingMode = RM_LastFeatureUsed;
360       aOperation->commit();
361     }
362   }
363 }
364
365 void PartSet_Module::onVertexSelected()
366 {
367   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
368   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
369     /// If last line finished on vertex the lines creation sequence has to be break
370     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
371     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
372     if (aWidgets.last() == aPanel->activeWidget()) {
373       myRestartingMode = RM_Forbided;
374     }
375   }
376 }
377
378 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
379                                             Config_WidgetAPI* theWidgetApi, std::string theParentId,
380                                             QList<ModuleBase_ModelWidget*>& theModelWidgets)
381 {
382   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
383   XGUI_Workshop* aWorkshop = aConnector->workshop();
384   if (theType == "sketch-start-label") {
385     PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
386     aWgt->setWorkshop(aWorkshop);
387     connect(aWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)), 
388       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
389     theModelWidgets.append(aWgt);
390     return aWgt->getControl();
391
392   } else if (theType == "sketch-2dpoint_selector") {
393     PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
394     aWgt->setWorkshop(aWorkshop);
395     aWgt->setSketch(mySketchMgr->activeSketch());
396
397     connect(aWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
398
399     theModelWidgets.append(aWgt);
400     return aWgt->getControl();
401
402   } if (theType == "point2ddistance") {
403     PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
404     aWgt->setWorkshop(aWorkshop);
405     aWgt->setSketch(mySketchMgr->activeSketch());
406
407     theModelWidgets.append(aWgt);
408     return aWgt->getControl();
409
410   } if (theType == "sketch_shape_selector") {
411     PartSet_WidgetShapeSelector* aWgt = 
412       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
413     aWgt->setSketcher(mySketchMgr->activeSketch());
414
415     theModelWidgets.append(aWgt);
416     return aWgt->getControl();
417
418   } if (theType == "sketch_constraint_shape_selector") {
419     PartSet_WidgetConstraintShapeSelector* aWgt = 
420       new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
421     aWgt->setSketcher(mySketchMgr->activeSketch());
422
423     theModelWidgets.append(aWgt);
424     return aWgt->getControl();
425
426   } else
427     return 0;
428 }
429
430 bool PartSet_Module::isSketchOperationActive() const
431 {
432   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
433
434   bool isSketchOp = aOperation && aOperation->id().toStdString() == SketchPlugin_Sketch::ID();
435   return isSketchOp;
436 }
437
438 bool PartSet_Module::isSketchFeatureOperationActive() const
439 {
440   bool isCurrentSketchOp = false;
441   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
442   if (aOperation) {
443     FeaturePtr aFeature = aOperation->feature();
444     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
445               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
446     isCurrentSketchOp = aSPFeature.get() != NULL;
447   }
448   return isCurrentSketchOp;
449 }
450
451 void PartSet_Module::createActions()
452 {
453   QAction* aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
454   addAction("DELETE_PARTSET_CMD", aAction);
455 }
456
457 QAction* PartSet_Module::action(const QString& theId) const
458 {
459   if (myActions.contains(theId))
460     return myActions[theId];
461   return 0;
462 }
463
464 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
465 {
466   if (myActions.contains(theId))
467     qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
468   theAction->setData(theId);
469   connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
470   myActions[theId] = theAction;
471 }
472
473 void PartSet_Module::onAction(bool isChecked)
474 {
475   QAction* aAction = static_cast<QAction*>(sender());
476   QString anId = aAction->data().toString();
477
478   if (anId == "DELETE_PARTSET_CMD") {
479     deleteObjects();
480   }
481 }
482
483 void PartSet_Module::deleteObjects()
484 {
485   bool isSketchOp = isSketchOperationActive();
486   if (!isSketchOp && !isSketchFeatureOperationActive())
487     return;
488
489   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
490   XGUI_Workshop* aWorkshop = aConnector->workshop();
491
492   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
493   if (!isSketchOp && anOpMgr->canStopOperation()) {
494     ModuleBase_Operation* aCurrentOp = anOpMgr->currentOperation();
495     if (aCurrentOp) {
496       aCurrentOp->abort();
497     }
498   }
499   // sketch feature should be skipped, only sub-features can be removed
500   // when sketch operation is active
501   CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
502
503   ModuleBase_ISelection* aSel = aConnector->selection();
504   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
505
506   std::set<FeaturePtr> aRefFeatures;
507   foreach (ObjectPtr aObj, aSelectedObj)
508   {
509     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
510     //if (aPart) {
511       // TODO: check for what there is this condition. It is placed here historicaly because
512       // ther is this condition during remove features.
513     //} else {
514     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
515     if (aFeature.get() != NULL) {
516       aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
517     }
518     //}
519   }
520
521   if (!aRefFeatures.empty()) {
522     QStringList aRefNames;
523     std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
524                                          aLast = aRefFeatures.end();
525     for (; anIt != aLast; anIt++) {
526       FeaturePtr aFeature = (*anIt);
527       if (aFeature == aSketch)
528         continue;
529       aRefNames.append((*anIt)->name().c_str());
530     }
531     if (!aRefNames.empty()) {
532       QString aNames = aRefNames.join(", ");
533
534       QMainWindow* aDesktop = aWorkshop->desktop();
535       QMessageBox::StandardButton aRes = QMessageBox::warning(
536           aDesktop, tr("Delete features"),
537           QString(tr("Selected features are used in the following features: %1.\
538   These features will be deleted also. Would you like to continue?")).arg(aNames),
539           QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
540       if (aRes != QMessageBox::Yes)
541         return;
542     }
543   }
544
545   SessionPtr aMgr = ModelAPI_Session::get();
546   aMgr->startOperation("DeletePartSet");
547   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
548                                        aLast = aRefFeatures.end();
549   for (; anIt != aLast; anIt++) {
550     FeaturePtr aRefFeature = (*anIt);
551     if (aRefFeature == aSketch)
552       continue;
553     aRefFeature->document()->removeFeature(aRefFeature);
554   }
555
556   foreach (ObjectPtr aObj, aSelectedObj)
557   {
558     DocumentPtr aDoc = aObj->document();
559     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
560     //if (aPart) {
561     //  if (aDoc == aMgr->activeDocument()) {
562     //    aDoc->close();
563     //  }
564     //} else {
565       //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
566     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
567     if (aFeature.get() != NULL) {
568       aDoc->removeFeature(aFeature);
569     }
570     //}
571   }
572   aWorkshop->displayer()->updateViewer();
573   //myDisplayer->updateViewer();
574   aMgr->finishOperation();
575 }