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