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