2 #define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */
6 #include "ApplicationCommon.h"
8 #include <QApplication>
11 #include <QColorDialog>
14 #include <QFileDialog>
15 #include <QMouseEvent>
16 #include <QRubberBand>
17 #include <QMdiSubWindow>
18 #include <QStyleFactory>
20 #include <Graphic3d_ExportFormat.hxx>
21 #include <Graphic3d_GraphicDriver.hxx>
22 #include <Graphic3d_TextureEnv.hxx>
24 #if defined(_WIN32) || defined(__WIN32__)
25 #include <WNT_Window.hxx>
26 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
27 #include <Cocoa_Window.hxx>
31 #include <X11/Xutil.h>
32 #include <X11/Xatom.h>
34 #include <Xw_Window.hxx>
38 #include <Aspect_DisplayConnection.hxx>
40 // the key for multi selection :
41 #define MULTISELECTIONKEY Qt::ShiftModifier
43 // the key for shortcut ( use to activate dynamic rotation, panning )
44 #define CASCADESHORTCUTKEY Qt::ControlModifier
46 // for elastic bean selection
49 static QCursor* defCursor = NULL;
50 static QCursor* handCursor = NULL;
51 static QCursor* panCursor = NULL;
52 static QCursor* globPanCursor = NULL;
53 static QCursor* zoomCursor = NULL;
54 static QCursor* rotCursor = NULL;
56 View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent )
58 myIsRaytracing( false ),
59 myIsShadowsEnabled (true),
60 myIsReflectionsEnabled (false),
61 myIsAntialiasingEnabled (false),
63 myRaytraceActions( 0 ),
66 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
67 //XSynchronize( x11Display(),true ); // it is possible to use QApplication::syncX();
68 XSynchronize( x11Info().display(),true ); // it is possible to use QApplication::syncX();
72 myContext = theContext;
81 setAttribute(Qt::WA_PaintOnScreen);
82 setAttribute(Qt::WA_NoSystemBackground);
84 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
85 XVisualInfo* pVisualInfo;
86 if ( x11Info().display() )
88 /* Initialization with the default VisualID */
89 Visual *v = DefaultVisual( x11Info().display(), DefaultScreen( x11Info().display() ) );
90 int visualID = XVisualIDFromVisual( v );
92 /* Here we use the settings from Optimizer_ViewInfo::TxglCreateWindow() */
93 int visualAttr[] = { GLX_RGBA, GLX_DEPTH_SIZE, 1, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
94 GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None };
95 pVisualInfo = ::glXChooseVisual( x11Info().display(), DefaultScreen( x11Info().display() ), visualAttr );
100 XSetWindowAttributes a;
102 Window p = RootWindow( x11Info().display(), DefaultScreen( x11Info().display() ) );
103 a.colormap = XCreateColormap( x11Info().display(), RootWindow( x11Info().display(), pVisualInfo->screen ),
104 pVisualInfo->visual, AllocNone );
106 QColor color = palette().color( backgroundRole() );
107 QColormap colmap = QColormap::instance();
108 a.background_pixel = colmap.pixel( color );
109 a.border_pixel = colmap.pixel( Qt::black );
110 if ( parentWidget() )
111 p = parentWidget()->winId();
113 Window w = XCreateWindow( x11Info().display(), p, x(), y(), width(), height(),
114 0, pVisualInfo->depth, InputOutput, pVisualInfo->visual,
115 CWBackPixel | CWBorderPixel | CWColormap, &a );
119 if ( XGetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), &cmwret, &count ) )
121 cmw = new Window[count+1];
122 memcpy( (char *)cmw, (char *)cmwret, sizeof(Window)*count );
123 XFree( (char *)cmwret );
125 for ( i = 0; i < count; i++ )
127 if ( cmw[i] == winId() ) /* replace old window */
133 if ( i >= count ) /* append new window */
139 cmw = new Window[count];
142 /* Creating new window (with good VisualID) for this widget */
144 XSetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), cmw, count );
150 XFree( (char *)pVisualInfo );
151 XFlush( x11Info().display() );
155 myCurrentMode = CurAction3d_Nothing;
156 myHlrModeIsOn = Standard_False;
157 setMouseTracking( true );
162 setBackgroundRole( QPalette::NoRole );//NoBackground );
163 // set focus policy to threat QContextMenuEvent from keyboard
164 setFocusPolicy( Qt::StrongFocus );
165 setAttribute( Qt::WA_PaintOnScreen );
166 setAttribute( Qt::WA_NoSystemBackground );
177 if ( myView.IsNull() )
178 myView = myContext->CurrentViewer()->CreateView();
180 #if defined(_WIN32) || defined(__WIN32__)
181 Aspect_Handle aWindowHandle = (Aspect_Handle )winId();
182 Handle(WNT_Window) hWnd = new WNT_Window (aWindowHandle);
183 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
184 NSView* aViewHandle = (NSView* )winId();
185 Handle(Cocoa_Window) hWnd = new Cocoa_Window (aViewHandle);
187 Window aWindowHandle = (Window )winId();
188 Handle(Aspect_DisplayConnection) aDispConnection = myContext->CurrentViewer()->Driver()->GetDisplayConnection();
189 Handle(Xw_Window) hWnd = new Xw_Window (aDispConnection, aWindowHandle);
192 myView->SetWindow (hWnd);
193 if ( !hWnd->IsMapped() )
197 myView->SetBackgroundColor (Quantity_NOC_BLACK);
198 myView->MustBeResized();
201 myView->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
204 void View::paintEvent( QPaintEvent * )
206 // QApplication::syncX();
215 void View::resizeEvent( QResizeEvent * )
217 // QApplication::syncX();
218 if( !myView.IsNull() )
220 myView->MustBeResized();
233 myCurrentMode = CurAction3d_WindowZooming;
238 myCurrentMode = CurAction3d_DynamicZooming;
243 myCurrentMode = CurAction3d_DynamicPanning;
246 void View::rotation()
248 myCurrentMode = CurAction3d_DynamicRotation;
251 void View::globalPan()
253 // save the current zoom value
254 myCurZoom = myView->Scale();
258 myCurrentMode = CurAction3d_GlobalPanning;
263 myView->SetProj( V3d_Xpos );
268 myView->SetProj( V3d_Xneg );
273 myView->SetProj( V3d_Zpos );
278 myView->SetProj( V3d_Zneg );
283 myView->SetProj( V3d_Ypos );
288 myView->SetProj( V3d_Yneg );
293 myView->SetProj( V3d_XposYnegZpos );
303 QApplication::setOverrideCursor( Qt::WaitCursor );
304 myHlrModeIsOn = Standard_False;
305 myView->SetComputedMode (myHlrModeIsOn);
306 QApplication::restoreOverrideCursor();
311 QApplication::setOverrideCursor( Qt::WaitCursor );
312 myHlrModeIsOn = Standard_True;
313 myView->SetComputedMode (myHlrModeIsOn);
314 QApplication::restoreOverrideCursor();
317 void View::SetRaytracedShadows (bool theState)
319 myView->ChangeRenderingParams().IsShadowEnabled = theState;
321 myIsShadowsEnabled = theState;
323 myContext->UpdateCurrentViewer();
326 void View::SetRaytracedReflections (bool theState)
328 myView->ChangeRenderingParams().IsReflectionEnabled = theState;
330 myIsReflectionsEnabled = theState;
332 myContext->UpdateCurrentViewer();
335 void View::onRaytraceAction()
337 QAction* aSentBy = (QAction*)sender();
339 if (aSentBy == myRaytraceActions->at (ToolRaytracingId))
341 bool aState = myRaytraceActions->at (ToolRaytracingId)->isChecked();
343 QApplication::setOverrideCursor (Qt::WaitCursor);
348 QApplication::restoreOverrideCursor();
351 if (aSentBy == myRaytraceActions->at (ToolShadowsId))
353 bool aState = myRaytraceActions->at (ToolShadowsId)->isChecked();
354 SetRaytracedShadows (aState);
357 if (aSentBy == myRaytraceActions->at (ToolReflectionsId))
359 bool aState = myRaytraceActions->at (ToolReflectionsId)->isChecked();
360 SetRaytracedReflections (aState);
363 if (aSentBy == myRaytraceActions->at (ToolAntialiasingId))
365 bool aState = myRaytraceActions->at (ToolAntialiasingId)->isChecked();
366 SetRaytracedAntialiasing (aState);
370 void View::SetRaytracedAntialiasing (bool theState)
372 myView->ChangeRenderingParams().IsAntialiasingEnabled = theState;
374 myIsAntialiasingEnabled = theState;
376 myContext->UpdateCurrentViewer();
379 void View::EnableRaytracing()
382 myView->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
384 myIsRaytracing = true;
386 myContext->UpdateCurrentViewer();
389 void View::DisableRaytracing()
392 myView->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION;
394 myIsRaytracing = false;
396 myContext->UpdateCurrentViewer();
399 void View::updateToggled( bool isOn )
401 QAction* sentBy = (QAction*)sender();
406 for ( int i = ViewFitAllId; i < ViewHlrOffId; i++ )
408 QAction* anAction = myViewActions->at( i );
410 if ( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
411 ( anAction == myViewActions->at( ViewZoomId ) ) ||
412 ( anAction == myViewActions->at( ViewPanId ) ) ||
413 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
414 ( anAction == myViewActions->at( ViewRotationId ) ) )
416 if ( anAction && ( anAction != sentBy ) )
418 anAction->setCheckable( true );
419 anAction->setChecked( false );
423 if ( sentBy == myViewActions->at( ViewFitAreaId ) )
424 setCursor( *handCursor );
425 else if ( sentBy == myViewActions->at( ViewZoomId ) )
426 setCursor( *zoomCursor );
427 else if ( sentBy == myViewActions->at( ViewPanId ) )
428 setCursor( *panCursor );
429 else if ( sentBy == myViewActions->at( ViewGlobalPanId ) )
430 setCursor( *globPanCursor );
431 else if ( sentBy == myViewActions->at( ViewRotationId ) )
432 setCursor( *rotCursor );
434 setCursor( *defCursor );
436 sentBy->setCheckable( false );
442 void View::initCursors()
445 defCursor = new QCursor( Qt::ArrowCursor );
447 handCursor = new QCursor( Qt::PointingHandCursor );
449 panCursor = new QCursor( Qt::SizeAllCursor );
450 if ( !globPanCursor )
451 globPanCursor = new QCursor( Qt::CrossCursor );
453 zoomCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ZOOM" ) ) );
455 rotCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ROTATE" ) ) );
458 QList<QAction*>* View::getViewActions()
461 return myViewActions;
464 QList<QAction*>* View::getRaytraceActions()
466 initRaytraceActions();
467 return myRaytraceActions;
471 Get paint engine for the OpenGL viewer. [ virtual public ]
473 QPaintEngine* View::paintEngine() const
478 void View::initViewActions()
483 myViewActions = new QList<QAction*>();
484 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
487 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITALL") ), QObject::tr("MNU_FITALL"), this );
488 a->setToolTip( QObject::tr("TBR_FITALL") );
489 a->setStatusTip( QObject::tr("TBR_FITALL") );
490 connect( a, SIGNAL( triggered() ) , this, SLOT( fitAll() ) );
491 myViewActions->insert(ViewFitAllId, a);
493 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITAREA") ), QObject::tr("MNU_FITAREA"), this );
494 a->setToolTip( QObject::tr("TBR_FITAREA") );
495 a->setStatusTip( QObject::tr("TBR_FITAREA") );
496 connect( a, SIGNAL( triggered() ) , this, SLOT( fitArea() ) );
498 a->setCheckable( true );
499 connect( a, SIGNAL( toggled( bool ) ) , this, SLOT( updateToggled( bool ) ) );
500 myViewActions->insert( ViewFitAreaId, a );
502 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ZOOM") ), QObject::tr("MNU_ZOOM"), this );
503 a->setToolTip( QObject::tr("TBR_ZOOM") );
504 a->setStatusTip( QObject::tr("TBR_ZOOM") );
505 connect( a, SIGNAL( triggered() ) , this, SLOT( zoom() ) );
507 a->setCheckable( true );
508 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
509 myViewActions->insert( ViewZoomId, a );
511 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_PAN") ), QObject::tr("MNU_PAN"), this );
512 a->setToolTip( QObject::tr("TBR_PAN") );
513 a->setStatusTip( QObject::tr("TBR_PAN") );
514 connect( a, SIGNAL( triggered() ) , this, SLOT( pan() ) );
516 a->setCheckable( true );
517 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
518 myViewActions->insert( ViewPanId, a );
520 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_GLOBALPAN") ), QObject::tr("MNU_GLOBALPAN"), this );
521 a->setToolTip( QObject::tr("TBR_GLOBALPAN") );
522 a->setStatusTip( QObject::tr("TBR_GLOBALPAN") );
523 connect( a, SIGNAL( triggered() ) , this, SLOT( globalPan() ) );
525 a->setCheckable( true );
526 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
527 myViewActions->insert( ViewGlobalPanId, a );
529 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FRONT") ), QObject::tr("MNU_FRONT"), this );
530 a->setToolTip( QObject::tr("TBR_FRONT") );
531 a->setStatusTip( QObject::tr("TBR_FRONT") );
532 connect( a, SIGNAL( triggered() ) , this, SLOT( front() ) );
533 myViewActions->insert( ViewFrontId, a );
535 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BACK") ), QObject::tr("MNU_BACK"), this );
536 a->setToolTip( QObject::tr("TBR_BACK") );
537 a->setStatusTip( QObject::tr("TBR_BACK") );
538 connect( a, SIGNAL( triggered() ) , this, SLOT( back() ) );
539 myViewActions->insert(ViewBackId, a);
541 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_TOP") ), QObject::tr("MNU_TOP"), this );
542 a->setToolTip( QObject::tr("TBR_TOP") );
543 a->setStatusTip( QObject::tr("TBR_TOP") );
544 connect( a, SIGNAL( triggered() ) , this, SLOT( top() ) );
545 myViewActions->insert( ViewTopId, a );
547 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BOTTOM") ), QObject::tr("MNU_BOTTOM"), this );
548 a->setToolTip( QObject::tr("TBR_BOTTOM") );
549 a->setStatusTip( QObject::tr("TBR_BOTTOM") );
550 connect( a, SIGNAL( triggered() ) , this, SLOT( bottom() ) );
551 myViewActions->insert( ViewBottomId, a );
553 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_LEFT") ), QObject::tr("MNU_LEFT"), this );
554 a->setToolTip( QObject::tr("TBR_LEFT") );
555 a->setStatusTip( QObject::tr("TBR_LEFT") );
556 connect( a, SIGNAL( triggered() ) , this, SLOT( left() ) );
557 myViewActions->insert( ViewLeftId, a );
559 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RIGHT") ), QObject::tr("MNU_RIGHT"), this );
560 a->setToolTip( QObject::tr("TBR_RIGHT") );
561 a->setStatusTip( QObject::tr("TBR_RIGHT") );
562 connect( a, SIGNAL( triggered() ) , this, SLOT( right() ) );
563 myViewActions->insert( ViewRightId, a );
565 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_AXO") ), QObject::tr("MNU_AXO"), this );
566 a->setToolTip( QObject::tr("TBR_AXO") );
567 a->setStatusTip( QObject::tr("TBR_AXO") );
568 connect( a, SIGNAL( triggered() ) , this, SLOT( axo() ) );
569 myViewActions->insert( ViewAxoId, a );
571 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ROTATION") ), QObject::tr("MNU_ROTATION"), this );
572 a->setToolTip( QObject::tr("TBR_ROTATION") );
573 a->setStatusTip( QObject::tr("TBR_ROTATION") );
574 connect( a, SIGNAL( triggered() ) , this, SLOT( rotation() ) );
575 a->setCheckable( true );
576 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
577 myViewActions->insert( ViewRotationId, a );
579 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RESET") ), QObject::tr("MNU_RESET"), this );
580 a->setToolTip( QObject::tr("TBR_RESET") );
581 a->setStatusTip( QObject::tr("TBR_RESET") );
582 connect( a, SIGNAL( triggered() ) , this, SLOT( reset() ) );
583 myViewActions->insert( ViewResetId, a );
585 QActionGroup* ag = new QActionGroup( this );
587 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLROFF") ), QObject::tr("MNU_HLROFF"), this );
588 a->setToolTip( QObject::tr("TBR_HLROFF") );
589 a->setStatusTip( QObject::tr("TBR_HLROFF") );
590 connect( a, SIGNAL( triggered() ) , this, SLOT( hlrOff() ) );
591 a->setCheckable( true );
593 myViewActions->insert(ViewHlrOffId, a);
595 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_HLRON"), this );
596 a->setToolTip( QObject::tr("TBR_HLRON") );
597 a->setStatusTip( QObject::tr("TBR_HLRON") );
598 connect( a, SIGNAL( triggered() ) ,this, SLOT( hlrOn() ) );
600 a->setCheckable( true );
602 myViewActions->insert( ViewHlrOnId, a );
605 void View::initRaytraceActions()
607 if ( myRaytraceActions )
610 myRaytraceActions = new QList<QAction*>();
611 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
614 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_RAYTRACING") ), QObject::tr("MNU_TOOL_RAYTRACING"), this );
615 a->setToolTip( QObject::tr("TBR_TOOL_RAYTRACING") );
616 a->setStatusTip( QObject::tr("TBR_TOOL_RAYTRACING") );
617 a->setCheckable( true );
618 a->setChecked( false );
619 connect( a, SIGNAL( activated() ) , this, SLOT( onRaytraceAction() ) );
620 myRaytraceActions->insert( ToolRaytracingId, a );
622 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_SHADOWS") ), QObject::tr("MNU_TOOL_SHADOWS"), this );
623 a->setToolTip( QObject::tr("TBR_TOOL_SHADOWS") );
624 a->setStatusTip( QObject::tr("TBR_TOOL_SHADOWS") );
625 a->setCheckable( true );
626 a->setChecked( true );
627 connect( a, SIGNAL( activated() ) , this, SLOT( onRaytraceAction() ) );
628 myRaytraceActions->insert( ToolShadowsId, a );
630 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_REFLECTIONS") ), QObject::tr("MNU_TOOL_REFLECTIONS"), this );
631 a->setToolTip( QObject::tr("TBR_TOOL_REFLECTIONS") );
632 a->setStatusTip( QObject::tr("TBR_TOOL_REFLECTIONS") );
633 a->setCheckable( true );
634 a->setChecked( false );
635 connect( a, SIGNAL( activated() ) , this, SLOT( onRaytraceAction() ) );
636 myRaytraceActions->insert( ToolReflectionsId, a );
638 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_ANTIALIASING") ), QObject::tr("MNU_TOOL_ANTIALIASING"), this );
639 a->setToolTip( QObject::tr("TBR_TOOL_ANTIALIASING") );
640 a->setStatusTip( QObject::tr("TBR_TOOL_ANTIALIASING") );
641 a->setCheckable( true );
642 a->setChecked( false );
643 connect( a, SIGNAL( activated() ) , this, SLOT( onRaytraceAction() ) );
644 myRaytraceActions->insert( ToolAntialiasingId, a );
647 void View::mousePressEvent( QMouseEvent* e )
649 if ( e->button() == Qt::LeftButton )
650 onLButtonDown( ( e->buttons() | e->modifiers() ), e->pos() );
651 else if ( e->button() == Qt::MidButton )
652 onMButtonDown( e->buttons() | e->modifiers(), e->pos() );
653 else if ( e->button() == Qt::RightButton )
654 onRButtonDown( e->buttons() | e->modifiers(), e->pos() );
657 void View::mouseReleaseEvent(QMouseEvent* e)
659 if ( e->button() == Qt::LeftButton )
660 onLButtonUp( e->buttons(), e->pos() );
661 else if ( e->button() == Qt::MidButton )
662 onMButtonUp( e->buttons(), e->pos() );
663 else if( e->button() == Qt::RightButton )
664 onRButtonUp( e->buttons(), e->pos() );
667 void View::mouseMoveEvent(QMouseEvent* e)
669 onMouseMove( e->buttons(), e->pos() );
672 void View::activateCursor( const CurrentAction3d mode )
676 case CurAction3d_DynamicPanning:
677 setCursor( *panCursor );
679 case CurAction3d_DynamicZooming:
680 setCursor( *zoomCursor );
682 case CurAction3d_DynamicRotation:
683 setCursor( *rotCursor );
685 case CurAction3d_GlobalPanning:
686 setCursor( *globPanCursor );
688 case CurAction3d_WindowZooming:
689 setCursor( *handCursor );
691 case CurAction3d_Nothing:
693 setCursor( *defCursor );
698 void View::onLButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
700 // save the current mouse coordinate in min
706 if ( nFlags & CASCADESHORTCUTKEY )
708 myCurrentMode = CurAction3d_DynamicZooming;
712 switch ( myCurrentMode )
714 case CurAction3d_Nothing:
715 if ( nFlags & MULTISELECTIONKEY )
716 MultiDragEvent( myXmax, myYmax, -1 );
718 DragEvent( myXmax, myYmax, -1 );
720 case CurAction3d_DynamicZooming:
722 case CurAction3d_WindowZooming:
724 case CurAction3d_DynamicPanning:
726 case CurAction3d_GlobalPanning:
728 case CurAction3d_DynamicRotation:
731 myView->SetComputedMode (Standard_False);
733 myView->StartRotation( point.x(), point.y() );
736 Standard_Failure::Raise( "incompatible Current Mode" );
740 activateCursor( myCurrentMode );
743 void View::onMButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint /*point*/ )
745 if ( nFlags & CASCADESHORTCUTKEY )
746 myCurrentMode = CurAction3d_DynamicPanning;
747 activateCursor( myCurrentMode );
750 void View::onRButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
752 if ( nFlags & CASCADESHORTCUTKEY )
756 myView->SetComputedMode (Standard_False);
758 myCurrentMode = CurAction3d_DynamicRotation;
759 myView->StartRotation( point.x(), point.y() );
763 Popup( point.x(), point.y() );
765 activateCursor( myCurrentMode );
768 void View::onLButtonUp( Qt::MouseButtons nFlags, const QPoint point )
770 switch( myCurrentMode )
772 case CurAction3d_Nothing:
773 if ( point.x() == myXmin && point.y() == myYmin )
775 // no offset between down and up --> selectEvent
778 if ( nFlags & MULTISELECTIONKEY )
779 MultiInputEvent( point.x(), point.y() );
781 InputEvent( point.x(), point.y() );
785 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
788 if ( nFlags & MULTISELECTIONKEY )
789 MultiDragEvent( point.x(), point.y(), 1 );
791 DragEvent( point.x(), point.y(), 1 );
794 case CurAction3d_DynamicZooming:
795 myCurrentMode = CurAction3d_Nothing;
798 case CurAction3d_WindowZooming:
799 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );//,LongDash);
802 if ( (abs( myXmin - myXmax ) > ValZWMin ) ||
803 (abs( myYmin - myYmax ) > ValZWMin ) )
804 myView->WindowFitAll( myXmin, myYmin, myXmax, myYmax );
805 myCurrentMode = CurAction3d_Nothing;
808 case CurAction3d_DynamicPanning:
809 myCurrentMode = CurAction3d_Nothing;
812 case CurAction3d_GlobalPanning :
813 myView->Place( point.x(), point.y(), myCurZoom );
814 myCurrentMode = CurAction3d_Nothing;
817 case CurAction3d_DynamicRotation:
818 myCurrentMode = CurAction3d_Nothing;
822 Standard_Failure::Raise(" incompatible Current Mode ");
825 activateCursor( myCurrentMode );
826 ApplicationCommonWindow::getApplication()->onSelectionChanged();
829 void View::onMButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint /*point*/ )
831 myCurrentMode = CurAction3d_Nothing;
832 activateCursor( myCurrentMode );
835 void View::onRButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint point )
837 if ( myCurrentMode == CurAction3d_Nothing )
838 Popup( point.x(), point.y() );
841 QApplication::setOverrideCursor( Qt::WaitCursor );
842 // reset tyhe good Degenerated mode according to the strored one
843 // --> dynamic rotation may have change it
844 myView->SetComputedMode (myHlrModeIsOn);
845 QApplication::restoreOverrideCursor();
846 myCurrentMode = CurAction3d_Nothing;
848 activateCursor( myCurrentMode );
851 void View::onMouseMove( Qt::MouseButtons nFlags, const QPoint point )
853 if ( nFlags & Qt::LeftButton || nFlags & Qt::RightButton || nFlags & Qt::MidButton )
855 switch ( myCurrentMode )
857 case CurAction3d_Nothing:
860 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
861 if ( nFlags & MULTISELECTIONKEY )
862 MultiDragEvent( myXmax, myYmax, 0 );
864 DragEvent( myXmax, myYmax, 0 );
865 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
867 case CurAction3d_DynamicZooming:
868 myView->Zoom( myXmax, myYmax, point.x(), point.y() );
872 case CurAction3d_WindowZooming:
875 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
876 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
878 case CurAction3d_DynamicPanning:
879 myView->Pan( point.x() - myXmax, myYmax - point.y() );
883 case CurAction3d_GlobalPanning:
885 case CurAction3d_DynamicRotation:
886 myView->Rotation( point.x(), point.y() );
890 Standard_Failure::Raise( "incompatible Current Mode" );
898 if ( nFlags & MULTISELECTIONKEY )
899 MultiMoveEvent( point.x(), point.y() );
901 MoveEvent( point.x(), point.y() );
905 void View::DragEvent( const int x, const int y, const int TheState )
907 // TheState == -1 button down
908 // TheState == 0 move
909 // TheState == 1 button up
911 static Standard_Integer theButtonDownX = 0;
912 static Standard_Integer theButtonDownY = 0;
914 if ( TheState == -1 )
922 myContext->Select( theButtonDownX, theButtonDownY, x, y, myView );
923 emit selectionChanged();
927 void View::InputEvent( const int /*x*/, const int /*y*/ )
930 emit selectionChanged();
933 void View::MoveEvent( const int x, const int y )
935 myContext->MoveTo( x, y, myView );
938 void View::MultiMoveEvent( const int x, const int y )
940 myContext->MoveTo( x, y, myView );
943 void View::MultiDragEvent( const int x, const int y, const int TheState )
945 static Standard_Integer theButtonDownX = 0;
946 static Standard_Integer theButtonDownY = 0;
948 if ( TheState == -1 )
955 myContext->ShiftSelect( theButtonDownX, theButtonDownY, x, y, myView );
956 emit selectionChanged();
960 void View::MultiInputEvent( const int /*x*/, const int /*y*/ )
962 myContext->ShiftSelect();
963 emit selectionChanged();
966 void View::Popup( const int /*x*/, const int /*y*/ )
968 ApplicationCommonWindow* stApp = ApplicationCommonWindow::getApplication();
969 QMdiArea* ws = ApplicationCommonWindow::getWorkspace();
970 QMdiSubWindow* w = ws->activeSubWindow();
971 if ( myContext->NbSelected() )
973 QList<QAction*>* aList = stApp->getToolActions();
974 QMenu* myToolMenu = new QMenu( 0 );
975 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolWireframeId ) );
976 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolShadingId ) );
977 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolColorId ) );
979 QMenu* myMaterMenu = new QMenu( myToolMenu );
981 QList<QAction*>* aMeterActions = ApplicationCommonWindow::getApplication()->getMaterialActions();
983 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
984 myMaterMenu = myToolMenu->addMenu( QPixmap( dir+QObject::tr("ICON_TOOL_MATER")), QObject::tr("MNU_MATER") );
985 for ( int i = 0; i < aMeterActions->size(); i++ )
986 myMaterMenu->addAction( aMeterActions->at( i ) );
988 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolTransparencyId ) );
989 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolDeleteId ) );
990 addItemInPopup(myToolMenu);
991 myToolMenu->exec( QCursor::pos() );
998 myBackMenu = new QMenu( 0 );
1000 QAction* a = new QAction( QObject::tr("MNU_CH_BACK"), this );
1001 a->setToolTip( QObject::tr("TBR_CH_BACK") );
1002 connect( a, SIGNAL( activated() ), this, SLOT( onBackground() ) );
1003 myBackMenu->addAction( a );
1004 addItemInPopup(myBackMenu);
1006 a = new QAction( QObject::tr("MNU_CH_ENV_MAP"), this );
1007 a->setToolTip( QObject::tr("TBR_CH_ENV_MAP") );
1008 connect( a, SIGNAL( activated() ), this, SLOT( onEnvironmentMap() ) );
1009 a->setCheckable( true );
1010 a->setChecked( false );
1011 myBackMenu->addAction( a );
1012 addItemInPopup(myBackMenu);
1015 myBackMenu->exec( QCursor::pos() );
1021 void View::addItemInPopup( QMenu* /*theMenu*/)
1025 void View::DrawRectangle(const int MinX, const int MinY,
1026 const int MaxX, const int MaxY, const bool Draw)
1028 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
1029 static Standard_Boolean m_IsVisible;
1031 StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
1032 StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
1033 StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
1034 StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;
1037 aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
1041 myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
1042 myRectBand->setStyle( QStyleFactory::create("windows") );
1043 myRectBand->setGeometry( aRect );
1047 palette.setColor(myRectBand->foregroundRole(), Qt::white);
1048 myRectBand->setPalette(palette);*/
1051 if ( m_IsVisible && !Draw ) // move or up : erase at the old position
1056 m_IsVisible = false;
1059 if (Draw) // move : draw
1061 //aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
1063 myRectBand->setGeometry( aRect );
1064 //myRectBand->show();
1068 void View::noActiveActions()
1070 for ( int i = ViewFitAllId; i < ViewHlrOffId ; i++ )
1072 QAction* anAction = myViewActions->at( i );
1073 if( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
1074 ( anAction == myViewActions->at( ViewZoomId ) ) ||
1075 ( anAction == myViewActions->at( ViewPanId ) ) ||
1076 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
1077 ( anAction == myViewActions->at( ViewRotationId ) ) )
1079 setCursor( *defCursor );
1080 anAction->setCheckable( true );
1081 anAction->setChecked( false );
1086 void View::onBackground()
1092 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
1093 aColor.setRgb(R1*255,G1*255,B1*255);
1095 QColor aRetColor = QColorDialog::getColor(aColor);
1097 if( aRetColor.isValid() )
1099 R1 = aRetColor.red()/255.;
1100 G1 = aRetColor.green()/255.;
1101 B1 = aRetColor.blue()/255.;
1102 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
1107 void View::onEnvironmentMap()
1109 if (myBackMenu->actions().at(1)->isChecked())
1111 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
1112 tr("All Image Files (*.bmp *.gif *.jpg *.jpeg *.png *.tga)"));
1114 Handle(Graphic3d_TextureEnv) aTexture = new Graphic3d_TextureEnv( fileName.toLatin1().data() );
1116 myView->SetTextureEnv (aTexture);
1117 myView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT);
1121 myView->SetSurfaceDetail (V3d_TEX_NONE);
1127 bool View::dump(Standard_CString theFile)
1130 QString ext = QFileInfo( QString( theFile ) ).completeSuffix();
1131 if ( !ext.compare("ps") || !ext.compare("eps") || !ext.compare("tex") || !ext.compare("pdf") || !ext.compare("svg") || !ext.compare("pgf") )
1133 Graphic3d_ExportFormat exFormat;
1134 if ( !ext.compare("ps") )
1135 exFormat = Graphic3d_EF_PostScript;
1136 if ( !ext.compare("eps") )
1137 exFormat = Graphic3d_EF_EnhPostScript;
1138 if ( !ext.compare("tex") )
1139 exFormat = Graphic3d_EF_TEX;
1140 if ( !ext.compare("pdf") )
1141 exFormat = Graphic3d_EF_PDF;
1142 if ( !ext.compare("svg") )
1143 exFormat = Graphic3d_EF_SVG;
1144 if ( !ext.compare("pgf") )
1145 exFormat = Graphic3d_EF_PGF;
1148 myView->Export( theFile, exFormat );
1156 return myView->Dump(theFile);
1159 Handle(V3d_View)& View::getView()
1164 Handle(AIS_InteractiveContext)& View::getContext()
1169 View::CurrentAction3d View::getCurrentMode()
1171 return myCurrentMode;