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