Salome HOME
table de Strickler complete
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ShapeLandCoverMap.cxx
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 #include "HYDROGUI_ShapeLandCoverMap.h"
20 #include "HYDROGUI_OCCDisplayer.h"
21 #include "HYDROGUI_LandCoverMapPrs.h"
22 #include "HYDROGUI_Tool.h"
23 #include "HYDROGUI_Module.h"
24
25 #include <LightApp_Application.h>
26 #include <OCCViewer_ViewManager.h>
27 #include <OCCViewer_ViewModel.h>
28 #include <OCCViewer_ViewWindow.h>
29 #include <OCCViewer_ViewPort3d.h>
30
31 #include <HYDROData_LandCoverMap.h>
32
33 #include <AIS_InteractiveContext.hxx>
34
35 HYDROGUI_ShapeLandCoverMap::HYDROGUI_ShapeLandCoverMap( HYDROGUI_OCCDisplayer* theDisplayer,
36                                                         const Handle(AIS_InteractiveContext)& theContext,
37                                                         const Handle_HYDROData_LandCoverMap&  theLandCoverMap,
38                                                         const int                             theZLayer,
39                                                         const bool                            theIsScalarMode )
40 : HYDROGUI_Shape( theContext, theLandCoverMap, theZLayer ),
41   myDisplayer( theDisplayer ),
42   myIsScalarMapMode( theIsScalarMode )
43 {
44   setFillingColor( QColor(), false, false );
45 }
46
47 HYDROGUI_ShapeLandCoverMap::~HYDROGUI_ShapeLandCoverMap()
48 {
49 }
50
51 void HYDROGUI_ShapeLandCoverMap::update( bool theIsUpdateViewer, bool isDeactivateSelection )
52 {
53   setIsToUpdate( false );
54
55   Handle(HYDROData_LandCoverMap) aLandCoverMapObj =
56     Handle(HYDROData_LandCoverMap)::DownCast( getObject() );
57
58   TopoDS_Shape aLandCoverMapShape = aLandCoverMapObj->GetShape();
59   if ( !aLandCoverMapShape.IsNull() ) {
60     setShape( aLandCoverMapShape, false, false );
61   }
62
63   Handle(HYDROGUI_LandCoverMapPrs) aLandCoverMapPrs = Handle(HYDROGUI_LandCoverMapPrs)::DownCast( getAISObject() );
64   if ( !aLandCoverMapPrs.IsNull() )
65     aLandCoverMapPrs->UpdateColors();
66
67   HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
68 }
69
70 bool HYDROGUI_ShapeLandCoverMap::isScalarMapModeEnabled() const
71 {
72   return myIsScalarMapMode;
73 }
74
75 void HYDROGUI_ShapeLandCoverMap::setScalarMapModeEnabled( const bool theIsToEnable )
76 {
77   myIsScalarMapMode = theIsToEnable;
78   update( false, false );
79 }
80
81 void HYDROGUI_ShapeLandCoverMap::setVisible( const bool theState,
82                                              const bool theIsUpdateViewer )
83 {
84   HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
85   myDisplayer->SetToUpdateColorScale();
86 }
87
88 void HYDROGUI_ShapeLandCoverMap::displayShape( const bool theIsUpdateViewer )
89 {
90   HYDROGUI_Shape::displayShape( theIsUpdateViewer );
91   myDisplayer->SetToUpdateColorScale();
92 }
93
94 Handle_AIS_InteractiveObject HYDROGUI_ShapeLandCoverMap::createShape() const
95 {
96   Handle(HYDROData_LandCoverMap) aLandCoverMap = Handle(HYDROData_LandCoverMap)::DownCast( getObject() );
97   if ( !aLandCoverMap.IsNull() )
98   {
99     Handle(HYDROGUI_LandCoverMapPrs) aLandCoverMapPrs = new HYDROGUI_LandCoverMapPrs( aLandCoverMap );    
100     if ( myIsScalarMapMode )
101     {
102       LightApp_Application* anApp = myDisplayer->module()->getApp();
103       OCCViewer_ViewManager* aViewManager = ::qobject_cast<OCCViewer_ViewManager*>( 
104         anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
105       if ( aViewManager )
106       {
107         if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
108         {
109           int aViewerId = (size_t)aViewer;
110
111           // Set Strickler table
112           Handle(HYDROData_StricklerTable) aTable = 
113             myDisplayer->module()->getLandCoverColoringTable( aViewerId );
114           if( !aTable.IsNull() )
115             aLandCoverMapPrs->SetTable( aTable );
116
117           // Set color scale
118           OCCViewer_ViewWindow* aWnd = dynamic_cast<OCCViewer_ViewWindow*>( aViewer->getViewManager()->getActiveView() );
119           Handle(V3d_View) aView = aWnd->getViewPort()->getView();
120           if( !aView.IsNull() )
121           {
122             Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
123             aLandCoverMapPrs->SetColorScale( aColorScale );
124           }
125         }
126       }
127     }
128     return aLandCoverMapPrs;
129   }
130   return NULL;
131 }
132
133 void HYDROGUI_ShapeLandCoverMap::display( const bool theIsUpdateViewer )
134 {
135   HYDROGUI_Shape::display( theIsUpdateViewer );
136   myDisplayer->SetToUpdateColorScale();
137 }
138
139 void HYDROGUI_ShapeLandCoverMap::erase( const bool theIsUpdateViewer )
140 {
141   HYDROGUI_Shape::erase( theIsUpdateViewer );
142   myDisplayer->SetToUpdateColorScale();
143 }