]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
Issue #663: Don't hide "Activate" menu item in PartSet pop-up
[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_WidgetPoint2dAngle.h"
11 #include "PartSet_WidgetMultiSelector.h"
12 #include "PartSet_WidgetEditor.h"
13 #include "PartSet_WidgetFileSelector.h"
14 #include "PartSet_WidgetSketchCreator.h"
15 #include "PartSet_SketcherMgr.h"
16 #include "PartSet_MenuMgr.h"
17 #include "PartSet_CustomPrs.h"
18 #include "PartSet_IconFactory.h"
19
20 #include "PartSet_Filters.h"
21 #include "PartSet_FilterInfinite.h"
22
23 #include <PartSetPlugin_Remove.h>
24 #include <PartSetPlugin_Part.h>
25 #include <PartSetPlugin_Duplicate.h>
26
27 #include <ModuleBase_Operation.h>
28 #include <ModuleBase_OperationAction.h>
29 #include <ModuleBase_IViewer.h>
30 #include <ModuleBase_IViewWindow.h>
31 #include <ModuleBase_IPropertyPanel.h>
32 #include <ModuleBase_WidgetEditor.h>
33 #include <ModuleBase_WidgetValidated.h>
34 #include <ModuleBase_FilterFactory.h>
35 #include <ModuleBase_Tools.h>
36 #include <ModuleBase_OperationFeature.h>
37
38 #include <GeomValidators_ShapeType.h>
39 #include <GeomValidators_Finite.h>
40 #include <GeomValidators_Face.h>
41 #include <GeomValidators_ConstructionComposite.h>
42 #include <GeomValidators_ZeroOffset.h>
43 #include <GeomValidators_BooleanArguments.h>
44 #include <GeomValidators_Different.h>
45
46
47 #include <ModelAPI_Object.h>
48 #include <ModelAPI_Events.h>
49 #include <ModelAPI_Validator.h>
50 #include <ModelAPI_Data.h>
51 #include <ModelAPI_Session.h>
52 #include <GeomValidators_DifferentShapes.h>
53 #include <ModelAPI_ResultBody.h>
54
55 #include <GeomDataAPI_Point2D.h>
56 #include <GeomDataAPI_Point.h>
57 #include <GeomDataAPI_Dir.h>
58
59 #include <XGUI_Displayer.h>
60 #include <XGUI_Workshop.h>
61 #include <XGUI_OperationMgr.h>
62 #include <XGUI_PropertyPanel.h>
63 #include <XGUI_ModuleConnector.h>
64 #include <XGUI_ContextMenuMgr.h>
65 #include <XGUI_Tools.h>
66 #include <XGUI_ObjectsBrowser.h>
67 #include <XGUI_SelectionMgr.h>
68 #include <XGUI_DataModel.h>
69
70 #include <SketchPlugin_Feature.h>
71 #include <SketchPlugin_Sketch.h>
72 #include <SketchPlugin_Line.h>
73 #include <SketchPlugin_Arc.h>
74 #include <SketchPlugin_Circle.h>
75 #include <SketchPlugin_Point.h>
76 #include <SketchPlugin_ConstraintAngle.h>
77 #include <SketchPlugin_ConstraintLength.h>
78 #include <SketchPlugin_ConstraintDistance.h>
79 #include <SketchPlugin_ConstraintParallel.h>
80 #include <SketchPlugin_ConstraintPerpendicular.h>
81 #include <SketchPlugin_ConstraintRadius.h>
82
83 #include <SketcherPrs_SymbolPrs.h>
84 #include <SketcherPrs_Tools.h>
85
86 #include <Events_Loop.h>
87 #include <Config_PropManager.h>
88 #include <Config_Keywords.h>
89
90 #include <StdSelect_TypeOfFace.hxx>
91 #include <TopoDS_Vertex.hxx>
92 #include <TopoDS.hxx>
93 #include <TopoDS_Shape.hxx>
94 #include <BRep_Tool.hxx>
95 #include <AIS_Dimension.hxx>
96
97 #include <QObject>
98 #include <QMouseEvent>
99 #include <QString>
100 #include <QTimer>
101 #include <QApplication>
102 #include <QMessageBox>
103 #include <QMainWindow>
104 #include <QLineEdit>
105
106 #include <GeomAlgoAPI_FaceBuilder.h>
107 #include <GeomDataAPI_Dir.h>
108
109 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
110
111 #ifdef _DEBUG
112 #include <QDebug>
113 #endif
114
115 /*!Create and return new instance of XGUI_Module*/
116 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
117 {
118   return new PartSet_Module(theWshop);
119 }
120
121 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
122   : ModuleBase_IModule(theWshop),
123   myRestartingMode(RM_None), myVisualLayerId(0)
124 {
125   new PartSet_IconFactory();
126
127   mySketchMgr = new PartSet_SketcherMgr(this);
128 #ifdef ModuleDataModel
129   myDataModel = new PartSet_DocumentDataModel(this);
130 #endif
131
132   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
133   XGUI_Workshop* aWorkshop = aConnector->workshop();
134
135   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
136   connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
137   connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
138           this, SLOT(onOperationActivatedByPreselection()));
139
140   ModuleBase_IViewer* aViewer = theWshop->viewer();
141   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
142           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
143   connect(aViewer, SIGNAL(viewTransformed(int)),
144           SLOT(onViewTransformed(int)));
145   connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
146           SLOT(onViewCreated(ModuleBase_IViewWindow*)));
147
148   myMenuMgr = new PartSet_MenuMgr(this);
149   myCustomPrs = new PartSet_CustomPrs(theWshop);
150
151   Events_Loop* aLoop = Events_Loop::loop();
152   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
153
154   mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
155   mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
156 }
157
158 PartSet_Module::~PartSet_Module()
159 {
160   SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
161   for (; aIt.More(); aIt.Next()) {
162     Handle(SelectMgr_Filter) aFilter = aIt.Value();
163     if (!aFilter.IsNull())
164       aFilter.Nullify();
165   }
166   delete myCustomPrs;
167 }
168
169 void PartSet_Module::activateSelectionFilters()
170 {
171   SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
172   for (; aIt.More(); aIt.Next()) {
173     Handle(SelectMgr_Filter) aFilter = aIt.Value();
174     if (!aFilter.IsNull())
175       myWorkshop->viewer()->addSelectionFilter(aFilter);
176   }
177 }
178
179 void PartSet_Module::deactivateSelectionFilters()
180 {
181   SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
182   for (; aIt.More(); aIt.Next()) {
183     Handle(SelectMgr_Filter) aFilter = aIt.Value();
184     if (!aFilter.IsNull())
185       myWorkshop->viewer()->removeSelectionFilter(aFilter);
186   }
187 }
188
189 void PartSet_Module::registerValidators()
190 {
191   //Registering of validators
192   SessionPtr aMgr = ModelAPI_Session::get();
193   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
194   aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
195   aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
196   aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
197   aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
198   aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
199   aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
200   aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
201   aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
202   aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
203   aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
204   aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
205   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
206   aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
207
208   aFactory->registerValidator("GeomValidators_DifferentShapes", new GeomValidators_DifferentShapes);
209   aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
210   aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
211   aFactory->registerValidator("GeomValidators_Finite", new GeomValidators_Finite);
212
213   aFactory->registerValidator("GeomValidators_ConstructionComposite",
214                               new GeomValidators_ConstructionComposite);
215
216   aFactory->registerValidator("GeomValidators_ZeroOffset",
217                               new GeomValidators_ZeroOffset);
218
219   aFactory->registerValidator("GeomValidators_BooleanArguments",
220                               new GeomValidators_BooleanArguments);
221
222   aFactory->registerValidator("PartSet_SketchEntityValidator",
223                               new PartSet_SketchEntityValidator);
224
225   aFactory->registerValidator("GeomValidators_Different",
226                               new GeomValidators_Different);
227 }
228
229 void PartSet_Module::registerFilters()
230 {
231   //Registering of selection filters
232   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
233   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
234 }
235
236 void PartSet_Module::registerProperties()
237 {
238   Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
239                                    PLANE_SIZE);
240   Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
241                                    Config_Prop::Integer, SKETCH_WIDTH);
242 }
243
244 void PartSet_Module::onOperationCommitted(ModuleBase_Operation* theOperation) 
245 {
246   if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
247     mySketchMgr->commitNestedSketch(theOperation);
248   }
249
250   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
251   if (!aFOperation || aFOperation->isEditOperation())
252     return;
253   // the selection is cleared after commit the create operation
254   // in order to do not use the same selected objects in the restarted operation
255   // for common behaviour, the selection is cleared even if the operation is not restarted
256   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
257   XGUI_Workshop* aWorkshop = aConnector->workshop();
258   aWorkshop->selector()->clearSelection();
259
260   /// Restart sketcher operations automatically
261   FeaturePtr aFeature = aFOperation->feature();
262   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
263             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
264   if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
265                      myRestartingMode == RM_EmptyFeatureUsed)) {
266     myLastOperationId = aFOperation->id();
267     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature() : FeaturePtr();
268     if (!sketchMgr()->sketchSolverError())
269       launchOperation(myLastOperationId);
270   }
271   breakOperationSequence();
272 }
273
274 void PartSet_Module::breakOperationSequence()
275 {
276   myLastOperationId = "";
277   myLastFeature = FeaturePtr();
278   myRestartingMode = RM_None;
279 }
280
281 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
282 {
283   breakOperationSequence();
284 }
285
286 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
287 {
288   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
289     mySketchMgr->startSketch(theOperation);
290   }
291   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
292     mySketchMgr->startNestedSketch(theOperation);
293   }
294
295   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
296   if (aFOperation)
297     myCustomPrs->activate(aFOperation->feature(), true);
298 }
299
300 void PartSet_Module::onOperationResumed(ModuleBase_Operation* theOperation)
301 {
302   ModuleBase_IModule::onOperationResumed(theOperation);
303
304   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
305   if (aFOperation)
306     myCustomPrs->activate(aFOperation->feature(), true);
307 }
308
309 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
310 {
311   bool isModified = myCustomPrs->deactivate(false);
312
313   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
314     mySketchMgr->stopSketch(theOperation);
315   }
316   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
317     mySketchMgr->stopNestedSketch(theOperation);
318   }
319
320   if (isModified) {
321     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
322     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
323     aDisplayer->updateViewer();
324   }
325 }
326
327 ModuleBase_Operation* PartSet_Module::currentOperation() const
328 {
329   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
330   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
331   return anOpMgr->currentOperation();
332 }
333
334 bool PartSet_Module::canUndo() const
335 {
336   bool aCanUndo = false;
337   SessionPtr aMgr = ModelAPI_Session::get();
338   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
339     aCanUndo = !aMgr->isOperation();
340     if (!aCanUndo) // check the enable state additionally by sketch manager
341       aCanUndo = aMgr->canUndo();
342   }
343   return aCanUndo;
344 }
345
346 bool PartSet_Module::canRedo() const
347 {
348   bool aCanRedo = false;
349   SessionPtr aMgr = ModelAPI_Session::get();
350   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
351     aCanRedo = !aMgr->isOperation();
352     if (!aCanRedo) // check the enable state additionally by sketch manager
353       aCanRedo = aMgr->canRedo();
354   }
355   return aCanRedo;
356 }
357
358 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
359 {
360   bool aValid = true;
361   if (theActionId == "DELETE_CMD" || theActionId == "MOVE_CMD") {
362     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
363     if (aFeature) {
364       // part features are removed in the PartSet module only.
365       if (aFeature->getKind() == PartSetPlugin_Part::ID())
366         aValid = false;
367     }
368   }
369   return aValid;
370 }
371
372 bool PartSet_Module::canCommitOperation() const
373 {
374   return mySketchMgr->canCommitOperation();
375 }
376
377 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
378 {
379   // the sketch manager put the restriction to the objects erase
380   return mySketchMgr->canEraseObject(theObject);
381 }
382
383 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
384 {
385   // the sketch manager put the restriction to the objects display
386   return mySketchMgr->canDisplayObject(theObject);
387 }
388
389 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
390 {
391   bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
392
393   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
394   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
395        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
396   if (isSketchOp || isNestedOp) {
397     // in active sketch operation it is possible to activate operation object in selection
398     // in the edit operation, e.g. points of the line can be moved when the line is edited
399     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
400     aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
401   }
402   return aCanActivate;
403 }
404
405 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
406 {
407   return myMenuMgr->addViewerMenu(theMenu, theStdActions);
408 }
409
410 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
411 {
412   myMenuMgr->updateViewerMenu(theStdActions);
413 }
414
415
416 void PartSet_Module::activeSelectionModes(QIntList& theModes)
417 {
418   theModes.clear();
419   if (mySketchMgr->activeSketch().get())
420     PartSet_SketcherMgr::sketchSelectionModes(theModes);
421 }
422
423 bool PartSet_Module::isMouseOverWindow()
424 {
425   return mySketchMgr->isMouseOverWindow();
426 }
427
428 void PartSet_Module::closeDocument()
429 {
430   clearViewer();
431 }
432
433 void PartSet_Module::clearViewer()
434 {
435   myCustomPrs->clearPrs();
436 }
437
438 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
439 {
440   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
441   if (!aFOperation)
442     return;
443
444   ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
445   if (PartSet_SketcherMgr::isSketchOperation(aFOperation) &&  (aFOperation->isEditOperation())) {
446     // we have to manually activate the sketch label in edit mode
447       aPanel->activateWidget(aPanel->modelWidgets().first());
448       return;
449   }
450
451   // Restart last operation type 
452   if ((aFOperation->id() == myLastOperationId) && myLastFeature) {
453     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
454     if (aFOperation->id().toStdString() == SketchPlugin_Line::ID()) {
455       // Initialise new line with first point equal to end of previous
456       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
457       if (aPnt2dWgt) {
458         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
459         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
460           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
461         if (aPoint) {
462           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
463           PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), aFOperation->feature(), 
464             aWgt->attributeID(), aPoint->x(), aPoint->y());
465           aPanel->activateNextWidget(aPnt2dWgt);
466         }
467       }
468     }
469   }
470 }
471
472
473 void PartSet_Module::onSelectionChanged()
474 {
475   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
476   if (!aOperation)
477     return;
478
479   bool isSketcherOp = false;
480   // An edit operation is enable only if the current opeation is the sketch operation
481   if (mySketchMgr->activeSketch()) {
482     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
483       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
484   }
485   if (isSketcherOp) {
486     // Editing of constraints can be done on selection
487     ModuleBase_ISelection* aSelect = myWorkshop->selection();
488     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
489     if (aSelected.size() == 1) {
490       ModuleBase_ViewerPrs aPrs = aSelected.first();
491       ObjectPtr aObject = aPrs.object();
492       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
493       if (aFeature) {
494         std::string aId = aFeature->getKind();
495         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
496             (aId == SketchPlugin_ConstraintLength::ID()) || 
497             (aId == SketchPlugin_ConstraintDistance::ID()) ||
498             (aId == SketchPlugin_ConstraintAngle::ID())) {
499           editFeature(aFeature);
500         }
501       }
502     }
503   } 
504 }
505
506 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
507 {
508   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
509   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
510   anOpMgr->onKeyReleased(theEvent);
511 }
512
513 void PartSet_Module::onEnterReleased()
514 {
515   myRestartingMode = RM_EmptyFeatureUsed;
516 }
517
518 void PartSet_Module::onOperationActivatedByPreselection()
519 {
520   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
521   if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
522     // Set final definitions if they are necessary
523     //propertyPanelDefined(aOperation);
524
525     /// Commit sketcher operations automatically
526     anOperation->commit();
527   }
528 }
529
530 void PartSet_Module::onNoMoreWidgets()
531 {
532   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
533   if (anOperation) {
534     if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
535       if (myRestartingMode != RM_Forbided)
536         myRestartingMode = RM_LastFeatureUsed;
537       XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
538       XGUI_Workshop* aWorkshop = aConnector->workshop();
539       XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
540       // do nothing if the feature can not be applyed
541       if (anOpMgr->isApplyEnabled())
542         anOperation->commit();
543     }
544   }
545 }
546
547 void PartSet_Module::onVertexSelected()
548 {
549   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
550   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
551     /// If last line finished on vertex the lines creation sequence has to be break
552     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
553     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
554     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
555     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
556     bool aFoundWidget = false;
557     bool aFoundObligatory = false;
558     for (; anIt != aLast && !aFoundObligatory; anIt++) {
559       if (!aFoundWidget)
560         aFoundWidget = *anIt == anActiveWidget;
561       else
562         aFoundObligatory = (*anIt)->isObligatory();
563     }
564     if (!aFoundObligatory)
565       myRestartingMode = RM_Forbided;
566   }
567 }
568
569 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
570                                             Config_WidgetAPI* theWidgetApi, std::string theParentId)
571 {
572   ModuleBase_IWorkshop* aWorkshop = workshop();
573   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
574   XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
575   ModuleBase_ModelWidget* aWgt = NULL;
576   if (theType == "sketch-start-label") {
577     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
578       theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
579     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
580       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
581     connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
582       mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
583     aWgt = aLabelWgt;
584   } else if (theType == "sketch-2dpoint_selector") {
585     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
586                                                                  theWidgetApi, theParentId);
587     aPointWgt->setSketch(mySketchMgr->activeSketch());
588     connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
589     aWgt = aPointWgt;
590   } else if (theType == "point2ddistance") {
591     PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
592                                                         aWorkshop, theWidgetApi, theParentId);
593     aDistanceWgt->setSketch(mySketchMgr->activeSketch());
594     aWgt = aDistanceWgt;
595   } else if(theType == "point2dangle") {
596     PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent,
597                                                            aWorkshop, theWidgetApi, theParentId);
598     anAngleWgt->setSketch(mySketchMgr->activeSketch());
599     aWgt = anAngleWgt;
600   } else if (theType == "sketch_shape_selector") {
601     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
602       new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
603     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
604     aWgt = aShapeSelectorWgt;
605   } else if (theType == "sketch_multi_selector") {
606     PartSet_WidgetMultiSelector* aShapeSelectorWgt =
607       new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
608     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
609     aWgt = aShapeSelectorWgt;
610   } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
611     aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
612   } else if (theType == "export_file_selector") {
613     aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
614   } else if (theType == "sketch_launcher") {
615     aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
616   }
617   return aWgt;
618 }
619
620
621 bool PartSet_Module::deleteObjects()
622 {
623   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
624   XGUI_Workshop* aWorkshop = aConnector->workshop();
625   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
626
627   //SessionPtr aMgr = ModelAPI_Session::get();
628   // 1. check whether the delete should be processed in the module
629   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
630   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
631        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
632   if (isSketchOp || isNestedOp) {
633     // 2. find selected presentations
634     // selected objects should be collected before the current operation abort because
635     // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
636     ModuleBase_ISelection* aSel = workshop()->selection();
637     QObjectPtrList aSelectedObj = aSel->selectedPresentations();
638     // if there are no selected objects in the viewer, that means that the selection in another
639     // place cased this method. It is necessary to return the false value to understande in above
640     // method that delete is not processed
641     if (aSelectedObj.count() == 0)
642       return false;
643
644     // avoid delete of the objects, which are not belong to the current sketch
645     // in order to do not delete results of other sketches
646     QObjectPtrList aSketchObjects;
647     QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
648     for ( ; anIt != aLast; anIt++) {
649       ObjectPtr anObject = *anIt;
650       if (mySketchMgr->isObjectOfSketch(anObject)) {
651         // sketch feature should be used in this list because workshop deletes features only
652         // results are skipped
653         FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
654         aSketchObjects.append(aSketchFeature);
655       }
656     }
657     // if the selection contains only local selected presentations from other sketches,
658     // the Delete operation should not be done at all
659     if (aSketchObjects.size() == 0)
660       return true;
661
662     // 3. start operation
663     QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
664     ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
665
666     // the active nested sketch operation should be aborted unconditionally
667     // the Delete action should be additionally granted for the Sketch operation
668     // in order to do not abort/commit it
669     if (!anOpMgr->canStartOperation(anOpAction->id(), isSketchOp/*granted*/))
670       return true; // the objects are processed but can not be deleted
671
672     anOpMgr->startOperation(anOpAction);
673
674     // 4. delete features
675     // sketch feature should be skipped, only sub-features can be removed
676     // when sketch operation is active
677     aWorkshop->deleteFeatures(aSketchObjects);
678     // 5. stop operation
679     anOpMgr->commitOperation();
680   }
681   else {
682     bool isPartRemoved = false;
683     // Delete part with help of PartSet plugin
684     // TODO: the deleted objects has to be processed by multiselection
685     QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
686     if (aObjects.size() == 1) {
687       ObjectPtr aObj = aObjects.first();
688       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
689       if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
690         // Remove feature should be created in the document of the part results
691         ResultPtr aPartResult = aFeature->firstResult();
692         if (aPartResult.get()) {
693           std::shared_ptr<ModelAPI_ResultPart> aPart =
694                        std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
695           DocumentPtr aPartDoc = aPart->partDoc();
696           if (aPartDoc.get()) {
697             ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction
698                                               (PartSetPlugin_Remove::ID().c_str(), this);
699             if (!anOpMgr->canStartOperation(anOpAction->id()))
700               return true; // the objects are processed but can not be deleted
701
702             anOpMgr->startOperation(anOpAction);
703
704             FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
705             aFeature->execute();
706
707             anOpMgr->commitOperation();
708             isPartRemoved = true;
709           }
710         }
711       }
712     }
713     return isPartRemoved;
714   }
715   return true;
716 }
717
718 void PartSet_Module::onFeatureTriggered()
719 {
720   QAction* aCmd = dynamic_cast<QAction*>(sender());
721   if (aCmd->isCheckable() && aCmd->isChecked()) {
722     // 1. check whether the delete should be processed in the module
723     ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
724     bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
725     if (isNestedOp) {
726       // in case if in the viewer nothing is displayed, the create operation should not be
727       // comitted even if all values of the feature are initialized
728       if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
729         // the action information should be saved before the operation is aborted
730         // because this abort leads to update command status, which unchecks this action
731         anOperation->abort();
732         launchOperation(aCmd->data().toString());
733       }
734     }
735   }
736   ModuleBase_IModule::onFeatureTriggered();
737 }
738
739 void PartSet_Module::launchOperation(const QString& theCmdId)
740 {
741   if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
742     // Show constraints if a constraint was anOperation
743     mySketchMgr->onShowConstraintsToggle(true);
744   }
745   ModuleBase_IModule::launchOperation(theCmdId);
746 }
747
748
749 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) 
750 {
751   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
752   if (!anAIS.IsNull()) {
753     Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
754     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
755     if (!aDim.IsNull()) {
756       aCtx->SetZLayer(aDim, myVisualLayerId);
757     } else {
758       Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
759       if (!aCons.IsNull())
760         aCtx->SetZLayer(aCons, myVisualLayerId);
761     }
762   }
763 }
764
765 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
766 {
767   // this is obsolete
768   // it should be recomputed in order to disappear in the viewer if the corresponded object
769   // is erased
770   //if (myCustomPrs->isActive())
771   //  myCustomPrs->redisplay(theObject, false);
772 }
773
774 void PartSet_Module::onViewTransformed(int theTrsfType)
775 {
776   // Set length of arrows constant in pixel size
777   // if the operation is panning or rotate or panglobal then do nothing
778   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
779     return;
780
781   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
782   //Handle(V3d_View) aView = aViewer->activeView();
783
784   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
785   XGUI_Workshop* aWorkshop = aConnector->workshop();
786   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
787   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
788
789   Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
790   Handle(V3d_View) aView;
791   double aScale = 0;
792   for (aV3dViewer->InitDefinedViews(); 
793        aV3dViewer->MoreDefinedViews(); 
794        aV3dViewer->NextDefinedViews()) {
795     Handle(V3d_View) aV = aV3dViewer->DefinedView();
796     double aS = aV->Scale();
797     if (aS > aScale) {
798       aScale = aS;
799       aView = aV;
800     }
801   }
802   if (aView.IsNull())
803     return;
804   double aLen = aView->Convert(20);
805
806   double aPrevLen = SketcherPrs_Tools::getArrowSize();
807   SketcherPrs_Tools::setArrowSize(aLen);
808   const double aPrevScale = aViewer->Scale(aViewer->activeView());
809   const double aCurScale = aViewer->activeView()->Camera()->Scale();
810   aViewer->SetScale(aViewer->activeView(), aCurScale);
811   SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
812   bool isModified = false;
813   QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
814   foreach (AISObjectPtr aAIS, aPrsList) {
815     Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
816
817     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
818     if (!aDim.IsNull()) {
819       aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
820       aContext->Redisplay(aDim, false);
821       isModified = true;
822     }
823   }
824   if (isModified)
825     aDisplayer->updateViewer();
826 }
827
828 bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
829 {
830   bool isRedisplayed = false;
831   if (myCustomPrs->isActive())
832     isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
833
834   return isRedisplayed;
835 }
836
837 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
838 {
839   XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
840   if (aOB) {
841     //QLineEdit* aLabel = aOB->activeDocLabel();
842     //QPalette aPalet = aLabel->palette();
843     //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
844     //aLabel->setPalette(aPalet);
845     aOB->treeView()->setExpandsOnDoubleClick(false);
846     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)), 
847       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
848 #ifdef ModuleDataModel
849     connect(aOB, SIGNAL(headerMouseDblClicked(const QModelIndex&)), 
850       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
851     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)), 
852       myDataModel, SLOT(onMouseDoubleClick(const QModelIndex&)));
853 #endif
854   }
855 }
856
857 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
858 {
859   ObjectPtr anObject;
860   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
861   if (aOperation) {
862     /// If last line finished on vertex the lines creation sequence has to be break
863     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
864     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
865     // if there is an active widget, find the presented object in it
866     if (!anActiveWidget)
867       anActiveWidget = aPanel->preselectionWidget();
868     
869     ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
870                                                                            (anActiveWidget);
871     if (aWidgetValidated)
872       anObject = aWidgetValidated->findPresentedObject(theAIS);
873   }
874   return anObject;
875 }
876
877 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
878 {
879   QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
880   int aSelected = aObjects.size();
881   SessionPtr aMgr = ModelAPI_Session::get();
882   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
883   QAction* aActivatePartSetAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
884   if (aSelected == 1) {
885     bool hasResult = false;
886     bool hasFeature = false;
887     bool hasParameter = false;
888     bool hasSubFeature = false;
889     ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
890
891     ObjectPtr aObject = aObjects.first();
892     if (aObject) {
893       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
894       FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
895       bool isPart = aPart.get() || 
896         (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID()));
897       if (isPart) {
898         DocumentPtr aPartDoc;
899         if (!aPart.get()) {
900           aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
901         }
902         if (aPart.get()) // this may be null is Part feature is disabled
903           aPartDoc = aPart->partDoc();
904           
905         theMenu->addAction(aActivatePartAction);
906         aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
907
908       } else if (aObject->document() == aMgr->activeDocument()) {
909         if (hasParameter || hasFeature)
910           theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
911       }
912
913       ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
914       if( aResult.get() )
915         theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
916     } else {  // If feature is 0 the it means that selected root object (document)
917       theMenu->addAction(aActivatePartSetAction);
918       aActivatePartSetAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
919     }
920   } else if (aSelected == 0) {
921     // if there is no selection then it means that upper label is selected
922     QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
923     if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
924       theMenu->addAction(aActivatePartSetAction);
925       aActivatePartSetAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
926   }
927   bool aNotDeactivate = (myWorkshop->currentOperation() == 0);
928   if (!aNotDeactivate) {
929     aActivatePartAction->setEnabled(false);
930     aActivatePartSetAction->setEnabled(false);
931   }
932 }
933
934 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
935 {
936   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
937     // Do not change activation of parts if an operation active
938     static QStringList aAllowActivationList;
939     if (aAllowActivationList.isEmpty())
940       aAllowActivationList << 
941       QString(PartSetPlugin_Part::ID().c_str()) << 
942       QString(PartSetPlugin_Duplicate::ID().c_str()) <<
943       QString(PartSetPlugin_Remove::ID().c_str());
944     if (myWorkshop->currentOperation() && 
945       (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
946       return;
947     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
948     XGUI_Workshop* aWorkshop = aConnector->workshop();
949     XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
950     QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
951     QPalette aPalet = aLabel->palette();
952
953     SessionPtr aMgr = ModelAPI_Session::get();
954     DocumentPtr aActiveDoc = aMgr->activeDocument();
955 #ifdef ModuleDataModel
956     QModelIndex aOldIndex = myDataModel->activePartTree();
957     DocumentPtr aDoc = aMgr->moduleDocument();
958     if (aActiveDoc == aDoc) {
959       if (aOldIndex.isValid())
960         aTreeView->setExpanded(aOldIndex, false);
961       myDataModel->deactivatePart();
962       aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
963     } else {
964       std::string aGrpName = ModelAPI_ResultPart::group();
965       for (int i = 0; i < aDoc->size(aGrpName); i++) {
966         ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
967         if (aPart->partDoc() == aActiveDoc) {
968           QModelIndex aIndex = myDataModel->partIndex(aPart);
969           if (myDataModel->activatePart(aIndex)) {
970             if (aOldIndex.isValid())
971               aTreeView->setExpanded(aOldIndex, false);
972             aTreeView->setExpanded(myDataModel->activePartTree(), true);
973             aPalet.setColor(QPalette::Text, Qt::black);
974           }
975           break;
976         }
977       }
978     }
979 #else
980     // Problem with MPV: At first time on creation it doesn't work because Part feature
981     // creation event will be sent after
982     if (aActivePartIndex.isValid())
983       aTreeView->setExpanded(aActivePartIndex, false);
984     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
985     aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
986     if (aActivePartIndex.isValid())
987       aTreeView->setExpanded(aActivePartIndex, true);
988 #endif
989     aLabel->setPalette(aPalet);
990     aWorkshop->updateCommandStatus();
991
992     // Update displayed objects in order to update active color
993     XGUI_Displayer* aDisplayer = aWorkshop->displayer();
994     QObjectPtrList aObjects = aDisplayer->displayedObjects();
995     foreach(ObjectPtr aObj, aObjects)
996       aDisplayer->redisplay(aObj, false);
997     aDisplayer->updateViewer();
998   }
999 }
1000
1001 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1002 {
1003   if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1004     return;
1005   SessionPtr aMgr = ModelAPI_Session::get();
1006   if (!theIndex.isValid()) {
1007     aMgr->setActiveDocument(aMgr->moduleDocument());
1008     return;
1009   }
1010   if (theIndex.column() != 0) // Use only first column
1011     return;
1012 #ifdef ModuleDataModel
1013   ObjectPtr aObj = myDataModel->object(theIndex);
1014 #else
1015   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
1016   XGUI_Workshop* aWorkshop = aConnector->workshop();
1017   XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1018   // De not use non editable Indexes
1019   if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1020     return;
1021   ObjectPtr aObj = aDataModel->object(theIndex);
1022 #endif
1023
1024   ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1025   if (!aPart.get()) { // Probably this is Feature
1026     FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1027     if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1028       aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1029     }
1030   }
1031   if (aPart.get()) { // if this is a part
1032     if (aPart->partDoc() == aMgr->activeDocument()) {
1033       myMenuMgr->activatePartSet();
1034     } else {
1035       aPart->activate();
1036     }
1037   }
1038 }
1039
1040
1041 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1042 {
1043   // z layer is created for all started operations in order to visualize operation AIS presentation
1044   // over the object
1045   Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
1046   if (myVisualLayerId == 0) {
1047     if (myVisualLayerId == 0)
1048       aViewer->AddZLayer(myVisualLayerId);
1049   } else {
1050     TColStd_SequenceOfInteger aZList;
1051     aViewer->GetAllZLayers(aZList);
1052     bool aFound = false;
1053     for (int i = 1; i <= aZList.Length(); i++) {
1054       if (aZList(i) == myVisualLayerId) {
1055         aFound = true;
1056         break;
1057       }
1058     }
1059     if (!aFound)
1060       aViewer->AddZLayer(myVisualLayerId);
1061   }
1062 }