]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
Task 5.2.6 "Part -> Parameters" dialog box: add a keyboard shortcut for "Add"
[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   else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
438     mySketchMgr->startNestedSketch(theOperation);
439   }
440 }
441
442 //******************************************************
443 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
444 {
445   ModuleBase_OperationFeature* aFOperation =
446     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
447   if (aFOperation) {
448     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
449     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
450   }
451 }
452
453 //******************************************************
454 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
455 {
456   ModuleBase_IModule::operationResumed(theOperation);
457
458   ModuleBase_OperationFeature* aFOperation =
459     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
460   if (aFOperation) {
461     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
462     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
463   }
464 }
465
466 //******************************************************
467 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
468 {
469   bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
470   bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
471   bool isModified = isModifiedArgs || isModifiedResults;
472
473   if (sketchMgr()->isNestedSketchOperation(theOperation)) {
474     mySketchMgr->stopNestedSketch(theOperation);
475   }
476   else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
477     setDefaultConstraintShown();
478
479   //VSV: Viewer is updated on feature update and redisplay
480   if (isModified) {
481     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
482     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
483     aDisplayer->updateViewer();
484   }
485
486   QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
487     anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
488   for (; anIt != aLast; anIt++) {
489     mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
490   }
491 }
492
493 //******************************************************
494 ModuleBase_Operation* PartSet_Module::currentOperation() const
495 {
496   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
497   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
498   return anOpMgr->currentOperation();
499 }
500
501 //******************************************************
502 bool PartSet_Module::canUndo() const
503 {
504   bool aCanUndo = false;
505   SessionPtr aMgr = ModelAPI_Session::get();
506   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
507     aCanUndo = !aMgr->isOperation();
508     if (!aCanUndo) // check the enable state additionally by sketch manager
509       aCanUndo = aMgr->canUndo();
510   }
511   return aCanUndo;
512 }
513
514 //******************************************************
515 bool PartSet_Module::canRedo() const
516 {
517   bool aCanRedo = false;
518   SessionPtr aMgr = ModelAPI_Session::get();
519   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
520     aCanRedo = !aMgr->isOperation();
521     if (!aCanRedo) // check the enable state additionally by sketch manager
522       aCanRedo = aMgr->canRedo();
523   }
524   return aCanRedo;
525 }
526
527 //******************************************************
528 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
529 {
530   bool aValid = true;
531   if (theActionId == "MOVE_CMD") {
532     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
533     if (aFeature) {
534       ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
535       // part features can not be moved in the history.
536       if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
537         aValid = false;
538     }
539   }
540   return aValid;
541 }
542
543 //******************************************************
544 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
545 {
546   // the sketch manager put the restriction to the objects erase
547   return mySketchMgr->canEraseObject(theObject);
548 }
549
550 //******************************************************
551 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
552 {
553   // the sketch manager put the restriction to the objects display
554   return mySketchMgr->canDisplayObject(theObject);
555 }
556
557 //******************************************************
558 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
559                                         const QString& theStartedOperationKind)
560 {
561   if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
562     return true;
563
564   return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
565 }
566
567 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
568 {
569   mySketchMgr->processHiddenObject(theObjects);
570 }*/
571
572 //******************************************************
573 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
574 {
575   bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
576
577   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
578   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
579        isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
580   if (isSketchOp || isNestedOp) {
581     // in active sketch operation it is possible to activate operation object in selection
582     // in the edit operation, e.g. points of the line can be moved when the line is edited
583     ModuleBase_OperationFeature* aFOperation =
584       dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
585     aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
586   }
587   return aCanActivate;
588 }
589
590 //******************************************************
591 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
592                                    QWidget* theParent,
593                                    QMap<int, QAction*>& theMenuActions) const
594 {
595   return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
596 }
597
598 //******************************************************
599 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
600 {
601   myMenuMgr->updateViewerMenu(theStdActions);
602 }
603
604 //******************************************************
605 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
606 {
607   bool isEnabledFixed = false;
608   if (theActionId == XGUI_ActionsMgr::AcceptAll &&
609       mySketchReentrantMgr->isInternalEditActive())
610     isEnabledFixed = true;
611   return isEnabledFixed;
612 }
613
614 //******************************************************
615 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
616 {
617   QString anError = ModuleBase_IModule::getFeatureError(theFeature);
618   if (anError.isEmpty())
619     anError = sketchMgr()->getFeatureError(theFeature);
620
621   return anError;
622 }
623
624 //******************************************************
625 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
626                                          QStringList& theIds) const
627 {
628   myMenuMgr->grantedOperationIds(theOperation, theIds);
629
630   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
631     XGUI_Workshop* aWorkshop = getWorkshop();
632     theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
633   }
634 }
635
636 //******************************************************
637 void PartSet_Module::activeSelectionModes(QIntList& theModes)
638 {
639   if (mySketchMgr->activeSketch().get())
640     PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
641   else
642     theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
643 }
644
645 //******************************************************
646 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
647 {
648   customSubShapesSelectionModes(theModes);
649   //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
650   //myWorkshop->module()->activeSelectionModes(theModes);
651 }
652
653 //******************************************************
654 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
655                                             SelectMgr_ListOfFilter& theSelectionFilters)
656 {
657   bool isSketchActive = mySketchMgr->activeSketch().get();
658
659   std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
660     mySelectionFilters.begin();
661   for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
662     int aFilterType = aFiltersIt->first;
663     // do not add not participating filters in given parameters
664     if (!theFilterTypes.contains(aFilterType))
665       continue;
666
667     // using sketch filters only if sketch operation is active
668     if (!isSketchActive &&
669         mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
670       continue;
671
672     // using filtering of construction results only from faces panel
673     if (aFilterType == SF_ResultGroupNameFilter)
674       continue;
675
676     theSelectionFilters.Append(aFiltersIt->second);
677   }
678 }
679
680 //******************************************************
681 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
682 {
683   if (theModes.contains(TopAbs_FACE))
684     theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
685   if (theModes.contains(TopAbs_WIRE))
686     theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
687
688   if (mySketchMgr->activeSketch().get())
689     PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
690 }
691
692 //******************************************************
693 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
694                                       ObjectPtr& theObject, AttributePtr& theAttribute)
695 {
696   ObjectPtr anObject = theSelected->object();
697   GeomShapePtr aShape = theSelected->shape();
698
699   theAttribute = findAttribute(anObject, aShape);
700   // TODO: try to create result if object is an external object
701   theObject = anObject;
702 }
703
704 //******************************************************
705 bool PartSet_Module::isMouseOverWindow()
706 {
707   return mySketchMgr->isMouseOverWindow();
708 }
709
710 //******************************************************
711 bool PartSet_Module::isSketchNeutralPointActivated() const
712 {
713   bool isNeutralPoint = true;
714   if (sketchReentranceMgr()->isInternalEditActive())
715     isNeutralPoint = false;
716   if (myIsOperationIsLaunched)
717     isNeutralPoint = false;
718
719   return isNeutralPoint;
720 }
721
722 //******************************************************
723 void PartSet_Module::closeDocument()
724 {
725   myActivePartIndex = QModelIndex();
726   SketcherPrs_PositionMgr::get()->clearAll();
727 }
728
729 //******************************************************
730 void PartSet_Module::clearViewer()
731 {
732   myCustomPrs->clearPrs();
733
734   XGUI_Workshop* aWorkshop = getWorkshop();
735   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
736   aDisplayer->deactivateSelectionFilters(false);
737 }
738
739 //******************************************************
740 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
741 {
742   ModuleBase_OperationFeature* aFOperation =
743     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
744   if (!aFOperation)
745     return;
746
747   ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
748   // we have to manually activate the sketch label in edit mode
749   if (PartSet_SketcherMgr::isSketchOperation(aFOperation) &&  (aFOperation->isEditOperation()))
750     aPanel->activateWidget(aPanel->modelWidgets().first());
751 }
752
753 //******************************************************
754 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
755                                    QList<ModuleBase_ModelWidget*>& theWidgets) const
756 {
757   bool aProcessed = false;
758
759   ModuleBase_OperationFeature* aFOperation =
760     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
761   XGUI_Workshop* aWorkshop = getWorkshop();
762   XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
763   if (mySketchMgr->activeSketch().get() && aFOperation && 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       FeaturePtr anOpFeature = aFOperation->feature();
773       GeomShapePtr aShape = aSelectedPrs->shape();
774       // click on the digit of dimension constrain comes here
775       // with an empty shape, so we need the check
776       if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
777         // if feature has only one result and shape of result is equal to selected shape
778         // this attribute is not processed. It is a case of Sketch Point.
779         if (aFeature->results().size() == 1) {
780           ResultPtr aResult = aFeature->results().front();
781           if (aResult.get() && aResult->shape()->isEqual(aShape))
782             return aProcessed;
783         }
784         const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
785         AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
786                                                                mySketchMgr->activeSketch());
787         if (anAttribute.get()) {
788           QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
789           ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
790
791           const std::string anAttributeId = anAttribute->id();
792           aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
793
794           theWidgets = aFactory.getModelWidgets();
795           // it is possible that the point does not present in XML definition,
796           // in this case, we assume that it is not processed by this module
797           // e.g. "Intersection point" feature
798           aProcessed = !theWidgets.isEmpty();
799         }
800       }
801     }
802   }
803   return aProcessed;
804 }
805
806 //******************************************************
807 void PartSet_Module::onSelectionChanged()
808 {
809   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
810   if (!aOperation)
811     return;
812
813   bool isSketcherOp = false;
814   // An edit operation is enable only if the current opeation is the sketch operation
815   if (mySketchMgr->activeSketch()) {
816     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
817       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
818   }
819   if (isSketcherOp) {
820     // Editing of constraints can be done on selection
821     ModuleBase_ISelection* aSelect = myWorkshop->selection();
822     QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
823     if (aSelected.size() == 1) {
824       ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
825       ObjectPtr aObject = aPrs->object();
826       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
827       if (aFeature) {
828         std::string aId = aFeature->getKind();
829         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
830             (aId == SketchPlugin_ConstraintLength::ID()) ||
831             (aId == SketchPlugin_ConstraintDistance::ID()) ||
832             (aId == SketchPlugin_ConstraintAngle::ID())) {
833           editFeature(aFeature);
834         }
835       }
836     }
837   }
838 }
839
840 //******************************************************
841 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
842 {
843   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
844   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
845   anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
846 }
847
848 //******************************************************
849 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
850                                                            QWidget* theParent,
851                                                            Config_WidgetAPI* theWidgetApi)
852 {
853   ModuleBase_IWorkshop* aWorkshop = workshop();
854   XGUI_Workshop* aXUIWorkshop = getWorkshop();
855   ModuleBase_ModelWidget* aWgt = NULL;
856   if (theType == "sketch-start-label") {
857     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
858                                                                theWidgetApi, myHasConstraintShown);
859     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
860       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
861     connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
862       mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
863     connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
864     connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
865       sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
866     aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
867     aWgt = aLabelWgt;
868   } else if (theType == "sketch-2dpoint_selector") {
869     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(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-2dpoint_flyout_selector") {
875     PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
876                                                                              theWidgetApi);
877     aPointWgt->setSketch(mySketchMgr->activeSketch());
878     connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
879     aWgt = aPointWgt;
880   } else if (theType == "sketch_shape_selector") {
881     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
882                           new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
883     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
884     aWgt = aShapeSelectorWgt;
885   } else if (theType == "sketch_multi_selector") {
886     PartSet_WidgetMultiSelector* aShapeSelectorWgt =
887                           new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
888     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
889     aWgt = aShapeSelectorWgt;
890   }
891   else if (theType == "sketch_feature_point_selector") {
892     PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
893             new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
894     aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
895     aWgt = aPointSelectorWgt;
896   }
897   else if (theType == WDG_DOUBLEVALUE_EDITOR) {
898     aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
899   } else if (theType == "export_file_selector") {
900     aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
901   } else if (theType == "sketch_launcher") {
902     aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
903   } else if (theType == "module_choice") {
904     aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
905     connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
906             this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
907   }
908   return aWgt;
909 }
910
911 //******************************************************
912 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
913 {
914   ModuleBase_ModelWidget* anActiveWidget = 0;
915
916   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
917   if (!aOperation)
918     return anActiveWidget;
919
920   ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
921   if (!aPanel)
922     return anActiveWidget;
923
924   return aPanel->activeWidget(true);
925 }
926
927 //******************************************************
928 bool PartSet_Module::deleteObjects()
929 {
930   bool isProcessed = false;
931
932   XGUI_Workshop* aWorkshop = getWorkshop();
933   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
934
935   //SessionPtr aMgr = ModelAPI_Session::get();
936   // 1. check whether the delete should be processed in the module
937   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
938   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
939        isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
940   if (isSketchOp || isNestedOp) {
941     isProcessed = true;
942     // 2. find selected presentations
943     // selected objects should be collected before the current operation abort because
944     // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
945     ModuleBase_ISelection* aSel = workshop()->selection();
946     QObjectPtrList aSelectedObj = aSel->selectedPresentations();
947     // if there are no selected objects in the viewer, that means that the selection in another
948     // place cased this method. It is necessary to return the false value to understande in above
949     // method that delete is not processed
950     if (aSelectedObj.count() == 0)
951       return false;
952
953     // avoid delete of the objects, which are not belong to the current sketch
954     // in order to do not delete results of other sketches
955     QObjectPtrList aSketchObjects;
956     QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
957     for ( ; anIt != aLast; anIt++) {
958       ObjectPtr anObject = *anIt;
959       if (mySketchMgr->isObjectOfSketch(anObject)) {
960         // sketch feature should be used in this list because workshop deletes features only
961         // results are skipped
962         FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
963         aSketchObjects.append(aSketchFeature);
964       }
965     }
966     // if the selection contains only local selected presentations from other sketches,
967     // the Delete operation should not be done at all
968     if (aSketchObjects.size() == 0)
969       return true;
970
971     // 3. start operation
972     QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
973     ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
974
975     // the active nested sketch operation should be aborted unconditionally
976     // the Delete action should be additionally granted for the Sketch operation
977     // in order to do not abort/commit it
978     bool isCommitted;
979     if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
980       return true; // the objects are processed but can not be deleted
981
982     anOpMgr->startOperation(anOpAction);
983
984     // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
985     // the problem is in AIS Dimensions recompute
986     // if a line and the dim are removed, line is the first
987     // it causes the AIS recompute, where the base line is null,
988     // the result is empty AIS in the viewer
989     XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
990
991     // 4. delete features
992     // sketch feature should be skipped, only sub-features can be removed
993     // when sketch operation is active
994     aWorkshop->deleteFeatures(aSketchObjects);
995     // 5. stop operation
996     anOpMgr->commitOperation();
997   }
998   return isProcessed;
999 }
1000
1001 //******************************************************
1002 void PartSet_Module::editFeature(FeaturePtr theFeature)
1003 {
1004   storeConstraintsState(theFeature->getKind());
1005   ModuleBase_IModule::editFeature(theFeature);
1006 }
1007
1008 //******************************************************
1009 bool PartSet_Module::canCommitOperation() const
1010 {
1011   return true;
1012 }
1013
1014 //******************************************************
1015 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1016 {
1017   myIsOperationIsLaunched = true;
1018   storeConstraintsState(theCmdId.toStdString());
1019   updateConstraintsState(theCmdId.toStdString());
1020
1021   ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1022
1023   myIsOperationIsLaunched = false;
1024 }
1025
1026 //******************************************************
1027 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1028 {
1029   if (myWorkshop->currentOperation() &&
1030       myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1031     const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1032                                                   mySketchMgr->showConstraintStates();
1033     myHasConstraintShown = aShownStates;
1034   }
1035 }
1036
1037 //******************************************************
1038 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1039 {
1040   if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1041       PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1042     // Show constraints if a constraint was anOperation
1043     mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1044     mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1045     mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1046                                           myHasConstraintShown[PartSet_Tools::Expressions]);
1047   }
1048 }
1049
1050 //******************************************************
1051 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1052 {
1053   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1054   if (!anAIS.IsNull()) {
1055     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1056     if (aFeature.get()) {
1057       bool aToUseZLayer = false;
1058       if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1059         aToUseZLayer = true;
1060       else {
1061         CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1062         aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1063       }
1064       if (aToUseZLayer) {
1065         Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1066         if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1067           aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1068         else
1069           aCtx->SetZLayer(anAIS, myVisualLayerId);
1070       }
1071     }
1072   }
1073 }
1074
1075 //******************************************************
1076 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1077 {
1078   // this is obsolete
1079   // it should be recomputed in order to disappear in the viewer if the corresponded object
1080   // is erased
1081   //if (myCustomPrs->isActive())
1082   //  myCustomPrs->redisplay(theObject, false);
1083 }
1084
1085 //******************************************************
1086 void PartSet_Module::onViewTransformed(int theTrsfType)
1087 {
1088   // Set length of arrows constant in pixel size
1089   // if the operation is panning or rotate or panglobal then do nothing
1090   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1091     return;
1092   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1093   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1094   if (aContext.IsNull())
1095     return;
1096
1097   //Handle(V3d_View) aView = aViewer->activeView();
1098
1099   XGUI_Workshop* aWorkshop = getWorkshop();
1100   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1101   Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1102   Handle(V3d_View) aView;
1103   double aScale = 0;
1104   for (aV3dViewer->InitDefinedViews();
1105        aV3dViewer->MoreDefinedViews();
1106        aV3dViewer->NextDefinedViews()) {
1107     Handle(V3d_View) aV = aV3dViewer->DefinedView();
1108     double aS = aV->Scale();
1109     if (aS > aScale) {
1110       aScale = aS;
1111       aView = aV;
1112     }
1113   }
1114   if (aView.IsNull())
1115     return;
1116
1117   bool isModified = false;
1118   ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1119   if (aCurrentOperation &&
1120     (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1121      sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1122      (aCurrentOperation->id() == "Measurement")))
1123   {
1124     double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1125
1126     double aPrevLen = SketcherPrs_Tools::getArrowSize();
1127     SketcherPrs_Tools::setArrowSize(aLen);
1128     const double aCurScale = aViewer->activeView()->Camera()->Scale();
1129     aViewer->SetScale(aViewer->activeView(), aCurScale);
1130 #ifdef OPTIMIZE_PRS
1131     QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1132     foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1133 #else
1134     QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1135     foreach(AISObjectPtr aAIS, aPrsList) {
1136       Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1137 #endif
1138       Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1139       if (!aDim.IsNull()) {
1140         aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1141         aContext->Redisplay(aDim, false);
1142         isModified = true;
1143       }
1144     }
1145     if (isModified)
1146       aDisplayer->updateViewer();
1147   }
1148
1149 }
1150
1151 //******************************************************
1152 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1153 {
1154   return myCustomPrs->isActive(theFlag);
1155 }
1156
1157 //******************************************************
1158 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1159                                        const ModuleBase_CustomizeFlag& theFlag,
1160                                        const bool theUpdateViewer)
1161 {
1162   myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1163 }
1164
1165 //******************************************************
1166 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1167                                          const bool theUpdateViewer)
1168 {
1169   myCustomPrs->deactivate(theFlag, theUpdateViewer);
1170 }
1171
1172 //******************************************************
1173 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1174                                            std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1175 {
1176   bool aCustomized = false;
1177
1178   XGUI_Workshop* aWorkshop = getWorkshop();
1179   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1180   ObjectPtr anObject = aDisplayer->getObject(thePrs);
1181   if (!anObject)
1182     return aCustomized;
1183
1184   if (!theResult.get()) {
1185     std::vector<int> aColor;
1186     XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1187     if (!aColor.empty()) {
1188       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1189     }
1190   }
1191   // customize dimentional constrains
1192   sketchMgr()->customizePresentation(anObject);
1193
1194   return aCustomized;
1195 }
1196
1197 //******************************************************
1198 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1199                                                 AISObjectPtr thePrs,
1200                                                 GeomCustomPrsPtr theCustomPrs)
1201 {
1202   bool aCustomized = false;
1203
1204   XGUI_Workshop* aWorkshop = getWorkshop();
1205   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1206   ObjectPtr anObject = aDisplayer->getObject(thePrs);
1207   if (!anObject)
1208     return aCustomized;
1209
1210   std::vector<int> aColor;
1211   bool aUseCustomColor = true;
1212   if (aUseCustomColor)
1213     myOverconstraintListener->getCustomColor(anObject, aColor);
1214   // customize sketch symbol presentation
1215   Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1216   if (!anAISIO.IsNull()) {
1217     if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1218       Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1219       if (!aPrs.IsNull()) {
1220         aPrs->SetCustomColor(aColor);
1221         aCustomized = true;
1222       }
1223     } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1224       Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1225       if (!aPrs.IsNull()) {
1226         aPrs->SetCustomColor(aColor);
1227         aCustomized = true;
1228       }
1229     }
1230   }
1231   // customize sketch dimension constraint presentation
1232   if (!aCustomized) {
1233     if (!aColor.empty()) { // otherwise presentation has the default color
1234       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1235     }
1236   }
1237   return aCustomized;
1238 }
1239
1240 //******************************************************
1241 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1242                                      const bool theUpdateViewer)
1243 {
1244   bool isRedisplayed = false;
1245   if (myCustomPrs->isActive(theFlag))
1246     isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1247
1248   return isRedisplayed;
1249 }
1250
1251 //******************************************************
1252 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1253 {
1254   XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1255   if (aOB) {
1256     QLabel* aLabel = aOB->activeDocLabel();
1257     aLabel->installEventFilter(myMenuMgr);
1258     connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1259           SLOT(onActiveDocPopup(const QPoint&)));
1260     aOB->treeView()->setExpandsOnDoubleClick(false);
1261     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1262       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1263
1264     Events_Loop* aLoop = Events_Loop::loop();
1265     aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1266   }
1267 }
1268
1269 //******************************************************
1270 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1271 {
1272   SessionPtr aMgr = ModelAPI_Session::get();
1273   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1274
1275   XGUI_Workshop* aWorkshop = getWorkshop();
1276   QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1277
1278   aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1279
1280   QMenu aMenu;
1281   aMenu.addAction(aActivatePartAction);
1282   aMenu.exec(aHeader->mapToGlobal(thePnt));
1283 }
1284
1285 //******************************************************
1286 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ObjectPtr& theObject)
1287 {
1288   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1289   if (aResult.get())
1290     return mySketchMgr->createPresentation(aResult);
1291   else {
1292     FieldStepPtr aStep =
1293       std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1294     if (aStep.get()) {
1295       return new PartSet_FieldStepPrs(aStep);
1296     }
1297   }
1298   return Handle(AIS_InteractiveObject)();
1299 }
1300
1301 //******************************************************
1302 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1303 {
1304   ObjectPtr anObject;
1305   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1306   if (aOperation) {
1307     /// If last line finished on vertex the lines creation sequence has to be break
1308     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1309     if (aPanel) {
1310       ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1311       // if there is an active widget, find the presented object in it
1312       if (!anActiveWidget)
1313         anActiveWidget = aPanel->preselectionWidget();
1314
1315       ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1316                                                                              (anActiveWidget);
1317       if (aWidgetValidated)
1318         anObject = aWidgetValidated->findPresentedObject(theAIS);
1319     }
1320   }
1321   return anObject;
1322 }
1323
1324 //******************************************************
1325 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1326 {
1327   bool aCanBeShaged = true;
1328
1329   Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1330   if (!aPrs.IsNull())
1331     aCanBeShaged = false;
1332
1333   return aCanBeShaged;
1334 }
1335
1336 //******************************************************
1337 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1338 {
1339   QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1340   int aSelected = aObjects.size();
1341   SessionPtr aMgr = ModelAPI_Session::get();
1342   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1343
1344   bool hasResult = false;
1345   bool hasFeature = false;
1346   bool hasParameter = false;
1347   bool hasCompositeOwner = false;
1348   bool hasResultInHistory = false;
1349   bool hasFolder = false;
1350   ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1351                                   hasCompositeOwner, hasResultInHistory, hasFolder);
1352
1353   ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1354   if (aSelected == 1) {
1355     ObjectPtr aObject = aObjects.first();
1356     if (aObject) {
1357       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1358       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1359       bool isPart = aPart.get() ||
1360         (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1361       if (isPart) {
1362         DocumentPtr aPartDoc;
1363         if (!aPart.get()) {
1364           aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1365         }
1366         if (aPart.get()) // this may be null is Part feature is disabled
1367           aPartDoc = aPart->partDoc();
1368
1369         theMenu->addAction(aActivatePartAction);
1370         aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1371
1372       } else if (aObject->document() == aMgr->activeDocument()) {
1373         if (hasParameter || hasFeature) {
1374           myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1375           theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1376           if (aCurrentOp && aFeature.get()) {
1377             if (aCurrentOp->id().toStdString() == aFeature->getKind())
1378               myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1379           }
1380         }
1381       }
1382     }
1383   } else {
1384     if (hasFeature) {
1385       myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1386       theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1387       theMenu->addSeparator();
1388     }
1389   }
1390   bool aNotDeactivate = (aCurrentOp == 0);
1391   if (!aNotDeactivate) {
1392     aActivatePartAction->setEnabled(false);
1393   }
1394 }
1395
1396 //******************************************************
1397 #define EXPAND_PARENT(OBJ) \
1398 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1399 if (aObjIndex.isValid()) { \
1400   QModelIndex aParent = aObjIndex.parent(); \
1401   int aCount = aDataModel->rowCount(aParent); \
1402   if (aCount == 1) \
1403     aTreeView->setExpanded(aParent, true); \
1404 }
1405
1406 //******************************************************
1407 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1408 {
1409   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1410     // Do not change activation of parts if an operation active
1411     static QStringList aAllowActivationList;
1412     if (aAllowActivationList.isEmpty())
1413       aAllowActivationList <<
1414       QString(PartSetPlugin_Part::ID().c_str()) <<
1415       QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1416       QString(PartSetPlugin_Remove::ID().c_str());
1417     if (myWorkshop->currentOperation() &&
1418       (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1419       return;
1420     XGUI_Workshop* aWorkshop = getWorkshop();
1421     XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1422     QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1423     QPalette aPalet = aLabel->palette();
1424
1425     SessionPtr aMgr = ModelAPI_Session::get();
1426     DocumentPtr aActiveDoc = aMgr->activeDocument();
1427
1428     // Clear active part index if there is no Part documents
1429     // It could be not null if document was closed and opened a new
1430     // without closeDocument call
1431     if (aMgr->allOpenedDocuments().size() <= 1)
1432       myActivePartIndex = QModelIndex();
1433
1434     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1435     QModelIndex aOldActive = myActivePartIndex;
1436     myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1437     bool needUpdate = false;
1438     if (myActivePartIndex.isValid()) {
1439       needUpdate = aTreeView->isExpanded(myActivePartIndex);
1440       if (!needUpdate)
1441         aTreeView->setExpanded(myActivePartIndex, true);
1442     }
1443     if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1444       aTreeView->setExpanded(aOldActive, false);
1445
1446     aLabel->setPalette(aPalet);
1447     aWorkshop->updateCommandStatus();
1448
1449     // Update displayed objects in order to update active color
1450     XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1451     QObjectPtrList aObjects = aDisplayer->displayedObjects();
1452     bool aHidden;
1453     bool aUpdateViewer = false;
1454     foreach(ObjectPtr aObj, aObjects) {
1455       aHidden = !aObj->data() || !aObj->data()->isValid() ||
1456         aObj->isDisabled() || (!aObj->isDisplayed());
1457       if (!aHidden) {
1458         aDisplayer->redisplay(aObj, false);
1459         aUpdateViewer = true;
1460       }
1461     }
1462     if (aUpdateViewer)
1463      aDisplayer->updateViewer();
1464     // Update tree items if they are expanded
1465     if (needUpdate) {
1466       aTreeView->viewport()->update(aTreeView->viewport()->rect());
1467     }
1468   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1469     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1470         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1471     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1472
1473     ObjectPtr aConstrObj;
1474     ObjectPtr aResultObj;
1475     std::set<ObjectPtr>::const_iterator aIt;
1476     DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1477     for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1478       ObjectPtr aObject = (*aIt);
1479       if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1480           && (aObject->document() != aRootDoc))
1481         aResultObj = aObject;
1482       if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1483           && (aObject->document() != aRootDoc))
1484         aConstrObj = aObject;
1485       if (aResultObj.get() && aConstrObj.get())
1486         break;
1487     }
1488
1489     if (aResultObj.get() || aConstrObj.get()) {
1490       XGUI_Workshop* aWorkshop = getWorkshop();
1491       XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1492       XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1493
1494       if (aResultObj.get()) {
1495         EXPAND_PARENT(aResultObj)
1496       }
1497       if (aConstrObj.get()) {
1498         EXPAND_PARENT(aConstrObj)
1499       }
1500     }
1501   }
1502   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1503     CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1504     if (aSketch.get()) {
1505       ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1506       if (PartSet_SketcherMgr::isSketchOperation(anOperation))
1507         mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1508     }
1509   }
1510 }
1511
1512 //******************************************************
1513 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1514 {
1515   if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1516     return;
1517   SessionPtr aMgr = ModelAPI_Session::get();
1518   if (!theIndex.isValid()) {
1519     // It seems that this code is obsolete
1520     //aMgr->setActiveDocument(aMgr->moduleDocument());
1521     return;
1522   }
1523   if (theIndex.column() != 1) // Use only first column
1524     return;
1525
1526   XGUI_Workshop* aWorkshop = getWorkshop();
1527   XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1528   // De not use non editable Indexes
1529   if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1530     return;
1531   ObjectPtr aObj = aDataModel->object(theIndex);
1532
1533   ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1534   if (!aPart.get()) { // Probably this is Feature
1535     FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1536     if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1537       aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1538     }
1539   }
1540   if (aPart.get()) { // if this is a part
1541     if (aPart->partDoc() == aMgr->activeDocument()) {
1542       myMenuMgr->activatePartSet();
1543     } else {
1544       myMenuMgr->activatePart(aPart);
1545     }
1546   }
1547 }
1548
1549 //******************************************************
1550 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1551 {
1552   // z layer is created for all started operations in order to visualize operation AIS presentation
1553   // over the object
1554   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1555   if (aContext.IsNull())
1556     return;
1557
1558   Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1559   if (myVisualLayerId == 0) {
1560     if (myVisualLayerId == 0)
1561       aViewer->AddZLayer(myVisualLayerId);
1562   } else {
1563     TColStd_SequenceOfInteger aZList;
1564     aViewer->GetAllZLayers(aZList);
1565     bool aFound = false;
1566     for (int i = 1; i <= aZList.Length(); i++) {
1567       if (aZList(i) == myVisualLayerId) {
1568         aFound = true;
1569         break;
1570       }
1571     }
1572     if (!aFound)
1573       aViewer->AddZLayer(myVisualLayerId);
1574   }
1575   // if there is an active operation with validated widget,
1576   // the filters of this widget should be activated in the created view
1577   myWorkshop->selectionActivate()->updateSelectionFilters();
1578   myWorkshop->selectionActivate()->updateSelectionModes();
1579 }
1580
1581 //******************************************************
1582 void PartSet_Module::widgetStateChanged(int thePreviousState)
1583 {
1584   mySketchMgr->widgetStateChanged(thePreviousState);
1585 }
1586
1587 //******************************************************
1588 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1589 {
1590   return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1591 }
1592
1593 //******************************************************
1594 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1595 {
1596   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1597     mySketchMgr->stopSketch(theOperation);
1598   }
1599 }
1600
1601 //******************************************************
1602 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1603 {
1604   GeomShapePtr aGeomShape;
1605
1606   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1607   if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1608     aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1609   }
1610   return aGeomShape;
1611 }
1612
1613 //******************************************************
1614 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1615                                            const GeomShapePtr& theGeomShape)
1616 {
1617   AttributePtr anAttribute;
1618   GeomShapePtr aGeomShape = theGeomShape;
1619   if (!aGeomShape.get()) {
1620     // processing shape of result, e.g. sketch circle center is selected, this is a result
1621     // the geom shape is empty, the shape of result should be used
1622     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1623     if (aResult.get()) {
1624       aGeomShape = aResult->shape();
1625     }
1626   }
1627
1628   if (aGeomShape.get()) {
1629     TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1630     return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1631                                                  mySketchMgr->activeSketch());
1632   }
1633   return anAttribute;
1634 }
1635
1636 //******************************************************
1637 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1638 {
1639   return sketchReentranceMgr()->reentrantMessage();
1640 }
1641
1642 //******************************************************
1643 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1644 {
1645   sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1646 }
1647
1648 //******************************************************
1649 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1650                                      int theIndex)
1651 {
1652   ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1653   if (!aChoiceWidget)
1654     return;
1655
1656   QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1657   if (!aChoiceTitle.isEmpty()) {
1658     ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1659     if (!aOperation)
1660       return;
1661     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1662     if (aPanel)
1663       aPanel->setWindowTitle(aChoiceTitle);
1664   }
1665 }
1666
1667 //******************************************************
1668 XGUI_Workshop* PartSet_Module::getWorkshop() const
1669 {
1670   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1671   return aConnector->workshop();
1672 }
1673
1674 void PartSet_Module::setDefaultConstraintShown()
1675 {
1676   myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1677   myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1678   myHasConstraintShown[PartSet_Tools::Expressions] = false;
1679 }
1680
1681 //******************************************************
1682 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1683 {
1684   return myRoot;
1685 }
1686
1687 //******************************************************
1688 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1689   myCustomPrs->disableCustomMode(theMode);
1690 }
1691
1692 //******************************************************
1693 void PartSet_Module::enableCustomModes() {
1694   myCustomPrs->enableCustomModes();
1695 }