]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
a first solution to get altitude text on bathymetrie selection of points
authorPaul RASCLE <paul.rascle@openfields.fr>
Sun, 20 Sep 2020 13:35:32 +0000 (15:35 +0200)
committerYOANN AUDOUIN <B61570@dsp0851742.postes.calibre.edf.fr>
Fri, 30 Oct 2020 16:08:09 +0000 (17:08 +0100)
src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx
src/HYDROGUI/HYDROGUI_BathymetryPrs.h
src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx
src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx
src/HYDROGUI/HYDROGUI_ShapeBathymetry.h

index e968bd00320368ac0cbe838745cec581d052c157..3dc4ab96b56ff9a4c6994b5e901bb834d17a2404 100644 (file)
@@ -17,6 +17,7 @@
 //
 
 #include <HYDROGUI_BathymetryPrs.h>
+#include <HYDROGUI_ShapeBathymetry.h>
 #include <HYDROGUI_Tool.h>
 
 #include <Prs3d_Root.hxx>
 #include <Graphic3d_MarkerImage.hxx>
 #include <TColStd_HPackedMapOfInteger.hxx>
 #include <TColStd_PackedMapOfInteger.hxx>
+#include <unistd.h>
 
 #include <QImage>
+#include <QVector>
 
 #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()
index 2470392e98d6097a47a44f0ebe2fd2bbd89547b3..26154eb6e07a02f85975b52236c947f8ca788133 100644 (file)
@@ -52,6 +52,8 @@ public:
 
   HYDROGUI_ShapeBathymetry* GetShape() const;
 
+  QVector<int> 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<int> myTextIndices;
+  QVector<int> mySelectedPoints;
 };
 
 class HYDROGUI_BathymetryPointOwner : public SelectMgr_EntityOwner
index c7037f83abf53eacb0d578fbc46d722df0aebd48..aa21b0046331c17c568501ee06eb9a2579e9f89c 100644 (file)
 #include <HYDROGUI_Operations.h>
 #include <OCCViewer_ViewManager.h>
 #include <LightApp_Application.h>
+#include <SUIT_Selector.h>
 #include <QAction>
 #include <QApplication>
+#include <QString>
+#include <QList>
+#include <LightApp_SelectionMgr.h>
 
 #define _DEVDEBUG_
 #include "HYDRO_trace.hxx"
@@ -106,6 +110,17 @@ void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive )
   QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
   if( isActive )
   {
+//    QList<SUIT_Selector*> aSelectorList;
+//    QString aViewType = OCCViewer_Viewer::Type();
+//    LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
+//    aSelectionMgr->selectors(aViewType, aSelectorList);
+//    QList<SUIT_Selector*>::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())
index 226561b534eb4b78249deac53da35d5aa05a5a3d..fbd57b3467e7207a3d81f3006569818df9f77fb9 100644 (file)
@@ -235,24 +235,31 @@ QVector<int> HYDROGUI_ShapeBathymetry::selected() const
 {
   DEBTRACE("selected");
   QVector<int> 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;
 }
 
index e88d09119c760c748b641aa51b257b52310565c4..3b9c9e2612a08a427d7a360fff9d57d274b5679e 100644 (file)
@@ -22,6 +22,7 @@
 #include <HYDROGUI_Shape.h>
 #include <TColgp_HArray1OfPnt.hxx>
 #include <Quantity_HArray1OfColor.hxx>
+#include <QVector>
 
 class HYDROData_Bathymetry;
 class AIS_ColorScale;
@@ -79,6 +80,7 @@ private:
   double myMin;
   double myMax;
   bool myRangeInitialized;
+  QVector<int> mySelectedPoints;
 };
 
 #endif