2 #define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */
6 #include "ApplicationCommon.h"
8 #include <QApplication>
11 #include <QColorDialog>
14 #include <QMouseEvent>
15 #include <QRubberBand>
17 #include <Visual3d_View.hxx>
18 #include <Graphic3d_ExportFormat.hxx>
19 #include <Graphic3d_GraphicDriver.hxx>
20 #include <QWindowsStyle>
22 #if defined(_WIN32) || defined(__WIN32__)
23 #include <WNT_Window.hxx>
24 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
25 #include <Cocoa_Window.hxx>
29 #include <X11/Xutil.h>
30 #include <X11/Xatom.h>
31 #include <X11/Xmu/StdCmap.h>
33 #include <Xw_Window.hxx>
37 #include <Aspect_DisplayConnection.hxx>
39 // the key for multi selection :
40 #define MULTISELECTIONKEY Qt::ShiftModifier
42 // the key for shortcut ( use to activate dynamic rotation, panning )
43 #define CASCADESHORTCUTKEY Qt::ControlModifier
45 // for elastic bean selection
48 static QCursor* defCursor = NULL;
49 static QCursor* handCursor = NULL;
50 static QCursor* panCursor = NULL;
51 static QCursor* globPanCursor = NULL;
52 static QCursor* zoomCursor = NULL;
53 static QCursor* rotCursor = NULL;
55 View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent )
59 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
60 //XSynchronize( x11Display(),true ); // it is possible to use QApplication::syncX();
61 XSynchronize( x11Info().display(),true ); // it is possible to use QApplication::syncX();
64 myContext = theContext;
73 setAttribute(Qt::WA_PaintOnScreen);
74 setAttribute(Qt::WA_NoSystemBackground);
76 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
77 XVisualInfo* pVisualInfo;
78 if ( x11Info().display() )
80 /* Initialization with the default VisualID */
81 Visual *v = DefaultVisual( x11Info().display(), DefaultScreen( x11Info().display() ) );
82 int visualID = XVisualIDFromVisual( v );
84 /* Here we use the settings from Optimizer_ViewInfo::TxglCreateWindow() */
85 int visualAttr[] = { GLX_RGBA, GLX_DEPTH_SIZE, 1, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
86 GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None };
87 pVisualInfo = ::glXChooseVisual( x11Info().display(), DefaultScreen( x11Info().display() ), visualAttr );
92 XSetWindowAttributes a;
94 Window p = RootWindow( x11Info().display(), DefaultScreen( x11Info().display() ) );
95 a.colormap = XCreateColormap( x11Info().display(), RootWindow( x11Info().display(), pVisualInfo->screen ),
96 pVisualInfo->visual, AllocNone );
98 QColor color = palette().color( backgroundRole() );
99 QColormap colmap = QColormap::instance();
100 a.background_pixel = colmap.pixel( color );
101 a.border_pixel = colmap.pixel( Qt::black );
102 if ( parentWidget() )
103 p = parentWidget()->winId();
105 Window w = XCreateWindow( x11Info().display(), p, x(), y(), width(), height(),
106 0, pVisualInfo->depth, InputOutput, pVisualInfo->visual,
107 CWBackPixel | CWBorderPixel | CWColormap, &a );
111 if ( XGetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), &cmwret, &count ) )
113 cmw = new Window[count+1];
114 memcpy( (char *)cmw, (char *)cmwret, sizeof(Window)*count );
115 XFree( (char *)cmwret );
117 for ( i = 0; i < count; i++ )
119 if ( cmw[i] == winId() ) /* replace old window */
125 if ( i >= count ) /* append new window */
131 cmw = new Window[count];
134 /* Creating new window (with good VisualID) for this widget */
136 XSetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), cmw, count );
142 XFree( (char *)pVisualInfo );
143 XFlush( x11Info().display() );
146 myCurrentMode = CurAction3d_Nothing;
147 myHlrModeIsOn = Standard_False;
148 setMouseTracking( true );
153 setBackgroundRole( QPalette::NoRole );//NoBackground );
154 // set focus policy to threat QContextMenuEvent from keyboard
155 setFocusPolicy( Qt::StrongFocus );
156 setAttribute( Qt::WA_PaintOnScreen );
157 setAttribute( Qt::WA_NoSystemBackground );
168 myView = myContext->CurrentViewer()->CreateView();
169 #if defined(_WIN32) || defined(__WIN32__)
170 Aspect_Handle aWindowHandle = (Aspect_Handle )winId();
171 Handle(WNT_Window) hWnd = new WNT_Window (aWindowHandle);
172 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
173 NSView* aViewHandle = (NSView* )winId();
174 Handle(Cocoa_Window) hWnd = new Cocoa_Window (aViewHandle);
176 Window aWindowHandle = (Window )winId();
177 Handle(Aspect_DisplayConnection) aDispConnection = myContext->CurrentViewer()->Driver()->GetDisplayConnection();
178 Handle(Xw_Window) hWnd = new Xw_Window (aDispConnection, aWindowHandle);
180 myView->SetWindow (hWnd);
181 if (!hWnd->IsMapped())
185 myView->SetBackgroundColor (Quantity_NOC_BLACK);
186 myView->MustBeResized();
189 void View::paintEvent( QPaintEvent * )
191 // QApplication::syncX();
200 void View::resizeEvent( QResizeEvent * )
202 // QApplication::syncX();
203 if( !myView.IsNull() )
205 myView->MustBeResized();
218 myCurrentMode = CurAction3d_WindowZooming;
223 myCurrentMode = CurAction3d_DynamicZooming;
228 myCurrentMode = CurAction3d_DynamicPanning;
231 void View::rotation()
233 myCurrentMode = CurAction3d_DynamicRotation;
236 void View::globalPan()
238 // save the current zoom value
239 myCurZoom = myView->Scale();
243 myCurrentMode = CurAction3d_GlobalPanning;
248 myView->SetProj( V3d_Xpos );
253 myView->SetProj( V3d_Xneg );
258 myView->SetProj( V3d_Zpos );
263 myView->SetProj( V3d_Zneg );
268 myView->SetProj( V3d_Ypos );
273 myView->SetProj( V3d_Yneg );
278 myView->SetProj( V3d_XposYnegZpos );
288 QApplication::setOverrideCursor( Qt::WaitCursor );
289 myHlrModeIsOn = Standard_False;
290 myView->SetComputedMode (myHlrModeIsOn);
291 QApplication::restoreOverrideCursor();
296 QApplication::setOverrideCursor( Qt::WaitCursor );
297 myHlrModeIsOn = Standard_True;
298 myView->SetComputedMode (myHlrModeIsOn);
299 QApplication::restoreOverrideCursor();
302 void View::updateToggled( bool isOn )
304 QAction* sentBy = (QAction*)sender();
309 for ( int i = ViewFitAllId; i < ViewHlrOffId; i++ )
311 QAction* anAction = myViewActions->at( i );
312 if ( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
313 ( anAction == myViewActions->at( ViewZoomId ) ) ||
314 ( anAction == myViewActions->at( ViewPanId ) ) ||
315 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
316 ( anAction == myViewActions->at( ViewRotationId ) ) )
318 if ( anAction && ( anAction != sentBy ) )
320 anAction->setCheckable( true );
321 anAction->setChecked( false );
325 if ( sentBy == myViewActions->at( ViewFitAreaId ) )
326 setCursor( *handCursor );
327 else if ( sentBy == myViewActions->at( ViewZoomId ) )
328 setCursor( *zoomCursor );
329 else if ( sentBy == myViewActions->at( ViewPanId ) )
330 setCursor( *panCursor );
331 else if ( sentBy == myViewActions->at( ViewGlobalPanId ) )
332 setCursor( *globPanCursor );
333 else if ( sentBy == myViewActions->at( ViewRotationId ) )
334 setCursor( *rotCursor );
336 setCursor( *defCursor );
338 sentBy->setCheckable( false );
344 void View::initCursors()
347 defCursor = new QCursor( Qt::ArrowCursor );
349 handCursor = new QCursor( Qt::PointingHandCursor );
351 panCursor = new QCursor( Qt::SizeAllCursor );
352 if ( !globPanCursor )
353 globPanCursor = new QCursor( Qt::CrossCursor );
355 zoomCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ZOOM" ) ) );
357 rotCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ROTATE" ) ) );
360 QList<QAction*>* View::getViewActions()
363 return myViewActions;
367 Get paint engine for the OpenGL viewer. [ virtual public ]
369 QPaintEngine* View::paintEngine() const
374 void View::initViewActions()
379 myViewActions = new QList<QAction*>();
380 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
383 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITALL") ), QObject::tr("MNU_FITALL"), this );
384 a->setToolTip( QObject::tr("TBR_FITALL") );
385 a->setStatusTip( QObject::tr("TBR_FITALL") );
386 connect( a, SIGNAL( triggered() ) , this, SLOT( fitAll() ) );
387 myViewActions->insert(ViewFitAllId, a);
389 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITAREA") ), QObject::tr("MNU_FITAREA"), this );
390 a->setToolTip( QObject::tr("TBR_FITAREA") );
391 a->setStatusTip( QObject::tr("TBR_FITAREA") );
392 connect( a, SIGNAL( triggered() ) , this, SLOT( fitArea() ) );
394 a->setCheckable( true );
395 connect( a, SIGNAL( toggled( bool ) ) , this, SLOT( updateToggled( bool ) ) );
396 myViewActions->insert( ViewFitAreaId, a );
398 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ZOOM") ), QObject::tr("MNU_ZOOM"), this );
399 a->setToolTip( QObject::tr("TBR_ZOOM") );
400 a->setStatusTip( QObject::tr("TBR_ZOOM") );
401 connect( a, SIGNAL( triggered() ) , this, SLOT( zoom() ) );
403 a->setCheckable( true );
404 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
405 myViewActions->insert( ViewZoomId, a );
407 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_PAN") ), QObject::tr("MNU_PAN"), this );
408 a->setToolTip( QObject::tr("TBR_PAN") );
409 a->setStatusTip( QObject::tr("TBR_PAN") );
410 connect( a, SIGNAL( triggered() ) , this, SLOT( pan() ) );
412 a->setCheckable( true );
413 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
414 myViewActions->insert( ViewPanId, a );
416 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_GLOBALPAN") ), QObject::tr("MNU_GLOBALPAN"), this );
417 a->setToolTip( QObject::tr("TBR_GLOBALPAN") );
418 a->setStatusTip( QObject::tr("TBR_GLOBALPAN") );
419 connect( a, SIGNAL( triggered() ) , this, SLOT( globalPan() ) );
421 a->setCheckable( true );
422 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
423 myViewActions->insert( ViewGlobalPanId, a );
425 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FRONT") ), QObject::tr("MNU_FRONT"), this );
426 a->setToolTip( QObject::tr("TBR_FRONT") );
427 a->setStatusTip( QObject::tr("TBR_FRONT") );
428 connect( a, SIGNAL( triggered() ) , this, SLOT( front() ) );
429 myViewActions->insert( ViewFrontId, a );
431 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BACK") ), QObject::tr("MNU_BACK"), this );
432 a->setToolTip( QObject::tr("TBR_BACK") );
433 a->setStatusTip( QObject::tr("TBR_BACK") );
434 connect( a, SIGNAL( triggered() ) , this, SLOT( back() ) );
435 myViewActions->insert(ViewBackId, a);
437 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_TOP") ), QObject::tr("MNU_TOP"), this );
438 a->setToolTip( QObject::tr("TBR_TOP") );
439 a->setStatusTip( QObject::tr("TBR_TOP") );
440 connect( a, SIGNAL( triggered() ) , this, SLOT( top() ) );
441 myViewActions->insert( ViewTopId, a );
443 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BOTTOM") ), QObject::tr("MNU_BOTTOM"), this );
444 a->setToolTip( QObject::tr("TBR_BOTTOM") );
445 a->setStatusTip( QObject::tr("TBR_BOTTOM") );
446 connect( a, SIGNAL( triggered() ) , this, SLOT( bottom() ) );
447 myViewActions->insert( ViewBottomId, a );
449 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_LEFT") ), QObject::tr("MNU_LEFT"), this );
450 a->setToolTip( QObject::tr("TBR_LEFT") );
451 a->setStatusTip( QObject::tr("TBR_LEFT") );
452 connect( a, SIGNAL( triggered() ) , this, SLOT( left() ) );
453 myViewActions->insert( ViewLeftId, a );
455 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RIGHT") ), QObject::tr("MNU_RIGHT"), this );
456 a->setToolTip( QObject::tr("TBR_RIGHT") );
457 a->setStatusTip( QObject::tr("TBR_RIGHT") );
458 connect( a, SIGNAL( triggered() ) , this, SLOT( right() ) );
459 myViewActions->insert( ViewRightId, a );
461 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_AXO") ), QObject::tr("MNU_AXO"), this );
462 a->setToolTip( QObject::tr("TBR_AXO") );
463 a->setStatusTip( QObject::tr("TBR_AXO") );
464 connect( a, SIGNAL( triggered() ) , this, SLOT( axo() ) );
465 myViewActions->insert( ViewAxoId, a );
467 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ROTATION") ), QObject::tr("MNU_ROTATION"), this );
468 a->setToolTip( QObject::tr("TBR_ROTATION") );
469 a->setStatusTip( QObject::tr("TBR_ROTATION") );
470 connect( a, SIGNAL( triggered() ) , this, SLOT( rotation() ) );
471 a->setCheckable( true );
472 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
473 myViewActions->insert( ViewRotationId, a );
475 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RESET") ), QObject::tr("MNU_RESET"), this );
476 a->setToolTip( QObject::tr("TBR_RESET") );
477 a->setStatusTip( QObject::tr("TBR_RESET") );
478 connect( a, SIGNAL( triggered() ) , this, SLOT( reset() ) );
479 myViewActions->insert( ViewResetId, a );
481 QActionGroup* ag = new QActionGroup( this );
483 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLROFF") ), QObject::tr("MNU_HLROFF"), this );
484 a->setToolTip( QObject::tr("TBR_HLROFF") );
485 a->setStatusTip( QObject::tr("TBR_HLROFF") );
486 connect( a, SIGNAL( triggered() ) , this, SLOT( hlrOff() ) );
487 a->setCheckable( true );
489 myViewActions->insert(ViewHlrOffId, a);
491 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_HLRON"), this );
492 a->setToolTip( QObject::tr("TBR_HLRON") );
493 a->setStatusTip( QObject::tr("TBR_HLRON") );
494 connect( a, SIGNAL( triggered() ) ,this, SLOT( hlrOn() ) );
496 a->setCheckable( true );
498 myViewActions->insert( ViewHlrOnId, a );
501 void View::mousePressEvent( QMouseEvent* e )
503 if ( e->button() == Qt::LeftButton )
504 onLButtonDown( ( e->buttons() | e->modifiers() ), e->pos() );
505 else if ( e->button() == Qt::MidButton )
506 onMButtonDown( e->buttons() | e->modifiers(), e->pos() );
507 else if ( e->button() == Qt::RightButton )
508 onRButtonDown( e->buttons() | e->modifiers(), e->pos() );
511 void View::mouseReleaseEvent(QMouseEvent* e)
513 if ( e->button() == Qt::LeftButton )
514 onLButtonUp( e->buttons(), e->pos() );
515 else if ( e->button() == Qt::MidButton )
516 onMButtonUp( e->buttons(), e->pos() );
517 else if( e->button() == Qt::RightButton )
518 onRButtonUp( e->buttons(), e->pos() );
521 void View::mouseMoveEvent(QMouseEvent* e)
523 onMouseMove( e->buttons(), e->pos() );
526 void View::activateCursor( const CurrentAction3d mode )
530 case CurAction3d_DynamicPanning:
531 setCursor( *panCursor );
533 case CurAction3d_DynamicZooming:
534 setCursor( *zoomCursor );
536 case CurAction3d_DynamicRotation:
537 setCursor( *rotCursor );
539 case CurAction3d_GlobalPanning:
540 setCursor( *globPanCursor );
542 case CurAction3d_WindowZooming:
543 setCursor( *handCursor );
545 case CurAction3d_Nothing:
547 setCursor( *defCursor );
552 void View::onLButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
554 // save the current mouse coordinate in min
560 if ( nFlags & CASCADESHORTCUTKEY )
562 myCurrentMode = CurAction3d_DynamicZooming;
566 switch ( myCurrentMode )
568 case CurAction3d_Nothing:
569 if ( nFlags & MULTISELECTIONKEY )
570 MultiDragEvent( myXmax, myYmax, -1 );
572 DragEvent( myXmax, myYmax, -1 );
574 case CurAction3d_DynamicZooming:
576 case CurAction3d_WindowZooming:
578 case CurAction3d_DynamicPanning:
580 case CurAction3d_GlobalPanning:
582 case CurAction3d_DynamicRotation:
585 myView->SetComputedMode (Standard_False);
587 myView->StartRotation( point.x(), point.y() );
590 Standard_Failure::Raise( "incompatible Current Mode" );
594 activateCursor( myCurrentMode );
597 void View::onMButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint /*point*/ )
599 if ( nFlags & CASCADESHORTCUTKEY )
600 myCurrentMode = CurAction3d_DynamicPanning;
601 activateCursor( myCurrentMode );
604 void View::onRButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
606 if ( nFlags & CASCADESHORTCUTKEY )
610 myView->SetComputedMode (Standard_False);
612 myCurrentMode = CurAction3d_DynamicRotation;
613 myView->StartRotation( point.x(), point.y() );
617 Popup( point.x(), point.y() );
619 activateCursor( myCurrentMode );
622 void View::onLButtonUp( Qt::MouseButtons nFlags, const QPoint point )
624 switch( myCurrentMode )
626 case CurAction3d_Nothing:
627 if ( point.x() == myXmin && point.y() == myYmin )
629 // no offset between down and up --> selectEvent
632 if ( nFlags & MULTISELECTIONKEY )
633 MultiInputEvent( point.x(), point.y() );
635 InputEvent( point.x(), point.y() );
639 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
642 if ( nFlags & MULTISELECTIONKEY )
643 MultiDragEvent( point.x(), point.y(), 1 );
645 DragEvent( point.x(), point.y(), 1 );
648 case CurAction3d_DynamicZooming:
649 myCurrentMode = CurAction3d_Nothing;
652 case CurAction3d_WindowZooming:
653 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );//,LongDash);
656 if ( (abs( myXmin - myXmax ) > ValZWMin ) ||
657 (abs( myYmin - myYmax ) > ValZWMin ) )
658 myView->WindowFitAll( myXmin, myYmin, myXmax, myYmax );
659 myCurrentMode = CurAction3d_Nothing;
662 case CurAction3d_DynamicPanning:
663 myCurrentMode = CurAction3d_Nothing;
666 case CurAction3d_GlobalPanning :
667 myView->Place( point.x(), point.y(), myCurZoom );
668 myCurrentMode = CurAction3d_Nothing;
671 case CurAction3d_DynamicRotation:
672 myCurrentMode = CurAction3d_Nothing;
676 Standard_Failure::Raise(" incompatible Current Mode ");
679 activateCursor( myCurrentMode );
680 ApplicationCommonWindow::getApplication()->onSelectionChanged();
683 void View::onMButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint /*point*/ )
685 myCurrentMode = CurAction3d_Nothing;
686 activateCursor( myCurrentMode );
689 void View::onRButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint point )
691 if ( myCurrentMode == CurAction3d_Nothing )
692 Popup( point.x(), point.y() );
695 QApplication::setOverrideCursor( Qt::WaitCursor );
696 // reset tyhe good Degenerated mode according to the strored one
697 // --> dynamic rotation may have change it
698 myView->SetComputedMode (myHlrModeIsOn);
699 QApplication::restoreOverrideCursor();
700 myCurrentMode = CurAction3d_Nothing;
702 activateCursor( myCurrentMode );
705 void View::onMouseMove( Qt::MouseButtons nFlags, const QPoint point )
707 if ( nFlags & Qt::LeftButton || nFlags & Qt::RightButton || nFlags & Qt::MidButton )
709 switch ( myCurrentMode )
711 case CurAction3d_Nothing:
714 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
715 if ( nFlags & MULTISELECTIONKEY )
716 MultiDragEvent( myXmax, myYmax, 0 );
718 DragEvent( myXmax, myYmax, 0 );
719 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
721 case CurAction3d_DynamicZooming:
722 myView->Zoom( myXmax, myYmax, point.x(), point.y() );
726 case CurAction3d_WindowZooming:
729 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
730 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
732 case CurAction3d_DynamicPanning:
733 myView->Pan( point.x() - myXmax, myYmax - point.y() );
737 case CurAction3d_GlobalPanning:
739 case CurAction3d_DynamicRotation:
740 myView->Rotation( point.x(), point.y() );
744 Standard_Failure::Raise( "incompatible Current Mode" );
752 if ( nFlags & MULTISELECTIONKEY )
753 MultiMoveEvent( point.x(), point.y() );
755 MoveEvent( point.x(), point.y() );
759 void View::DragEvent( const int x, const int y, const int TheState )
761 // TheState == -1 button down
762 // TheState == 0 move
763 // TheState == 1 button up
765 static Standard_Integer theButtonDownX = 0;
766 static Standard_Integer theButtonDownY = 0;
768 if ( TheState == -1 )
776 myContext->Select( theButtonDownX, theButtonDownY, x, y, myView );
777 emit selectionChanged();
781 void View::InputEvent( const int /*x*/, const int /*y*/ )
784 emit selectionChanged();
787 void View::MoveEvent( const int x, const int y )
789 myContext->MoveTo( x, y, myView );
792 void View::MultiMoveEvent( const int x, const int y )
794 myContext->MoveTo( x, y, myView );
797 void View::MultiDragEvent( const int x, const int y, const int TheState )
799 static Standard_Integer theButtonDownX = 0;
800 static Standard_Integer theButtonDownY = 0;
802 if ( TheState == -1 )
809 myContext->ShiftSelect( theButtonDownX, theButtonDownY, x, y, myView );
810 emit selectionChanged();
814 void View::MultiInputEvent( const int /*x*/, const int /*y*/ )
816 myContext->ShiftSelect();
817 emit selectionChanged();
820 void View::Popup( const int /*x*/, const int /*y*/ )
822 ApplicationCommonWindow* stApp = ApplicationCommonWindow::getApplication();
823 QWorkspace* ws = ApplicationCommonWindow::getWorkspace();
824 QWidget* w = ws->activeWindow();
825 if ( myContext->NbSelected() )
827 QList<QAction*>* aList = stApp->getToolActions();
828 QMenu* myToolMenu = new QMenu( 0 );
829 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolWireframeId ) );
830 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolShadingId ) );
831 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolColorId ) );
833 QMenu* myMaterMenu = new QMenu( myToolMenu );
835 QList<QAction*>* aMeterActions = ApplicationCommonWindow::getApplication()->getMaterialActions();
837 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
838 myMaterMenu = myToolMenu->addMenu( QPixmap( dir+QObject::tr("ICON_TOOL_MATER")), QObject::tr("MNU_MATER") );
839 for ( int i = 0; i < aMeterActions->size(); i++ )
840 myMaterMenu->addAction( aMeterActions->at( i ) );
842 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolTransparencyId ) );
843 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolDeleteId ) );
844 addItemInPopup(myToolMenu);
845 myToolMenu->exec( QCursor::pos() );
850 QMenu* myBackMenu = new QMenu( 0 );
851 QAction* a = new QAction( QObject::tr("MNU_CH_BACK"), this );
852 a->setToolTip( QObject::tr("TBR_CH_BACK") );
853 connect( a,SIGNAL( triggered() ), this, SLOT( onBackground() ) );
854 myBackMenu->addAction( a );
855 addItemInPopup(myBackMenu);
856 myBackMenu->exec( QCursor::pos() );
863 void View::addItemInPopup( QMenu* /*theMenu*/)
867 void View::DrawRectangle(const int MinX, const int MinY,
868 const int MaxX, const int MaxY, const bool Draw)
870 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
871 static Standard_Boolean m_IsVisible;
873 StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
874 StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
875 StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
876 StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;
879 aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
883 myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
884 myRectBand->setStyle(new QWindowsStyle);
885 myRectBand->setGeometry( aRect );
889 palette.setColor(myRectBand->foregroundRole(), Qt::white);
890 myRectBand->setPalette(palette);*/
893 if ( m_IsVisible && !Draw ) // move or up : erase at the old position
901 if (Draw) // move : draw
903 //aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
905 myRectBand->setGeometry( aRect );
906 //myRectBand->show();
910 void View::noActiveActions()
912 for ( int i = ViewFitAllId; i < ViewHlrOffId ; i++ )
914 QAction* anAction = myViewActions->at( i );
915 if( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
916 ( anAction == myViewActions->at( ViewZoomId ) ) ||
917 ( anAction == myViewActions->at( ViewPanId ) ) ||
918 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
919 ( anAction == myViewActions->at( ViewRotationId ) ) )
921 setCursor( *defCursor );
922 anAction->setCheckable( true );
923 anAction->setChecked( false );
928 void View::onBackground()
934 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
935 aColor.setRgb(R1*255,G1*255,B1*255);
937 QColor aRetColor = QColorDialog::getColor(aColor);
939 if( aRetColor.isValid() )
941 R1 = aRetColor.red()/255.;
942 G1 = aRetColor.green()/255.;
943 B1 = aRetColor.blue()/255.;
944 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
949 bool View::dump(Standard_CString theFile)
952 QString ext = QFileInfo( QString( theFile ) ).completeSuffix();
953 if ( !ext.compare("ps") || !ext.compare("eps") || !ext.compare("tex") || !ext.compare("pdf") || !ext.compare("svg") || !ext.compare("pgf") )
955 Graphic3d_ExportFormat exFormat;
956 if ( !ext.compare("ps") )
957 exFormat = Graphic3d_EF_PostScript;
958 if ( !ext.compare("eps") )
959 exFormat = Graphic3d_EF_EnhPostScript;
960 if ( !ext.compare("tex") )
961 exFormat = Graphic3d_EF_TEX;
962 if ( !ext.compare("pdf") )
963 exFormat = Graphic3d_EF_PDF;
964 if ( !ext.compare("svg") )
965 exFormat = Graphic3d_EF_SVG;
966 if ( !ext.compare("pgf") )
967 exFormat = Graphic3d_EF_PGF;
970 myView->View()->Export( theFile, exFormat );
978 return myView->Dump(theFile);
981 Handle(V3d_View)& View::getView()
986 Handle(AIS_InteractiveContext)& View::getContext()
991 View::CurrentAction3d View::getCurrentMode()
993 return myCurrentMode;