#include <vtkDataObject.h>
#include <vtkCollection.h>
+#include <vtkIdTypeArray.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPVRenderView.h>
#include <vtkPVDataInformation.h>
#include <pqPVApplicationCore.h>
#include <pqSelectionManager.h>
#include <pqServerManagerModel.h>
+#include <vtkPVEncodeSelectionForServer.h>
+#include <vtkInformation.h>
#include "SPV3D_Prs.h"
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:
vtkSMRepresentationProxy* repr =
vtkSMRepresentationProxy::SafeDownCast(selectedRepresentations->GetItemAsObject(0));
+ // Forward the selection to the server
if (repr && !presel)
{
repr->InvokeCommand("BeginSelect");
// 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)
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)
{
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)
{
}
// 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 =
}
+// TODO: Prefer passing parameters by const ref rather than by copy
void SPV3D_CADSelection::SetSelectionFromEntrySet(std::set<std::string> EntryList)
{
if (this->Representation == nullptr) {
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();
}