]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
selection synchronisation between OB and SPV3D_Viewer:
authorDUC ANH HOANG <dh77501n@dsp1043837>
Thu, 1 Aug 2024 10:00:05 +0000 (12:00 +0200)
committerDUC ANH HOANG <dh77501n@dsp1043837>
Thu, 1 Aug 2024 10:00:05 +0000 (12:00 +0200)
   From Viewer to OB: finish
   From OB to Viewer: need kitware to send seletion request with vtkidtype list to CADrepresentation server

src/LightApp/LightApp_PV3DSelector.cxx
src/SPV3D/SPV3D_CADSelection.cxx
src/SPV3D/SPV3D_CADSelection.h
src/SPV3D/SPV3D_Prs.cxx
src/SPV3D/SPV3D_Prs.h
src/SPV3D/SPV3D_ViewModel.cxx
src/SPV3D/SPV3D_ViewModel.h
src/SPV3D/SPV3D_ViewWindow.cxx
src/SPV3D/SPV3D_ViewWindow.h

index 635515d4747f3cc2cf2aa2e4caeaed81a2cf6807..e4e5dd79ec4ae1a2a48b86449be0a17fbd19d6f0 100644 (file)
@@ -26,6 +26,7 @@
 #include "SUIT_Desktop.h"
 
 #ifndef DISABLE_PV3DVIEWER
+  #include "SPV3D_CADSelection.h"
   #include "SPV3D_ViewModel.h"
   #include "SPV3D_ViewManager.h"
   #include "SPV3D_ViewWindow.h"
@@ -82,29 +83,28 @@ void LightApp_PV3DSelector::onSelectionChanged()
 /*!
   Gets list of selected data owners.(output \a aList).
 */
-void LightApp_PV3DSelector::getSelection( SUIT_DataOwnerPtrList& /*aList*/ ) const
+void LightApp_PV3DSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
 {
   if ( !myViewer )
     return;
-
-  if ( !myViewer->isSelectionEnabled() )
+  if( !myViewer->isSelectionEnabled() )
     return;
+  if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
+    if(SPV3D_ViewManager* aViewMgr = dynamic_cast<SPV3D_ViewManager*>(aViewManager)){
+      if(SPV3D_ViewWindow* aViewWindow = dynamic_cast<SPV3D_ViewWindow*>(aViewMgr->getActiveView())){
+        if(SPV3D_CADSelection* aSelector = aViewWindow->GetCADSelection()){
+          std::set<std::string> EntryList = aSelector->GetSelectedObEntry();
+          if (!EntryList.empty()){
+            for (auto Selected_Entry : EntryList) {
+              aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( QString(Selected_Entry.c_str()) ) ) );
+            }
+          }
+        }
+      }
+    }
+
+  }
 
-  // if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
-  //   if(PV3DViewer_ViewManager* aViewMgr = dynamic_cast<PV3DViewer_ViewManager*>(aViewManager)){
-  //     if(PV3DViewer_ViewWindow* aView = dynamic_cast<PV3DViewer_ViewWindow*>(aViewMgr->getActiveView())){
-  //       if(SPV3D_Selector* aSelector = aView->GetSelector()){
-  //         const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
-  //         SALOME_ListIteratorOfListIO anIter(aListIO);
-  //         for(; anIter.More(); anIter.Next()){
-  //           Handle(SALOME_InteractiveObject) anIO = anIter.Value();
-  //           if(anIO->hasEntry())
-  //             aList.append(new LightApp_SPV3DDataOwner(anIO,aViewMgr->getDesktop()));
-  //         }
-  //       }
-  //     }
-  //   }
-  // }
 }
 
 /*!
@@ -112,51 +112,30 @@ void LightApp_PV3DSelector::getSelection( SUIT_DataOwnerPtrList& /*aList*/ ) con
 */
 void LightApp_PV3DSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
 {
-  if ( myViewer && ( theList.isEmpty() || myViewer->isSelectionEnabled() )) {
-    //if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager())
+  if ( myViewer && ( theList.isEmpty() || myViewer->isSelectionEnabled() ))
+  {
+    if(SUIT_ViewManager* aViewManager = myViewer->getViewManager())
     {
-    //  if(SPV3D_ViewWindow* aView = dynamic_cast<SPV3D_ViewWindow*>(aViewMgr->getActiveView()))
+      if(SPV3D_ViewManager* aViewMgr = dynamic_cast<SPV3D_ViewManager*>(aViewManager))
       {
-        // if(PV3DViewer_Selector* aSelector = aView->GetSelector()){
-        //   SALOME_ListIO anAppendList;
-        //   const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
-        //   SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
-        //   for(; anIter != theList.end(); ++anIter) {
-        //     const SUIT_DataOwner* aDataOwner = (*anIter).get();
-        //     if(const LightApp_SPV3DDataOwner* anOwner = dynamic_cast<const LightApp_SPV3DDataOwner*>(aDataOwner))
-        //     {
-        //       MESSAGE("aSelector->SetSelectionMode("<<anOwner->GetMode()<<");");
-        //       aSelector->SetSelectionMode(anOwner->GetMode());
-        //       Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
-
-        //       aSelector->AddIObject(anIO);
-
-        //       anAppendList.Append(anIO);
-        //       aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
-        //     }
-        //     else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner))
-        //     {
-        //       Handle(SALOME_InteractiveObject) anIO =
-        //         new SALOME_InteractiveObject(anOwner->entry().toUtf8(),"");
-        //       aSelector->AddIObject(anIO);
-        //       anAppendList.Append(anIO);
-        //     }
-        //   }
-        //   // To remove IOs, which is not selected.
-        //   QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
-        //   SALOME_ListIteratorOfListIO anIt( aStoredList );
-        //   for( ; anIt.More(); anIt.Next() )
-        //     if( !anIt.Value().IsNull() )
-        //       toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
-
-        //   anIt = SALOME_ListIteratorOfListIO(anAppendList);
-        //   for( ; anIt.More(); anIt.Next() )
-        //     toRemove.remove( anIt.Value()->getEntry() );
-
-        //   QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
-        //     REnd = toRemove.end();
-        //   for( ; RIt!=REnd; RIt++ )
-        //     aSelector->RemoveIObject( RIt.value() );
+        if(SPV3D_ViewWindow* aViewWindow = dynamic_cast<SPV3D_ViewWindow*>(aViewMgr->getActiveView()))
+        {
+          if(SPV3D_CADSelection* aSelector = aViewWindow->GetCADSelection()){
+            SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
+            std::set<std::string> SelectedEntryList;
+
+            for(; anIter != theList.end(); ++anIter)
+            {
+              const SUIT_DataOwner* aDataOwner = (*anIter).get();
+              if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner))
+              {
+                if (aViewWindow->isEntryAlreadyExist(anOwner->entry().toStdString().c_str()) != -1)
+                  SelectedEntryList.emplace(anOwner->entry().toStdString());
+              }
+            }
+            aSelector->SetSelectionFromEntrySet(SelectedEntryList);
+          }
+        }
 
         //   aView->onSelectionChanged();
         // }
index 2cf4d17515a86eaaf3c751bc9f1988c34a0904b1..7a67475e0854866317abb0a5ec124c927cede686 100644 (file)
@@ -296,7 +296,7 @@ void SPV3D_CADSelection::onMouseMove()
     proxyRepresentation->GetProperty("PreSelectedID");
   if (!PreselectedIDProperty)
   {
-    qWarning()<< "The representation named '" << proxyRepresentation->GetXMLName()<< "' didn't have a property named 'SelectedIDInfo'.";
+    qWarning()<< "The representation named '" << proxyRepresentation->GetXMLName()<< "' didn't have a property named 'PreSelectedID'.";
     return;
   }
 
@@ -305,7 +305,7 @@ void SPV3D_CADSelection::onMouseMove()
 
   vtkIdType PreSelectedID =
     vtkSMPropertyHelper(proxyRepresentation,"PreSelectedID").GetAsInt(0);
-  qInfo() << "entry from client: "<< SPV3D_Prs::FromVtkIdToEntry(PreSelectedID);
+  qInfo() << "entry from client: "<< SPV3D_Prs::FromVtkIdToEntry(PreSelectedID).c_str();
   
 }
 
@@ -316,6 +316,7 @@ void SPV3D_CADSelection::onLeftButtonRelease()
   {
     this->fastSelection();
   }
+  emit selectionChanged();
 }
 
 //-----------------------------------------------------------------------------
@@ -473,3 +474,56 @@ void SPV3D_CADSelection::cleanupObservers()
   }
   this->ObservedObject = nullptr;
 }
+
+std::set<std::string> SPV3D_CADSelection::GetSelectedObEntry()
+{
+  std::set<std::string> EntryList;
+
+    // get preselected id here
+  if (this->Representation == nullptr)
+    return EntryList;
+  vtkSMProxy* proxyRepresentation = this->Representation->getProxy();
+  if (!proxyRepresentation)
+  {
+    qWarning()<< "There is no representation in the active view for the Geometry Source.";
+    return EntryList;
+  }
+
+  // Retrieve the wanted information property
+  vtkSMProperty* SelectedIDProperty =
+    proxyRepresentation->GetProperty("SelectedIDInfo");
+  if (!SelectedIDProperty)
+  {
+    qWarning()<< "The representation named '" << proxyRepresentation->GetXMLName()<< "' didn't have a property named 'SelectedIDInfo'.";
+    return EntryList;
+  }
+
+  // Force to update the information property
+  proxyRepresentation->UpdatePropertyInformation(SelectedIDProperty);
+
+  // Extract all selected indices
+  std::vector<int> selectedIdx =
+   vtkSMPropertyHelper(proxyRepresentation,"SelectedIDInfo").GetIntArray();
+
+  if (selectedIdx.empty())
+  {
+    qWarning() << "There is no selected id for now.";
+  }
+  else
+  {
+    // Convert all selectedId from Representation in entry type and insert them in set
+    for(std::size_t i = 0; i < selectedIdx.size(); i++)
+      EntryList.insert( SPV3D_Prs::FromVtkIdToEntry(static_cast<vtkIdType>(selectedIdx[i])) );
+  }
+  return EntryList;
+
+}
+
+void SPV3D_CADSelection::SetSelectionFromEntrySet(std::set<std::string> EntryList)
+{
+  std::cout <<"EntryList to be selected provided by client: ";
+  for (std::string entry : EntryList)
+    std::cout << SPV3D_Prs::FromEntryToVtkId(entry.c_str()) << " ";
+  std::cout << std::endl;
+  std::cout <<"We need send the selection request to server here!!!!!" <<std::endl;
+}
\ No newline at end of file
index 24d44d95bf094374051352e2eabdf2f3a164be45..84bfd040ee4ae8278b88efa22877555c2a090e2c 100644 (file)
@@ -30,6 +30,8 @@
 #include <QPushButton>
 #include <QComboBox>
 
+#include <set>
+
 class vtkObject;
 class pqView;
 class pqRenderView;
@@ -72,6 +74,19 @@ public:
    */
   void SetMode(const SPV3D_CADSelection::SelectionMode mode);
   
+  /**
+   * Get Selected entry list from server
+   */
+  std::set<std::string> GetSelectedObEntry();
+
+  /**
+   * Called when the active representation changes.
+   */
+  void SetSelectionFromEntrySet(std::set<std::string> EntryList);
+
+signals:
+  void selectionChanged();
+
 public Q_SLOTS:
   /**
    * For checkable actions, this calls this->beginSelection() or
index 210d89a502095f868d4fd2e8f3ccb5d22b4f505b..d2c0b3fcbab0ee662a6f3b670e73f1f2342fca35 100644 (file)
@@ -187,15 +187,14 @@ vtkIdType SPV3D_Prs::FromEntryToVtkId (const char* entry)
 
   return static_cast<vtkIdType> (ret);
 }
-
-const char* SPV3D_Prs::FromVtkIdToEntry(vtkIdType id)
+std::string SPV3D_Prs::FromVtkIdToEntry(vtkIdType id)
 {
   int d = id & 0xFF;
   std::uint32_t c_work = ( id & 0xFF00 ); int c = c_work >> 8;
   std::uint32_t b_work = ( id & 0xFF0000 ); int b = b_work >> 16;
   std::uint32_t a_work = ( id & 0xFF000000 ); int a = a_work >> 24;
   std::string ret = std::to_string(a) + ":" + std::to_string(b) + ":" + std::to_string(c)+ ":" + std::to_string(d);
-  return ret.c_str();
+  return ret;
 }
 
 SPV3D_Prs *SPV3D_Prs::deepCopy() const
index 191fd556b839e2e69c38b8308ab46476db00f79e..687090c512861788e25a3ce3f0fe1a4fbea1a434 100644 (file)
@@ -93,7 +93,7 @@ public:
 
   bool IsNull() const override;
   static vtkIdType FromEntryToVtkId (const char*);
-  static const char* FromVtkIdToEntry (vtkIdType);
+  static std::string FromVtkIdToEntry (vtkIdType);
 
 private:
 
index 90cae0b6a96f122486d227e3fde2391db441121b..1b6ef8930df7347d4d9762607c3fb1ce66fe97fb 100644 (file)
@@ -363,3 +363,8 @@ void SPV3D_ViewModel::showSelectedMode()
   activeView->render();
   activeView->resetDisplay();
 }
+
+void SPV3D_ViewModel::performSelectionChanged()
+{
+  emit selectionChanged();
+}
\ No newline at end of file
index 3daf72d7ee320a4ee23b66f2a8e53ceccdb69ce4..926477d99c9e749e46ddd94c42b79e1cd758839d 100644 (file)
@@ -89,6 +89,12 @@ public:
   //! See #SALOME_View::Repaint()
   virtual void Repaint();
 
+  //! Trigger selection changed
+  void performSelectionChanged();
+
+signals:
+  void selectionChanged();
+
 protected slots:
   void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
   void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
@@ -98,6 +104,7 @@ protected slots:
 
   void onSourceCreated(pqPipelineSource* source);
   void showSelectedMode();
+  void onSelectionChanged();
 
 protected:
   pqPipelineSource* GeometrySource = nullptr;
index b4e04f9b55f94597d70517340a9bfa8670c6b71c..b22a9fda30605630b0feae68a945e51068f36070 100644 (file)
@@ -114,11 +114,18 @@ void SPV3D_ViewWindow::init()
   QAction *selectionAction =  toolMgr()->toolBar(myToolBar)->addAction(SUIT_Session::session()->resourceMgr()->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ), tr( "MNU_SVTK_PRESELECTION_STANDARD" ) );
   selectionAction->setCheckable(true);
   QObject::connect(selectionAction, &QAction::toggled, this, &SPV3D_ViewWindow::goSelect);
+  QObject::connect( mySelection, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
+
   
   SPV3D_EXPORTSPV3DData* rawPtr = new SPV3D_EXPORTSPV3DData();
   myPrs.reset(rawPtr);
 }
 
+void SPV3D_ViewWindow::onSelectionChanged()
+{
+  this->myModel->performSelectionChanged();
+}
+
 void SPV3D_ViewWindow::goSelect(bool val)
 {
   if(val)
@@ -133,7 +140,14 @@ void SPV3D_ViewWindow::goSelect(bool val)
       {
         vtkSMProxy* repr = activeView->getViewProxy()->FindRepresentation(
           geometrySource->getSourceProxy(), 0);
-        repr->InvokeCommand("Reset");
+        if(repr)
+        {
+          repr->InvokeCommand("Reset");
+        }
+        else
+        {
+          val = false;
+        }
       }
       activeView->forceRender();
       activeView->render();
@@ -400,3 +414,11 @@ void SPV3D_ViewWindow::hideEvent( QHideEvent * theEvent )
 {
   emit Hide( theEvent );
 }
+
+/*!
+  Get Selector to get entry of selected object to salome
+*/
+SPV3D_CADSelection* SPV3D_ViewWindow::GetCADSelection()
+{
+  return this->mySelection;
+}
\ No newline at end of file
index fb546dc784a0e4bf644d93b4b7b6ba12532bd975..43d551b85a23f1ecc65066b410f8346510f30880 100644 (file)
@@ -83,9 +83,13 @@ class SPV3D_EXPORT SPV3D_ViewWindow : public PV3DViewer_ViewWindow
   //! Enable/disable selection
   virtual void SetSelectionEnabled( bool );
 
+  //! Get selector
+  SPV3D_CADSelection * GetCADSelection();
+
  signals:
   void Show( QShowEvent * );
   void Hide( QHideEvent * );
+  void selectionChanged();
 
 public slots:
   virtual void showEvent( QShowEvent * );
@@ -93,6 +97,7 @@ public slots:
   void showCenterAxes(bool);
   void pickCenterOfRotation(int posx, int posy);
   void goSelect(bool val);
+  void onSelectionChanged();
 
 protected slots:
   void onKeyPressed(QKeyEvent* event);