Salome HOME
74ca6f83495d41cce0ccaf64dd61471098ffa358
[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_WidgetPoint2dAngle.h>
10 #include <PartSet_WidgetShapeSelector.h>
11 #include <PartSet_WidgetMultiSelector.h>
12 #include <PartSet_WidgetEditor.h>
13 #include "PartSet_SketcherMgr.h"
14 #include "PartSet_MenuMgr.h"
15
16 #include <ModuleBase_Operation.h>
17 #include <ModuleBase_IViewer.h>
18 #include <ModuleBase_IViewWindow.h>
19 #include <ModuleBase_IPropertyPanel.h>
20 #include <ModuleBase_WidgetEditor.h>
21 #include <ModuleBase_FilterFactory.h>
22 #include <GeomValidators_ShapeType.h>
23 #include <GeomValidators_Face.h>
24 #include <GeomValidators_ConstructionComposite.h>
25
26
27 #include <ModelAPI_Object.h>
28 #include <ModelAPI_Events.h>
29 #include <ModelAPI_Validator.h>
30 #include <ModelAPI_Data.h>
31 #include <ModelAPI_Session.h>
32 #include <ModelAPI_ShapeValidator.h>
33
34 #include <GeomDataAPI_Point2D.h>
35 #include <GeomDataAPI_Point.h>
36 #include <GeomDataAPI_Dir.h>
37
38 #include <XGUI_Displayer.h>
39 #include <XGUI_Workshop.h>
40 #include <XGUI_OperationMgr.h>
41 #include <XGUI_PropertyPanel.h>
42 #include <XGUI_ModuleConnector.h>
43 #include <XGUI_ContextMenuMgr.h>
44 #include <XGUI_Tools.h>
45
46 #include <SketchPlugin_Feature.h>
47 #include <SketchPlugin_Sketch.h>
48 #include <SketchPlugin_Line.h>
49 #include <SketchPlugin_Arc.h>
50 #include <SketchPlugin_Circle.h>
51 #include <SketchPlugin_Point.h>
52 #include <SketchPlugin_ConstraintLength.h>
53 #include <SketchPlugin_ConstraintDistance.h>
54 #include <SketchPlugin_ConstraintParallel.h>
55 #include <SketchPlugin_ConstraintPerpendicular.h>
56 #include <SketchPlugin_ConstraintRadius.h>
57
58 #include <SketcherPrs_SymbolPrs.h>
59 #include <SketcherPrs_Tools.h>
60
61 #include <Events_Loop.h>
62 #include <Config_PropManager.h>
63 #include <Config_Keywords.h>
64
65 #include <StdSelect_TypeOfFace.hxx>
66 #include <TopoDS_Vertex.hxx>
67 #include <TopoDS.hxx>
68 #include <TopoDS_Shape.hxx>
69 #include <BRep_Tool.hxx>
70 #include <AIS_Dimension.hxx>
71
72 #include <QObject>
73 #include <QMouseEvent>
74 #include <QString>
75 #include <QTimer>
76 #include <QApplication>
77 #include <QMessageBox>
78 #include <QMainWindow>
79
80 #include <GeomAlgoAPI_FaceBuilder.h>
81 #include <GeomDataAPI_Dir.h>
82
83 #ifdef _DEBUG
84 #include <QDebug>
85 #endif
86
87 /*!Create and return new instance of XGUI_Module*/
88 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
89 {
90   return new PartSet_Module(theWshop);
91 }
92
93 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
94   : ModuleBase_IModule(theWshop), 
95   myRestartingMode(RM_None), myVisualLayerId(0)
96 {
97   mySketchMgr = new PartSet_SketcherMgr(this);
98
99   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
100   XGUI_Workshop* aWorkshop = aConnector->workshop();
101
102   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
103   connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
104   connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
105           this, SLOT(onOperationActivatedByPreselection()));
106
107   ModuleBase_IViewer* aViewer = theWshop->viewer();
108   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
109           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
110   connect(aViewer, SIGNAL(viewTransformed(int)),
111           SLOT(onViewTransformed(int)));
112
113   myMenuMgr = new PartSet_MenuMgr(this);
114 }
115
116 PartSet_Module::~PartSet_Module()
117 {
118   if (!myDocumentShapeFilter.IsNull())
119     myDocumentShapeFilter.Nullify();
120 }
121
122 void PartSet_Module::registerValidators()
123 {
124   //Registering of validators
125   SessionPtr aMgr = ModelAPI_Session::get();
126   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
127   aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
128   aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
129   aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
130   aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
131   aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
132   aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
133   aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
134   aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
135   aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
136   aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
137
138   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
139   aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
140
141   aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
142   aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
143
144   aFactory->registerValidator("GeomValidators_ConstructionComposite",
145                               new GeomValidators_ConstructionComposite);
146
147   aFactory->registerValidator("PartSet_SketchEntityValidator",
148                               new PartSet_SketchEntityValidator);
149
150   aFactory->registerValidator("PartSet_SameTypeAttr",
151                               new PartSet_SameTypeAttrValidator);
152 }
153
154 void PartSet_Module::registerFilters()
155 {
156   //Registering of selection filters
157   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
158   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
159 }
160
161 void PartSet_Module::registerProperties()
162 {
163   Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
164                                    PLANE_SIZE);
165   Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
166                                    Config_Prop::Integer, SKETCH_WIDTH);
167 }
168
169 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation) 
170 {
171   if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
172     mySketchMgr->commitNestedSketch(theOperation);
173   }
174
175   if (theOperation->isEditOperation())
176     return;
177   // the selection is cleared after commit the create operation
178   // in order to do not use the same selected objects in the restarted operation
179   // for common behaviour, the selection is cleared even if the operation is not restarted
180   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
181   if (!aContext.IsNull())
182     aContext->ClearSelected();
183
184   /// Restart sketcher operations automatically
185   FeaturePtr aFeature = theOperation->feature();
186   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
187             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
188   if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
189                      myRestartingMode == RM_EmptyFeatureUsed)) {
190     myLastOperationId = theOperation->id();
191     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
192     
193     launchOperation(myLastOperationId);
194   }
195   breakOperationSequence();
196 }
197
198 void PartSet_Module::breakOperationSequence()
199 {
200   myLastOperationId = "";
201   myLastFeature = FeaturePtr();
202   myRestartingMode = RM_None;
203 }
204
205 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
206 {
207   breakOperationSequence();
208 }
209
210 void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
211 {
212   // Install the document filter before any other filter
213   if (myDocumentShapeFilter.IsNull())
214     myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
215   myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
216
217   ModuleBase_IModule::sendOperation(theOperation);
218 }
219
220 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
221 {
222   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
223     Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
224     aViewer->AddZLayer(myVisualLayerId);
225     mySketchMgr->startSketch(theOperation);
226   }
227   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
228     mySketchMgr->startNestedSketch(theOperation);
229   }
230 }
231
232 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
233 {
234   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
235     mySketchMgr->stopSketch(theOperation);
236     Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
237     aViewer->RemoveZLayer(myVisualLayerId);
238     myVisualLayerId = 0;
239   }
240   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
241     mySketchMgr->stopNestedSketch(theOperation);
242   }
243   myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
244 }
245
246 ModuleBase_Operation* PartSet_Module::currentOperation() const
247 {
248   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
249   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
250   return anOpMgr->currentOperation();
251 }
252
253 bool PartSet_Module::canUndo() const
254 {
255   bool aCanUndo = false;
256   SessionPtr aMgr = ModelAPI_Session::get();
257   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
258     aCanUndo = !aMgr->isOperation();
259     if (!aCanUndo) // check the enable state additionally by sketch manager
260       aCanUndo = aMgr->canUndo();
261   }
262   return aCanUndo;
263 }
264
265 bool PartSet_Module::canRedo() const
266 {
267   bool aCanRedo = false;
268   SessionPtr aMgr = ModelAPI_Session::get();
269   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
270     aCanRedo = !aMgr->isOperation();
271     if (!aCanRedo) // check the enable state additionally by sketch manager
272       aCanRedo = aMgr->canRedo();
273   }
274   return aCanRedo;
275 }
276
277 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
278 {
279   // the sketch manager put the restriction to the objects display
280   return mySketchMgr->canDisplayObject(theObject);
281 }
282
283
284 bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
285 {
286   return myMenuMgr->addViewerItems(theMenu, theStdActions);
287 }
288
289 void PartSet_Module::activeSelectionModes(QIntList& theModes)
290 {
291   theModes.clear();
292   if (mySketchMgr->activeSketch().get())
293     PartSet_SketcherMgr::sketchSelectionModes(theModes);
294 }
295
296 bool PartSet_Module::isMouseOverWindow()
297 {
298   return mySketchMgr->isMouseOverWindow();
299 }
300
301 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
302 {
303   ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
304   if (PartSet_SketcherMgr::isSketchOperation(theOperation) &&  (theOperation->isEditOperation())) {
305     // we have to manually activate the sketch label in edit mode
306       aPanel->activateWidget(aPanel->modelWidgets().first());
307       return;
308   }
309
310   // Restart last operation type 
311   if ((theOperation->id() == myLastOperationId) && myLastFeature) {
312     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
313     if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
314       // Initialise new line with first point equal to end of previous
315       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
316       if (aPnt2dWgt) {
317         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
318         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
319           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
320         if (aPoint) {
321           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
322           PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(), 
323             aWgt->attributeID(), aPoint->x(), aPoint->y());
324           aPanel->activateNextWidget(aPnt2dWgt);
325         }
326       }
327     }
328   } else {
329     // Start editing constraint
330     if (theOperation->isEditOperation()) {
331       // TODO: #391 - to be removed
332       std::string aId = theOperation->id().toStdString();
333       if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
334           PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
335         // Find and activate widget for management of point for dimension line position
336         QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
337         foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
338           PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
339           if (aPntWgt) {
340             aPanel->activateWidget(aPntWgt);
341             return;
342           }
343         }
344       }
345     }
346   }
347 }
348
349
350 void PartSet_Module::onSelectionChanged()
351 {
352   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
353   if (!aOperation)
354     return;
355
356   bool isSketcherOp = false;
357   // An edit operation is enable only if the current opeation is the sketch operation
358   if (mySketchMgr->activeSketch()) {
359     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
360       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
361   }
362   if (isSketcherOp) {
363     // Editing of constraints can be done on selection
364     ModuleBase_ISelection* aSelect = myWorkshop->selection();
365     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
366     if (aSelected.size() == 1) {
367       ModuleBase_ViewerPrs aPrs = aSelected.first();
368       ObjectPtr aObject = aPrs.object();
369       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
370       if (aFeature) {
371         std::string aId = aFeature->getKind();
372         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
373             (aId == SketchPlugin_ConstraintLength::ID()) || 
374             (aId == SketchPlugin_ConstraintDistance::ID())) {
375           editFeature(aFeature);
376         }
377       }
378     }
379   } 
380 }
381
382 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
383 {
384   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
385   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
386   anOpMgr->onKeyReleased(theEvent);
387 }
388
389 void PartSet_Module::onEnterReleased()
390 {
391   myRestartingMode = RM_EmptyFeatureUsed;
392 }
393
394 void PartSet_Module::onOperationActivatedByPreselection()
395 {
396   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
397   if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
398     // Set final definitions if they are necessary
399     //propertyPanelDefined(aOperation);
400
401     /// Commit sketcher operations automatically
402     anOperation->commit();
403   }
404 }
405
406 void PartSet_Module::onNoMoreWidgets()
407 {
408   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
409   if (anOperation) {
410     if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
411       if (myRestartingMode != RM_Forbided)
412         myRestartingMode = RM_LastFeatureUsed;
413       anOperation->commit();
414     }
415   }
416 }
417
418 void PartSet_Module::onVertexSelected()
419 {
420   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
421   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
422     /// If last line finished on vertex the lines creation sequence has to be break
423     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
424     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
425     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
426     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
427     bool aFoundWidget = false;
428     bool aFoundObligatory = false;
429     for (; anIt != aLast && !aFoundObligatory; anIt++) {
430       if (!aFoundWidget)
431         aFoundWidget = *anIt == anActiveWidget;
432       else
433         aFoundObligatory = (*anIt)->isObligatory();
434     }
435     if (!aFoundObligatory)
436       myRestartingMode = RM_Forbided;
437   }
438 }
439
440 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
441                                             Config_WidgetAPI* theWidgetApi, std::string theParentId)
442 {
443   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
444   XGUI_Workshop* aWorkshop = aConnector->workshop();
445   ModuleBase_ModelWidget* aWgt = NULL;
446   if (theType == "sketch-start-label") {
447     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, 
448       theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
449     aLabelWgt->setWorkshop(aWorkshop);
450     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
451       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
452     connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
453       mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
454     aWgt = aLabelWgt;
455   } else if (theType == "sketch-2dpoint_selector") {
456     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
457     aPointWgt->setWorkshop(aWorkshop);
458     aPointWgt->setSketch(mySketchMgr->activeSketch());
459     connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
460     aWgt = aPointWgt;
461   } if (theType == "point2ddistance") {
462     PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
463     aDistanceWgt->setWorkshop(aWorkshop);
464     aDistanceWgt->setSketch(mySketchMgr->activeSketch());
465     aWgt = aDistanceWgt;
466   } if(theType == "point2dangle") {
467     PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent, theWidgetApi, theParentId);
468     anAngleWgt->setWorkshop(aWorkshop);
469     anAngleWgt->setSketch(mySketchMgr->activeSketch());
470     aWgt = anAngleWgt;
471   }
472   if (theType == "sketch_shape_selector") {
473     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
474       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
475     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
476     aWgt = aShapeSelectorWgt;
477   } if (theType == "sketch_multi_selector") {
478     PartSet_WidgetMultiSelector* aShapeSelectorWgt =
479       new PartSet_WidgetMultiSelector(theParent, workshop(), theWidgetApi, theParentId);
480     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
481     aWgt = aShapeSelectorWgt;
482   }
483   if (theType == WDG_DOUBLEVALUE_EDITOR) {
484     aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
485   } 
486   return aWgt;
487 }
488
489
490 bool PartSet_Module::deleteObjects()
491 {
492   // 1. check whether the delete should be processed in the module
493   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
494   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
495        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
496   if (!isSketchOp && !isNestedOp)
497     return false;
498
499   // 2. find selected presentations
500   // selected objects should be collected before the current operation abort because
501   // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
502   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
503   XGUI_Workshop* aWorkshop = aConnector->workshop();
504   ModuleBase_ISelection* aSel = workshop()->selection();
505   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
506   // if there are no selected objects in the viewer, that means that the selection in another
507   // place cased this method. It is necessary to return the false value to understande in above
508   // method that delete is not processed
509   if (aSelectedObj.count() == 0)
510     return false;
511
512   // avoid delete of the objects, which are not belong to the current sketch
513   // in order to do not delete results of other sketches
514   QObjectPtrList aSketchObjects;
515   QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
516   for ( ; anIt != aLast; anIt++) {
517     ObjectPtr anObject = *anIt;
518     if (mySketchMgr->isObjectOfSketch(anObject))
519       aSketchObjects.append(anObject);
520   }
521   // if the selection contains only local selected presentations from other sketches,
522   // the Delete operation should not be done at all
523   if (aSketchObjects.size() == 0)
524     return true;
525
526   // the active nested sketch operation should be aborted unconditionally
527   if (isNestedOp)
528     anOperation->abort();
529
530   // 3. start operation
531   QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
532   SessionPtr aMgr = ModelAPI_Session::get();
533   aMgr->startOperation(aDescription.toStdString());
534
535   // 4. delete features
536   // sketch feature should be skipped, only sub-features can be removed
537   // when sketch operation is active
538   std::set<FeaturePtr> anIgnoredFeatures;
539   anIgnoredFeatures.insert(mySketchMgr->activeSketch());
540   aWorkshop->deleteFeatures(aSketchObjects, anIgnoredFeatures);
541   
542   // 5. stop operation
543   aWorkshop->displayer()->updateViewer();
544   aMgr->finishOperation();
545
546   return true;
547 }
548
549
550 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) 
551 {
552   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
553   if (!anAIS.IsNull()) {
554     Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
555     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
556     if (!aDim.IsNull()) {
557       aCtx->SetZLayer(aDim, myVisualLayerId);
558     } else {
559       Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
560       if (!aCons.IsNull())
561         aCtx->SetZLayer(aCons, myVisualLayerId);
562     }
563   }
564 }
565
566 void PartSet_Module::onViewTransformed(int theTrsfType)
567 {
568   // Set length of arrows constant in pixel size
569   // if the operation is panning or rotate or panglobal then do nothing
570   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
571     return;
572
573   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
574   //Handle(V3d_View) aView = aViewer->activeView();
575
576   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
577   XGUI_Workshop* aWorkshop = aConnector->workshop();
578   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
579   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
580
581   Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
582   Handle(V3d_View) aView;
583   double aScale = 0;
584   for (aV3dViewer->InitDefinedViews(); 
585        aV3dViewer->MoreDefinedViews(); 
586        aV3dViewer->NextDefinedViews()) {
587     Handle(V3d_View) aV = aV3dViewer->DefinedView();
588     double aS = aV->Scale();
589     if (aS > aScale) {
590       aScale = aS;
591       aView = aV;
592     }
593   }
594   if (aView.IsNull())
595     return;
596   double aLen = aView->Convert(20);
597
598   SketcherPrs_Tools::setArrowSize(aLen);
599   bool isModified = false;
600   QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
601   foreach (AISObjectPtr aAIS, aPrsList) {
602     Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
603
604     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
605     if (!aDim.IsNull()) {
606       aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
607       aContext->Redisplay(aDim, false);
608       isModified = true;
609     }
610   }
611   if (isModified)
612     aDisplayer->updateViewer();
613 }