]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
5.2.2 Drawing in the sketcher: change the mouse cursor arrow
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "PartSet_Module.h"
21 #include "PartSet_WidgetSketchLabel.h"
22 #include "PartSet_Validators.h"
23 #include "PartSet_Tools.h"
24 #include "PartSet_PreviewPlanes.h"
25 #include "PartSet_WidgetPoint2d.h"
26 #include "PartSet_WidgetPoint2DFlyout.h"
27 #include "PartSet_WidgetShapeSelector.h"
28 #include "PartSet_WidgetMultiSelector.h"
29 #include "PartSet_WidgetFeaturePointSelector.h"
30 #include "PartSet_WidgetEditor.h"
31 #include "PartSet_WidgetFileSelector.h"
32 #include "PartSet_WidgetSketchCreator.h"
33 #include "PartSet_SketcherMgr.h"
34 #include "PartSet_SketcherReentrantMgr.h"
35 #include "PartSet_ResultSketchPrs.h"
36 #include "PartSet_MenuMgr.h"
37 #include "PartSet_CustomPrs.h"
38 #include "PartSet_IconFactory.h"
39 #include "PartSet_OverconstraintListener.h"
40 #include "PartSet_TreeNodes.h"
41 #include "PartSet_FieldStepPrs.h"
42
43 #include "PartSet_Filters.h"
44 #include "PartSet_FilterInfinite.h"
45
46 #ifdef _DEBUG
47 #include <QDebug>
48 #endif
49
50 #include <PartSetPlugin_Remove.h>
51 #include <PartSetPlugin_Part.h>
52 #include <PartSetPlugin_Duplicate.h>
53
54 #include <SketchPlugin_ConstraintCoincidence.h>
55
56 #include <ModuleBase_Operation.h>
57 #include <ModuleBase_OperationAction.h>
58 #include <ModuleBase_IViewer.h>
59 #include <ModuleBase_IViewWindow.h>
60 #include <ModuleBase_IPropertyPanel.h>
61 #include <ModuleBase_ISelectionActivate.h>
62 #include <ModuleBase_WidgetChoice.h>
63 #include <ModuleBase_WidgetEditor.h>
64 #include <ModuleBase_WidgetValidated.h>
65 #include <ModuleBase_Tools.h>
66 #include <ModuleBase_OperationFeature.h>
67 #include <ModuleBase_WidgetFactory.h>
68 #include <ModuleBase_OperationDescription.h>
69 #include <ModuleBase_ViewerPrs.h>
70 #include <ModelAPI_ResultField.h>
71
72 #include <ModelAPI_Object.h>
73 #include <ModelAPI_Events.h>
74 #include <ModelAPI_Validator.h>
75 #include <ModelAPI_Data.h>
76 #include <ModelAPI_Session.h>
77 #include <ModelAPI_ResultBody.h>
78 #include <ModelAPI_AttributeString.h>
79 #include <ModelAPI_AttributeSelectionList.h>
80 #include <ModelAPI_Tools.h>
81 #include <ModelAPI_ResultConstruction.h>
82 #include <ModelAPI_AttributeIntArray.h>
83
84 #include <GeomDataAPI_Point2D.h>
85 #include <GeomDataAPI_Point.h>
86 #include <GeomDataAPI_Dir.h>
87
88 #include <XGUI_ActiveControlMgr.h>
89 #include <XGUI_ActiveControlSelector.h>
90 #include <XGUI_ActionsMgr.h>
91 #include <XGUI_ContextMenuMgr.h>
92 #include <XGUI_CustomPrs.h>
93 #include <XGUI_DataModel.h>
94 #include <XGUI_Displayer.h>
95 #include <XGUI_ErrorMgr.h>
96 #include <XGUI_FacesPanelSelector.h>
97 #include <XGUI_ModuleConnector.h>
98 #include <XGUI_ObjectsBrowser.h>
99 #include <XGUI_OperationMgr.h>
100 #include <XGUI_PropertyPanel.h>
101 #include <XGUI_SelectionMgr.h>
102 #include <XGUI_Tools.h>
103 #include <XGUI_Workshop.h>
104
105 #include <SketchPlugin_ConstraintAngle.h>
106 #include <SketchPlugin_ConstraintLength.h>
107 #include <SketchPlugin_ConstraintDistance.h>
108 #include <SketchPlugin_ConstraintParallel.h>
109 #include <SketchPlugin_ConstraintPerpendicular.h>
110 #include <SketchPlugin_ConstraintRadius.h>
111 #include <SketchPlugin_Feature.h>
112 #include <SketchPlugin_Projection.h>
113 #include <SketchPlugin_Sketch.h>
114
115 #include <SketcherPrs_SymbolPrs.h>
116 #include <SketcherPrs_PositionMgr.h>
117 #include <SketcherPrs_Coincident.h>
118 #include <SketcherPrs_Tools.h>
119
120 #include <Events_Loop.h>
121 #include <Config_PropManager.h>
122 #include <Config_Keywords.h>
123
124 #include <AIS_Dimension.hxx>
125 #include <AIS_InteractiveObject.hxx>
126 #include <StdSelect_TypeOfFace.hxx>
127 #include <TopoDS_Vertex.hxx>
128 #include <TopoDS.hxx>
129 #include <TopoDS_Shape.hxx>
130 #include <BRep_Tool.hxx>
131
132 #include <QObject>
133 #include <QMouseEvent>
134 #include <QString>
135 #include <QTimer>
136 #include <QApplication>
137 #include <QMessageBox>
138 #include <QMainWindow>
139 #include <QLineEdit>
140 #include <QString>
141
142 #include <GeomAlgoAPI_FaceBuilder.h>
143 #include <GeomDataAPI_Dir.h>
144
145 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
146
147 /*!Create and return new instance of XGUI_Module*/
148 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
149 {
150   return new PartSet_Module(theWshop);
151 }
152
153 //******************************************************
154 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
155 : ModuleBase_IModule(theWshop),
156   myVisualLayerId(0),
157   myRoot(0),
158   myIsOperationIsLaunched(false)
159 {
160   new PartSet_IconFactory(this);
161
162   mySketchMgr = new PartSet_SketcherMgr(this);
163   mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
164
165   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
166   XGUI_Workshop* aWorkshop = aConnector->workshop();
167
168   ModuleBase_IViewer* aViewer = theWshop->viewer();
169   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
170           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
171   connect(aViewer, SIGNAL(viewTransformed(int)),
172           SLOT(onViewTransformed(int)));
173   connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
174           SLOT(onViewCreated(ModuleBase_IViewWindow*)));
175   myMenuMgr = new PartSet_MenuMgr(this);
176   myCustomPrs = new PartSet_CustomPrs(theWshop);
177
178   myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
179
180   Events_Loop* aLoop = Events_Loop::loop();
181   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
182   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
183
184   registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
185   registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
186   Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
187   std::set<std::string> aCRGroupNames;
188   aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
189   aCRFilter->setGroupNames(aCRGroupNames);
190   registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
191
192   setDefaultConstraintShown();
193
194   Config_PropManager::registerProp("Visualization", "operation_parameter_color",
195                           "Reference shape wireframe color in operation", Config_Prop::Color,
196                           PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
197   Config_PropManager::registerProp("Visualization", "operation_result_color",
198                           "Result shape wireframe color in operation", Config_Prop::Color,
199                           PartSet_CustomPrs::OPERATION_RESULT_COLOR());
200   Config_PropManager::registerProp("Visualization", "operation_highlight_color",
201                           "Multi selector item color in operation", Config_Prop::Color,
202                           PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
203   Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
204                           "Color of removed feature in operation", Config_Prop::Color,
205                           PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
206   Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
207                           "Color of sketch plane", Config_Prop::Color,
208                           PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
209
210   Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
211                                    "Hidden faces transparency",
212                                    Config_Prop::DblSpin,
213                                    "0.8");
214   std::ostringstream aStream;
215   aStream << SketcherPrs_Tools::getDefaultArrowSize();
216   Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
217     "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
218
219   Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
220     Config_Prop::String, "Times-bold");
221
222   aStream.str("");
223   aStream.clear();
224   aStream << SketcherPrs_Tools::getDefaultTextHeight();
225   Config_PropManager::registerProp("Visualization", "dimension_value_size",
226     "Dimension value size", Config_Prop::IntSpin, aStream.str());
227
228   Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
229     "Dimension color",
230     Config_Prop::Color, SKETCH_DIMENSION_COLOR);
231
232   Config_PropManager::registerProp("Shortcuts", "add_parameter_shortcut",
233     "Add parameter in parameters manager dialog",
234     Config_Prop::Shortcut, "Ctrl+A");
235 }
236
237 //******************************************************
238 PartSet_Module::~PartSet_Module()
239 {
240   delete myCustomPrs;
241   delete myOverconstraintListener;
242   delete myRoot;
243 }
244
245 //******************************************************
246 void PartSet_Module::createFeatures()
247 {
248   ModuleBase_IModule::createFeatures();
249   myRoot = new PartSet_RootNode();
250   myRoot->setWorkshop(workshop());
251 }
252
253
254 //******************************************************
255 void PartSet_Module::storeSelection()
256 {
257   // cash is used only to restore selection, so it should be filled in storeSelection and
258   // after applying immediatelly cleared in restoreSelection
259   myCurrentSelection.clear();
260   sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
261 }
262
263 //******************************************************
264 void PartSet_Module::restoreSelection()
265 {
266   // cash is used only to restore selection, so it should be filled in storeSelection and
267   // after applying immediatelly cleared in restoreSelection
268   sketchMgr()->restoreSelection(myCurrentSelection);
269   myCurrentSelection.clear();
270 }
271
272 //******************************************************
273 void PartSet_Module::registerValidators()
274 {
275   //Registering of validators
276   SessionPtr aMgr = ModelAPI_Session::get();
277   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
278   aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
279   aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
280   aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
281   aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
282   aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
283   aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
284   aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
285   aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
286   aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
287   aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
288   aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
289   aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
290   aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
291   aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
292   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
293   aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
294   aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
295   aFactory->registerValidator("PartSet_MultyTranslationSelection",
296     new PartSet_MultyTranslationSelection);
297   aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
298   aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
299   aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
300 }
301
302 //******************************************************
303 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
304                                             const bool isToConnect)
305 {
306   mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
307 }
308
309 //******************************************************
310 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
311 {
312   if (sketchMgr()->isNestedSketchOperation(theOperation)) {
313     mySketchMgr->commitNestedSketch(theOperation);
314   }
315   /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
316   if (PartSet_SketcherMgr::isSketchOperation(theOperation))
317     overconstraintListener()->setActive(false);
318
319   /// Restart sketcher operations automatically
320   if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
321
322     ModuleBase_OperationFeature* aFOperation =
323       dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
324     if (aFOperation && !aFOperation->isEditOperation()) {
325       // the selection is cleared after commit the create operation
326       // in order to do not use the same selected objects in the restarted operation
327       // for common behaviour, the selection is cleared even if the operation is not restarted
328       getWorkshop()->selector()->clearSelection();
329     }
330   }
331 }
332
333 //******************************************************
334 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
335 {
336   /// Restart sketcher operations automatically
337   mySketchReentrantMgr->operationAborted(theOperation);
338   /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
339   if (PartSet_SketcherMgr::isSketchOperation(theOperation))
340     overconstraintListener()->setActive(false);
341 }
342
343 //******************************************************
344 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
345 {
346   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
347                                                                                 (theOperation);
348   if (aFOperation) {
349     XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
350     XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
351
352     ModuleBase_ModelWidget* aFilledWidget = 0;
353     bool aPostonedWidgetActivation = false;
354
355     FeaturePtr aFeature = aFOperation->feature();
356     /// Restart sketcher operations automatically
357     /// it is important to call method of sketch reentrant manager before filling of PP
358     /// because it fills some created feature attributes, these new values should be used
359     /// to fill the property panel
360     mySketchReentrantMgr->operationStarted(theOperation);
361
362     aWorkshop->fillPropertyPanel(aFOperation);
363     // filling the operation values by the current selection
364     // if the operation can be committed after the controls filling, the method perform should
365     // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
366     bool isOperationCommitted = false;
367     if (!aFOperation->isEditOperation()) {
368       std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
369       // if there is a greed attribute, automatic commit by preselection
370       // for this feature is prohibited
371       aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
372       if (currentOperation() != aFOperation)
373         isOperationCommitted = true;
374       else {
375         if (aGreedAttributeId.empty()) {
376           // a signal should be emitted before the next widget activation
377           // because, the activation of the next widget will give a focus to the widget.
378           // As a result the value of the widget is initialized.
379           // And commit may happens until the value is entered.
380           if (aFilledWidget) {
381             if (mySketchReentrantMgr->canBeCommittedByPreselection())
382               isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
383             // activate the next obligatory widget
384             if (!isOperationCommitted)
385               aPropertyPanel->activateNextWidget(aFilledWidget);
386           }
387         }
388         else { // there is a greed widget
389           const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
390           std::string aFirstAttributeId = aWidgets.front()->attributeID();
391           // activate next widget after greeded if it is the first widget in the panel
392           // else the first panel widget is already activated by operation start
393           if (aFirstAttributeId == aGreedAttributeId)
394             aPostonedWidgetActivation = true;
395         }
396       }
397     } if (!isOperationCommitted) {
398       aWorkshop->connectToPropertyPanel(true);
399       updateSketcherOnStart(aFOperation);
400       updatePresentationsOnStart(aFOperation);
401
402       // the objects of the current operation should be deactivated
403       QObjectPtrList anObjects;
404       anObjects.append(aFeature);
405       std::list<ResultPtr> aResults;
406       ModelAPI_Tools::allResults(aFeature, aResults);
407       std::list<ResultPtr>::const_iterator aIt;
408       for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
409         anObjects.append(*aIt);
410       }
411       QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
412       for (; anIt != aLast; anIt++)
413         aWorkshop->deactivateActiveObject(*anIt, false);
414       if (anObjects.size() > 0) {
415         XGUI_Displayer* aDisplayer = aWorkshop->displayer();
416         aDisplayer->updateViewer();
417       }
418       /// state of command actions should be updated after displayed objects modification because
419       /// deactivation(for example) of objects may influence on selection in the viewer
420       /// State of command actions may depend on selection in the viewer(e.g. Sketch)
421       workshop()->updateCommandStatus();
422     }
423     if (aPostonedWidgetActivation) {
424       // if the widget is an empty in the chain of activated widgets, the current operation
425       // is restarted. It should be performed after functionality of the operation starting
426       aPropertyPanel->activateNextWidget(aFilledWidget);
427     }
428   }
429 }
430
431 //******************************************************
432 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
433 {
434   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
435     mySketchMgr->startSketch(theOperation);
436   }
437   // It is switched off because of
438   // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
439   //else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
440   //  mySketchMgr->startNestedSketch(theOperation);
441   //}
442 }
443
444 //******************************************************
445 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
446 {
447   ModuleBase_OperationFeature* aFOperation =
448     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
449   if (aFOperation) {
450     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
451     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
452   }
453 }
454
455 //******************************************************
456 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
457 {
458   ModuleBase_IModule::operationResumed(theOperation);
459
460   ModuleBase_OperationFeature* aFOperation =
461     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
462   if (aFOperation) {
463     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
464     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
465   }
466 }
467
468 //******************************************************
469 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
470 {
471   bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
472   bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
473   bool isModified = isModifiedArgs || isModifiedResults;
474
475   if (sketchMgr()->isNestedSketchOperation(theOperation)) {
476     mySketchMgr->stopNestedSketch(theOperation);
477   }
478   else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
479     setDefaultConstraintShown();
480
481   //VSV: Viewer is updated on feature update and redisplay
482   if (isModified) {
483     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
484     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
485     aDisplayer->updateViewer();
486   }
487
488   QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
489     anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
490   for (; anIt != aLast; anIt++) {
491     mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
492   }
493 }
494
495 //******************************************************
496 ModuleBase_Operation* PartSet_Module::currentOperation() const
497 {
498   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
499   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
500   return anOpMgr->currentOperation();
501 }
502
503 //******************************************************
504 bool PartSet_Module::canUndo() const
505 {
506   bool aCanUndo = false;
507   SessionPtr aMgr = ModelAPI_Session::get();
508   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
509     aCanUndo = !aMgr->isOperation();
510     if (!aCanUndo) // check the enable state additionally by sketch manager
511       aCanUndo = aMgr->canUndo();
512   }
513   return aCanUndo;
514 }
515
516 //******************************************************
517 bool PartSet_Module::canRedo() const
518 {
519   bool aCanRedo = false;
520   SessionPtr aMgr = ModelAPI_Session::get();
521   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
522     aCanRedo = !aMgr->isOperation();
523     if (!aCanRedo) // check the enable state additionally by sketch manager
524       aCanRedo = aMgr->canRedo();
525   }
526   return aCanRedo;
527 }
528
529 //******************************************************
530 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
531 {
532   bool aValid = true;
533   if (theActionId == "MOVE_CMD") {
534     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
535     if (aFeature) {
536       ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
537       // part features can not be moved in the history.
538       if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
539         aValid = false;
540     }
541   }
542   return aValid;
543 }
544
545 //******************************************************
546 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
547 {
548   // the sketch manager put the restriction to the objects erase
549   return mySketchMgr->canEraseObject(theObject);
550 }
551
552 //******************************************************
553 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
554 {
555   // the sketch manager put the restriction to the objects display
556   return mySketchMgr->canDisplayObject(theObject);
557 }
558
559 //******************************************************
560 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
561                                         const QString& theStartedOperationKind)
562 {
563   if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
564     return true;
565
566   return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
567 }
568
569 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
570 {
571   mySketchMgr->processHiddenObject(theObjects);
572 }*/
573
574 //******************************************************
575 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
576 {
577   bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
578
579   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
580   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
581        isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
582   if (isSketchOp || isNestedOp) {
583     // in active sketch operation it is possible to activate operation object in selection
584     // in the edit operation, e.g. points of the line can be moved when the line is edited
585     ModuleBase_OperationFeature* aFOperation =
586       dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
587     aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
588   }
589   return aCanActivate;
590 }
591
592 //******************************************************
593 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
594                                    QWidget* theParent,
595                                    QMap<int, QAction*>& theMenuActions) const
596 {
597   return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
598 }
599
600 //******************************************************
601 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
602 {
603   myMenuMgr->updateViewerMenu(theStdActions);
604 }
605
606 //******************************************************
607 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
608 {
609   bool isEnabledFixed = false;
610   if (theActionId == XGUI_ActionsMgr::AcceptAll &&
611       mySketchReentrantMgr->isInternalEditActive())
612     isEnabledFixed = true;
613   return isEnabledFixed;
614 }
615
616 //******************************************************
617 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
618 {
619   QString anError = ModuleBase_IModule::getFeatureError(theFeature);
620   if (anError.isEmpty())
621     anError = sketchMgr()->getFeatureError(theFeature);
622
623   return anError;
624 }
625
626 //******************************************************
627 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
628                                          QStringList& theIds) const
629 {
630   myMenuMgr->grantedOperationIds(theOperation, theIds);
631
632   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
633     XGUI_Workshop* aWorkshop = getWorkshop();
634     theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
635   }
636 }
637
638 //******************************************************
639 void PartSet_Module::activeSelectionModes(QIntList& theModes)
640 {
641   if (mySketchMgr->activeSketch().get())
642     PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
643   else
644     theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
645 }
646
647 //******************************************************
648 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
649 {
650   customSubShapesSelectionModes(theModes);
651   //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
652   //myWorkshop->module()->activeSelectionModes(theModes);
653 }
654
655 //******************************************************
656 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
657                                             SelectMgr_ListOfFilter& theSelectionFilters)
658 {
659   bool isSketchActive = mySketchMgr->activeSketch().get();
660
661   std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
662     mySelectionFilters.begin();
663   for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
664     int aFilterType = aFiltersIt->first;
665     // do not add not participating filters in given parameters
666     if (!theFilterTypes.contains(aFilterType))
667       continue;
668
669     // using sketch filters only if sketch operation is active
670     if (!isSketchActive &&
671         mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
672       continue;
673
674     // using filtering of construction results only from faces panel
675     if (aFilterType == SF_ResultGroupNameFilter)
676       continue;
677
678     theSelectionFilters.Append(aFiltersIt->second);
679   }
680 }
681
682 //******************************************************
683 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
684 {
685   if (theModes.contains(TopAbs_FACE))
686     theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
687   if (theModes.contains(TopAbs_WIRE))
688     theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
689
690   if (mySketchMgr->activeSketch().get())
691     PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
692 }
693
694 //******************************************************
695 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
696                                       ObjectPtr& theObject, AttributePtr& theAttribute)
697 {
698   ObjectPtr anObject = theSelected->object();
699   GeomShapePtr aShape = theSelected->shape();
700
701   theAttribute = findAttribute(anObject, aShape);
702   // TODO: try to create result if object is an external object
703   theObject = anObject;
704 }
705
706 //******************************************************
707 bool PartSet_Module::isMouseOverWindow()
708 {
709   return mySketchMgr->isMouseOverWindow();
710 }
711
712 //******************************************************
713 bool PartSet_Module::isSketchNeutralPointActivated() const
714 {
715   bool isNeutralPoint = true;
716   if (sketchReentranceMgr()->isInternalEditActive())
717     isNeutralPoint = false;
718   if (myIsOperationIsLaunched)
719     isNeutralPoint = false;
720
721   return isNeutralPoint;
722 }
723
724 //******************************************************
725 void PartSet_Module::closeDocument()
726 {
727   myActivePartIndex = QModelIndex();
728   SketcherPrs_PositionMgr::get()->clearAll();
729 }
730
731 //******************************************************
732 void PartSet_Module::clearViewer()
733 {
734   myCustomPrs->clearPrs();
735
736   XGUI_Workshop* aWorkshop = getWorkshop();
737   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
738   aDisplayer->deactivateSelectionFilters(false);
739 }
740
741 //******************************************************
742 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
743 {
744   ModuleBase_OperationFeature* aFOperation =
745     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
746   if (!aFOperation)
747     return;
748
749   ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
750   // we have to manually activate the sketch label in edit mode
751   if (PartSet_SketcherMgr::isSketchOperation(aFOperation) &&  (aFOperation->isEditOperation()))
752     aPanel->activateWidget(aPanel->modelWidgets().first());
753 }
754
755 //******************************************************
756 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
757                                    QList<ModuleBase_ModelWidget*>& theWidgets) const
758 {
759   bool aProcessed = false;
760
761   ModuleBase_OperationFeature* aFOperation =
762     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
763   XGUI_Workshop* aWorkshop = getWorkshop();
764   XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
765   if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
766     ModuleBase_ISelection* aSelection = workshop()->selection();
767     // click on a point in sketch leads here with the point is highlighted, not yet selected
768     QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
769     if (aPreselection.size() == 1) {
770       ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
771       ObjectPtr anObject = aSelectedPrs->object();
772
773       FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
774       FeaturePtr anOpFeature = aFOperation->feature();
775       GeomShapePtr aShape = aSelectedPrs->shape();
776       // click on the digit of dimension constrain comes here
777       // with an empty shape, so we need the check
778       if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
779         // if feature has only one result and shape of result is equal to selected shape
780         // this attribute is not processed. It is a case of Sketch Point.
781         if (aFeature->results().size() == 1) {
782           ResultPtr aResult = aFeature->results().front();
783           if (aResult.get() && aResult->shape()->isEqual(aShape))
784             return aProcessed;
785         }
786         const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
787         AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
788                                                                mySketchMgr->activeSketch());
789         if (anAttribute.get()) {
790           QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
791           ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
792
793           const std::string anAttributeId = anAttribute->id();
794           aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
795
796           theWidgets = aFactory.getModelWidgets();
797           // it is possible that the point does not present in XML definition,
798           // in this case, we assume that it is not processed by this module
799           // e.g. "Intersection point" feature
800           aProcessed = !theWidgets.isEmpty();
801         }
802       }
803     }
804   }
805   return aProcessed;
806 }
807
808 //******************************************************
809 void PartSet_Module::onSelectionChanged()
810 {
811   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
812   if (!aOperation)
813     return;
814
815   bool isSketcherOp = false;
816   // An edit operation is enable only if the current opeation is the sketch operation
817   if (mySketchMgr->activeSketch()) {
818     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
819       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
820   }
821   if (isSketcherOp) {
822     // Editing of constraints can be done on selection
823     ModuleBase_ISelection* aSelect = myWorkshop->selection();
824     QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
825     if (aSelected.size() == 1) {
826       ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
827       ObjectPtr aObject = aPrs->object();
828       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
829       if (aFeature) {
830         std::string aId = aFeature->getKind();
831         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
832             (aId == SketchPlugin_ConstraintLength::ID()) ||
833             (aId == SketchPlugin_ConstraintDistance::ID()) ||
834             (aId == SketchPlugin_ConstraintAngle::ID())) {
835           editFeature(aFeature);
836         }
837       }
838     }
839   }
840 }
841
842 //******************************************************
843 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
844 {
845   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
846   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
847   anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
848 }
849
850 //******************************************************
851 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
852                                                            QWidget* theParent,
853                                                            Config_WidgetAPI* theWidgetApi)
854 {
855   ModuleBase_IWorkshop* aWorkshop = workshop();
856   XGUI_Workshop* aXUIWorkshop = getWorkshop();
857   ModuleBase_ModelWidget* aWgt = NULL;
858   if (theType == "sketch-start-label") {
859     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
860                                                                theWidgetApi, myHasConstraintShown);
861     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
862       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
863     connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
864       mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
865     connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
866     connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
867       sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
868     aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
869     aWgt = aLabelWgt;
870   } else if (theType == "sketch-2dpoint_selector") {
871     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
872                                                                  theWidgetApi);
873     aPointWgt->setSketch(mySketchMgr->activeSketch());
874     connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
875     aWgt = aPointWgt;
876   }else if (theType == "sketch-2dpoint_flyout_selector") {
877     PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
878                                                                              theWidgetApi);
879     aPointWgt->setSketch(mySketchMgr->activeSketch());
880     connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
881     aWgt = aPointWgt;
882   } else if (theType == "sketch_shape_selector") {
883     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
884                           new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
885     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
886     aWgt = aShapeSelectorWgt;
887   } else if (theType == "sketch_multi_selector") {
888     PartSet_WidgetMultiSelector* aShapeSelectorWgt =
889                           new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
890     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
891     aWgt = aShapeSelectorWgt;
892   }
893   else if (theType == "sketch_feature_point_selector") {
894     PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
895             new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
896     aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
897     aWgt = aPointSelectorWgt;
898   }
899   else if (theType == WDG_DOUBLEVALUE_EDITOR) {
900     aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
901   } else if (theType == "export_file_selector") {
902     aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
903   } else if (theType == "sketch_launcher") {
904     aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
905   } else if (theType == "module_choice") {
906     aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
907     connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
908             this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
909   }
910   return aWgt;
911 }
912
913 //******************************************************
914 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
915 {
916   ModuleBase_ModelWidget* anActiveWidget = 0;
917
918   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
919   if (!aOperation)
920     return anActiveWidget;
921
922   ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
923   if (!aPanel)
924     return anActiveWidget;
925
926   return aPanel->activeWidget(true);
927 }
928
929 //******************************************************
930 bool PartSet_Module::deleteObjects()
931 {
932   bool isProcessed = false;
933
934   XGUI_Workshop* aWorkshop = getWorkshop();
935   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
936
937   //SessionPtr aMgr = ModelAPI_Session::get();
938   // 1. check whether the delete should be processed in the module
939   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
940   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
941        isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
942   if (isSketchOp || isNestedOp) {
943     isProcessed = true;
944     // 2. find selected presentations
945     // selected objects should be collected before the current operation abort because
946     // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
947     ModuleBase_ISelection* aSel = workshop()->selection();
948     QObjectPtrList aSelectedObj = aSel->selectedPresentations();
949     // if there are no selected objects in the viewer, that means that the selection in another
950     // place cased this method. It is necessary to return the false value to understande in above
951     // method that delete is not processed
952     if (aSelectedObj.count() == 0)
953       return false;
954
955     // avoid delete of the objects, which are not belong to the current sketch
956     // in order to do not delete results of other sketches
957     QObjectPtrList aSketchObjects;
958     QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
959     for ( ; anIt != aLast; anIt++) {
960       ObjectPtr anObject = *anIt;
961       if (mySketchMgr->isObjectOfSketch(anObject)) {
962         // sketch feature should be used in this list because workshop deletes features only
963         // results are skipped
964         FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
965         aSketchObjects.append(aSketchFeature);
966       }
967     }
968     // if the selection contains only local selected presentations from other sketches,
969     // the Delete operation should not be done at all
970     if (aSketchObjects.size() == 0)
971       return true;
972
973     // 3. start operation
974     QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
975     ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
976
977     // the active nested sketch operation should be aborted unconditionally
978     // the Delete action should be additionally granted for the Sketch operation
979     // in order to do not abort/commit it
980     bool isCommitted;
981     if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
982       return true; // the objects are processed but can not be deleted
983
984     anOpMgr->startOperation(anOpAction);
985
986     // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
987     // the problem is in AIS Dimensions recompute
988     // if a line and the dim are removed, line is the first
989     // it causes the AIS recompute, where the base line is null,
990     // the result is empty AIS in the viewer
991     XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
992
993     // 4. delete features
994     // sketch feature should be skipped, only sub-features can be removed
995     // when sketch operation is active
996     aWorkshop->deleteFeatures(aSketchObjects);
997     // 5. stop operation
998     anOpMgr->commitOperation();
999   }
1000   return isProcessed;
1001 }
1002
1003 //******************************************************
1004 void PartSet_Module::editFeature(FeaturePtr theFeature)
1005 {
1006   storeConstraintsState(theFeature->getKind());
1007   ModuleBase_IModule::editFeature(theFeature);
1008 }
1009
1010 //******************************************************
1011 bool PartSet_Module::canCommitOperation() const
1012 {
1013   return true;
1014 }
1015
1016 //******************************************************
1017 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1018 {
1019   myIsOperationIsLaunched = true;
1020   storeConstraintsState(theCmdId.toStdString());
1021   updateConstraintsState(theCmdId.toStdString());
1022
1023   ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1024
1025   myIsOperationIsLaunched = false;
1026 }
1027
1028 //******************************************************
1029 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1030 {
1031   if (myWorkshop->currentOperation() &&
1032       myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1033     const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1034                                                   mySketchMgr->showConstraintStates();
1035     myHasConstraintShown = aShownStates;
1036   }
1037 }
1038
1039 //******************************************************
1040 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1041 {
1042   if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1043       PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1044     // Show constraints if a constraint was anOperation
1045     mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1046     mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1047     mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1048                                           myHasConstraintShown[PartSet_Tools::Expressions]);
1049   }
1050 }
1051
1052 //******************************************************
1053 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1054 {
1055   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1056   if (!anAIS.IsNull()) {
1057     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1058     if (aFeature.get()) {
1059       bool aToUseZLayer = false;
1060       if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1061         aToUseZLayer = true;
1062       else {
1063         CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1064         aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1065       }
1066       if (aToUseZLayer) {
1067         Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1068         if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1069           aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1070         else
1071           aCtx->SetZLayer(anAIS, myVisualLayerId);
1072       }
1073     }
1074   }
1075 }
1076
1077 //******************************************************
1078 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1079 {
1080   // this is obsolete
1081   // it should be recomputed in order to disappear in the viewer if the corresponded object
1082   // is erased
1083   //if (myCustomPrs->isActive())
1084   //  myCustomPrs->redisplay(theObject, false);
1085 }
1086
1087 //******************************************************
1088 void PartSet_Module::onViewTransformed(int theTrsfType)
1089 {
1090   // Set length of arrows constant in pixel size
1091   // if the operation is panning or rotate or panglobal then do nothing
1092   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1093     return;
1094   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1095   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1096   if (aContext.IsNull())
1097     return;
1098
1099   //Handle(V3d_View) aView = aViewer->activeView();
1100
1101   XGUI_Workshop* aWorkshop = getWorkshop();
1102   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1103   Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1104   Handle(V3d_View) aView;
1105   double aScale = 0;
1106   for (aV3dViewer->InitDefinedViews();
1107        aV3dViewer->MoreDefinedViews();
1108        aV3dViewer->NextDefinedViews()) {
1109     Handle(V3d_View) aV = aV3dViewer->DefinedView();
1110     double aS = aV->Scale();
1111     if (aS > aScale) {
1112       aScale = aS;
1113       aView = aV;
1114     }
1115   }
1116   if (aView.IsNull())
1117     return;
1118
1119   bool isModified = false;
1120   ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1121   if (aCurrentOperation &&
1122     (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1123      sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1124      (aCurrentOperation->id() == "Measurement")))
1125   {
1126     double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1127
1128     double aPrevLen = SketcherPrs_Tools::getArrowSize();
1129     SketcherPrs_Tools::setArrowSize(aLen);
1130     const double aCurScale = aViewer->activeView()->Camera()->Scale();
1131     aViewer->SetScale(aViewer->activeView(), aCurScale);
1132 #ifdef OPTIMIZE_PRS
1133     QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1134     foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1135 #else
1136     QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1137     foreach(AISObjectPtr aAIS, aPrsList) {
1138       Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1139 #endif
1140       Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1141       if (!aDim.IsNull()) {
1142         aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1143         aContext->Redisplay(aDim, false);
1144         isModified = true;
1145       }
1146     }
1147     if (isModified)
1148       aDisplayer->updateViewer();
1149   }
1150
1151 }
1152
1153 //******************************************************
1154 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1155 {
1156   return myCustomPrs->isActive(theFlag);
1157 }
1158
1159 //******************************************************
1160 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1161                                        const ModuleBase_CustomizeFlag& theFlag,
1162                                        const bool theUpdateViewer)
1163 {
1164   myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1165 }
1166
1167 //******************************************************
1168 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1169                                          const bool theUpdateViewer)
1170 {
1171   myCustomPrs->deactivate(theFlag, theUpdateViewer);
1172 }
1173
1174 //******************************************************
1175 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1176                                            std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1177 {
1178   bool aCustomized = false;
1179
1180   XGUI_Workshop* aWorkshop = getWorkshop();
1181   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1182   ObjectPtr anObject = aDisplayer->getObject(thePrs);
1183   if (!anObject)
1184     return aCustomized;
1185
1186   if (!theResult.get()) {
1187     std::vector<int> aColor;
1188     XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1189     if (!aColor.empty()) {
1190       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1191     }
1192   }
1193   // customize dimentional constrains
1194   sketchMgr()->customizePresentation(anObject);
1195
1196   return aCustomized;
1197 }
1198
1199 //******************************************************
1200 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1201                                                 AISObjectPtr thePrs,
1202                                                 GeomCustomPrsPtr theCustomPrs)
1203 {
1204   bool aCustomized = false;
1205
1206   XGUI_Workshop* aWorkshop = getWorkshop();
1207   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1208   ObjectPtr anObject = aDisplayer->getObject(thePrs);
1209   if (!anObject)
1210     return aCustomized;
1211
1212   std::vector<int> aColor;
1213   bool aUseCustomColor = true;
1214   if (aUseCustomColor)
1215     myOverconstraintListener->getCustomColor(anObject, aColor);
1216   // customize sketch symbol presentation
1217   Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1218   if (!anAISIO.IsNull()) {
1219     if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1220       Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1221       if (!aPrs.IsNull()) {
1222         aPrs->SetCustomColor(aColor);
1223         aCustomized = true;
1224       }
1225     } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1226       Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1227       if (!aPrs.IsNull()) {
1228         aPrs->SetCustomColor(aColor);
1229         aCustomized = true;
1230       }
1231     }
1232   }
1233   // customize sketch dimension constraint presentation
1234   if (!aCustomized) {
1235     if (!aColor.empty()) { // otherwise presentation has the default color
1236       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1237     }
1238   }
1239   return aCustomized;
1240 }
1241
1242 //******************************************************
1243 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1244                                      const bool theUpdateViewer)
1245 {
1246   bool isRedisplayed = false;
1247   if (myCustomPrs->isActive(theFlag))
1248     isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1249
1250   return isRedisplayed;
1251 }
1252
1253 //******************************************************
1254 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1255 {
1256   XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1257   if (aOB) {
1258     QLabel* aLabel = aOB->activeDocLabel();
1259     aLabel->installEventFilter(myMenuMgr);
1260     connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1261           SLOT(onActiveDocPopup(const QPoint&)));
1262     aOB->treeView()->setExpandsOnDoubleClick(false);
1263     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1264       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1265
1266     Events_Loop* aLoop = Events_Loop::loop();
1267     aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1268   }
1269 }
1270
1271 //******************************************************
1272 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1273 {
1274   SessionPtr aMgr = ModelAPI_Session::get();
1275   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1276
1277   XGUI_Workshop* aWorkshop = getWorkshop();
1278   QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1279
1280   aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1281
1282   QMenu aMenu;
1283   aMenu.addAction(aActivatePartAction);
1284   aMenu.exec(aHeader->mapToGlobal(thePnt));
1285 }
1286
1287 //******************************************************
1288 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ObjectPtr& theObject)
1289 {
1290   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1291   if (aResult.get())
1292     return mySketchMgr->createPresentation(aResult);
1293   else {
1294     FieldStepPtr aStep =
1295       std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1296     if (aStep.get()) {
1297       return new PartSet_FieldStepPrs(aStep);
1298     }
1299   }
1300   return Handle(AIS_InteractiveObject)();
1301 }
1302
1303 //******************************************************
1304 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1305 {
1306   ObjectPtr anObject;
1307   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1308   if (aOperation) {
1309     /// If last line finished on vertex the lines creation sequence has to be break
1310     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1311     if (aPanel) {
1312       ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1313       // if there is an active widget, find the presented object in it
1314       if (!anActiveWidget)
1315         anActiveWidget = aPanel->preselectionWidget();
1316
1317       ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1318                                                                              (anActiveWidget);
1319       if (aWidgetValidated)
1320         anObject = aWidgetValidated->findPresentedObject(theAIS);
1321     }
1322   }
1323   return anObject;
1324 }
1325
1326 //******************************************************
1327 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1328 {
1329   bool aCanBeShaged = true;
1330
1331   Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1332   if (!aPrs.IsNull())
1333     aCanBeShaged = false;
1334
1335   return aCanBeShaged;
1336 }
1337
1338 //******************************************************
1339 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1340 {
1341   QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1342   int aSelected = aObjects.size();
1343   SessionPtr aMgr = ModelAPI_Session::get();
1344   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1345
1346   bool hasResult = false;
1347   bool hasFeature = false;
1348   bool hasParameter = false;
1349   bool hasCompositeOwner = false;
1350   bool hasResultInHistory = false;
1351   bool hasFolder = false;
1352   ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1353                                   hasCompositeOwner, hasResultInHistory, hasFolder);
1354
1355   ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1356   if (aSelected == 1) {
1357     ObjectPtr aObject = aObjects.first();
1358     if (aObject) {
1359       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1360       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1361       bool isPart = aPart.get() ||
1362         (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1363       if (isPart) {
1364         DocumentPtr aPartDoc;
1365         if (!aPart.get()) {
1366           aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1367         }
1368         if (aPart.get()) // this may be null is Part feature is disabled
1369           aPartDoc = aPart->partDoc();
1370
1371         theMenu->addAction(aActivatePartAction);
1372         aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1373
1374       } else if (aObject->document() == aMgr->activeDocument()) {
1375         if (hasParameter || hasFeature) {
1376           myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1377           theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1378           if (aCurrentOp && aFeature.get()) {
1379             if (aCurrentOp->id().toStdString() == aFeature->getKind())
1380               myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1381           }
1382         }
1383       }
1384     }
1385   } else {
1386     if (hasFeature) {
1387       myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1388       theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1389       theMenu->addSeparator();
1390     }
1391   }
1392   bool aNotDeactivate = (aCurrentOp == 0);
1393   if (!aNotDeactivate) {
1394     aActivatePartAction->setEnabled(false);
1395   }
1396 }
1397
1398 //******************************************************
1399 #define EXPAND_PARENT(OBJ) \
1400 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1401 if (aObjIndex.isValid()) { \
1402   QModelIndex aParent = aObjIndex.parent(); \
1403   int aCount = aDataModel->rowCount(aParent); \
1404   if (aCount == 1) \
1405     aTreeView->setExpanded(aParent, true); \
1406 }
1407
1408 //******************************************************
1409 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1410 {
1411   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1412     // Do not change activation of parts if an operation active
1413     static QStringList aAllowActivationList;
1414     if (aAllowActivationList.isEmpty())
1415       aAllowActivationList <<
1416       QString(PartSetPlugin_Part::ID().c_str()) <<
1417       QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1418       QString(PartSetPlugin_Remove::ID().c_str());
1419     if (myWorkshop->currentOperation() &&
1420       (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1421       return;
1422     XGUI_Workshop* aWorkshop = getWorkshop();
1423     XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1424     QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1425     QPalette aPalet = aLabel->palette();
1426
1427     SessionPtr aMgr = ModelAPI_Session::get();
1428     DocumentPtr aActiveDoc = aMgr->activeDocument();
1429
1430     // Clear active part index if there is no Part documents
1431     // It could be not null if document was closed and opened a new
1432     // without closeDocument call
1433     if (aMgr->allOpenedDocuments().size() <= 1)
1434       myActivePartIndex = QModelIndex();
1435
1436     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1437     QModelIndex aOldActive = myActivePartIndex;
1438     myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1439     bool needUpdate = false;
1440     if (myActivePartIndex.isValid()) {
1441       needUpdate = aTreeView->isExpanded(myActivePartIndex);
1442       if (!needUpdate)
1443         aTreeView->setExpanded(myActivePartIndex, true);
1444     }
1445     if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1446       aTreeView->setExpanded(aOldActive, false);
1447
1448     aLabel->setPalette(aPalet);
1449     aWorkshop->updateCommandStatus();
1450
1451     // Update displayed objects in order to update active color
1452     XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1453     QObjectPtrList aObjects = aDisplayer->displayedObjects();
1454     bool aHidden;
1455     bool aUpdateViewer = false;
1456     foreach(ObjectPtr aObj, aObjects) {
1457       aHidden = !aObj->data() || !aObj->data()->isValid() ||
1458         aObj->isDisabled() || (!aObj->isDisplayed());
1459       if (!aHidden) {
1460         aDisplayer->redisplay(aObj, false);
1461         aUpdateViewer = true;
1462       }
1463     }
1464     if (aUpdateViewer)
1465      aDisplayer->updateViewer();
1466     // Update tree items if they are expanded
1467     if (needUpdate) {
1468       aTreeView->viewport()->update(aTreeView->viewport()->rect());
1469     }
1470   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1471     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1472         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1473     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1474
1475     ObjectPtr aConstrObj;
1476     ObjectPtr aResultObj;
1477     std::set<ObjectPtr>::const_iterator aIt;
1478     DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1479     for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1480       ObjectPtr aObject = (*aIt);
1481       if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1482           && (aObject->document() != aRootDoc))
1483         aResultObj = aObject;
1484       if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1485           && (aObject->document() != aRootDoc))
1486         aConstrObj = aObject;
1487       if (aResultObj.get() && aConstrObj.get())
1488         break;
1489     }
1490
1491     if (aResultObj.get() || aConstrObj.get()) {
1492       XGUI_Workshop* aWorkshop = getWorkshop();
1493       XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1494       XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1495
1496       if (aResultObj.get()) {
1497         EXPAND_PARENT(aResultObj)
1498       }
1499       if (aConstrObj.get()) {
1500         EXPAND_PARENT(aConstrObj)
1501       }
1502     }
1503   }
1504   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1505     CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1506     if (aSketch.get()) {
1507       ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1508       if (PartSet_SketcherMgr::isSketchOperation(anOperation))
1509         mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1510     }
1511   }
1512 }
1513
1514 //******************************************************
1515 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1516 {
1517   if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1518     return;
1519   SessionPtr aMgr = ModelAPI_Session::get();
1520   if (!theIndex.isValid()) {
1521     // It seems that this code is obsolete
1522     //aMgr->setActiveDocument(aMgr->moduleDocument());
1523     return;
1524   }
1525   if (theIndex.column() != 1) // Use only first column
1526     return;
1527
1528   XGUI_Workshop* aWorkshop = getWorkshop();
1529   XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1530   // De not use non editable Indexes
1531   if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1532     return;
1533   ObjectPtr aObj = aDataModel->object(theIndex);
1534
1535   ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1536   if (!aPart.get()) { // Probably this is Feature
1537     FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1538     if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1539       aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1540     }
1541   }
1542   if (aPart.get()) { // if this is a part
1543     if (aPart->partDoc() == aMgr->activeDocument()) {
1544       myMenuMgr->activatePartSet();
1545     } else {
1546       myMenuMgr->activatePart(aPart);
1547     }
1548   }
1549 }
1550
1551 //******************************************************
1552 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1553 {
1554   // z layer is created for all started operations in order to visualize operation AIS presentation
1555   // over the object
1556   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1557   if (aContext.IsNull())
1558     return;
1559
1560   Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1561   if (myVisualLayerId == 0) {
1562     if (myVisualLayerId == 0)
1563       aViewer->AddZLayer(myVisualLayerId);
1564   } else {
1565     TColStd_SequenceOfInteger aZList;
1566     aViewer->GetAllZLayers(aZList);
1567     bool aFound = false;
1568     for (int i = 1; i <= aZList.Length(); i++) {
1569       if (aZList(i) == myVisualLayerId) {
1570         aFound = true;
1571         break;
1572       }
1573     }
1574     if (!aFound)
1575       aViewer->AddZLayer(myVisualLayerId);
1576   }
1577   // if there is an active operation with validated widget,
1578   // the filters of this widget should be activated in the created view
1579   myWorkshop->selectionActivate()->updateSelectionFilters();
1580   myWorkshop->selectionActivate()->updateSelectionModes();
1581 }
1582
1583 //******************************************************
1584 void PartSet_Module::widgetStateChanged(int thePreviousState)
1585 {
1586   mySketchMgr->widgetStateChanged(thePreviousState);
1587 }
1588
1589 //******************************************************
1590 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1591 {
1592   return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1593 }
1594
1595 //******************************************************
1596 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1597 {
1598   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1599     mySketchMgr->stopSketch(theOperation);
1600   }
1601 }
1602
1603 //******************************************************
1604 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1605 {
1606   GeomShapePtr aGeomShape;
1607
1608   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1609   if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1610     aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1611   }
1612   return aGeomShape;
1613 }
1614
1615 //******************************************************
1616 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1617                                            const GeomShapePtr& theGeomShape)
1618 {
1619   AttributePtr anAttribute;
1620   GeomShapePtr aGeomShape = theGeomShape;
1621   if (!aGeomShape.get()) {
1622     // processing shape of result, e.g. sketch circle center is selected, this is a result
1623     // the geom shape is empty, the shape of result should be used
1624     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1625     if (aResult.get()) {
1626       aGeomShape = aResult->shape();
1627     }
1628   }
1629
1630   if (aGeomShape.get()) {
1631     TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1632     return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1633                                                  mySketchMgr->activeSketch());
1634   }
1635   return anAttribute;
1636 }
1637
1638 //******************************************************
1639 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1640 {
1641   return sketchReentranceMgr()->reentrantMessage();
1642 }
1643
1644 //******************************************************
1645 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1646 {
1647   sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1648 }
1649
1650 //******************************************************
1651 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1652                                      int theIndex)
1653 {
1654   ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1655   if (!aChoiceWidget)
1656     return;
1657
1658   QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1659   if (!aChoiceTitle.isEmpty()) {
1660     ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1661     if (!aOperation)
1662       return;
1663     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1664     if (aPanel)
1665       aPanel->setWindowTitle(aChoiceTitle);
1666   }
1667 }
1668
1669 //******************************************************
1670 XGUI_Workshop* PartSet_Module::getWorkshop() const
1671 {
1672   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1673   return aConnector->workshop();
1674 }
1675
1676 void PartSet_Module::setDefaultConstraintShown()
1677 {
1678   myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1679   myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1680   myHasConstraintShown[PartSet_Tools::Expressions] = false;
1681 }
1682
1683 //******************************************************
1684 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1685 {
1686   return myRoot;
1687 }
1688
1689 //******************************************************
1690 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1691   myCustomPrs->disableCustomMode(theMode);
1692 }
1693
1694 //******************************************************
1695 void PartSet_Module::enableCustomModes() {
1696   myCustomPrs->enableCustomModes();
1697 }