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