Salome HOME
6a7822b4ce45fbd3066c3d62daab39e3cb6898c1
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PrsImage.h
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef HYDROGUI_PRSIMAGE_H
24 #define HYDROGUI_PRSIMAGE_H
25
26 #include "HYDROGUI_Prs.h"
27
28 class HYDROGUI_PrsImageFrame;
29
30 /*
31   Class       : HYDROGUI_PrsImage
32   Description : Presentation for image object
33 */
34 class HYDROGUI_PrsImage : public HYDROGUI_Prs
35 {
36 public:
37   enum TransformationPointType { None = 0, PointA, PointB, PointC };
38   struct TransformationPoint
39   {
40     TransformationPoint() : Point( 0, 0 ), Caption( "" ), GroupItem( 0 ) {}
41
42     QPoint              Point;
43     QString             Caption;
44     QGraphicsItemGroup* GroupItem;
45   };
46   typedef QMap        < int, TransformationPoint > TransformationPointMap;
47   typedef QMapIterator< int, TransformationPoint > TransformationPointMapIterator;
48
49 public:
50   HYDROGUI_PrsImage( const Handle(HYDROData_Entity)& theObject );
51   virtual ~HYDROGUI_PrsImage();
52
53 public:
54   void                            setImage( const QImage& theImage,
55                                             const bool theCompute = false );
56   QImage                          getImage() const;
57
58   void                            setCaption( const QString& theCaption );
59   QString                         getCaption() const;
60
61   void                            setIsTransformationPointPreview( const bool theState );
62   bool                            getIsTransformationPointPreview() const;
63
64   void                            setIsByTwoPoints( const bool theIsByTwoPoints );
65   bool                            getIsByTwoPoints() const;
66
67   void                            setTransformationPointType( const int thePointType );
68
69   void                            setTransformationPointMap( const TransformationPointMap& theMap );
70   const TransformationPointMap&   getTransformationPointMap() const { return myTransformationPointMap; }
71
72   void                            updateTransformationPoint( const int thePointType,
73                                                              const bool theIsY,
74                                                              const int theValue );
75
76   /**
77    * Set shape of the transformation point cursor.
78    * @param theCursorShape a cursor shape to be set
79    */
80   void                            setTransformationPointCursorShape(Qt::CursorShape theCursorShape);
81
82 public:
83   // from QGraphicsItem
84   virtual QRectF                  boundingRect() const;
85
86   // from GraphicsView_Object
87   virtual void                    compute();
88
89   virtual void                    addTo( GraphicsView_ViewPort* theViewPort );
90   virtual void                    removeFrom( GraphicsView_ViewPort* theViewPort );
91
92   virtual bool                    isMovable() const { return false; }
93
94   virtual bool                    checkHighlight( double theX, double theY, QCursor& theCursor ) const;
95
96   virtual bool                    select( double theX, double theY, const QRectF& theRect );
97   virtual void                    unselect();
98   virtual void                    setSelected( bool theState );
99
100 protected:
101   void                            computeTransformationPoints( const bool theObligatoryInit = false );
102
103   QGraphicsItemGroup*             createPointItem( const QString& theCaption,
104                                                    const QColor& theColor );
105
106   /**
107    * Create presentations for transformation points A, B and C or update the presentation
108    * parameters if it is already created
109    */
110   void                            initTrsfPoints( const int thePointType );
111   /**
112    * Show/hide a transformation point if necessary.
113    */
114   void                            updateTrsfPoint( const int thePointType );
115
116 protected:
117   QCursor*                        getTransformationPointCursor() const { return myTransformationPointCursor; }
118
119 protected:
120   QImage                          myImage;
121
122   QGraphicsPixmapItem*            myPixmapItem;
123   QGraphicsSimpleTextItem*        myCaptionItem;
124   HYDROGUI_PrsImageFrame*         myPrsImageFrame;
125
126   bool                            myIsTransformationPointPreview;
127   bool                            myIsByTwoPoints;
128   int                             myTransformationPointType;
129   TransformationPointMap          myTransformationPointMap;
130
131 private:
132   QCursor*                        myTransformationPointCursor;
133 };
134
135 #endif