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