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