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