Salome HOME
Linux compilation correction.
[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_Coincident.h>
108 #include <SketcherPrs_Tools.h>
109
110 #include <Events_Loop.h>
111 #include <Config_PropManager.h>
112 #include <Config_Keywords.h>
113
114 #include <AIS_Dimension.hxx>
115 #include <AIS_InteractiveObject.hxx>
116 #include <StdSelect_TypeOfFace.hxx>
117 #include <TopoDS_Vertex.hxx>
118 #include <TopoDS.hxx>
119 #include <TopoDS_Shape.hxx>
120 #include <BRep_Tool.hxx>
121
122 #include <QObject>
123 #include <QMouseEvent>
124 #include <QString>
125 #include <QTimer>
126 #include <QApplication>
127 #include <QMessageBox>
128 #include <QMainWindow>
129 #include <QLineEdit>
130 #include <QString>
131
132 #include <GeomAlgoAPI_FaceBuilder.h>
133 #include <GeomDataAPI_Dir.h>
134
135 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
136
137 #ifdef _DEBUG
138 #include <QDebug>
139 #endif
140
141 /*!Create and return new instance of XGUI_Module*/
142 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
143 {
144   return new PartSet_Module(theWshop);
145 }
146
147 //******************************************************
148 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
149 : ModuleBase_IModule(theWshop),
150   myVisualLayerId(0),
151   myIsOperationIsLaunched(false)
152 {
153   new PartSet_IconFactory();
154
155   mySketchMgr = new PartSet_SketcherMgr(this);
156   mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
157
158   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
159   XGUI_Workshop* aWorkshop = aConnector->workshop();
160
161   ModuleBase_IViewer* aViewer = theWshop->viewer();
162   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
163           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
164   connect(aViewer, SIGNAL(viewTransformed(int)),
165           SLOT(onViewTransformed(int)));
166   connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
167           SLOT(onViewCreated(ModuleBase_IViewWindow*)));
168   myMenuMgr = new PartSet_MenuMgr(this);
169   myCustomPrs = new PartSet_CustomPrs(theWshop);
170
171   myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
172
173   Events_Loop* aLoop = Events_Loop::loop();
174   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
175
176   registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
177   registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
178   Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
179   std::set<std::string> aCRGroupNames;
180   aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
181   aCRFilter->setGroupNames(aCRGroupNames);
182   registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
183
184   setDefaultConstraintShown();
185
186   Config_PropManager::registerProp("Visualization", "operation_parameter_color",
187                           "Reference shape wireframe color in operation", Config_Prop::Color,
188                           PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
189   Config_PropManager::registerProp("Visualization", "operation_result_color",
190                           "Result shape wireframe color in operation", Config_Prop::Color,
191                           PartSet_CustomPrs::OPERATION_RESULT_COLOR());
192   Config_PropManager::registerProp("Visualization", "operation_highlight_color",
193                           "Multi selector item color in operation", Config_Prop::Color,
194                           PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
195   Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
196                           "Color of removed feature in operation", Config_Prop::Color,
197                           PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
198   Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
199                           "Color of sketch plane", Config_Prop::Color,
200                           PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
201
202   Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
203                                    "Hidden faces transparency",
204                                    Config_Prop::Double,
205                                    "0.8");
206 }
207
208 //******************************************************
209 PartSet_Module::~PartSet_Module()
210 {
211   std::map<PartSet_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
212     mySelectionFilters.begin();
213   for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
214     Handle(SelectMgr_Filter) aFilter = aFiltersIt->second;
215     if (!aFilter.IsNull())
216       aFilter.Nullify();
217   }
218   delete myCustomPrs;
219   delete myOverconstraintListener;
220 }
221
222 //******************************************************
223 void PartSet_Module::storeSelection()
224 {
225   // cash is used only to restore selection, so it should be filled in storeSelection and
226   // after applying immediatelly cleared in restoreSelection
227   myCurrentSelection.clear();
228   sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
229 }
230
231 //******************************************************
232 void PartSet_Module::restoreSelection()
233 {
234   // cash is used only to restore selection, so it should be filled in storeSelection and
235   // after applying immediatelly cleared in restoreSelection
236   sketchMgr()->restoreSelection(myCurrentSelection);
237   myCurrentSelection.clear();
238 }
239
240 //******************************************************
241 void PartSet_Module::registerValidators()
242 {
243   //Registering of validators
244   SessionPtr aMgr = ModelAPI_Session::get();
245   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
246   aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
247   aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
248   aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
249   aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
250   aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
251   aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
252   aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
253   aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
254   aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
255   aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
256   aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
257   aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
258   aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
259   aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
260   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
261   aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
262   aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
263   aFactory->registerValidator("PartSet_MultyTranslationSelection",
264     new PartSet_MultyTranslationSelection);
265   aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
266   aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
267 }
268
269 //******************************************************
270 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
271                                             const bool isToConnect)
272 {
273   mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
274 }
275
276 //******************************************************
277 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
278 {
279   if (sketchMgr()->isNestedSketchOperation(theOperation)) {
280     mySketchMgr->commitNestedSketch(theOperation);
281   }
282   /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
283   if (PartSet_SketcherMgr::isSketchOperation(theOperation))
284     overconstraintListener()->setActive(false);
285
286   /// Restart sketcher operations automatically
287   if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
288
289     ModuleBase_OperationFeature* aFOperation =
290       dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
291     if (aFOperation && !aFOperation->isEditOperation()) {
292       // the selection is cleared after commit the create operation
293       // in order to do not use the same selected objects in the restarted operation
294       // for common behaviour, the selection is cleared even if the operation is not restarted
295       getWorkshop()->selector()->clearSelection();
296     }
297   }
298 }
299
300 //******************************************************
301 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
302 {
303   /// Restart sketcher operations automatically
304   mySketchReentrantMgr->operationAborted(theOperation);
305   /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
306   if (PartSet_SketcherMgr::isSketchOperation(theOperation))
307     overconstraintListener()->setActive(false);
308 }
309
310 //******************************************************
311 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
312 {
313   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
314                                                                                 (theOperation);
315   if (aFOperation) {
316     XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
317     XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
318
319     ModuleBase_ModelWidget* aFilledWidget = 0;
320     bool aPostonedWidgetActivation = false;
321
322     FeaturePtr aFeature = aFOperation->feature();
323     /// Restart sketcher operations automatically
324     /// it is important to call method of sketch reentrant manager before filling of PP
325     /// because it fills some created feature attributes, these new values should be used
326     /// to fill the property panel
327     mySketchReentrantMgr->operationStarted(theOperation);
328
329     aWorkshop->fillPropertyPanel(aFOperation);
330     // filling the operation values by the current selection
331     // if the operation can be committed after the controls filling, the method perform should
332     // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
333     bool isOperationCommitted = false;
334     if (!aFOperation->isEditOperation()) {
335       std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
336       // if there is a greed attribute, automatic commit by preselection
337       // for this feature is prohibited
338       aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
339       if (currentOperation() != aFOperation)
340         isOperationCommitted = true;
341       else {
342         if (aGreedAttributeId.empty()) {
343           // a signal should be emitted before the next widget activation
344           // because, the activation of the next widget will give a focus to the widget.
345           // As a result the value of the widget is initialized.
346           // And commit may happens until the value is entered.
347           if (aFilledWidget) {
348             if (mySketchReentrantMgr->canBeCommittedByPreselection())
349               isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
350             // activate the next obligatory widget
351             if (!isOperationCommitted)
352               aPropertyPanel->activateNextWidget(aFilledWidget);
353           }
354         }
355         else { // there is a greed widget
356           const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
357           std::string aFirstAttributeId = aWidgets.front()->attributeID();
358           // activate next widget after greeded if it is the first widget in the panel
359           // else the first panel widget is already activated by operation start
360           if (aFirstAttributeId == aGreedAttributeId)
361             aPostonedWidgetActivation = true;
362         }
363       }
364     } if (!isOperationCommitted) {
365       aWorkshop->connectToPropertyPanel(true);
366       updateSketcherOnStart(aFOperation);
367       updatePresentationsOnStart(aFOperation);
368
369       // the objects of the current operation should be deactivated
370       QObjectPtrList anObjects;
371       anObjects.append(aFeature);
372       std::list<ResultPtr> aResults;
373       ModelAPI_Tools::allResults(aFeature, aResults);
374       std::list<ResultPtr>::const_iterator aIt;
375       for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
376         anObjects.append(*aIt);
377       }
378       QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
379       for (; anIt != aLast; anIt++)
380         aWorkshop->deactivateActiveObject(*anIt, false);
381       if (anObjects.size() > 0) {
382         XGUI_Displayer* aDisplayer = aWorkshop->displayer();
383         aDisplayer->updateViewer();
384       }
385       /// state of command actions should be updated after displayed objects modification because
386       /// deactivation(for example) of objects may influence on selection in the viewer
387       /// State of command actions may depend on selection in the viewer(e.g. Sketch)
388       workshop()->updateCommandStatus();
389     }
390     if (aPostonedWidgetActivation) {
391       // if the widget is an empty in the chain of activated widgets, the current operation
392       // is restarted. It should be performed after functionality of the operation starting
393       aPropertyPanel->activateNextWidget(aFilledWidget);
394     }
395   }
396 }
397
398 //******************************************************
399 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
400 {
401   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
402     mySketchMgr->startSketch(theOperation);
403   }
404   else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
405     mySketchMgr->startNestedSketch(theOperation);
406   }
407 }
408
409 //******************************************************
410 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
411 {
412   ModuleBase_OperationFeature* aFOperation =
413     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
414   if (aFOperation) {
415     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
416     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
417   }
418 }
419
420 //******************************************************
421 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
422 {
423   ModuleBase_IModule::operationResumed(theOperation);
424
425   ModuleBase_OperationFeature* aFOperation =
426     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
427   if (aFOperation) {
428     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
429     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
430   }
431 }
432
433 //******************************************************
434 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
435 {
436   bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
437   bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
438   bool isModified = isModifiedArgs || isModifiedResults;
439
440   if (sketchMgr()->isNestedSketchOperation(theOperation)) {
441     mySketchMgr->stopNestedSketch(theOperation);
442   }
443   else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
444     setDefaultConstraintShown();
445
446   //VSV: Viewer is updated on feature update and redisplay
447   if (isModified) {
448     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
449     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
450     aDisplayer->updateViewer();
451   }
452
453   QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
454     anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
455   for (; anIt != aLast; anIt++) {
456     mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
457   }
458 }
459
460 //******************************************************
461 ModuleBase_Operation* PartSet_Module::currentOperation() const
462 {
463   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
464   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
465   return anOpMgr->currentOperation();
466 }
467
468 //******************************************************
469 bool PartSet_Module::canUndo() const
470 {
471   bool aCanUndo = false;
472   SessionPtr aMgr = ModelAPI_Session::get();
473   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
474     aCanUndo = !aMgr->isOperation();
475     if (!aCanUndo) // check the enable state additionally by sketch manager
476       aCanUndo = aMgr->canUndo();
477   }
478   return aCanUndo;
479 }
480
481 //******************************************************
482 bool PartSet_Module::canRedo() const
483 {
484   bool aCanRedo = false;
485   SessionPtr aMgr = ModelAPI_Session::get();
486   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
487     aCanRedo = !aMgr->isOperation();
488     if (!aCanRedo) // check the enable state additionally by sketch manager
489       aCanRedo = aMgr->canRedo();
490   }
491   return aCanRedo;
492 }
493
494 //******************************************************
495 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
496 {
497   bool aValid = true;
498   if (theActionId == "MOVE_CMD") {
499     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
500     if (aFeature) {
501       ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
502       // part features can not be moved in the history.
503       if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
504         aValid = false;
505     }
506   }
507   return aValid;
508 }
509
510 //******************************************************
511 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
512 {
513   // the sketch manager put the restriction to the objects erase
514   return mySketchMgr->canEraseObject(theObject);
515 }
516
517 //******************************************************
518 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
519 {
520   // the sketch manager put the restriction to the objects display
521   return mySketchMgr->canDisplayObject(theObject);
522 }
523
524 //******************************************************
525 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
526                                         const QString& theStartedOperationKind)
527 {
528   if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
529     return true;
530
531   return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
532 }
533
534 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
535 {
536   mySketchMgr->processHiddenObject(theObjects);
537 }*/
538
539 //******************************************************
540 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
541 {
542   bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
543
544   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
545   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
546        isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
547   if (isSketchOp || isNestedOp) {
548     // in active sketch operation it is possible to activate operation object in selection
549     // in the edit operation, e.g. points of the line can be moved when the line is edited
550     ModuleBase_OperationFeature* aFOperation =
551       dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
552     aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
553   }
554   return aCanActivate;
555 }
556
557 //******************************************************
558 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
559                                    QWidget* theParent,
560                                    QMap<int, QAction*>& theMenuActions) const
561 {
562   return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
563 }
564
565 //******************************************************
566 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
567 {
568   myMenuMgr->updateViewerMenu(theStdActions);
569 }
570
571 //******************************************************
572 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
573 {
574   bool isEnabledFixed = false;
575   if (theActionId == XGUI_ActionsMgr::AcceptAll &&
576       mySketchReentrantMgr->isInternalEditActive())
577     isEnabledFixed = true;
578   return isEnabledFixed;
579 }
580
581 //******************************************************
582 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
583 {
584   QString anError = ModuleBase_IModule::getFeatureError(theFeature);
585   if (anError.isEmpty())
586     anError = sketchMgr()->getFeatureError(theFeature);
587
588   return anError;
589 }
590
591 //******************************************************
592 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
593                                          QStringList& theIds) const
594 {
595   myMenuMgr->grantedOperationIds(theOperation, theIds);
596
597   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
598     XGUI_Workshop* aWorkshop = getWorkshop();
599     theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
600   }
601 }
602
603 //******************************************************
604 void PartSet_Module::activeSelectionModes(QIntList& theModes)
605 {
606   if (mySketchMgr->activeSketch().get())
607     PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
608   else
609     theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
610 }
611
612 //******************************************************
613 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
614 {
615   customSubShapesSelectionModes(theModes);
616   //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
617   //myWorkshop->module()->activeSelectionModes(theModes);
618 }
619
620 //******************************************************
621 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
622                                             SelectMgr_ListOfFilter& theSelectionFilters)
623 {
624   bool isSketchActive = mySketchMgr->activeSketch();
625   XGUI_ActiveControlSelector* anActiveSelector =
626     getWorkshop()->activeControlMgr()->activeSelector();
627   bool isHideFacesActive = anActiveSelector &&
628                            anActiveSelector->getType() == XGUI_FacesPanelSelector::Type();
629
630   std::map<PartSet_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
631     mySelectionFilters.begin();
632   for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
633     int aFilterType = aFiltersIt->first;
634     // do not add not participating filters in given parameters
635     if (!theFilterTypes.contains(aFilterType))
636       continue;
637
638     // using sketch filters only if sketch operation is active
639     if (!isSketchActive &&
640         mySketchMgr->sketchSelectionFilter((PartSet_SelectionFilterType)aFilterType))
641       continue;
642
643     // using filtering of construction results only when faces panel is active
644     if (aFilterType == SF_ResultGroupNameFilter && !isHideFacesActive)
645       continue;
646
647     theSelectionFilters.Append(aFiltersIt->second);
648   }
649 }
650
651 //******************************************************
652 QIntList PartSet_Module::selectionFilters()
653 {
654   QIntList aTypes;
655
656   std::map<PartSet_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
657     mySelectionFilters.begin();
658   for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++)
659     aTypes.append(aFiltersIt->first);
660
661   return aTypes;
662 }
663
664 //******************************************************
665 void PartSet_Module::registerSelectionFilter(const PartSet_SelectionFilterType theFilterType,
666                                              const Handle(SelectMgr_Filter)& theFilter)
667 {
668   mySelectionFilters[theFilterType] = theFilter;
669 }
670
671 //******************************************************
672 Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(
673   const PartSet_SelectionFilterType theFilterType)
674 {
675   if (mySelectionFilters.find(theFilterType) != mySelectionFilters.end())
676     return mySelectionFilters[theFilterType];
677   else
678     return Handle(SelectMgr_Filter)();
679 }
680
681 //******************************************************
682 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
683 {
684   if (theModes.contains(TopAbs_FACE))
685     theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
686   if (theModes.contains(TopAbs_WIRE))
687     theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
688
689   if (mySketchMgr->activeSketch().get())
690     PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
691 }
692
693 //******************************************************
694 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
695                                       ObjectPtr& theObject, AttributePtr& theAttribute)
696 {
697   ObjectPtr anObject = theSelected->object();
698   GeomShapePtr aShape = theSelected->shape();
699
700   theAttribute = findAttribute(anObject, aShape);
701   // TODO: try to create result if object is an external object
702   theObject = anObject;
703 }
704
705 //******************************************************
706 bool PartSet_Module::isMouseOverWindow()
707 {
708   return mySketchMgr->isMouseOverWindow();
709 }
710
711 //******************************************************
712 bool PartSet_Module::isSketchNeutralPointActivated() const
713 {
714   bool isNeutralPoint = true;
715   if (sketchReentranceMgr()->isInternalEditActive())
716     isNeutralPoint = false;
717   if (myIsOperationIsLaunched)
718     isNeutralPoint = false;
719
720   return isNeutralPoint;
721 }
722
723 //******************************************************
724 void PartSet_Module::closeDocument()
725 {
726   myActivePartIndex = QModelIndex();
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   anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
913   if (!anActiveWidget) {
914     ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
915     if (aOperation) {
916       ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
917       anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
918     }
919   }
920   return anActiveWidget;
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     bool aToUseZLayer = false;
1052     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1053     if (aFeature.get() && PartSet_Tools::findRefsToMeFeature(aFeature,
1054                                                         SketchPlugin_Projection::ID()))
1055       aToUseZLayer = true;
1056     Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1057     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
1058     if (!aDim.IsNull()) {
1059       aToUseZLayer = true;
1060     } else {
1061       Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
1062       if (!aCons.IsNull())
1063       aToUseZLayer = true;
1064     }
1065     if (aToUseZLayer)
1066       aCtx->SetZLayer(anAIS, myVisualLayerId);
1067   }
1068 }
1069
1070 //******************************************************
1071 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1072 {
1073   // this is obsolete
1074   // it should be recomputed in order to disappear in the viewer if the corresponded object
1075   // is erased
1076   //if (myCustomPrs->isActive())
1077   //  myCustomPrs->redisplay(theObject, false);
1078 }
1079
1080 //******************************************************
1081 void PartSet_Module::onViewTransformed(int theTrsfType)
1082 {
1083   // Set length of arrows constant in pixel size
1084   // if the operation is panning or rotate or panglobal then do nothing
1085   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1086     return;
1087   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1088   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1089   if (aContext.IsNull())
1090     return;
1091
1092   //Handle(V3d_View) aView = aViewer->activeView();
1093
1094   XGUI_Workshop* aWorkshop = getWorkshop();
1095   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1096   Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1097   Handle(V3d_View) aView;
1098   double aScale = 0;
1099   for (aV3dViewer->InitDefinedViews();
1100        aV3dViewer->MoreDefinedViews();
1101        aV3dViewer->NextDefinedViews()) {
1102     Handle(V3d_View) aV = aV3dViewer->DefinedView();
1103     double aS = aV->Scale();
1104     if (aS > aScale) {
1105       aScale = aS;
1106       aView = aV;
1107     }
1108   }
1109   if (aView.IsNull())
1110     return;
1111
1112   ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1113   if (aCurrentOperation &&
1114     (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1115      sketchMgr()->isNestedSketchOperation(aCurrentOperation)))
1116   {
1117     double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1118
1119     double aPrevLen = SketcherPrs_Tools::getArrowSize();
1120     SketcherPrs_Tools::setArrowSize(aLen);
1121     const double aCurScale = aViewer->activeView()->Camera()->Scale();
1122     aViewer->SetScale(aViewer->activeView(), aCurScale);
1123     bool isModified = false;
1124     QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1125     foreach (AISObjectPtr aAIS, aPrsList) {
1126       Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1127
1128       Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1129       if (!aDim.IsNull()) {
1130         aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1131         aContext->Redisplay(aDim, false);
1132         isModified = true;
1133       }
1134     }
1135     if (isModified)
1136       aDisplayer->updateViewer();
1137   }
1138 }
1139
1140 //******************************************************
1141 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1142 {
1143   return myCustomPrs->isActive(theFlag);
1144 }
1145
1146 //******************************************************
1147 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1148                                        const ModuleBase_CustomizeFlag& theFlag,
1149                                        const bool theUpdateViewer)
1150 {
1151   myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1152 }
1153
1154 //******************************************************
1155 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1156                                          const bool theUpdateViewer)
1157 {
1158   myCustomPrs->deactivate(theFlag, theUpdateViewer);
1159 }
1160
1161 //******************************************************
1162 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1163                                            std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1164 {
1165   bool aCustomized = false;
1166
1167   XGUI_Workshop* aWorkshop = getWorkshop();
1168   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1169   ObjectPtr anObject = aDisplayer->getObject(thePrs);
1170   if (!anObject)
1171     return aCustomized;
1172
1173   if (!theResult.get()) {
1174     std::vector<int> aColor;
1175     XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1176     if (!aColor.empty()) {
1177       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1178     }
1179   }
1180   // customize dimentional constrains
1181   sketchMgr()->customizePresentation(anObject);
1182
1183   return aCustomized;
1184 }
1185
1186 //******************************************************
1187 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1188                                                 AISObjectPtr thePrs,
1189                                                 GeomCustomPrsPtr theCustomPrs)
1190 {
1191   bool aCustomized = false;
1192
1193   XGUI_Workshop* aWorkshop = getWorkshop();
1194   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1195   ObjectPtr anObject = aDisplayer->getObject(thePrs);
1196   if (!anObject)
1197     return aCustomized;
1198
1199   std::vector<int> aColor;
1200   bool aUseCustomColor = true;
1201   if (aUseCustomColor)
1202     myOverconstraintListener->getCustomColor(anObject, aColor);
1203   // customize sketch symbol presentation
1204   Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1205   if (!anAISIO.IsNull()) {
1206     if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1207       Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1208       if (!aPrs.IsNull()) {
1209         aPrs->SetCustomColor(aColor);
1210         aCustomized = true;
1211       }
1212     } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1213       Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1214       if (!aPrs.IsNull()) {
1215         aPrs->SetCustomColor(aColor);
1216         aCustomized = true;
1217       }
1218     }
1219   }
1220   // customize sketch dimension constraint presentation
1221   if (!aCustomized) {
1222     if (!aColor.empty()) { // otherwise presentation has the default color
1223       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1224     }
1225   }
1226   return aCustomized;
1227 }
1228
1229 //******************************************************
1230 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1231                                      const bool theUpdateViewer)
1232 {
1233   bool isRedisplayed = false;
1234   if (myCustomPrs->isActive(theFlag))
1235     isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1236
1237   return isRedisplayed;
1238 }
1239
1240 //******************************************************
1241 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1242 {
1243   XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1244   if (aOB) {
1245     QLabel* aLabel = aOB->activeDocLabel();
1246     aLabel->installEventFilter(myMenuMgr);
1247     connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1248           SLOT(onActiveDocPopup(const QPoint&)));
1249     aOB->treeView()->setExpandsOnDoubleClick(false);
1250     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1251       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1252
1253     Events_Loop* aLoop = Events_Loop::loop();
1254     aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1255   }
1256 }
1257
1258 //******************************************************
1259 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1260 {
1261   SessionPtr aMgr = ModelAPI_Session::get();
1262   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1263
1264   XGUI_Workshop* aWorkshop = getWorkshop();
1265   QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1266
1267   aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1268
1269   QMenu aMenu;
1270   aMenu.addAction(aActivatePartAction);
1271   aMenu.exec(aHeader->mapToGlobal(thePnt));
1272 }
1273
1274 //******************************************************
1275 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1276 {
1277   return mySketchMgr->createPresentation(theResult);
1278 }
1279
1280 //******************************************************
1281 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1282 {
1283   ObjectPtr anObject;
1284   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1285   if (aOperation) {
1286     /// If last line finished on vertex the lines creation sequence has to be break
1287     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1288     if (aPanel) {
1289       ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1290       // if there is an active widget, find the presented object in it
1291       if (!anActiveWidget)
1292         anActiveWidget = aPanel->preselectionWidget();
1293
1294       ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1295                                                                              (anActiveWidget);
1296       if (aWidgetValidated)
1297         anObject = aWidgetValidated->findPresentedObject(theAIS);
1298     }
1299   }
1300   return anObject;
1301 }
1302
1303 //******************************************************
1304 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1305 {
1306   bool aCanBeShaged = true;
1307
1308   Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1309   if (!aPrs.IsNull())
1310     aCanBeShaged = false;
1311
1312   return aCanBeShaged;
1313 }
1314
1315 //******************************************************
1316 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1317 {
1318   QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1319   int aSelected = aObjects.size();
1320   SessionPtr aMgr = ModelAPI_Session::get();
1321   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1322
1323   bool hasResult = false;
1324   bool hasFeature = false;
1325   bool hasParameter = false;
1326   bool hasCompositeOwner = false;
1327   bool hasResultInHistory = false;
1328   bool hasFolder = false;
1329   ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1330                                   hasCompositeOwner, hasResultInHistory, hasFolder);
1331
1332   ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1333   if (aSelected == 1) {
1334     ObjectPtr aObject = aObjects.first();
1335     if (aObject) {
1336       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1337       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1338       bool isPart = aPart.get() ||
1339         (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1340       if (isPart) {
1341         DocumentPtr aPartDoc;
1342         if (!aPart.get()) {
1343           aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1344         }
1345         if (aPart.get()) // this may be null is Part feature is disabled
1346           aPartDoc = aPart->partDoc();
1347
1348         theMenu->addAction(aActivatePartAction);
1349         aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1350
1351       } else if (aObject->document() == aMgr->activeDocument()) {
1352         if (hasParameter || hasFeature) {
1353           myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1354           theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1355           if (aCurrentOp && aFeature.get()) {
1356             if (aCurrentOp->id().toStdString() == aFeature->getKind())
1357               myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1358           }
1359         }
1360       }
1361     }
1362   } else {
1363     if (hasFeature) {
1364       myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1365       theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1366       theMenu->addSeparator();
1367     }
1368   }
1369   bool aNotDeactivate = (aCurrentOp == 0);
1370   if (!aNotDeactivate) {
1371     aActivatePartAction->setEnabled(false);
1372   }
1373 }
1374
1375 //******************************************************
1376 #define EXPAND_PARENT(OBJ) \
1377 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1378 if (aObjIndex.isValid()) { \
1379   QModelIndex aParent = aObjIndex.parent(); \
1380   int aCount = aDataModel->rowCount(aParent); \
1381   if (aCount == 1) \
1382     aTreeView->setExpanded(aParent, true); \
1383 }
1384
1385 //******************************************************
1386 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1387 {
1388   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1389     // Do not change activation of parts if an operation active
1390     static QStringList aAllowActivationList;
1391     if (aAllowActivationList.isEmpty())
1392       aAllowActivationList <<
1393       QString(PartSetPlugin_Part::ID().c_str()) <<
1394       QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1395       QString(PartSetPlugin_Remove::ID().c_str());
1396     if (myWorkshop->currentOperation() &&
1397       (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1398       return;
1399     XGUI_Workshop* aWorkshop = getWorkshop();
1400     XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1401     QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1402     QPalette aPalet = aLabel->palette();
1403
1404     SessionPtr aMgr = ModelAPI_Session::get();
1405     DocumentPtr aActiveDoc = aMgr->activeDocument();
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 }