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