Skip to content
Snippets Groups Projects
Commit 40c8c44b authored by MelanieCarriere's avatar MelanieCarriere
Browse files

[feat] Enable saving properties from multiple Lidars

We want to be able to save the transform and other functionnality applied to a Lidar.

We tried to use "Save/Load paraview state" to save all the current open sources.
But there is a bug to load a ProxyProperty (transform) of a proxyProperty (Interpreter) of a proxy (Reader or stream).
The reapply of the transform does not work and may crash when we try to access it (https://gitlab.kitware.com/LidarView/lidarview-core/-/blob/master/ApplicationComponents/lqHelper.cxx#L256)

To restore a transform we add the "Save/Load Lidar State" button to each sensorsWidget in the sensor List.
It allows the user to save some properties of the specific Lidar into a json file
or to load the properties from a json file to a specific Lidar
parent bbf4342d
No related branches found
No related tags found
1 merge request!249[feat] Enable saving properties from multiple Lidars
......@@ -30,16 +30,6 @@ lqLoadLidarStateReaction::lqLoadLidarStateReaction(QAction *action)
//-----------------------------------------------------------------------------
void lqLoadLidarStateReaction::onTriggered()
{
// Get the Lidar state file
QString LidarStateFile = QFileDialog::getOpenFileName(nullptr,
QString("Choose the lidar state file to load on the first lidar"),
"", QString("json (*.json)"));
if(LidarStateFile.isEmpty())
{
return;
}
// Get the first lidar source
std::vector<vtkSMProxy*> lidarProxys = GetLidarsProxy();
......@@ -54,7 +44,21 @@ void lqLoadLidarStateReaction::onTriggered()
QMessageBox::warning(nullptr, tr(""), tr("Multiple lidars sources found, only the first one will be updated") );
}
vtkSMProxy * lidarCurrentProxy = lidarProxys[0];
lqLoadLidarStateReaction::LoadLidarState(lidarProxys[0]);
}
//-----------------------------------------------------------------------------
void lqLoadLidarStateReaction::LoadLidarState(vtkSMProxy * lidarCurrentProxy)
{
// Get the Lidar state file
QString LidarStateFile = QFileDialog::getOpenFileName(nullptr,
QString("Choose the lidar state file to load on the first lidar"),
"", QString("json (*.json)"));
if(LidarStateFile.isEmpty())
{
return;
}
// Read and get information of the JSON file
Json::Value contents;
......@@ -73,7 +77,7 @@ void lqLoadLidarStateReaction::onTriggered()
std::vector<propertyInfo> propertyInfo;
try
{
this->ParseJsonContent(contents, "",propertyInfo);
ParseJsonContent(contents, "",propertyInfo);
}
catch(std::exception e)
{
......
......@@ -25,6 +25,8 @@ class LQAPPLICATIONCOMPONENTS_EXPORT lqLoadLidarStateReaction : public pqReactio
public:
lqLoadLidarStateReaction(QAction* action);
static void LoadLidarState(vtkSMProxy * lidarCurrentProxy);
/**
* @brief UpdateProxyProperty set the values to the property "propNameToFind" of the proxy
* If the property is not found in the proxy, a message is displayed but nothing is done.
......@@ -55,7 +57,7 @@ private:
* @param ObjectName name of the current proxy
* @param propertyInfo vector to write information (name, value) of the found properties
*/
void ParseJsonContent(Json::Value contents, std::string ObjectName, std::vector<propertyInfo>& propertyInfo);
static void ParseJsonContent(Json::Value contents, std::string ObjectName, std::vector<propertyInfo>& propertyInfo);
};
......
......@@ -28,17 +28,6 @@ lqSaveLidarStateReaction::lqSaveLidarStateReaction(QAction *action)
//-----------------------------------------------------------------------------
void lqSaveLidarStateReaction::onTriggered()
{
// Save Lidar Save information file
QString defaultFileName = QString("SaveLidarInformation.json");
QString StateFile = QFileDialog::getSaveFileName(nullptr,
QString("File to save the first lidar information:"),
defaultFileName, QString("json (*.json)"));
if(StateFile.isEmpty())
{
return;
}
// Get the first lidar source
pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
if(smmodel == nullptr)
......@@ -67,6 +56,23 @@ void lqSaveLidarStateReaction::onTriggered()
return;
}
lqSaveLidarStateReaction::SaveLidarState(lidarProxy);
}
//-----------------------------------------------------------------------------
void lqSaveLidarStateReaction::SaveLidarState(vtkSMProxy * lidarProxy)
{
// Save Lidar Save information file
QString defaultFileName = QString("SaveLidarInformation.json");
QString StateFile = QFileDialog::getSaveFileName(nullptr,
QString("File to save the first lidar information:"),
defaultFileName, QString("json (*.json)"));
if(StateFile.isEmpty())
{
return;
}
std::vector<propertyInfo> propertiesInfo;
constructPropertiesInfo(lidarProxy, propertiesInfo);
......@@ -174,7 +180,7 @@ void lqSaveLidarStateReaction::constructPropertiesInfo(vtkSMProxy * lidarProxy,
// We want all specific properties of a proxy stick together
for(unsigned int p = 0; p < proxysToCompute.size(); p++)
{
this->constructPropertiesInfo(proxysToCompute[p], propertiesVector);
constructPropertiesInfo(proxysToCompute[p], propertiesVector);
}
}
......
......@@ -25,6 +25,9 @@ class LQAPPLICATIONCOMPONENTS_EXPORT lqSaveLidarStateReaction : public pqReactio
public:
lqSaveLidarStateReaction(QAction* action);
static void SaveLidarState(vtkSMProxy * lidarProxy);
public slots:
/**
* Called when the action is triggered.
......@@ -40,7 +43,7 @@ private:
* @param lidarProxy proxy to extract the properties
* @param propertiesVector contains all the properties (names, value) of the current proxy and ots sub-proxy.
*/
void constructPropertiesInfo(vtkSMProxy * lidarProxy, std::vector<propertyInfo>& propertiesVector);
static void constructPropertiesInfo(vtkSMProxy * lidarProxy, std::vector<propertyInfo>& propertiesVector);
/**
* @brief getValueOfPropAsString get the values of a property
......@@ -48,7 +51,7 @@ private:
* @return The std::vector containing the values of the property prop.
* If the property is a not an array, only the first element is fill
*/
std::vector<std::string> getValueOfPropAsString(vtkSMProperty * prop);
static std::vector<std::string> getValueOfPropAsString(vtkSMProperty * prop);
};
......
#include "lqSensorWidget.h"
#include "ui_lqSensorWidget.h"
#include "lqLoadLidarStateReaction.h"
#include "lqSaveLidarStateReaction.h"
#include <pqApplicationCore.h>
#include <pqPipelineSource.h>
#include <pqObjectBuilder.h>
......@@ -34,6 +37,9 @@ lqSensorWidget::lqSensorWidget(QWidget *parent) :
// create all connection
this->connect(UI->close, SIGNAL(clicked()), this, SLOT(onClose()));
this->connect(UI->calibrate, SIGNAL(clicked()), this, SLOT(onCalibrate()));
this->connect(UI->SaveLidarState, SIGNAL(clicked()), this, SLOT(onSaveLidarState()));
this->connect(UI->LoadLidarState, SIGNAL(clicked()), this, SLOT(onLoadLidarState()));
}
//-----------------------------------------------------------------------------
......@@ -144,6 +150,24 @@ void lqSensorWidget::onShowHide()
}
}
//-----------------------------------------------------------------------------
void lqSensorWidget::onLoadLidarState()
{
if (this->LidarSource)
{
lqLoadLidarStateReaction::LoadLidarState(this->LidarSource->getProxy());
}
}
//-----------------------------------------------------------------------------
void lqSensorWidget::onSaveLidarState()
{
if (this->LidarSource)
{
lqSaveLidarStateReaction::SaveLidarState(this->LidarSource->getProxy());
}
}
//-----------------------------------------------------------------------------
void lqSensorWidget::deleteSource(pqPipelineSource *src)
{
......
......@@ -44,7 +44,8 @@ class LQAPPLICATIONCOMPONENTS_EXPORT lqSensorWidget : public QWidget
void onCalibrate();
void onClose();
void onShowHide();
void onSaveLidarState();
void onLoadLidarState();
protected:
Q_DISABLE_COPY(lqSensorWidget)
......
......@@ -416,6 +416,28 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="SaveLidarState">
<property name="icon">
<iconset resource="../LVCore/ApplicationComponents/lqResources.qrc">
<normaloff>:/lqResources/Icons/pqSaveState.png</normaloff>:/lqResources/Icons/pqSaveState.png</iconset>
</property>
<property name="toolTip">
<string>Save Lidar state</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="LoadLidarState">
<property name="icon">
<iconset resource="../LVCore/ApplicationComponents/lqResources.qrc">
<normaloff>:/lqResources/Icons/pqLoadState.png</normaloff>:/lqResources/Icons/pqLoadState.png</iconset>
</property>
<property name="toolTip">
<string>Load Lidar state</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment