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