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);
207 QApplication::restoreOverrideCursor();
212 QApplication::setOverrideCursor( Qt::WaitCursor );
213 myHlrModeIsOn = Standard_True;
214 myView->SetComputedMode (myHlrModeIsOn);
215 QApplication::restoreOverrideCursor();
218 void View::SetRaytracedShadows (bool theState)
220 myView->ChangeRenderingParams().IsShadowEnabled = theState;
222 myIsShadowsEnabled = theState;
224 myContext->UpdateCurrentViewer();
227 void View::SetRaytracedReflections (bool theState)
229 myView->ChangeRenderingParams().IsReflectionEnabled = theState;
231 myIsReflectionsEnabled = theState;
233 myContext->UpdateCurrentViewer();
236 void View::onRaytraceAction()
238 QAction* aSentBy = (QAction*)sender();
240 if (aSentBy == myRaytraceActions->at (ToolRaytracingId))
242 bool aState = myRaytraceActions->at (ToolRaytracingId)->isChecked();
244 QApplication::setOverrideCursor (Qt::WaitCursor);
249 QApplication::restoreOverrideCursor();
252 if (aSentBy == myRaytraceActions->at (ToolShadowsId))
254 bool aState = myRaytraceActions->at (ToolShadowsId)->isChecked();
255 SetRaytracedShadows (aState);
258 if (aSentBy == myRaytraceActions->at (ToolReflectionsId))
260 bool aState = myRaytraceActions->at (ToolReflectionsId)->isChecked();
261 SetRaytracedReflections (aState);
264 if (aSentBy == myRaytraceActions->at (ToolAntialiasingId))
266 bool aState = myRaytraceActions->at (ToolAntialiasingId)->isChecked();
267 SetRaytracedAntialiasing (aState);
271 void View::SetRaytracedAntialiasing (bool theState)
273 myView->ChangeRenderingParams().IsAntialiasingEnabled = theState;
275 myIsAntialiasingEnabled = theState;
277 myContext->UpdateCurrentViewer();
280 void View::EnableRaytracing()
283 myView->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
285 myIsRaytracing = true;
287 myContext->UpdateCurrentViewer();
290 void View::DisableRaytracing()
293 myView->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION;
295 myIsRaytracing = false;
297 myContext->UpdateCurrentViewer();
300 void View::updateToggled( bool isOn )
302 QAction* sentBy = (QAction*)sender();
307 for ( int i = ViewFitAllId; i < ViewHlrOffId; i++ )
309 QAction* anAction = myViewActions->at( i );
311 if ( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
312 ( anAction == myViewActions->at( ViewZoomId ) ) ||
313 ( anAction == myViewActions->at( ViewPanId ) ) ||
314 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
315 ( anAction == myViewActions->at( ViewRotationId ) ) )
317 if ( anAction && ( anAction != sentBy ) )
319 anAction->setCheckable( true );
320 anAction->setChecked( false );
324 if ( sentBy == myViewActions->at( ViewFitAreaId ) )
325 setCursor( *handCursor );
326 else if ( sentBy == myViewActions->at( ViewZoomId ) )
327 setCursor( *zoomCursor );
328 else if ( sentBy == myViewActions->at( ViewPanId ) )
329 setCursor( *panCursor );
330 else if ( sentBy == myViewActions->at( ViewGlobalPanId ) )
331 setCursor( *globPanCursor );
332 else if ( sentBy == myViewActions->at( ViewRotationId ) )
333 setCursor( *rotCursor );
335 setCursor( *defCursor );
337 sentBy->setCheckable( false );
343 void View::initCursors()
346 defCursor = new QCursor( Qt::ArrowCursor );
348 handCursor = new QCursor( Qt::PointingHandCursor );
350 panCursor = new QCursor( Qt::SizeAllCursor );
351 if ( !globPanCursor )
352 globPanCursor = new QCursor( Qt::CrossCursor );
354 zoomCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ZOOM" ) ) );
356 rotCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ROTATE" ) ) );
359 QList<QAction*>* View::getViewActions()
362 return myViewActions;
365 QList<QAction*>* View::getRaytraceActions()
367 initRaytraceActions();
368 return myRaytraceActions;
372 Get paint engine for the OpenGL viewer. [ virtual public ]
374 QPaintEngine* View::paintEngine() const
379 void View::initViewActions()
384 myViewActions = new QList<QAction*>();
385 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
388 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITALL") ), QObject::tr("MNU_FITALL"), this );
389 a->setToolTip( QObject::tr("TBR_FITALL") );
390 a->setStatusTip( QObject::tr("TBR_FITALL") );
391 connect( a, SIGNAL( triggered() ) , this, SLOT( fitAll() ) );
392 myViewActions->insert(ViewFitAllId, a);
394 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITAREA") ), QObject::tr("MNU_FITAREA"), this );
395 a->setToolTip( QObject::tr("TBR_FITAREA") );
396 a->setStatusTip( QObject::tr("TBR_FITAREA") );
397 connect( a, SIGNAL( triggered() ) , this, SLOT( fitArea() ) );
399 a->setCheckable( true );
400 connect( a, SIGNAL( toggled( bool ) ) , this, SLOT( updateToggled( bool ) ) );
401 myViewActions->insert( ViewFitAreaId, a );
403 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ZOOM") ), QObject::tr("MNU_ZOOM"), this );
404 a->setToolTip( QObject::tr("TBR_ZOOM") );
405 a->setStatusTip( QObject::tr("TBR_ZOOM") );
406 connect( a, SIGNAL( triggered() ) , this, SLOT( zoom() ) );
408 a->setCheckable( true );
409 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
410 myViewActions->insert( ViewZoomId, a );
412 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_PAN") ), QObject::tr("MNU_PAN"), this );
413 a->setToolTip( QObject::tr("TBR_PAN") );
414 a->setStatusTip( QObject::tr("TBR_PAN") );
415 connect( a, SIGNAL( triggered() ) , this, SLOT( pan() ) );
417 a->setCheckable( true );
418 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
419 myViewActions->insert( ViewPanId, a );
421 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_GLOBALPAN") ), QObject::tr("MNU_GLOBALPAN"), this );
422 a->setToolTip( QObject::tr("TBR_GLOBALPAN") );
423 a->setStatusTip( QObject::tr("TBR_GLOBALPAN") );
424 connect( a, SIGNAL( triggered() ) , this, SLOT( globalPan() ) );
426 a->setCheckable( true );
427 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
428 myViewActions->insert( ViewGlobalPanId, a );
430 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FRONT") ), QObject::tr("MNU_FRONT"), this );
431 a->setToolTip( QObject::tr("TBR_FRONT") );
432 a->setStatusTip( QObject::tr("TBR_FRONT") );
433 connect( a, SIGNAL( triggered() ) , this, SLOT( front() ) );
434 myViewActions->insert( ViewFrontId, a );
436 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BACK") ), QObject::tr("MNU_BACK"), this );
437 a->setToolTip( QObject::tr("TBR_BACK") );
438 a->setStatusTip( QObject::tr("TBR_BACK") );
439 connect( a, SIGNAL( triggered() ) , this, SLOT( back() ) );
440 myViewActions->insert(ViewBackId, a);
442 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_TOP") ), QObject::tr("MNU_TOP"), this );
443 a->setToolTip( QObject::tr("TBR_TOP") );
444 a->setStatusTip( QObject::tr("TBR_TOP") );
445 connect( a, SIGNAL( triggered() ) , this, SLOT( top() ) );
446 myViewActions->insert( ViewTopId, a );
448 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BOTTOM") ), QObject::tr("MNU_BOTTOM"), this );
449 a->setToolTip( QObject::tr("TBR_BOTTOM") );
450 a->setStatusTip( QObject::tr("TBR_BOTTOM") );
451 connect( a, SIGNAL( triggered() ) , this, SLOT( bottom() ) );
452 myViewActions->insert( ViewBottomId, a );
454 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_LEFT") ), QObject::tr("MNU_LEFT"), this );
455 a->setToolTip( QObject::tr("TBR_LEFT") );
456 a->setStatusTip( QObject::tr("TBR_LEFT") );
457 connect( a, SIGNAL( triggered() ) , this, SLOT( left() ) );
458 myViewActions->insert( ViewLeftId, a );
460 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RIGHT") ), QObject::tr("MNU_RIGHT"), this );
461 a->setToolTip( QObject::tr("TBR_RIGHT") );
462 a->setStatusTip( QObject::tr("TBR_RIGHT") );
463 connect( a, SIGNAL( triggered() ) , this, SLOT( right() ) );
464 myViewActions->insert( ViewRightId, a );
466 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_AXO") ), QObject::tr("MNU_AXO"), this );
467 a->setToolTip( QObject::tr("TBR_AXO") );
468 a->setStatusTip( QObject::tr("TBR_AXO") );
469 connect( a, SIGNAL( triggered() ) , this, SLOT( axo() ) );
470 myViewActions->insert( ViewAxoId, a );
472 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ROTATION") ), QObject::tr("MNU_ROTATION"), this );
473 a->setToolTip( QObject::tr("TBR_ROTATION") );
474 a->setStatusTip( QObject::tr("TBR_ROTATION") );
475 connect( a, SIGNAL( triggered() ) , this, SLOT( rotation() ) );
476 a->setCheckable( true );
477 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
478 myViewActions->insert( ViewRotationId, a );
480 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RESET") ), QObject::tr("MNU_RESET"), this );
481 a->setToolTip( QObject::tr("TBR_RESET") );
482 a->setStatusTip( QObject::tr("TBR_RESET") );
483 connect( a, SIGNAL( triggered() ) , this, SLOT( reset() ) );
484 myViewActions->insert( ViewResetId, a );
486 QActionGroup* ag = new QActionGroup( this );
488 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLROFF") ), QObject::tr("MNU_HLROFF"), this );
489 a->setToolTip( QObject::tr("TBR_HLROFF") );
490 a->setStatusTip( QObject::tr("TBR_HLROFF") );
491 connect( a, SIGNAL( triggered() ) , this, SLOT( hlrOff() ) );
492 a->setCheckable( true );
494 myViewActions->insert(ViewHlrOffId, a);
496 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_HLRON"), this );
497 a->setToolTip( QObject::tr("TBR_HLRON") );
498 a->setStatusTip( QObject::tr("TBR_HLRON") );
499 connect( a, SIGNAL( triggered() ) ,this, SLOT( hlrOn() ) );
501 a->setCheckable( true );
503 myViewActions->insert( ViewHlrOnId, a );
506 void View::initRaytraceActions()
508 if ( myRaytraceActions )
511 myRaytraceActions = new QList<QAction*>();
512 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
515 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_RAYTRACING") ), QObject::tr("MNU_TOOL_RAYTRACING"), this );
516 a->setToolTip( QObject::tr("TBR_TOOL_RAYTRACING") );
517 a->setStatusTip( QObject::tr("TBR_TOOL_RAYTRACING") );
518 a->setCheckable( true );
519 a->setChecked( false );
520 connect( a, SIGNAL( triggered() ) , this, SLOT( onRaytraceAction() ) );
521 myRaytraceActions->insert( ToolRaytracingId, a );
523 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_SHADOWS") ), QObject::tr("MNU_TOOL_SHADOWS"), this );
524 a->setToolTip( QObject::tr("TBR_TOOL_SHADOWS") );
525 a->setStatusTip( QObject::tr("TBR_TOOL_SHADOWS") );
526 a->setCheckable( true );
527 a->setChecked( true );
528 connect( a, SIGNAL( triggered() ) , this, SLOT( onRaytraceAction() ) );
529 myRaytraceActions->insert( ToolShadowsId, a );
531 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_REFLECTIONS") ), QObject::tr("MNU_TOOL_REFLECTIONS"), this );
532 a->setToolTip( QObject::tr("TBR_TOOL_REFLECTIONS") );
533 a->setStatusTip( QObject::tr("TBR_TOOL_REFLECTIONS") );
534 a->setCheckable( true );
535 a->setChecked( false );
536 connect( a, SIGNAL( triggered() ) , this, SLOT( onRaytraceAction() ) );
537 myRaytraceActions->insert( ToolReflectionsId, a );
539 a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_ANTIALIASING") ), QObject::tr("MNU_TOOL_ANTIALIASING"), this );
540 a->setToolTip( QObject::tr("TBR_TOOL_ANTIALIASING") );
541 a->setStatusTip( QObject::tr("TBR_TOOL_ANTIALIASING") );
542 a->setCheckable( true );
543 a->setChecked( false );
544 connect( a, SIGNAL( triggered() ) , this, SLOT( onRaytraceAction() ) );
545 myRaytraceActions->insert( ToolAntialiasingId, a );
548 void View::mousePressEvent( QMouseEvent* e )
550 if ( e->button() == Qt::LeftButton )
551 onLButtonDown( ( e->buttons() | e->modifiers() ), e->pos() );
552 else if ( e->button() == Qt::MidButton )
553 onMButtonDown( e->buttons() | e->modifiers(), e->pos() );
554 else if ( e->button() == Qt::RightButton )
555 onRButtonDown( e->buttons() | e->modifiers(), e->pos() );
558 void View::mouseReleaseEvent(QMouseEvent* e)
560 if ( e->button() == Qt::LeftButton )
561 onLButtonUp( e->buttons(), e->pos() );
562 else if ( e->button() == Qt::MidButton )
563 onMButtonUp( e->buttons(), e->pos() );
564 else if( e->button() == Qt::RightButton )
565 onRButtonUp( e->buttons(), e->pos() );
568 void View::mouseMoveEvent(QMouseEvent* e)
570 onMouseMove( e->buttons(), e->pos() );
573 void View::activateCursor( const CurrentAction3d mode )
577 case CurAction3d_DynamicPanning:
578 setCursor( *panCursor );
580 case CurAction3d_DynamicZooming:
581 setCursor( *zoomCursor );
583 case CurAction3d_DynamicRotation:
584 setCursor( *rotCursor );
586 case CurAction3d_GlobalPanning:
587 setCursor( *globPanCursor );
589 case CurAction3d_WindowZooming:
590 setCursor( *handCursor );
592 case CurAction3d_Nothing:
594 setCursor( *defCursor );
599 void View::onLButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
601 // save the current mouse coordinate in min
607 if ( nFlags & CASCADESHORTCUTKEY )
609 myCurrentMode = CurAction3d_DynamicZooming;
613 switch ( myCurrentMode )
615 case CurAction3d_Nothing:
616 if ( nFlags & MULTISELECTIONKEY )
617 MultiDragEvent( myXmax, myYmax, -1 );
619 DragEvent( myXmax, myYmax, -1 );
621 case CurAction3d_DynamicZooming:
623 case CurAction3d_WindowZooming:
625 case CurAction3d_DynamicPanning:
627 case CurAction3d_GlobalPanning:
629 case CurAction3d_DynamicRotation:
632 myView->SetComputedMode (Standard_False);
634 myView->StartRotation( point.x(), point.y() );
637 Standard_Failure::Raise( "incompatible Current Mode" );
641 activateCursor( myCurrentMode );
644 void View::onMButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint /*point*/ )
646 if ( nFlags & CASCADESHORTCUTKEY )
647 myCurrentMode = CurAction3d_DynamicPanning;
648 activateCursor( myCurrentMode );
651 void View::onRButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
653 if ( nFlags & CASCADESHORTCUTKEY )
657 myView->SetComputedMode (Standard_False);
659 myCurrentMode = CurAction3d_DynamicRotation;
660 myView->StartRotation( point.x(), point.y() );
664 Popup( point.x(), point.y() );
666 activateCursor( myCurrentMode );
669 void View::onLButtonUp( Qt::MouseButtons nFlags, const QPoint point )
671 switch( myCurrentMode )
673 case CurAction3d_Nothing:
674 if ( point.x() == myXmin && point.y() == myYmin )
676 // no offset between down and up --> selectEvent
679 if ( nFlags & MULTISELECTIONKEY )
680 MultiInputEvent( point.x(), point.y() );
682 InputEvent( point.x(), point.y() );
686 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
689 if ( nFlags & MULTISELECTIONKEY )
690 MultiDragEvent( point.x(), point.y(), 1 );
692 DragEvent( point.x(), point.y(), 1 );
695 case CurAction3d_DynamicZooming:
696 myCurrentMode = CurAction3d_Nothing;
699 case CurAction3d_WindowZooming:
700 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );//,LongDash);
703 if ( (abs( myXmin - myXmax ) > ValZWMin ) ||
704 (abs( myYmin - myYmax ) > ValZWMin ) )
705 myView->WindowFitAll( myXmin, myYmin, myXmax, myYmax );
706 myCurrentMode = CurAction3d_Nothing;
709 case CurAction3d_DynamicPanning:
710 myCurrentMode = CurAction3d_Nothing;
713 case CurAction3d_GlobalPanning :
714 myView->Place( point.x(), point.y(), myCurZoom );
715 myCurrentMode = CurAction3d_Nothing;
718 case CurAction3d_DynamicRotation:
719 myCurrentMode = CurAction3d_Nothing;
723 Standard_Failure::Raise(" incompatible Current Mode ");
726 activateCursor( myCurrentMode );
727 ApplicationCommonWindow::getApplication()->onSelectionChanged();
730 void View::onMButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint /*point*/ )
732 myCurrentMode = CurAction3d_Nothing;
733 activateCursor( myCurrentMode );
736 void View::onRButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint point )
738 if ( myCurrentMode == CurAction3d_Nothing )
739 Popup( point.x(), point.y() );
742 QApplication::setOverrideCursor( Qt::WaitCursor );
743 // reset tyhe good Degenerated mode according to the strored one
744 // --> dynamic rotation may have change it
745 myView->SetComputedMode (myHlrModeIsOn);
746 QApplication::restoreOverrideCursor();
747 myCurrentMode = CurAction3d_Nothing;
749 activateCursor( myCurrentMode );
752 void View::onMouseMove( Qt::MouseButtons nFlags, const QPoint point )
754 if ( nFlags & Qt::LeftButton || nFlags & Qt::RightButton || nFlags & Qt::MidButton )
756 switch ( myCurrentMode )
758 case CurAction3d_Nothing:
761 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
762 if ( nFlags & MULTISELECTIONKEY )
763 MultiDragEvent( myXmax, myYmax, 0 );
765 DragEvent( myXmax, myYmax, 0 );
766 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
768 case CurAction3d_DynamicZooming:
769 myView->Zoom( myXmax, myYmax, point.x(), point.y() );
773 case CurAction3d_WindowZooming:
776 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
777 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
779 case CurAction3d_DynamicPanning:
780 myView->Pan( point.x() - myXmax, myYmax - point.y() );
784 case CurAction3d_GlobalPanning:
786 case CurAction3d_DynamicRotation:
787 myView->Rotation( point.x(), point.y() );
791 Standard_Failure::Raise( "incompatible Current Mode" );
799 if ( nFlags & MULTISELECTIONKEY )
800 MultiMoveEvent( point.x(), point.y() );
802 MoveEvent( point.x(), point.y() );
806 void View::DragEvent( const int x, const int y, const int TheState )
808 // TheState == -1 button down
809 // TheState == 0 move
810 // TheState == 1 button up
812 static Standard_Integer theButtonDownX = 0;
813 static Standard_Integer theButtonDownY = 0;
815 if ( TheState == -1 )
823 myContext->Select( theButtonDownX, theButtonDownY, x, y, myView );
824 emit selectionChanged();
828 void View::InputEvent( const int /*x*/, const int /*y*/ )
831 emit selectionChanged();
834 void View::MoveEvent( const int x, const int y )
836 myContext->MoveTo( x, y, myView );
839 void View::MultiMoveEvent( const int x, const int y )
841 myContext->MoveTo( x, y, myView );
844 void View::MultiDragEvent( const int x, const int y, const int TheState )
846 static Standard_Integer theButtonDownX = 0;
847 static Standard_Integer theButtonDownY = 0;
849 if ( TheState == -1 )
856 myContext->ShiftSelect( theButtonDownX, theButtonDownY, x, y, myView );
857 emit selectionChanged();
861 void View::MultiInputEvent( const int /*x*/, const int /*y*/ )
863 myContext->ShiftSelect();
864 emit selectionChanged();
867 void View::Popup( const int /*x*/, const int /*y*/ )
869 ApplicationCommonWindow* stApp = ApplicationCommonWindow::getApplication();
870 QMdiArea* ws = ApplicationCommonWindow::getWorkspace();
871 QMdiSubWindow* w = ws->activeSubWindow();
872 if ( myContext->NbSelected() )
874 QList<QAction*>* aList = stApp->getToolActions();
875 QMenu* myToolMenu = new QMenu( 0 );
876 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolWireframeId ) );
877 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolShadingId ) );
878 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolColorId ) );
880 QMenu* myMaterMenu = new QMenu( myToolMenu );
882 QList<QAction*>* aMeterActions = ApplicationCommonWindow::getApplication()->getMaterialActions();
884 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
885 myMaterMenu = myToolMenu->addMenu( QPixmap( dir+QObject::tr("ICON_TOOL_MATER")), QObject::tr("MNU_MATER") );
886 for ( int i = 0; i < aMeterActions->size(); i++ )
887 myMaterMenu->addAction( aMeterActions->at( i ) );
889 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolTransparencyId ) );
890 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolDeleteId ) );
891 addItemInPopup(myToolMenu);
892 myToolMenu->exec( QCursor::pos() );
899 myBackMenu = new QMenu( 0 );
901 QAction* a = new QAction( QObject::tr("MNU_CH_BACK"), this );
902 a->setToolTip( QObject::tr("TBR_CH_BACK") );
903 connect( a, SIGNAL( triggered() ), this, SLOT( onBackground() ) );
904 myBackMenu->addAction( a );
905 addItemInPopup(myBackMenu);
907 a = new QAction( QObject::tr("MNU_CH_ENV_MAP"), this );
908 a->setToolTip( QObject::tr("TBR_CH_ENV_MAP") );
909 connect( a, SIGNAL( triggered() ), this, SLOT( onEnvironmentMap() ) );
910 a->setCheckable( true );
911 a->setChecked( false );
912 myBackMenu->addAction( a );
913 addItemInPopup(myBackMenu);
916 myBackMenu->exec( QCursor::pos() );
922 void View::addItemInPopup( QMenu* /*theMenu*/)
926 void View::DrawRectangle(const int MinX, const int MinY,
927 const int MaxX, const int MaxY, const bool Draw)
929 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
930 static Standard_Boolean m_IsVisible;
932 StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
933 StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
934 StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
935 StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;
938 aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
942 myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
943 myRectBand->setStyle( QStyleFactory::create("windows") );
944 myRectBand->setGeometry( aRect );
948 palette.setColor(myRectBand->foregroundRole(), Qt::white);
949 myRectBand->setPalette(palette);*/
952 if ( m_IsVisible && !Draw ) // move or up : erase at the old position
960 if (Draw) // move : draw
962 //aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
964 myRectBand->setGeometry( aRect );
965 //myRectBand->show();
969 void View::noActiveActions()
971 for ( int i = ViewFitAllId; i < ViewHlrOffId ; i++ )
973 QAction* anAction = myViewActions->at( i );
974 if( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
975 ( anAction == myViewActions->at( ViewZoomId ) ) ||
976 ( anAction == myViewActions->at( ViewPanId ) ) ||
977 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
978 ( anAction == myViewActions->at( ViewRotationId ) ) )
980 setCursor( *defCursor );
981 anAction->setCheckable( true );
982 anAction->setChecked( false );
987 void View::onBackground()
993 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
994 aColor.setRgb(R1*255,G1*255,B1*255);
996 QColor aRetColor = QColorDialog::getColor(aColor);
998 if( aRetColor.isValid() )
1000 R1 = aRetColor.red()/255.;
1001 G1 = aRetColor.green()/255.;
1002 B1 = aRetColor.blue()/255.;
1003 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
1008 void View::onEnvironmentMap()
1010 if (myBackMenu->actions().at(1)->isChecked())
1012 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
1013 tr("All Image Files (*.bmp *.gif *.jpg *.jpeg *.png *.tga)"));
1015 Handle(Graphic3d_TextureEnv) aTexture = new Graphic3d_TextureEnv( fileName.toLatin1().data() );
1017 myView->SetTextureEnv (aTexture);
1021 myView->SetTextureEnv (Handle(Graphic3d_TextureEnv)());
1027 bool View::dump(Standard_CString theFile)
1030 QString ext = QFileInfo( QString( theFile ) ).completeSuffix();
1031 if ( !ext.compare("ps") || !ext.compare("eps") || !ext.compare("tex") || !ext.compare("pdf") || !ext.compare("svg") || !ext.compare("pgf") )
1033 Graphic3d_ExportFormat exFormat;
1034 if ( !ext.compare("ps") )
1035 exFormat = Graphic3d_EF_PostScript;
1036 if ( !ext.compare("eps") )
1037 exFormat = Graphic3d_EF_EnhPostScript;
1038 if ( !ext.compare("tex") )
1039 exFormat = Graphic3d_EF_TEX;
1040 if ( !ext.compare("pdf") )
1041 exFormat = Graphic3d_EF_PDF;
1042 if ( !ext.compare("svg") )
1043 exFormat = Graphic3d_EF_SVG;
1044 if ( !ext.compare("pgf") )
1045 exFormat = Graphic3d_EF_PGF;
1048 myView->Export( theFile, exFormat );
1056 return myView->Dump(theFile);
1059 Handle(V3d_View)& View::getView()
1064 Handle(AIS_InteractiveContext)& View::getContext()
1069 View::CurrentAction3d View::getCurrentMode()
1071 return myCurrentMode;