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