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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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"
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>
31 #include <HYDROData_LandCoverMap.h>
33 #include <AIS_InteractiveContext.hxx>
35 HYDROGUI_ShapeLandCoverMap::HYDROGUI_ShapeLandCoverMap( HYDROGUI_OCCDisplayer* theDisplayer,
36 const Handle(AIS_InteractiveContext)& theContext,
37 const Handle_HYDROData_LandCoverMap& theLandCoverMap,
39 const bool theIsScalarMode )
40 : HYDROGUI_Shape( theContext, theLandCoverMap, theZLayer ),
41 myDisplayer( theDisplayer ),
42 myIsScalarMapMode( theIsScalarMode )
46 HYDROGUI_ShapeLandCoverMap::~HYDROGUI_ShapeLandCoverMap()
50 void HYDROGUI_ShapeLandCoverMap::update( bool theIsUpdateViewer, bool isDeactivateSelection )
52 setIsToUpdate( false );
54 Handle(HYDROData_LandCoverMap) aLandCoverMapObj =
55 Handle(HYDROData_LandCoverMap)::DownCast( getObject() );
57 TopoDS_Shape aLandCoverMapShape = aLandCoverMapObj->GetShape();
58 if ( !aLandCoverMapShape.IsNull() ) {
59 setShape( aLandCoverMapShape, false, false );
62 Handle(HYDROGUI_LandCoverMapPrs) aLandCoverMapPrs = Handle(HYDROGUI_LandCoverMapPrs)::DownCast( getAISObject() );
63 if ( !aLandCoverMapPrs.IsNull() )
64 aLandCoverMapPrs->UpdateColors();
66 HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
69 void HYDROGUI_ShapeLandCoverMap::setScalarMapModeEnabled( const bool theIsToEnable )
71 myIsScalarMapMode = theIsToEnable;
72 update( false, false );
75 void HYDROGUI_ShapeLandCoverMap::setVisible( const bool theState,
76 const bool theIsUpdateViewer )
78 HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
79 myDisplayer->SetToUpdateColorScale();
82 void HYDROGUI_ShapeLandCoverMap::displayShape( const bool theIsUpdateViewer )
84 HYDROGUI_Shape::displayShape( theIsUpdateViewer );
85 myDisplayer->SetToUpdateColorScale();
88 Handle_AIS_InteractiveObject HYDROGUI_ShapeLandCoverMap::createShape() const
90 Handle(HYDROData_LandCoverMap) aLandCoverMap = Handle(HYDROData_LandCoverMap)::DownCast( getObject() );
91 if ( !aLandCoverMap.IsNull() )
93 Handle(HYDROGUI_LandCoverMapPrs) aLandCoverMapPrs = new HYDROGUI_LandCoverMapPrs( aLandCoverMap );
94 if ( myIsScalarMapMode )
96 LightApp_Application* anApp = myDisplayer->module()->getApp();
97 OCCViewer_ViewManager* aViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
98 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
101 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
103 int aViewerId = (size_t)aViewer;
105 // Set Strickler table
106 Handle(HYDROData_StricklerTable) aTable =
107 myDisplayer->module()->getLandCoverColoringTable( aViewerId );
108 if( !aTable.IsNull() )
109 aLandCoverMapPrs->SetTable( aTable );
112 OCCViewer_ViewWindow* aWnd = dynamic_cast<OCCViewer_ViewWindow*>( aViewer->getViewManager()->getActiveView() );
113 Handle(V3d_View) aView = aWnd->getViewPort()->getView();
114 if( !aView.IsNull() )
116 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
117 aLandCoverMapPrs->SetColorScale( aColorScale );
122 return aLandCoverMapPrs;
127 void HYDROGUI_ShapeLandCoverMap::display( const bool theIsUpdateViewer )
129 HYDROGUI_Shape::display( theIsUpdateViewer );
130 myDisplayer->SetToUpdateColorScale();
133 void HYDROGUI_ShapeLandCoverMap::erase( const bool theIsUpdateViewer )
135 HYDROGUI_Shape::erase( theIsUpdateViewer );
136 myDisplayer->SetToUpdateColorScale();