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