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