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