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