Salome HOME
Issue #3073: Show inspection panel for features
[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(const FeaturePtr& theFeature, const QString& theXmlRepr,
757                                    QList<ModuleBase_ModelWidget*>& theWidgets) const
758 {
759   bool aProcessed = false;
760
761   XGUI_Workshop* aWorkshop = getWorkshop();
762   XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
763   if (mySketchMgr->activeSketch().get() && aPropertyPanel) {
764     ModuleBase_ISelection* aSelection = workshop()->selection();
765     // click on a point in sketch leads here with the point is highlighted, not yet selected
766     QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
767     if (aPreselection.size() == 1) {
768       ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
769       ObjectPtr anObject = aSelectedPrs->object();
770
771       FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
772       GeomShapePtr aShape = aSelectedPrs->shape();
773       // click on the digit of dimension constrain comes here
774       // with an empty shape, so we need the check
775       if (aFeature == theFeature && aShape.get() && !aShape->isNull()) {
776         // if feature has only one result and shape of result is equal to selected shape
777         // this attribute is not processed. It is a case of Sketch Point.
778         if (aFeature->results().size() == 1) {
779           ResultPtr aResult = aFeature->results().front();
780           if (aResult.get() && aResult->shape()->isEqual(aShape))
781             return aProcessed;
782         }
783         const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
784         AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
785                                                                mySketchMgr->activeSketch());
786         if (anAttribute.get()) {
787           ModuleBase_WidgetFactory aFactory(theXmlRepr.toStdString(), workshop());
788
789           const std::string anAttributeId = anAttribute->id();
790           aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
791
792           theWidgets = aFactory.getModelWidgets();
793           // it is possible that the point does not present in XML definition,
794           // in this case, we assume that it is not processed by this module
795           // e.g. "Intersection point" feature
796           aProcessed = !theWidgets.isEmpty();
797         }
798       }
799     }
800   }
801   return aProcessed;
802 }
803
804 //******************************************************
805 void PartSet_Module::onSelectionChanged()
806 {
807   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
808   if (!aOperation)
809     return;
810
811   bool isSketcherOp = false;
812   // An edit operation is enable only if the current opeation is the sketch operation
813   if (mySketchMgr->activeSketch()) {
814     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
815       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
816   }
817   if (isSketcherOp) {
818     // Editing of constraints can be done on selection
819     ModuleBase_ISelection* aSelect = myWorkshop->selection();
820     QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
821     if (aSelected.size() == 1) {
822       ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
823       ObjectPtr aObject = aPrs->object();
824       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
825       if (aFeature) {
826         std::string aId = aFeature->getKind();
827         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
828             (aId == SketchPlugin_ConstraintLength::ID()) ||
829             (aId == SketchPlugin_ConstraintDistance::ID()) ||
830             (aId == SketchPlugin_ConstraintAngle::ID())) {
831           editFeature(aFeature);
832         }
833       }
834     }
835   }
836 }
837
838 //******************************************************
839 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
840 {
841   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
842   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
843   anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
844 }
845
846 //******************************************************
847 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
848                                                            QWidget* theParent,
849                                                            Config_WidgetAPI* theWidgetApi)
850 {
851   ModuleBase_IWorkshop* aWorkshop = workshop();
852   XGUI_Workshop* aXUIWorkshop = getWorkshop();
853   ModuleBase_ModelWidget* aWgt = NULL;
854   if (theType == "sketch-start-label") {
855     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
856                                                                theWidgetApi, myHasConstraintShown);
857     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
858       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
859     connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
860       mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
861     connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
862     connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
863       sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
864     aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
865     aWgt = aLabelWgt;
866   } else if (theType == "sketch-2dpoint_selector") {
867     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
868                                                                  theWidgetApi);
869     aPointWgt->setSketch(mySketchMgr->activeSketch());
870     connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
871     aWgt = aPointWgt;
872   }else if (theType == "sketch-2dpoint_flyout_selector") {
873     PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
874                                                                              theWidgetApi);
875     aPointWgt->setSketch(mySketchMgr->activeSketch());
876     connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
877     aWgt = aPointWgt;
878   } else if (theType == "sketch_shape_selector") {
879     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
880                           new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
881     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
882     aWgt = aShapeSelectorWgt;
883   } else if (theType == "sketch_multi_selector") {
884     PartSet_WidgetMultiSelector* aShapeSelectorWgt =
885                           new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
886     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
887     aWgt = aShapeSelectorWgt;
888   }
889   else if (theType == "sketch_feature_point_selector") {
890     PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
891             new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
892     aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
893     aWgt = aPointSelectorWgt;
894   }
895   else if (theType == WDG_DOUBLEVALUE_EDITOR) {
896     aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
897   } else if (theType == "export_file_selector") {
898     aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
899   } else if (theType == "sketch_launcher") {
900     aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
901   } else if (theType == "module_choice") {
902     aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
903     connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
904             this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
905   }
906   return aWgt;
907 }
908
909 //******************************************************
910 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
911 {
912   ModuleBase_ModelWidget* anActiveWidget = 0;
913
914   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
915   if (!aOperation)
916     return anActiveWidget;
917
918   ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
919   if (!aPanel)
920     return anActiveWidget;
921
922   return aPanel->activeWidget(true);
923 }
924
925 //******************************************************
926 bool PartSet_Module::deleteObjects()
927 {
928   bool isProcessed = false;
929
930   XGUI_Workshop* aWorkshop = getWorkshop();
931   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
932
933   //SessionPtr aMgr = ModelAPI_Session::get();
934   // 1. check whether the delete should be processed in the module
935   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
936   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
937        isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
938   if (isSketchOp || isNestedOp) {
939     isProcessed = true;
940     // 2. find selected presentations
941     // selected objects should be collected before the current operation abort because
942     // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
943     ModuleBase_ISelection* aSel = workshop()->selection();
944     QObjectPtrList aSelectedObj = aSel->selectedPresentations();
945     // if there are no selected objects in the viewer, that means that the selection in another
946     // place cased this method. It is necessary to return the false value to understande in above
947     // method that delete is not processed
948     if (aSelectedObj.count() == 0)
949       return false;
950
951     // avoid delete of the objects, which are not belong to the current sketch
952     // in order to do not delete results of other sketches
953     QObjectPtrList aSketchObjects;
954     QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
955     for ( ; anIt != aLast; anIt++) {
956       ObjectPtr anObject = *anIt;
957       if (mySketchMgr->isObjectOfSketch(anObject)) {
958         // sketch feature should be used in this list because workshop deletes features only
959         // results are skipped
960         FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
961         aSketchObjects.append(aSketchFeature);
962       }
963     }
964     // if the selection contains only local selected presentations from other sketches,
965     // the Delete operation should not be done at all
966     if (aSketchObjects.size() == 0)
967       return true;
968
969     // 3. start operation
970     QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
971     ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
972
973     // the active nested sketch operation should be aborted unconditionally
974     // the Delete action should be additionally granted for the Sketch operation
975     // in order to do not abort/commit it
976     bool isCommitted;
977     if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
978       return true; // the objects are processed but can not be deleted
979
980     anOpMgr->startOperation(anOpAction);
981
982     // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
983     // the problem is in AIS Dimensions recompute
984     // if a line and the dim are removed, line is the first
985     // it causes the AIS recompute, where the base line is null,
986     // the result is empty AIS in the viewer
987     XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
988
989     // 4. delete features
990     // sketch feature should be skipped, only sub-features can be removed
991     // when sketch operation is active
992     aWorkshop->deleteFeatures(aSketchObjects);
993     // 5. stop operation
994     anOpMgr->commitOperation();
995   }
996   return isProcessed;
997 }
998
999 //******************************************************
1000 void PartSet_Module::editFeature(FeaturePtr theFeature)
1001 {
1002   storeConstraintsState(theFeature->getKind());
1003   ModuleBase_IModule::editFeature(theFeature);
1004 }
1005
1006 //******************************************************
1007 bool PartSet_Module::canCommitOperation() const
1008 {
1009   return true;
1010 }
1011
1012 //******************************************************
1013 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1014 {
1015   myIsOperationIsLaunched = true;
1016   storeConstraintsState(theCmdId.toStdString());
1017   updateConstraintsState(theCmdId.toStdString());
1018
1019   ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1020
1021   myIsOperationIsLaunched = false;
1022 }
1023
1024 //******************************************************
1025 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1026 {
1027   if (myWorkshop->currentOperation() &&
1028       myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1029     const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1030                                                   mySketchMgr->showConstraintStates();
1031     myHasConstraintShown = aShownStates;
1032   }
1033 }
1034
1035 //******************************************************
1036 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1037 {
1038   if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1039       PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1040     // Show constraints if a constraint was anOperation
1041     mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1042     mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1043     mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1044                                           myHasConstraintShown[PartSet_Tools::Expressions]);
1045   }
1046 }
1047
1048 //******************************************************
1049 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1050 {
1051   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1052   if (!anAIS.IsNull()) {
1053     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1054     if (aFeature.get()) {
1055       bool aToUseZLayer = false;
1056       if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1057         aToUseZLayer = true;
1058       else {
1059         CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1060         aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1061       }
1062       if (aToUseZLayer) {
1063         Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1064         if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1065           aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1066         else
1067           aCtx->SetZLayer(anAIS, myVisualLayerId);
1068       }
1069     }
1070   }
1071 }
1072
1073 //******************************************************
1074 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1075 {
1076   // this is obsolete
1077   // it should be recomputed in order to disappear in the viewer if the corresponded object
1078   // is erased
1079   //if (myCustomPrs->isActive())
1080   //  myCustomPrs->redisplay(theObject, false);
1081 }
1082
1083 //******************************************************
1084 void PartSet_Module::onViewTransformed(int theTrsfType)
1085 {
1086   // Set length of arrows constant in pixel size
1087   // if the operation is panning or rotate or panglobal then do nothing
1088   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1089     return;
1090   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1091   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1092   if (aContext.IsNull())
1093     return;
1094
1095   //Handle(V3d_View) aView = aViewer->activeView();
1096
1097   XGUI_Workshop* aWorkshop = getWorkshop();
1098   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1099   Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1100   Handle(V3d_View) aView;
1101   double aScale = 0;
1102   for (aV3dViewer->InitDefinedViews();
1103        aV3dViewer->MoreDefinedViews();
1104        aV3dViewer->NextDefinedViews()) {
1105     Handle(V3d_View) aV = aV3dViewer->DefinedView();
1106     double aS = aV->Scale();
1107     if (aS > aScale) {
1108       aScale = aS;
1109       aView = aV;
1110     }
1111   }
1112   if (aView.IsNull())
1113     return;
1114
1115   bool isModified = false;
1116   ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1117   if (aCurrentOperation &&
1118     (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1119      sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1120      (aCurrentOperation->id() == "Measurement")))
1121   {
1122     double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1123
1124     double aPrevLen = SketcherPrs_Tools::getArrowSize();
1125     SketcherPrs_Tools::setArrowSize(aLen);
1126     const double aCurScale = aViewer->activeView()->Camera()->Scale();
1127     aViewer->SetScale(aViewer->activeView(), aCurScale);
1128 #ifdef OPTIMIZE_PRS
1129     QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1130     foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1131 #else
1132     QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1133     foreach(AISObjectPtr aAIS, aPrsList) {
1134       Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1135 #endif
1136       Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1137       if (!aDim.IsNull()) {
1138         aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1139         aContext->Redisplay(aDim, false);
1140         isModified = true;
1141       }
1142     }
1143     if (isModified)
1144       aDisplayer->updateViewer();
1145   }
1146
1147 }
1148
1149 //******************************************************
1150 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1151 {
1152   return myCustomPrs->isActive(theFlag);
1153 }
1154
1155 //******************************************************
1156 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1157                                        const ModuleBase_CustomizeFlag& theFlag,
1158                                        const bool theUpdateViewer)
1159 {
1160   myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1161 }
1162
1163 //******************************************************
1164 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1165                                          const bool theUpdateViewer)
1166 {
1167   myCustomPrs->deactivate(theFlag, theUpdateViewer);
1168 }
1169
1170 //******************************************************
1171 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1172                                            std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1173 {
1174   bool aCustomized = false;
1175
1176   XGUI_Workshop* aWorkshop = getWorkshop();
1177   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1178   ObjectPtr anObject = aDisplayer->getObject(thePrs);
1179   if (!anObject)
1180     return aCustomized;
1181
1182   if (!theResult.get()) {
1183     std::vector<int> aColor;
1184     XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1185     if (!aColor.empty()) {
1186       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1187     }
1188   }
1189   // customize dimentional constrains
1190   sketchMgr()->customizePresentation(anObject);
1191
1192   return aCustomized;
1193 }
1194
1195 //******************************************************
1196 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1197                                                 AISObjectPtr thePrs,
1198                                                 GeomCustomPrsPtr theCustomPrs)
1199 {
1200   bool aCustomized = false;
1201
1202   XGUI_Workshop* aWorkshop = getWorkshop();
1203   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1204   ObjectPtr anObject = aDisplayer->getObject(thePrs);
1205   if (!anObject)
1206     return aCustomized;
1207
1208   std::vector<int> aColor;
1209   bool aUseCustomColor = true;
1210   if (aUseCustomColor)
1211     myOverconstraintListener->getCustomColor(anObject, aColor);
1212   // customize sketch symbol presentation
1213   Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1214   if (!anAISIO.IsNull()) {
1215     if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1216       Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1217       if (!aPrs.IsNull()) {
1218         aPrs->SetCustomColor(aColor);
1219         aCustomized = true;
1220       }
1221     } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1222       Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1223       if (!aPrs.IsNull()) {
1224         aPrs->SetCustomColor(aColor);
1225         aCustomized = true;
1226       }
1227     }
1228   }
1229   // customize sketch dimension constraint presentation
1230   if (!aCustomized) {
1231     if (!aColor.empty()) { // otherwise presentation has the default color
1232       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1233     }
1234   }
1235   return aCustomized;
1236 }
1237
1238 //******************************************************
1239 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1240                                      const bool theUpdateViewer)
1241 {
1242   bool isRedisplayed = false;
1243   if (myCustomPrs->isActive(theFlag))
1244     isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1245
1246   return isRedisplayed;
1247 }
1248
1249 //******************************************************
1250 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1251 {
1252   XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1253   if (aOB) {
1254     QLabel* aLabel = aOB->activeDocLabel();
1255     aLabel->installEventFilter(myMenuMgr);
1256     connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1257           SLOT(onActiveDocPopup(const QPoint&)));
1258     aOB->treeView()->setExpandsOnDoubleClick(false);
1259     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1260       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1261
1262     Events_Loop* aLoop = Events_Loop::loop();
1263     aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1264   }
1265 }
1266
1267 //******************************************************
1268 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1269 {
1270   SessionPtr aMgr = ModelAPI_Session::get();
1271   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1272
1273   XGUI_Workshop* aWorkshop = getWorkshop();
1274   QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1275
1276   aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1277
1278   QMenu aMenu;
1279   aMenu.addAction(aActivatePartAction);
1280   aMenu.exec(aHeader->mapToGlobal(thePnt));
1281 }
1282
1283 //******************************************************
1284 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ObjectPtr& theObject)
1285 {
1286   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1287   if (aResult.get())
1288     return mySketchMgr->createPresentation(aResult);
1289   else {
1290     FieldStepPtr aStep =
1291       std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1292     if (aStep.get()) {
1293       return new PartSet_FieldStepPrs(aStep);
1294     }
1295   }
1296   return Handle(AIS_InteractiveObject)();
1297 }
1298
1299 //******************************************************
1300 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1301 {
1302   ObjectPtr anObject;
1303   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1304   if (aOperation) {
1305     /// If last line finished on vertex the lines creation sequence has to be break
1306     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1307     if (aPanel) {
1308       ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1309       // if there is an active widget, find the presented object in it
1310       if (!anActiveWidget)
1311         anActiveWidget = aPanel->preselectionWidget();
1312
1313       ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1314                                                                              (anActiveWidget);
1315       if (aWidgetValidated)
1316         anObject = aWidgetValidated->findPresentedObject(theAIS);
1317     }
1318   }
1319   return anObject;
1320 }
1321
1322 //******************************************************
1323 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1324 {
1325   bool aCanBeShaged = true;
1326
1327   Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1328   if (!aPrs.IsNull())
1329     aCanBeShaged = false;
1330
1331   return aCanBeShaged;
1332 }
1333
1334 //******************************************************
1335 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1336 {
1337   QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1338   int aSelected = aObjects.size();
1339   SessionPtr aMgr = ModelAPI_Session::get();
1340   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1341
1342   bool hasResult = false;
1343   bool hasFeature = false;
1344   bool hasParameter = false;
1345   bool hasCompositeOwner = false;
1346   bool hasResultInHistory = false;
1347   bool hasFolder = false;
1348   ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1349                                   hasCompositeOwner, hasResultInHistory, hasFolder);
1350
1351   ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1352   if (aSelected == 1) {
1353     ObjectPtr aObject = aObjects.first();
1354     if (aObject) {
1355       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1356       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1357       bool isPart = aPart.get() ||
1358         (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1359       if (isPart) {
1360         DocumentPtr aPartDoc;
1361         if (!aPart.get()) {
1362           aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1363         }
1364         if (aPart.get()) // this may be null is Part feature is disabled
1365           aPartDoc = aPart->partDoc();
1366
1367         theMenu->addAction(aActivatePartAction);
1368         aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1369
1370       } else if (aObject->document() == aMgr->activeDocument()) {
1371         if (hasParameter || hasFeature) {
1372           myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1373           theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1374           if (aCurrentOp && aFeature.get()) {
1375             if (aCurrentOp->id().toStdString() == aFeature->getKind())
1376               myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1377           }
1378         }
1379       }
1380     }
1381   } else {
1382     if (hasFeature) {
1383       myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1384       theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1385       theMenu->addSeparator();
1386     }
1387   }
1388   bool aNotDeactivate = (aCurrentOp == 0);
1389   if (!aNotDeactivate) {
1390     aActivatePartAction->setEnabled(false);
1391   }
1392 }
1393
1394 //******************************************************
1395 #define EXPAND_PARENT(OBJ) \
1396 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1397 if (aObjIndex.isValid()) { \
1398   QModelIndex aParent = aObjIndex.parent(); \
1399   int aCount = aDataModel->rowCount(aParent); \
1400   if (aCount == 1) \
1401     aTreeView->setExpanded(aParent, true); \
1402 }
1403
1404 //******************************************************
1405 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1406 {
1407   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1408     // Do not change activation of parts if an operation active
1409     static QStringList aAllowActivationList;
1410     if (aAllowActivationList.isEmpty())
1411       aAllowActivationList <<
1412       QString(PartSetPlugin_Part::ID().c_str()) <<
1413       QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1414       QString(PartSetPlugin_Remove::ID().c_str());
1415     if (myWorkshop->currentOperation() &&
1416       (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1417       return;
1418     XGUI_Workshop* aWorkshop = getWorkshop();
1419     XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1420     QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1421     QPalette aPalet = aLabel->palette();
1422
1423     SessionPtr aMgr = ModelAPI_Session::get();
1424     DocumentPtr aActiveDoc = aMgr->activeDocument();
1425
1426     // Clear active part index if there is no Part documents
1427     // It could be not null if document was closed and opened a new
1428     // without closeDocument call
1429     if (aMgr->allOpenedDocuments().size() <= 1)
1430       myActivePartIndex = QModelIndex();
1431
1432     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1433     QModelIndex aOldActive = myActivePartIndex;
1434     myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1435     bool needUpdate = false;
1436     if (myActivePartIndex.isValid()) {
1437       needUpdate = aTreeView->isExpanded(myActivePartIndex);
1438       if (!needUpdate)
1439         aTreeView->setExpanded(myActivePartIndex, true);
1440     }
1441     if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1442       aTreeView->setExpanded(aOldActive, false);
1443
1444     aLabel->setPalette(aPalet);
1445     aWorkshop->updateCommandStatus();
1446
1447     // Update displayed objects in order to update active color
1448     XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1449     QObjectPtrList aObjects = aDisplayer->displayedObjects();
1450     bool aHidden;
1451     bool aUpdateViewer = false;
1452     foreach(ObjectPtr aObj, aObjects) {
1453       aHidden = !aObj->data() || !aObj->data()->isValid() ||
1454         aObj->isDisabled() || (!aObj->isDisplayed());
1455       if (!aHidden) {
1456         aDisplayer->redisplay(aObj, false);
1457         aUpdateViewer = true;
1458       }
1459     }
1460     if (aUpdateViewer)
1461      aDisplayer->updateViewer();
1462     // Update tree items if they are expanded
1463     if (needUpdate) {
1464       aTreeView->viewport()->update(aTreeView->viewport()->rect());
1465     }
1466   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1467     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1468         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1469     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1470
1471     ObjectPtr aConstrObj;
1472     ObjectPtr aResultObj;
1473     std::set<ObjectPtr>::const_iterator aIt;
1474     DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1475     for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1476       ObjectPtr aObject = (*aIt);
1477       if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1478           && (aObject->document() != aRootDoc))
1479         aResultObj = aObject;
1480       if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1481           && (aObject->document() != aRootDoc))
1482         aConstrObj = aObject;
1483       if (aResultObj.get() && aConstrObj.get())
1484         break;
1485     }
1486
1487     if (aResultObj.get() || aConstrObj.get()) {
1488       XGUI_Workshop* aWorkshop = getWorkshop();
1489       XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1490       XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1491
1492       if (aResultObj.get()) {
1493         EXPAND_PARENT(aResultObj)
1494       }
1495       if (aConstrObj.get()) {
1496         EXPAND_PARENT(aConstrObj)
1497       }
1498     }
1499   }
1500   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1501     CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1502     if (aSketch.get()) {
1503       ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1504       if (PartSet_SketcherMgr::isSketchOperation(anOperation))
1505         mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1506     }
1507   }
1508 }
1509
1510 //******************************************************
1511 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1512 {
1513   if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1514     return;
1515   SessionPtr aMgr = ModelAPI_Session::get();
1516   if (!theIndex.isValid()) {
1517     // It seems that this code is obsolete
1518     //aMgr->setActiveDocument(aMgr->moduleDocument());
1519     return;
1520   }
1521   if (theIndex.column() != 1) // Use only first column
1522     return;
1523
1524   XGUI_Workshop* aWorkshop = getWorkshop();
1525   XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1526   // De not use non editable Indexes
1527   if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1528     return;
1529   ObjectPtr aObj = aDataModel->object(theIndex);
1530
1531   ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1532   if (!aPart.get()) { // Probably this is Feature
1533     FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1534     if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1535       aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1536     }
1537   }
1538   if (aPart.get()) { // if this is a part
1539     if (aPart->partDoc() == aMgr->activeDocument()) {
1540       myMenuMgr->activatePartSet();
1541     } else {
1542       myMenuMgr->activatePart(aPart);
1543     }
1544   }
1545 }
1546
1547 //******************************************************
1548 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1549 {
1550   // z layer is created for all started operations in order to visualize operation AIS presentation
1551   // over the object
1552   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1553   if (aContext.IsNull())
1554     return;
1555
1556   Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1557   if (myVisualLayerId == 0) {
1558     if (myVisualLayerId == 0)
1559       aViewer->AddZLayer(myVisualLayerId);
1560   } else {
1561     TColStd_SequenceOfInteger aZList;
1562     aViewer->GetAllZLayers(aZList);
1563     bool aFound = false;
1564     for (int i = 1; i <= aZList.Length(); i++) {
1565       if (aZList(i) == myVisualLayerId) {
1566         aFound = true;
1567         break;
1568       }
1569     }
1570     if (!aFound)
1571       aViewer->AddZLayer(myVisualLayerId);
1572   }
1573   // if there is an active operation with validated widget,
1574   // the filters of this widget should be activated in the created view
1575   myWorkshop->selectionActivate()->updateSelectionFilters();
1576   myWorkshop->selectionActivate()->updateSelectionModes();
1577 }
1578
1579 //******************************************************
1580 void PartSet_Module::widgetStateChanged(int thePreviousState)
1581 {
1582   mySketchMgr->widgetStateChanged(thePreviousState);
1583 }
1584
1585 //******************************************************
1586 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1587 {
1588   return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1589 }
1590
1591 //******************************************************
1592 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1593 {
1594   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1595     mySketchMgr->stopSketch(theOperation);
1596   }
1597 }
1598
1599 //******************************************************
1600 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1601 {
1602   GeomShapePtr aGeomShape;
1603
1604   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1605   if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1606     aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1607   }
1608   return aGeomShape;
1609 }
1610
1611 //******************************************************
1612 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1613                                            const GeomShapePtr& theGeomShape)
1614 {
1615   AttributePtr anAttribute;
1616   GeomShapePtr aGeomShape = theGeomShape;
1617   if (!aGeomShape.get()) {
1618     // processing shape of result, e.g. sketch circle center is selected, this is a result
1619     // the geom shape is empty, the shape of result should be used
1620     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1621     if (aResult.get()) {
1622       aGeomShape = aResult->shape();
1623     }
1624   }
1625
1626   if (aGeomShape.get()) {
1627     TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1628     return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1629                                                  mySketchMgr->activeSketch());
1630   }
1631   return anAttribute;
1632 }
1633
1634 //******************************************************
1635 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1636 {
1637   return sketchReentranceMgr()->reentrantMessage();
1638 }
1639
1640 //******************************************************
1641 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1642 {
1643   sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1644 }
1645
1646 //******************************************************
1647 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1648                                      int theIndex)
1649 {
1650   ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1651   if (!aChoiceWidget)
1652     return;
1653
1654   QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1655   if (!aChoiceTitle.isEmpty()) {
1656     ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1657     if (!aOperation)
1658       return;
1659     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1660     if (aPanel)
1661       aPanel->setWindowTitle(aChoiceTitle);
1662   }
1663 }
1664
1665 //******************************************************
1666 XGUI_Workshop* PartSet_Module::getWorkshop() const
1667 {
1668   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1669   return aConnector->workshop();
1670 }
1671
1672 void PartSet_Module::setDefaultConstraintShown()
1673 {
1674   myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1675   myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1676   myHasConstraintShown[PartSet_Tools::Expressions] = false;
1677 }
1678
1679 //******************************************************
1680 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1681 {
1682   return myRoot;
1683 }
1684
1685 //******************************************************
1686 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1687   myCustomPrs->disableCustomMode(theMode);
1688 }
1689
1690 //******************************************************
1691 void PartSet_Module::enableCustomModes() {
1692   myCustomPrs->enableCustomModes();
1693 }