+ // Get viewer id
+ size_t aViewerId = (size_t)theViewer;
+
+ // Get object shape
+ HYDROGUI_Shape* anObjShape = module()->getObjectShape( aViewerId, theObject );
+
+ // Set Z layer
+ if ( anObjShape ) {
+ aCtx->SetZLayer( anObjShape->getAISObject(), theZLayerId );
+ }
+}
+
+void HYDROGUI_OCCDisplayer::SetToUpdateColorScale()
+{
+ myToUpdateColorScale = true;
+}
+
+void HYDROGUI_OCCDisplayer::UpdateColorScale( const OCCViewer_Viewer* theViewer )
+{
+ if( !myToUpdateColorScale || !theViewer )
+ return;
+
+ OCCViewer_ViewWindow* aWnd = dynamic_cast<OCCViewer_ViewWindow*>( theViewer->getViewManager()->getActiveView() );
+ Handle(V3d_View) aView = aWnd->getViewPort()->getView();
+
+ int aViewerId = (size_t)theViewer;//TODO: check if viewer id is correct
+ bool isLandCoverColoringOn = module()->isLandCoversScalarMapModeOn( aViewerId );
+
+ QList<HYDROGUI_Shape*> aLandCoverMapShapes = module()->getObjectShapes( aViewerId, KIND_LAND_COVER_MAP );
+ QList<HYDROGUI_Shape*> aBathShapes = module()->getObjectShapes( aViewerId, KIND_BATHYMETRY );
+
+ bool isDisplayColorScale = !aBathShapes.empty() || isLandCoverColoringOn;
+ Standard_Real anXPos = 0.05; //TODO
+ Standard_Real anYPos = 0.1; //TODO
+ Standard_Real aWidth = 0.2; //TODO
+ Standard_Real aHeight = 0.5; //TODO
+ Standard_Integer aTextHeight = 14; //TODO
+ Standard_Integer aNbIntervals = 20; //TODO
+ TCollection_ExtendedString aColorScaleTitle = "";//TODO
+
+ Standard_Real aColorScaleMin = 0, aColorScaleMax = 1;
+
+ // Get range
+ Handle(HYDROData_StricklerTable) aTable;
+ QStringList aTableTypes;
+ if ( isLandCoverColoringOn ) {
+ aTable = module()->getLandCoverColoringTable( aViewerId );
+ if ( !aTable.IsNull() ) {
+ // TODO: non-empty title leads to buggy behaviour
+ // aColorScaleTitle = TCollection_ExtendedString( aTable->GetName().toLatin1().constData() );
+ aTable->GetCoefficientRange( aColorScaleMin, aColorScaleMax );
+ aTableTypes = aTable->GetTypes();
+ }
+ } else {
+ Standard_Real aMin, aMax;
+ bool isFirst = true;
+ foreach( HYDROGUI_Shape* aShape, aBathShapes )
+ {
+ HYDROGUI_ShapeBathymetry* aBathShape = dynamic_cast<HYDROGUI_ShapeBathymetry*>( aShape );
+ if( !aBathShape || !aBathShape->isVisible() )
+ continue;
+
+ aBathShape->GetRange( aMin, aMax );
+
+ if( isFirst || aMin < aColorScaleMin )
+ aColorScaleMin = aMin;
+ if( isFirst || aMax > aColorScaleMax )
+ aColorScaleMax = aMax;
+
+ isFirst = false;
+ }
+ }
+
+ Handle(AIS_ColorScale) aColorScale = GetColorScale( aViewerId );
+ Handle(AIS_InteractiveContext) aCtx = theViewer->getAISContext();
+ if( isDisplayColorScale )
+ {
+ if( !aColorScale.IsNull() )
+ {
+ aColorScale->SetXPosition( anXPos );
+ aColorScale->SetYPosition( anYPos );
+ aColorScale->SetWidth( aWidth );
+ aColorScale->SetHeight( aHeight );
+
+ aColorScale->SetTextHeight( aTextHeight );
+ aColorScale->SetNumberOfIntervals( aNbIntervals );
+
+ aColorScale->SetTitle( aColorScaleTitle );
+ aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
+
+ aColorScale->SetToUpdate();
+
+ if ( !isLandCoverColoringOn ) {
+ foreach( HYDROGUI_Shape* aShape, aBathShapes ) {
+ HYDROGUI_ShapeBathymetry* aBathShape = dynamic_cast<HYDROGUI_ShapeBathymetry*>( aShape );
+ if( !aBathShape || !aBathShape->isVisible() )
+ continue;
+
+ aBathShape->UpdateWithColorScale( aColorScale );
+ }
+ }
+
+ if ( !aCtx.IsNull() && !aCtx->IsDisplayed( aColorScale ) ) {
+ aCtx->Display( aColorScale );
+ }
+ }
+ }
+ else
+ {
+ if ( !aCtx.IsNull() && aCtx->IsDisplayed( aColorScale ) ) {
+ aCtx->Erase( aColorScale );
+ }
+ }
+
+ foreach( HYDROGUI_Shape* aShape, aLandCoverMapShapes ) {
+ HYDROGUI_ShapeLandCoverMap* aLandCoverMapShape =
+ dynamic_cast<HYDROGUI_ShapeLandCoverMap*>( aShape );
+
+ if ( !aLandCoverMapShape || !aLandCoverMapShape->isVisible() ) {
+ continue;
+ }
+
+ Handle(HYDROData_LandCoverMap) aLandCoverMap =
+ Handle(HYDROData_LandCoverMap)::DownCast( aLandCoverMapShape->getObject() );
+
+ if ( aLandCoverMap.IsNull() ) {
+ continue;
+ }
+
+ bool isScalarMode = aLandCoverMapShape->isScalarMapModeEnabled();
+ if( isScalarMode != isLandCoverColoringOn )
+ {
+ aLandCoverMapShape->setScalarMapModeEnabled( isLandCoverColoringOn );
+ theViewer->getAISContext()->Redisplay( aLandCoverMapShape->getAISObject() );
+ }
+ }
+
+ myToUpdateColorScale = false;
+}
+
+Handle(AIS_ColorScale) HYDROGUI_OCCDisplayer::GetColorScale( const int theViewerId )
+{
+ Handle(AIS_ColorScale) aColorScale;
+
+ aColorScale = myColorScales.value( theViewerId, aColorScale );
+ if ( aColorScale.IsNull() ) {
+ aColorScale = new AIS_ColorScale();
+ myColorScales.insert( theViewerId, aColorScale );
+ }
+
+ return aColorScale;
+}