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