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