]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
ModuleBase_WidgetShapeSelector correction to process AttrRefAtt like MultiSelector...
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include "PartSet_Module.h"
4 #include "PartSet_WidgetSketchLabel.h"
5 #include "PartSet_Validators.h"
6 #include "PartSet_Tools.h"
7 #include "PartSet_WidgetPoint2d.h"
8 #include "PartSet_WidgetPoint2dDistance.h"
9 #include "PartSet_WidgetPoint2DFlyout.h"
10 #include "PartSet_WidgetShapeSelector.h"
11 #include "PartSet_WidgetMultiSelector.h"
12 #include "PartSet_WidgetEditor.h"
13 #include "PartSet_WidgetFileSelector.h"
14 #include "PartSet_WidgetSketchCreator.h"
15 #include "PartSet_SketcherMgr.h"
16 #include "PartSet_SketcherReetntrantMgr.h"
17 #include "PartSet_MenuMgr.h"
18 #include "PartSet_CustomPrs.h"
19 #include "PartSet_IconFactory.h"
20 #include "PartSet_WidgetChoice.h"
21
22 #include "PartSet_Filters.h"
23 #include "PartSet_FilterInfinite.h"
24
25 #include <PartSetPlugin_Remove.h>
26 #include <PartSetPlugin_Part.h>
27 #include <PartSetPlugin_Duplicate.h>
28
29 #include <ModuleBase_Operation.h>
30 #include <ModuleBase_OperationAction.h>
31 #include <ModuleBase_IViewer.h>
32 #include <ModuleBase_IViewWindow.h>
33 #include <ModuleBase_IPropertyPanel.h>
34 #include <ModuleBase_WidgetEditor.h>
35 #include <ModuleBase_WidgetValidated.h>
36 #include <ModuleBase_FilterFactory.h>
37 #include <ModuleBase_Tools.h>
38 #include <ModuleBase_OperationFeature.h>
39
40 #include <ModelAPI_Object.h>
41 #include <ModelAPI_Events.h>
42 #include <ModelAPI_Validator.h>
43 #include <ModelAPI_Data.h>
44 #include <ModelAPI_Session.h>
45 #include <ModelAPI_ResultBody.h>
46 #include <ModelAPI_AttributeString.h>
47
48 #include <GeomDataAPI_Point2D.h>
49 #include <GeomDataAPI_Point.h>
50 #include <GeomDataAPI_Dir.h>
51
52 #include <XGUI_Displayer.h>
53 #include <XGUI_Workshop.h>
54 #include <XGUI_OperationMgr.h>
55 #include <XGUI_PropertyPanel.h>
56 #include <XGUI_ModuleConnector.h>
57 #include <XGUI_ContextMenuMgr.h>
58 #include <XGUI_Tools.h>
59 #include <XGUI_ObjectsBrowser.h>
60 #include <XGUI_SelectionMgr.h>
61 #include <XGUI_DataModel.h>
62 #include <XGUI_ErrorMgr.h>
63
64 #include <SketchPlugin_Feature.h>
65 #include <SketchPlugin_Sketch.h>
66 #include <SketchPlugin_ConstraintAngle.h>
67 #include <SketchPlugin_ConstraintLength.h>
68 #include <SketchPlugin_ConstraintDistance.h>
69 #include <SketchPlugin_ConstraintParallel.h>
70 #include <SketchPlugin_ConstraintPerpendicular.h>
71 #include <SketchPlugin_ConstraintRadius.h>
72
73 #include <SketcherPrs_SymbolPrs.h>
74 #include <SketcherPrs_Tools.h>
75
76 #include <Events_Loop.h>
77 #include <Config_PropManager.h>
78 #include <Config_Keywords.h>
79
80 #include <StdSelect_TypeOfFace.hxx>
81 #include <TopoDS_Vertex.hxx>
82 #include <TopoDS.hxx>
83 #include <TopoDS_Shape.hxx>
84 #include <BRep_Tool.hxx>
85 #include <AIS_Dimension.hxx>
86
87 #include <QObject>
88 #include <QMouseEvent>
89 #include <QString>
90 #include <QTimer>
91 #include <QApplication>
92 #include <QMessageBox>
93 #include <QMainWindow>
94 #include <QLineEdit>
95
96 #include <GeomAlgoAPI_FaceBuilder.h>
97 #include <GeomDataAPI_Dir.h>
98
99 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
100
101 #ifdef _DEBUG
102 #include <QDebug>
103 #endif
104
105 /*!Create and return new instance of XGUI_Module*/
106 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
107 {
108   return new PartSet_Module(theWshop);
109 }
110
111 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
112 : ModuleBase_IModule(theWshop),
113   myVisualLayerId(0)
114 {
115   new PartSet_IconFactory();
116
117   mySketchMgr = new PartSet_SketcherMgr(this);
118   mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
119
120   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
121   XGUI_Workshop* aWorkshop = aConnector->workshop();
122
123   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
124   connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
125           this, SLOT(onOperationActivatedByPreselection()));
126
127   ModuleBase_IViewer* aViewer = theWshop->viewer();
128   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
129           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
130   connect(aViewer, SIGNAL(viewTransformed(int)),
131           SLOT(onViewTransformed(int)));
132   connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
133           SLOT(onViewCreated(ModuleBase_IViewWindow*)));
134   myMenuMgr = new PartSet_MenuMgr(this);
135   myCustomPrs = new PartSet_CustomPrs(theWshop);
136
137   Events_Loop* aLoop = Events_Loop::loop();
138   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
139
140   mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
141   mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
142
143   myHasConstraintShown[PartSet_Tools::Geometrical] = true;
144   myHasConstraintShown[PartSet_Tools::Dimensional] = true;
145
146   Config_PropManager::registerProp("Visualization", "operation_parameter_color",
147                           "Reference shape wireframe color in operation", Config_Prop::Color,
148                           PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
149   Config_PropManager::registerProp("Visualization", "operation_result_color",
150                           "Result shape wireframe color in operation", Config_Prop::Color,
151                           PartSet_CustomPrs::OPERATION_RESULT_COLOR());
152   Config_PropManager::registerProp("Visualization", "operation_highlight_color",
153                           "Multi selector item color in operation", Config_Prop::Color,
154                           PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
155 }
156
157 PartSet_Module::~PartSet_Module()
158 {
159   SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
160   for (; aIt.More(); aIt.Next()) {
161     Handle(SelectMgr_Filter) aFilter = aIt.Value();
162     if (!aFilter.IsNull())
163       aFilter.Nullify();
164   }
165   delete myCustomPrs;
166 }
167
168 void PartSet_Module::activateSelectionFilters()
169 {
170   SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
171   for (; aIt.More(); aIt.Next()) {
172     Handle(SelectMgr_Filter) aFilter = aIt.Value();
173     if (!aFilter.IsNull())
174       myWorkshop->viewer()->addSelectionFilter(aFilter);
175   }
176 }
177
178 void PartSet_Module::deactivateSelectionFilters()
179 {
180   SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
181   for (; aIt.More(); aIt.Next()) {
182     Handle(SelectMgr_Filter) aFilter = aIt.Value();
183     if (!aFilter.IsNull())
184       myWorkshop->viewer()->removeSelectionFilter(aFilter);
185   }
186 }
187
188 void PartSet_Module::registerValidators()
189 {
190   //Registering of validators
191   SessionPtr aMgr = ModelAPI_Session::get();
192   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
193   aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
194   aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
195   aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
196   aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
197   aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
198   aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
199   aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
200   aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
201   aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
202   aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
203   aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
204   aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
205   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
206   aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
207   aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator);
208 }
209
210 void PartSet_Module::registerFilters()
211 {
212   //Registering of selection filters
213   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
214   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
215 }
216
217 void PartSet_Module::registerProperties()
218 {
219   Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
220                                    PLANE_SIZE);
221   Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
222                                    Config_Prop::Integer, SKETCH_WIDTH);
223   Config_PropManager::registerProp("Sketch planes", "rotate_to_plane", "Rotate to plane when selected",
224     Config_Prop::Boolean, "false");
225 }
226
227 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
228 {
229   mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
230 }
231
232 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation) 
233 {
234   if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
235     mySketchMgr->commitNestedSketch(theOperation);
236   }
237
238   /// Restart sketcher operations automatically
239   if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
240
241     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
242     if (aFOperation && !aFOperation->isEditOperation()) {
243       // the selection is cleared after commit the create operation
244       // in order to do not use the same selected objects in the restarted operation
245       // for common behaviour, the selection is cleared even if the operation is not restarted
246       XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
247       XGUI_Workshop* aWorkshop = aConnector->workshop();
248       aWorkshop->selector()->clearSelection();
249     }
250   }
251 }
252
253 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
254 {
255   /// Restart sketcher operations automatically
256   mySketchReentrantMgr->operationAborted(theOperation);
257 }
258
259 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
260 {
261   /// Restart sketcher operations automatically
262   mySketchReentrantMgr->operationStarted(theOperation);
263
264   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
265     mySketchMgr->startSketch(theOperation);
266   }
267   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
268     mySketchMgr->startNestedSketch(theOperation);
269   }
270
271   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
272   if (aFOperation) {
273     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
274     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
275   }
276 }
277
278 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
279 {
280   ModuleBase_IModule::operationResumed(theOperation);
281
282   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
283   if (aFOperation) {
284     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
285     myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
286   }
287 }
288
289 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
290 {
291   bool isModified = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false) ||
292                     myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
293
294   if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
295     mySketchMgr->stopNestedSketch(theOperation);
296   }
297
298   //VSV: Viewer is updated on feature update and redisplay
299   if (isModified) {
300     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
301     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
302     aDisplayer->updateViewer();
303   }
304
305   QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator anIt = myHasConstraintShown.begin(),
306                                                                     aLast = myHasConstraintShown.end();
307   for (; anIt != aLast; anIt++) {
308     myHasConstraintShown[anIt.key()];
309     mySketchMgr->onShowConstraintsToggle(anIt.value(), myHasConstraintShown[anIt.key()]);
310   }
311 }
312
313 ModuleBase_Operation* PartSet_Module::currentOperation() const
314 {
315   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
316   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
317   return anOpMgr->currentOperation();
318 }
319
320 bool PartSet_Module::canUndo() const
321 {
322   bool aCanUndo = false;
323   SessionPtr aMgr = ModelAPI_Session::get();
324   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
325     aCanUndo = !aMgr->isOperation();
326     if (!aCanUndo) // check the enable state additionally by sketch manager
327       aCanUndo = aMgr->canUndo();
328   }
329   return aCanUndo;
330 }
331
332 bool PartSet_Module::canRedo() const
333 {
334   bool aCanRedo = false;
335   SessionPtr aMgr = ModelAPI_Session::get();
336   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
337     aCanRedo = !aMgr->isOperation();
338     if (!aCanRedo) // check the enable state additionally by sketch manager
339       aCanRedo = aMgr->canRedo();
340   }
341   return aCanRedo;
342 }
343
344 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
345 {
346   bool aValid = true;
347   if (theActionId == "MOVE_CMD") {
348     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
349     if (aFeature) {
350       // part features can not be moved in the history.
351       if (aFeature->getKind() == PartSetPlugin_Part::ID())
352         aValid = false;
353     }
354   }
355   return aValid;
356 }
357
358 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
359 {
360   // the sketch manager put the restriction to the objects erase
361   return mySketchMgr->canEraseObject(theObject);
362 }
363
364 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
365 {
366   // the sketch manager put the restriction to the objects display
367   return mySketchMgr->canDisplayObject(theObject);
368 }
369
370 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
371 {
372   bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
373
374   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
375   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
376        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
377   if (isSketchOp || isNestedOp) {
378     // in active sketch operation it is possible to activate operation object in selection
379     // in the edit operation, e.g. points of the line can be moved when the line is edited
380     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
381     aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
382   }
383   return aCanActivate;
384 }
385
386 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
387 {
388   return myMenuMgr->addViewerMenu(theMenu, theStdActions);
389 }
390
391 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
392 {
393   myMenuMgr->updateViewerMenu(theStdActions);
394 }
395
396 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
397 {
398   QString anError = ModuleBase_IModule::getFeatureError(theFeature);
399   if (anError.isEmpty())
400     anError = sketchMgr()->getFeatureError(theFeature);
401
402   return anError;
403 }
404
405 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
406                                          QStringList& theIds) const
407 {
408   myMenuMgr->grantedOperationIds(theOperation, theIds);
409
410   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
411     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
412     XGUI_Workshop* aWorkshop = aConnector->workshop();
413
414     theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
415   }
416 }
417
418 void PartSet_Module::activeSelectionModes(QIntList& theModes)
419 {
420   theModes.clear();
421   if (mySketchMgr->activeSketch().get())
422     PartSet_SketcherMgr::sketchSelectionModes(theModes);
423 }
424
425 bool PartSet_Module::isMouseOverWindow()
426 {
427   return mySketchMgr->isMouseOverWindow();
428 }
429
430 void PartSet_Module::closeDocument()
431 {
432   clearViewer();
433 }
434
435 void PartSet_Module::clearViewer()
436 {
437   myCustomPrs->clearPrs();
438
439   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
440   XGUI_Workshop* aWorkshop = aConnector->workshop();
441   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
442   aDisplayer->deactivateSelectionFilters();
443 }
444
445 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
446 {
447   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
448   if (!aFOperation)
449     return;
450
451   ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
452   // we have to manually activate the sketch label in edit mode
453   if (PartSet_SketcherMgr::isSketchOperation(aFOperation) &&  (aFOperation->isEditOperation()))
454     aPanel->activateWidget(aPanel->modelWidgets().first());
455 }
456
457
458 void PartSet_Module::onSelectionChanged()
459 {
460   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
461   if (!aOperation)
462     return;
463
464   bool isSketcherOp = false;
465   // An edit operation is enable only if the current opeation is the sketch operation
466   if (mySketchMgr->activeSketch()) {
467     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
468       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
469   }
470   if (isSketcherOp) {
471     // Editing of constraints can be done on selection
472     ModuleBase_ISelection* aSelect = myWorkshop->selection();
473     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
474     if (aSelected.size() == 1) {
475       ModuleBase_ViewerPrs aPrs = aSelected.first();
476       ObjectPtr aObject = aPrs.object();
477       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
478       if (aFeature) {
479         std::string aId = aFeature->getKind();
480         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
481             (aId == SketchPlugin_ConstraintLength::ID()) || 
482             (aId == SketchPlugin_ConstraintDistance::ID()) ||
483             (aId == SketchPlugin_ConstraintAngle::ID())) {
484           editFeature(aFeature);
485         }
486       }
487     }
488   } 
489 }
490
491 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
492 {
493   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
494   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
495   anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
496 }
497
498 void PartSet_Module::onOperationActivatedByPreselection()
499 {
500   if (!mySketchReentrantMgr->canBeCommittedByPreselection())
501     return;
502   mySketchMgr->operationActivatedByPreselection();
503 }
504
505 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
506                                             Config_WidgetAPI* theWidgetApi, std::string theParentId)
507 {
508   ModuleBase_IWorkshop* aWorkshop = workshop();
509   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
510   XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
511   ModuleBase_ModelWidget* aWgt = NULL;
512   if (theType == "sketch-start-label") {
513     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
514       theWidgetApi, theParentId, mySketchMgr->showConstraintStates());
515     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
516       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
517     connect(aLabelWgt, SIGNAL(showConstraintToggled(bool, int)),
518       mySketchMgr, SLOT(onShowConstraintsToggle(bool, int)));
519     aWgt = aLabelWgt;
520   } else if (theType == "sketch-2dpoint_selector") {
521     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
522                                                                  theWidgetApi, theParentId);
523     aPointWgt->setSketch(mySketchMgr->activeSketch());
524     connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
525     aWgt = aPointWgt;
526   }else if (theType == "sketch-2dpoint_flyout_selector") {
527     PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
528                                                                  theWidgetApi, theParentId);
529     aPointWgt->setSketch(mySketchMgr->activeSketch());
530     connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
531     aWgt = aPointWgt;
532   } else if (theType == "point2ddistance") {
533     PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
534                                                         aWorkshop, theWidgetApi, theParentId);
535     aDistanceWgt->setSketch(mySketchMgr->activeSketch());
536     aWgt = aDistanceWgt;
537   } else if (theType == "sketch_shape_selector") {
538     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
539       new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
540     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
541     aWgt = aShapeSelectorWgt;
542   } else if (theType == "sketch_multi_selector") {
543     PartSet_WidgetMultiSelector* aShapeSelectorWgt =
544       new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
545     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
546     aWgt = aShapeSelectorWgt;
547   } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
548     aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
549   } else if (theType == "export_file_selector") {
550     aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
551   } else if (theType == "sketch_launcher") {
552     aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
553   } else if (theType == "module_choice") {
554     aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi, theParentId);
555     connect(aWgt, SIGNAL(itemSelected(int)), SLOT(onBooleanOperationChange(int)));
556   }
557   return aWgt;
558 }
559
560 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
561 {
562   ModuleBase_ModelWidget* anActiveWidget = 0;
563
564   anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
565   if (!anActiveWidget) {
566     ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
567     if (aOperation) {
568       ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
569       anActiveWidget = aPanel->activeWidget();
570     }
571   }
572   return anActiveWidget;
573 }
574
575 bool PartSet_Module::deleteObjects()
576 {
577   bool isProcessed = false;
578
579   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
580   XGUI_Workshop* aWorkshop = aConnector->workshop();
581   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
582
583   //SessionPtr aMgr = ModelAPI_Session::get();
584   // 1. check whether the delete should be processed in the module
585   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
586   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
587        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
588   if (isSketchOp || isNestedOp) {
589     isProcessed = true;
590     // 2. find selected presentations
591     // selected objects should be collected before the current operation abort because
592     // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
593     ModuleBase_ISelection* aSel = workshop()->selection();
594     QObjectPtrList aSelectedObj = aSel->selectedPresentations();
595     // if there are no selected objects in the viewer, that means that the selection in another
596     // place cased this method. It is necessary to return the false value to understande in above
597     // method that delete is not processed
598     if (aSelectedObj.count() == 0)
599       return false;
600
601     // avoid delete of the objects, which are not belong to the current sketch
602     // in order to do not delete results of other sketches
603     QObjectPtrList aSketchObjects;
604     QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
605     for ( ; anIt != aLast; anIt++) {
606       ObjectPtr anObject = *anIt;
607       if (mySketchMgr->isObjectOfSketch(anObject)) {
608         // sketch feature should be used in this list because workshop deletes features only
609         // results are skipped
610         FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
611         aSketchObjects.append(aSketchFeature);
612       }
613     }
614     // if the selection contains only local selected presentations from other sketches,
615     // the Delete operation should not be done at all
616     if (aSketchObjects.size() == 0)
617       return true;
618
619     // 3. start operation
620     QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
621     ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
622
623     // the active nested sketch operation should be aborted unconditionally
624     // the Delete action should be additionally granted for the Sketch operation
625     // in order to do not abort/commit it
626     if (!anOpMgr->canStartOperation(anOpAction->id()))
627       return true; // the objects are processed but can not be deleted
628
629     anOpMgr->startOperation(anOpAction);
630
631     // 4. delete features
632     // sketch feature should be skipped, only sub-features can be removed
633     // when sketch operation is active
634     aWorkshop->deleteFeatures(aSketchObjects);
635     // 5. stop operation
636     anOpMgr->commitOperation();
637   }
638   return isProcessed;
639 }
640
641 void PartSet_Module::onFeatureTriggered()
642 {
643   QAction* aCmd = dynamic_cast<QAction*>(sender());
644   if (aCmd->isCheckable() && aCmd->isChecked()) {
645     // 1. check whether the delete should be processed in the module
646     ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
647     bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
648     if (isNestedOp) {
649       // in case if in the viewer nothing is displayed, the create operation should not be
650       // comitted even if all values of the feature are initialized
651       if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
652         // the action information should be saved before the operation is aborted
653         // because this abort leads to update command status, which unchecks this action
654         anOperation->abort();
655         launchOperation(aCmd->data().toString());
656       }
657     }
658   }
659   ModuleBase_IModule::onFeatureTriggered();
660 }
661
662 void PartSet_Module::launchOperation(const QString& theCmdId)
663 {
664   if (myWorkshop->currentOperation() && 
665       myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
666       const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates = mySketchMgr->showConstraintStates();
667       myHasConstraintShown = aShownStates;
668   }
669   if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
670     // Show constraints if a constraint was anOperation
671     mySketchMgr->onShowConstraintsToggle(true, PartSet_Tools::Geometrical);
672     mySketchMgr->onShowConstraintsToggle(true, PartSet_Tools::Dimensional);
673   }
674   ModuleBase_IModule::launchOperation(theCmdId);
675 }
676
677
678 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) 
679 {
680   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
681   if (!anAIS.IsNull()) {
682     Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
683     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
684     if (!aDim.IsNull()) {
685       aCtx->SetZLayer(aDim, myVisualLayerId);
686     } else {
687       Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
688       if (!aCons.IsNull())
689         aCtx->SetZLayer(aCons, myVisualLayerId);
690     }
691   }
692 }
693
694 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
695 {
696   // this is obsolete
697   // it should be recomputed in order to disappear in the viewer if the corresponded object
698   // is erased
699   //if (myCustomPrs->isActive())
700   //  myCustomPrs->redisplay(theObject, false);
701 }
702
703 void PartSet_Module::onViewTransformed(int theTrsfType)
704 {
705   // Set length of arrows constant in pixel size
706   // if the operation is panning or rotate or panglobal then do nothing
707   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
708     return;
709   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
710   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
711   if (aContext.IsNull())
712     return;
713
714   //Handle(V3d_View) aView = aViewer->activeView();
715
716   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
717   XGUI_Workshop* aWorkshop = aConnector->workshop();
718   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
719   Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
720   Handle(V3d_View) aView;
721   double aScale = 0;
722   for (aV3dViewer->InitDefinedViews(); 
723        aV3dViewer->MoreDefinedViews(); 
724        aV3dViewer->NextDefinedViews()) {
725     Handle(V3d_View) aV = aV3dViewer->DefinedView();
726     double aS = aV->Scale();
727     if (aS > aScale) {
728       aScale = aS;
729       aView = aV;
730     }
731   }
732   if (aView.IsNull())
733     return;
734   double aLen = aView->Convert(20);
735
736   double aPrevLen = SketcherPrs_Tools::getArrowSize();
737   SketcherPrs_Tools::setArrowSize(aLen);
738   const double aPrevScale = aViewer->Scale(aViewer->activeView());
739   const double aCurScale = aViewer->activeView()->Camera()->Scale();
740   aViewer->SetScale(aViewer->activeView(), aCurScale);
741   SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
742   bool isModified = false;
743   QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
744   foreach (AISObjectPtr aAIS, aPrsList) {
745     Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
746
747     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
748     if (!aDim.IsNull()) {
749       aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
750       aContext->Redisplay(aDim, false);
751       isModified = true;
752     }
753   }
754   if (isModified)
755     aDisplayer->updateViewer();
756 }
757
758 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature, const ModuleBase_CustomizeFlag& theFlag,
759                                        const bool theUpdateViewer)
760 {
761   myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
762 }
763
764 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
765                                          const bool theUpdateViewer)
766 {
767   myCustomPrs->deactivate(theFlag, theUpdateViewer);
768 }
769
770 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
771                                      const bool theUpdateViewer)
772 {
773   bool isRedisplayed = false;
774   if (myCustomPrs->isActive(theFlag))
775     isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
776
777   return isRedisplayed;
778 }
779
780 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
781 {
782   XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
783   if (aOB) {
784     QLabel* aLabel = aOB->activeDocLabel();
785     aLabel->installEventFilter(myMenuMgr);
786     connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)), 
787           SLOT(onActiveDocPopup(const QPoint&)));
788     //QPalette aPalet = aLabel->palette();
789     //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
790     //aLabel->setPalette(aPalet);
791     aOB->treeView()->setExpandsOnDoubleClick(false);
792     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)), 
793       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
794   }
795 }
796
797 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
798 {
799   SessionPtr aMgr = ModelAPI_Session::get();
800   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
801
802   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
803   XGUI_Workshop* aWorkshop = aConnector->workshop();
804   QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
805
806   aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
807
808   QMenu aMenu;
809   aMenu.addAction(aActivatePartAction);
810   aMenu.exec(aHeader->mapToGlobal(thePnt));
811 }
812
813
814 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
815 {
816   ObjectPtr anObject;
817   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
818   if (aOperation) {
819     /// If last line finished on vertex the lines creation sequence has to be break
820     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
821     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
822     // if there is an active widget, find the presented object in it
823     if (!anActiveWidget)
824       anActiveWidget = aPanel->preselectionWidget();
825     
826     ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
827                                                                            (anActiveWidget);
828     if (aWidgetValidated)
829       anObject = aWidgetValidated->findPresentedObject(theAIS);
830   }
831   return anObject;
832 }
833
834 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
835 {
836   QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
837   int aSelected = aObjects.size();
838   SessionPtr aMgr = ModelAPI_Session::get();
839   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
840
841   ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
842   if (aSelected == 1) {
843     bool hasResult = false;
844     bool hasFeature = false;
845     bool hasParameter = false;
846     bool hasSubFeature = false;
847     ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
848
849     ObjectPtr aObject = aObjects.first();
850     if (aObject) {
851       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
852       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
853       bool isPart = aPart.get() || 
854         (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
855       if (isPart) {
856         DocumentPtr aPartDoc;
857         if (!aPart.get()) {
858           aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
859         }
860         if (aPart.get()) // this may be null is Part feature is disabled
861           aPartDoc = aPart->partDoc();
862           
863         theMenu->addAction(aActivatePartAction);
864         aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
865
866       } else if (aObject->document() == aMgr->activeDocument()) {
867         if (hasParameter || hasFeature) {
868           myMenuMgr->action("EDIT_CMD")->setEnabled(true);
869           theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
870           if (aCurrentOp && aFeature.get()) {
871             if (aCurrentOp->id().toStdString() == aFeature->getKind())
872               myMenuMgr->action("EDIT_CMD")->setEnabled(false);
873           }
874         }
875       }
876
877       ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
878       if( aResult.get() )
879         theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
880     }
881   }
882   bool aNotDeactivate = (aCurrentOp == 0);
883   if (!aNotDeactivate) {
884     aActivatePartAction->setEnabled(false);
885   }
886 }
887
888 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
889 {
890   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
891     // Do not change activation of parts if an operation active
892     static QStringList aAllowActivationList;
893     if (aAllowActivationList.isEmpty())
894       aAllowActivationList << 
895       QString(PartSetPlugin_Part::ID().c_str()) << 
896       QString(PartSetPlugin_Duplicate::ID().c_str()) <<
897       QString(PartSetPlugin_Remove::ID().c_str());
898     if (myWorkshop->currentOperation() && 
899       (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
900       return;
901     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
902     XGUI_Workshop* aWorkshop = aConnector->workshop();
903     XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
904     QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
905     QPalette aPalet = aLabel->palette();
906
907     SessionPtr aMgr = ModelAPI_Session::get();
908     DocumentPtr aActiveDoc = aMgr->activeDocument();
909     if (aActivePartIndex.isValid())
910       aTreeView->setExpanded(aActivePartIndex, false);
911     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
912     aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
913     if (aActivePartIndex.isValid())
914       aTreeView->setExpanded(aActivePartIndex, true);
915
916     aLabel->setPalette(aPalet);
917     aWorkshop->updateCommandStatus();
918
919     // Update displayed objects in order to update active color
920     XGUI_Displayer* aDisplayer = aWorkshop->displayer();
921     QObjectPtrList aObjects = aDisplayer->displayedObjects();
922     bool aHidden;
923     foreach(ObjectPtr aObj, aObjects) {
924       //TODO: replace by redisplay event.
925       aHidden = !aObj->data() || !aObj->data()->isValid() || 
926         aObj->isDisabled() || (!aObj->isDisplayed());
927       if (!aHidden)
928         aDisplayer->redisplay(aObj, false);
929     }
930     aDisplayer->updateViewer();
931   }
932 }
933
934 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
935 {
936   if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
937     return;
938   SessionPtr aMgr = ModelAPI_Session::get();
939   if (!theIndex.isValid()) {
940     aMgr->setActiveDocument(aMgr->moduleDocument());
941     return;
942   }
943   if (theIndex.column() != 0) // Use only first column
944     return;
945
946   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
947   XGUI_Workshop* aWorkshop = aConnector->workshop();
948   XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
949   // De not use non editable Indexes
950   if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
951     return;
952   ObjectPtr aObj = aDataModel->object(theIndex);
953
954   ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
955   if (!aPart.get()) { // Probably this is Feature
956     FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
957     if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
958       aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
959     }
960   }
961   if (aPart.get()) { // if this is a part
962     if (aPart->partDoc() == aMgr->activeDocument()) {
963       myMenuMgr->activatePartSet();
964     } else {
965       aPart->activate();
966     }
967   }
968 }
969
970
971 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
972 {
973   // z layer is created for all started operations in order to visualize operation AIS presentation
974   // over the object
975   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
976   if (aContext.IsNull())
977     return;
978
979   Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
980   if (myVisualLayerId == 0) {
981     if (myVisualLayerId == 0)
982       aViewer->AddZLayer(myVisualLayerId);
983   } else {
984     TColStd_SequenceOfInteger aZList;
985     aViewer->GetAllZLayers(aZList);
986     bool aFound = false;
987     for (int i = 1; i <= aZList.Length(); i++) {
988       if (aZList(i) == myVisualLayerId) {
989         aFound = true;
990         break;
991       }
992     }
993     if (!aFound)
994       aViewer->AddZLayer(myVisualLayerId);
995   }
996   // if there is an active operation with validated widget,
997   // the filters of this widget should be activated in the created view
998   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
999   if (aOperation) {
1000     ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1001     if (anActiveWidget) {
1002       ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1003       if (aWSelector)
1004         aWSelector->activateSelectionAndFilters(true);
1005     }
1006   }
1007 }
1008
1009 //******************************************************
1010 void PartSet_Module::widgetStateChanged(int thePreviousState)
1011 {
1012   mySketchMgr->widgetStateChanged(thePreviousState);
1013 }
1014
1015 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1016 {
1017   return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1018 }
1019
1020 //******************************************************
1021 void PartSet_Module::beforeOperationStarted(ModuleBase_Operation* theOperation)
1022 {
1023 }
1024
1025 //******************************************************
1026 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1027 {
1028   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1029     mySketchMgr->stopSketch(theOperation);
1030   }
1031 }
1032
1033 //******************************************************
1034 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1035 {
1036   GeomShapePtr aGeomShape;
1037
1038   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1039   if (anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1040     aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1041   }
1042   return aGeomShape;
1043 }
1044
1045 //******************************************************
1046 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1047                                            const GeomShapePtr& theGeomShape)
1048 {
1049   AttributePtr anAttribute;
1050   GeomShapePtr aGeomShape = theGeomShape;
1051   if (!aGeomShape.get()) {
1052     // processing shape of result, e.g. sketch circle center is selected, this is a result
1053     // the geom shape is empty, the shape of result should be used
1054     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1055     if (aResult.get()) {
1056       aGeomShape = aResult->shape();
1057     }
1058   }
1059
1060   if (aGeomShape.get()) {
1061     TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1062     return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, 
1063                                                  mySketchMgr->activeSketch());
1064   }
1065   return anAttribute;
1066 }
1067
1068 //******************************************************
1069 void PartSet_Module::onBooleanOperationChange(int theOperation)
1070 {
1071   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1072   if (!aOperation)
1073     return;
1074   ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1075   switch (theOperation) {
1076   case 0:
1077     aPanel->setWindowTitle(tr("Cut"));
1078     break;
1079   case 1:
1080     aPanel->setWindowTitle(tr("Fuse"));
1081     break;
1082   case 2:
1083     aPanel->setWindowTitle(tr("Common"));
1084     break;
1085   }
1086 }