]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
Redevelopment of object browser data model
[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<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1136     foreach (AISObjectPtr aAIS, aPrsList) {
1137       Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1138
1139       Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1140       if (!aDim.IsNull()) {
1141         aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1142         aContext->Redisplay(aDim, false);
1143         isModified = true;
1144       }
1145     }
1146     if (isModified)
1147       aDisplayer->updateViewer();
1148   }
1149 }
1150
1151 //******************************************************
1152 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1153 {
1154   return myCustomPrs->isActive(theFlag);
1155 }
1156
1157 //******************************************************
1158 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1159                                        const ModuleBase_CustomizeFlag& theFlag,
1160                                        const bool theUpdateViewer)
1161 {
1162   myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1163 }
1164
1165 //******************************************************
1166 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1167                                          const bool theUpdateViewer)
1168 {
1169   myCustomPrs->deactivate(theFlag, theUpdateViewer);
1170 }
1171
1172 //******************************************************
1173 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1174                                            std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1175 {
1176   bool aCustomized = false;
1177
1178   XGUI_Workshop* aWorkshop = getWorkshop();
1179   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1180   ObjectPtr anObject = aDisplayer->getObject(thePrs);
1181   if (!anObject)
1182     return aCustomized;
1183
1184   if (!theResult.get()) {
1185     std::vector<int> aColor;
1186     XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1187     if (!aColor.empty()) {
1188       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1189     }
1190   }
1191   // customize dimentional constrains
1192   sketchMgr()->customizePresentation(anObject);
1193
1194   return aCustomized;
1195 }
1196
1197 //******************************************************
1198 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1199                                                 AISObjectPtr thePrs,
1200                                                 GeomCustomPrsPtr theCustomPrs)
1201 {
1202   bool aCustomized = false;
1203
1204   XGUI_Workshop* aWorkshop = getWorkshop();
1205   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1206   ObjectPtr anObject = aDisplayer->getObject(thePrs);
1207   if (!anObject)
1208     return aCustomized;
1209
1210   std::vector<int> aColor;
1211   bool aUseCustomColor = true;
1212   if (aUseCustomColor)
1213     myOverconstraintListener->getCustomColor(anObject, aColor);
1214   // customize sketch symbol presentation
1215   Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1216   if (!anAISIO.IsNull()) {
1217     if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1218       Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1219       if (!aPrs.IsNull()) {
1220         aPrs->SetCustomColor(aColor);
1221         aCustomized = true;
1222       }
1223     } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1224       Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1225       if (!aPrs.IsNull()) {
1226         aPrs->SetCustomColor(aColor);
1227         aCustomized = true;
1228       }
1229     }
1230   }
1231   // customize sketch dimension constraint presentation
1232   if (!aCustomized) {
1233     if (!aColor.empty()) { // otherwise presentation has the default color
1234       aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1235     }
1236   }
1237   return aCustomized;
1238 }
1239
1240 //******************************************************
1241 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1242                                      const bool theUpdateViewer)
1243 {
1244   bool isRedisplayed = false;
1245   if (myCustomPrs->isActive(theFlag))
1246     isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1247
1248   return isRedisplayed;
1249 }
1250
1251 //******************************************************
1252 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1253 {
1254   XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1255   if (aOB) {
1256     QLabel* aLabel = aOB->activeDocLabel();
1257     aLabel->installEventFilter(myMenuMgr);
1258     connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1259           SLOT(onActiveDocPopup(const QPoint&)));
1260     aOB->treeView()->setExpandsOnDoubleClick(false);
1261     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1262       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1263
1264     Events_Loop* aLoop = Events_Loop::loop();
1265     aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1266   }
1267 }
1268
1269 //******************************************************
1270 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1271 {
1272   SessionPtr aMgr = ModelAPI_Session::get();
1273   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1274
1275   XGUI_Workshop* aWorkshop = getWorkshop();
1276   QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1277
1278   aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1279
1280   QMenu aMenu;
1281   aMenu.addAction(aActivatePartAction);
1282   aMenu.exec(aHeader->mapToGlobal(thePnt));
1283 }
1284
1285 //******************************************************
1286 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1287 {
1288   return mySketchMgr->createPresentation(theResult);
1289 }
1290
1291 //******************************************************
1292 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1293 {
1294   ObjectPtr anObject;
1295   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1296   if (aOperation) {
1297     /// If last line finished on vertex the lines creation sequence has to be break
1298     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1299     if (aPanel) {
1300       ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1301       // if there is an active widget, find the presented object in it
1302       if (!anActiveWidget)
1303         anActiveWidget = aPanel->preselectionWidget();
1304
1305       ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1306                                                                              (anActiveWidget);
1307       if (aWidgetValidated)
1308         anObject = aWidgetValidated->findPresentedObject(theAIS);
1309     }
1310   }
1311   return anObject;
1312 }
1313
1314 //******************************************************
1315 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1316 {
1317   bool aCanBeShaged = true;
1318
1319   Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1320   if (!aPrs.IsNull())
1321     aCanBeShaged = false;
1322
1323   return aCanBeShaged;
1324 }
1325
1326 //******************************************************
1327 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1328 {
1329   QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1330   int aSelected = aObjects.size();
1331   SessionPtr aMgr = ModelAPI_Session::get();
1332   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1333
1334   bool hasResult = false;
1335   bool hasFeature = false;
1336   bool hasParameter = false;
1337   bool hasCompositeOwner = false;
1338   bool hasResultInHistory = false;
1339   bool hasFolder = false;
1340   ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1341                                   hasCompositeOwner, hasResultInHistory, hasFolder);
1342
1343   ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1344   if (aSelected == 1) {
1345     ObjectPtr aObject = aObjects.first();
1346     if (aObject) {
1347       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1348       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1349       bool isPart = aPart.get() ||
1350         (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1351       if (isPart) {
1352         DocumentPtr aPartDoc;
1353         if (!aPart.get()) {
1354           aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1355         }
1356         if (aPart.get()) // this may be null is Part feature is disabled
1357           aPartDoc = aPart->partDoc();
1358
1359         theMenu->addAction(aActivatePartAction);
1360         aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1361
1362       } else if (aObject->document() == aMgr->activeDocument()) {
1363         if (hasParameter || hasFeature) {
1364           myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1365           theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1366           if (aCurrentOp && aFeature.get()) {
1367             if (aCurrentOp->id().toStdString() == aFeature->getKind())
1368               myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1369           }
1370         }
1371       }
1372     }
1373   } else {
1374     if (hasFeature) {
1375       myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1376       theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1377       theMenu->addSeparator();
1378     }
1379   }
1380   bool aNotDeactivate = (aCurrentOp == 0);
1381   if (!aNotDeactivate) {
1382     aActivatePartAction->setEnabled(false);
1383   }
1384 }
1385
1386 //******************************************************
1387 #define EXPAND_PARENT(OBJ) \
1388 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1389 if (aObjIndex.isValid()) { \
1390   QModelIndex aParent = aObjIndex.parent(); \
1391   int aCount = aDataModel->rowCount(aParent); \
1392   if (aCount == 1) \
1393     aTreeView->setExpanded(aParent, true); \
1394 }
1395
1396 //******************************************************
1397 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1398 {
1399   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1400     // Do not change activation of parts if an operation active
1401     static QStringList aAllowActivationList;
1402     if (aAllowActivationList.isEmpty())
1403       aAllowActivationList <<
1404       QString(PartSetPlugin_Part::ID().c_str()) <<
1405       QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1406       QString(PartSetPlugin_Remove::ID().c_str());
1407     if (myWorkshop->currentOperation() &&
1408       (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1409       return;
1410     XGUI_Workshop* aWorkshop = getWorkshop();
1411     XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1412     QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1413     QPalette aPalet = aLabel->palette();
1414
1415     SessionPtr aMgr = ModelAPI_Session::get();
1416     DocumentPtr aActiveDoc = aMgr->activeDocument();
1417     // workaround for #2431 (SISGSEGV when launching some unit tests from GUI)
1418     //if (myActivePartIndex.isValid())
1419     //  aTreeView->setExpanded(myActivePartIndex, false);
1420
1421     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1422     myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1423     bool needUpdate = false;
1424     if (myActivePartIndex.isValid()) {
1425       needUpdate = aTreeView->isExpanded(myActivePartIndex);
1426       if (!needUpdate)
1427         aTreeView->setExpanded(myActivePartIndex, true);
1428     }
1429
1430     aLabel->setPalette(aPalet);
1431     aWorkshop->updateCommandStatus();
1432
1433     // Update displayed objects in order to update active color
1434     XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1435     QObjectPtrList aObjects = aDisplayer->displayedObjects();
1436     bool aHidden;
1437     foreach(ObjectPtr aObj, aObjects) {
1438       aHidden = !aObj->data() || !aObj->data()->isValid() ||
1439         aObj->isDisabled() || (!aObj->isDisplayed());
1440       if (!aHidden)
1441         aDisplayer->redisplay(aObj, false);
1442     }
1443     aDisplayer->updateViewer();
1444     // Update tree items if they are expanded
1445     if (needUpdate) {
1446       aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1447     }
1448   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1449     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1450         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1451     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1452
1453     ObjectPtr aConstrObj;
1454     ObjectPtr aResultObj;
1455     std::set<ObjectPtr>::const_iterator aIt;
1456     DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1457     for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1458       ObjectPtr aObject = (*aIt);
1459       if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1460           && (aObject->document() != aRootDoc))
1461         aResultObj = aObject;
1462       if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1463           && (aObject->document() != aRootDoc))
1464         aConstrObj = aObject;
1465       if (aResultObj.get() && aConstrObj.get())
1466         break;
1467     }
1468
1469     if (aResultObj.get() || aConstrObj.get()) {
1470       XGUI_Workshop* aWorkshop = getWorkshop();
1471       XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1472       XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1473
1474       if (aResultObj.get()) {
1475         EXPAND_PARENT(aResultObj)
1476       }
1477       if (aConstrObj.get()) {
1478         EXPAND_PARENT(aConstrObj)
1479       }
1480     }
1481   }
1482 }
1483
1484 //******************************************************
1485 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1486 {
1487   if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1488     return;
1489   SessionPtr aMgr = ModelAPI_Session::get();
1490   if (!theIndex.isValid()) {
1491     // It seems that this code is obsolete
1492     //aMgr->setActiveDocument(aMgr->moduleDocument());
1493     return;
1494   }
1495   if (theIndex.column() != 1) // Use only first column
1496     return;
1497
1498   XGUI_Workshop* aWorkshop = getWorkshop();
1499   XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1500   // De not use non editable Indexes
1501   if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1502     return;
1503   ObjectPtr aObj = aDataModel->object(theIndex);
1504
1505   ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1506   if (!aPart.get()) { // Probably this is Feature
1507     FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1508     if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1509       aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1510     }
1511   }
1512   if (aPart.get()) { // if this is a part
1513     if (aPart->partDoc() == aMgr->activeDocument()) {
1514       myMenuMgr->activatePartSet();
1515     } else {
1516       myMenuMgr->activatePart(aPart);
1517     }
1518   }
1519 }
1520
1521 //******************************************************
1522 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1523 {
1524   // z layer is created for all started operations in order to visualize operation AIS presentation
1525   // over the object
1526   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1527   if (aContext.IsNull())
1528     return;
1529
1530   Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1531   if (myVisualLayerId == 0) {
1532     if (myVisualLayerId == 0)
1533       aViewer->AddZLayer(myVisualLayerId);
1534   } else {
1535     TColStd_SequenceOfInteger aZList;
1536     aViewer->GetAllZLayers(aZList);
1537     bool aFound = false;
1538     for (int i = 1; i <= aZList.Length(); i++) {
1539       if (aZList(i) == myVisualLayerId) {
1540         aFound = true;
1541         break;
1542       }
1543     }
1544     if (!aFound)
1545       aViewer->AddZLayer(myVisualLayerId);
1546   }
1547   // if there is an active operation with validated widget,
1548   // the filters of this widget should be activated in the created view
1549   myWorkshop->selectionActivate()->updateSelectionFilters();
1550   myWorkshop->selectionActivate()->updateSelectionModes();
1551 }
1552
1553 //******************************************************
1554 void PartSet_Module::widgetStateChanged(int thePreviousState)
1555 {
1556   mySketchMgr->widgetStateChanged(thePreviousState);
1557 }
1558
1559 //******************************************************
1560 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1561 {
1562   return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1563 }
1564
1565 //******************************************************
1566 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1567 {
1568   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1569     mySketchMgr->stopSketch(theOperation);
1570   }
1571 }
1572
1573 //******************************************************
1574 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1575 {
1576   GeomShapePtr aGeomShape;
1577
1578   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1579   if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1580     aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1581   }
1582   return aGeomShape;
1583 }
1584
1585 //******************************************************
1586 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1587                                            const GeomShapePtr& theGeomShape)
1588 {
1589   AttributePtr anAttribute;
1590   GeomShapePtr aGeomShape = theGeomShape;
1591   if (!aGeomShape.get()) {
1592     // processing shape of result, e.g. sketch circle center is selected, this is a result
1593     // the geom shape is empty, the shape of result should be used
1594     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1595     if (aResult.get()) {
1596       aGeomShape = aResult->shape();
1597     }
1598   }
1599
1600   if (aGeomShape.get()) {
1601     TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1602     return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1603                                                  mySketchMgr->activeSketch());
1604   }
1605   return anAttribute;
1606 }
1607
1608 //******************************************************
1609 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1610 {
1611   return sketchReentranceMgr()->reentrantMessage();
1612 }
1613
1614 //******************************************************
1615 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1616 {
1617   sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1618 }
1619
1620 //******************************************************
1621 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1622                                      int theIndex)
1623 {
1624   ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1625   if (!aChoiceWidget)
1626     return;
1627
1628   QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1629   if (!aChoiceTitle.isEmpty()) {
1630     ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1631     if (!aOperation)
1632       return;
1633     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1634     if (aPanel)
1635       aPanel->setWindowTitle(aChoiceTitle);
1636   }
1637 }
1638
1639 //******************************************************
1640 XGUI_Workshop* PartSet_Module::getWorkshop() const
1641 {
1642   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1643   return aConnector->workshop();
1644 }
1645
1646 void PartSet_Module::setDefaultConstraintShown()
1647 {
1648   myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1649   myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1650   myHasConstraintShown[PartSet_Tools::Expressions] = false;
1651 }
1652
1653 //******************************************************
1654 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1655 {
1656   return myRoot;
1657 }