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