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