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