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