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