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>
19 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && QT_VERSION < 0x050000
24 #include <Graphic3d_ExportFormat.hxx>
25 #include <Graphic3d_GraphicDriver.hxx>
26 #include <Graphic3d_TextureEnv.hxx>
28 #include <OcctWindow.h>
29 #include <Aspect_DisplayConnection.hxx>
31 // the key for multi selection :
32 #define MULTISELECTIONKEY Qt::ShiftModifier
34 // the key for shortcut ( use to activate dynamic rotation, panning )
35 #define CASCADESHORTCUTKEY Qt::ControlModifier
37 // for elastic bean selection
40 static QCursor* defCursor = NULL;
41 static QCursor* handCursor = NULL;
42 static QCursor* panCursor = NULL;
43 static QCursor* globPanCursor = NULL;
44 static QCursor* zoomCursor = NULL;
45 static QCursor* rotCursor = NULL;
47 View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent )
49 myIsRaytracing( false ),
50 myIsShadowsEnabled (true),
51 myIsReflectionsEnabled (false),
52 myIsAntialiasingEnabled (false),
54 myRaytraceActions( 0 ),
57 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && QT_VERSION < 0x050000
58 XSynchronize(x11Info().display(),true);
60 myContext = theContext;
69 setAttribute(Qt::WA_PaintOnScreen);
70 setAttribute(Qt::WA_NoSystemBackground);
72 myCurrentMode = CurAction3d_Nothing;
73 myHlrModeIsOn = Standard_False;
74 setMouseTracking( true );
79 setBackgroundRole( QPalette::NoRole );//NoBackground );
80 // set focus policy to threat QContextMenuEvent from keyboard
81 setFocusPolicy( Qt::StrongFocus );
82 setAttribute( Qt::WA_PaintOnScreen );
83 setAttribute( Qt::WA_NoSystemBackground );
94 if ( myView.IsNull() )
95 myView = myContext->CurrentViewer()->CreateView();
97 Handle(OcctWindow) hWnd = new OcctWindow ( this );
98 myView->SetWindow (hWnd);
99 if ( !hWnd->IsMapped() )
103 myView->SetBackgroundColor (Quantity_NOC_BLACK);
104 myView->MustBeResized();
107 myView->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
110 void View::paintEvent( QPaintEvent * )
112 // QApplication::syncX();
116 void View::resizeEvent( QResizeEvent * )
118 // QApplication::syncX();
119 if( !myView.IsNull() )
121 myView->MustBeResized();
134 myCurrentMode = CurAction3d_WindowZooming;
139 myCurrentMode = CurAction3d_DynamicZooming;
144 myCurrentMode = CurAction3d_DynamicPanning;
147 void View::rotation()
149 myCurrentMode = CurAction3d_DynamicRotation;
152 void View::globalPan()
154 // save the current zoom value
155 myCurZoom = myView->Scale();
159 myCurrentMode = CurAction3d_GlobalPanning;
164 myView->SetProj( V3d_Yneg );
169 myView->SetProj( V3d_Ypos );
174 myView->SetProj( V3d_Zpos );
179 myView->SetProj( V3d_Zneg );
184 myView->SetProj( V3d_Xneg );
189 myView->SetProj( V3d_Xpos );
194 myView->SetProj( V3d_XposYnegZpos );
204 QApplication::setOverrideCursor( Qt::WaitCursor );
205 myHlrModeIsOn = Standard_False;
206 myView->SetComputedMode (myHlrModeIsOn);
208 QApplication::restoreOverrideCursor();
213 QApplication::setOverrideCursor( Qt::WaitCursor );
214 myHlrModeIsOn = Standard_True;
215 myView->SetComputedMode (myHlrModeIsOn);
217 QApplication::restoreOverrideCursor();
220 void View::SetRaytracedShadows (bool theState)
222 myView->ChangeRenderingParams().IsShadowEnabled = theState;
224 myIsShadowsEnabled = theState;
226 myContext->UpdateCurrentViewer();
229 void View::SetRaytracedReflections (bool theState)
231 myView->ChangeRenderingParams().IsReflectionEnabled = theState;
233 myIsReflectionsEnabled = theState;
235 myContext->UpdateCurrentViewer();
238 void View::onRaytraceAction()
240 QAction* aSentBy = (QAction*)sender();
242 if (aSentBy == myRaytraceActions->at (ToolRaytracingId))
244 bool aState = myRaytraceActions->at (ToolRaytracingId)->isChecked();
246 QApplication::setOverrideCursor (Qt::WaitCursor);
251 QApplication::restoreOverrideCursor();
254 if (aSentBy == myRaytraceActions->at (ToolShadowsId))
256 bool aState = myRaytraceActions->at (ToolShadowsId)->isChecked();
257 SetRaytracedShadows (aState);
260 if (aSentBy == myRaytraceActions->at (ToolReflectionsId))
262 bool aState = myRaytraceActions->at (ToolReflectionsId)->isChecked();
263 SetRaytracedReflections (aState);
266 if (aSentBy == myRaytraceActions->at (ToolAntialiasingId))
268 bool aState = myRaytraceActions->at (ToolAntialiasingId)->isChecked();
269 SetRaytracedAntialiasing (aState);
273 void View::SetRaytracedAntialiasing (bool theState)
275 myView->ChangeRenderingParams().IsAntialiasingEnabled = theState;
277 myIsAntialiasingEnabled = theState;
279 myContext->UpdateCurrentViewer();
282 void View::EnableRaytracing()
285 myView->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
287 myIsRaytracing = true;
289 myContext->UpdateCurrentViewer();
292 void View::DisableRaytracing()
295 myView->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION;
297 myIsRaytracing = false;
299 myContext->UpdateCurrentViewer();
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 );
313 if ( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
314 ( anAction == myViewActions->at( ViewZoomId ) ) ||
315 ( anAction == myViewActions->at( ViewPanId ) ) ||
316 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
317 ( anAction == myViewActions->at( ViewRotationId ) ) )
319 if ( anAction && ( anAction != sentBy ) )
321 anAction->setCheckable( true );
322 anAction->setChecked( false );
326 if ( sentBy == myViewActions->at( ViewFitAreaId ) )
327 setCursor( *handCursor );
328 else if ( sentBy == myViewActions->at( ViewZoomId ) )
329 setCursor( *zoomCursor );
330 else if ( sentBy == myViewActions->at( ViewPanId ) )
331 setCursor( *panCursor );
332 else if ( sentBy == myViewActions->at( ViewGlobalPanId ) )
333 setCursor( *globPanCursor );
334 else if ( sentBy == myViewActions->at( ViewRotationId ) )
335 setCursor( *rotCursor );
337 setCursor( *defCursor );
339 sentBy->setCheckable( false );
345 void View::initCursors()
348 defCursor = new QCursor( Qt::ArrowCursor );
350 handCursor = new QCursor( Qt::PointingHandCursor );
352 panCursor = new QCursor( Qt::SizeAllCursor );
353 if ( !globPanCursor )
354 globPanCursor = new QCursor( Qt::CrossCursor );
356 zoomCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ZOOM" ) ) );
358 rotCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ROTATE" ) ) );
361 QList<QAction*>* View::getViewActions()
364 return myViewActions;
367 QList<QAction*>* View::getRaytraceActions()
369 initRaytraceActions();
370 return myRaytraceActions;
374 Get paint engine for the OpenGL viewer. [ virtual public ]
376 QPaintEngine* View::paintEngine() const
381 void View::initViewActions()
386 myViewActions = new QList<QAction*>();
387 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
390 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITALL") ), QObject::tr("MNU_FITALL"), this );
391 a->setToolTip( QObject::tr("TBR_FITALL") );
392 a->setStatusTip( QObject::tr("TBR_FITALL") );
393 connect( a, SIGNAL( triggered() ) , this, SLOT( fitAll() ) );
394 myViewActions->insert(ViewFitAllId, a);
396 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITAREA") ), QObject::tr("MNU_FITAREA"), this );
397 a->setToolTip( QObject::tr("TBR_FITAREA") );
398 a->setStatusTip( QObject::tr("TBR_FITAREA") );
399 connect( a, SIGNAL( triggered() ) , this, SLOT( fitArea() ) );
401 a->setCheckable( true );
402 connect( a, SIGNAL( toggled( bool ) ) , this, SLOT( updateToggled( bool ) ) );
403 myViewActions->insert( ViewFitAreaId, a );
405 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ZOOM") ), QObject::tr("MNU_ZOOM"), this );
406 a->setToolTip( QObject::tr("TBR_ZOOM") );
407 a->setStatusTip( QObject::tr("TBR_ZOOM") );
408 connect( a, SIGNAL( triggered() ) , this, SLOT( zoom() ) );
410 a->setCheckable( true );
411 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
412 myViewActions->insert( ViewZoomId, a );
414 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_PAN") ), QObject::tr("MNU_PAN"), this );
415 a->setToolTip( QObject::tr("TBR_PAN") );
416 a->setStatusTip( QObject::tr("TBR_PAN") );
417 connect( a, SIGNAL( triggered() ) , this, SLOT( pan() ) );
419 a->setCheckable( true );
420 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
421 myViewActions->insert( ViewPanId, a );
423 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_GLOBALPAN") ), QObject::tr("MNU_GLOBALPAN"), this );
424 a->setToolTip( QObject::tr("TBR_GLOBALPAN") );
425 a->setStatusTip( QObject::tr("TBR_GLOBALPAN") );
426 connect( a, SIGNAL( triggered() ) , this, SLOT( globalPan() ) );
428 a->setCheckable( true );
429 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
430 myViewActions->insert( ViewGlobalPanId, a );
432 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FRONT") ), QObject::tr("MNU_FRONT"), this );
433 a->setToolTip( QObject::tr("TBR_FRONT") );
434 a->setStatusTip( QObject::tr("TBR_FRONT") );
435 connect( a, SIGNAL( triggered() ) , this, SLOT( front() ) );
436 myViewActions->insert( ViewFrontId, a );
438 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BACK") ), QObject::tr("MNU_BACK"), this );
439 a->setToolTip( QObject::tr("TBR_BACK") );
440 a->setStatusTip( QObject::tr("TBR_BACK") );
441 connect( a, SIGNAL( triggered() ) , this, SLOT( back() ) );
442 myViewActions->insert(ViewBackId, a);
444 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_TOP") ), QObject::tr("MNU_TOP"), this );
445 a->setToolTip( QObject::tr("TBR_TOP") );
446 a->setStatusTip( QObject::tr("TBR_TOP") );
447 connect( a, SIGNAL( triggered() ) , this, SLOT( top() ) );
448 myViewActions->insert( ViewTopId, a );
450 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BOTTOM") ), QObject::tr("MNU_BOTTOM"), this );
451 a->setToolTip( QObject::tr("TBR_BOTTOM") );
452 a->setStatusTip( QObject::tr("TBR_BOTTOM") );
453 connect( a, SIGNAL( triggered() ) , this, SLOT( bottom() ) );
454 myViewActions->insert( ViewBottomId, a );
456 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_LEFT") ), QObject::tr("MNU_LEFT"), this );
457 a->setToolTip( QObject::tr("TBR_LEFT") );
458 a->setStatusTip( QObject::tr("TBR_LEFT") );
459 connect( a, SIGNAL( triggered() ) , this, SLOT( left() ) );
460 myViewActions->insert( ViewLeftId, a );
462 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RIGHT") ), QObject::tr("MNU_RIGHT"), this );
463 a->setToolTip( QObject::tr("TBR_RIGHT") );
464 a->setStatusTip( QObject::tr("TBR_RIGHT") );
465 connect( a, SIGNAL( triggered() ) , this, SLOT( right() ) );
466 myViewActions->insert( ViewRightId, a );
468 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_AXO") ), QObject::tr("MNU_AXO"), this );
469 a->setToolTip( QObject::tr("TBR_AXO") );
470 a->setStatusTip( QObject::tr("TBR_AXO") );
471 connect( a, SIGNAL( triggered() ) , this, SLOT( axo() ) );
472 myViewActions->insert( ViewAxoId, a );
474 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ROTATION") ), QObject::tr("MNU_ROTATION"), this );
475 a->setToolTip( QObject::tr("TBR_ROTATION") );
476 a->setStatusTip( QObject::tr("TBR_ROTATION") );
477 connect( a, SIGNAL( triggered() ) , this, SLOT( rotation() ) );
478 a->setCheckable( true );
479 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
480 myViewActions->insert( ViewRotationId, a );
482 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RESET") ), QObject::tr("MNU_RESET"), this );
483 a->setToolTip( QObject::tr("TBR_RESET") );
484 a->setStatusTip( QObject::tr("TBR_RESET") );
485 connect( a, SIGNAL( triggered() ) , this, SLOT( reset() ) );
486 myViewActions->insert( ViewResetId, a );
488 QActionGroup* ag = new QActionGroup( this );
490 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLROFF") ), QObject::tr("MNU_HLROFF"), this );
491 a->setToolTip( QObject::tr("TBR_HLROFF") );
492 a->setStatusTip( QObject::tr("TBR_HLROFF") );
493 connect( a, SIGNAL( triggered() ) , this, SLOT( hlrOff() ) );
494 a->setCheckable( true );
496 myViewActions->insert(ViewHlrOffId, a);
498 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_HLRON"), this );
499 a->setToolTip( QObject::tr("TBR_HLRON") );
500 a->setStatusTip( QObject::tr("TBR_HLRON") );
501 connect( a, SIGNAL( triggered() ) ,this, SLOT( hlrOn() ) );
503 a->setCheckable( true );
505 myViewActions->insert( ViewHlrOnId, a );
508 void View::initRaytraceActions()
510 if ( myRaytraceActions )
513 myRaytraceActions = new QList<QAction*>();
514 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
517 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_RAYTRACING") ), QObject::tr("MNU_TOOL_RAYTRACING"), this );
518 a->setToolTip( QObject::tr("TBR_TOOL_RAYTRACING") );
519 a->setStatusTip( QObject::tr("TBR_TOOL_RAYTRACING") );
520 a->setCheckable( true );
521 a->setChecked( false );
522 connect( a, SIGNAL( triggered() ) , this, SLOT( onRaytraceAction() ) );
523 myRaytraceActions->insert( ToolRaytracingId, a );
525 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_SHADOWS") ), QObject::tr("MNU_TOOL_SHADOWS"), this );
526 a->setToolTip( QObject::tr("TBR_TOOL_SHADOWS") );
527 a->setStatusTip( QObject::tr("TBR_TOOL_SHADOWS") );
528 a->setCheckable( true );
529 a->setChecked( true );
530 connect( a, SIGNAL( triggered() ) , this, SLOT( onRaytraceAction() ) );
531 myRaytraceActions->insert( ToolShadowsId, a );
533 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_REFLECTIONS") ), QObject::tr("MNU_TOOL_REFLECTIONS"), this );
534 a->setToolTip( QObject::tr("TBR_TOOL_REFLECTIONS") );
535 a->setStatusTip( QObject::tr("TBR_TOOL_REFLECTIONS") );
536 a->setCheckable( true );
537 a->setChecked( false );
538 connect( a, SIGNAL( triggered() ) , this, SLOT( onRaytraceAction() ) );
539 myRaytraceActions->insert( ToolReflectionsId, a );
541 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_ANTIALIASING") ), QObject::tr("MNU_TOOL_ANTIALIASING"), this );
542 a->setToolTip( QObject::tr("TBR_TOOL_ANTIALIASING") );
543 a->setStatusTip( QObject::tr("TBR_TOOL_ANTIALIASING") );
544 a->setCheckable( true );
545 a->setChecked( false );
546 connect( a, SIGNAL( triggered() ) , this, SLOT( onRaytraceAction() ) );
547 myRaytraceActions->insert( ToolAntialiasingId, a );
550 void View::mousePressEvent( QMouseEvent* e )
552 if ( e->button() == Qt::LeftButton )
553 onLButtonDown( ( e->buttons() | e->modifiers() ), e->pos() );
554 else if ( e->button() == Qt::MidButton )
555 onMButtonDown( e->buttons() | e->modifiers(), e->pos() );
556 else if ( e->button() == Qt::RightButton )
557 onRButtonDown( e->buttons() | e->modifiers(), e->pos() );
560 void View::mouseReleaseEvent(QMouseEvent* e)
562 if ( e->button() == Qt::LeftButton )
563 onLButtonUp( e->buttons(), e->pos() );
564 else if ( e->button() == Qt::MidButton )
565 onMButtonUp( e->buttons(), e->pos() );
566 else if( e->button() == Qt::RightButton )
567 onRButtonUp( e->buttons(), e->pos() );
570 void View::mouseMoveEvent(QMouseEvent* e)
572 onMouseMove( e->buttons(), e->pos() );
575 void View::activateCursor( const CurrentAction3d mode )
579 case CurAction3d_DynamicPanning:
580 setCursor( *panCursor );
582 case CurAction3d_DynamicZooming:
583 setCursor( *zoomCursor );
585 case CurAction3d_DynamicRotation:
586 setCursor( *rotCursor );
588 case CurAction3d_GlobalPanning:
589 setCursor( *globPanCursor );
591 case CurAction3d_WindowZooming:
592 setCursor( *handCursor );
594 case CurAction3d_Nothing:
596 setCursor( *defCursor );
601 void View::onLButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
603 // save the current mouse coordinate in min
609 if ( nFlags & CASCADESHORTCUTKEY )
611 myCurrentMode = CurAction3d_DynamicZooming;
615 switch ( myCurrentMode )
617 case CurAction3d_Nothing:
618 if ( nFlags & MULTISELECTIONKEY )
619 MultiDragEvent( myXmax, myYmax, -1 );
621 DragEvent( myXmax, myYmax, -1 );
623 case CurAction3d_DynamicZooming:
625 case CurAction3d_WindowZooming:
627 case CurAction3d_DynamicPanning:
629 case CurAction3d_GlobalPanning:
631 case CurAction3d_DynamicRotation:
634 myView->SetComputedMode (Standard_False);
636 myView->StartRotation( point.x(), point.y() );
639 throw Standard_Failure( "incompatible Current Mode" );
643 activateCursor( myCurrentMode );
646 void View::onMButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint /*point*/ )
648 if ( nFlags & CASCADESHORTCUTKEY )
649 myCurrentMode = CurAction3d_DynamicPanning;
650 activateCursor( myCurrentMode );
653 void View::onRButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
655 if ( nFlags & CASCADESHORTCUTKEY )
659 myView->SetComputedMode (Standard_False);
661 myCurrentMode = CurAction3d_DynamicRotation;
662 myView->StartRotation( point.x(), point.y() );
666 Popup( point.x(), point.y() );
668 activateCursor( myCurrentMode );
671 void View::onLButtonUp( Qt::MouseButtons nFlags, const QPoint point )
673 switch( myCurrentMode )
675 case CurAction3d_Nothing:
676 if ( point.x() == myXmin && point.y() == myYmin )
678 // no offset between down and up --> selectEvent
681 if ( nFlags & MULTISELECTIONKEY )
682 MultiInputEvent( point.x(), point.y() );
684 InputEvent( point.x(), point.y() );
688 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
691 if ( nFlags & MULTISELECTIONKEY )
692 MultiDragEvent( point.x(), point.y(), 1 );
694 DragEvent( point.x(), point.y(), 1 );
697 case CurAction3d_DynamicZooming:
698 myCurrentMode = CurAction3d_Nothing;
701 case CurAction3d_WindowZooming:
702 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );//,LongDash);
705 if ( (abs( myXmin - myXmax ) > ValZWMin ) ||
706 (abs( myYmin - myYmax ) > ValZWMin ) )
707 myView->WindowFitAll( myXmin, myYmin, myXmax, myYmax );
708 myCurrentMode = CurAction3d_Nothing;
711 case CurAction3d_DynamicPanning:
712 myCurrentMode = CurAction3d_Nothing;
715 case CurAction3d_GlobalPanning :
716 myView->Place( point.x(), point.y(), myCurZoom );
717 myCurrentMode = CurAction3d_Nothing;
720 case CurAction3d_DynamicRotation:
721 myCurrentMode = CurAction3d_Nothing;
725 throw Standard_Failure(" incompatible Current Mode ");
728 activateCursor( myCurrentMode );
729 ApplicationCommonWindow::getApplication()->onSelectionChanged();
732 void View::onMButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint /*point*/ )
734 myCurrentMode = CurAction3d_Nothing;
735 activateCursor( myCurrentMode );
738 void View::onRButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint point )
740 if ( myCurrentMode == CurAction3d_Nothing )
741 Popup( point.x(), point.y() );
744 QApplication::setOverrideCursor( Qt::WaitCursor );
745 // reset tyhe good Degenerated mode according to the strored one
746 // --> dynamic rotation may have change it
749 myView->SetComputedMode (myHlrModeIsOn);
752 QApplication::restoreOverrideCursor();
753 myCurrentMode = CurAction3d_Nothing;
755 activateCursor( myCurrentMode );
758 void View::onMouseMove( Qt::MouseButtons nFlags, const QPoint point )
760 if ( nFlags & Qt::LeftButton || nFlags & Qt::RightButton || nFlags & Qt::MidButton )
762 switch ( myCurrentMode )
764 case CurAction3d_Nothing:
767 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
768 if ( nFlags & MULTISELECTIONKEY )
769 MultiDragEvent( myXmax, myYmax, 0 );
771 DragEvent( myXmax, myYmax, 0 );
772 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
774 case CurAction3d_DynamicZooming:
775 myView->Zoom( myXmax, myYmax, point.x(), point.y() );
779 case CurAction3d_WindowZooming:
782 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
783 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
785 case CurAction3d_DynamicPanning:
786 myView->Pan( point.x() - myXmax, myYmax - point.y() );
790 case CurAction3d_GlobalPanning:
792 case CurAction3d_DynamicRotation:
793 myView->Rotation( point.x(), point.y() );
797 throw Standard_Failure( "incompatible Current Mode" );
805 if ( nFlags & MULTISELECTIONKEY )
806 MultiMoveEvent( point.x(), point.y() );
808 MoveEvent( point.x(), point.y() );
812 void View::DragEvent( const int x, const int y, const int TheState )
814 // TheState == -1 button down
815 // TheState == 0 move
816 // TheState == 1 button up
818 static Standard_Integer theButtonDownX = 0;
819 static Standard_Integer theButtonDownY = 0;
821 if ( TheState == -1 )
829 myContext->Select( theButtonDownX, theButtonDownY, x, y, myView, Standard_True );
830 emit selectionChanged();
834 void View::InputEvent( const int /*x*/, const int /*y*/ )
836 myContext->Select (Standard_True);
837 emit selectionChanged();
840 void View::MoveEvent( const int x, const int y )
842 myContext->MoveTo( x, y, myView, Standard_True );
845 void View::MultiMoveEvent( const int x, const int y )
847 myContext->MoveTo( x, y, myView, Standard_True );
850 void View::MultiDragEvent( const int x, const int y, const int TheState )
852 static Standard_Integer theButtonDownX = 0;
853 static Standard_Integer theButtonDownY = 0;
855 if ( TheState == -1 )
862 myContext->ShiftSelect( theButtonDownX, theButtonDownY, x, y, myView, Standard_True );
863 emit selectionChanged();
867 void View::MultiInputEvent( const int /*x*/, const int /*y*/ )
869 myContext->ShiftSelect (Standard_True);
870 emit selectionChanged();
873 void View::Popup( const int /*x*/, const int /*y*/ )
875 ApplicationCommonWindow* stApp = ApplicationCommonWindow::getApplication();
876 QMdiArea* ws = ApplicationCommonWindow::getWorkspace();
877 QMdiSubWindow* w = ws->activeSubWindow();
878 if ( myContext->NbSelected() )
880 QList<QAction*>* aList = stApp->getToolActions();
881 QMenu* myToolMenu = new QMenu( 0 );
882 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolWireframeId ) );
883 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolShadingId ) );
884 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolColorId ) );
886 QMenu* myMaterMenu = new QMenu( myToolMenu );
888 QList<QAction*>* aMeterActions = ApplicationCommonWindow::getApplication()->getMaterialActions();
890 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
891 myMaterMenu = myToolMenu->addMenu( QPixmap( dir+QObject::tr("ICON_TOOL_MATER")), QObject::tr("MNU_MATER") );
892 for ( int i = 0; i < aMeterActions->size(); i++ )
893 myMaterMenu->addAction( aMeterActions->at( i ) );
895 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolTransparencyId ) );
896 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolDeleteId ) );
897 addItemInPopup(myToolMenu);
898 myToolMenu->exec( QCursor::pos() );
905 myBackMenu = new QMenu( 0 );
907 QAction* a = new QAction( QObject::tr("MNU_CH_BACK"), this );
908 a->setToolTip( QObject::tr("TBR_CH_BACK") );
909 connect( a, SIGNAL( triggered() ), this, SLOT( onBackground() ) );
910 myBackMenu->addAction( a );
911 addItemInPopup(myBackMenu);
913 a = new QAction( QObject::tr("MNU_CH_ENV_MAP"), this );
914 a->setToolTip( QObject::tr("TBR_CH_ENV_MAP") );
915 connect( a, SIGNAL( triggered() ), this, SLOT( onEnvironmentMap() ) );
916 a->setCheckable( true );
917 a->setChecked( false );
918 myBackMenu->addAction( a );
919 addItemInPopup(myBackMenu);
922 myBackMenu->exec( QCursor::pos() );
928 void View::addItemInPopup( QMenu* /*theMenu*/)
932 void View::DrawRectangle(const int MinX, const int MinY,
933 const int MaxX, const int MaxY, const bool Draw)
935 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
936 static Standard_Boolean m_IsVisible;
938 StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
939 StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
940 StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
941 StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;
944 aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
948 myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
949 myRectBand->setStyle( QStyleFactory::create("windows") );
950 myRectBand->setGeometry( aRect );
954 palette.setColor(myRectBand->foregroundRole(), Qt::white);
955 myRectBand->setPalette(palette);*/
958 if ( m_IsVisible && !Draw ) // move or up : erase at the old position
966 if (Draw) // move : draw
968 //aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
970 myRectBand->setGeometry( aRect );
971 //myRectBand->show();
975 void View::noActiveActions()
977 for ( int i = ViewFitAllId; i < ViewHlrOffId ; i++ )
979 QAction* anAction = myViewActions->at( i );
980 if( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
981 ( anAction == myViewActions->at( ViewZoomId ) ) ||
982 ( anAction == myViewActions->at( ViewPanId ) ) ||
983 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
984 ( anAction == myViewActions->at( ViewRotationId ) ) )
986 setCursor( *defCursor );
987 anAction->setCheckable( true );
988 anAction->setChecked( false );
993 void View::onBackground()
999 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
1000 aColor.setRgb(R1*255,G1*255,B1*255);
1002 QColor aRetColor = QColorDialog::getColor(aColor);
1004 if( aRetColor.isValid() )
1006 R1 = aRetColor.red()/255.;
1007 G1 = aRetColor.green()/255.;
1008 B1 = aRetColor.blue()/255.;
1009 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
1014 void View::onEnvironmentMap()
1016 if (myBackMenu->actions().at(1)->isChecked())
1018 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
1019 tr("All Image Files (*.bmp *.gif *.jpg *.jpeg *.png *.tga)"));
1021 const TCollection_AsciiString anUtf8Path (fileName.toUtf8().data());
1023 Handle(Graphic3d_TextureEnv) aTexture = new Graphic3d_TextureEnv( anUtf8Path );
1025 myView->SetTextureEnv (aTexture);
1029 myView->SetTextureEnv (Handle(Graphic3d_TextureEnv)());
1035 bool View::dump(Standard_CString theFile)
1037 return myView->Dump(theFile);
1040 Handle(V3d_View)& View::getView()
1045 Handle(AIS_InteractiveContext)& View::getContext()
1050 View::CurrentAction3d View::getCurrentMode()
1052 return myCurrentMode;