Salome HOME
ec2f4843e3a63f35761fd3e461bdd00fed6af61d
[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 public:
73   // from QGraphicsItem
74   virtual QRectF                  boundingRect() const;
75
76   // from GraphicsView_Object
77   virtual void                    compute();
78
79   virtual void                    addTo( GraphicsView_ViewPort* theViewPort );
80   virtual void                    removeFrom( GraphicsView_ViewPort* theViewPort );
81
82   virtual bool                    isMovable() const { return false; }
83
84   virtual bool                    checkHighlight( double theX, double theY, QCursor& theCursor ) const;
85
86   virtual bool                    select( double theX, double theY, const QRectF& theRect );
87   virtual void                    unselect();
88   virtual void                    setSelected( bool theState );
89
90 protected:
91   void                            computeTransformationPoints( const bool theObligatoryInit = false );
92
93   QGraphicsItemGroup*             createPointItem( const QString& theCaption,
94                                                    const QColor& theColor );
95
96   /**
97    * Create presentations for transformation points A, B and C or update the presentation
98    * parameters if it is already created
99    */
100   void                            initTrsfPoints( const int thePointType );
101   /**
102    * Show/hide a transformation point if necessary.
103    */
104   void                            updateTrsfPoint( const int thePointType );
105
106 protected:
107   QCursor*                        getTransformationPointCursor() const { return myTransformationPointCursor; }
108
109 protected:
110   QImage                          myImage;
111
112   QGraphicsPixmapItem*            myPixmapItem;
113   QGraphicsSimpleTextItem*        myCaptionItem;
114   HYDROGUI_PrsImageFrame*         myPrsImageFrame;
115
116   bool                            myIsTransformationPointPreview;
117   bool                            myIsByTwoPoints;
118   int                             myTransformationPointType;
119   TransformationPointMap          myTransformationPointMap;
120
121 private:
122   QCursor*                        myTransformationPointCursor;
123 };
124
125 #endif