Salome HOME
Resources XML file created
[modules/shaper.git] / src / XGUI / XGUI_Viewer.cpp
1 #include "XGUI_Viewer.h"
2 #include "XGUI_MainWindow.h"
3 #include "XGUI_ViewWindow.h"
4 #include "XGUI_ViewPort.h"
5 #include "XGUI_Workshop.h"
6
7 #include <SUIT_ResourceMgr.h>
8
9 #include <QMdiArea>
10 #include <QMdiSubWindow>
11 #include <QApplication>
12 #include <QMouseEvent>
13 #include <QMenu>
14
15 #include <V3d_View.hxx>
16
17 #include <Aspect_DisplayConnection.hxx>
18 #include <Graphic3d.hxx>
19 #include <Graphic3d_GraphicDriver.hxx>
20 #include <Geom_Axis2Placement.hxx>
21 #include <AIS_Drawer.hxx>
22 #include <Prs3d_DatumAspect.hxx>
23 #include <Prs3d_LineAspect.hxx>
24 #include <V3d_View.hxx>
25 #include <Visual3d_View.hxx>
26 #include <AIS_ListOfInteractive.hxx>
27 #include <AIS_ListIteratorOfListOfInteractive.hxx>
28 #include <AIS_Shape.hxx>
29
30
31 #ifdef WIN32
32 #include <WNT_Window.hxx>
33 #else
34 #include <Xw_Window.hxx>
35 #endif
36
37 XGUI_Viewer::InteractionStyle2StatesMap XGUI_Viewer::myStateMap;
38 XGUI_Viewer::InteractionStyle2ButtonsMap XGUI_Viewer::myButtonMap;
39 static bool isInitialized = false;
40
41 /*!
42  Creates viewer 3d [ static ]
43  */
44 Handle(V3d_Viewer) CreateViewer(const Standard_ExtString name, const Standard_CString displayName,
45                                 const Standard_CString domain, const Standard_Real viewSize,
46                                 const V3d_TypeOfOrientation viewProjection,
47                                 const Standard_Boolean computedMode,
48                                 const Standard_Boolean defaultComputedMode)
49 {
50   static Handle(Graphic3d_GraphicDriver) aGraphicDriver;
51   if (aGraphicDriver.IsNull()) {
52     Handle(Aspect_DisplayConnection) aDisplayConnection;
53 #ifndef WIN32
54     aDisplayConnection = new Aspect_DisplayConnection( displayName );
55 #else
56     aDisplayConnection = new Aspect_DisplayConnection();
57 #endif
58     aGraphicDriver = Graphic3d::InitGraphicDriver(aDisplayConnection);
59   }
60
61   return new V3d_Viewer(aGraphicDriver, name, domain, viewSize, viewProjection, Quantity_NOC_GRAY30,
62                         V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT, computedMode, defaultComputedMode,
63                         V3d_TEX_NONE);
64 }
65
66 // VSR: Uncomment below line to allow texture background support in OCC viewer
67 #define OCC_ENABLE_TEXTURED_BACKGROUND
68
69 /*!
70  Get data for supported background modes: gradient types, identifiers and supported image formats
71  */
72 QString XGUI_Viewer::backgroundData(QStringList& gradList, QIntList& idList, QIntList& txtList)
73 {
74   gradList << tr("Horizontal gradient") << tr("Vertical gradient")
75       << tr("First diagonal gradient") << tr("Second diagonal gradient")
76       << tr("First corner gradient") << tr("Second corner gradient")
77       << tr("Third corner gradient") << tr("Fourth corner gradient");
78   idList << XGUI::HorizontalGradient << XGUI::VerticalGradient << XGUI::Diagonal1Gradient
79       << XGUI::Diagonal2Gradient << XGUI::Corner1Gradient << XGUI::Corner2Gradient
80       << XGUI::Corner3Gradient << XGUI::Corner4Gradient;
81 #ifdef OCC_ENABLE_TEXTURED_BACKGROUND
82   txtList << XGUI::CenterTexture << XGUI::TileTexture << XGUI::StretchTexture;
83 #endif
84   return tr("Image files (*.bmp *.gif *.pix *.xwd *.rgb *.rs)");
85 }
86
87 XGUI_Viewer::XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron)
88     : QObject(theParent), 
89     myMainWindow(theParent), 
90     myPreselectionEnabled(true), 
91     mySelectionEnabled(true), 
92     myMultiSelectionEnabled(true), 
93     myIsRelative(true), 
94     myInteractionStyle(XGUI::STANDARD), 
95     myTrihedronSize(100),
96     myActiveView(0),
97     myWndIdCount(0)
98 {
99   if (!isInitialized) {
100     isInitialized = true;
101
102     // standard interaction style
103     XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::ZOOM] = Qt::ControlModifier;
104     XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::ZOOM] = Qt::LeftButton;
105
106     XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::PAN] = Qt::ControlModifier;
107     XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::PAN] = Qt::MidButton;
108
109     XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::ROTATE] = Qt::ControlModifier;
110     XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::ROTATE] = Qt::RightButton;
111
112     XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::FIT_AREA] = Qt::ControlModifier;
113     XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::FIT_AREA] = Qt::RightButton;
114
115     // "key free" interaction style
116     XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::ZOOM] = Qt::NoModifier;
117     XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::ZOOM] = Qt::RightButton;
118
119     XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::PAN] = Qt::NoModifier;
120     XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::PAN] = Qt::MidButton;
121
122     XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::ROTATE] = Qt::NoModifier;
123     XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::ROTATE] = Qt::LeftButton;
124
125     XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::FIT_AREA] = Qt::NoModifier; // unused
126     XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::FIT_AREA] = Qt::NoButton; // unused
127   }
128
129   // init CasCade viewers
130   myV3dViewer = CreateViewer(TCollection_ExtendedString("Viewer3d").ToExtString(), "", "", 1000.0,
131                              V3d_XposYnegZpos, Standard_True, Standard_True);
132   myV3dViewer->SetDefaultLights();
133
134   // init selector
135   myAISContext = new AIS_InteractiveContext(myV3dViewer);
136   myAISContext->SelectionColor(Quantity_NOC_WHITE);
137
138   // display isoline on planar faces (box for ex.)
139   myAISContext->IsoOnPlane(true);
140
141   if (DisplayTrihedron) {
142     Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
143     myTrihedron = new AIS_Trihedron(anAxis);
144     myTrihedron->SetInfiniteState( Standard_True);
145
146     Quantity_Color Col(193 / 255., 205 / 255., 193 / 255., Quantity_TOC_RGB);
147     myTrihedron->SetArrowColor(Col.Name());
148     myTrihedron->SetSize(myTrihedronSize);
149     Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
150     if (drawer->HasDatumAspect()) {
151       Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
152       daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
153       daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
154       daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
155     }
156   }
157   // set zooming style to standard
158   //myZoomingStyle = 0;
159
160   QMdiArea* aMDI = myMainWindow->mdiArea();
161   connect(aMDI, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(onWindowActivated(QMdiSubWindow*)));
162
163 }
164
165 XGUI_Viewer::~XGUI_Viewer(void)
166 {
167   myAISContext.Nullify();
168   myV3dViewer.Nullify();
169 }
170
171 QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType)
172 {
173   // create view frame
174   XGUI_ViewWindow* view = new XGUI_ViewWindow(this, theType);
175   // get main view window (created by view frame)
176   //OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
177   // initialize main view window
178   //initView( vw );
179   // set default background for view window
180   //vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
181   // connect signal from viewport
182   //connect(view->viewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed()));
183     //connect(view->viewPort(), SIGNAL(vpMapped()), this, SLOT(onViewMapped()));
184   if (myViews.size() == 0) 
185     setTrihedronShown(true);
186
187   Qtx::BackgroundData aBk = XGUI_Workshop::resourceMgr()->backgroundValue("Viewer", "background");
188   view->setBackground(aBk);
189   view->updateEnabledDrawMode();
190
191   QMdiArea* aMDI = myMainWindow->mdiArea();
192   QMdiSubWindow* aWnd = aMDI->addSubWindow(view, Qt::FramelessWindowHint);
193   addView(aWnd);
194   aWnd->setGeometry(0, 0, aMDI->width() / 2, aMDI->height() / 2);
195   aWnd->show();
196   aWnd->setWindowTitle(QString("Viewer #%1").arg(++myWndIdCount));
197   emit viewCreated(view);
198   return aWnd;
199 }
200
201 XGUI_ViewWindow* XGUI_Viewer::activeViewWindow() const
202 {
203   if (myActiveView)
204     return dynamic_cast<XGUI_ViewWindow*>(myActiveView->widget());
205   return 0;
206 }
207
208 void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
209 {
210   theList.Clear();
211   for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
212     theList.Append(myAISContext->SelectedInteractive());
213 }
214
215 void XGUI_Viewer::getSelectedShapes(NCollection_List<TopoDS_Shape>& theList)
216 {
217   Handle(AIS_InteractiveContext) ic = AISContext();
218
219   for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
220     TopoDS_Shape aShape = ic->SelectedShape();
221     if (!aShape.IsNull())
222       theList.Append(aShape);
223   }
224 }
225
226 void XGUI_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
227 {
228   AIS_ListIteratorOfListOfInteractive aIt;
229   for (aIt.Initialize(theList); aIt.More(); aIt.Next())
230     myAISContext->AddOrRemoveSelected(aIt.Value(), false);
231   myAISContext->UpdateCurrentViewer();
232 }
233
234 /*! Sets hot button
235  *\param theOper - hot operation
236  *\param theState - adding state to state map operations.
237  *\param theButton - adding state to button map operations.
238  */
239 void XGUI_Viewer::setHotButton(XGUI::InteractionStyle theInteractionStyle,
240                                XGUI::HotOperation theOper, Qt::KeyboardModifiers theState,
241                                Qt::MouseButtons theButton)
242 {
243   myStateMap[theInteractionStyle][theOper] = theState;
244   myButtonMap[theInteractionStyle][theOper] = theButton;
245 }
246
247 /*! Gets hot button for operation \a theOper.
248  *\param theOper - input hot operation
249  *\param theState - output state from state map operations.
250  *\param theButton - output state from button map operations.
251  */
252 void XGUI_Viewer::getHotButton(XGUI::InteractionStyle theInteractionStyle,
253                                XGUI::HotOperation theOper, Qt::KeyboardModifiers& theState,
254                                Qt::MouseButtons& theButton)
255 {
256   theState = myStateMap[theInteractionStyle][theOper];
257   theButton = myButtonMap[theInteractionStyle][theOper];
258 }
259
260 /*!
261  Changes visibility of trihedron to opposite
262  */
263 void XGUI_Viewer::toggleTrihedron()
264 {
265   setTrihedronShown(!isTrihedronVisible());
266 }
267
268 /*!
269  \return true if trihedron is visible
270  */
271 bool XGUI_Viewer::isTrihedronVisible() const
272 {
273   return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed(myTrihedron);
274 }
275
276 /*!
277  Sets visibility state of trihedron
278  \param on - new state
279  */
280
281 void XGUI_Viewer::setTrihedronShown(bool on)
282 {
283   if (myTrihedron.IsNull())
284     return;
285
286   if (on) {
287     myAISContext->Display(myTrihedron);
288     myAISContext->Deactivate(myTrihedron);
289   } else {
290     myAISContext->Erase(myTrihedron);
291   }
292 }
293
294 /*!
295  \return trihedron size
296  */
297 double XGUI_Viewer::trihedronSize() const
298 {
299   double sz = 0;
300   if (!myTrihedron.IsNull())
301     sz = myTrihedron->Size();
302   return sz;
303 }
304
305 /*!
306  Changes trihedron size
307  \param sz - new size
308  */
309 void XGUI_Viewer::setTrihedronSize(const double sz, bool isRelative)
310 {
311   if (myTrihedronSize != sz || isRelative != myIsRelative) {
312     myTrihedronSize = sz;
313     myIsRelative = isRelative;
314     updateTrihedron();
315   }
316 }
317
318 /*! 
319  * Update the size of the trihedron
320  */
321 void XGUI_Viewer::updateTrihedron()
322 {
323   if (myTrihedron.IsNull())
324     return;
325
326   if (myIsRelative) {
327     double newSz, oldSz;
328
329     if (computeTrihedronSize(newSz, oldSz))
330       myTrihedron->SetSize(newSz);
331
332   } else if (myTrihedron->Size() != myTrihedronSize) {
333     myTrihedron->SetSize(myTrihedronSize);
334   }
335 }
336
337 /*!
338  Get new and current trihedron size corresponding to the current model size
339  */
340 bool XGUI_Viewer::computeTrihedronSize(double& theNewSize, double& theSize)
341 {
342   theNewSize = 100;
343   theSize = 100;
344
345   //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
346   Handle(V3d_Viewer) viewer = v3dViewer();
347   viewer->InitActiveViews();
348   if (!viewer->MoreActiveViews())
349     return false;
350
351   Handle(V3d_View) view3d = viewer->ActiveView();
352   //SRN: END of fix
353
354   if (view3d.IsNull())
355     return false;
356
357   double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
358   double aMaxSide;
359
360   view3d->View()->MinMaxValues(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
361
362   if (Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() || Xmax == RealLast()
363       || Ymax == RealLast() || Zmax == RealLast())
364     return false;
365
366   aMaxSide = Xmax - Xmin;
367   if (aMaxSide < Ymax - Ymin)
368     aMaxSide = Ymax - Ymin;
369   if (aMaxSide < Zmax - Zmin)
370     aMaxSide = Zmax - Zmin;
371
372   // IPAL21687
373   // The boundary box of the view may be initialized but nullified
374   // (case of infinite objects)
375   if (aMaxSide < Precision::Confusion())
376     return false;
377
378   static float EPS = (float)5.0E-3;
379   theSize = trihedron()->Size();
380   //theNewSize = aMaxSide*aSizeInPercents / 100.0;
381
382   return fabs(theNewSize - theSize) > theSize * EPS || fabs(theNewSize - theSize) > theNewSize * EPS;
383 }
384
385 void XGUI_Viewer::onViewClosed(QMdiSubWindow* theView)
386 {
387   if ( !theView )
388     return;
389
390   emit deleteView( static_cast<XGUI_ViewWindow*>(theView->widget()) );
391   removeView( theView );
392
393   // if this is last view
394   if (myViews.size() == 0) {
395     Standard_Integer aViewsNb = 0;
396     for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
397       ++aViewsNb;
398     if ( aViewsNb < 2 ) {
399       //clean up presentations before last view is closed
400       myAISContext->RemoveAll(Standard_False);
401     }
402   }
403 }
404
405 /*!Remove view window \a theView from view manager.
406  *And close the last view, if it has \a theView.
407 */
408 void XGUI_Viewer::removeView( QMdiSubWindow* theView )
409 {
410     XGUI_ViewWindow* aWindow = static_cast<XGUI_ViewWindow*>(theView->widget());
411
412     aWindow->disconnect( this );
413     myViews.removeAt( myViews.indexOf( theView ) );
414     if ( myActiveView == theView )
415         myActiveView = 0;
416     if ( myViews.size() == 0 )
417         emit lastViewClosed();
418 }
419
420
421 /*void XGUI_Viewer::onViewMapped()
422 {
423   setTrihedronShown(true);
424 }*/
425
426
427 void XGUI_Viewer::addView(QMdiSubWindow* theView)
428 {
429     XGUI_ViewWindow* aWindow = dynamic_cast<XGUI_ViewWindow*>(theView->widget());
430
431     connect(aWindow, SIGNAL(closed(QMdiSubWindow*)),
432             this,    SLOT(onViewClosed(QMdiSubWindow*)));
433
434     connect(aWindow, SIGNAL(tryClosing(XGUI_ViewWindow*)),
435             this,    SIGNAL(tryCloseView(XGUI_ViewWindow*)));
436
437     connect(aWindow, SIGNAL(mousePressed(XGUI_ViewWindow*, QMouseEvent*)),
438             this,    SLOT(onMousePressed(XGUI_ViewWindow*, QMouseEvent*)));
439
440     connect(aWindow, SIGNAL(mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*)),
441             this,    SIGNAL(mouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)));
442
443     connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)),
444             this,    SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)));
445
446     connect(aWindow, SIGNAL(keyPressed(XGUI_ViewWindow*, QKeyEvent*)),
447             this,    SIGNAL(keyPress(XGUI_ViewWindow*, QKeyEvent*)));
448
449     connect(aWindow, SIGNAL(keyReleased(XGUI_ViewWindow*, QKeyEvent*)),
450             this,    SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)));
451
452     //connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )),
453     //        this,    SLOT  (onContextMenuRequested( QContextMenuEvent* )));
454     connect(aWindow, SIGNAL( contextMenuRequested(QContextMenuEvent*) ), 
455             this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) );
456
457     connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)),
458             this, SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
459
460     connect(aWindow, SIGNAL(mouseReleased(XGUI_ViewWindow*, QMouseEvent*)),
461             this, SLOT(onMouseReleased(XGUI_ViewWindow*, QMouseEvent*)));
462
463     myViews.append(theView);
464 }
465
466 /*!
467     Emit activated for view \a view.
468 */
469 void XGUI_Viewer::onWindowActivated(QMdiSubWindow* view)
470 {
471   if (view && (view != myActiveView) && (!view->isMinimized())) {
472     myActiveView = view;
473     ((XGUI_ViewWindow*)myActiveView->widget())->windowActivated();
474     QList<QMdiSubWindow*>::iterator aIt;
475     for (aIt = myViews.begin(); aIt != myViews.end(); ++aIt) {
476       if ((*aIt) != myActiveView) {
477         ((XGUI_ViewWindow*)(*aIt)->widget())->windowDeactivated();
478       }
479     }
480   }
481 }
482
483
484 void XGUI_Viewer::onWindowMinimized(QMdiSubWindow* theWnd)
485 {
486   if (myActiveView == theWnd) {
487     myActiveView = 0;
488     QList<QMdiSubWindow*>::iterator aIt;
489     for (aIt = myViews.begin(); aIt != myViews.end(); ++aIt) {
490       if (!(*aIt)->widget()->isMinimized()) {
491         (*aIt)->raise();
492         onWindowActivated(*aIt);
493         break;
494       }
495     }
496   }
497 }
498
499 /*!
500   SLOT: called on mouse button press, stores current mouse position as start point for transformations
501 */
502 void XGUI_Viewer::onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
503 {
504   myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
505   emit mousePress(theWindow, theEvent);
506 }
507
508 /*!
509   SLOT: called on mouse move, processes hilighting
510 */
511 void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
512 {
513   myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
514   if (!mySelectionEnabled) return;
515
516   Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
517   if ( !aView3d.IsNull() ) {
518     myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
519   }
520 }
521
522 /*!
523   SLOT: called on mouse button release, finishes selection
524 */
525 void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
526 {
527   if (!mySelectionEnabled || theEvent->button() != Qt::LeftButton) {
528     emit mouseRelease(theWindow, theEvent);
529     return;
530   }
531
532   myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
533   bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
534   
535   //if (!aHasShift) 
536   //  emit deselection();
537
538   if (myStartPnt == myEndPnt) {
539     // the MoveTo is necessary for the second click in the same point. Otherwise the selection is lost.
540     Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
541     if ( !aView3d.IsNull() ) {
542       myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
543     }
544     if (aHasShift && myMultiSelectionEnabled)
545       myAISContext->ShiftSelect();
546     else
547       myAISContext->Select();
548   } else {
549     if (aHasShift && myMultiSelectionEnabled)
550       myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
551                                 myEndPnt.x(), myEndPnt.y(),
552                                 theWindow->viewPort()->getView(), false );
553     else
554       myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
555                            myEndPnt.x(), myEndPnt.y(),
556                            theWindow->viewPort()->getView(), false );
557
558     int Nb = myAISContext->NbSelected();
559     if( Nb>1 && !myMultiSelectionEnabled ) {
560       myAISContext->InitSelected();
561       Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
562       if( !anOwner.IsNull() ) {
563         myAISContext->ClearSelected( Standard_False );
564         myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
565       }
566     }
567
568     myAISContext->UpdateCurrentViewer();
569   }
570   emit mouseRelease(theWindow, theEvent);
571   emit selectionChanged();
572 }
573
574 //******************************************************
575 void XGUI_Viewer::setMultiSelectionEnabled(bool toEnable) 
576
577   myMultiSelectionEnabled = toEnable; 
578   updateViewsDrawMode();
579 }
580
581 //******************************************************
582 void XGUI_Viewer::setSelectionEnabled(bool toEnable) 
583
584   mySelectionEnabled = toEnable; 
585   updateViewsDrawMode();
586 }
587
588 //******************************************************
589 void XGUI_Viewer::updateViewsDrawMode() const
590 {
591   foreach(QMdiSubWindow* aWnd, myViews){
592     XGUI_ViewWindow* aView = static_cast<XGUI_ViewWindow*>(aWnd->widget());
593     aView->updateEnabledDrawMode();
594   }
595 }
596
597 //******************************************************
598 //void XGUI_Viewer::onContextMenuRequested(QContextMenuEvent* theEvent)
599 //{
600 //  XGUI_ViewWindow* aWnd = dynamic_cast<XGUI_ViewWindow*>(sender());
601 //  if (!aWnd) return;
602 //
603 //  QMenu aMenu;
604 //
605 //  // Include Viewer actions
606 //  if (myActions.size() > 0) {
607 //    aMenu.addActions(myActions);
608 //    aMenu.addSeparator();
609 //  }
610 //  if (aWnd->actions().size() > 0) {
611 //    aMenu.addActions(aWnd->actions());
612 //    aMenu.addSeparator();
613 //  }
614 //
615 //  QMdiArea* aMDI = myMainWindow->mdiArea();
616 //  if (aMenu.actions().size() > 0) {
617 //    QMenu* aSubMenu = aMenu.addMenu(tr("Windows"));
618 //    aSubMenu->addActions(aMDI->actions());
619 //  } else {
620 //    aMenu.addActions(aMDI->actions());
621 //  }
622 //  aMenu.exec(theEvent->globalPos());
623 //}