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