Back to index

salome-gui  6.5.0
OCCViewer_ViewModel.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifndef OCCVIEWER_VIEWMODEL_H
00024 #define OCCVIEWER_VIEWMODEL_H
00025 
00026 #include <QColor>
00027 #include <QPoint>
00028 #include <QVector>
00029 
00030 #include "OCCViewer.h"
00031 
00032 #include "Qtx.h"
00033 #include "SUIT_ViewModel.h"
00034 
00035 #include <V3d_View.hxx>
00036 #include <AIS_Trihedron.hxx>
00037 #include <AIS_InteractiveContext.hxx>
00038 
00039 class QKeyEvent;
00040 class QMouseEvent;
00041 
00042 class SUIT_ViewWindow;
00043 class SUIT_Desktop;
00044 class OCCViewer_ViewWindow;
00045 
00046 class AIS_ListOfInteractive;
00047 
00048 #ifdef WIN32
00049 #pragma warning( disable:4251 )
00050 #endif
00051 
00052 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
00053 {
00054   Q_OBJECT
00055 
00056 public:
00058   enum { 
00059     HorizontalGradient, VerticalGradient,
00060     Diagonal1Gradient,  Diagonal2Gradient,
00061     Corner1Gradient,    Corner2Gradient,
00062     Corner3Gradient,    Corner4Gradient,
00063     LastGradient = Corner4Gradient
00064   };
00065   
00066   static QString           Type() { return "OCCViewer"; }
00067   static QString           backgroundData( QStringList&, QIntList&, QIntList& );
00068 
00069   OCCViewer_Viewer( bool DisplayTrihedron = true);
00070   virtual ~OCCViewer_Viewer();
00071 
00072   void update();
00073 
00074   virtual SUIT_ViewWindow*        createView(SUIT_Desktop* theDesktop);
00075   
00076   virtual void                    setViewManager(SUIT_ViewManager* theViewManager);
00077   virtual QString                 getType() const { return Type(); }
00078 
00079   virtual void                    contextMenuPopup(QMenu*);
00080   
00081   void                            getSelectedObjects(AIS_ListOfInteractive& theList);
00082   void                            setObjectsSelected(const AIS_ListOfInteractive& theList);
00083   void                            setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO);}
00084 
00085   void                            performSelectionChanged();
00086   // emit signal selectionChanged
00087 
00088   QColor                          backgroundColor() const;                              // obsolete
00089   void                            setBackgroundColor( const QColor& );                  // obsolete
00090   Qtx::BackgroundData             background() const;
00091   void                            setBackground( const Qtx::BackgroundData& );
00092 
00093   QColor                          backgroundColor(int theViewId) const;                 // obsolete
00094   void                            setBackgroundColor( int theViewId, const QColor& );   // obsolete
00095   Qtx::BackgroundData             background(int theViewId) const;
00096   void                            setBackground( int theViewId, const Qtx::BackgroundData& );
00097 
00099   bool                            trihedronActivated() const { return !myTrihedron.IsNull(); }
00100 
00101   void                            toggleTrihedron();
00102   bool                            isTrihedronVisible() const;
00103   virtual void                    setTrihedronShown( const bool );
00104 
00105   double                          trihedronSize() const;
00106   virtual void                    setTrihedronSize( const double , bool isRelative = true);
00107   
00108   bool                            trihedronRelative() const {return myIsRelative; }
00109 
00110   // a utility function, used by SALOME_View_s methods
00111   bool                            computeTrihedronSize( double& theNewSize, double& theSize );
00112 
00113   void                            updateTrihedron();
00114   
00115 
00116   virtual OCCViewer_ViewWindow*   createSubWindow();
00117 
00118 public:
00119   Handle(V3d_Viewer)              getViewer3d()    const { return myV3dViewer;}
00120   Handle(V3d_Viewer)              getCollector3d() const { return myV3dCollector; }
00121   Handle(AIS_InteractiveContext)  getAISContext()  const { return myAISContext; }
00122   Handle(AIS_Trihedron)           getTrihedron()   const { return myTrihedron; }
00123 
00124   int                             getTopLayerId();
00125 
00126   int                             interactionStyle() const;
00127   void                            setInteractionStyle( const int );
00128 
00129   int                             zoomingStyle() const;
00130   void                            setZoomingStyle( const int );
00131 
00132   void                            enableSelection(bool isEnabled);
00133   bool                            isSelectionEnabled() const { return mySelectionEnabled; }
00134 
00135   void                            enableMultiselection(bool isEnable);
00136   bool                            isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
00137 
00138   int                             getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
00139 
00140   bool                            isStaticTrihedronDisplayed() { return myShowStaticTrihedron; }
00141   void                            setStaticTrihedronDisplayed(const bool on);
00142 
00143   /* Selection management */
00144   bool    highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
00145   bool    unHighlightAll( bool=true ); 
00146   bool    isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
00147   bool    isVisible( const Handle(AIS_InteractiveObject)& );
00148 
00149   void    setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
00150   void    switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
00151   void    setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
00152   void    setIsos( const int u, const int v ); // number of isolines
00153   void    isos( int& u, int& v ) const;
00154 
00155   void    initView( OCCViewer_ViewWindow* view );
00156 
00157 signals:
00158   void selectionChanged();
00159   void deselection();
00160 
00161 protected slots:
00162   virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
00163   virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
00164   virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
00165   virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
00166 
00167   void onDumpView();
00168   void onChangeBackground();
00169 
00170 protected:
00171   Handle(V3d_Viewer)              myV3dViewer;
00172   Handle(V3d_Viewer)              myV3dCollector;
00173 
00174   Handle(AIS_Trihedron)           myTrihedron;
00175   Handle(AIS_InteractiveContext)  myAISContext;  
00176 
00177   int                             myInteractionStyle;
00178   int                             myZoomingStyle;
00179 
00180   bool                            mySelectionEnabled;
00181   bool                            myMultiSelectionEnabled;
00182   bool                            myIsRelative;
00183 
00184   int                             myTopLayerId;
00185 
00186   //QColor                          myBgColor;
00187   QPoint                          myStartPnt, myEndPnt;
00188 
00189   bool                            myShowStaticTrihedron;
00190 
00191   double                          myTrihedronSize;
00192 
00193   QVector<Qtx::BackgroundData>    myBackgrounds;
00194 };
00195 
00196 #ifdef WIN32
00197 #pragma warning( default:4251 )
00198 #endif
00199 
00200 #endif