qocc3dwidget.h

Go to the documentation of this file.
00001 /************************************************************************************
00002 **
00003 ** This file is part of the QtOPENCASCADE Toolkit.
00004 **
00005 ** Copyright (C) 2006, 2007, 2008 QtOCC Team Members
00006 **               Peter Dolbey, Marc Britten, Stephane Routelous
00007 **               Stefan Boeykens, Pawel Dobrolowski, Walter Steffe
00008 **               Álvaro Castro Castilla, Dirk Burski, Fotis Sioutis
00009 **
00010 ** This library is free software; you can redistribute it and/or
00011 ** modify it under the terms of the GNU Lesser General Public
00012 ** License as published by the Free Software Foundation; either
00013 ** version 2.1 of the License, or (at your option) any later version.
00014 ** 
00015 ** This library is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 ** Lesser General Public License for more details.
00019 ** 
00020 ** You should have received a copy of the GNU Lesser General Public
00021 ** License along with this library; if not, write to the Free Software
00022 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023 **
00024 ***********************************************************************************/
00025 
00026 #ifndef QOCC3DWIDGET_H
00027 #define QOCC3DWIDGET_H
00028 
00029 #include <QtGui/QRubberBand>
00030 #include <QtGui/QToolBar>
00031 
00032 #include "qocc.h"
00033 #include "qoccdocument.h"
00034 #include "qocccontroller.h"
00035 
00036 /** the key for multi selection */
00037 #define MULTISELECTIONKEY  Qt::ShiftModifier   
00038 
00039 /** The key for shortcut ( use to activate dynamic rotation, panning ) */
00040 #define CASCADESHORTCUTKEY Qt::ControlModifier 
00041 
00042 #define ValZWMin 1 /** For elastic bean selection */
00043 
00044 class Handle(Visual3d_View);
00045 
00046 class QOCC_DECLSPEC Qocc3dWidget : public QWidget 
00047 {
00048         Q_OBJECT
00049 
00050 public:
00051 
00052         enum CurrentAction3d {  CurAction3d_Undefined,
00053                                                         CurAction3d_Nothing, 
00054                                                         CurAction3d_Picking,
00055                                                         CurAction3d_DynamicZooming,
00056                                                         CurAction3d_WindowZooming, 
00057                                                         CurAction3d_DynamicPanning,
00058                                                         CurAction3d_GlobalPanning, 
00059                                                         CurAction3d_DynamicRotation };
00060 /*
00061         enum ViewAction {       ViewFitAllId, 
00062                                                 ViewFitAreaId, 
00063                                                 ViewZoomId, 
00064                                                 ViewPanId, 
00065                                                 ViewGlobalPanId,
00066                                                 ViewFrontId, 
00067                                                 ViewBackId, 
00068                                                 ViewTopId, 
00069                                                 ViewBottomId, 
00070                                                 ViewLeftId, 
00071                                                 ViewRightId,
00072                                                 ViewAxoId, 
00073                                                 ViewRotationId, 
00074                                                 ViewResetId, 
00075                                                 ViewHlrOffId, 
00076                                                 ViewHlrOnId };
00077 */
00078 public:
00079 
00080         Qocc3dWidget(  const QoccController* aController = NULL, 
00081                                    QWidget *parent = NULL, 
00082                                    Qt::WindowFlags wflags = 0 );
00083 
00084     ~Qocc3dWidget();
00085 
00086         inline QoccController*                                  getController( void ) { return myController; }
00087         inline Handle(AIS_InteractiveContext)&  getContext( void )    { return myController->getContext(); }
00088         inline Handle(V3d_Viewer)&                              getViewer( void )     { return myController->getViewer(); }
00089         inline Handle(V3d_View)&                                        getView( void )       { return myView; }
00090 
00091         inline V3d_Coordinate x( void ) { return myCurrentX; }
00092         inline V3d_Coordinate y( void ) { return myCurrentY; }
00093         inline V3d_Coordinate z( void ) { return myCurrentZ; }
00094 
00095         inline Qt::MouseButtons      buttons()  const { return myMouseState; }
00096         inline Qt::MouseButtons      button()   const { return myMouseFlags; }
00097         inline Qt::KeyboardModifiers keyboard() const { return  myKeyboardFlags; }
00098 
00099         void setStatusMessage (const QString& aString);
00100 
00101         // Overrides
00102         QPaintEngine* paintEngine() const;
00103 
00104         // Accessors
00105         gp_Dir getDirection();
00106         gp_Pln getPlane();
00107         gp_Pnt getPoint();
00108         
00109         void redraw( bool isPainting = false );
00110         void setProjection( V3d_TypeOfOrientation orientation );
00111 
00112 signals:
00113 
00114         void initialized();
00115         void selectionChanged();
00116         void mouseMoved   ( Qocc3dWidget* widget, QMouseEvent* e );
00117         void mouseClicked ( Qocc3dWidget* widget, QMouseEvent* e );
00118         void sendStatus   ( const QString aMessage );
00119         //! Just a placeholder for now
00120         void popupMenu ( const Qocc3dWidget* aView, const QPoint aPoint ); 
00121         void error ( int errorCode, QString& errorDescription );
00122 
00123 public slots:
00124 
00125         void idle();
00126         void fitExtents();
00127         void fitAll();
00128     void fitArea();
00129     void zoom();
00130     void pan();
00131     void globalPan();
00132     void rotation();
00133     void hiddenLineOn();
00134     void hiddenLineOff();
00135         void background();
00136         void viewFront();
00137     void viewBack();
00138     void viewTop();
00139     void viewBottom();
00140     void viewLeft();
00141     void viewRight();
00142     void viewAxo();
00143         void viewTopFront();
00144         void viewGrid();
00145         void viewReset();
00146         void setReset();
00147 
00148         void newShape();
00149         void refresh();
00150 
00151 protected: // methods
00152 
00153         void initializeOCC();
00154 
00155     virtual void paintEvent        ( QPaintEvent* e );
00156     virtual void resizeEvent       ( QResizeEvent* e );
00157     virtual void mousePressEvent   ( QMouseEvent* e );
00158     virtual void mouseReleaseEvent ( QMouseEvent* e );
00159     virtual void mouseMoveEvent    ( QMouseEvent* e );
00160         virtual void wheelEvent        ( QWheelEvent* e );
00161 
00162         virtual void leaveEvent            ( QEvent * );
00163 
00164 private: // members
00165 
00166 #ifdef WNT
00167     Handle_WNT_Window     myWindow;
00168 #else
00169     Handle_Xw_Window      myWindow;
00170 #endif // WNT
00171 
00172         Handle(V3d_View)      myView;
00173         Handle(Visual3d_View) myVisual;
00174         QoccController*           myController;
00175                                         
00176         Standard_Boolean          myViewResized;
00177         Standard_Boolean          myViewInitialized;
00178     CurrentAction3d       myMode;
00179     Quantity_Factor       myCurZoom;
00180     Standard_Boolean      myGridSnap;
00181         AIS_StatusOfDetection myDetection;
00182 
00183         V3d_Coordinate        myCurrentX;
00184         V3d_Coordinate        myCurrentY;
00185         V3d_Coordinate        myCurrentZ;
00186                 
00187         QRubberBand*          myRubberBand;
00188         QPoint                    myStartPoint;
00189         QPoint                    myCurrentPoint;
00190         
00191         Standard_Real         myPrecision;
00192         Standard_Real         myViewPrecision;
00193         Standard_Boolean      myMapIsValid;
00194 
00195         Qt::KeyboardModifiers myKeyboardFlags;
00196         Qt::MouseButton           myMouseFlags;
00197         Qt::MouseButtons          myMouseState;
00198         QCursor                           myCrossCursor;
00199         QToolBar*                         myToolBar;
00200         
00201         // Shared message
00202         static QString            myStatusMessage;
00203 
00204 private: // methods
00205 
00206         void onLeftButtonDown  ( Qt::KeyboardModifiers nFlags, const QPoint point );
00207     void onMiddleButtonDown( Qt::KeyboardModifiers nFlags, const QPoint point );
00208     void onRightButtonDown ( Qt::KeyboardModifiers nFlags, const QPoint point );
00209     void onLeftButtonUp    ( Qt::KeyboardModifiers nFlags, const QPoint point );
00210     void onMiddleButtonUp  ( Qt::KeyboardModifiers nFlags, const QPoint point );
00211     void onRightButtonUp   ( Qt::KeyboardModifiers nFlags, const QPoint point );
00212     
00213         void onMouseMove  ( Qt::MouseButtons buttons, 
00214                                                 Qt::KeyboardModifiers nFlags, const QPoint point );
00215 
00216     AIS_StatusOfPick            dragEvent ( const QPoint startPoint, const QPoint endPoint, const bool multi = false );
00217     AIS_StatusOfPick            inputEvent( const bool multi = false );
00218     AIS_StatusOfDetection       moveEvent ( const QPoint point );
00219     
00220     void setMode( const CurrentAction3d mode );
00221         
00222         Standard_Real precision( Standard_Real aReal );
00223         Standard_Real viewPrecision( bool resized = false );
00224 
00225         void drawRubberBand( const QPoint origin, const QPoint position );
00226         void showRubberBand( void );
00227         void hideRubberBand( void );
00228 
00229         void sendStatusLocation ( void );
00230 
00231         Standard_Boolean convertToPlane(const Standard_Integer Xs, 
00232                                                                         const Standard_Integer Ys, 
00233                                                                                   Standard_Real& X,
00234                                                                                   Standard_Real& Y,
00235                                                                                   Standard_Real& Z);
00236                                                                                   
00237         void paintOCC();
00238         static int paintCallBack (Aspect_Drawable, 
00239                                                           void*, 
00240                                                           Aspect_GraphicCallbackStruct*);
00241 
00242 public:
00243 
00244         bool dump(Standard_CString theFile);
00245 
00246 };
00247 
00248 #endif // Qocc3dWidget_H

Generated on Sat Feb 23 21:22:15 2008 for QtGEOM by  doxygen 1.4.7