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>
33 #include <X11/Xmu/StdCmap.h>
35 #include <Xw_Window.hxx>
39 #include <Aspect_DisplayConnection.hxx>
41 // the key for multi selection :
42 #define MULTISELECTIONKEY Qt::ShiftModifier
44 // the key for shortcut ( use to activate dynamic rotation, panning )
45 #define CASCADESHORTCUTKEY Qt::ControlModifier
47 // for elastic bean selection
50 static QCursor* defCursor = NULL;
51 static QCursor* handCursor = NULL;
52 static QCursor* panCursor = NULL;
53 static QCursor* globPanCursor = NULL;
54 static QCursor* zoomCursor = NULL;
55 static QCursor* rotCursor = NULL;
57 View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent )
59 myIsRaytracing( false ),
60 myIsShadowsEnabled (true),
61 myIsReflectionsEnabled (false),
62 myIsAntialiasingEnabled (false),
64 myRaytraceActions( 0 ),
67 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
68 //XSynchronize( x11Display(),true ); // it is possible to use QApplication::syncX();
69 XSynchronize( x11Info().display(),true ); // it is possible to use QApplication::syncX();
73 myContext = theContext;
82 setAttribute(Qt::WA_PaintOnScreen);
83 setAttribute(Qt::WA_NoSystemBackground);
85 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
86 XVisualInfo* pVisualInfo;
87 if ( x11Info().display() )
89 /* Initialization with the default VisualID */
90 Visual *v = DefaultVisual( x11Info().display(), DefaultScreen( x11Info().display() ) );
91 int visualID = XVisualIDFromVisual( v );
93 /* Here we use the settings from Optimizer_ViewInfo::TxglCreateWindow() */
94 int visualAttr[] = { GLX_RGBA, GLX_DEPTH_SIZE, 1, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
95 GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None };
96 pVisualInfo = ::glXChooseVisual( x11Info().display(), DefaultScreen( x11Info().display() ), visualAttr );
101 XSetWindowAttributes a;
103 Window p = RootWindow( x11Info().display(), DefaultScreen( x11Info().display() ) );
104 a.colormap = XCreateColormap( x11Info().display(), RootWindow( x11Info().display(), pVisualInfo->screen ),
105 pVisualInfo->visual, AllocNone );
107 QColor color = palette().color( backgroundRole() );
108 QColormap colmap = QColormap::instance();
109 a.background_pixel = colmap.pixel( color );
110 a.border_pixel = colmap.pixel( Qt::black );
111 if ( parentWidget() )
112 p = parentWidget()->winId();
114 Window w = XCreateWindow( x11Info().display(), p, x(), y(), width(), height(),
115 0, pVisualInfo->depth, InputOutput, pVisualInfo->visual,
116 CWBackPixel | CWBorderPixel | CWColormap, &a );
120 if ( XGetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), &cmwret, &count ) )
122 cmw = new Window[count+1];
123 memcpy( (char *)cmw, (char *)cmwret, sizeof(Window)*count );
124 XFree( (char *)cmwret );
126 for ( i = 0; i < count; i++ )
128 if ( cmw[i] == winId() ) /* replace old window */
134 if ( i >= count ) /* append new window */
140 cmw = new Window[count];
143 /* Creating new window (with good VisualID) for this widget */
145 XSetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), cmw, count );
151 XFree( (char *)pVisualInfo );
152 XFlush( x11Info().display() );
156 myCurrentMode = CurAction3d_Nothing;
157 myHlrModeIsOn = Standard_False;
158 setMouseTracking( true );
163 setBackgroundRole( QPalette::NoRole );//NoBackground );
164 // set focus policy to threat QContextMenuEvent from keyboard
165 setFocusPolicy( Qt::StrongFocus );
166 setAttribute( Qt::WA_PaintOnScreen );
167 setAttribute( Qt::WA_NoSystemBackground );
178 if ( myView.IsNull() )
179 myView = myContext->CurrentViewer()->CreateView();
181 #if defined(_WIN32) || defined(__WIN32__)
182 Aspect_Handle aWindowHandle = (Aspect_Handle )winId();
183 Handle(WNT_Window) hWnd = new WNT_Window (aWindowHandle);
184 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
185 NSView* aViewHandle = (NSView* )winId();
186 Handle(Cocoa_Window) hWnd = new Cocoa_Window (aViewHandle);
188 Window aWindowHandle = (Window )winId();
189 Handle(Aspect_DisplayConnection) aDispConnection = myContext->CurrentViewer()->Driver()->GetDisplayConnection();
190 Handle(Xw_Window) hWnd = new Xw_Window (aDispConnection, aWindowHandle);
193 myView->SetWindow (hWnd);
194 if ( !hWnd->IsMapped() )
198 myView->SetBackgroundColor (Quantity_NOC_BLACK);
199 myView->MustBeResized();
202 myView->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
205 void View::paintEvent( QPaintEvent * )
207 // QApplication::syncX();
216 void View::resizeEvent( QResizeEvent * )
218 // QApplication::syncX();
219 if( !myView.IsNull() )
221 myView->MustBeResized();
234 myCurrentMode = CurAction3d_WindowZooming;
239 myCurrentMode = CurAction3d_DynamicZooming;
244 myCurrentMode = CurAction3d_DynamicPanning;
247 void View::rotation()
249 myCurrentMode = CurAction3d_DynamicRotation;
252 void View::globalPan()
254 // save the current zoom value
255 myCurZoom = myView->Scale();
259 myCurrentMode = CurAction3d_GlobalPanning;
264 myView->SetProj( V3d_Xpos );
269 myView->SetProj( V3d_Xneg );
274 myView->SetProj( V3d_Zpos );
279 myView->SetProj( V3d_Zneg );
284 myView->SetProj( V3d_Ypos );
289 myView->SetProj( V3d_Yneg );
294 myView->SetProj( V3d_XposYnegZpos );
304 QApplication::setOverrideCursor( Qt::WaitCursor );
305 myHlrModeIsOn = Standard_False;
306 myView->SetComputedMode (myHlrModeIsOn);
307 QApplication::restoreOverrideCursor();
312 QApplication::setOverrideCursor( Qt::WaitCursor );
313 myHlrModeIsOn = Standard_True;
314 myView->SetComputedMode (myHlrModeIsOn);
315 QApplication::restoreOverrideCursor();
318 void View::SetRaytracedShadows (bool theState)
320 myView->ChangeRenderingParams().IsShadowEnabled = theState;
322 myIsShadowsEnabled = theState;
324 myContext->UpdateCurrentViewer();
327 void View::SetRaytracedReflections (bool theState)
329 myView->ChangeRenderingParams().IsReflectionEnabled = theState;
331 myIsReflectionsEnabled = theState;
333 myContext->UpdateCurrentViewer();
336 void View::onRaytraceAction()
338 QAction* aSentBy = (QAction*)sender();
340 if (aSentBy == myRaytraceActions->at (ToolRaytracingId))
342 bool aState = myRaytraceActions->at (ToolRaytracingId)->isChecked();
344 QApplication::setOverrideCursor (Qt::WaitCursor);
349 QApplication::restoreOverrideCursor();
352 if (aSentBy == myRaytraceActions->at (ToolShadowsId))
354 bool aState = myRaytraceActions->at (ToolShadowsId)->isChecked();
355 SetRaytracedShadows (aState);
358 if (aSentBy == myRaytraceActions->at (ToolReflectionsId))
360 bool aState = myRaytraceActions->at (ToolReflectionsId)->isChecked();
361 SetRaytracedReflections (aState);
364 if (aSentBy == myRaytraceActions->at (ToolAntialiasingId))
366 bool aState = myRaytraceActions->at (ToolAntialiasingId)->isChecked();
367 SetRaytracedAntialiasing (aState);
371 void View::SetRaytracedAntialiasing (bool theState)
373 myView->ChangeRenderingParams().IsAntialiasingEnabled = theState;
375 myIsAntialiasingEnabled = theState;
377 myContext->UpdateCurrentViewer();
380 void View::EnableRaytracing()
383 myView->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
385 myIsRaytracing = true;
387 myContext->UpdateCurrentViewer();
390 void View::DisableRaytracing()
393 myView->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION;
395 myIsRaytracing = false;
397 myContext->UpdateCurrentViewer();
400 void View::updateToggled( bool isOn )
402 QAction* sentBy = (QAction*)sender();
407 for ( int i = ViewFitAllId; i < ViewHlrOffId; i++ )
409 QAction* anAction = myViewActions->at( i );
411 if ( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
412 ( anAction == myViewActions->at( ViewZoomId ) ) ||
413 ( anAction == myViewActions->at( ViewPanId ) ) ||
414 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
415 ( anAction == myViewActions->at( ViewRotationId ) ) )
417 if ( anAction && ( anAction != sentBy ) )
419 anAction->setCheckable( true );
420 anAction->setChecked( false );
424 if ( sentBy == myViewActions->at( ViewFitAreaId ) )
425 setCursor( *handCursor );
426 else if ( sentBy == myViewActions->at( ViewZoomId ) )
427 setCursor( *zoomCursor );
428 else if ( sentBy == myViewActions->at( ViewPanId ) )
429 setCursor( *panCursor );
430 else if ( sentBy == myViewActions->at( ViewGlobalPanId ) )
431 setCursor( *globPanCursor );
432 else if ( sentBy == myViewActions->at( ViewRotationId ) )
433 setCursor( *rotCursor );
435 setCursor( *defCursor );
437 sentBy->setCheckable( false );
443 void View::initCursors()
446 defCursor = new QCursor( Qt::ArrowCursor );
448 handCursor = new QCursor( Qt::PointingHandCursor );
450 panCursor = new QCursor( Qt::SizeAllCursor );
451 if ( !globPanCursor )
452 globPanCursor = new QCursor( Qt::CrossCursor );
454 zoomCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ZOOM" ) ) );
456 rotCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ROTATE" ) ) );
459 QList<QAction*>* View::getViewActions()
462 return myViewActions;
465 QList<QAction*>* View::getRaytraceActions()
467 initRaytraceActions();
468 return myRaytraceActions;
472 Get paint engine for the OpenGL viewer. [ virtual public ]
474 QPaintEngine* View::paintEngine() const
479 void View::initViewActions()
484 myViewActions = new QList<QAction*>();
485 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
488 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITALL") ), QObject::tr("MNU_FITALL"), this );
489 a->setToolTip( QObject::tr("TBR_FITALL") );
490 a->setStatusTip( QObject::tr("TBR_FITALL") );
491 connect( a, SIGNAL( triggered() ) , this, SLOT( fitAll() ) );
492 myViewActions->insert(ViewFitAllId, a);
494 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITAREA") ), QObject::tr("MNU_FITAREA"), this );
495 a->setToolTip( QObject::tr("TBR_FITAREA") );
496 a->setStatusTip( QObject::tr("TBR_FITAREA") );
497 connect( a, SIGNAL( triggered() ) , this, SLOT( fitArea() ) );
499 a->setCheckable( true );
500 connect( a, SIGNAL( toggled( bool ) ) , this, SLOT( updateToggled( bool ) ) );
501 myViewActions->insert( ViewFitAreaId, a );
503 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ZOOM") ), QObject::tr("MNU_ZOOM"), this );
504 a->setToolTip( QObject::tr("TBR_ZOOM") );
505 a->setStatusTip( QObject::tr("TBR_ZOOM") );
506 connect( a, SIGNAL( triggered() ) , this, SLOT( zoom() ) );
508 a->setCheckable( true );
509 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
510 myViewActions->insert( ViewZoomId, a );
512 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_PAN") ), QObject::tr("MNU_PAN"), this );
513 a->setToolTip( QObject::tr("TBR_PAN") );
514 a->setStatusTip( QObject::tr("TBR_PAN") );
515 connect( a, SIGNAL( triggered() ) , this, SLOT( pan() ) );
517 a->setCheckable( true );
518 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
519 myViewActions->insert( ViewPanId, a );
521 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_GLOBALPAN") ), QObject::tr("MNU_GLOBALPAN"), this );
522 a->setToolTip( QObject::tr("TBR_GLOBALPAN") );
523 a->setStatusTip( QObject::tr("TBR_GLOBALPAN") );
524 connect( a, SIGNAL( triggered() ) , this, SLOT( globalPan() ) );
526 a->setCheckable( true );
527 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
528 myViewActions->insert( ViewGlobalPanId, a );
530 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FRONT") ), QObject::tr("MNU_FRONT"), this );
531 a->setToolTip( QObject::tr("TBR_FRONT") );
532 a->setStatusTip( QObject::tr("TBR_FRONT") );
533 connect( a, SIGNAL( triggered() ) , this, SLOT( front() ) );
534 myViewActions->insert( ViewFrontId, a );
536 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BACK") ), QObject::tr("MNU_BACK"), this );
537 a->setToolTip( QObject::tr("TBR_BACK") );
538 a->setStatusTip( QObject::tr("TBR_BACK") );
539 connect( a, SIGNAL( triggered() ) , this, SLOT( back() ) );
540 myViewActions->insert(ViewBackId, a);
542 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_TOP") ), QObject::tr("MNU_TOP"), this );
543 a->setToolTip( QObject::tr("TBR_TOP") );
544 a->setStatusTip( QObject::tr("TBR_TOP") );
545 connect( a, SIGNAL( triggered() ) , this, SLOT( top() ) );
546 myViewActions->insert( ViewTopId, a );
548 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BOTTOM") ), QObject::tr("MNU_BOTTOM"), this );
549 a->setToolTip( QObject::tr("TBR_BOTTOM") );
550 a->setStatusTip( QObject::tr("TBR_BOTTOM") );
551 connect( a, SIGNAL( triggered() ) , this, SLOT( bottom() ) );
552 myViewActions->insert( ViewBottomId, a );
554 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_LEFT") ), QObject::tr("MNU_LEFT"), this );
555 a->setToolTip( QObject::tr("TBR_LEFT") );
556 a->setStatusTip( QObject::tr("TBR_LEFT") );
557 connect( a, SIGNAL( triggered() ) , this, SLOT( left() ) );
558 myViewActions->insert( ViewLeftId, a );
560 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RIGHT") ), QObject::tr("MNU_RIGHT"), this );
561 a->setToolTip( QObject::tr("TBR_RIGHT") );
562 a->setStatusTip( QObject::tr("TBR_RIGHT") );
563 connect( a, SIGNAL( triggered() ) , this, SLOT( right() ) );
564 myViewActions->insert( ViewRightId, a );
566 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_AXO") ), QObject::tr("MNU_AXO"), this );
567 a->setToolTip( QObject::tr("TBR_AXO") );
568 a->setStatusTip( QObject::tr("TBR_AXO") );
569 connect( a, SIGNAL( triggered() ) , this, SLOT( axo() ) );
570 myViewActions->insert( ViewAxoId, a );
572 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ROTATION") ), QObject::tr("MNU_ROTATION"), this );
573 a->setToolTip( QObject::tr("TBR_ROTATION") );
574 a->setStatusTip( QObject::tr("TBR_ROTATION") );
575 connect( a, SIGNAL( triggered() ) , this, SLOT( rotation() ) );
576 a->setCheckable( true );
577 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
578 myViewActions->insert( ViewRotationId, a );
580 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RESET") ), QObject::tr("MNU_RESET"), this );
581 a->setToolTip( QObject::tr("TBR_RESET") );
582 a->setStatusTip( QObject::tr("TBR_RESET") );
583 connect( a, SIGNAL( triggered() ) , this, SLOT( reset() ) );
584 myViewActions->insert( ViewResetId, a );
586 QActionGroup* ag = new QActionGroup( this );
588 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLROFF") ), QObject::tr("MNU_HLROFF"), this );
589 a->setToolTip( QObject::tr("TBR_HLROFF") );
590 a->setStatusTip( QObject::tr("TBR_HLROFF") );
591 connect( a, SIGNAL( triggered() ) , this, SLOT( hlrOff() ) );
592 a->setCheckable( true );
594 myViewActions->insert(ViewHlrOffId, a);
596 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_HLRON"), this );
597 a->setToolTip( QObject::tr("TBR_HLRON") );
598 a->setStatusTip( QObject::tr("TBR_HLRON") );
599 connect( a, SIGNAL( triggered() ) ,this, SLOT( hlrOn() ) );
601 a->setCheckable( true );
603 myViewActions->insert( ViewHlrOnId, a );
606 void View::initRaytraceActions()
608 if ( myRaytraceActions )
611 myRaytraceActions = new QList<QAction*>();
612 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
615 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_RAYTRACING") ), QObject::tr("MNU_TOOL_RAYTRACING"), this );
616 a->setToolTip( QObject::tr("TBR_TOOL_RAYTRACING") );
617 a->setStatusTip( QObject::tr("TBR_TOOL_RAYTRACING") );
618 a->setCheckable( true );
619 a->setChecked( false );
620 connect( a, SIGNAL( activated() ) , this, SLOT( onRaytraceAction() ) );
621 myRaytraceActions->insert( ToolRaytracingId, a );
623 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_SHADOWS") ), QObject::tr("MNU_TOOL_SHADOWS"), this );
624 a->setToolTip( QObject::tr("TBR_TOOL_SHADOWS") );
625 a->setStatusTip( QObject::tr("TBR_TOOL_SHADOWS") );
626 a->setCheckable( true );
627 a->setChecked( true );
628 connect( a, SIGNAL( activated() ) , this, SLOT( onRaytraceAction() ) );
629 myRaytraceActions->insert( ToolShadowsId, a );
631 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_REFLECTIONS") ), QObject::tr("MNU_TOOL_REFLECTIONS"), this );
632 a->setToolTip( QObject::tr("TBR_TOOL_REFLECTIONS") );
633 a->setStatusTip( QObject::tr("TBR_TOOL_REFLECTIONS") );
634 a->setCheckable( true );
635 a->setChecked( false );
636 connect( a, SIGNAL( activated() ) , this, SLOT( onRaytraceAction() ) );
637 myRaytraceActions->insert( ToolReflectionsId, a );
639 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_ANTIALIASING") ), QObject::tr("MNU_TOOL_ANTIALIASING"), this );
640 a->setToolTip( QObject::tr("TBR_TOOL_ANTIALIASING") );
641 a->setStatusTip( QObject::tr("TBR_TOOL_ANTIALIASING") );
642 a->setCheckable( true );
643 a->setChecked( false );
644 connect( a, SIGNAL( activated() ) , this, SLOT( onRaytraceAction() ) );
645 myRaytraceActions->insert( ToolAntialiasingId, a );
648 void View::mousePressEvent( QMouseEvent* e )
650 if ( e->button() == Qt::LeftButton )
651 onLButtonDown( ( e->buttons() | e->modifiers() ), e->pos() );
652 else if ( e->button() == Qt::MidButton )
653 onMButtonDown( e->buttons() | e->modifiers(), e->pos() );
654 else if ( e->button() == Qt::RightButton )
655 onRButtonDown( e->buttons() | e->modifiers(), e->pos() );
658 void View::mouseReleaseEvent(QMouseEvent* e)
660 if ( e->button() == Qt::LeftButton )
661 onLButtonUp( e->buttons(), e->pos() );
662 else if ( e->button() == Qt::MidButton )
663 onMButtonUp( e->buttons(), e->pos() );
664 else if( e->button() == Qt::RightButton )
665 onRButtonUp( e->buttons(), e->pos() );
668 void View::mouseMoveEvent(QMouseEvent* e)
670 onMouseMove( e->buttons(), e->pos() );
673 void View::activateCursor( const CurrentAction3d mode )
677 case CurAction3d_DynamicPanning:
678 setCursor( *panCursor );
680 case CurAction3d_DynamicZooming:
681 setCursor( *zoomCursor );
683 case CurAction3d_DynamicRotation:
684 setCursor( *rotCursor );
686 case CurAction3d_GlobalPanning:
687 setCursor( *globPanCursor );
689 case CurAction3d_WindowZooming:
690 setCursor( *handCursor );
692 case CurAction3d_Nothing:
694 setCursor( *defCursor );
699 void View::onLButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
701 // save the current mouse coordinate in min
707 if ( nFlags & CASCADESHORTCUTKEY )
709 myCurrentMode = CurAction3d_DynamicZooming;
713 switch ( myCurrentMode )
715 case CurAction3d_Nothing:
716 if ( nFlags & MULTISELECTIONKEY )
717 MultiDragEvent( myXmax, myYmax, -1 );
719 DragEvent( myXmax, myYmax, -1 );
721 case CurAction3d_DynamicZooming:
723 case CurAction3d_WindowZooming:
725 case CurAction3d_DynamicPanning:
727 case CurAction3d_GlobalPanning:
729 case CurAction3d_DynamicRotation:
732 myView->SetComputedMode (Standard_False);
734 myView->StartRotation( point.x(), point.y() );
737 Standard_Failure::Raise( "incompatible Current Mode" );
741 activateCursor( myCurrentMode );
744 void View::onMButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint /*point*/ )
746 if ( nFlags & CASCADESHORTCUTKEY )
747 myCurrentMode = CurAction3d_DynamicPanning;
748 activateCursor( myCurrentMode );
751 void View::onRButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
753 if ( nFlags & CASCADESHORTCUTKEY )
757 myView->SetComputedMode (Standard_False);
759 myCurrentMode = CurAction3d_DynamicRotation;
760 myView->StartRotation( point.x(), point.y() );
764 Popup( point.x(), point.y() );
766 activateCursor( myCurrentMode );
769 void View::onLButtonUp( Qt::MouseButtons nFlags, const QPoint point )
771 switch( myCurrentMode )
773 case CurAction3d_Nothing:
774 if ( point.x() == myXmin && point.y() == myYmin )
776 // no offset between down and up --> selectEvent
779 if ( nFlags & MULTISELECTIONKEY )
780 MultiInputEvent( point.x(), point.y() );
782 InputEvent( point.x(), point.y() );
786 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
789 if ( nFlags & MULTISELECTIONKEY )
790 MultiDragEvent( point.x(), point.y(), 1 );
792 DragEvent( point.x(), point.y(), 1 );
795 case CurAction3d_DynamicZooming:
796 myCurrentMode = CurAction3d_Nothing;
799 case CurAction3d_WindowZooming:
800 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );//,LongDash);
803 if ( (abs( myXmin - myXmax ) > ValZWMin ) ||
804 (abs( myYmin - myYmax ) > ValZWMin ) )
805 myView->WindowFitAll( myXmin, myYmin, myXmax, myYmax );
806 myCurrentMode = CurAction3d_Nothing;
809 case CurAction3d_DynamicPanning:
810 myCurrentMode = CurAction3d_Nothing;
813 case CurAction3d_GlobalPanning :
814 myView->Place( point.x(), point.y(), myCurZoom );
815 myCurrentMode = CurAction3d_Nothing;
818 case CurAction3d_DynamicRotation:
819 myCurrentMode = CurAction3d_Nothing;
823 Standard_Failure::Raise(" incompatible Current Mode ");
826 activateCursor( myCurrentMode );
827 ApplicationCommonWindow::getApplication()->onSelectionChanged();
830 void View::onMButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint /*point*/ )
832 myCurrentMode = CurAction3d_Nothing;
833 activateCursor( myCurrentMode );
836 void View::onRButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint point )
838 if ( myCurrentMode == CurAction3d_Nothing )
839 Popup( point.x(), point.y() );
842 QApplication::setOverrideCursor( Qt::WaitCursor );
843 // reset tyhe good Degenerated mode according to the strored one
844 // --> dynamic rotation may have change it
845 myView->SetComputedMode (myHlrModeIsOn);
846 QApplication::restoreOverrideCursor();
847 myCurrentMode = CurAction3d_Nothing;
849 activateCursor( myCurrentMode );
852 void View::onMouseMove( Qt::MouseButtons nFlags, const QPoint point )
854 if ( nFlags & Qt::LeftButton || nFlags & Qt::RightButton || nFlags & Qt::MidButton )
856 switch ( myCurrentMode )
858 case CurAction3d_Nothing:
861 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
862 if ( nFlags & MULTISELECTIONKEY )
863 MultiDragEvent( myXmax, myYmax, 0 );
865 DragEvent( myXmax, myYmax, 0 );
866 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
868 case CurAction3d_DynamicZooming:
869 myView->Zoom( myXmax, myYmax, point.x(), point.y() );
873 case CurAction3d_WindowZooming:
876 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
877 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
879 case CurAction3d_DynamicPanning:
880 myView->Pan( point.x() - myXmax, myYmax - point.y() );
884 case CurAction3d_GlobalPanning:
886 case CurAction3d_DynamicRotation:
887 myView->Rotation( point.x(), point.y() );
891 Standard_Failure::Raise( "incompatible Current Mode" );
899 if ( nFlags & MULTISELECTIONKEY )
900 MultiMoveEvent( point.x(), point.y() );
902 MoveEvent( point.x(), point.y() );
906 void View::DragEvent( const int x, const int y, const int TheState )
908 // TheState == -1 button down
909 // TheState == 0 move
910 // TheState == 1 button up
912 static Standard_Integer theButtonDownX = 0;
913 static Standard_Integer theButtonDownY = 0;
915 if ( TheState == -1 )
923 myContext->Select( theButtonDownX, theButtonDownY, x, y, myView );
924 emit selectionChanged();
928 void View::InputEvent( const int /*x*/, const int /*y*/ )
931 emit selectionChanged();
934 void View::MoveEvent( const int x, const int y )
936 myContext->MoveTo( x, y, myView );
939 void View::MultiMoveEvent( const int x, const int y )
941 myContext->MoveTo( x, y, myView );
944 void View::MultiDragEvent( const int x, const int y, const int TheState )
946 static Standard_Integer theButtonDownX = 0;
947 static Standard_Integer theButtonDownY = 0;
949 if ( TheState == -1 )
956 myContext->ShiftSelect( theButtonDownX, theButtonDownY, x, y, myView );
957 emit selectionChanged();
961 void View::MultiInputEvent( const int /*x*/, const int /*y*/ )
963 myContext->ShiftSelect();
964 emit selectionChanged();
967 void View::Popup( const int /*x*/, const int /*y*/ )
969 ApplicationCommonWindow* stApp = ApplicationCommonWindow::getApplication();
970 QMdiArea* ws = ApplicationCommonWindow::getWorkspace();
971 QMdiSubWindow* w = ws->activeSubWindow();
972 if ( myContext->NbSelected() )
974 QList<QAction*>* aList = stApp->getToolActions();
975 QMenu* myToolMenu = new QMenu( 0 );
976 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolWireframeId ) );
977 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolShadingId ) );
978 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolColorId ) );
980 QMenu* myMaterMenu = new QMenu( myToolMenu );
982 QList<QAction*>* aMeterActions = ApplicationCommonWindow::getApplication()->getMaterialActions();
984 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
985 myMaterMenu = myToolMenu->addMenu( QPixmap( dir+QObject::tr("ICON_TOOL_MATER")), QObject::tr("MNU_MATER") );
986 for ( int i = 0; i < aMeterActions->size(); i++ )
987 myMaterMenu->addAction( aMeterActions->at( i ) );
989 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolTransparencyId ) );
990 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolDeleteId ) );
991 addItemInPopup(myToolMenu);
992 myToolMenu->exec( QCursor::pos() );
999 myBackMenu = new QMenu( 0 );
1001 QAction* a = new QAction( QObject::tr("MNU_CH_BACK"), this );
1002 a->setToolTip( QObject::tr("TBR_CH_BACK") );
1003 connect( a, SIGNAL( activated() ), this, SLOT( onBackground() ) );
1004 myBackMenu->addAction( a );
1005 addItemInPopup(myBackMenu);
1007 a = new QAction( QObject::tr("MNU_CH_ENV_MAP"), this );
1008 a->setToolTip( QObject::tr("TBR_CH_ENV_MAP") );
1009 connect( a, SIGNAL( activated() ), this, SLOT( onEnvironmentMap() ) );
1010 a->setCheckable( true );
1011 a->setChecked( false );
1012 myBackMenu->addAction( a );
1013 addItemInPopup(myBackMenu);
1016 myBackMenu->exec( QCursor::pos() );
1022 void View::addItemInPopup( QMenu* /*theMenu*/)
1026 void View::DrawRectangle(const int MinX, const int MinY,
1027 const int MaxX, const int MaxY, const bool Draw)
1029 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
1030 static Standard_Boolean m_IsVisible;
1032 StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
1033 StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
1034 StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
1035 StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;
1038 aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
1042 myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
1043 myRectBand->setStyle( QStyleFactory::create("windows") );
1044 myRectBand->setGeometry( aRect );
1048 palette.setColor(myRectBand->foregroundRole(), Qt::white);
1049 myRectBand->setPalette(palette);*/
1052 if ( m_IsVisible && !Draw ) // move or up : erase at the old position
1057 m_IsVisible = false;
1060 if (Draw) // move : draw
1062 //aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
1064 myRectBand->setGeometry( aRect );
1065 //myRectBand->show();
1069 void View::noActiveActions()
1071 for ( int i = ViewFitAllId; i < ViewHlrOffId ; i++ )
1073 QAction* anAction = myViewActions->at( i );
1074 if( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
1075 ( anAction == myViewActions->at( ViewZoomId ) ) ||
1076 ( anAction == myViewActions->at( ViewPanId ) ) ||
1077 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
1078 ( anAction == myViewActions->at( ViewRotationId ) ) )
1080 setCursor( *defCursor );
1081 anAction->setCheckable( true );
1082 anAction->setChecked( false );
1087 void View::onBackground()
1093 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
1094 aColor.setRgb(R1*255,G1*255,B1*255);
1096 QColor aRetColor = QColorDialog::getColor(aColor);
1098 if( aRetColor.isValid() )
1100 R1 = aRetColor.red()/255.;
1101 G1 = aRetColor.green()/255.;
1102 B1 = aRetColor.blue()/255.;
1103 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
1108 void View::onEnvironmentMap()
1110 if (myBackMenu->actions().at(1)->isChecked())
1112 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
1113 tr("All Image Files (*.bmp *.gif *.jpg *.jpeg *.png *.tga)"));
1115 Handle(Graphic3d_TextureEnv) aTexture = new Graphic3d_TextureEnv( fileName.toLatin1().data() );
1117 myView->SetTextureEnv (aTexture);
1118 myView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT);
1122 myView->SetSurfaceDetail (V3d_TEX_NONE);
1128 bool View::dump(Standard_CString theFile)
1131 QString ext = QFileInfo( QString( theFile ) ).completeSuffix();
1132 if ( !ext.compare("ps") || !ext.compare("eps") || !ext.compare("tex") || !ext.compare("pdf") || !ext.compare("svg") || !ext.compare("pgf") )
1134 Graphic3d_ExportFormat exFormat;
1135 if ( !ext.compare("ps") )
1136 exFormat = Graphic3d_EF_PostScript;
1137 if ( !ext.compare("eps") )
1138 exFormat = Graphic3d_EF_EnhPostScript;
1139 if ( !ext.compare("tex") )
1140 exFormat = Graphic3d_EF_TEX;
1141 if ( !ext.compare("pdf") )
1142 exFormat = Graphic3d_EF_PDF;
1143 if ( !ext.compare("svg") )
1144 exFormat = Graphic3d_EF_SVG;
1145 if ( !ext.compare("pgf") )
1146 exFormat = Graphic3d_EF_PGF;
1149 myView->Export( theFile, exFormat );
1157 return myView->Dump(theFile);
1160 Handle(V3d_View)& View::getView()
1165 Handle(AIS_InteractiveContext)& View::getContext()
1170 View::CurrentAction3d View::getCurrentMode()
1172 return myCurrentMode;