From 3ed45c2513ad0293c67182540faa2da9c3d2a909 Mon Sep 17 00:00:00 2001 From: DUC ANH HOANG Date: Thu, 1 Aug 2024 12:00:05 +0200 Subject: [PATCH] selection synchronisation between OB and SPV3D_Viewer: 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 | 101 ++++++++++--------------- src/SPV3D/SPV3D_CADSelection.cxx | 58 +++++++++++++- src/SPV3D/SPV3D_CADSelection.h | 15 ++++ src/SPV3D/SPV3D_Prs.cxx | 5 +- src/SPV3D/SPV3D_Prs.h | 2 +- src/SPV3D/SPV3D_ViewModel.cxx | 5 ++ src/SPV3D/SPV3D_ViewModel.h | 7 ++ src/SPV3D/SPV3D_ViewWindow.cxx | 24 +++++- src/SPV3D/SPV3D_ViewWindow.h | 5 ++ 9 files changed, 154 insertions(+), 68 deletions(-) diff --git a/src/LightApp/LightApp_PV3DSelector.cxx b/src/LightApp/LightApp_PV3DSelector.cxx index 635515d47..e4e5dd79e 100644 --- a/src/LightApp/LightApp_PV3DSelector.cxx +++ b/src/LightApp/LightApp_PV3DSelector.cxx @@ -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(aViewManager)){ + if(SPV3D_ViewWindow* aViewWindow = dynamic_cast(aViewMgr->getActiveView())){ + if(SPV3D_CADSelection* aSelector = aViewWindow->GetCADSelection()){ + std::set 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(aViewManager)){ - // if(PV3DViewer_ViewWindow* aView = dynamic_cast(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(aViewMgr->getActiveView())) + if(SPV3D_ViewManager* aViewMgr = dynamic_cast(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(aDataOwner)) - // { - // MESSAGE("aSelector->SetSelectionMode("<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(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(aViewMgr->getActiveView())) + { + if(SPV3D_CADSelection* aSelector = aViewWindow->GetCADSelection()){ + SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin(); + std::set SelectedEntryList; + + for(; anIter != theList.end(); ++anIter) + { + const SUIT_DataOwner* aDataOwner = (*anIter).get(); + if(const LightApp_DataOwner* anOwner = dynamic_cast(aDataOwner)) + { + if (aViewWindow->isEntryAlreadyExist(anOwner->entry().toStdString().c_str()) != -1) + SelectedEntryList.emplace(anOwner->entry().toStdString()); + } + } + aSelector->SetSelectionFromEntrySet(SelectedEntryList); + } + } // aView->onSelectionChanged(); // } diff --git a/src/SPV3D/SPV3D_CADSelection.cxx b/src/SPV3D/SPV3D_CADSelection.cxx index 2cf4d1751..7a67475e0 100644 --- a/src/SPV3D/SPV3D_CADSelection.cxx +++ b/src/SPV3D/SPV3D_CADSelection.cxx @@ -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 SPV3D_CADSelection::GetSelectedObEntry() +{ + std::set 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 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(selectedIdx[i])) ); + } + return EntryList; + +} + +void SPV3D_CADSelection::SetSelectionFromEntrySet(std::set 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!!!!!" < #include +#include + 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 GetSelectedObEntry(); + + /** + * Called when the active representation changes. + */ + void SetSelectionFromEntrySet(std::set EntryList); + +signals: + void selectionChanged(); + public Q_SLOTS: /** * For checkable actions, this calls this->beginSelection() or diff --git a/src/SPV3D/SPV3D_Prs.cxx b/src/SPV3D/SPV3D_Prs.cxx index 210d89a50..d2c0b3fcb 100644 --- a/src/SPV3D/SPV3D_Prs.cxx +++ b/src/SPV3D/SPV3D_Prs.cxx @@ -187,15 +187,14 @@ vtkIdType SPV3D_Prs::FromEntryToVtkId (const char* entry) return static_cast (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 diff --git a/src/SPV3D/SPV3D_Prs.h b/src/SPV3D/SPV3D_Prs.h index 191fd556b..687090c51 100644 --- a/src/SPV3D/SPV3D_Prs.h +++ b/src/SPV3D/SPV3D_Prs.h @@ -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: diff --git a/src/SPV3D/SPV3D_ViewModel.cxx b/src/SPV3D/SPV3D_ViewModel.cxx index 90cae0b6a..1b6ef8930 100644 --- a/src/SPV3D/SPV3D_ViewModel.cxx +++ b/src/SPV3D/SPV3D_ViewModel.cxx @@ -363,3 +363,8 @@ void SPV3D_ViewModel::showSelectedMode() activeView->render(); activeView->resetDisplay(); } + +void SPV3D_ViewModel::performSelectionChanged() +{ + emit selectionChanged(); +} \ No newline at end of file diff --git a/src/SPV3D/SPV3D_ViewModel.h b/src/SPV3D/SPV3D_ViewModel.h index 3daf72d7e..926477d99 100644 --- a/src/SPV3D/SPV3D_ViewModel.h +++ b/src/SPV3D/SPV3D_ViewModel.h @@ -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; diff --git a/src/SPV3D/SPV3D_ViewWindow.cxx b/src/SPV3D/SPV3D_ViewWindow.cxx index b4e04f9b5..b22a9fda3 100644 --- a/src/SPV3D/SPV3D_ViewWindow.cxx +++ b/src/SPV3D/SPV3D_ViewWindow.cxx @@ -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 diff --git a/src/SPV3D/SPV3D_ViewWindow.h b/src/SPV3D/SPV3D_ViewWindow.h index fb546dc78..43d551b85 100644 --- a/src/SPV3D/SPV3D_ViewWindow.h +++ b/src/SPV3D/SPV3D_ViewWindow.h @@ -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); -- 2.39.2