00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
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 
00037 #define MULTISELECTIONKEY  Qt::ShiftModifier   
00038 
00039 
00040 #define CASCADESHORTCUTKEY Qt::ControlModifier 
00041 
00042 #define ValZWMin 1 
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 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
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         
00102         QPaintEngine* paintEngine() const;
00103 
00104         
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 
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: 
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: 
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         
00202         static QString            myStatusMessage;
00203 
00204 private: 
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