Salome HOME
c5b3b41ffe9f4b9d242505dd85daea71f9cf02d0
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.h
1 // Copyright (C) 2007-2013  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.
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_SHAPE_H
24 #define HYDROGUI_SHAPE_H
25
26 #include <AIS_InteractiveContext.hxx>
27 #include <AIS_InteractiveObject.hxx>
28 #include <Aspect_ColorScale.hxx>
29 #include <TColgp_HArray1OfPnt.hxx>
30 #include <Quantity_HArray1OfColor.hxx>
31
32 #include <HYDROData_Entity.h>
33
34 #include <QColor>
35 #include <QImage>
36
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Wire.hxx>
39 #include <TopoDS_Compound.hxx>
40
41 class HYDROGUI_Shape
42 {
43 public:
44   HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext,
45                   const Handle(HYDROData_Entity)&       theObject,
46                   const int                             theZLayer = -1 );
47   ~HYDROGUI_Shape();
48
49 public:
50   virtual void               display( const bool theIsUpdateViewer = true );
51   virtual void               erase( const bool theIsUpdateViewer = true );
52
53   virtual void               highlight( bool theIsHighlight, bool isUpdateViewer );
54   virtual bool               isHighlighted() const;
55
56   Handle(HYDROData_Entity)   getObject() const { return myObject; }
57
58   virtual void               update( const bool theIsUpdateViewer = true );
59
60   virtual bool               getIsToUpdate() const { return myIsToUpdate; }
61   virtual void               setIsToUpdate( bool theState ) { myIsToUpdate = theState; }
62
63   virtual bool               isVisible() const { return myIsVisible; }
64   virtual void               setVisible( const bool theState,
65                                          const bool theIsUpdateViewer = true );
66
67   virtual void               setWire( const TopoDS_Wire& theWire,
68                                       const bool         theToDisplay = true,
69                                       const bool         theIsUpdateViewer = true );
70
71   virtual void               setFaces( const TopoDS_Compound& theWires,
72                                        const bool             theToDisplay = true,
73                                        const bool             theIsUpdateViewer = true );
74
75   virtual void               setFace( const TopoDS_Wire& theWire,
76                                       const bool         theToDisplay = true,
77                                       const bool         theIsUpdateViewer = true );
78
79   virtual void               setFace( const TopoDS_Face& theFace,
80                                       const bool         theToDisplay = true,
81                                       const bool         theIsUpdateViewer = true );
82
83   virtual void               setShape( const TopoDS_Shape& theShape,
84                                        const bool          theToDisplay = true,
85                                        const bool          theIsUpdateViewer = true );
86
87   virtual void               setFillingColor( const QColor& theColor,
88                                               const bool    theToDisplay = true,
89                                               const bool    theIsUpdateViewer = true );
90   virtual QColor             getFillingColor() const;
91
92   virtual void               setBorderColor( const QColor& theColor,
93                                              const bool    theToDisplay = true,
94                                              const bool    theIsUpdateViewer = true );
95   virtual QColor             getBorderColor() const;
96
97   virtual void               setHighlightColor( const QColor& theColor );
98   virtual QColor             getHighlightColor() const;
99
100   virtual void               setTextureFileName( const QString& theFileName,
101                                                  const bool     theToDisplay = true,
102                                                  const bool     theIsUpdateViewer = true );
103   virtual QString            getTextureFileName() const;
104
105   virtual Handle(AIS_InteractiveObject)  getAISObject() const { return myShape; }
106
107   void                       setZLayer( const int theZLayer );
108
109   void GetRange( double& theMin, double& theMax ) const;
110   void UpdateWithColorScale( const Handle(Aspect_ColorScale)& );
111
112 protected:
113   virtual void               buildShape();
114   virtual void               updateShape( const bool theToDisplay      = true,
115                                           const bool theIsUpdateViewer = true );
116   void                       displayShape( const bool theIsUpdateViewer );
117
118   virtual QColor             getActiveColor() const;
119
120 private:
121   static double              getQuantityColorVal( const int theColorVal );
122   void                       colorShapeBorder( const QColor& theColor );
123
124   static QString             generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj );
125   void                       removeTextureFile() const;
126
127   static QImage              reduceTexture( const QImage& theImage, const int theSizeLimit );
128
129 private:
130   Handle(AIS_InteractiveContext) myContext;
131   Handle(HYDROData_Entity)       myObject;
132   Handle(AIS_InteractiveObject)  myShape;
133
134   int                            myZLayer;
135
136   bool                           myIsToUpdate;
137   bool                           myIsVisible;
138
139   bool                           myIsHighlight;
140   TopoDS_Shape                   myTopoShape;
141   int                            myDisplayMode;
142   
143   QColor                         myFillingColor;
144   QColor                         myBorderColor;
145   QColor                         myHighlightColor;
146
147   QString                        myTextureFileName;
148
149   Handle_TColgp_HArray1OfPnt     myCoords;
150   Handle_Quantity_HArray1OfColor myColors;
151 };
152
153 #endif
154