Salome HOME
refs #1832
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverColoringOp.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_LandCoverColoringOp.h"
20
21 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_OCCDisplayer.h"
23 #include "HYDROGUI_Operations.h"
24 #include "HYDROGUI_Tool2.h"
25 #include "HYDROGUI_UpdateFlags.h"
26
27 #include <HYDROData_Iterator.h>
28 #include <HYDROData_Bathymetry.h>
29 #include <HYDROData_StricklerTable.h>
30
31 #include <LightApp_Application.h>
32
33 #include <OCCViewer_ViewModel.h>
34 #include <OCCViewer_ViewManager.h>
35
36
37 HYDROGUI_LandCoverColoringOp::HYDROGUI_LandCoverColoringOp( HYDROGUI_Module* theModule, int theId )
38 : HYDROGUI_Operation( theModule ),
39   myId( theId )
40 {
41   QString aName;
42   switch( myId )
43   {
44     case LandCoverScalarMapModeOnId:  aName = tr( "LC_SCALARMAP_COLORING_ON" ); break;
45     case LandCoverScalarMapModeOffId: aName = tr( "LC_SCALARMAP_COLORING_OFF" ); break;
46     default: break;
47   }
48   setName( aName );
49 }
50
51 HYDROGUI_LandCoverColoringOp::~HYDROGUI_LandCoverColoringOp()
52 {
53 }
54
55 void HYDROGUI_LandCoverColoringOp::startOperation()
56 {
57   HYDROGUI_Operation::startOperation();
58
59   HYDROGUI_Module* aModule = module();
60
61   LightApp_Application* anApp = module()->getApp();
62   OCCViewer_ViewManager* aViewManager =
63     dynamic_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), false ) );
64
65   size_t aViewId = (size_t)aViewManager->getViewModel();
66
67   Handle(HYDROData_StricklerTable) aTable;
68
69   if ( myId == LandCoverScalarMapModeOnId ) {
70     aTable = Handle(HYDROData_StricklerTable)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
71     if ( !aTable.IsNull() ) {
72       aModule->setLandCoverColoringTable( aViewId, aTable );
73     }
74   } else if ( myId == LandCoverScalarMapModeOffId ) {
75     aModule->setLandCoversScalarMapModeOff( aViewId );
76   }
77     
78   // Hide bathymetries
79   HYDROData_Iterator anIterator( doc(), KIND_BATHYMETRY );
80   for( ; anIterator.More(); anIterator.Next() ) {
81     Handle(HYDROData_Bathymetry) aBath =
82       Handle(HYDROData_Bathymetry)::DownCast( anIterator.Current() );   
83     if ( !aBath.IsNull() && aModule->isObjectVisible( aViewId, aBath ) ) {
84       aModule->setObjectVisible( aViewId, aBath, false );
85     }
86   }
87
88   aModule->getOCCDisplayer()->SetToUpdateColorScale();
89   aModule->update( UF_OCCViewer );
90   commit();
91 }