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