From: Léon Victor Date: Thu, 24 Oct 2024 19:06:11 +0000 (+0200) Subject: wip X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=778a21417b95c4b3e638c36afb77b6110b067020;p=modules%2Fgui.git wip --- diff --git a/src/SPV3D/SPV3D_CADSelection.cxx b/src/SPV3D/SPV3D_CADSelection.cxx index 85c0e8375..94ef5a2b2 100644 --- a/src/SPV3D/SPV3D_CADSelection.cxx +++ b/src/SPV3D/SPV3D_CADSelection.cxx @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,8 @@ #include #include #include +#include +#include #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 selectedRepresentations; vtkNew 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 SPV3D_CADSelection::GetSelectedObEntry() { std::set 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 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 selectedIdx = @@ -530,6 +535,7 @@ std::set SPV3D_CADSelection::GetSelectedObEntry() } +// TODO: Prefer passing parameters by const ref rather than by copy void SPV3D_CADSelection::SetSelectionFromEntrySet(std::set EntryList) { if (this->Representation == nullptr) { @@ -537,67 +543,57 @@ void SPV3D_CADSelection::SetSelectionFromEntrySet(std::set 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 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 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 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(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(); }