]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Viewer.cpp
Salome HOME
Editing preferences added
[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_Preferences.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_Preferences::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 void XGUI_Viewer::updateFromResources()
202 {
203   Qtx::BackgroundData aBk = XGUI_Preferences::resourceMgr()->backgroundValue("Viewer", "background");
204   foreach (QMdiSubWindow* aWnd, myViews) {
205     XGUI_ViewWindow* aView = dynamic_cast<XGUI_ViewWindow*>(aWnd->widget());
206     if (aView)
207       aView->setBackground(aBk);
208   }
209 }
210
211
212 XGUI_ViewWindow* XGUI_Viewer::activeViewWindow() const
213 {
214   if (myActiveView)
215     return dynamic_cast<XGUI_ViewWindow*>(myActiveView->widget());
216   return 0;
217 }
218
219 void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
220 {
221   theList.Clear();
222   for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
223     theList.Append(myAISContext->SelectedInteractive());
224 }
225
226 void XGUI_Viewer::getSelectedShapes(NCollection_List<TopoDS_Shape>& theList)
227 {
228   Handle(AIS_InteractiveContext) ic = AISContext();
229
230   for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
231     TopoDS_Shape aShape = ic->SelectedShape();
232     if (!aShape.IsNull())
233       theList.Append(aShape);
234   }
235 }
236
237 void XGUI_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
238 {
239   AIS_ListIteratorOfListOfInteractive aIt;
240   for (aIt.Initialize(theList); aIt.More(); aIt.Next())
241     myAISContext->AddOrRemoveSelected(aIt.Value(), false);
242   myAISContext->UpdateCurrentViewer();
243 }
244
245 /*! Sets hot button
246  *\param theOper - hot operation
247  *\param theState - adding state to state map operations.
248  *\param theButton - adding state to button map operations.
249  */
250 void XGUI_Viewer::setHotButton(XGUI::InteractionStyle theInteractionStyle,
251                                XGUI::HotOperation theOper, Qt::KeyboardModifiers theState,
252                                Qt::MouseButtons theButton)
253 {
254   myStateMap[theInteractionStyle][theOper] = theState;
255   myButtonMap[theInteractionStyle][theOper] = theButton;
256 }
257
258 /*! Gets hot button for operation \a theOper.
259  *\param theOper - input hot operation
260  *\param theState - output state from state map operations.
261  *\param theButton - output state from button map operations.
262  */
263 void XGUI_Viewer::getHotButton(XGUI::InteractionStyle theInteractionStyle,
264                                XGUI::HotOperation theOper, Qt::KeyboardModifiers& theState,
265                                Qt::MouseButtons& theButton)
266 {
267   theState = myStateMap[theInteractionStyle][theOper];
268   theButton = myButtonMap[theInteractionStyle][theOper];
269 }
270
271 /*!
272  Changes visibility of trihedron to opposite
273  */
274 void XGUI_Viewer::toggleTrihedron()
275 {
276   setTrihedronShown(!isTrihedronVisible());
277 }
278
279 /*!
280  \return true if trihedron is visible
281  */
282 bool XGUI_Viewer::isTrihedronVisible() const
283 {
284   return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed(myTrihedron);
285 }
286
287 /*!
288  Sets visibility state of trihedron
289  \param on - new state
290  */
291
292 void XGUI_Viewer::setTrihedronShown(bool on)
293 {
294   if (myTrihedron.IsNull())
295     return;
296
297   if (on) {
298     myAISContext->Display(myTrihedron);
299     myAISContext->Deactivate(myTrihedron);
300   } else {
301     myAISContext->Erase(myTrihedron);
302   }
303 }
304
305 /*!
306  \return trihedron size
307  */
308 double XGUI_Viewer::trihedronSize() const
309 {
310   double sz = 0;
311   if (!myTrihedron.IsNull())
312     sz = myTrihedron->Size();
313   return sz;
314 }
315
316 /*!
317  Changes trihedron size
318  \param sz - new size
319  */
320 void XGUI_Viewer::setTrihedronSize(const double sz, bool isRelative)
321 {
322   if (myTrihedronSize != sz || isRelative != myIsRelative) {
323     myTrihedronSize = sz;
324     myIsRelative = isRelative;
325     updateTrihedron();
326   }
327 }
328
329 /*! 
330  * Update the size of the trihedron
331  */
332 void XGUI_Viewer::updateTrihedron()
333 {
334   if (myTrihedron.IsNull())
335     return;
336
337   if (myIsRelative) {
338     double newSz, oldSz;
339
340     if (computeTrihedronSize(newSz, oldSz))
341       myTrihedron->SetSize(newSz);
342
343   } else if (myTrihedron->Size() != myTrihedronSize) {
344     myTrihedron->SetSize(myTrihedronSize);
345   }
346 }
347
348 /*!
349  Get new and current trihedron size corresponding to the current model size
350  */
351 bool XGUI_Viewer::computeTrihedronSize(double& theNewSize, double& theSize)
352 {
353   theNewSize = 100;
354   theSize = 100;
355
356   //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
357   Handle(V3d_Viewer) viewer = v3dViewer();
358   viewer->InitActiveViews();
359   if (!viewer->MoreActiveViews())
360     return false;
361
362   Handle(V3d_View) view3d = viewer->ActiveView();
363   //SRN: END of fix
364
365   if (view3d.IsNull())
366     return false;
367
368   double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
369   double aMaxSide;
370
371   view3d->View()->MinMaxValues(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
372
373   if (Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() || Xmax == RealLast()
374       || Ymax == RealLast() || Zmax == RealLast())
375     return false;
376
377   aMaxSide = Xmax - Xmin;
378   if (aMaxSide < Ymax - Ymin)
379     aMaxSide = Ymax - Ymin;
380   if (aMaxSide < Zmax - Zmin)
381     aMaxSide = Zmax - Zmin;
382
383   // IPAL21687
384   // The boundary box of the view may be initialized but nullified
385   // (case of infinite objects)
386   if (aMaxSide < Precision::Confusion())
387     return false;
388
389   static float EPS = (float)5.0E-3;
390   theSize = trihedron()->Size();
391   //theNewSize = aMaxSide*aSizeInPercents / 100.0;
392
393   return fabs(theNewSize - theSize) > theSize * EPS || fabs(theNewSize - theSize) > theNewSize * EPS;
394 }
395
396 void XGUI_Viewer::onViewClosed(QMdiSubWindow* theView)
397 {
398   if ( !theView )
399     return;
400
401   emit deleteView( static_cast<XGUI_ViewWindow*>(theView->widget()) );
402   removeView( theView );
403
404   // if this is last view
405   if (myViews.size() == 0) {
406     Standard_Integer aViewsNb = 0;
407     for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
408       ++aViewsNb;
409     if ( aViewsNb < 2 ) {
410       //clean up presentations before last view is closed
411       myAISContext->RemoveAll(Standard_False);
412     }
413   }
414 }
415
416 /*!Remove view window \a theView from view manager.
417  *And close the last view, if it has \a theView.
418 */
419 void XGUI_Viewer::removeView( QMdiSubWindow* theView )
420 {
421     XGUI_ViewWindow* aWindow = static_cast<XGUI_ViewWindow*>(theView->widget());
422
423     aWindow->disconnect( this );
424     myViews.removeAt( myViews.indexOf( theView ) );
425     if ( myActiveView == theView )
426         myActiveView = 0;
427     if ( myViews.size() == 0 )
428         emit lastViewClosed();
429 }
430
431
432 /*void XGUI_Viewer::onViewMapped()
433 {
434   setTrihedronShown(true);
435 }*/
436
437
438 void XGUI_Viewer::addView(QMdiSubWindow* theView)
439 {
440     XGUI_ViewWindow* aWindow = dynamic_cast<XGUI_ViewWindow*>(theView->widget());
441
442     connect(aWindow, SIGNAL(closed(QMdiSubWindow*)),
443             this,    SLOT(onViewClosed(QMdiSubWindow*)));
444
445     connect(aWindow, SIGNAL(tryClosing(XGUI_ViewWindow*)),
446             this,    SIGNAL(tryCloseView(XGUI_ViewWindow*)));
447
448     connect(aWindow, SIGNAL(mousePressed(XGUI_ViewWindow*, QMouseEvent*)),
449             this,    SLOT(onMousePressed(XGUI_ViewWindow*, QMouseEvent*)));
450
451     connect(aWindow, SIGNAL(mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*)),
452             this,    SIGNAL(mouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)));
453
454     connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)),
455             this,    SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)));
456
457     connect(aWindow, SIGNAL(keyPressed(XGUI_ViewWindow*, QKeyEvent*)),
458             this,    SIGNAL(keyPress(XGUI_ViewWindow*, QKeyEvent*)));
459
460     connect(aWindow, SIGNAL(keyReleased(XGUI_ViewWindow*, QKeyEvent*)),
461             this,    SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)));
462
463     //connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )),
464     //        this,    SLOT  (onContextMenuRequested( QContextMenuEvent* )));
465     connect(aWindow, SIGNAL( contextMenuRequested(QContextMenuEvent*) ), 
466             this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) );
467
468     connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)),
469             this, SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
470
471     connect(aWindow, SIGNAL(mouseReleased(XGUI_ViewWindow*, QMouseEvent*)),
472             this, SLOT(onMouseReleased(XGUI_ViewWindow*, QMouseEvent*)));
473
474     myViews.append(theView);
475 }
476
477 /*!
478     Emit activated for view \a view.
479 */
480 void XGUI_Viewer::onWindowActivated(QMdiSubWindow* view)
481 {
482   if (view && (view != myActiveView) && (!view->isMinimized())) {
483     myActiveView = view;
484     ((XGUI_ViewWindow*)myActiveView->widget())->windowActivated();
485     QList<QMdiSubWindow*>::iterator aIt;
486     for (aIt = myViews.begin(); aIt != myViews.end(); ++aIt) {
487       if ((*aIt) != myActiveView) {
488         ((XGUI_ViewWindow*)(*aIt)->widget())->windowDeactivated();
489       }
490     }
491   }
492 }
493
494
495 void XGUI_Viewer::onWindowMinimized(QMdiSubWindow* theWnd)
496 {
497   if (myActiveView == theWnd) {
498     myActiveView = 0;
499     QList<QMdiSubWindow*>::iterator aIt;
500     for (aIt = myViews.begin(); aIt != myViews.end(); ++aIt) {
501       if (!(*aIt)->widget()->isMinimized()) {
502         (*aIt)->raise();
503         onWindowActivated(*aIt);
504         break;
505       }
506     }
507   }
508 }
509
510 /*!
511   SLOT: called on mouse button press, stores current mouse position as start point for transformations
512 */
513 void XGUI_Viewer::onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
514 {
515   myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
516   emit mousePress(theWindow, theEvent);
517 }
518
519 /*!
520   SLOT: called on mouse move, processes hilighting
521 */
522 void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
523 {
524   myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
525   if (!mySelectionEnabled) return;
526
527   Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
528   if ( !aView3d.IsNull() ) {
529     myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
530   }
531 }
532
533 /*!
534   SLOT: called on mouse button release, finishes selection
535 */
536 void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
537 {
538   if (!mySelectionEnabled || theEvent->button() != Qt::LeftButton) {
539     emit mouseRelease(theWindow, theEvent);
540     return;
541   }
542
543   myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
544   bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
545   
546   //if (!aHasShift) 
547   //  emit deselection();
548
549   if (myStartPnt == myEndPnt) {
550     // the MoveTo is necessary for the second click in the same point. Otherwise the selection is lost.
551     Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
552     if ( !aView3d.IsNull() ) {
553       myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
554     }
555     if (aHasShift && myMultiSelectionEnabled)
556       myAISContext->ShiftSelect();
557     else
558       myAISContext->Select();
559   } else {
560     if (aHasShift && myMultiSelectionEnabled)
561       myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
562                                 myEndPnt.x(), myEndPnt.y(),
563                                 theWindow->viewPort()->getView(), false );
564     else
565       myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
566                            myEndPnt.x(), myEndPnt.y(),
567                            theWindow->viewPort()->getView(), false );
568
569     int Nb = myAISContext->NbSelected();
570     if( Nb>1 && !myMultiSelectionEnabled ) {
571       myAISContext->InitSelected();
572       Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
573       if( !anOwner.IsNull() ) {
574         myAISContext->ClearSelected( Standard_False );
575         myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
576       }
577     }
578
579     myAISContext->UpdateCurrentViewer();
580   }
581   emit mouseRelease(theWindow, theEvent);
582   emit selectionChanged();
583 }
584
585 //******************************************************
586 void XGUI_Viewer::setMultiSelectionEnabled(bool toEnable) 
587
588   myMultiSelectionEnabled = toEnable; 
589   updateViewsDrawMode();
590 }
591
592 //******************************************************
593 void XGUI_Viewer::setSelectionEnabled(bool toEnable) 
594
595   mySelectionEnabled = toEnable; 
596   updateViewsDrawMode();
597 }
598
599 //******************************************************
600 void XGUI_Viewer::updateViewsDrawMode() const
601 {
602   foreach(QMdiSubWindow* aWnd, myViews){
603     XGUI_ViewWindow* aView = static_cast<XGUI_ViewWindow*>(aWnd->widget());
604     aView->updateEnabledDrawMode();
605   }
606 }
607
608 //******************************************************
609 //void XGUI_Viewer::onContextMenuRequested(QContextMenuEvent* theEvent)
610 //{
611 //  XGUI_ViewWindow* aWnd = dynamic_cast<XGUI_ViewWindow*>(sender());
612 //  if (!aWnd) return;
613 //
614 //  QMenu aMenu;
615 //
616 //  // Include Viewer actions
617 //  if (myActions.size() > 0) {
618 //    aMenu.addActions(myActions);
619 //    aMenu.addSeparator();
620 //  }
621 //  if (aWnd->actions().size() > 0) {
622 //    aMenu.addActions(aWnd->actions());
623 //    aMenu.addSeparator();
624 //  }
625 //
626 //  QMdiArea* aMDI = myMainWindow->mdiArea();
627 //  if (aMenu.actions().size() > 0) {
628 //    QMenu* aSubMenu = aMenu.addMenu(tr("Windows"));
629 //    aSubMenu->addActions(aMDI->actions());
630 //  } else {
631 //    aMenu.addActions(aMDI->actions());
632 //  }
633 //  aMenu.exec(theEvent->globalPos());
634 //}