]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
wip
authorLéon Victor <leon.victor@kitware.com>
Thu, 24 Oct 2024 19:06:11 +0000 (21:06 +0200)
committerLéon Victor <leon.victor@kitware.com>
Thu, 24 Oct 2024 19:06:11 +0000 (21:06 +0200)
src/SPV3D/SPV3D_CADSelection.cxx

index 85c0e837595a650108cc2fe725e2135dc5dc3cb5..94ef5a2b2c4a552b4156a0e8553760726a13b1e0 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <vtkDataObject.h>
 #include <vtkCollection.h>
+#include <vtkIdTypeArray.h>
 #include <vtkRenderWindowInteractor.h>
 #include <vtkPVRenderView.h>
 #include <vtkPVDataInformation.h>
@@ -45,6 +46,8 @@
 #include <pqPVApplicationCore.h>
 #include <pqSelectionManager.h>
 #include <pqServerManagerModel.h>
+#include <vtkPVEncodeSelectionForServer.h>
+#include <vtkInformation.h>
 
 #include "SPV3D_Prs.h"
 
@@ -350,10 +353,10 @@ void SPV3D_CADSelection::fastSelection(bool presel)
 
   int region[4] = { x, y, x, y };
 
+  // Do the selection on the current region (client side)
   vtkNew<vtkCollection> selectedRepresentations;
   vtkNew<vtkCollection> selectionSources;
   bool status = false;
-  // Do the selection on the current region
   switch (this->Mode)
   {
     case SELECT_SOLIDS:
@@ -376,6 +379,7 @@ void SPV3D_CADSelection::fastSelection(bool presel)
   vtkSMRepresentationProxy* repr =
     vtkSMRepresentationProxy::SafeDownCast(selectedRepresentations->GetItemAsObject(0));
 
+  // Forward the selection to the server
   if (repr && !presel)
   {
     repr->InvokeCommand("BeginSelect");
@@ -384,9 +388,6 @@ void SPV3D_CADSelection::fastSelection(bool presel)
   // If something has been preselected or selected
   if (status)
   {
-    vtkSMRepresentationProxy* repr =
-      vtkSMRepresentationProxy::SafeDownCast(selectedRepresentations->GetItemAsObject(0));
-
     // If the selection occurs on a new represention, clean the selection on the
     // current representation before continuing
     if (this->CurrentRepresentation != nullptr && repr != this->CurrentRepresentation)
@@ -402,10 +403,12 @@ void SPV3D_CADSelection::fastSelection(bool presel)
     this->CurrentRepresentation = repr;
 
     // Set the selection (selection source) to the current representation
+    // TODO: There should be some cases where we append instead. Which ones ? When a modifier is pressed ? (i.e. the Control Key)
     vtkSMSourceProxy* sel = vtkSMSourceProxy::SafeDownCast(selectionSources->GetItemAsObject(0));
     vtkSMPropertyHelper(repr, "Selection").Set(sel);
     repr->UpdateVTKObjects();
   }
+
   // If nothing has been selected then clean current representation
   // with an "empty" selection source
   else if (this->CurrentRepresentation != nullptr)
@@ -485,9 +488,12 @@ std::set<std::string> SPV3D_CADSelection::GetSelectedObEntry()
 {
   std::set<std::string> EntryList;
 
-    // get preselected id here
+  // get preselected id here
   if (this->Representation == nullptr)
+  {
     return EntryList;
+  }
+
   vtkSMProxy* proxyRepresentation = this->Representation->getProxy();
   if (!proxyRepresentation)
   {
@@ -496,16 +502,15 @@ std::set<std::string> SPV3D_CADSelection::GetSelectedObEntry()
   }
 
   // Retrieve the wanted information property
-  vtkSMProperty* SelectedIDProperty =
-    proxyRepresentation->GetProperty("SelectedIDInfo");
-  if (!SelectedIDProperty)
+  vtkSMProperty* selectionProperty = proxyRepresentation->GetProperty("Selection");
+  if (selectionProperty == nullptr)
   {
-    qWarning()<< "The representation named '" << proxyRepresentation->GetXMLName()<< "' didn't have a property named 'SelectedIDInfo'.";
+    qWarning()<< "The representation named '" << proxyRepresentation->GetXMLName()<< "' did not have a property named 'Selection'.";
     return EntryList;
   }
 
   // Force to update the information property
-  proxyRepresentation->UpdatePropertyInformation(SelectedIDProperty);
+  proxyRepresentation->UpdatePropertyInformation(selectionProperty);
 
   // Extract all selected indices
   std::vector<int> selectedIdx =
@@ -530,6 +535,7 @@ std::set<std::string> SPV3D_CADSelection::GetSelectedObEntry()
 
 }
 
+// TODO: Prefer passing parameters by const ref rather than by copy
 void SPV3D_CADSelection::SetSelectionFromEntrySet(std::set<std::string> EntryList)
 {
   if (this->Representation == nullptr) {
@@ -537,67 +543,57 @@ void SPV3D_CADSelection::SetSelectionFromEntrySet(std::set<std::string> EntryLis
     return;
   }
 
+
   vtkSMProxy* proxyRepresentation = this->Representation->getProxy();
   if (!proxyRepresentation) 
   {
     qWarning() << "There is no representation";
     return;
   }
+  // this->View->forceRender();
 
-  std::cout << "(Client) Sending selected entries to server:" << std::endl;
+  proxyRepresentation->InvokeCommand("BeginSelect");
 
-  auto producerPort = vtkSMPropertyHelper(proxyRepresentation, "Input").GetAsOutputPort();
-  if (producerPort)
-  {
-    std::cout << producerPort->GetDataClassName() << std::endl;
-  }
+  // Create a new selection source on the server side and its proxy on the client side
+  vtkSMRenderViewProxy* rmp = this->View->getRenderViewProxy();
+  vtkSMSessionProxyManager* pxm = rmp->GetSessionProxyManager();
+  vtkSMProxy* selectionSource = pxm->NewProxy("sources", "ValueSelectionSource");
+  vtkSMPropertyHelper(selectionSource, "ArrayName").Set("Solid id");
+  vtkSMPropertyHelper(selectionSource, "FieldType").Set("CELL");
+  vtkSMPropertyHelper(selectionSource, "Values").SetNumberOfElements(EntryList.size());
 
-  vtkNew<vtkSelectionSource> selectionSource;
-  selectionSource->SetFieldType(vtkSelectionNode::CELL);
-  selectionSource->SetContentType(vtkSelectionNode::BLOCKS);
-  selectionSource->SetArrayName("name"); // TODO 
+  // TODO: How do i get that properly ?
+  vtkIdType processNumber = 0;
 
   // Retrieve entry ids and put them in a vector
-  std::vector<int> selectedIds;
-  selectedIds.reserve(EntryList.size());
+  std::cout << "(Client) Sending selected entries to server:" << std::endl;
+  
+  // TODO: Make sure this works for multiple selections
   for (const std::string& entryName: EntryList)
   {
-    vtkIdType id = SPV3D_Prs::FromEntryToVtkId(entryName.c_str());
-    std::cout << "(Client) " << id << std::endl;
-    selectedIds.push_back(id);
-
-    // TODO: I'm not sure what ids reference
-    selectionSource->AddBlock(id);
-
+    vtkIdType solidId = SPV3D_Prs::FromEntryToVtkId(entryName.c_str());
+    std::cout << "(Client) " << solidId << std::endl;
 
+    // This takes pairs of values as (process number, value).
+    std::array<vtkIdType, 2> values = {solidId, processNumber};
+    vtkSMPropertyHelper(selectionSource, "Values").Append(values.data(), 2);
   }
 
-  selectionSource->Update();
-
-  auto producer = producerPort->GetSourceProxy();
+  selectionSource->UpdateVTKObjects();
   
-  auto selectionSourceProxy = vtk::TakeSmartPointer(
-    vtkSMSourceProxy::SafeDownCast(vtkSMSelectionHelper::NewSelectionSourceFromSelection(
-      producer->GetSession(), selectionSource->GetOutput())));
-  // create append selection proxy from selection source proxy
-  auto appendSelections = vtk::TakeSmartPointer(vtkSMSourceProxy::SafeDownCast(
-    vtkSMSelectionHelper::NewAppendSelectionsFromSelectionSource(selectionSourceProxy)));
-  if (appendSelections)
-  {
-    producer->SetSelectionInput(producerPort->GetPortIndex(), appendSelections, 0);
-
-    auto smmodel = pqApplicationCore::instance()->getServerManagerModel();
-    auto selManager = pqPVApplicationCore::instance()->selectionManager();
-    selManager->select(smmodel->findItem<pqOutputPort*>(producerPort));
-  }
-
-
+  vtkSMPropertyHelper(proxyRepresentation, "Selection").Set(selectionSource);
+  proxyRepresentation->UpdateVTKObjects();
+  
+  selectionSource->Delete();
+  
+  // TODO: Which render calls are necessary to display the selection right away ?
+  // TODO: Before, after or during the slection ?
+  // Force render to make sure the selection appears
+  this->View->forceRender();
+  this->View->forceRender();
+  rmp->StillRender();
 
-  // vtkSMSelectionHelper::NewSelectionSourceFromSelection(, vtkSelection *selection);
-  vtkSMProperty* selectionProperty = proxyRepresentation->GetProperty("Selection");
-  // vtkSMPropertyHelper(selectionProperty)
+  proxyRepresentation->InvokeCommand("EndSelect");
+  
 
-  vtkSMProperty* selectedIDsProperty = proxyRepresentation->GetProperty("SelectedIDs");
-  vtkSMPropertyHelper(selectedIDsProperty).Set(selectedIds.data(), selectedIds.size());
-  proxyRepresentation->UpdateVTKObjects();
 }