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