From: Paul RASCLE Date: Sat, 19 Sep 2020 12:41:57 +0000 (+0200) Subject: trying to use the new AIS_PointCloud: bathy representation and global selection OK... X-Git-Tag: SH_V2_2_0~41 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6cf38123d79b342bab18ebc46f378d678d71edc6;p=modules%2Fhydro.git trying to use the new AIS_PointCloud: bathy representation and global selection OK, point selection NOK , but HYDROGUI_BathymetryPrs::HilightSelected called --- diff --git a/src/HYDROGUI/HYDROGUI_BathymetryOp.cxx b/src/HYDROGUI/HYDROGUI_BathymetryOp.cxx index 3c6cc317..10c27f89 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetryOp.cxx +++ b/src/HYDROGUI/HYDROGUI_BathymetryOp.cxx @@ -144,6 +144,7 @@ void HYDROGUI_BathymetryOp::activate( bool isActivate ) { case BathymetryTextId: { + DEBTRACE("BathymetryTextId"); foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths ) bath->GetShape()->TextLabels( isActivate, bath==baths.last() ); //commit(); diff --git a/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx b/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx index 9b2c66a6..a7ade032 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include @@ -56,6 +58,7 @@ HYDROGUI_ShapeBathymetry* HYDROGUI_BathymetryPrs::GetShape() const void HYDROGUI_BathymetryPrs::UpdateBound() { + DEBTRACE("UpdateBound"); Handle(Graphic3d_ArrayOfPoints) points = GetPoints(); myBound.SetVoid(); if( !points.IsNull() ) @@ -75,10 +78,11 @@ void HYDROGUI_BathymetryPrs::UpdateBound() } void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)& theCoords, - const Handle(Quantity_HArray1OfColor)& theColors ) + const Handle(Quantity_HArray1OfColor)& theColors, + const Handle(TColgp_HArray1OfDir)& theNormals ) { - AIS_PointCloud::SetPoints( theCoords, theColors ); - UpdateBound(); + AIS_PointCloud::SetPoints( theCoords, theColors, theNormals ); + //UpdateBound(); } void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, @@ -86,58 +90,59 @@ void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d) const Standard_Integer theMode ) { DEBTRACE("Compute " << theMode); - thePresentation->Clear(); - Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); +// thePresentation->Clear(); +// Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); - if( theMode==BATH_HIGHLIGHT_MODE ) // highlight ==> draw bounding box + if( theMode== BATH_HIGHLIGHT_MODE ) // highlight ==> draw bounding box { - if( myBound.IsVoid() ) - UpdateBound(); - - if( myBound.IsVoid() || - myBound.IsOpenXmin() || myBound.IsOpenXmax() || - myBound.IsOpenYmin() || myBound.IsOpenYmax() || - myBound.IsOpenZmin() || myBound.IsOpenZmax() ) - return; - - Standard_Real xmin, xmax, ymin, ymax, zmin, zmax; - myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax ); - - Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_DASH, 4.0 ); - aGroup->SetPrimitivesAspect( aWireAspect->Aspect() ); // use Aspect_TOL_DASH to find the group by the aspect style - - Handle(Graphic3d_ArrayOfPolylines) aLines = new Graphic3d_ArrayOfPolylines( 18, 6 ); - - aLines->AddBound( 5 ); - aLines->AddVertex( xmin, ymin, zmin ); - aLines->AddVertex( xmax, ymin, zmin ); - aLines->AddVertex( xmax, ymax, zmin ); - aLines->AddVertex( xmin, ymax, zmin ); - aLines->AddVertex( xmin, ymin, zmin ); - aLines->AddBound( 5 ); - aLines->AddVertex( xmin, ymin, zmax ); - aLines->AddVertex( xmax, ymin, zmax ); - aLines->AddVertex( xmax, ymax, zmax ); - aLines->AddVertex( xmin, ymax, zmax ); - aLines->AddVertex( xmin, ymin, zmax ); - aLines->AddBound( 2 ); - aLines->AddVertex( xmin, ymin, zmin ); - aLines->AddVertex( xmin, ymin, zmax ); - aLines->AddBound( 2 ); - aLines->AddVertex( xmax, ymin, zmin ); - aLines->AddVertex( xmax, ymin, zmax ); - aLines->AddBound( 2 ); - aLines->AddVertex( xmax, ymax, zmin ); - aLines->AddVertex( xmax, ymax, zmax ); - aLines->AddBound( 2 ); - aLines->AddVertex( xmin, ymax, zmin ); - aLines->AddVertex( xmin, ymax, zmax ); - aGroup->AddPrimitiveArray( aLines ); + AIS_PointCloud::Compute( thePresentationManager, thePresentation, AIS_PointCloud::DM_BndBox ); +// if( myBound.IsVoid() ) +// UpdateBound(); +// +// if( myBound.IsVoid() || +// myBound.IsOpenXmin() || myBound.IsOpenXmax() || +// myBound.IsOpenYmin() || myBound.IsOpenYmax() || +// myBound.IsOpenZmin() || myBound.IsOpenZmax() ) +// return; +// +// Standard_Real xmin, xmax, ymin, ymax, zmin, zmax; +// myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax ); +// +// Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_DASH, 4.0 ); +// aGroup->SetPrimitivesAspect( aWireAspect->Aspect() ); // use Aspect_TOL_DASH to find the group by the aspect style +// +// Handle(Graphic3d_ArrayOfPolylines) aLines = new Graphic3d_ArrayOfPolylines( 18, 6 ); +// +// aLines->AddBound( 5 ); +// aLines->AddVertex( xmin, ymin, zmin ); +// aLines->AddVertex( xmax, ymin, zmin ); +// aLines->AddVertex( xmax, ymax, zmin ); +// aLines->AddVertex( xmin, ymax, zmin ); +// aLines->AddVertex( xmin, ymin, zmin ); +// aLines->AddBound( 5 ); +// aLines->AddVertex( xmin, ymin, zmax ); +// aLines->AddVertex( xmax, ymin, zmax ); +// aLines->AddVertex( xmax, ymax, zmax ); +// aLines->AddVertex( xmin, ymax, zmax ); +// aLines->AddVertex( xmin, ymin, zmax ); +// aLines->AddBound( 2 ); +// aLines->AddVertex( xmin, ymin, zmin ); +// aLines->AddVertex( xmin, ymin, zmax ); +// aLines->AddBound( 2 ); +// aLines->AddVertex( xmax, ymin, zmin ); +// aLines->AddVertex( xmax, ymin, zmax ); +// aLines->AddBound( 2 ); +// aLines->AddVertex( xmax, ymax, zmin ); +// aLines->AddVertex( xmax, ymax, zmax ); +// aLines->AddBound( 2 ); +// aLines->AddVertex( xmin, ymax, zmin ); +// aLines->AddVertex( xmin, ymax, zmax ); +// aGroup->AddPrimitiveArray( aLines ); } - else + else if (theMode == 0) { DEBTRACE("non highlight mode"); // display the nodes as points with color (HYDROGUI_ShapeBathymetry::UpdateWithColorScale) - AIS_PointCloud::Compute( thePresentationManager, thePresentation, theMode ); + AIS_PointCloud::Compute( thePresentationManager, thePresentation, AIS_PointCloud::DM_Points ); QImage qtMark( 4, 4, QImage::Format_RGB888 ); // points marks as 4x4 rectangles Handle(Image_PixMap) aMark = HYDROGUI_Tool::Pixmap( qtMark ); @@ -157,61 +162,87 @@ void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d) if (!asp.IsNull()) { DEBTRACE("aspect: " << asp->get_type_name()); + DEBTRACE("asp->LineType() " << asp->LineType()); if (asp->LineType() != Aspect_TOL_DASH) // find the group which does not correspond to the bounding box 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(); +// +// 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"); } void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection, const Standard_Integer theMode ) { - if( theMode == 0 ) - { - if( myBound.IsVoid() ) - UpdateBound(); - - if( myBound.IsVoid() || - myBound.IsOpenXmin() || myBound.IsOpenXmax() || - myBound.IsOpenYmin() || myBound.IsOpenYmax() || - myBound.IsOpenZmin() || myBound.IsOpenZmax() ) - return; - - Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this ); - Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound ); - theSelection->Add( aSensitiveBox ); - } - if( theMode == 1 ) + DEBTRACE("ComputeSelection " << theMode); + switch (theMode) { - Handle(Graphic3d_ArrayOfPoints) points = GetPoints(); - int n = points.IsNull() ? 0 : points->VertexNumber(); - for( int i=1; i<=n; i++ ) + case 0: { - 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 ); + DEBTRACE("Bounding box selection"); + AIS_PointCloud::ComputeSelection( theSelection, SM_BndBox); + break; + } + case 1: + { + DEBTRACE("Subset of points detection"); + AIS_PointCloud::ComputeSelection( theSelection, SM_SubsetOfPoints ); + break; + } + default: + { + DEBTRACE("Do Nothing"); + return; } } + +// if( theMode == 0 ) +// { +// if( myBound.IsVoid() ) +// UpdateBound(); +// +// if( myBound.IsVoid() || +// myBound.IsOpenXmin() || myBound.IsOpenXmax() || +// myBound.IsOpenYmin() || myBound.IsOpenYmax() || +// myBound.IsOpenZmin() || myBound.IsOpenZmax() ) +// return; +// +// Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this ); +// 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 ); +//// } +// } } int HYDROGUI_BathymetryPrs::NbPoints() const @@ -233,6 +264,7 @@ gp_Pnt HYDROGUI_BathymetryPrs::GetPoint( int theIndex ) const void HYDROGUI_BathymetryPrs::AddPoint( const Handle(Graphic3d_ArrayOfPoints)& thePoints, const Handle(SelectMgr_EntityOwner)& theOwner ) { + DEBTRACE("AddPoint"); Handle(HYDROGUI_BathymetryPointOwner) anOwner = Handle(HYDROGUI_BathymetryPointOwner)::DownCast( theOwner ); if( anOwner.IsNull() ) return; @@ -241,9 +273,10 @@ void HYDROGUI_BathymetryPrs::AddPoint( const Handle(Graphic3d_ArrayOfPoints)& th } void HYDROGUI_BathymetryPrs::HilightOwnerWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM, - const Handle(Graphic3d_HighlightStyle)& theColor, + const Handle(Prs3d_Drawer)& theColor, const Handle(SelectMgr_EntityOwner)& theOwner ) { + DEBTRACE("HilightOwnerWithColor"); Handle(Prs3d_Presentation) aHilightPrs = GetHilightPresentation( thePM ); aHilightPrs->SetZLayer( Graphic3d_ZLayerId_Topmost ); aHilightPrs->Clear(); @@ -262,25 +295,41 @@ void HYDROGUI_BathymetryPrs::HilightOwnerWithColor( const Handle(PrsMgr_Presenta void HYDROGUI_BathymetryPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePM, const SelectMgr_SequenceOfOwner& theOwners ) { - 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 ) ); + DEBTRACE("HilightSelected " << theOwners.Size()); + if (theOwners.Size() == 0) + return; + Handle(SelectMgr_EntityOwner) owner = theOwners.First(); + Handle(AIS_PointCloudOwner) anOwner = Handle(AIS_PointCloudOwner)::DownCast( owner ); + if (anOwner.IsNull()) + return; + Handle(TColStd_HPackedMapOfInteger) thePointsH = anOwner->SelectedPoints(); + TColStd_PackedMapOfInteger thePoints = thePointsH->Map(); + DEBTRACE("thePoints.Extent() :" << thePoints.Extent()); + Handle(TColStd_HPackedMapOfInteger) thePointsDH = anOwner->DetectedPoints(); + TColStd_PackedMapOfInteger thePointsD = thePointsDH->Map(); + DEBTRACE("thePointsD.Extent() :" << thePointsD.Extent()); - 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(); +// 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(); } void HYDROGUI_BathymetryPrs::ClearSelected() { + DEBTRACE("ClearSelected"); Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( NULL ); if( !aSelectPrs.IsNull() ) aSelectPrs->Clear(); @@ -288,6 +337,7 @@ void HYDROGUI_BathymetryPrs::ClearSelected() void HYDROGUI_BathymetryPrs::SetTextLabels( const QVector& theTextIndices ) { + DEBTRACE("SetTextLabels"); myTextIndices = theTextIndices; } diff --git a/src/HYDROGUI/HYDROGUI_BathymetryPrs.h b/src/HYDROGUI/HYDROGUI_BathymetryPrs.h index 1732016d..2470392e 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetryPrs.h +++ b/src/HYDROGUI/HYDROGUI_BathymetryPrs.h @@ -33,13 +33,14 @@ public: virtual ~HYDROGUI_BathymetryPrs(); virtual void SetPoints( const Handle(TColgp_HArray1OfPnt)& theCoords, - const Handle(Quantity_HArray1OfColor)& theColors = NULL ); + const Handle(Quantity_HArray1OfColor)& theColors = NULL, + const Handle(TColgp_HArray1OfDir)& theNormals = NULL) Standard_OVERRIDE; int NbPoints() const; gp_Pnt GetPoint( int theIndex ) const; virtual void HilightOwnerWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM, - const Handle(Graphic3d_HighlightStyle)& theColor, + const Handle(Prs3d_Drawer)& theColor, const Handle(SelectMgr_EntityOwner)& theOwner ); virtual void HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePM, @@ -54,9 +55,9 @@ public: protected: virtual void Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, - const Standard_Integer theMode = 0 ); + const Standard_Integer theMode = 0 ) Standard_OVERRIDE; virtual void ComputeSelection( const Handle(SelectMgr_Selection)& theSelection, - const Standard_Integer theMode ); + const Standard_Integer theMode ) Standard_OVERRIDE; void UpdateBound(); void AddPoint( const Handle(Graphic3d_ArrayOfPoints)&, const Handle(SelectMgr_EntityOwner)& ); diff --git a/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx index 3f550f19..b9a7d1a6 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx +++ b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx @@ -106,14 +106,15 @@ void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive ) QList baths = getShownBathymetries( module() ); if( isActive ) { - const int aSelectionMode = 1; // 2 AIS_PointCloud selection bounding box + const int aSelectionMode = 1; // Cf. AIS_PointCloud 0=selection by points ? //ctx->Deactivate( Standard_True ); //ctx->OpenLocalContext( Standard_True ); foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths ) { DEBTRACE("bathy name: " << bath->GetShape()->getObject()->GetName().toStdString()); ctx->Deactivate(bath); - ctx->Activate( bath, aSelectionMode, Standard_True ); + //ctx->Activate( bath, aSelectionMode, Standard_True ); + ctx->SetSelectionModeActive (bath, aSelectionMode, Standard_True, AIS_SelectionModesConcurrency_Multiple, Standard_False); bath->SetAutoHilight( Standard_False ); } ctx->UpdateCurrentViewer(); @@ -126,6 +127,7 @@ void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive ) bath->SetAutoHilight( Standard_True ); bath->GetShape()->TextLabels( false ); ctx->Deactivate( bath ); + ctx->SetSelectionModeActive (bath, 0, Standard_True, AIS_SelectionModesConcurrency_Multiple, Standard_False); } //ctx->CloseLocalContext( -1, Standard_True ); }