From: Paul RASCLE Date: Sun, 20 Sep 2020 13:35:32 +0000 (+0200) Subject: a first solution to get altitude text on bathymetrie selection of points X-Git-Tag: SH_V2_2_0~38 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3c05f4947cb1d3fa887ac56cc901f28fe7022414;p=modules%2Fhydro.git a first solution to get altitude text on bathymetrie selection of points --- diff --git a/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx b/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx index e968bd00..3dc4ab96 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx @@ -17,6 +17,7 @@ // #include +#include #include #include @@ -31,8 +32,10 @@ #include #include #include +#include #include +#include #define _DEVDEBUG_ #include "HYDRO_trace.hxx" @@ -167,24 +170,25 @@ void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d) aGrp->SetGroupPrimitivesAspect( anAspect ); } } -// -// Handle(Graphic3d_ArrayOfPoints) points = GetPoints(); -// if (!points.IsNull()) -// DEBTRACE("nb points " << points->ItemNumber()); -// -// if( !myTextIndices.empty() && !points.IsNull() ) // points selected ==> altitude labels -// { -// DEBTRACE("myTextIndices.size() " << myTextIndices.size()); -// char aBuf[1024]; -// Handle(Prs3d_TextAspect) anAspect = new Prs3d_TextAspect(); -// -// foreach( int index, myTextIndices ) -// { -// gp_Pnt p = points->Vertice( index ); -// sprintf( aBuf, "%.2f", p.Z() ); -// Prs3d_Text::Draw( aGroup, anAspect, aBuf, p ); -// } -// } + + Handle(Graphic3d_ArrayOfPoints) points = GetPoints(); + if (!points.IsNull()) + DEBTRACE("nb points " << points->ItemNumber()); + + if( !myTextIndices.empty() && !points.IsNull() ) // points selected ==> altitude labels + { + DEBTRACE("myTextIndices.size() " << myTextIndices.size()); + char aBuf[1024]; + Handle(Prs3d_TextAspect) anAspect = new Prs3d_TextAspect(); + + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); + foreach( int index, myTextIndices ) + { + gp_Pnt p = points->Vertice( index ); + sprintf( aBuf, "%.2f", p.Z() ); + Prs3d_Text::Draw( aGroup, anAspect, aBuf, p ); + } + } } else DEBTRACE("Do nothing"); @@ -231,19 +235,18 @@ void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection) // Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound ); // theSelection->Add( aSensitiveBox ); // } -// if( theMode == 1 ) -// { -// AIS_PointCloud::ComputeSelection(theSelection, theMode); -//// Handle(Graphic3d_ArrayOfPoints) points = GetPoints(); -//// int n = points.IsNull() ? 0 : points->VertexNumber(); -//// for( int i=1; i<=n; i++ ) -//// { -//// gp_Pnt p = points->Vertice( i ); -//// Handle(HYDROGUI_BathymetryPointOwner) anOwner = new HYDROGUI_BathymetryPointOwner( this, i ); -//// Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint( anOwner, p ); -//// theSelection->Add( aSensitivePoint ); -//// } -// } + if( theMode == 1 ) + { + Handle(Graphic3d_ArrayOfPoints) points = GetPoints(); + int n = points.IsNull() ? 0 : points->VertexNumber(); + for( int i=1; i<=n; i++ ) + { + gp_Pnt p = points->Vertice( i ); + Handle(HYDROGUI_BathymetryPointOwner) anOwner = new HYDROGUI_BathymetryPointOwner( this, i ); + Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint( anOwner, p ); + theSelection->Add( aSensitivePoint ); + } + } } int HYDROGUI_BathymetryPrs::NbPoints() const @@ -266,11 +269,13 @@ void HYDROGUI_BathymetryPrs::AddPoint( const Handle(Graphic3d_ArrayOfPoints)& th const Handle(SelectMgr_EntityOwner)& theOwner ) { DEBTRACE("AddPoint"); - Handle(AIS_PointCloudOwner) anOwner = Handle(AIS_PointCloudOwner)::DownCast( theOwner ); + Handle(HYDROGUI_BathymetryPointOwner) anOwner = Handle(HYDROGUI_BathymetryPointOwner)::DownCast( theOwner ); if( anOwner.IsNull() ) return; -// gp_Pnt p = GetPoint( anOwner->GetIndex() ); -// thePoints->AddVertex( p ); + DEBTRACE("index " << anOwner->GetIndex()); + gp_Pnt p = GetPoint( anOwner->GetIndex() ); + DEBTRACE("p: " << p.X() << " " << p.Y() << " " << p.Z()); + thePoints->AddVertex( p ); } void HYDROGUI_BathymetryPrs::HilightOwnerWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM, @@ -307,30 +312,39 @@ void HYDROGUI_BathymetryPrs::HilightSelected( const Handle(PrsMgr_PresentationMa return; Handle(SelectMgr_EntityOwner) owner = theOwners.First(); Handle(AIS_PointCloudOwner) anOwner = Handle(AIS_PointCloudOwner)::DownCast( owner ); - if (anOwner.IsNull()) - return; - DEBTRACE("immediateMode: " << thePM->IsImmediateModeOn()); // semble sans effet - const Handle(TColStd_HPackedMapOfInteger)& aSMap = anOwner->SelectedPoints(); - DEBTRACE("selectedPoints.Extent() :" << aSMap->Map().Extent()); - const Handle(TColStd_HPackedMapOfInteger)& aDMap = anOwner->DetectedPoints(); - DEBTRACE("detectedPoints.Extent() :" << aDMap->Map().Extent()); + if (!anOwner.IsNull()) + { + DEBTRACE("immediateMode: " << thePM->IsImmediateModeOn()); // semble sans effet + const Handle(TColStd_HPackedMapOfInteger)& aSMap = anOwner->SelectedPoints(); + DEBTRACE("selectedPoints.Extent() :" << aSMap->Map().Extent()); + const Handle(TColStd_HPackedMapOfInteger)& aDMap = anOwner->DetectedPoints(); + DEBTRACE("detectedPoints.Extent() :" << aDMap->Map().Extent()); + } + Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePM ); + aSelectPrs->SetZLayer( Graphic3d_ZLayerId_Topmost ); + aSelectPrs->Clear(); -// Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePM ); -// aSelectPrs->SetZLayer( Graphic3d_ZLayerId_Topmost ); -// aSelectPrs->Clear(); -// -// Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( theOwners.Size() ); -// for( int i=theOwners.Lower(); i<=theOwners.Upper(); i++ ) -// AddPoint( points, theOwners.Value( i ) ); -// -// Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aSelectPrs ); -// Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 ); -// aGroup->SetGroupPrimitivesAspect( anAspect ); -// aGroup->AddPrimitiveArray( points ); -// -// aSelectPrs->SetDisplayPriority(9); -// aSelectPrs->Display(); + //mySelectedPoints.clear(); + mySelectedPoints.reserve(theOwners.Size()); + Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( theOwners.Size() ); + for( int i=theOwners.Lower(); i<=theOwners.Upper(); i++ ) + { + AddPoint( points, theOwners.Value( i ) ); + Handle(HYDROGUI_BathymetryPointOwner) anOwner = Handle(HYDROGUI_BathymetryPointOwner)::DownCast( theOwners.Value( i ) ); + if (!anOwner.IsNull()) + mySelectedPoints.append(anOwner->GetIndex()); + } + + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aSelectPrs ); + //Handle(Graphic3d_Group) aGroup = aSelectPrs->NewGroup(); + Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 ); + aGroup->SetGroupPrimitivesAspect( anAspect ); + aGroup->AddPrimitiveArray( points ); + + aSelectPrs->SetDisplayPriority(5); + aSelectPrs->Display(); + //sleep(5); } void HYDROGUI_BathymetryPrs::ClearSelected() diff --git a/src/HYDROGUI/HYDROGUI_BathymetryPrs.h b/src/HYDROGUI/HYDROGUI_BathymetryPrs.h index 2470392e..26154eb6 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetryPrs.h +++ b/src/HYDROGUI/HYDROGUI_BathymetryPrs.h @@ -52,6 +52,8 @@ public: HYDROGUI_ShapeBathymetry* GetShape() const; + QVector getSelectedPoints() {return mySelectedPoints;}; + protected: virtual void Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, @@ -66,6 +68,7 @@ private: const HYDROGUI_ShapeBathymetry* myShape; Bnd_Box myBound; QVector myTextIndices; + QVector mySelectedPoints; }; class HYDROGUI_BathymetryPointOwner : public SelectMgr_EntityOwner diff --git a/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx index c7037f83..aa21b004 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx +++ b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx @@ -25,8 +25,12 @@ #include #include #include +#include #include #include +#include +#include +#include #define _DEVDEBUG_ #include "HYDRO_trace.hxx" @@ -106,6 +110,17 @@ void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive ) QList baths = getShownBathymetries( module() ); if( isActive ) { +// QList aSelectorList; +// QString aViewType = OCCViewer_Viewer::Type(); +// LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr(); +// aSelectionMgr->selectors(aViewType, aSelectorList); +// QList::iterator anIter, anIterEnd = aSelectorList.end(); +// for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ ) +// { +// SUIT_Selector* aSelector = *anIter; +// aSelector->setEnabled( false ); +// } + const int aSelectionMode = 1; // Cf. AIS_PointCloud 0=selection by points ? //ctx->Deactivate( Standard_True ); //ctx->OpenLocalContext( Standard_True ); @@ -113,8 +128,10 @@ void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive ) { DEBTRACE("bathy name: " << bath->GetShape()->getObject()->GetName().toStdString()); ctx->Deactivate(bath); + ctx->RemoveFilters(); //ctx->Activate( bath, aSelectionMode, Standard_True ); - ctx->SetSelectionModeActive (bath, aSelectionMode, Standard_True, AIS_SelectionModesConcurrency_Single, Standard_False); + ctx->SetSelectionModeActive (bath, aSelectionMode, Standard_True, AIS_SelectionModesConcurrency_Multiple, Standard_False); + ctx->SetSelectionModeActive (bath, 0, Standard_True, AIS_SelectionModesConcurrency_Multiple, Standard_False); bath->SetAutoHilight( Standard_False ); // True bloque le passage dans hilightSelected... // DEBTRACE("immediateMode: " << ctx->MainPrsMgr()->IsImmediateModeOn()); // if (!ctx->MainPrsMgr()->IsImmediateModeOn()) diff --git a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx index 226561b5..fbd57b34 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx +++ b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx @@ -235,24 +235,31 @@ QVector HYDROGUI_ShapeBathymetry::selected() const { DEBTRACE("selected"); QVector selected; - selected.reserve( myCoords->Size() ); - Handle(AIS_InteractiveObject) obj = getAISObjects().first(); + // HYDROGUI_BathymetryPrs::ClearSelected() called before: Nothing left... +// selected.reserve( myCoords->Size() ); +// +// Handle(AIS_InteractiveObject) obj = getAISObjects().first(); +// +// Handle(AIS_InteractiveContext) c = getContext(); +// int cnt = 0; +// if( !c.IsNull() ) +// { +// for( c->InitSelected(); c->MoreSelected(); c->NextSelected() ) +// { +// cnt++; +// Handle(HYDROGUI_BathymetryPointOwner) anOwner = +// Handle(HYDROGUI_BathymetryPointOwner)::DownCast( c->SelectedOwner() ); +// if( !anOwner.IsNull() && anOwner->Selectable()==obj ) +// selected.append( anOwner->GetIndex() ); +// } +// } +// DEBTRACE("selected " << cnt << " " << selected.size() ); - Handle(AIS_InteractiveContext) c = getContext(); - int cnt = 0; - if( !c.IsNull() ) - { - for( c->InitSelected(); c->MoreSelected(); c->NextSelected() ) - { - cnt++; - Handle(HYDROGUI_BathymetryPointOwner) anOwner = - Handle(HYDROGUI_BathymetryPointOwner)::DownCast( c->SelectedOwner() ); - if( !anOwner.IsNull() && anOwner->Selectable()==obj ) - selected.append( anOwner->GetIndex() ); - } - } - DEBTRACE("selected " << cnt << " " << selected.size() ); + Handle(HYDROGUI_BathymetryPrs) aPntCloud = Handle(HYDROGUI_BathymetryPrs)::DownCast( getAISObjects()[0] ); + if (!aPntCloud.IsNull()) + selected = aPntCloud->getSelectedPoints(); + DEBTRACE("selected " << selected.size()); return selected; } diff --git a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h index e88d0911..3b9c9e26 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h +++ b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h @@ -22,6 +22,7 @@ #include #include #include +#include class HYDROData_Bathymetry; class AIS_ColorScale; @@ -79,6 +80,7 @@ private: double myMin; double myMax; bool myRangeInitialized; + QVector mySelectedPoints; }; #endif