]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
External object manager to be used in the multi selector widget
[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_Edge.h>
22 #include <GeomValidators_EdgeOrVertex.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_Edge", new GeomValidators_Edge);
142   aFactory->registerValidator("GeomValidators_EdgeOrVertex",
143                               new GeomValidators_EdgeOrVertex);
144   aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
145
146   aFactory->registerValidator("GeomValidators_ConstructionComposite",
147                               new GeomValidators_ConstructionComposite);
148
149   aFactory->registerValidator("PartSet_SketchEntityValidator",
150                               new PartSet_SketchEntityValidator);
151
152   aFactory->registerValidator("PartSet_SameTypeAttr",
153                               new PartSet_SameTypeAttrValidator);
154 }
155
156 void PartSet_Module::registerFilters()
157 {
158   //Registering of selection filters
159   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
160   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
161 }
162
163 void PartSet_Module::registerProperties()
164 {
165   Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
166                                    PLANE_SIZE);
167   Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
168                                    Config_Prop::Integer, SKETCH_WIDTH);
169 }
170
171 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation) 
172 {
173   if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
174     mySketchMgr->commitNestedSketch(theOperation);
175   }
176
177   if (theOperation->isEditOperation())
178     return;
179   // the selection is cleared after commit the create operation
180   // in order to do not use the same selected objects in the restarted operation
181   // for common behaviour, the selection is cleared even if the operation is not restarted
182   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
183   if (!aContext.IsNull())
184     aContext->ClearSelected();
185
186   /// Restart sketcher operations automatically
187   FeaturePtr aFeature = theOperation->feature();
188   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
189             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
190   if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
191                      myRestartingMode == RM_EmptyFeatureUsed)) {
192     myLastOperationId = theOperation->id();
193     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
194     
195     launchOperation(myLastOperationId);
196   }
197   breakOperationSequence();
198 }
199
200 void PartSet_Module::breakOperationSequence()
201 {
202   myLastOperationId = "";
203   myLastFeature = FeaturePtr();
204   myRestartingMode = RM_None;
205 }
206
207 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
208 {
209   breakOperationSequence();
210 }
211
212 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
213 {
214   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
215     Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
216     aViewer->AddZLayer(myVisualLayerId);
217     mySketchMgr->startSketch(theOperation);
218   }
219   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
220     mySketchMgr->startNestedSketch(theOperation);
221   }
222
223   if (myDocumentShapeFilter.IsNull())
224     myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
225   myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
226 }
227
228 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
229 {
230   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
231     mySketchMgr->stopSketch(theOperation);
232     Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
233     aViewer->RemoveZLayer(myVisualLayerId);
234     myVisualLayerId = 0;
235   }
236   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
237     mySketchMgr->stopNestedSketch(theOperation);
238   }
239   myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
240 }
241
242 ModuleBase_Operation* PartSet_Module::currentOperation() const
243 {
244   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
245   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
246   return anOpMgr->currentOperation();
247 }
248
249 bool PartSet_Module::canUndo() const
250 {
251   bool aCanUndo = false;
252   SessionPtr aMgr = ModelAPI_Session::get();
253   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
254     aCanUndo = !aMgr->isOperation();
255     if (!aCanUndo) // check the enable state additionally by sketch manager
256       aCanUndo = aMgr->canUndo();
257   }
258   return aCanUndo;
259 }
260
261 bool PartSet_Module::canRedo() const
262 {
263   bool aCanRedo = false;
264   SessionPtr aMgr = ModelAPI_Session::get();
265   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
266     aCanRedo = !aMgr->isOperation();
267     if (!aCanRedo) // check the enable state additionally by sketch manager
268       aCanRedo = aMgr->canRedo();
269   }
270   return aCanRedo;
271 }
272
273 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
274 {
275   // the sketch manager put the restriction to the objects display
276   return mySketchMgr->canDisplayObject(theObject);
277 }
278
279
280 bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
281 {
282   return myMenuMgr->addViewerItems(theMenu, theStdActions);
283 }
284
285 bool PartSet_Module::isMouseOverWindow()
286 {
287   return mySketchMgr->isMouseOverWindow();
288 }
289
290 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
291 {
292   ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
293   if (PartSet_SketcherMgr::isSketchOperation(theOperation) &&  (theOperation->isEditOperation())) {
294     // we have to manually activate the sketch label in edit mode
295       aPanel->activateWidget(aPanel->modelWidgets().first());
296       return;
297   }
298
299   // Restart last operation type 
300   if ((theOperation->id() == myLastOperationId) && myLastFeature) {
301     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
302     if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
303       // Initialise new line with first point equal to end of previous
304       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
305       if (aPnt2dWgt) {
306         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
307         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
308           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
309         if (aPoint) {
310           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
311           PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(), 
312             aWgt->attributeID(), aPoint->x(), aPoint->y());
313           aPanel->activateNextWidget(aPnt2dWgt);
314         }
315       }
316     }
317   } else {
318     // Start editing constraint
319     if (theOperation->isEditOperation()) {
320       // TODO: #391 - to be removed
321       std::string aId = theOperation->id().toStdString();
322       if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
323           PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
324         // Find and activate widget for management of point for dimension line position
325         QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
326         foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
327           PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
328           if (aPntWgt) {
329             aPanel->activateWidget(aPntWgt);
330             return;
331           }
332         }
333       }
334     }
335   }
336 }
337
338
339 void PartSet_Module::onSelectionChanged()
340 {
341   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
342   if (!aOperation)
343     return;
344
345   bool isSketcherOp = false;
346   // An edit operation is enable only if the current opeation is the sketch operation
347   if (mySketchMgr->activeSketch()) {
348     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
349       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
350   }
351   if (isSketcherOp) {
352     // Editing of constraints can be done on selection
353     ModuleBase_ISelection* aSelect = myWorkshop->selection();
354     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
355     if (aSelected.size() == 1) {
356       ModuleBase_ViewerPrs aPrs = aSelected.first();
357       ObjectPtr aObject = aPrs.object();
358       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
359       if (aFeature) {
360         std::string aId = aFeature->getKind();
361         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
362             (aId == SketchPlugin_ConstraintLength::ID()) || 
363             (aId == SketchPlugin_ConstraintDistance::ID())) {
364           editFeature(aFeature);
365         }
366       }
367     }
368   } 
369 }
370
371 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
372 {
373   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
374   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
375   anOpMgr->onKeyReleased(theEvent);
376 }
377
378 void PartSet_Module::onEnterReleased()
379 {
380   myRestartingMode = RM_EmptyFeatureUsed;
381 }
382
383 void PartSet_Module::onOperationActivatedByPreselection()
384 {
385   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
386   if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
387     // Set final definitions if they are necessary
388     //propertyPanelDefined(aOperation);
389
390     /// Commit sketcher operations automatically
391     anOperation->commit();
392   }
393 }
394
395 void PartSet_Module::onNoMoreWidgets()
396 {
397   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
398   if (anOperation) {
399     if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
400       if (myRestartingMode != RM_Forbided)
401         myRestartingMode = RM_LastFeatureUsed;
402       anOperation->commit();
403     }
404   }
405 }
406
407 void PartSet_Module::onVertexSelected()
408 {
409   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
410   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
411     /// If last line finished on vertex the lines creation sequence has to be break
412     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
413     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
414     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
415     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
416     bool aFoundWidget = false;
417     bool aFoundObligatory = false;
418     for (; anIt != aLast && !aFoundObligatory; anIt++) {
419       if (!aFoundWidget)
420         aFoundWidget = *anIt == anActiveWidget;
421       else
422         aFoundObligatory = (*anIt)->isObligatory();
423     }
424     if (!aFoundObligatory)
425       myRestartingMode = RM_Forbided;
426   }
427 }
428
429 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
430                                             Config_WidgetAPI* theWidgetApi, std::string theParentId)
431 {
432   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
433   XGUI_Workshop* aWorkshop = aConnector->workshop();
434   ModuleBase_ModelWidget* aWgt = NULL;
435   if (theType == "sketch-start-label") {
436     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, 
437       theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
438     aLabelWgt->setWorkshop(aWorkshop);
439     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
440       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
441     connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
442       mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
443     aWgt = aLabelWgt;
444   } else if (theType == "sketch-2dpoint_selector") {
445     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
446     aPointWgt->setWorkshop(aWorkshop);
447     aPointWgt->setSketch(mySketchMgr->activeSketch());
448     connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
449     aWgt = aPointWgt;
450   } if (theType == "point2ddistance") {
451     PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
452     aDistanceWgt->setWorkshop(aWorkshop);
453     aDistanceWgt->setSketch(mySketchMgr->activeSketch());
454     aWgt = aDistanceWgt;
455   } if (theType == "sketch_shape_selector") {
456     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
457       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
458     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
459     aWgt = aShapeSelectorWgt;
460   } if (theType == "sketch_multi_selector") {
461     PartSet_WidgetMultiSelector* aShapeSelectorWgt =
462       new PartSet_WidgetMultiSelector(theParent, workshop(), theWidgetApi, theParentId);
463     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
464     aWgt = aShapeSelectorWgt;
465   }
466   if (theType == WDG_DOUBLEVALUE_EDITOR) {
467     aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
468   } 
469   return aWgt;
470 }
471
472
473 bool PartSet_Module::deleteObjects()
474 {
475   // 1. check whether the delete should be processed in the module
476   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
477   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
478        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
479   if (!isSketchOp && !isNestedOp)
480     return false;
481
482   // 2. find selected presentations
483   // selected objects should be collected before the current operation abort because
484   // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
485   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
486   XGUI_Workshop* aWorkshop = aConnector->workshop();
487   ModuleBase_ISelection* aSel = workshop()->selection();
488   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
489   // if there are no selected objects in the viewer, that means that the selection in another
490   // place cased this method. It is necessary to return the false value to understande in above
491   // method that delete is not processed
492   if (aSelectedObj.count() == 0)
493     return false;
494
495   // avoid delete of the objects, which are not belong to the current sketch
496   // in order to do not delete results of other sketches
497   QObjectPtrList aSketchObjects;
498   QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
499   for ( ; anIt != aLast; anIt++) {
500     ObjectPtr anObject = *anIt;
501     if (mySketchMgr->isObjectOfSketch(anObject))
502       aSketchObjects.append(anObject);
503   }
504   // if the selection contains only local selected presentations from other sketches,
505   // the Delete operation should not be done at all
506   if (aSketchObjects.size() == 0)
507     return true;
508
509   // the active nested sketch operation should be aborted unconditionally
510   if (isNestedOp)
511     anOperation->abort();
512
513   // 3. start operation
514   QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
515   SessionPtr aMgr = ModelAPI_Session::get();
516   aMgr->startOperation(aDescription.toStdString());
517
518   // 4. delete features
519   // sketch feature should be skipped, only sub-features can be removed
520   // when sketch operation is active
521   std::set<FeaturePtr> anIgnoredFeatures;
522   anIgnoredFeatures.insert(mySketchMgr->activeSketch());
523   aWorkshop->deleteFeatures(aSketchObjects, anIgnoredFeatures);
524   
525   // 5. stop operation
526   aWorkshop->displayer()->updateViewer();
527   aMgr->finishOperation();
528
529   return true;
530 }
531
532
533 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) 
534 {
535   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
536   if (!anAIS.IsNull()) {
537     Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
538     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
539     if (!aDim.IsNull()) {
540       aCtx->SetZLayer(aDim, myVisualLayerId);
541     } else {
542       Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
543       if (!aCons.IsNull())
544         aCtx->SetZLayer(aCons, myVisualLayerId);
545     }
546   }
547 }
548
549 void PartSet_Module::onViewTransformed(int theTrsfType)
550 {
551   // Set length of arrows constant in pixel size
552   // if the operation is panning or rotate or panglobal then do nothing
553   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
554     return;
555
556   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
557   Handle(V3d_View) aView = aViewer->activeView();
558
559   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
560   XGUI_Workshop* aWorkshop = aConnector->workshop();
561   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
562   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
563
564   double aLen = aView->Convert(15);
565
566   SketcherPrs_Tools::setArrowSize(aLen);
567   bool isModified = false;
568   QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
569   foreach (AISObjectPtr aAIS, aPrsList) {
570     Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
571
572     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
573     if (!aDim.IsNull()) {
574       aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
575       aContext->Redisplay(aDim, false);
576       isModified = true;
577     }
578   }
579   if (isModified)
580     aDisplayer->updateViewer();
581 }