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