X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ShapeBathymetry.cxx;h=a6de2d915509941d23825af2618fac74c0cf06e5;hb=92c3e5ddda56d434c842e744b3db1341ad2f87f5;hp=e8e7941b670df5490036037941cc70b95161a62b;hpb=4d7e02f0b23d84c6b1636e64618083e44182a995;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx index e8e7941b..a6de2d91 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx +++ b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx @@ -20,17 +20,29 @@ #include #include #include +#include #include -#include +#include #include +#include +#include +#include +#include +#include + +//#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" HYDROGUI_ShapeBathymetry::HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer* theDisplayer, const Handle(AIS_InteractiveContext)& theContext, - const Handle_HYDROData_Bathymetry& theBathymetry, + const Handle(HYDROData_Bathymetry)& theBathymetry, const int theZLayer ) : HYDROGUI_Shape( theContext, theBathymetry, theZLayer ), - myDisplayer( theDisplayer ) + myDisplayer( theDisplayer ), + myMin( 0 ), + myMax( 0 ), + myRangeInitialized( false ) { setDisplayMode( AIS_PointCloud::DM_Points ); } @@ -57,14 +69,18 @@ void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivate HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection ); } - -Handle_AIS_InteractiveObject HYDROGUI_ShapeBathymetry::createShape() const +QList HYDROGUI_ShapeBathymetry::createShape() const { - Handle_HYDROData_Bathymetry aBath = Handle_HYDROData_Bathymetry::DownCast( getObject() ); + DEBTRACE("createShape"); + QList shapes; + + Handle(AIS_InteractiveObject) aPntCloud; + + Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( getObject() ); if( !aBath.IsNull() ) { - Handle_AIS_PointCloud aPntCloud = new HYDROGUI_BathymetryPrs(); - aPntCloud->SetHilightMode( AIS_PointCloud::DM_BndBox ); + aPntCloud = new HYDROGUI_BathymetryPrs( this ); + //aPntCloud->SetHilightMode( AIS_PointCloud::DM_BndBox ); aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 2.0)); const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints(); @@ -77,51 +93,42 @@ Handle_AIS_InteractiveObject HYDROGUI_ShapeBathymetry::createShape() const for( int i=aLower; i<=anUpper; i++ ) aThat->myCoords->SetValue( i, gp_Pnt( aBathPoints[i].X, aBathPoints[i].Y, aBathPoints[i].Z ) ); - return aPntCloud; + shapes.append( aPntCloud ); } - else - return Handle_AIS_InteractiveObject(); -} -void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const -{ - theMin = 0; - theMax = 0; - if( myCoords.IsNull() ) - return; - - bool isFirst = true; - for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ ) - { - double aValue = myCoords->Value( i ).Z(); - if( isFirst || aValue < theMin ) - theMin = aValue; - if( isFirst || aValue > theMax ) - theMax = aValue; - isFirst = false; - } + return shapes; } -void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale ) +void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(AIS_ColorScale)& theColorScale ) { - if (!myCoords) + DEBTRACE("UpdateWithColorScale"); + if (!myCoords || getAISObjects().isEmpty()) return; + for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ ) { double z = myCoords->Value( i ).Z(); + if( zmyMax ) + z = myMax; Quantity_Color aColor; theColorScale->FindColor( z, aColor ); myColors->SetValue( i, aColor ); } - Handle_AIS_PointCloud aPntCloud = Handle_AIS_PointCloud::DownCast( getAISObject() ); + Handle(HYDROGUI_BathymetryPrs) aPntCloud = Handle(HYDROGUI_BathymetryPrs)::DownCast( getAISObjects()[0] ); aPntCloud->SetPoints( myCoords, myColors ); - getContext()->Redisplay( aPntCloud, Standard_False ); + getContext()->RecomputePrsOnly( aPntCloud, Standard_True ); + getContext()->RecomputeSelectionOnly( aPntCloud ); } void HYDROGUI_ShapeBathymetry::setVisible( const bool theState, const bool theIsUpdateViewer ) { - bool isShown = getContext()->IsDisplayed( getAISObject() ); + if( getAISObjects().isEmpty() ) + return; + + bool isShown = getContext()->IsDisplayed( getAISObjects()[0] ); bool isChanged = ( isShown != theState ); HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer ); setToUpdateColorScale( isChanged ); @@ -129,7 +136,10 @@ void HYDROGUI_ShapeBathymetry::setVisible( const bool theState, void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer ) { - bool isShown = getContext()->IsDisplayed( getAISObject() ); + if( getAISObjects().isEmpty() ) + return; + + bool isShown = getContext()->IsDisplayed( getAISObjects()[0] ); bool isChanged = ( !isShown ); HYDROGUI_Shape::displayShape( theIsUpdateViewer ); setToUpdateColorScale( isChanged ); @@ -137,7 +147,10 @@ void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer ) void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer ) { - bool isShown = getContext()->IsDisplayed( getAISObject() ); + if( getAISObjects().isEmpty() ) + return; + + bool isShown = getContext()->IsDisplayed( getAISObjects()[0] ); bool isChanged = ( !isShown ); HYDROGUI_Shape::display( theIsUpdateViewer ); setToUpdateColorScale( isChanged ); @@ -145,7 +158,10 @@ void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer ) void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer ) { - bool isShown = getContext()->IsDisplayed( getAISObject() ); + if( getAISObjects().isEmpty() ) + return; + + bool isShown = getContext()->IsDisplayed( getAISObjects()[0] ); bool isChanged = ( isShown ); HYDROGUI_Shape::erase( theIsUpdateViewer ); setToUpdateColorScale( isChanged ); @@ -158,3 +174,148 @@ void HYDROGUI_ShapeBathymetry::setToUpdateColorScale( bool isChanged ) myDisplayer->SetToUpdateColorScale(); #endif } + +void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const +{ + if( !myRangeInitialized ) + { + HYDROGUI_ShapeBathymetry* that = + const_cast( this ); + that->RescaleDefault(); + that->myRangeInitialized = true; + } + + theMin = myMin; + theMax = myMax; +} + +void HYDROGUI_ShapeBathymetry::RescaleByVisible( OCCViewer_ViewWindow* theWindow ) +{ + QVector visible; + visible.reserve( myCoords->Size() ); + + OCCViewer_ViewPort3d* vp = theWindow->getViewPort(); + Handle(V3d_View) v = vp->getView(); + + int xp, yp; + int w = vp->width(); + int h = vp->height(); + int n = myCoords->Upper(); + bool isVisible; + +#ifdef _DEBUG + MESSAGE("RescaleByVisible: " << n); + QTime t1; + t1.start(); +#endif + + for( int i=myCoords->Lower(); i<=n; i++ ) + { + gp_Pnt p = myCoords->Value( i ); + v->Convert( p.X(), p.Y(), p.Z(), xp, yp ); + isVisible = ( xp>=0 && yp>=0 && xp HYDROGUI_ShapeBathymetry::selected() const +{ + DEBTRACE("selected"); + QVector selected; + + // HYDROGUI_BathymetryPrs::ClearSelected() called before: Nothing left... + + Handle(HYDROGUI_BathymetryPrs) aPntCloud = Handle(HYDROGUI_BathymetryPrs)::DownCast( getAISObjects()[0] ); + if (!aPntCloud.IsNull()) + selected = aPntCloud->getSelectedPoints(); + DEBTRACE("selected " << selected.size()); + return selected; +} + +void HYDROGUI_ShapeBathymetry::RescaleBySelection() +{ + QVector selection = selected(); + + //TODO: question: empty selection produce empty bathymetry or complete bathymetry? + // For now "complete" is implemented + Rescale( selection, selection.isEmpty() ); +} + +void HYDROGUI_ShapeBathymetry::Rescale( double theMin, double theMax ) +{ + getContext()->ClearSelected(true); + myMin = qMin( theMin, theMax ); + myMax = qMax( theMin, theMax ); + setToUpdateColorScale( true ); + + if( !getAISObjects().isEmpty() ) + { + getContext()->RecomputePrsOnly( getAISObjects()[0], true ); + } +} + +void HYDROGUI_ShapeBathymetry::RescaleDefault() +{ + Rescale( QVector(), true ); +} + +void HYDROGUI_ShapeBathymetry::Rescale( const QVector& theIndices, bool isForcedAll ) +{ + double aMin = 0, aMax = 0; + if( !myCoords.IsNull() ) + { + bool isFirst = true; + int n = isForcedAll ? myCoords->Size() : theIndices.size(); + for( int i=0; iLower() + i : theIndices[i]; + + double aValue = myCoords->Value( index ).Z(); + if( isFirst || aValue < aMin ) + aMin = aValue; + if( isFirst || aValue > aMax ) + aMax = aValue; + isFirst = false; + } + } + Rescale( aMin, aMax ); +} + +void HYDROGUI_ShapeBathymetry::Build() +{ + buildShape(); +} + +void HYDROGUI_ShapeBathymetry::TextLabels( bool isOn, bool isUpdateCurrentViewer ) +{ + DEBTRACE("TextLabels " << isOn << " " << isUpdateCurrentViewer); + if( getAISObjects().isEmpty() ) + return; + + Handle(HYDROGUI_BathymetryPrs) prs = Handle(HYDROGUI_BathymetryPrs)::DownCast( getAISObjects()[0] ); + if( prs.IsNull() ) + return; + + QVector selection; + if( isOn ) + selection = selected(); + + + prs->SetTextLabels( selection ); + getContext()->RecomputePrsOnly( prs, Standard_False, Standard_False ); + if( isUpdateCurrentViewer ) + getContext()->UpdateCurrentViewer(); +}