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