Salome HOME
automatic load of shapes from dialog 'adjust shapefile to mesh'
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_OCCDisplayer.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_OCCDISPLAYER_H
20 #define HYDROGUI_OCCDISPLAYER_H
21
22 #include "HYDROGUI_AbstractDisplayer.h"
23
24 class HYDROGUI_Shape;
25 class AIS_InteractiveContext;
26 class AIS_ColorScale;
27 class OCCViewer_ViewManager;
28 class OCCViewer_Viewer;
29
30 /**
31  * \class HYDROGUI_OCCDisplayer
32  * \brief Class intended to create, display and update the presentations on OCC viewer.
33  */
34 class HYDROGUI_OCCDisplayer : public HYDROGUI_AbstractDisplayer
35 {
36 public:
37   /**
38    * \brief Constructor.
39    * \param theModule module object
40    */
41   HYDROGUI_OCCDisplayer( HYDROGUI_Module* theModule );
42
43   /**
44    * \brief Destructor.
45    */
46   virtual ~HYDROGUI_OCCDisplayer();
47
48 public:
49   /**
50    * \brief Force the specified objects to be updated.
51    * \param theObjs sequence of objects to update
52    * \param theViewerId viewer identifier
53    */
54   void                            SetToUpdate( const HYDROData_SequenceOfObjects& theObjs,
55                                                const size_t theViewerId );
56
57   /**
58    * \brief Get the applicable viewer type.
59    */
60   virtual QString  GetType() const;
61
62   /**
63    * \brief Add the z layer for preview and returns its index.
64    * \param theMgr OCC view manager
65    */
66   int                             AddPreviewZLayer( OCCViewer_ViewManager* theMgr );
67
68   /**
69    * \brief Removes the z layer.
70    * \param theMgr OCC view manager
71    * \param theLayer a layer index
72    */
73   void                            RemoveZLayer( OCCViewer_ViewManager* theMgr,
74                                                 const int theLayer,
75                                                 bool isClearAll = false);
76
77   void SetToUpdateColorScale();
78
79   /**
80    * \brief Get color scale for the viewer.
81    * \param theViewerId viewer identifier
82    * \return the color scale 
83    */
84   Handle(AIS_ColorScale) GetColorScale( const size_t theViewerId );
85
86
87   void UpdatePolylines( size_t theViewerId, int theType, int theSize );
88
89   void UpdateColorScale( const OCCViewer_Viewer* );
90
91 protected:
92   /**
93    * \brief Erase all viewer objects.
94    * \param theViewerId viewer identifier
95    */
96   void                            EraseAll( const size_t theViewerId );
97
98   /**
99    * \brief Erase the specified viewer objects.
100    * \param theObjs sequence of objects to erase
101    * \param theViewerId viewer identifier
102    */
103   void                            Erase( const HYDROData_SequenceOfObjects& theObjs,
104                                          const size_t theViewerId );
105
106   /**
107    * \brief Display the specified viewer objects.
108    * \param theObjs sequence of objects to display
109    * \param theViewerId viewer identifier
110    * \param theIsForced flag used to update all objects, including the unchanged ones
111    * \param theDoFitAll flag used to fit the view to all visible objects; do not fit by default
112    */
113   void                            Display( const HYDROData_SequenceOfObjects& theObjs,
114                                            const size_t theViewerId,
115                                            const bool theIsForced,
116                                            const bool theDoFitAll );
117   /**
118    * \brief Purge all invalid objects in the viewer.
119    * \param theViewerId viewer identifier
120    */
121   void                            purgeObjects( const size_t theViewerId );
122   
123 private:
124   /**
125    * \brief Creates new OCC shape.
126    * \param theViewerId viewer identifier
127    * \param theContext context of OCC viewer
128    * \param theObject data model object
129    * \return pointer to new created shape
130    */
131   HYDROGUI_Shape*                 createShape( const size_t                          theViewerId,
132                                                const Handle(AIS_InteractiveContext)& theContext,
133                                                const Handle(HYDROData_Entity)&       theObject );
134
135    /**
136    * \brief Display the specified object.
137    * \param theObject the object to display
138    * \param theViewer the viewer for displaying
139    * \param theIsForced the flag used to update the object shape
140    * \return true in case of success
141    */
142   bool                            Display( const Handle(HYDROData_Entity)& theObject,
143                                            const OCCViewer_Viewer* theViewer,
144                                            const bool theIsForced );
145
146    /**
147    * \brief Set Z layer to the shape corresponding to the HYDRO data object.
148    * \param theViewer the viewer for Z layer setting
149    * \param theObject the HYDRO object
150    * \param theZLayerId the Z layer ID
151    */
152   void                            SetZLayer( const OCCViewer_Viewer* theViewer,
153                                              const Handle(HYDROData_Entity)& theObject, 
154                                              const int theZLayerId );
155
156 private:
157   bool myToUpdateColorScale;
158   
159   QMap<size_t, Handle(AIS_ColorScale)> myColorScales;
160 };
161
162 #endif
163