2 #define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */
6 #include "ApplicationCommon.h"
8 #include <QApplication>
11 #include <QColorDialog>
14 #include <QMouseEvent>
15 #include <QRubberBand>
17 #include <Visual3d_View.hxx>
18 #include <Graphic3d_ExportFormat.hxx>
19 #include <QWindowsStyle>
22 #include <WNT_Window.hxx>
23 #include <Graphic3d_WNTGraphicDevice.hxx>
27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
29 #include <X11/Xmu/StdCmap.h>
31 #include <Xw_Window.hxx>
32 #include <Graphic3d_GraphicDevice.hxx>
36 // the key for multi selection :
37 #define MULTISELECTIONKEY Qt::ShiftModifier
39 // the key for shortcut ( use to activate dynamic rotation, panning )
40 #define CASCADESHORTCUTKEY Qt::ControlModifier
42 // for elastic bean selection
45 static QCursor* defCursor = NULL;
46 static QCursor* handCursor = NULL;
47 static QCursor* panCursor = NULL;
48 static QCursor* globPanCursor = NULL;
49 static QCursor* zoomCursor = NULL;
50 static QCursor* rotCursor = NULL;
52 View::View( Handle(AIS_InteractiveContext) theContext, QWidget* parent )
57 //XSynchronize( x11Display(),true ); // it is possible to use QApplication::syncX();
58 XSynchronize( x11Info().display(),true ); // it is possible to use QApplication::syncX();
61 myContext = theContext;
70 setAttribute(Qt::WA_PaintOnScreen);
71 setAttribute(Qt::WA_NoSystemBackground);
74 XVisualInfo* pVisualInfo;
75 if ( x11Info().display() )
77 /* Initialization with the default VisualID */
78 Visual *v = DefaultVisual( x11Info().display(), DefaultScreen( x11Info().display() ) );
79 int visualID = XVisualIDFromVisual( v );
81 /* Here we use the settings from Optimizer_ViewInfo::TxglCreateWindow() */
82 int visualAttr[] = { GLX_RGBA, GLX_DEPTH_SIZE, 1, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
83 GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None };
84 pVisualInfo = ::glXChooseVisual( x11Info().display(), DefaultScreen( x11Info().display() ), visualAttr );
89 XSetWindowAttributes a;
91 Window p = RootWindow( x11Info().display(), DefaultScreen( x11Info().display() ) );
92 a.colormap = XCreateColormap( x11Info().display(), RootWindow( x11Info().display(), pVisualInfo->screen ),
93 pVisualInfo->visual, AllocNone );
95 QColor color = palette().color( backgroundRole() );
96 QColormap colmap = QColormap::instance();
97 a.background_pixel = colmap.pixel( color );
98 a.border_pixel = colmap.pixel( Qt::black );
100 p = parentWidget()->winId();
102 Window w = XCreateWindow( x11Info().display(), p, x(), y(), width(), height(),
103 0, pVisualInfo->depth, InputOutput, pVisualInfo->visual,
104 CWBackPixel | CWBorderPixel | CWColormap, &a );
108 if ( XGetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), &cmwret, &count ) )
110 cmw = new Window[count+1];
111 memcpy( (char *)cmw, (char *)cmwret, sizeof(Window)*count );
112 XFree( (char *)cmwret );
114 for ( i = 0; i < count; i++ )
116 if ( cmw[i] == winId() ) /* replace old window */
122 if ( i >= count ) /* append new window */
128 cmw = new Window[count];
131 /* Creating new window (with good VisualID) for this widget */
133 XSetWMColormapWindows( x11Info().display(), topLevelWidget()->winId(), cmw, count );
139 XFree( (char *)pVisualInfo );
140 XFlush( x11Info().display() );
143 myCurrentMode = CurAction3d_Nothing;
144 myDegenerateModeIsOn = Standard_True;
145 setMouseTracking( true );
150 setBackgroundRole( QPalette::NoRole );//NoBackground );
151 // set focus policy to threat QContextMenuEvent from keyboard
152 setFocusPolicy( Qt::StrongFocus );
153 setAttribute( Qt::WA_PaintOnScreen );
154 setAttribute( Qt::WA_NoSystemBackground );
165 myView = myContext->CurrentViewer()->CreateView();
166 int windowHandle = (int) winId();
168 lo = (short) windowHandle;
169 hi = (short) (windowHandle >> 16);
171 Handle(WNT_Window) hWnd = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(myContext->CurrentViewer()->Device()),(int) hi,(int) lo);
173 Handle(Xw_Window) hWnd = new Xw_Window(Handle(Graphic3d_GraphicDevice)::DownCast(myContext->CurrentViewer()->Device()),(int) hi,(int) lo,Xw_WQ_SAMEQUALITY);
175 myView->SetWindow( hWnd );
176 if ( !hWnd->IsMapped() )
178 myView->SetBackgroundColor(Quantity_NOC_BLACK);
179 myView->MustBeResized();
182 void View::paintEvent( QPaintEvent * e )
184 // QApplication::syncX();
193 void View::resizeEvent( QResizeEvent * e)
195 // QApplication::syncX();
196 if( !myView.IsNull() )
198 myView->MustBeResized();
211 myCurrentMode = CurAction3d_WindowZooming;
216 myCurrentMode = CurAction3d_DynamicZooming;
221 myCurrentMode = CurAction3d_DynamicPanning;
224 void View::rotation()
226 myCurrentMode = CurAction3d_DynamicRotation;
229 void View::globalPan()
231 // save the current zoom value
232 myCurZoom = myView->Scale();
236 myCurrentMode = CurAction3d_GlobalPanning;
241 myView->SetProj( V3d_Xpos );
246 myView->SetProj( V3d_Xneg );
251 myView->SetProj( V3d_Zpos );
256 myView->SetProj( V3d_Zneg );
261 myView->SetProj( V3d_Ypos );
266 myView->SetProj( V3d_Yneg );
271 myView->SetProj( V3d_XposYnegZpos );
281 QApplication::setOverrideCursor( Qt::WaitCursor );
282 myView->SetDegenerateModeOn();
283 myDegenerateModeIsOn = Standard_True;
284 QApplication::restoreOverrideCursor();
289 QApplication::setOverrideCursor( Qt::WaitCursor );
290 myView->SetDegenerateModeOff();
291 myDegenerateModeIsOn = Standard_False;
292 QApplication::restoreOverrideCursor();
295 void View::updateToggled( bool isOn )
297 QAction* sentBy = (QAction*)sender();
302 for ( int i = ViewFitAllId; i < ViewHlrOffId; i++ )
304 QAction* anAction = myViewActions->at( i );
305 if ( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
306 ( anAction == myViewActions->at( ViewZoomId ) ) ||
307 ( anAction == myViewActions->at( ViewPanId ) ) ||
308 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
309 ( anAction == myViewActions->at( ViewRotationId ) ) )
311 if ( anAction && ( anAction != sentBy ) )
313 anAction->setCheckable( true );
314 anAction->setChecked( false );
318 if ( sentBy == myViewActions->at( ViewFitAreaId ) )
319 setCursor( *handCursor );
320 else if ( sentBy == myViewActions->at( ViewZoomId ) )
321 setCursor( *zoomCursor );
322 else if ( sentBy == myViewActions->at( ViewPanId ) )
323 setCursor( *panCursor );
324 else if ( sentBy == myViewActions->at( ViewGlobalPanId ) )
325 setCursor( *globPanCursor );
326 else if ( sentBy == myViewActions->at( ViewRotationId ) )
327 setCursor( *rotCursor );
329 setCursor( *defCursor );
331 sentBy->setCheckable( false );
337 void View::initCursors()
340 defCursor = new QCursor( Qt::ArrowCursor );
342 handCursor = new QCursor( Qt::PointingHandCursor );
344 panCursor = new QCursor( Qt::SizeAllCursor );
345 if ( !globPanCursor )
346 globPanCursor = new QCursor( Qt::CrossCursor );
348 zoomCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ZOOM" ) ) );
350 rotCursor = new QCursor( QPixmap( ApplicationCommonWindow::getResourceDir() + QString( "/" ) + QObject::tr( "ICON_CURSOR_ROTATE" ) ) );
353 QList<QAction*>* View::getViewActions()
356 return myViewActions;
360 Get paint engine for the OpenGL viewer. [ virtual public ]
362 QPaintEngine* View::paintEngine() const
367 void View::initViewActions()
372 myViewActions = new QList<QAction*>();
373 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
376 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITALL") ), QObject::tr("MNU_FITALL"), this );
377 a->setToolTip( QObject::tr("TBR_FITALL") );
378 a->setStatusTip( QObject::tr("TBR_FITALL") );
379 connect( a, SIGNAL( activated() ) , this, SLOT( fitAll() ) );
380 myViewActions->insert(ViewFitAllId, a);
382 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FITAREA") ), QObject::tr("MNU_FITAREA"), this );
383 a->setToolTip( QObject::tr("TBR_FITAREA") );
384 a->setStatusTip( QObject::tr("TBR_FITAREA") );
385 connect( a, SIGNAL( activated() ) , this, SLOT( fitArea() ) );
387 a->setCheckable( true );
388 connect( a, SIGNAL( toggled( bool ) ) , this, SLOT( updateToggled( bool ) ) );
389 myViewActions->insert( ViewFitAreaId, a );
391 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ZOOM") ), QObject::tr("MNU_ZOOM"), this );
392 a->setToolTip( QObject::tr("TBR_ZOOM") );
393 a->setStatusTip( QObject::tr("TBR_ZOOM") );
394 connect( a, SIGNAL( activated() ) , this, SLOT( zoom() ) );
396 a->setCheckable( true );
397 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
398 myViewActions->insert( ViewZoomId, a );
400 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_PAN") ), QObject::tr("MNU_PAN"), this );
401 a->setToolTip( QObject::tr("TBR_PAN") );
402 a->setStatusTip( QObject::tr("TBR_PAN") );
403 connect( a, SIGNAL( activated() ) , this, SLOT( pan() ) );
405 a->setCheckable( true );
406 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
407 myViewActions->insert( ViewPanId, a );
409 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_GLOBALPAN") ), QObject::tr("MNU_GLOBALPAN"), this );
410 a->setToolTip( QObject::tr("TBR_GLOBALPAN") );
411 a->setStatusTip( QObject::tr("TBR_GLOBALPAN") );
412 connect( a, SIGNAL( activated() ) , this, SLOT( globalPan() ) );
414 a->setCheckable( true );
415 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
416 myViewActions->insert( ViewGlobalPanId, a );
418 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_FRONT") ), QObject::tr("MNU_FRONT"), this );
419 a->setToolTip( QObject::tr("TBR_FRONT") );
420 a->setStatusTip( QObject::tr("TBR_FRONT") );
421 connect( a, SIGNAL( activated() ) , this, SLOT( front() ) );
422 myViewActions->insert( ViewFrontId, a );
424 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BACK") ), QObject::tr("MNU_BACK"), this );
425 a->setToolTip( QObject::tr("TBR_BACK") );
426 a->setStatusTip( QObject::tr("TBR_BACK") );
427 connect( a, SIGNAL( activated() ) , this, SLOT( back() ) );
428 myViewActions->insert(ViewBackId, a);
430 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_TOP") ), QObject::tr("MNU_TOP"), this );
431 a->setToolTip( QObject::tr("TBR_TOP") );
432 a->setStatusTip( QObject::tr("TBR_TOP") );
433 connect( a, SIGNAL( activated() ) , this, SLOT( top() ) );
434 myViewActions->insert( ViewTopId, a );
436 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_BOTTOM") ), QObject::tr("MNU_BOTTOM"), this );
437 a->setToolTip( QObject::tr("TBR_BOTTOM") );
438 a->setStatusTip( QObject::tr("TBR_BOTTOM") );
439 connect( a, SIGNAL( activated() ) , this, SLOT( bottom() ) );
440 myViewActions->insert( ViewBottomId, a );
442 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_LEFT") ), QObject::tr("MNU_LEFT"), this );
443 a->setToolTip( QObject::tr("TBR_LEFT") );
444 a->setStatusTip( QObject::tr("TBR_LEFT") );
445 connect( a, SIGNAL( activated() ) , this, SLOT( left() ) );
446 myViewActions->insert( ViewLeftId, a );
448 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RIGHT") ), QObject::tr("MNU_RIGHT"), this );
449 a->setToolTip( QObject::tr("TBR_RIGHT") );
450 a->setStatusTip( QObject::tr("TBR_RIGHT") );
451 connect( a, SIGNAL( activated() ) , this, SLOT( right() ) );
452 myViewActions->insert( ViewRightId, a );
454 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_AXO") ), QObject::tr("MNU_AXO"), this );
455 a->setToolTip( QObject::tr("TBR_AXO") );
456 a->setStatusTip( QObject::tr("TBR_AXO") );
457 connect( a, SIGNAL( activated() ) , this, SLOT( axo() ) );
458 myViewActions->insert( ViewAxoId, a );
460 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_ROTATION") ), QObject::tr("MNU_ROTATION"), this );
461 a->setToolTip( QObject::tr("TBR_ROTATION") );
462 a->setStatusTip( QObject::tr("TBR_ROTATION") );
463 connect( a, SIGNAL( activated() ) , this, SLOT( rotation() ) );
464 a->setCheckable( true );
465 connect( a, SIGNAL( toggled(bool) ) , this, SLOT( updateToggled(bool) ) );
466 myViewActions->insert( ViewRotationId, a );
468 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_RESET") ), QObject::tr("MNU_RESET"), this );
469 a->setToolTip( QObject::tr("TBR_RESET") );
470 a->setStatusTip( QObject::tr("TBR_RESET") );
471 connect( a, SIGNAL( activated() ) , this, SLOT( reset() ) );
472 myViewActions->insert( ViewResetId, a );
474 QActionGroup* ag = new QActionGroup( this );
476 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLROFF") ), QObject::tr("MNU_HLROFF"), this );
477 a->setToolTip( QObject::tr("TBR_HLROFF") );
478 a->setStatusTip( QObject::tr("TBR_HLROFF") );
479 connect( a, SIGNAL( activated() ) , this, SLOT( hlrOff() ) );
480 a->setCheckable( true );
482 myViewActions->insert(ViewHlrOffId, a);
484 a = new QAction( QPixmap( dir+QObject::tr("ICON_VIEW_HLRON") ), QObject::tr("MNU_HLRON"), this );
485 a->setToolTip( QObject::tr("TBR_HLRON") );
486 a->setStatusTip( QObject::tr("TBR_HLRON") );
487 connect( a, SIGNAL( activated() ) ,this, SLOT( hlrOn() ) );
489 a->setCheckable( true );
491 myViewActions->insert( ViewHlrOnId, a );
494 void View::mousePressEvent( QMouseEvent* e )
496 if ( e->button() == Qt::LeftButton )
497 onLButtonDown( ( e->buttons() | e->modifiers() ), e->pos() );
498 else if ( e->button() == Qt::MidButton )
499 onMButtonDown( e->buttons() | e->modifiers(), e->pos() );
500 else if ( e->button() == Qt::RightButton )
501 onRButtonDown( e->buttons() | e->modifiers(), e->pos() );
504 void View::mouseReleaseEvent(QMouseEvent* e)
506 if ( e->button() == Qt::LeftButton )
507 onLButtonUp( e->buttons(), e->pos() );
508 else if ( e->button() == Qt::MidButton )
509 onMButtonUp( e->buttons(), e->pos() );
510 else if( e->button() == Qt::RightButton )
511 onRButtonUp( e->buttons(), e->pos() );
514 void View::mouseMoveEvent(QMouseEvent* e)
516 onMouseMove( e->buttons(), e->pos() );
519 void View::activateCursor( const CurrentAction3d mode )
523 case CurAction3d_DynamicPanning:
524 setCursor( *panCursor );
526 case CurAction3d_DynamicZooming:
527 setCursor( *zoomCursor );
529 case CurAction3d_DynamicRotation:
530 setCursor( *rotCursor );
532 case CurAction3d_GlobalPanning:
533 setCursor( *globPanCursor );
535 case CurAction3d_WindowZooming:
536 setCursor( *handCursor );
538 case CurAction3d_Nothing:
540 setCursor( *defCursor );
545 void View::onLButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
547 // save the current mouse coordinate in min
553 if ( nFlags & CASCADESHORTCUTKEY )
555 myCurrentMode = CurAction3d_DynamicZooming;
559 switch ( myCurrentMode )
561 case CurAction3d_Nothing:
562 if ( nFlags & MULTISELECTIONKEY )
563 MultiDragEvent( myXmax, myYmax, -1 );
565 DragEvent( myXmax, myYmax, -1 );
567 case CurAction3d_DynamicZooming:
569 case CurAction3d_WindowZooming:
571 case CurAction3d_DynamicPanning:
573 case CurAction3d_GlobalPanning:
575 case CurAction3d_DynamicRotation:
576 if ( !myDegenerateModeIsOn )
577 myView->SetDegenerateModeOn();
578 myView->StartRotation( point.x(), point.y() );
581 Standard_Failure::Raise( "incompatible Current Mode" );
585 activateCursor( myCurrentMode );
588 void View::onMButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
590 if ( nFlags & CASCADESHORTCUTKEY )
591 myCurrentMode = CurAction3d_DynamicPanning;
592 activateCursor( myCurrentMode );
595 void View::onRButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
597 if ( nFlags & CASCADESHORTCUTKEY )
599 if ( !myDegenerateModeIsOn )
600 myView->SetDegenerateModeOn();
601 myCurrentMode = CurAction3d_DynamicRotation;
602 myView->StartRotation( point.x(), point.y() );
606 Popup( point.x(), point.y() );
608 activateCursor( myCurrentMode );
611 void View::onLButtonUp( Qt::MouseButtons nFlags, const QPoint point )
613 switch( myCurrentMode )
615 case CurAction3d_Nothing:
616 if ( point.x() == myXmin && point.y() == myYmin )
618 // no offset between down and up --> selectEvent
621 if ( nFlags & MULTISELECTIONKEY )
622 MultiInputEvent( point.x(), point.y() );
624 InputEvent( point.x(), point.y() );
628 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
631 if ( nFlags & MULTISELECTIONKEY )
632 MultiDragEvent( point.x(), point.y(), 1 );
634 DragEvent( point.x(), point.y(), 1 );
637 case CurAction3d_DynamicZooming:
638 myCurrentMode = CurAction3d_Nothing;
641 case CurAction3d_WindowZooming:
642 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );//,LongDash);
645 if ( (abs( myXmin - myXmax ) > ValZWMin ) ||
646 (abs( myYmin - myYmax ) > ValZWMin ) )
647 myView->WindowFitAll( myXmin, myYmin, myXmax, myYmax );
648 myCurrentMode = CurAction3d_Nothing;
651 case CurAction3d_DynamicPanning:
652 myCurrentMode = CurAction3d_Nothing;
655 case CurAction3d_GlobalPanning :
656 myView->Place( point.x(), point.y(), myCurZoom );
657 myCurrentMode = CurAction3d_Nothing;
660 case CurAction3d_DynamicRotation:
661 myCurrentMode = CurAction3d_Nothing;
665 Standard_Failure::Raise(" incompatible Current Mode ");
668 activateCursor( myCurrentMode );
669 ApplicationCommonWindow::getApplication()->onSelectionChanged();
672 void View::onMButtonUp( Qt::MouseButtons nFlags, const QPoint point )
674 myCurrentMode = CurAction3d_Nothing;
675 activateCursor( myCurrentMode );
678 void View::onRButtonUp( Qt::MouseButtons nFlags, const QPoint point )
680 if ( myCurrentMode == CurAction3d_Nothing )
681 Popup( point.x(), point.y() );
684 QApplication::setOverrideCursor( Qt::WaitCursor );
685 // reset tyhe good Degenerated mode according to the strored one
686 // --> dynamic rotation may have change it
687 if ( !myDegenerateModeIsOn )
689 myView->SetDegenerateModeOff();
690 myDegenerateModeIsOn = Standard_False;
694 myView->SetDegenerateModeOn();
695 myDegenerateModeIsOn = Standard_True;
697 QApplication::restoreOverrideCursor();
698 myCurrentMode = CurAction3d_Nothing;
700 activateCursor( myCurrentMode );
703 void View::onMouseMove( Qt::MouseButtons nFlags, const QPoint point )
705 if ( nFlags & Qt::LeftButton || nFlags & Qt::RightButton || nFlags & Qt::MidButton )
707 switch ( myCurrentMode )
709 case CurAction3d_Nothing:
712 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
713 if ( nFlags & MULTISELECTIONKEY )
714 MultiDragEvent( myXmax, myYmax, 0 );
716 DragEvent( myXmax, myYmax, 0 );
717 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
719 case CurAction3d_DynamicZooming:
720 myView->Zoom( myXmax, myYmax, point.x(), point.y() );
724 case CurAction3d_WindowZooming:
727 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_False );
728 DrawRectangle( myXmin, myYmin, myXmax, myYmax, Standard_True );
730 case CurAction3d_DynamicPanning:
731 myView->Pan( point.x() - myXmax, myYmax - point.y() );
735 case CurAction3d_GlobalPanning:
737 case CurAction3d_DynamicRotation:
738 myView->Rotation( point.x(), point.y() );
742 Standard_Failure::Raise( "incompatible Current Mode" );
750 if ( nFlags & MULTISELECTIONKEY )
751 MultiMoveEvent( point.x(), point.y() );
753 MoveEvent( point.x(), point.y() );
757 void View::DragEvent( const int x, const int y, const int TheState )
759 // TheState == -1 button down
760 // TheState == 0 move
761 // TheState == 1 button up
763 static Standard_Integer theButtonDownX = 0;
764 static Standard_Integer theButtonDownY = 0;
766 if ( TheState == -1 )
774 myContext->Select( theButtonDownX, theButtonDownY, x, y, myView );
775 emit selectionChanged();
779 void View::InputEvent( const int x, const int y )
782 emit selectionChanged();
785 void View::MoveEvent( const int x, const int y )
787 myContext->MoveTo( x, y, myView );
790 void View::MultiMoveEvent( const int x, const int y )
792 myContext->MoveTo( x, y, myView );
795 void View::MultiDragEvent( const int x, const int y, const int TheState )
797 static Standard_Integer theButtonDownX = 0;
798 static Standard_Integer theButtonDownY = 0;
800 if ( TheState == -1 )
807 myContext->ShiftSelect( theButtonDownX, theButtonDownY, x, y, myView );
808 emit selectionChanged();
812 void View::MultiInputEvent( const int x, const int y )
814 myContext->ShiftSelect();
815 emit selectionChanged();
818 void View::Popup( const int x, const int y )
820 ApplicationCommonWindow* stApp = ApplicationCommonWindow::getApplication();
821 QWorkspace* ws = ApplicationCommonWindow::getWorkspace();
822 QWidget* w = ws->activeWindow();
823 if ( myContext->NbSelected() )
825 QList<QAction*>* aList = stApp->getToolActions();
826 QMenu* myToolMenu = new QMenu( 0 );
827 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolWireframeId ) );
828 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolShadingId ) );
829 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolColorId ) );
831 QMenu* myMaterMenu = new QMenu( myToolMenu );
833 QList<QAction*>* aMeterActions = ApplicationCommonWindow::getApplication()->getMaterialActions();
835 QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" );
836 myMaterMenu = myToolMenu->addMenu( QPixmap( dir+QObject::tr("ICON_TOOL_MATER")), QObject::tr("MNU_MATER") );
837 for ( int i = 0; i < aMeterActions->size(); i++ )
838 myMaterMenu->addAction( aMeterActions->at( i ) );
840 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolTransparencyId ) );
841 myToolMenu->addAction( aList->at( ApplicationCommonWindow::ToolDeleteId ) );
842 addItemInPopup(myToolMenu);
843 myToolMenu->exec( QCursor::pos() );
848 QMenu* myBackMenu = new QMenu( 0 );
849 QAction* a = new QAction( QObject::tr("MNU_CH_BACK"), this );
850 a->setToolTip( QObject::tr("TBR_CH_BACK") );
851 connect( a,SIGNAL( activated() ), this, SLOT( onBackground() ) );
852 myBackMenu->addAction( a );
853 addItemInPopup(myBackMenu);
854 myBackMenu->exec( QCursor::pos() );
861 void View::addItemInPopup( QMenu* theMenu)
865 void View::DrawRectangle(const int MinX, const int MinY,
866 const int MaxX, const int MaxY, const bool Draw)
868 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
869 static Standard_Boolean m_IsVisible;
871 StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
872 StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
873 StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
874 StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;
877 aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
881 myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
882 myRectBand->setStyle(new QWindowsStyle);
883 myRectBand->setGeometry( aRect );
887 palette.setColor(myRectBand->foregroundRole(), Qt::white);
888 myRectBand->setPalette(palette);*/
891 if ( m_IsVisible && !Draw ) // move or up : erase at the old position
899 if (Draw) // move : draw
901 //aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
903 myRectBand->setGeometry( aRect );
904 //myRectBand->show();
908 void View::noActiveActions()
910 for ( int i = ViewFitAllId; i < ViewHlrOffId ; i++ )
912 QAction* anAction = myViewActions->at( i );
913 if( ( anAction == myViewActions->at( ViewFitAreaId ) ) ||
914 ( anAction == myViewActions->at( ViewZoomId ) ) ||
915 ( anAction == myViewActions->at( ViewPanId ) ) ||
916 ( anAction == myViewActions->at( ViewGlobalPanId ) ) ||
917 ( anAction == myViewActions->at( ViewRotationId ) ) )
919 setCursor( *defCursor );
920 anAction->setCheckable( true );
921 anAction->setChecked( false );
926 void View::onBackground()
932 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
933 aColor.setRgb(R1*255,G1*255,B1*255);
935 QColor aRetColor = QColorDialog::getColor(aColor);
937 if( aRetColor.isValid() )
939 R1 = aRetColor.red()/255.;
940 G1 = aRetColor.green()/255.;
941 B1 = aRetColor.blue()/255.;
942 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
947 bool View::dump(Standard_CString theFile)
950 QString ext = QFileInfo( QString( theFile ) ).completeSuffix();
951 if ( !ext.compare("ps") || !ext.compare("eps") || !ext.compare("tex") || !ext.compare("pdf") || !ext.compare("svg") || !ext.compare("pgf") )
953 Graphic3d_ExportFormat exFormat;
954 if ( !ext.compare("ps") )
955 exFormat = Graphic3d_EF_PostScript;
956 if ( !ext.compare("eps") )
957 exFormat = Graphic3d_EF_EnhPostScript;
958 if ( !ext.compare("tex") )
959 exFormat = Graphic3d_EF_TEX;
960 if ( !ext.compare("pdf") )
961 exFormat = Graphic3d_EF_PDF;
962 if ( !ext.compare("svg") )
963 exFormat = Graphic3d_EF_SVG;
964 if ( !ext.compare("pgf") )
965 exFormat = Graphic3d_EF_PGF;
968 myView->View()->Export( theFile, exFormat );
976 return myView->Dump(theFile);
979 Handle(V3d_View)& View::getView()
984 Handle(AIS_InteractiveContext)& View::getContext()
989 View::CurrentAction3d View::getCurrentMode()
991 return myCurrentMode;