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